-
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.
- Loading branch information
Showing
15 changed files
with
2,275 additions
and
2 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
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,30 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default { | ||
// other rules... | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
project: ['./tsconfig.json', './tsconfig.node.json'], | ||
tsconfigRootDir: __dirname, | ||
}, | ||
} | ||
``` | ||
|
||
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` | ||
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list |
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,36 @@ | ||
{ | ||
"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": "*", | ||
"grommet": "^2.37.0", | ||
"grommet-icons": "^4.12.1", | ||
"grommet-theme-hpe": "^5.4.0", | ||
"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,205 @@ | ||
import { useContext, useEffect, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { | ||
Grommet, | ||
Page, | ||
Data, | ||
PageContent, | ||
Header, | ||
Grid, | ||
Button, | ||
Box, | ||
Text, | ||
DataSearch, | ||
DataFilters, | ||
DataContext, | ||
DataSummary, | ||
Toolbar, | ||
} from 'grommet'; | ||
import { hpe } from 'grommet-theme-hpe'; | ||
import tokens from 'design-tokens/tree'; | ||
import { Github, LinkNext, Moon, Sun } from 'grommet-icons'; | ||
|
||
const tokensArr = []; | ||
Object.keys(tokens).forEach(mode => { | ||
Object.keys(tokens[mode]).forEach(token => | ||
tokensArr.push({ | ||
name: token, | ||
mode: mode, | ||
...tokens[mode][token], | ||
}), | ||
); | ||
}); | ||
|
||
const StyledBox = styled(Box)` | ||
&:focus:not(:focus-visible) { | ||
box-shadow: none; | ||
} | ||
`; | ||
|
||
const TokenValue = ({ value }) => { | ||
let content; | ||
if (typeof value === 'string' || typeof value === 'number') content = value; | ||
if (Array.isArray(value)) content = `[${value.join(', ')}]`; | ||
|
||
return <Text size="small">{content}</Text>; | ||
}; | ||
const Tag = ({ name, badge, value, ...rest }) => ( | ||
<StyledBox | ||
gap="xsmall" | ||
pad={{ horizontal: 'small', vertical: 'xsmall' }} | ||
border | ||
round="xsmall" | ||
flex={false} | ||
{...rest} | ||
> | ||
<Box direction="row" gap="small" align="center"> | ||
<Text weight={500} color="text-strong"> | ||
{name} | ||
</Text> | ||
<Box | ||
background="background-contrast" | ||
round="xsmall" | ||
pad={{ horizontal: 'xsmall' }} | ||
> | ||
<Text size="small" weight={500}> | ||
{badge} | ||
</Text> | ||
</Box> | ||
</Box> | ||
{value ? <TokenValue value={value} /> : undefined} | ||
</StyledBox> | ||
); | ||
|
||
const FilteredTokens = ({ selected, setSelected }) => { | ||
const { data } = useContext(DataContext); | ||
|
||
return ( | ||
<Box | ||
align="start" | ||
gap="xsmall" | ||
overflow="auto" | ||
style={{ height: 'calc(100vh - 196px)' }} | ||
> | ||
{data.map(token => ( | ||
<Tag | ||
key={`${token.name}-${token.mode}`} | ||
badge={token.mode} | ||
name={token.name} | ||
onClick={() => | ||
selected.name === token.name && selected.mode === token.mode | ||
? setSelected({}) | ||
: setSelected({ name: token.name, mode: token.mode }) | ||
} | ||
active={selected.name === token.name && selected.mode === token.mode} | ||
/> | ||
))} | ||
</Box> | ||
); | ||
}; | ||
|
||
const buildTree = (selectedToken, showValue) => { | ||
const { mode, name } = selectedToken; | ||
const usedBy = tokens[mode][name].usedBy; | ||
return ( | ||
<Box | ||
key={`${name}-${mode}`} | ||
direction="row" | ||
gap="small" | ||
align="start" | ||
flex={false} | ||
> | ||
<Tag | ||
name={name} | ||
badge={mode} | ||
value={showValue ? tokens[mode][name]['$value'] : undefined} | ||
/> | ||
{usedBy?.length ? ( | ||
<Box direction="row" gap="small" align="start" flex={false}> | ||
<Box pad={{ vertical: 'xsmall' }}> | ||
<LinkNext height="medium" /> | ||
</Box> | ||
<Box gap="small">{usedBy?.map(t => buildTree(t))}</Box> | ||
</Box> | ||
) : undefined} | ||
</Box> | ||
); | ||
}; | ||
|
||
function App() { | ||
const [selected, setSelected] = useState({}); | ||
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" | ||
> | ||
<Header | ||
background="background-front" | ||
pad={{ vertical: 'small', horizontal: 'medium' }} | ||
border={{ side: 'bottom', color: 'border-weak' }} | ||
> | ||
<Text weight={500} color="text-strong"> | ||
Design Token Visualizer | ||
</Text> | ||
<Box direction="row" gap="xsmall"> | ||
<Button | ||
icon={<Github />} | ||
href="https://github.com/grommet/hpe-design-system/tree/design-tokens/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> | ||
<Page kind="full"> | ||
<Data | ||
data={tokensArr} | ||
properties={{ | ||
mode: { label: 'Mode' }, | ||
name: { filter: false }, | ||
$type: { label: 'Type' }, | ||
}} | ||
> | ||
<Grid columns={['medium', 'flex']}> | ||
<Box gap="small" pad="medium" background="background-front"> | ||
<Box> | ||
<Toolbar> | ||
<Box flex> | ||
<DataSearch /> | ||
</Box> | ||
<DataFilters drop /> | ||
</Toolbar> | ||
<DataSummary /> | ||
</Box> | ||
<FilteredTokens selected={selected} setSelected={setSelected} /> | ||
</Box> | ||
<PageContent overflow="auto" flex={false} fill> | ||
<Box pad={{ vertical: 'medium' }}> | ||
{selected.name | ||
? buildTree(selected, true) | ||
: 'Select a token to see dependencies.'} | ||
</Box> | ||
</PageContent> | ||
</Grid> | ||
</Data> | ||
</Page> | ||
</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,9 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './App.jsx'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
); |
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 @@ | ||
/// <reference types="vite/client" /> |
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,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["src"], | ||
"references": [{ "path": "./tsconfig.node.json" }] | ||
} |
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,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"skipLibCheck": true, | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true | ||
}, | ||
"include": ["vite.config.ts"] | ||
} |
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,7 @@ | ||
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
}) |
Oops, something went wrong.