Skip to content

Commit be634dc

Browse files
adamstankiewiczPKulkoRaccoonGang
authored andcommitted
feat: --output-references CLI arg, registers filters, updates CSS vars format (#3203)
* feat: --output-references CLI arg for build-tokens, registers filters, and updates CSS vars format * Exposes `--output-references` CLI argument for `build-tokens` command. Defaults to `true`. Ensures brand package output with the CLI includes references in build output out-of-the-box. * Registers filter(s) `isThemeVariant.{'light'}`, handling future theme variants when implemented (e.g., `isThemeVariant.dark`). * Migrates `createCustomCSSVariables` to use `formattedVariables` to rely on out-of-the-box CSS variable formatting. The formatter still supports token-specific overrides of `outputReferences`. If a token has modifications via `modify`, the modified base reference is not included in the output. * Updates custom fileHeader implementation, including a relative path to design tokens documentation. * Fixes bug with line-height tokens, switching their `$type` from `dimension` to `number` to resolve typography style regressions. * Updates typography tokens related to font size, font weight, and line-height for more consistent naming structure when taking into account mobile. * Updates `@mobile-type` SCSS mixin to support level-specific customization of mobile typography styles for display 1-4. * Renames `"description"` field in tokens to `"$description""` per the DTCG format. * Ensures the "Typography" foundations page properly previews the correct font size for regular "Body" text and includes the missing "HEADING LABEL" example. * Updates to "Colors" page in docs site: * Displays token name instead of CSS variable in the color swatch previews (see screenshot below). * Include `accent-a` and `accent-b` alongside other color names, rather than manually rendering `Swatch` for the accents. * Modifies the grid styles for color swatch preview to be more responsive. * Resolves `NaNpx` bug in `MeasuredItem` component on docs site, while computing the measurements to display for an element (e.g., font size). Instead, it renders an empty block while measurements are resolved. * Updates `CodeBlock` styles on docs site to add its border and background color only to the `LivePreview`, not the entire `CodeBlock` example. * Reduces whitespace on docs site homepage. * Simplifies columns on docs site header, ensuring `SiteTitle` is horizontally aligned in the center.
1 parent ea914e1 commit be634dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1006
-1375
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.PHONY: build
12
build:
23
rm -rf ./dist
34
tsc --project tsconfig.build.json

bin/paragon-scripts.js

+10
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,21 @@ const COMMANDS = {
8585
description: 'Include only source design tokens in the build.',
8686
defaultValue: false,
8787
},
88+
{
89+
name: '--output-references',
90+
description: 'Include references in the build output.',
91+
defaultValue: true,
92+
},
8893
{
8994
name: '-t, --themes',
9095
description: 'Specify themes to include in the token build.',
9196
defaultValue: 'light',
9297
},
98+
{
99+
name: '-v, --verbose',
100+
description: 'Enable verbose logging.',
101+
defaultValue: false,
102+
},
93103
],
94104
},
95105
'replace-variables': {

lib/build-tokens.js

+55-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const path = require('path');
22
const minimist = require('minimist');
3-
const { initializeStyleDictionary, createCustomCSSVariables, colorTransform } = require('../tokens/style-dictionary');
3+
const {
4+
initializeStyleDictionary,
5+
colorTransform,
6+
} = require('../tokens/style-dictionary');
47
const { createIndexCssFile } = require('../tokens/utils');
58

69
/**
@@ -13,24 +16,37 @@ const { createIndexCssFile } = require('../tokens/utils');
1316
* @param {string|string[]} [commandArgs.themes=['light']] - The themes (variants) for which to build tokens.
1417
*/
1518
async function buildTokensCommand(commandArgs) {
16-
const StyleDictionary = await initializeStyleDictionary();
17-
1819
const defaultParams = {
1920
themes: ['light'],
2021
'build-dir': './build/',
22+
'source-tokens-only': false,
23+
'output-references': true,
24+
verbose: false,
2125
};
2226

2327
const alias = {
2428
'build-dir': 'b',
2529
themes: 't',
30+
verbose: '-v',
2631
};
2732

2833
const {
2934
'build-dir': buildDir,
3035
source: tokensSource,
3136
'source-tokens-only': hasSourceTokensOnly,
37+
'output-references': outputReferences,
3238
themes,
33-
} = minimist(commandArgs, { alias, default: defaultParams, boolean: 'source-tokens-only' });
39+
verbose,
40+
} = minimist(
41+
commandArgs,
42+
{
43+
alias,
44+
default: defaultParams,
45+
boolean: ['source-tokens-only', 'output-references', 'verbose'],
46+
},
47+
);
48+
49+
const StyleDictionary = await initializeStyleDictionary({ themes });
3450

3551
const coreConfig = {
3652
include: [
@@ -43,33 +59,35 @@ async function buildTokensCommand(commandArgs) {
4359
platforms: {
4460
css: {
4561
prefix: 'pgn',
46-
transformGroup: 'css',
4762
// NOTE: buildPath must end with a slash
4863
buildPath: buildDir.slice(-1) === '/' ? buildDir : `${buildDir}/`,
64+
options: {
65+
fileHeader: 'customFileHeader',
66+
},
4967
files: [
5068
{
5169
format: 'css/custom-variables',
5270
destination: 'core/variables.css',
5371
filter: hasSourceTokensOnly ? 'isSource' : undefined,
5472
options: {
55-
outputReferences: !hasSourceTokensOnly,
73+
outputReferences,
5674
},
5775
},
5876
{
5977
format: 'css/custom-media-breakpoints',
6078
destination: 'core/custom-media-breakpoints.css',
6179
filter: hasSourceTokensOnly ? 'isSource' : undefined,
6280
options: {
63-
outputReferences: !hasSourceTokensOnly,
81+
outputReferences,
6482
},
6583
},
6684
],
6785
transforms: StyleDictionary.hooks.transformGroups.css.filter(item => item !== 'size/rem').concat('color/sass-color-functions', 'str-replace'),
68-
options: {
69-
fileHeader: 'customFileHeader',
70-
},
7186
},
7287
},
88+
log: {
89+
verbosity: verbose ? 'verbose' : 'default',
90+
},
7391
};
7492

7593
const getStyleDictionaryConfig = (themeVariant) => ({
@@ -91,45 +109,56 @@ async function buildTokensCommand(commandArgs) {
91109
transform: (token) => colorTransform(token, themeVariant),
92110
},
93111
},
94-
format: {
95-
'css/custom-variables': formatterArgs => createCustomCSSVariables({
96-
formatterArgs,
97-
themeVariant,
98-
}),
99-
},
100112
platforms: {
101113
css: {
102114
...coreConfig.platforms.css,
103115
files: [
104116
{
105117
format: 'css/custom-variables',
106118
destination: `themes/${themeVariant}/variables.css`,
107-
filter: hasSourceTokensOnly ? 'isSource' : undefined,
119+
filter: hasSourceTokensOnly
120+
? `isSource.${themeVariant}`
121+
: `isThemeVariant.${themeVariant}`,
108122
options: {
109-
outputReferences: !hasSourceTokensOnly,
123+
outputReferences,
110124
},
111125
},
112126
{
113127
format: 'css/utility-classes',
114128
destination: `themes/${themeVariant}/utility-classes.css`,
115129
filter: hasSourceTokensOnly ? 'isSource' : undefined,
116130
options: {
117-
outputReferences: !hasSourceTokensOnly,
131+
outputReferences,
118132
},
119133
},
120134
],
121135
},
122136
},
123137
});
124138

125-
new StyleDictionary(coreConfig).buildAllPlatforms();
126-
createIndexCssFile({ buildDir, isTheme: false });
139+
// Create list of style-dictionary configurations to build (core + theme variants)
140+
const configs = [
141+
{ config: coreConfig },
142+
...themes.map((themeVariant) => {
143+
const config = getStyleDictionaryConfig(themeVariant);
144+
return {
145+
config,
146+
themeVariant,
147+
};
148+
}),
149+
];
127150

128-
themes.forEach(async (themeVariant) => {
129-
const config = getStyleDictionaryConfig(themeVariant);
130-
new StyleDictionary(config).buildAllPlatforms();
131-
createIndexCssFile({ buildDir, isTheme: true, themeVariant });
132-
});
151+
// Build tokens for each configuration
152+
await Promise.all(configs.map(async ({ config, isThemeVariant, themeVariant }) => {
153+
const sd = new StyleDictionary(config);
154+
await sd.cleanAllPlatforms();
155+
await sd.buildAllPlatforms();
156+
createIndexCssFile({
157+
buildDir,
158+
isThemeVariant: !!isThemeVariant,
159+
themeVariant,
160+
});
161+
}));
133162
}
134163

135164
module.exports = buildTokensCommand;

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"prepare": "husky || true",
5353
"build-tokens": "./bin/paragon-scripts.js build-tokens --build-dir ./styles/css",
5454
"replace-variables-usage-with-css": "./bin/paragon-scripts.js replace-variables -p src -t usage",
55-
"replace-variables-definition-with-css": "./bin/paragon-scripts.js replace-variables -p src -t definition"
55+
"replace-variables-definition-with-css": "./bin/paragon-scripts.js replace-variables -p src -t definition",
56+
"cli:help": "./bin/paragon-scripts.js help"
5657
},
5758
"dependencies": {
5859
"@popperjs/core": "^2.11.4",
@@ -114,7 +115,7 @@
114115
"@babel/preset-typescript": "^7.16.7",
115116
"@edx/eslint-config": "^3.2.0",
116117
"@edx/stylelint-config-edx": "^2.3.0",
117-
"@edx/typescript-config": "^1.0.1",
118+
"@edx/typescript-config": "^1.1.0",
118119
"@formatjs/cli": "^5.0.2",
119120
"@semantic-release/changelog": "^6.0.1",
120121
"@semantic-release/git": "^10.0.1",

src/Form/_FormText.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.pgn__form-text {
2-
font-size: var(--pgn-typography-font-size-small-base);
2+
font-size: var(--pgn-typography-font-size-sm);
33
display: flex;
44
align-items: center;
55

src/PageBanner/index.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
min-height: 36px;
55
display: flex;
66
flex-wrap: nowrap;
7-
font-size: var(--pgn-typography-font-size-small-x);
7+
font-size: var(--pgn-typography-font-size-xs);
88
background-color: var(--pgn-page-baner-bg, inherit);
99
color: var(--pgn-page-baner-color, inherit);
1010

1111
@include media-breakpoint-up(md) {
12-
font-size: var(--pgn-typography-font-size-small-base);
12+
font-size: var(--pgn-typography-font-size-sm);
1313
}
1414
}
1515

src/ProgressBar/index.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@
8787
.pgn__progress-hint {
8888
box-sizing: border-box;
8989
padding: 0 var(--pgn-spacing-progress-bar-hint-annotation-gap);
90-
font-size: var(--pgn-typography-font-size-small-base);
90+
font-size: var(--pgn-typography-font-size-sm);
9191
}
9292
}

