Skip to content

Commit

Permalink
refactor: use TypeScript for Storybook React config
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed May 29, 2023
1 parent b846427 commit 953018d
Show file tree
Hide file tree
Showing 24 changed files with 436 additions and 1,503 deletions.
2 changes: 0 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ module.exports = {
'packages/web-component-library-vue/tsconfig.json',
'packages/web-component-library-vue/tsconfig.app.json',
'packages/web-component-library-vue/tsconfig.vite-config.json',
'packages/email-template-nodemailer/tsconfig.json',
'packages/react-emails/tsconfig.json',
],
tsconfigRootDir: __dirname,
},
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ generated/
tmp/
*.tgz
.angular
tsconfig.tsbuildinfo

# Ignore log files
*.err
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook-angular/config/manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addons } from '@storybook/addons';
import { create } from '@storybook/theming/create';
import theme from '@utrecht/storybook-helpers/storybook-theme.json';
import { theme } from '@utrecht/storybook-helpers/dist/storybook-theme';

addons.setConfig({
theme: create(theme),
Expand Down
4 changes: 2 additions & 2 deletions packages/storybook-angular/config/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { setCompodocJson } from '@storybook/addon-docs/angular';
import { withTests } from '@storybook/addon-jest';
import { componentWrapperDecorator } from '@storybook/angular';
import results from '@utrecht/component-library-angular/dist/.jest-test-results.json';
import { addonStatus } from '@utrecht/storybook-helpers/src/addon-status';
import { addonViewport } from '@utrecht/storybook-helpers/src/addon-viewport';
import { addonStatus } from '@utrecht/storybook-helpers/dist/addon-status';
import { addonViewport } from '@utrecht/storybook-helpers/dist/addon-viewport';
import docJson from '../tmp/documentation.json';
setCompodocJson(docJson);

Expand Down
9 changes: 9 additions & 0 deletions packages/storybook-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,14 @@
"repository": {
"type": "git+ssh",
"url": "git@github.com:nl-design-system/utrecht.git"
},
"scripts": {
"build": "tsc --project tsconfig.dist.json",
"clean": "rimraf dist",
"lint": "tsc --noEmit --project tsconfig.json"
},
"devDependencies": {
"@storybook/theming": "7.0.7",
"typescript": "4.9.5"
}
}
18 changes: 18 additions & 0 deletions packages/storybook-helpers/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"root": "{workspaceRoot}/packages/storybook-helpers",
"sourceRoot": "{projectRoot}",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/workspace:run-commands",
"outputs": ["{projectRoot}/dist"],
"options": {
"command": "npm run build",
"cwd": "packages/storybook-helpers",
"outputPath": "packages/storybook-helpers/dist"
},
"dependsOn": ["^build"]
}
}
}
20 changes: 20 additions & 0 deletions packages/storybook-helpers/src/storybook-theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ThemeVars } from '@storybook/theming';

export const theme: ThemeVars = {
appBg: '#e6e6e6',
appBorderColor: '#666666',
appBorderRadius: 0,
appContentBg: '#ffffff',
barBg: 'rgb(208, 208, 208)',
barSelectedColor: 'green',
barTextColor: '#000000',
base: 'light',
brandImage: 'logo.svg',
brandTitle: 'Gemeente Utrecht',
brandUrl: 'https://www.utrecht.nl',
colorPrimary: '#2964a3',
colorSecondary: '#1b4050',
fontBase: '"Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Verdana, sans-serif',
fontCode: 'monospace',
textColor: '#1d1d1c',
};
19 changes: 0 additions & 19 deletions packages/storybook-helpers/storybook-theme.json

This file was deleted.

8 changes: 8 additions & 0 deletions packages/storybook-helpers/tsconfig.dist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": false,
"outDir": "dist",
"rootDir": "src"
}
}
12 changes: 12 additions & 0 deletions packages/storybook-helpers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"composite": true,
"esModuleInterop": true,
"outDir": "dist",
"rootDir": "src"
},
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts"],
"exclude": ["**/node_modules/*"]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env node */
module.exports = {
import type { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
core: {
disableTelemetry: true,
},
Expand All @@ -16,25 +17,17 @@ module.exports = {
'storybook-addon-themes',
],
features: {
babelModeV7: true,
postcss: false,
buildStoriesJson: true,
previewMdx2: true,
storyStoreV7: true,
},
framework: {
name: '@storybook/react-vite',
options: {},
},
staticDirs: ['../../../proprietary/assets'],
webpackFinal: async (config) => ({
...config,
performance: {
// Disable warning for: "asset size exceeds the recommended limit (244 KiB)"
hints: false,
},
}),
docs: {
autodocs: true,
},
};

export default config;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addons } from '@storybook/addons';
import { create } from '@storybook/theming/create';
import theme from '@utrecht/storybook-helpers/storybook-theme.json';
import { theme } from '@utrecht/storybook-helpers/src/storybook-theme';

