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

feat(plasma-themes): Add fallback tokens for plasma-themes #1355

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions packages/plasma-b2c/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/plasma-b2c/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@salutejs/plasma-core": "1.166.0",
"@salutejs/plasma-hope": "1.292.0",
"@salutejs/plasma-new-hope": "0.121.1-dev.0",
"@salutejs/plasma-themes": "0.13.0",
"@salutejs/plasma-tokens-b2c": "0.51.0",
"@salutejs/plasma-tokens-web": "1.56.0",
"@salutejs/plasma-typo": "0.40.0"
Expand Down Expand Up @@ -107,4 +108,4 @@
"react"
],
"sideEffects": false
}
}
1 change: 1 addition & 0 deletions packages/plasma-tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"access": "public"
},
"files": [
"css",
"colors",
"brands",
"es",
Expand Down
11 changes: 11 additions & 0 deletions packages/plasma-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/plasma-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@salutejs/plasma-core": "1.166.0",
"@salutejs/plasma-hope": "1.292.0",
"@salutejs/plasma-new-hope": "0.121.1-dev.0",
"@salutejs/plasma-themes": "0.13.0",
"@salutejs/plasma-tokens-b2b": "1.41.0",
"@salutejs/plasma-tokens-b2c": "0.51.0",
"@salutejs/plasma-tokens-web": "1.56.0",
Expand Down Expand Up @@ -110,4 +111,4 @@
"Fanil Zubairov"
],
"sideEffects": false
}
}
12 changes: 9 additions & 3 deletions packages/themes/core-themes/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
generateThemes,
generateTokens,
} from './generators';
import { getMetaGrouped, readTheme } from './utils';
import { getMetaGrouped, readTheme, fallbackCreateColorTokensWrapper } from './utils';

