diff --git a/packages/react/.storybook/main.js b/packages/react/.storybook/main.js index a00c646d..f86cd480 100644 --- a/packages/react/.storybook/main.js +++ b/packages/react/.storybook/main.js @@ -9,14 +9,16 @@ import remarkGfm from 'remark-gfm'; function getAbsolutePath(value) { return dirname(require.resolve(join(value, 'package.json'))); } + const config = { stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'], addons: [ - getAbsolutePath('@storybook/addon-onboarding'), - getAbsolutePath('@storybook/addon-essentials'), - getAbsolutePath('@storybook/addon-interactions'), - getAbsolutePath('@storybook/addon-storysource'), - getAbsolutePath('@storybook/addon-webpack5-compiler-babel'), + '@storybook/addon-onboarding', + '@storybook/addon-essentials', + '@storybook/addon-interactions', + '@storybook/addon-storysource', + '@storybook/addon-webpack5-compiler-babel', + 'storybook-addon-accessibility-checker', { name: '@storybook/addon-docs', options: { diff --git a/packages/react/.storybook/preview.js b/packages/react/.storybook/preview.js index 5589f0d5..a8083d96 100644 --- a/packages/react/.storybook/preview.js +++ b/packages/react/.storybook/preview.js @@ -1,14 +1,216 @@ -import { Preview } from '@storybook/react'; +import React from 'react'; +import { white, g10, g90, g100 } from '@carbon/themes'; +import { breakpoints } from '@carbon/layout'; +import { GlobalTheme } from '@carbon/react/es/components/Theme'; +import { Layout } from '@carbon/react/es/components/Layout'; +import { TextDirection } from '@carbon/react/es/components/Text'; import './styles.scss'; -const preview = { - parameters: { - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/i, + +import theme from './theme'; + +console.log('process.env.NODE_ENV', process.env.NODE_ENV); + +const devTools = { + layoutSize: { + description: "Set the layout context's size", + defaultValue: false, + toolbar: { + title: 'dev :: unstable__Layout size', + items: [ + { + value: false, + title: 'None', + }, + 'xs', + 'sm', + 'md', + 'lg', + 'xl', + '2xl', + ], + }, + }, + layoutDensity: { + description: "Set the layout context's density", + defaultValue: false, + toolbar: { + title: 'dev :: unstable__Layout density', + items: [ + { + value: false, + title: 'None', + }, + 'condensed', + 'normal', + ], + }, + }, +}; + +export const globalTypes = { + dir: { + name: 'Text direction', + description: 'Set the text direction for the story', + defaultValue: 'ltr', + toolbar: { + icon: 'transfer', + title: 'Text direction', + items: [ + { + right: '🔄', + title: 'auto', + value: 'auto', + }, + { + right: '➡️', + title: 'left-to-right (ltr)', + value: 'ltr', + }, + { + right: '⬅️', + title: 'right-to-left (rtl)', + value: 'rtl', + }, + ], + }, + }, + theme: { + name: 'Theme', + description: 'Set the global theme for displaying components', + defaultValue: 'white', + toolbar: { + icon: 'paintbrush', + items: ['white', 'g10', 'g90', 'g100'], + }, + }, + ...(process.env.NODE_ENV === 'development' ? devTools : {}), +}; + +export const parameters = { + backgrounds: { + // https://storybook.js.org/docs/react/essentials/backgrounds#grid + grid: { + cellSize: 8, + opacity: 0.5, + }, + values: [ + { + name: 'white', + value: white.background, + }, + { + name: 'g10', + value: g10.background, + }, + { + name: 'g90', + value: g90.background, + }, + { + name: 'g100', + value: g100.background, + }, + ], + }, + controls: { + // https://storybook.js.org/docs/react/essentials/controls#show-full-documentation-for-each-property + expanded: true, + + // https://storybook.js.org/docs/react/essentials/controls#specify-initial-preset-color-swatches + // presetColors: [], + + // https://storybook.js.org/docs/react/essentials/controls#sorting-controls + sort: 'alpha', + + hideNoControlsWarning: true, + }, + darkMode: { + current: 'light', + }, + docs: { + theme, + }, + // Small (<672) + // Medium (672 - 1056px) + // Large (1056 - 1312px) + // X-Large (1312 - 1584px) + // Max (>1584) + viewport: { + viewports: { + sm: { + name: 'Small', + styles: { + width: breakpoints.sm.width, + height: '100%', + }, + }, + md: { + name: 'Medium', + styles: { + width: breakpoints.md.width, + height: '100%', + }, + }, + lg: { + name: 'Large', + styles: { + width: breakpoints.lg.width, + height: '100%', + }, + }, + xlg: { + name: 'X-Large', + styles: { + width: breakpoints.xlg.width, + height: '100%', + }, + }, + Max: { + name: 'Max', + styles: { + width: breakpoints.max.width, + height: '100%', + }, }, }, }, }; +const decorators = [ + (Story, context) => { + const { layoutDensity, layoutSize, locale, dir, theme } = context.globals; + const [randomKey, setRandomKey] = React.useState(1); + + React.useEffect(() => { + document.documentElement.setAttribute('data-carbon-theme', theme); + }, [theme]); + + React.useLayoutEffect(() => { + document.documentElement.lang = locale; + document.documentElement.dir = dir; + // Need to set random key to recalculate Popover coordinates + setRandomKey(Math.floor(Math.random() * 10)); + }, [locale, dir]); + + return ( + + + { + return dir; + }}> + + + + + ); + }, +]; + +const preview = { + parameters, + decorators, + globalTypes, +}; + export default preview; diff --git a/packages/react/.storybook/theme.js b/packages/react/.storybook/theme.js new file mode 100644 index 00000000..dad16d4a --- /dev/null +++ b/packages/react/.storybook/theme.js @@ -0,0 +1,25 @@ +/** + * Copyright IBM Corp. 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { create } from '@storybook/theming'; +import PackageInfo from '../package.json'; + +/** + * @see https://storybook.js.org/docs/react/configure/theming + */ +export default create({ + base: 'light', + + // Typography + fontBase: "'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif", + fontCode: + "'IBM Plex Mono', Menlo, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Courier, monospace", + + brandTitle: `@carbon-labs React`, + brandUrl: + 'https://github.com/carbon-design-system/carbon/tree/main/packages/react', +}); diff --git a/packages/react/package.json b/packages/react/package.json index a11800bb..c6d3dfb6 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -56,6 +56,7 @@ "remark-gfm": "^4.0.0", "sass-loader": "^16.0.4", "storybook": "^8.4.6", + "storybook-addon-accessibility-checker": "^3.1.61-rc.3", "style-loader": "^4.0.0", "typescript-config-carbon": "^0.3.0", "webpack": "^5.97.0" diff --git a/yarn.lock b/yarn.lock index c3e70870..1a08172e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5920,6 +5920,17 @@ __metadata: languageName: node linkType: hard +"@storybook/addon-highlight@npm:7.4.5": + version: 7.4.5 + resolution: "@storybook/addon-highlight@npm:7.4.5" + dependencies: + "@storybook/core-events": "npm:7.4.5" + "@storybook/global": "npm:^5.0.0" + "@storybook/preview-api": "npm:7.4.5" + checksum: 10c0/c1b4e41ca689fbc58e3dbeded012d09e8b7bf144cf6eb5876c1d3a3ee37f788ab1fe26e47bbdb30c31314e8045f81a2099a6dd6c3f64d1ecdc41a256a718a182 + languageName: node + linkType: hard + "@storybook/addon-highlight@npm:8.4.3": version: 8.4.3 resolution: "@storybook/addon-highlight@npm:8.4.3" @@ -6243,6 +6254,20 @@ __metadata: languageName: node linkType: hard +"@storybook/channels@npm:7.4.5": + version: 7.4.5 + resolution: "@storybook/channels@npm:7.4.5" + dependencies: + "@storybook/client-logger": "npm:7.4.5" + "@storybook/core-events": "npm:7.4.5" + "@storybook/global": "npm:^5.0.0" + qs: "npm:^6.10.0" + telejson: "npm:^7.2.0" + tiny-invariant: "npm:^1.3.1" + checksum: 10c0/d6da39c420dfe001e8a2929b79e0bc2d7683fcc74cd24b95df56067b4da76e02a2d174319587aefbb294da0678823eae20bff5b9595001557c3a24f41c323dac + languageName: node + linkType: hard + "@storybook/channels@npm:7.6.17": version: 7.6.17 resolution: "@storybook/channels@npm:7.6.17" @@ -6271,6 +6296,15 @@ __metadata: languageName: node linkType: hard +"@storybook/client-logger@npm:7.4.5": + version: 7.4.5 + resolution: "@storybook/client-logger@npm:7.4.5" + dependencies: + "@storybook/global": "npm:^5.0.0" + checksum: 10c0/cd5e70d7dcfa1fdb3b3beada1a2342a091959ec6a99c03805749bc3c0ad31d8f2d2ba62ec00ed18b8bb2a1ab9623a42e9fe47d97b9cc5df51bebbbe0f11aedeb + languageName: node + linkType: hard + "@storybook/client-logger@npm:7.6.17": version: 7.6.17 resolution: "@storybook/client-logger@npm:7.6.17" @@ -6289,6 +6323,27 @@ __metadata: languageName: node linkType: hard +"@storybook/components@npm:7.4.5": + version: 7.4.5 + resolution: "@storybook/components@npm:7.4.5" + dependencies: + "@radix-ui/react-select": "npm:^1.2.2" + "@radix-ui/react-toolbar": "npm:^1.0.4" + "@storybook/client-logger": "npm:7.4.5" + "@storybook/csf": "npm:^0.1.0" + "@storybook/global": "npm:^5.0.0" + "@storybook/theming": "npm:7.4.5" + "@storybook/types": "npm:7.4.5" + memoizerific: "npm:^1.11.3" + use-resize-observer: "npm:^9.1.0" + util-deprecate: "npm:^1.0.2" + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + checksum: 10c0/f309eeb87138a2c34624fc0f5c89f8063432d721d075bebe1d824a38cc6a63535766e08640c0082f80e34fbefb454f4c8e7fb37cc62ebb66d5c036ba052dc5d2 + languageName: node + linkType: hard + "@storybook/components@npm:8.4.3": version: 8.4.3 resolution: "@storybook/components@npm:8.4.3" @@ -6359,6 +6414,15 @@ __metadata: languageName: node linkType: hard +"@storybook/core-events@npm:7.4.5": + version: 7.4.5 + resolution: "@storybook/core-events@npm:7.4.5" + dependencies: + ts-dedent: "npm:^2.0.0" + checksum: 10c0/d5d331ac85198e4b3c2c41e2ef5b36069638b2bfba83b6c5fc5263a06745c31c6f33b5a5e38ae8789f44ddb27834f8248758d813cb6aa6802bc9e18c13c2a3c7 + languageName: node + linkType: hard + "@storybook/core-events@npm:7.6.17": version: 7.6.17 resolution: "@storybook/core-events@npm:7.6.17" @@ -6468,6 +6532,15 @@ __metadata: languageName: node linkType: hard +"@storybook/csf@npm:^0.1.0": + version: 0.1.12 + resolution: "@storybook/csf@npm:0.1.12" + dependencies: + type-fest: "npm:^2.19.0" + checksum: 10c0/3d96a976ada67eb683279338d1eb6aa730b228107d4c4f6616ea7b94061899c1fdc11957a756e7bc0708d18cb39af0010c865d124efd84559cd82dcb2d8bc959 + languageName: node + linkType: hard + "@storybook/csf@npm:^0.1.11": version: 0.1.11 resolution: "@storybook/csf@npm:0.1.11" @@ -6515,6 +6588,32 @@ __metadata: languageName: node linkType: hard +"@storybook/manager-api@npm:7.4.5": + version: 7.4.5 + resolution: "@storybook/manager-api@npm:7.4.5" + dependencies: + "@storybook/channels": "npm:7.4.5" + "@storybook/client-logger": "npm:7.4.5" + "@storybook/core-events": "npm:7.4.5" + "@storybook/csf": "npm:^0.1.0" + "@storybook/global": "npm:^5.0.0" + "@storybook/router": "npm:7.4.5" + "@storybook/theming": "npm:7.4.5" + "@storybook/types": "npm:7.4.5" + dequal: "npm:^2.0.2" + lodash: "npm:^4.17.21" + memoizerific: "npm:^1.11.3" + semver: "npm:^7.3.7" + store2: "npm:^2.14.2" + telejson: "npm:^7.2.0" + ts-dedent: "npm:^2.0.0" + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + checksum: 10c0/e3e92e07a78c22f00e452d1703bb70d73f35e8a78a04ab811fef674536be76be874d76c01fd50b003f876588a8d84225ae3d061ae91f02308671615188b89ac9 + languageName: node + linkType: hard + "@storybook/manager-api@npm:7.6.17": version: 7.6.17 resolution: "@storybook/manager-api@npm:7.6.17" @@ -6618,6 +6717,28 @@ __metadata: languageName: node linkType: hard +"@storybook/preview-api@npm:7.4.5": + version: 7.4.5 + resolution: "@storybook/preview-api@npm:7.4.5" + dependencies: + "@storybook/channels": "npm:7.4.5" + "@storybook/client-logger": "npm:7.4.5" + "@storybook/core-events": "npm:7.4.5" + "@storybook/csf": "npm:^0.1.0" + "@storybook/global": "npm:^5.0.0" + "@storybook/types": "npm:7.4.5" + "@types/qs": "npm:^6.9.5" + dequal: "npm:^2.0.2" + lodash: "npm:^4.17.21" + memoizerific: "npm:^1.11.3" + qs: "npm:^6.10.0" + synchronous-promise: "npm:^2.0.15" + ts-dedent: "npm:^2.0.0" + util-deprecate: "npm:^1.0.2" + checksum: 10c0/f8926c76d592a7a071a78dbb30f127314b1738f52957245a5825dd1aad66293c50507b358148b6540533dbaa5e4a95134e8116042e3a312457ce794f3a2299b8 + languageName: node + linkType: hard + "@storybook/preview-api@npm:8.4.3": version: 8.4.3 resolution: "@storybook/preview-api@npm:8.4.3" @@ -6743,6 +6864,20 @@ __metadata: languageName: node linkType: hard +"@storybook/router@npm:7.4.5": + version: 7.4.5 + resolution: "@storybook/router@npm:7.4.5" + dependencies: + "@storybook/client-logger": "npm:7.4.5" + memoizerific: "npm:^1.11.3" + qs: "npm:^6.10.0" + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + checksum: 10c0/6b8d2d95c74649b8d7f65e449304598a203a1f7cb6b33345fbf4f787d65c52bf0b3f0b8561ea7aab3350f4064b31f0088bc8a894f10bb3b657ee35a63b972dba + languageName: node + linkType: hard + "@storybook/router@npm:7.6.17": version: 7.6.17 resolution: "@storybook/router@npm:7.6.17" @@ -6797,6 +6932,21 @@ __metadata: languageName: node linkType: hard +"@storybook/theming@npm:7.4.5": + version: 7.4.5 + resolution: "@storybook/theming@npm:7.4.5" + dependencies: + "@emotion/use-insertion-effect-with-fallbacks": "npm:^1.0.0" + "@storybook/client-logger": "npm:7.4.5" + "@storybook/global": "npm:^5.0.0" + memoizerific: "npm:^1.11.3" + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + checksum: 10c0/2caae3a4b0d634d85dd4749c4f9734fbbb5392e9e0769bf6955aeada72bba8cb227a8b067dcd87ad7b51047903603ea42b5c53bb1151f24fdd403bdbf9270f1b + languageName: node + linkType: hard + "@storybook/theming@npm:7.6.17": version: 7.6.17 resolution: "@storybook/theming@npm:7.6.17" @@ -6845,6 +6995,18 @@ __metadata: languageName: node linkType: hard +"@storybook/types@npm:7.4.5": + version: 7.4.5 + resolution: "@storybook/types@npm:7.4.5" + dependencies: + "@storybook/channels": "npm:7.4.5" + "@types/babel__core": "npm:^7.0.0" + "@types/express": "npm:^4.7.0" + file-system-cache: "npm:2.3.0" + checksum: 10c0/35cd3c5d388be8e1d2b636cd028b571ebb3bb17ede17669cbb1f8b26b95f69c90476f98340b8e70a1f98b910eac8435b80e6acf0a5ba9eff7a30fa0164216a22 + languageName: node + linkType: hard + "@storybook/types@npm:7.6.17": version: 7.6.17 resolution: "@storybook/types@npm:7.6.17" @@ -8795,6 +8957,13 @@ __metadata: languageName: node linkType: hard +"accessibility-checker-engine@npm:^3.1.61": + version: 3.1.78 + resolution: "accessibility-checker-engine@npm:3.1.78" + checksum: 10c0/a8a21c2ff40cb9d41015ee8993114a9e8af7db69c352981d4a3400d6ede1b689d410ae93b3b67ca7efb181e544e3aac58dedabb48d8ca334de27b0d86bc06151 + languageName: node + linkType: hard + "accessor-fn@npm:1": version: 1.5.1 resolution: "accessor-fn@npm:1.5.1" @@ -9623,6 +9792,13 @@ __metadata: languageName: node linkType: hard +"axe-core@npm:^4.2.0": + version: 4.10.2 + resolution: "axe-core@npm:4.10.2" + checksum: 10c0/0e20169077de96946a547fce0df39d9aeebe0077f9d3eeff4896518b96fde857f80b98f0d4279274a7178791744dd5a54bb4f322de45b4f561ffa2586ff9a09d + languageName: node + linkType: hard + "axe-core@npm:^4.3.3": version: 4.8.4 resolution: "axe-core@npm:4.8.4" @@ -20311,6 +20487,7 @@ __metadata: remark-gfm: "npm:^4.0.0" sass-loader: "npm:^16.0.4" storybook: "npm:^8.4.6" + storybook-addon-accessibility-checker: "npm:^3.1.61-rc.3" style-loader: "npm:^4.0.0" typescript: "npm:^5.2.2" typescript-config-carbon: "npm:^0.3.0" @@ -23235,6 +23412,18 @@ __metadata: languageName: node linkType: hard +"react-resize-detector@npm:^7.1.2": + version: 7.1.2 + resolution: "react-resize-detector@npm:7.1.2" + dependencies: + lodash: "npm:^4.17.21" + peerDependencies: + react: ^16.0.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.0.0 || ^17.0.0 || ^18.0.0 + checksum: 10c0/2285b0024bcc736c7d5e80279e819835a5e8bef0899778100d2434b1c4b10971e6ae253df073ca96a20cacc47b3c249bc675479e5fc4ec1f6652fcca7f48ec22 + languageName: node + linkType: hard + "react-style-singleton@npm:^2.2.1": version: 2.2.1 resolution: "react-style-singleton@npm:2.2.1" @@ -25076,6 +25265,36 @@ __metadata: languageName: node linkType: hard +"storybook-addon-accessibility-checker@npm:^3.1.61-rc.3": + version: 3.1.61-rc.3 + resolution: "storybook-addon-accessibility-checker@npm:3.1.61-rc.3" + dependencies: + "@storybook/addon-highlight": "npm:7.4.5" + "@storybook/channels": "npm:7.4.5" + "@storybook/client-logger": "npm:7.4.5" + "@storybook/components": "npm:7.4.5" + "@storybook/core-events": "npm:7.4.5" + "@storybook/global": "npm:^5.0.0" + "@storybook/manager-api": "npm:7.4.5" + "@storybook/preview-api": "npm:7.4.5" + "@storybook/theming": "npm:7.4.5" + "@storybook/types": "npm:7.4.5" + accessibility-checker-engine: "npm:^3.1.61" + axe-core: "npm:^4.2.0" + lodash: "npm:^4.17.21" + react-resize-detector: "npm:^7.1.2" + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + peerDependenciesMeta: + react: + optional: true + react-dom: + optional: true + checksum: 10c0/56a7cecb97cefe9dccb1c296c34412ff2509d9d538bb68341885e21364a49e1504b5820cc633e51f62376ff3321ddcb4a26d607e7d27bfc2724e63f72a42602a + languageName: node + linkType: hard + "storybook@npm:^8.4.2": version: 8.4.3 resolution: "storybook@npm:8.4.3"