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

chore(docs): rebuild table from all-tokens json #72

Merged
merged 25 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
27bf3ef
chore(docs): rebuild table from all-tokens json
evwilkin Jun 14, 2024
aa4fb1a
chore(table): pass in tokenJson to TokenTable
evwilkin Jun 14, 2024
6ea0390
chore(docs): multiple theme values & token chains
evwilkin Jun 14, 2024
b0784c3
chore(docs): adding more token data to view
evwilkin Jun 14, 2024
69d06c0
chore(docs): build out new tokens table implementation
evwilkin Jun 18, 2024
8159348
merge main
evwilkin Jul 5, 2024
6b63daf
merge origin changes
evwilkin Jul 5, 2024
42dc548
chore(token-docs): expand correctly, add swatches, dark-only expand fix
evwilkin Jul 9, 2024
037f17b
design feedback - simplify rows
evwilkin Jul 11, 2024
6dd16e2
chore(docs): token chains by theme in grid
evwilkin Jul 14, 2024
b71c4ae
fix spacing between tables
evwilkin Jul 14, 2024
c11293c
cleanup & comment code
evwilkin Jul 14, 2024
43b3389
add category select
evwilkin Jul 15, 2024
7b1dc2d
remove extra commas in select
evwilkin Jul 15, 2024
950c490
chore(docs): remove unused files, rename for clarity
evwilkin Aug 5, 2024
e401748
chore(docs): update readme, delete unused files
evwilkin Aug 8, 2024
ea09c51
chore(docs): fixed search and categories select
evwilkin Aug 9, 2024
c60c1b8
chore(docs): remove unused config files
evwilkin Aug 9, 2024
82b2515
add toc jumplinks
evwilkin Aug 9, 2024
9935966
remove jumplinks, increase width at xl breakpoints
evwilkin Aug 9, 2024
b2d0f83
Discard changes to packages/module/build/css/tokens-charts-dark.scss
evwilkin Aug 9, 2024
2beb3c4
Discard changes to packages/module/build/css/tokens-charts.scss
evwilkin Aug 9, 2024
3b3f622
Discard changes to packages/module/build/css/tokens-dark.scss
evwilkin Aug 9, 2024
8e46302
Discard changes to packages/module/build/css/tokens-default.scss
evwilkin Aug 9, 2024
f99a914
Discard changes to packages/module/build/css/tokens-palette.scss
evwilkin Aug 9, 2024
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ We are temporarily pushing the built SCSS files to the repo for ease of access.
# Docs build

