Skip to content

Commit

Permalink
support text transform in Text and remove old name ref
Browse files Browse the repository at this point in the history
  • Loading branch information
OskiTheCoder committed Oct 31, 2023
1 parent 1298252 commit cea70bc
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion easy-ui-react/src/SearchNav/SearchNav.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ less than `640px`.

<Canvas of={SearchNavStories.Simple} />

## Emphasized Text
## Title

<Canvas of={SearchNavStories.Title} />

Expand Down
3 changes: 0 additions & 3 deletions easy-ui-react/src/SearchNav/Title.module.scss

This file was deleted.

11 changes: 4 additions & 7 deletions easy-ui-react/src/SearchNav/Title.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React, { ReactNode } from "react";
import { Text } from "../Text";
import { classNames } from "../utilities/css";

import styles from "./Title.module.scss";

export type TitleProps = {
/**
* Emphasized text content to display.
* Text content to display.
*/
children: ReactNode;
};
Expand All @@ -15,9 +12,9 @@ export function Title(props: TitleProps) {
const { children } = props;

return (
<span className={classNames(styles.title)}>
<Text variant="subtitle1">{children}</Text>
</span>
<Text variant="subtitle1" transform="uppercase">
{children}
</Text>
);
}

Expand Down
16 changes: 16 additions & 0 deletions easy-ui-react/src/Text/Text.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,19 @@
.numeric {
font-variant-numeric: tabular-nums lining-nums;
}

.transformNone {
text-transform: none;
}

.transformCapitalize {
text-transform: capitalize;
}

.transformUppercase {
text-transform: uppercase;
}

.transformLowercase {
text-transform: lowercase;
}
8 changes: 8 additions & 0 deletions easy-ui-react/src/Text/Text.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ describe("<Text />", () => {
expect.stringContaining("visuallyHidden"),
);
});

it("should transform text", () => {
render(<Text transform="uppercase">Here is some text</Text>);
expect(screen.getByText("Here is some text")).toHaveAttribute(
"class",
expect.stringContaining("transformUppercase"),
);
});
});
11 changes: 10 additions & 1 deletion easy-ui-react/src/Text/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React, { ReactNode } from "react";
import { ThemeTokenNamespace, DesignTokenNamespace } from "../types";
import { classNames, getComponentThemeToken } from "../utilities/css";
import {
classNames,
getComponentThemeToken,
variationName,
} from "../utilities/css";

import styles from "./Text.module.scss";

Expand All @@ -18,6 +22,7 @@ export type TextAs =
export type TextColor = ThemeTokenNamespace<"color.text">;
export type TextVariant = DesignTokenNamespace<"font.style", "family">;
export type TextWeight = "normal" | "medium" | "semibold" | "bold";
export type TextTransform = "none" | "capitalize" | "uppercase" | "lowercase";

export type TextProps = {
/** Adjusts horizontal alignment of text */
Expand All @@ -32,6 +37,8 @@ export type TextProps = {
color?: TextColor;
/** HTML id attribute */
id?: string;
/** Transform text */
transform?: TextTransform;
/** Truncate text overflow with ellipsis */
truncate?: boolean;
/** Adjusts the style of text that's rendered */
Expand Down Expand Up @@ -90,6 +97,7 @@ export function Text({
children,
color,
id,
transform = "none",
truncate = false,
variant,
visuallyHidden = false,
Expand All @@ -104,6 +112,7 @@ export function Text({
breakWord && styles.break,
truncate && styles.truncate,
visuallyHidden && styles.visuallyHidden,
transform && styles[variationName("transform", transform)],
);

const style = {
Expand Down

0 comments on commit cea70bc

Please sign in to comment.