Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
ui-components: Uppercase text transformation
Browse files Browse the repository at this point in the history
Avatar component has to be forced to display text with upper-case.

Added `transformCase` prop with the same styles
as in `Badge` component to follow the same styles.
  • Loading branch information
koorosh committed May 22, 2020
1 parent b4d4765 commit 407133a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const demo = () => (
)}
onClick={action("button-click")}
selectable={boolean("Selectable", true)}
transformCase={select("transformCase", ["none", "uppercase"], "uppercase")}
>
{text("Text", "RL")}
</Avatar>
Expand Down
12 changes: 12 additions & 0 deletions packages/ui-components/src/Avatar/Avatar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@
letter-spacing: 0.1px;
}

.noTransform {
text-transform: none;
}

.transformCase-none {
text-transform: none;
}

.transformCase-uppercase {
text-transform: uppercase;
}

.disabled {
background: $crl-neutral-2;
color: $crl-base-text--light;
Expand Down
1 change: 1 addition & 0 deletions packages/ui-components/src/Avatar/Avatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe("Avatar", () => {
const className = wrapper.prop("className");
expect(className).toContain("intent-default");
expect(className).toContain("size-l");
expect(className).toContain("transformCase-uppercase");
expect(className).not.toContain("disabled");
expect(className).not.toContain("selectable");
});
Expand Down
7 changes: 5 additions & 2 deletions packages/ui-components/src/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export interface AvatarProps {
disabled?: boolean;
selectable?: boolean;
onClick?: () => void;
transformCase?: AvatarCase;
}

export type AvatarSize = "xs" | "s" | "m" | "l";
export type AvatarIntent = "default" | "active" | "pending" | "invalid";
export type AvatarCase = "none" | "uppercase";

const cx = classNames.bind(styles);

Expand All @@ -25,15 +27,16 @@ const Avatar: React.FC<AvatarProps> = ({
disabled = false,
selectable = false,
onClick,
transformCase = "uppercase",
}) => {
const classnames = useMemo(
() =>
cx("avatar", objectToClassnames({ size }), {
cx("avatar", objectToClassnames({ size, transformCase }), {
disabled,
selectable: !disabled && selectable,
[`intent-${intent}`]: !disabled,
}),
[intent, size, disabled, selectable],
[intent, size, disabled, selectable, transformCase],
);

const onClickHandler = useCallback(() => {
Expand Down

0 comments on commit 407133a

Please sign in to comment.