Skip to content

Commit

Permalink
chore: Add Storybook and Chromatic
Browse files Browse the repository at this point in the history
  • Loading branch information
alanbsmith committed Oct 18, 2023
1 parent 13b551c commit 55d7dc3
Show file tree
Hide file tree
Showing 47 changed files with 1,499 additions and 6,042 deletions.
56 changes: 55 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,34 @@ jobs:
with:
node_version: 18.x

check:
build:
runs-on: ubuntu-latest
needs: 'install'

steps:
- uses: actions/checkout@v3

- uses: Workday/canvas-kit-actions/install@v1
with:
node_version: 18.x

- name: Build Tokens
run: yarn build:tokens

- name: Build Storybook
run: yarn build-storybook --quiet

- name: Cache Build
id: build-cache
uses: actions/cache@v3
with:
path: docs
key: ${{ runner.os }}-build-${{ github.sha }}

check:
runs-on: ubuntu-latest
needs: ['install', 'build']

steps:
- uses: actions/checkout@v3

Expand All @@ -29,10 +53,40 @@ jobs:
shell: bash
run: yarn lint

- name: Build Tokens
run: yarn build:tokens

- name: Type Check
shell: bash
run: yarn typecheck

- name: Run Unit Tests
shell: bash
run: yarn test

visual-test:
runs-on: ubuntu-latest
needs: 'build'

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required to retrieve git history

- uses: Workday/canvas-kit-actions/install@v1
with:
node_version: 18.x

- name: Restore Build
uses: actions/cache@v3
with:
path: docs
key: ${{ runner.os }}-build-${{ github.sha }}

- uses: chromaui/action@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: chpt_a9e354687a28e6e
storybookBuildDir: docs/storybook/@workday/canvas-tokens-docs/
exitOnceUploaded: false
exitZeroOnChanges: true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# compiled output
dist
docs
tmp
/out-tsc
*.tsbuildinfo
Expand Down Expand Up @@ -31,3 +32,6 @@ testem.log

# Keys
.env

# Storybook
build-storybook.log
6 changes: 0 additions & 6 deletions .vscode/extensions.json

This file was deleted.

8 changes: 4 additions & 4 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"extends": "nx/presets/npm.json",
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"]
"cacheableOperations": ["build", "lint", "test", "e2e", "build-storybook"]
}
}
}
},
"extends": "nx/presets/npm.json",
"$schema": "./node_modules/nx/schemas/nx-schema.json"
}
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,31 @@
"lint": "eslint -c ./.eslintrc.js --ext=ts .",
"precommit": "lint-staged",
"prepare": "husky install",
"storybook": "nx storybook @workday/canvas-tokens-docs",
"build-storybook": "nx build-storybook @workday/canvas-tokens-docs",
"test": "jest -c jest.config.ts",
"tokens-config": "ts-node scripts/tokens-config",
"typecheck": "tsc -p . --noEmit",
"release": "yarn build:tokens && changeset publish --tags latest"
},
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@commitlint/cli": "^17.6.3",
"@commitlint/config-conventional": "^17.6.3",
"@nx/js": "16.7.4",
"@nx/react": "^16.7.4",
"@nx/storybook": "^16.7.4",
"@nx/vite": "16.7.4",
"@octokit/openapi-types": "^18.0.0",
"@octokit/rest": "^18.12.0",
"@types/node": "^18.18.0",
"@storybook/addon-essentials": "7.4.0",
"@storybook/core-server": "7.4.0",
"@storybook/react-vite": "7.4.0",
"@types/jest": "^29.5.2",
"@typescript-eslint/eslint-plugin": "^5.59.5",
"@typescript-eslint/parser": "^5.59.5",
"chromatic": "^7.2.0",
"commander": "^11.0.0",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.3.1",
Expand All @@ -40,9 +51,12 @@
"lint-staged": "^13.2.2",
"nx": "16.1.2",
"prettier": "^2.8.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"ts-jest": "^29.1.0",
"ts-node": "10.9.1",
"typescript": "^5.0.4"
"typescript": "^5.0.4",
"vite": "~4.3.9"
},
"workspaces": [
"packages/*"
Expand All @@ -55,8 +69,5 @@
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"dependencies": {
"@changesets/cli": "^2.26.2"
}
}
24 changes: 24 additions & 0 deletions packages/canvas-tokens-docs/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type {StorybookConfig} from '@storybook/react-vite';

