Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NDS-809] feat: revisit typography parsing mechanism [v5] #676

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/components/Avatar/Avatar.style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { css, SerializedStyles } from '@emotion/react';
import { get } from 'lodash';

import {
AvatarTextTokens,
Expand All @@ -10,12 +9,13 @@ import {
import { AvatarColors, AvatarSizes } from './Avatar.types';
import { Theme } from '../../theme';
import { flex } from '../../theme/functions';
import { generateStylesFromTokens } from 'components/Typography/utils';

export const avatarStyle =
({ size, color }: { size: AvatarSizes; color: AvatarColors }) =>
(theme: Theme): SerializedStyles => {
const tokens = getAvatarTokens(theme);
const typographyTokens = getAvatarTextTokens();
const typographyTokens = getAvatarTextTokens(theme);

return css`
${flex};
Expand All @@ -34,10 +34,7 @@ export const avatarStyle =
user-select: none;
justify-content: center;

font-size: ${get(typographyTokens(`${size}` as AvatarTextTokens), 'fontSize')};
font-weight: ${get(typographyTokens(`${size}` as AvatarTextTokens), 'fontWeight')};
line-height: ${get(typographyTokens(`${size}` as AvatarTextTokens), 'lineHeight')};
letter-spacing: ${get(typographyTokens(`${size}` as AvatarTextTokens), 'letterSpacing')};
${generateStylesFromTokens(typographyTokens(`${size}` as AvatarTextTokens))};

img {
border-radius: ${tokens('borderRadius')};
Expand Down
10 changes: 6 additions & 4 deletions src/components/Avatar/Avatar.tokens.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import avatar from 'theme/tokens/components/variables/avatar';
import avatarText from 'theme/tokens/components/variables/avatarText';
import { getComponentTokens, parseCompositionToken, DotKeys } from 'theme/tokens/utils';
import { getComponentTokens, DotKeys } from 'theme/tokens/utils';
import { rem } from 'theme/utils';

import { Theme } from '../../theme';
Expand All @@ -17,10 +17,12 @@ export type AvatarTextTokens = DotKeys<typeof avatarText>;

export const getAvatarTokens = (
theme: Theme
): ((path: AvatarTokens, fn?: (val: string) => any) => string) => {
): ((path: AvatarTokens, fn?: (val: string) => any) => any) => {
panvourtsis marked this conversation as resolved.
Show resolved Hide resolved
return getComponentTokens(avatar, theme);
};

export const getAvatarTextTokens = (): ((path: DotKeys<typeof avatarText>) => string) => {
return parseCompositionToken(avatarText);
export const getAvatarTextTokens = (
theme: Theme
): ((path: DotKeys<typeof avatarText>) => any) => {
panvourtsis marked this conversation as resolved.
Show resolved Hide resolved
return getComponentTokens(avatarText, theme);
};
57 changes: 38 additions & 19 deletions src/components/Avatar/__snapshots__/Avatar.stories.storyshot
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar Playground 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.625rem;
font-family: Roboto;
font-weight: 500;
line-height: 0.875rem;
font-size: 0.625rem;
letter-spacing: 0.00625rem;
}

Expand Down Expand Up @@ -229,9 +230,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with icon 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.625rem;
font-family: Roboto;
font-weight: 500;
line-height: 0.875rem;
font-size: 0.625rem;
letter-spacing: 0.00625rem;
}

Expand Down Expand Up @@ -300,9 +302,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with icon 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.75rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.125rem;
font-size: 0.75rem;
letter-spacing: 0.015625rem;
}

Expand Down Expand Up @@ -355,9 +358,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with icon 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.875rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.25rem;
font-size: 0.875rem;
letter-spacing: 0.015625rem;
}

Expand Down Expand Up @@ -410,9 +414,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with icon 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 1rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.375rem;
font-size: 1rem;
letter-spacing: 0.00625rem;
}

Expand Down Expand Up @@ -465,9 +470,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with icon 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 1.5rem;
font-family: Roboto;
font-weight: 500;
line-height: 2rem;
font-size: 1.5rem;
letter-spacing: 0rem;
}

Expand Down Expand Up @@ -520,9 +526,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with icon 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 2rem;
font-family: Roboto;
font-weight: 500;
line-height: 2.5rem;
font-size: 2rem;
letter-spacing: 0rem;
}

Expand Down Expand Up @@ -745,9 +752,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with letter 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.625rem;
font-family: Roboto;
font-weight: 500;
line-height: 0.875rem;
font-size: 0.625rem;
letter-spacing: 0.00625rem;
}

Expand Down Expand Up @@ -790,9 +798,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with letter 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.75rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.125rem;
font-size: 0.75rem;
letter-spacing: 0.015625rem;
}

Expand Down Expand Up @@ -835,9 +844,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with letter 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.875rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.25rem;
font-size: 0.875rem;
letter-spacing: 0.015625rem;
}

Expand Down Expand Up @@ -880,9 +890,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with letter 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 1rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.375rem;
font-size: 1rem;
letter-spacing: 0.00625rem;
}

Expand Down Expand Up @@ -925,9 +936,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with letter 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 1.5rem;
font-family: Roboto;
font-weight: 500;
line-height: 2rem;
font-size: 1.5rem;
letter-spacing: 0rem;
}

Expand Down Expand Up @@ -970,9 +982,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with letter 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 2rem;
font-family: Roboto;
font-weight: 500;
line-height: 2.5rem;
font-size: 2rem;
letter-spacing: 0rem;
}

Expand Down Expand Up @@ -1143,9 +1156,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with src 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.625rem;
font-family: Roboto;
font-weight: 500;
line-height: 0.875rem;
font-size: 0.625rem;
letter-spacing: 0.00625rem;
}

Expand Down Expand Up @@ -1188,9 +1202,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with src 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.75rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.125rem;
font-size: 0.75rem;
letter-spacing: 0.015625rem;
}

Expand Down Expand Up @@ -1233,9 +1248,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with src 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.875rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.25rem;
font-size: 0.875rem;
letter-spacing: 0.015625rem;
}

Expand Down Expand Up @@ -1278,9 +1294,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with src 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 1rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.375rem;
font-size: 1rem;
letter-spacing: 0.00625rem;
}

Expand Down Expand Up @@ -1323,9 +1340,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with src 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 1.5rem;
font-family: Roboto;
font-weight: 500;
line-height: 2rem;
font-size: 1.5rem;
letter-spacing: 0rem;
}

Expand Down Expand Up @@ -1368,9 +1386,10 @@ exports[`Storyshots Design System/Avatar/Avatar Avatar with src 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 2rem;
font-family: Roboto;
font-weight: 500;
line-height: 2.5rem;
font-size: 2rem;
letter-spacing: 0rem;
}

Expand Down
18 changes: 12 additions & 6 deletions src/components/Avatar/__snapshots__/AvatarStack.stories.storyshot
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ exports[`Storyshots Design System/Avatar/AvatarStack Avatar Stack 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.625rem;
font-family: Roboto;
font-weight: 500;
line-height: 0.875rem;
font-size: 0.625rem;
letter-spacing: 0.00625rem;
}

Expand Down Expand Up @@ -166,9 +167,10 @@ exports[`Storyshots Design System/Avatar/AvatarStack Avatar Stack 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.75rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.125rem;
font-size: 0.75rem;
letter-spacing: 0.015625rem;
}

Expand Down Expand Up @@ -250,9 +252,10 @@ exports[`Storyshots Design System/Avatar/AvatarStack Avatar Stack 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 0.875rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.25rem;
font-size: 0.875rem;
letter-spacing: 0.015625rem;
}

Expand Down Expand Up @@ -355,9 +358,10 @@ exports[`Storyshots Design System/Avatar/AvatarStack Avatar Stack 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 1rem;
font-family: Roboto;
font-weight: 500;
line-height: 1.375rem;
font-size: 1rem;
letter-spacing: 0.00625rem;
}

Expand Down Expand Up @@ -439,9 +443,10 @@ exports[`Storyshots Design System/Avatar/AvatarStack Avatar Stack 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 1.5rem;
font-family: Roboto;
font-weight: 500;
line-height: 2rem;
font-size: 1.5rem;
letter-spacing: 0rem;
}

Expand Down Expand Up @@ -528,9 +533,10 @@ exports[`Storyshots Design System/Avatar/AvatarStack Avatar Stack 1`] = `
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
font-size: 2rem;
font-family: Roboto;
font-weight: 500;
line-height: 2.5rem;
font-size: 2rem;
letter-spacing: 0rem;
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/Button/Button.tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export type IconButtonTokens = DotKeys<typeof iconButton>;

export const getButtonTokens = (
theme: Theme
): ((path: ButtonTokens, fn?: (val: string) => any) => string) => {
): ((path: ButtonTokens, fn?: (val: string) => any) => any) => {
panvourtsis marked this conversation as resolved.
Show resolved Hide resolved
return getComponentTokens(button, theme);
};

export const getTextButtonTokens = (
theme: Theme
): ((path: TextButtonTokens, fn?: (val: string) => any) => string) => {
): ((path: TextButtonTokens, fn?: (val: string) => any) => any) => {
return getComponentTokens(textButton, theme);
};

export const getIconButtonTokens = (
theme: Theme
): ((path: IconButtonTokens, fn?: (val: string) => any) => string) => {
): ((path: IconButtonTokens, fn?: (val: string) => any) => any) => {
return getComponentTokens(iconButton, theme);
};
4 changes: 2 additions & 2 deletions src/components/ButtonBase/ButtonBase.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getIconButtonTokens,
getTextButtonTokens,
} from '../Button/Button.tokens';
import { label02 } from '../Typography/Typography.config.styles';
import { generateStylesFromTokens } from 'components/Typography/utils';

export const buttonWrapperStyle = ({
isBlock,
Expand Down Expand Up @@ -73,7 +73,7 @@ export const buttonBaseStyle =
: {};

return css`
${label02(theme)};
${generateStylesFromTokens(tokens('text.normal'))};
${baseButtonStyles};
${loadingStyles};
${sx?.container};
Expand Down
Loading
Loading