-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4166 from grommet/design-tokens-alpha
Add design tokens alpha
- Loading branch information
Showing
202 changed files
with
49,539 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ name: Sync tokens to Figma | |
on: | ||
push: | ||
branches: | ||
- design-tokens | ||
- master | ||
paths: | ||
- design-tokens/** | ||
|
||
jobs: | ||
sync-tokens-to-figma: | ||
|
@@ -11,7 +13,7 @@ jobs: | |
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18.16.0' | ||
node-version: '18.18.0' | ||
|
||
- name: Set NPM version | ||
run: npm install -g [email protected] | ||
|
@@ -20,12 +22,14 @@ jobs: | |
uses: actions/checkout@v3 | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
run: yarn install | ||
working-directory: design-tokens | ||
|
||
- name: Sync tokens to Figma file | ||
run: npm run sync-tokens-to-figma | ||
run: yarn sync-tokens-to-figma | ||
working-directory: design-tokens | ||
env: | ||
FILE_KEY: ${{ secrets.GH_ACTION_FIGMA_FILE_KEY }} | ||
FILE_KEY_PRIMITIVE: ${{ secrets.GH_ACTION_FIGMA_FILE_KEY_PRIMITIVE }} | ||
FILE_KEY_SEMANTIC: ${{ secrets.GH_ACTION_FIGMA_FILE_KEY_SEMANTIC }} | ||
FILE_KEY_COMPONENT: ${{ secrets.GH_ACTION_FIGMA_FILE_KEY_COMPONENT }} | ||
PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_ACTION_VARIABLES_SYNC_FIGMA_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
name: Update design-tokens-alpha-stable | ||
name: Update design-tokens-stable | ||
on: | ||
push: | ||
branches: | ||
- design-tokens-alpha | ||
- master | ||
paths: | ||
- design-tokens/** | ||
|
||
jobs: | ||
update-design-tokens-alpha-stable: | ||
update-design-tokens-stable: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Node.js | ||
|
@@ -26,12 +28,20 @@ jobs: | |
- name: Build | ||
run: yarn build | ||
working-directory: design-tokens | ||
|
||
- name: Update design-tokens-alpha-stable | ||
- name: Update design-tokens-stable | ||
run: | | ||
git config --global user.name "Grommet Community Bot" | ||
git config --global user.email "[email protected]" | ||
yarn release-stable | ||
working-directory: design-tokens | ||
env: | ||
GH_TOKEN: ${{ secrets.GH_ACTION_ACCESS_TOKEN }} | ||
# If stable is successfully update, push the same updates to Figma | ||
- name: Sync tokens to Figma file | ||
run: yarn sync-tokens-to-figma | ||
working-directory: design-tokens | ||
env: | ||
FILE_KEY_PRIMITIVE: ${{ secrets.GH_ACTION_FIGMA_FILE_KEY_PRIMITIVE }} | ||
FILE_KEY_SEMANTIC: ${{ secrets.GH_ACTION_FIGMA_FILE_KEY_SEMANTIC }} | ||
FILE_KEY_COMPONENT: ${{ secrets.GH_ACTION_FIGMA_FILE_KEY_COMPONENT }} | ||
PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_ACTION_VARIABLES_SYNC_FIGMA_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:react-hooks/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# HPE Design Tokens Manager | ||
|
||
This is a tool to manage hpe-design-tokens. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>HPE Design Token Manager</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "design-tokens-manager", | ||
"private": true, | ||
"authors": [ | ||
"Taylor Seamans" | ||
], | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"design-tokens": "*", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"styled-components": "5.3.11" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.66", | ||
"@types/react-dom": "^18.2.22", | ||
"@typescript-eslint/eslint-plugin": "^7.2.0", | ||
"@typescript-eslint/parser": "^7.2.0", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.4.6", | ||
"typescript": "^5.2.2", | ||
"vite": "^5.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* /index.html 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom'; | ||
import { Grommet, Header, Button, Box, Text } from 'grommet'; | ||
import { hpe } from 'grommet-theme-hpe'; | ||
import { Github, Moon, Sun } from 'grommet-icons'; | ||
import { Visualizer } from './routes/Visualizer'; | ||
// import { Builder } from './routes/Builder'; | ||
import { Docs } from './routes/Docs'; | ||
|
||
function App() { | ||
const [darkMode, setDarkMode] = useState( | ||
localStorage.getItem('darkMode') === 'true' || false, | ||
); | ||
useEffect(() => { | ||
if (darkMode) localStorage.setItem('darkMode', 'true'); | ||
else localStorage.setItem('darkMode', 'false'); | ||
}, [darkMode]); | ||
|
||
return ( | ||
<Grommet | ||
background="background-back" | ||
theme={hpe} | ||
themeMode={darkMode ? 'dark' : 'light'} | ||
full="min" | ||
> | ||
<BrowserRouter> | ||
<Header | ||
background="background-front" | ||
pad={{ vertical: 'small', horizontal: 'medium' }} | ||
border={{ side: 'bottom', color: 'border-weak' }} | ||
> | ||
<Button as={Link} to="/"> | ||
<Text weight={500} color="text-strong"> | ||
HPE Design Tokens Manager | ||
</Text> | ||
</Button> | ||
<Box direction="row" gap="xsmall"> | ||
<Button as={Link} to="/visualizer" label="Token Visualizer" /> | ||
{/* <Button as={Link} to="/builder" label="Token builder" /> */} | ||
<Button | ||
icon={<Github />} | ||
href="https://github.com/grommet/hpe-design-system/tree/design-tokens-alpha/design-tokens/tokens" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
tip="View tokens in Github" | ||
/> | ||
<Button | ||
icon={darkMode ? <Moon /> : <Sun />} | ||
onClick={() => setDarkMode(!darkMode)} | ||
tip={`Swith to ${darkMode ? 'light' : 'dark'} mode`} | ||
/> | ||
</Box> | ||
</Header> | ||
<Routes> | ||
<Route path="/" element={<Docs />} /> | ||
{/* <Route path="/builder" element={<Builder />} /> */} | ||
<Route path="/visualizer" element={<Visualizer />} /> | ||
</Routes> | ||
</BrowserRouter> | ||
</Grommet> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
export const buildTokenTree = tokens => { | ||
const tree = {}; | ||
|
||
Object.keys(tokens).forEach(collection => { | ||
let mode = collection; | ||
if ( | ||
collection === 'base' || | ||
collection === 'components' || | ||
collection === 'global' | ||
) { | ||
mode = 'default'; | ||
} else if (collection.includes('elevation')) | ||
mode = collection.replace('elevation', ''); | ||
|
||
const flat = Object.fromEntries( | ||
Object.keys(tokens[collection]).map(token => [ | ||
token, | ||
tokens[collection][token], | ||
]), | ||
); | ||
if (!(mode in tree)) tree[mode] = {}; | ||
tree[mode] = { ...tree[mode], ...flat }; | ||
}); | ||
|
||
Object.keys(tree).forEach(mode => { | ||
Object.keys(tree[mode]).forEach(key => { | ||
// if it's a reference, add it to the "usedBy" for the referenced token | ||
const value = tree[mode][key].original.value; | ||
if (/^{.*}$/.test(value)) { | ||
const token = value.slice(1, -1); | ||
// for color tokens, add it to the used by for "light" and "dark" modes | ||
// for dimension tokens, addit to the used by for "large" and "small" | ||
// otherwise, mode is "default" | ||
const referenceModes = []; | ||
if (mode === 'default') { | ||
if (token.includes('component')) referenceModes.push('default'); | ||
if (tree[mode][key].$type === 'color') | ||
referenceModes.push(...['light', 'dark']); | ||
else if (tree[mode][key].$type === 'number') | ||
referenceModes.push(...['large', 'small']); | ||
} else { | ||
referenceModes.push(tree[mode][token] ? mode : 'default'); | ||
} | ||
referenceModes.forEach(referenceMode => { | ||
// if this is the first reference, create `usedBy` | ||
const reference = tree[referenceMode][`hpe.${token}`]; | ||
if (reference) { | ||
if (!('usedBy' in reference)) { | ||
reference.usedBy = [ | ||
{ | ||
name: key, | ||
mode, | ||
}, | ||
]; | ||
} else if ( | ||
!reference.usedBy.find( | ||
ref => ref.name === key && ref.mode === mode, | ||
) | ||
) { | ||
reference.usedBy.push({ | ||
name: key, | ||
mode, | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
return tree; | ||
}; |
Oops, something went wrong.