src/Stepper/index.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
}
5757

5858
.pgn__stepper-header-step-description {
59-
font-size: var(--pgn-typography-font-size-small-x);
59+
font-size: var(--pgn-typography-font-size-xs);
6060
}
6161

6262
&.pgn__stepper-header-step-active ~ .pgn__stepper-header-step {

src/Toast/index.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
padding: 0;
3232

3333
p {
34-
font-size: var(--pgn-typography-font-size-small-base);
34+
font-size: var(--pgn-typography-font-size-sm);
3535
margin: 0;
3636
padding-right: .75rem;
3737
}

styles/css/core/custom-media-breakpoints.css

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
/*
2-
* IMPORTANT: This file is the result of assembling design tokens.
3-
* Do not edit directly.
4-
* Generated on Tue, 27 Aug 2024 17:14:44 GMT
1+
/**
2+
* Do not edit directly, this file was auto-generated. while transforming design tokens.
3+
* See <root>/tokens/README.md for more details.
54
*/
65

7-
@custom-media --pgn-size-breakpoint-min-width-xs (min-width: 0rem);
6+
@custom-media --pgn-size-breakpoint-min-width-xs (min-width: 0);
87
@custom-media --pgn-size-breakpoint-max-width-xs (max-width: 576px);
98
@custom-media --pgn-size-breakpoint-min-width-sm (min-width: 576px);
109
@custom-media --pgn-size-breakpoint-max-width-sm (max-width: 768px);

0 commit comments

Comments
 (0)