import {nxViteTsPaths} from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import {mergeConfig} from 'vite';

const config: StorybookConfig = {
stories: ['../**/*.stories.@(mdx|tsx)', '../stories/*.mdx'],
addons: ['@storybook/addon-essentials'],
framework: {
name: '@storybook/react-vite',
options: {},
},

viteFinal: async config =>
mergeConfig(config, {
plugins: [nxViteTsPaths()],
}),
};

export default config;

// To customize your Vite configuration you can use the viteFinal field.
// Check https://storybook.js.org/docs/react/builders/vite#configuration
// and https://nx.dev/packages/storybook/documents/custom-builder-configs
67 changes: 67 additions & 0 deletions packages/canvas-tokens-docs/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<script>
document.title = 'Canvas Tokens Storybook';
</script>

<style type="text/css">
.sb-unstyled h1,h2,h3,h3,h5,h6,p {
box-sizing: border-box;
font-family: Roboto;
}
</style>

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans&family=Roboto+Mono&family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">

<style>
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 300;
src: local('Roboto Light'), local('Roboto-Light'), url(Roboto-Light.ttf) format('truetype');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto Regular'), local('Roboto-Regular'),
url(Roboto-Regular.ttf) format('truetype');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 500;
src: local('Roboto Medium'), local('Roboto-Medium'), url(Roboto-Medium.ttf) format('truetype');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 700;
src: local('Roboto Bold'), local('Roboto-Bold'), url(Roboto-Bold.ttf) format('truetype');
}

@font-face {
font-family: 'Roboto Mono';
font-style: normal;
font-weight: 400;
src: local('Roboto Mono'), local('RobotoMono-Regular'),
url(RobotoMono-Regular.ttf) format('truetype');
}

@font-face {
font-family: 'Noto Sans';
font-style: normal;
font-weight: 400;
src: local('Noto Sans'), local('NotoSans-Regular'),
url(NotoSans-Regular.ttf) format('truetype');
}
</style>

<style>
pre {
font-family: 'Roboto Mono';
}
</style>
17 changes: 17 additions & 0 deletions packages/canvas-tokens-docs/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {Preview} from '@storybook/react';
import '@workday/canvas-tokens-web/dist/css/base/_variables.css';
import '@workday/canvas-tokens-web/dist/css/brand/_variables.css';
import '@workday/canvas-tokens-web/dist/css/system/_variables.css';

const preview: Preview = {
parameters: {
chromatic: {disableSnapshot: false},
options: {
storySort: {
order: ['Docs', ['Getting Started'], 'Visual Tests'],
},
},
},
};

export default preview;
24 changes: 24 additions & 0 deletions packages/canvas-tokens-docs/.storybook/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"composite": true,
"outDir": ""
},
"files": [
"../../../node_modules/@nx/react/typings/styled-jsx.d.ts",
"../../../node_modules/@nx/react/typings/cssmodule.d.ts",
"../../../node_modules/@nx/react/typings/image.d.ts"
],
"exclude": ["../**/*.spec.ts", "../**/*.spec.js", "../**/*.spec.tsx", "../**/*.spec.jsx"],
"include": [
"../src/**/*.stories.ts",
"../src/**/*.stories.js",
"../src/**/*.stories.jsx",
"../src/**/*.stories.tsx",
"../src/**/*.stories.mdx",
"*.ts",
"*.js"
]
}
Loading

0 comments on commit 55d7dc3

Please sign in to comment.