addons.setConfig({
theme: create(theme),
Expand Down
32 changes: 0 additions & 32 deletions packages/storybook-react/config/preview.jsx

This file was deleted.

37 changes: 37 additions & 0 deletions packages/storybook-react/config/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Preview } from '@storybook/react';
import { addonStatus } from '@utrecht/storybook-helpers/src/addon-status';
import { addonThemes } from '@utrecht/storybook-helpers/src/addon-themes';
import { addonViewport } from '@utrecht/storybook-helpers/src/addon-viewport';
// import { withTests } from '@storybook/addon-jest';
// import results from '@utrecht/component-library-react/dist/.jest-test-results.json';
import React from 'react';
import '@utrecht/design-tokens/dist/index.css';
import '@utrecht/storybook-helpers/src/storybook-docs.scss';

const preview: Preview = {
decorators: [
(Story: any) => <div className="utrecht-document">{Story()}</div>,
// withTests({ results }),
],
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
docs: {
// Show code by default.
// Stories without concise code snippets can hide the code at Story level.
source: {
state: 'open',
},
},
...addonStatus,
...addonThemes,
...addonViewport,
},
};

export default preview;
2 changes: 1 addition & 1 deletion packages/storybook-react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"resolveJsonModule": true
},
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts", "src/**/*.tsx"],
"include": ["config/**/*.ts", "config/**/*.tsx", "src/**/*.ts", "src/**/*.tsx"],
"exclude": ["**/node_modules/*"]
}
2 changes: 1 addition & 1 deletion packages/storybook-vue/config/manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addons } from '@storybook/addons';
import { create } from '@storybook/theming/create';
import theme from '@utrecht/storybook-helpers/storybook-theme.json';
import { theme } from '@utrecht/storybook-helpers/dist/storybook-theme';

addons.setConfig({
theme: create(theme),
Expand Down
4 changes: 2 additions & 2 deletions packages/storybook-vue/config/preview.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Document } from '@utrecht/component-library-vue';
import { addonStatus } from '@utrecht/storybook-helpers/src/addon-status';
import { addonViewport } from '@utrecht/storybook-helpers/src/addon-viewport';
import { addonStatus } from '@utrecht/storybook-helpers/dist/addon-status';
import { addonViewport } from '@utrecht/storybook-helpers/dist/addon-viewport';
import { defineCustomElements } from '@utrecht/web-component-library-stencil/loader';
import '@utrecht/component-library-vue/dist/style.css';
import '@utrecht/design-tokens/dist/index.css';
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook/config/manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { addons } from '@storybook/addons';
import { create } from '@storybook/theming/create';
import { utrechtTypographySansSerifFontFamily } from '@utrecht/design-tokens/dist/index.mjs';
import theme from '@utrecht/storybook-helpers/storybook-theme.json';
import { theme } from '@utrecht/storybook-helpers/dist/storybook-theme';

addons.setConfig({
theme: create({
Expand Down
6 changes: 3 additions & 3 deletions packages/storybook/config/preview.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env node */
import { addonStatus } from '@utrecht/storybook-helpers/src/addon-status';
import { addonThemes } from '@utrecht/storybook-helpers/src/addon-themes';
import { addonViewport } from '@utrecht/storybook-helpers/src/addon-viewport';
import { addonStatus } from '@utrecht/storybook-helpers/dist/addon-status';
import { addonThemes } from '@utrecht/storybook-helpers/dist/addon-themes';
import { addonViewport } from '@utrecht/storybook-helpers/dist/addon-viewport';
import { defineCustomElements } from '@utrecht/web-component-library-stencil/loader';
import clsx from 'clsx';
import defaultsDeep from 'lodash.defaultsdeep';
Expand Down
Loading

1 comment on commit 953018d

@vercel
Copy link

@vercel vercel bot commented on 953018d May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.