export const generate = async (themes: ThemeRequest[]) => {
const themeDir = 'src';
Expand All @@ -29,8 +29,14 @@ export const generate = async (themes: ThemeRequest[]) => {
const { meta, variations } = themeSource;
const metaGrouped = getMetaGrouped(themeSource.meta);

const colorCSSVariables = createColorTokens(variations.color, metaGrouped.color);
const colorJSVariables = createColorTokens(variations.color, metaGrouped.color, isJS);
// TODO: Использовать createColorTokens: https://github.com/salute-developers/plasma/issues/1363
const colorCSSVariables = fallbackCreateColorTokensWrapper(theme.name, variations.color, metaGrouped.color);
const colorJSVariables = fallbackCreateColorTokensWrapper(
theme.name,
variations.color,
metaGrouped.color,
isJS,
);

const gradientCSSVariables = createGradientTokens(variations.gradient, metaGrouped.gradient);
const gradientJSVariables = createGradientTokens(variations.gradient, metaGrouped.gradient, isJS);
Expand Down
74 changes: 74 additions & 0 deletions packages/themes/core-themes/src/utils/fallbackTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// TODO: Убрать использование файла: https://github.com/salute-developers/plasma/issues/1363

import { createColorTokens } from '../creators';
import { TokenType } from '../types';

import { camelToKebab } from './other';

export const deprecatedColorTokenOnActualToken: Record<string, string> = {
denivladislav marked this conversation as resolved.
Show resolved Hide resolved
whitePrimary: 'onDarkTextPrimary',
whiteSecondary: 'onDarkTextSecondary',
whiteTertiary: 'onDarkTextTertiary',
blackPrimary: 'onLightTextPrimary',
blackSecondary: 'onLightTextSecondary',
blackTertiary: 'onLightTextTertiary',
buttonBlack: 'onLightSurfaceSolidDefault',
buttonBlackSecondary: 'onLightSurfaceTransparentSecondary',
buttonWhite: 'onDarkSurfaceSolidDefault',
buttonWhiteSecondary: 'onDarkSurfaceTransparentSecondary',
text: 'textPrimary',
primary: 'textPrimary',
secondary: 'textSecondary',
tertiary: 'textTertiary',
paragraph: 'textParagraph',
background: 'backgroundPrimary',
accent: 'textAccent',
success: 'textPositive',
warning: 'textWarning',
critical: 'textNegative',
overlay: 'overlaySoft',
surfaceLiquid01: 'surfaceTransparentPrimary',
surfaceLiquid02: 'surfaceTransparentSecondary',
surfaceLiquid03: 'surfaceTransparentTertiary',
surfaceSolid01: 'surfaceSolidPrimary',
surfaceSolid02: 'surfaceSolidSecondary',
surfaceSolid03: 'surfaceSolidTertiary',
surfaceCard: 'surfaceTransparentCard',
buttonSecondary: 'surfaceTransparentSecondary',
buttonAccent: 'textAccent',
buttonSuccess: 'surfacePositive',
buttonWarning: 'surfaceWarning',
buttonCritical: 'surfaceNegative',
};

export const getFallbackTokens = (isJS?: boolean) => {
const legacyPrefix = 'plasmaColors';

return Object.entries(deprecatedColorTokenOnActualToken)
.map(([oldName, actualName]) => {
const oldVarName = `--${camelToKebab(legacyPrefix)}-${camelToKebab(oldName)}`;
const actualVarName = `--${camelToKebab(actualName)}`;

if (isJS) {
return `/** @deprecated instead use ${actualName} */\nexport const ${oldName} = 'var(${oldVarName}, var(${actualVarName}))';\n`;
}

return ` ${oldVarName}: var(${actualVarName});`;
})
.join('\n');
};

export const fallbackCreateColorTokensWrapper = (name: string, color: any, tokens?: Array<TokenType>, isJS = false) => {
const colorVariables = createColorTokens(color, tokens, isJS);

if (name === 'plasma_web' || name === 'plasma_b2c') {
const fallbackTokens = getFallbackTokens(isJS);

return {
dark: `${colorVariables.dark}\n${fallbackTokens}`,
light: `${colorVariables.light}\n${fallbackTokens}`,
};
}

return colorVariables;
};
1 change: 1 addition & 0 deletions packages/themes/core-themes/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './meta';
export * from './theme';
export * from './other';
export * from './fallbackTokens';
2 changes: 2 additions & 0 deletions packages/themes/core-themes/src/utils/other.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const kebabToCamel = (str: string) =>
str.replace(/-([a-z])/g, (_, group) => group.toUpperCase()).replace(/^./, (char) => char.toLowerCase());

export const camelToKebab = (str: string) => str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
66 changes: 66 additions & 0 deletions packages/themes/plasma-themes/src/css/plasma_b2c.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,39 @@
--on-light-overlay-blur: #F9F9F947;
color: var(--text-primary);
background-color: var(--background-primary);
--plasma-colors-white-primary: var(--on-dark-text-primary);
--plasma-colors-white-secondary: var(--on-dark-text-secondary);
--plasma-colors-white-tertiary: var(--on-dark-text-tertiary);
--plasma-colors-black-primary: var(--on-light-text-primary);
--plasma-colors-black-secondary: var(--on-light-text-secondary);
--plasma-colors-black-tertiary: var(--on-light-text-tertiary);
--plasma-colors-button-black: var(--on-light-surface-solid-default);
--plasma-colors-button-black-secondary: var(--on-light-surface-transparent-secondary);
--plasma-colors-button-white: var(--on-dark-surface-solid-default);
--plasma-colors-button-white-secondary: var(--on-dark-surface-transparent-secondary);
--plasma-colors-text: var(--text-primary);
--plasma-colors-primary: var(--text-primary);
--plasma-colors-secondary: var(--text-secondary);
--plasma-colors-tertiary: var(--text-tertiary);
--plasma-colors-paragraph: var(--text-paragraph);
--plasma-colors-background: var(--background-primary);
--plasma-colors-accent: var(--text-accent);
--plasma-colors-success: var(--text-positive);
--plasma-colors-warning: var(--text-warning);
--plasma-colors-critical: var(--text-negative);
--plasma-colors-overlay: var(--overlay-soft);
--plasma-colors-surface-liquid01: var(--surface-transparent-primary);
--plasma-colors-surface-liquid02: var(--surface-transparent-secondary);
--plasma-colors-surface-liquid03: var(--surface-transparent-tertiary);
--plasma-colors-surface-solid01: var(--surface-solid-primary);
--plasma-colors-surface-solid02: var(--surface-solid-secondary);
--plasma-colors-surface-solid03: var(--surface-solid-tertiary);
--plasma-colors-surface-card: var(--surface-transparent-card);
--plasma-colors-button-secondary: var(--surface-transparent-secondary);
--plasma-colors-button-accent: var(--text-accent);
--plasma-colors-button-success: var(--surface-positive);
--plasma-colors-button-warning: var(--surface-warning);
--plasma-colors-button-critical: var(--surface-negative);
}

.dark {
Expand Down Expand Up @@ -527,6 +560,39 @@
--on-light-overlay-blur: #F9F9F947;
color: var(--text-primary);
background-color: var(--background-primary);
--plasma-colors-white-primary: var(--on-dark-text-primary);
--plasma-colors-white-secondary: var(--on-dark-text-secondary);
--plasma-colors-white-tertiary: var(--on-dark-text-tertiary);
--plasma-colors-black-primary: var(--on-light-text-primary);
--plasma-colors-black-secondary: var(--on-light-text-secondary);
--plasma-colors-black-tertiary: var(--on-light-text-tertiary);
--plasma-colors-button-black: var(--on-light-surface-solid-default);
--plasma-colors-button-black-secondary: var(--on-light-surface-transparent-secondary);
--plasma-colors-button-white: var(--on-dark-surface-solid-default);
--plasma-colors-button-white-secondary: var(--on-dark-surface-transparent-secondary);
--plasma-colors-text: var(--text-primary);
--plasma-colors-primary: var(--text-primary);
--plasma-colors-secondary: var(--text-secondary);
--plasma-colors-tertiary: var(--text-tertiary);
--plasma-colors-paragraph: var(--text-paragraph);
--plasma-colors-background: var(--background-primary);
--plasma-colors-accent: var(--text-accent);
--plasma-colors-success: var(--text-positive);
--plasma-colors-warning: var(--text-warning);
--plasma-colors-critical: var(--text-negative);
--plasma-colors-overlay: var(--overlay-soft);
--plasma-colors-surface-liquid01: var(--surface-transparent-primary);
--plasma-colors-surface-liquid02: var(--surface-transparent-secondary);
--plasma-colors-surface-liquid03: var(--surface-transparent-tertiary);
--plasma-colors-surface-solid01: var(--surface-solid-primary);
--plasma-colors-surface-solid02: var(--surface-solid-secondary);
--plasma-colors-surface-solid03: var(--surface-solid-tertiary);
--plasma-colors-surface-card: var(--surface-transparent-card);
--plasma-colors-button-secondary: var(--surface-transparent-secondary);
--plasma-colors-button-accent: var(--text-accent);
--plasma-colors-button-success: var(--surface-positive);
--plasma-colors-button-warning: var(--surface-warning);
--plasma-colors-button-critical: var(--surface-negative);
}

.light {
Expand Down
33 changes: 33 additions & 0 deletions packages/themes/plasma-themes/src/css/plasma_b2c__dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,39 @@
--on-light-overlay-blur: #F9F9F947;
color: var(--text-primary);
background-color: var(--background-primary);
--plasma-colors-white-primary: var(--on-dark-text-primary);
--plasma-colors-white-secondary: var(--on-dark-text-secondary);
--plasma-colors-white-tertiary: var(--on-dark-text-tertiary);
--plasma-colors-black-primary: var(--on-light-text-primary);
--plasma-colors-black-secondary: var(--on-light-text-secondary);
--plasma-colors-black-tertiary: var(--on-light-text-tertiary);
--plasma-colors-button-black: var(--on-light-surface-solid-default);
--plasma-colors-button-black-secondary: var(--on-light-surface-transparent-secondary);
--plasma-colors-button-white: var(--on-dark-surface-solid-default);
--plasma-colors-button-white-secondary: var(--on-dark-surface-transparent-secondary);
--plasma-colors-text: var(--text-primary);
--plasma-colors-primary: var(--text-primary);
--plasma-colors-secondary: var(--text-secondary);
--plasma-colors-tertiary: var(--text-tertiary);
--plasma-colors-paragraph: var(--text-paragraph);
--plasma-colors-background: var(--background-primary);
--plasma-colors-accent: var(--text-accent);
--plasma-colors-success: var(--text-positive);
--plasma-colors-warning: var(--text-warning);
--plasma-colors-critical: var(--text-negative);
--plasma-colors-overlay: var(--overlay-soft);
--plasma-colors-surface-liquid01: var(--surface-transparent-primary);
--plasma-colors-surface-liquid02: var(--surface-transparent-secondary);
--plasma-colors-surface-liquid03: var(--surface-transparent-tertiary);
--plasma-colors-surface-solid01: var(--surface-solid-primary);
--plasma-colors-surface-solid02: var(--surface-solid-secondary);
--plasma-colors-surface-solid03: var(--surface-solid-tertiary);
--plasma-colors-surface-card: var(--surface-transparent-card);
--plasma-colors-button-secondary: var(--surface-transparent-secondary);
--plasma-colors-button-accent: var(--text-accent);
--plasma-colors-button-success: var(--surface-positive);
--plasma-colors-button-warning: var(--surface-warning);
--plasma-colors-button-critical: var(--surface-negative);
}

:root {
Expand Down
33 changes: 33 additions & 0 deletions packages/themes/plasma-themes/src/css/plasma_b2c__light.css
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,39 @@
--on-light-overlay-blur: #F9F9F947;
color: var(--text-primary);
background-color: var(--background-primary);
--plasma-colors-white-primary: var(--on-dark-text-primary);
--plasma-colors-white-secondary: var(--on-dark-text-secondary);
--plasma-colors-white-tertiary: var(--on-dark-text-tertiary);
--plasma-colors-black-primary: var(--on-light-text-primary);
--plasma-colors-black-secondary: var(--on-light-text-secondary);
--plasma-colors-black-tertiary: var(--on-light-text-tertiary);
--plasma-colors-button-black: var(--on-light-surface-solid-default);
--plasma-colors-button-black-secondary: var(--on-light-surface-transparent-secondary);
--plasma-colors-button-white: var(--on-dark-surface-solid-default);
--plasma-colors-button-white-secondary: var(--on-dark-surface-transparent-secondary);
--plasma-colors-text: var(--text-primary);
--plasma-colors-primary: var(--text-primary);
--plasma-colors-secondary: var(--text-secondary);
--plasma-colors-tertiary: var(--text-tertiary);
--plasma-colors-paragraph: var(--text-paragraph);
--plasma-colors-background: var(--background-primary);
--plasma-colors-accent: var(--text-accent);
--plasma-colors-success: var(--text-positive);
--plasma-colors-warning: var(--text-warning);
--plasma-colors-critical: var(--text-negative);
--plasma-colors-overlay: var(--overlay-soft);
--plasma-colors-surface-liquid01: var(--surface-transparent-primary);
--plasma-colors-surface-liquid02: var(--surface-transparent-secondary);
--plasma-colors-surface-liquid03: var(--surface-transparent-tertiary);
--plasma-colors-surface-solid01: var(--surface-solid-primary);
--plasma-colors-surface-solid02: var(--surface-solid-secondary);
--plasma-colors-surface-solid03: var(--surface-solid-tertiary);
--plasma-colors-surface-card: var(--surface-transparent-card);
--plasma-colors-button-secondary: var(--surface-transparent-secondary);
--plasma-colors-button-accent: var(--text-accent);
--plasma-colors-button-success: var(--surface-positive);
--plasma-colors-button-warning: var(--surface-warning);
--plasma-colors-button-critical: var(--surface-negative);
}

:root {
Expand Down
Loading
Loading