Whenever `yarn build:docs` is executed:
- the [build-js-for-docs.js](https://github.com/patternfly/design-tokens/blob/main/packages/module/build-js-for-docs.js) script is run to turn the scss files into a javascript object.
- The javascript object is stored in the [scssAsJson.json](https://github.com/patternfly/design-tokens/blob/main/packages/module/patternfly-docs/scssAsJson.json) file.
- The code for generating the table containing all tokens is the [tokensTable.js](https://github.com/patternfly/design-tokens/blob/main/packages/module/patternfly-docs/content/tokensTable.js), which consumes the javascript object from scssAsJson.json as data.
- Ultimately, the markdown file which is rendering the docs is [all-patternfly-tokens.md](https://github.com/patternfly/design-tokens/blob/main/packages/module/patternfly-docs/content/all-patternfly-tokens.md). This markdown file imports the tokensTable.js.
- the [build:scss](https://github.com/patternfly/design-tokens/blob/main/packages/module/build.js) script is run which transforms tokens pulled from Figma (split into separate token json files in the `/tokens` directory) into combined default and dark theme files (in addition to the .scss files within `build/css`).
- The two new json files (`token-layers-default.json` and `token-layers-dark.json`) are stored in the [patternfly-docs/content](https://github.com/patternfly/design-tokens/blob/main/packages/module/patternfly-docs/content) directory.
- The code for generating the table containing all tokens is the [tokensTable.js](https://github.com/patternfly/design-tokens/blob/main/packages/module/patternfly-docs/content/tokensTable.js), which combines the default and dark theme json tokens into one object and consumes it as data.
- Ultimately, the markdown file which is rendering the docs is [all-patternfly-tokens.md](https://github.com/patternfly/design-tokens/blob/main/packages/module/patternfly-docs/content/all-patternfly-tokens.md). This markdown file imports the tokensTable.js and takes the token theme files as props.

41 changes: 0 additions & 41 deletions packages/module/build-js-for-docs.js

This file was deleted.

60 changes: 57 additions & 3 deletions packages/module/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
const StyleDictionary = require('style-dictionary');
const config = require('./config.default.json'); // Adjust the path if necessary
const basePxFontSize = config.basePxFontSize || 16;
const getTokenLayer = ({ filePath }) => {
if (filePath.includes('semantic.json')) return ['semantic', 'colors'];
if (filePath.includes('semantic.dark.json')) return ['semantic', 'colors'];
if (filePath.includes('semantic.dimension.json')) return ['semantic', 'dimension'];
if (filePath.includes('semantic.motion.json')) return ['semantic', 'motion'];
if (filePath.includes('base.json')) return ['base', 'colors'];
if (filePath.includes('base.dark.json')) return ['base', 'colors'];
if (filePath.includes('base.dimension.json')) return ['base', 'dimension'];
if (filePath.includes('base.motion.json')) return ['base', 'motion'];
if (filePath.includes('chart')) return ['chart'];
if (filePath.includes('palette.color.json')) return ['palette'];
return ['palette'];
};
// returns subdirectory within 'tokens' directory (ex: default, dark, etc)
const getTheme = ({ filePath }) => /tokens\/([^\/]*)\//gm.exec(filePath)[1];

const build = (selector) => {
const { fileHeader, formattedVariables, sortByName } = StyleDictionary.formatHelpers;
Expand All @@ -25,6 +40,43 @@ const build = (selector) => {
}
});

StyleDictionary.registerFormat({
name: 'json/flat-categories',
formatter: function (dictionary) {
let tokens = {
semantic: {
colors: {},
dimension: {},
motion: {}
},
base: {
colors: {},
dimension: {},
motion: {}
},
palette: {},
chart: {}
};
dictionary.allTokens.map((token) => {
// determine token type based on tokens filepath
const theme = getTheme(token);
const layer = getTokenLayer(token);
let insertLayer = tokens;
while (layer.length) {
insertLayer = insertLayer[layer.shift()];
}
// assign each token object to token.name
insertLayer[token.name] = {};
insertLayer[token.name][theme] = token;
// attach references to build token chain
if (dictionary.usesReference(token.original.value)) {
token.references = dictionary.getReferences(token.original.value);
}
});
return JSON.stringify(tokens, null, 2);
}
});

// Register custom transforms
StyleDictionary.registerTransform({
name: 'patternfly/global/px',
Expand All @@ -39,9 +91,7 @@ const build = (selector) => {
name: 'patternfly/global/pxToRem',
type: 'value',
matcher: (token) =>
token.attributes.type === 'spacer' ||
token.attributes.item === 'size' ||
token.attributes.type === 'breakpoint',
token.attributes.type === 'spacer' || token.attributes.item === 'size' || token.attributes.type === 'breakpoint',
transformer: (token) => `${token.value / basePxFontSize}rem`
});

Expand Down Expand Up @@ -83,13 +133,17 @@ const build = (selector) => {
const paletteExtendedSD = StyleDictionary.extend(__dirname + '/config.palette-colors.json');
const chartsExtendedSD = StyleDictionary.extend(__dirname + '/config.charts.json');
const chartsDarkExtendedSD = StyleDictionary.extend(__dirname + '/config.charts.dark.json');
const layersSD = StyleDictionary.extend(__dirname + '/config.layers.json');
const layersDarkSD = StyleDictionary.extend(__dirname + '/config.layers.dark.json');

// Build all
defaultExtendedSD.buildAllPlatforms();
darkExtendedSD.buildAllPlatforms();
paletteExtendedSD.buildAllPlatforms();
chartsExtendedSD.buildAllPlatforms();
chartsDarkExtendedSD.buildAllPlatforms();
layersSD.buildAllPlatforms();
layersDarkSD.buildAllPlatforms();

console.log('\n============================');
console.log('\nBuild completed.');
Expand Down
20 changes: 20 additions & 0 deletions packages/module/config.layers.dark.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"include": ["tokens/default/*.json"],
"source": ["tokens/dark/*.json"],
"platforms": {
"json/default": {
"transformGroup": "patternfly/css",
"buildPath": "patternfly-docs/content/",
"prefix": "pf-t",
"files": [
{
"destination": "token-layers-dark.json",
"format": "json/flat-categories",
"options": {
"outputReferences": false
}
}
]
}
}
}
19 changes: 19 additions & 0 deletions packages/module/config.layers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"source": ["tokens/default/*.json"],
"platforms": {
"json/default": {
"transformGroup": "patternfly/css",
"buildPath": "patternfly-docs/content/",
"prefix": "pf-t",
"files": [
{
"destination": "token-layers-default.json",
"format": "json/flat-categories",
"options": {
"outputReferences": false
}
}
]
}
}
}
15 changes: 7 additions & 8 deletions packages/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
"scripts": {
"build": "yarn build:js-from-scss",
"build": "yarn build:scss",
"build:fed:packages": "node generate-fed-package-json.js",
"build:scss": "node ./cli.js",
"build:js-from-scss": "node ./build-js-for-docs.js",
"build:plugin": "webpack",
"clean": "rimraf dist",
"docs:develop": "pf-docs-framework start",
"docs:build": "yarn build:js-from-scss && pf-docs-framework build all --output public",
"docs:build": "yarn build:scss && pf-docs-framework build all --output public",
"docs:serve": "pf-docs-framework serve public --port 5000",
"docs:screenshots": "pf-docs-framework screenshots --urlPrefix http://localhost:5000",
"test:a11y": "patternfly-a11y --config patternfly-a11y.config",
Expand All @@ -32,7 +31,7 @@
"access": "public"
},
"dependencies": {
"@patternfly/react-core": "^6.0.0-alpha.36",
"@patternfly/react-core": "6.0.0-alpha.94",
"commander": "^12.0.0"
},
"peerDependencies": {
Expand All @@ -41,11 +40,11 @@
},
"devDependencies": {
"@figma/plugin-typings": "^1.95.0",
"@patternfly/documentation-framework": "6.0.0-alpha.12",
"@patternfly/patternfly": "6.0.0-alpha.91",
"@patternfly/documentation-framework": "^6.0.0-alpha.66",
"@patternfly/patternfly": "6.0.0-alpha.205",
"@patternfly/patternfly-a11y": "^4.3.1",
"@patternfly/react-code-editor": "6.0.0-alpha.36",
"@patternfly/react-table": "6.0.0-alpha.36",
"@patternfly/react-code-editor": "6.0.0-alpha.94",
"@patternfly/react-table": "6.0.0-alpha.95",
"css-loader": "^7.1.2",
"html-inline-script-webpack-plugin": "^3.2.1",
"html-webpack-plugin": "^5.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ section: tokens
id: All PatternFly tokens
---


import * as defaultTokens from './token-layers-default.json';
import * as darkTokens from './token-layers-dark.json';
import { TokensTable } from './tokensTable.js';

<TokensTable/>
<TokensTable tokenJson={{default: defaultTokens, dark: darkTokens}} />
Loading
Loading