Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storybook 8 Upgrade #1816

Merged
merged 37 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e0701b0
Initial SB 8 upgrade
fredvisser Feb 9, 2024
8131547
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Feb 12, 2024
bd45267
Change files
fredvisser Feb 12, 2024
72b2837
beta 2
fredvisser Feb 12, 2024
aa7d8d3
add missing types
fredvisser Feb 12, 2024
decbe65
chromatic local compare addon
fredvisser Feb 14, 2024
41e15fc
Configure webpack minification to avoid error in --test build
m-akinc Feb 14, 2024
aed7cf7
Fix lint issues
m-akinc Feb 14, 2024
315dde2
Merge branch 'user/fvisser/storybook-8-beta-test' of github.com:ni/ni…
fredvisser Feb 14, 2024
5608fea
remove test flag
fredvisser Feb 14, 2024
7ab6fdc
updated package-lock
fredvisser Feb 14, 2024
6a7fe1b
fix for prettier
fredvisser Feb 14, 2024
beee7aa
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Feb 19, 2024
4d66620
update package-lock
fredvisser Feb 19, 2024
edba305
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Feb 19, 2024
6cd90eb
pin beachball to patch version
fredvisser Feb 19, 2024
5e72a40
fix build
fredvisser Feb 19, 2024
f4c3587
beta 4
fredvisser Feb 21, 2024
bd34937
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Feb 21, 2024
fa5f835
fix build
fredvisser Feb 22, 2024
7eccd74
Upgrade Chromatic Github Action
fredvisser Feb 22, 2024
b7ce0d9
update to rc.0
fredvisser Mar 1, 2024
9e59868
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Mar 1, 2024
ef34718
migrate to new addon manager package
fredvisser Mar 1, 2024
5780109
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Mar 12, 2024
2816c86
update theme
fredvisser Mar 12, 2024
87d0f50
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Mar 12, 2024
d279590
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Mar 20, 2024
d971482
review feedback
fredvisser Mar 20, 2024
187dd78
upgrade and remove icon color workaround
fredvisser Mar 25, 2024
1656254
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Mar 25, 2024
01b0ed5
Fix storySort
fredvisser Mar 26, 2024
ce17abd
test fix
fredvisser Mar 26, 2024
3ff6b1e
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Mar 26, 2024
89ee1ca
last fixes
fredvisser Mar 26, 2024
92090e6
update base dir path
fredvisser Mar 27, 2024
eca1f18
Merge branch 'main' into user/fvisser/storybook-8-beta-test
fredvisser Mar 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
- '../packages/nimble-tokens/dist/icons/svg/**'
- '../packages/nimble-tokens/source/styledictionary/properties/**'
storybookBuildDir: ../../packages/site/dist/storybook
storybookBaseDir: ./packages/nimble-components
exitOnceUploaded: true # Do not wait for test results
exitZeroOnChanges: true # Option to prevent the workflow from failing

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
fredvisser marked this conversation as resolved.
Show resolved Hide resolved
fredvisser marked this conversation as resolved.
Show resolved Hide resolved
"type": "none",
"comment": "Initial SB 8 upgrade",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "none"
fredvisser marked this conversation as resolved.
Show resolved Hide resolved
}
39,879 changes: 19,102 additions & 20,777 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 29 additions & 7 deletions packages/nimble-components/.storybook/blocks/StoryLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
import React from 'react';
import React, { ReactNode } from 'react';
import './story-layout.css';
import { NimbleIconCheck } from '../../src/icons/tests/check.react';
import { NimbleIconExclamationMark } from '../../src/icons/tests/exclamation-mark.react';

interface ChildrenProp {
children?: ReactNode
}

/**
* Renders a frame to match visual design of existing Storybook Doc blocks.
*/
export const Frame = ({ children }) => {
export const Frame = ({ children }: ChildrenProp) => {
return <div className="story-layout-frame">{children}</div>;
};

interface ContainerProp {
children?: ReactNode
config?: string
}

/**
* Renders a container with grid configuration. Use with <Column> to create grided documentation.
* Use CSS grid syntax for the config prop to specify the number of columns and their widths.
*/
export const Container = ({ children, config = '200px 1fr' }) => {
export const Container = ({ children, config = '200px 1fr' }: ContainerProp) => {
return <div className="story-layout-container" style={{gridTemplateColumns: config}}>{children}</div>;
};

interface ColumnProp {
children?: ReactNode
stylingClass?: string
}

/**
* Renders a column for use with <Container>.
* If you need to put Nimble components in a column, use the stylingClass="controls" prop to apply the correct margins.
*/
export const Column = ({ children, stylingClass = '' }) => {
export const Column = ({ children, stylingClass = '' }: ColumnProp) => {
const cn = `story-layout-column ${stylingClass}`;
return <div className={cn}>{children}</div>;
};
Expand All @@ -37,7 +51,7 @@ export const Divider = () => {
/**
* Renders a "Do" section for Storybook documentation.
*/
export const Do = ({ children }) => {
export const Do = ({ children }: ChildrenProp) => {
return (
<Container config='48px 1fr'>
<Column>
Expand All @@ -51,7 +65,7 @@ export const Do = ({ children }) => {
/**
* Renders a "Dont" section for Storybook documentation.
*/
export const Dont = ({ children }) => {
export const Dont = ({ children }: ChildrenProp) => {
return (
<Container config='48px 1fr'>
<Column>
Expand All @@ -62,10 +76,18 @@ export const Dont = ({ children }) => {
);
};

interface TagProp {
name: string
open?: boolean
openClose?: boolean
close?: boolean
selfClose?: boolean
}

/**
* Renders a "Tag" component for Storybook documentation.
*/
export const Tag = ({ name, open, openClose, close, selfClose }) => {
export const Tag = ({ name, open, openClose, close, selfClose }: TagProp) => {
if (open) {
return (<code>&lt;{name}&gt;</code>);
} else if (close) {
Expand Down
37 changes: 26 additions & 11 deletions packages/nimble-components/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { dirname, join } from 'path';
import remarkGfm from 'remark-gfm';
import CircularDependencyPlugin from 'circular-dependency-plugin';
import TerserPlugin from 'terser-webpack-plugin';

// All files participating in storybook should be in src
// so that TypeScript and linters can track them correctly
export const stories = ['../src/**/*.mdx', '../src/**/*.stories.ts'];
export const addons = [
{
name: '@storybook/addon-essentials',
name: getAbsolutePath('@storybook/addon-essentials'),
options: {
outline: false,
docs: false
}
},
{
name: '@storybook/addon-docs',
name: getAbsolutePath('@storybook/addon-docs'),
options: {
mdxPluginOptions: {
mdxCompileOptions: {
Expand All @@ -22,12 +24,14 @@ export const addons = [
}
}
},
'@storybook/addon-a11y',
'@storybook/addon-interactions'
getAbsolutePath('@storybook/addon-a11y'),
getAbsolutePath('@storybook/addon-interactions'),
getAbsolutePath('@chromatic-com/storybook'),
fredvisser marked this conversation as resolved.
Show resolved Hide resolved
'@storybook/addon-webpack5-compiler-swc'
fredvisser marked this conversation as resolved.
Show resolved Hide resolved
];
export function webpackFinal(config) {
config.module.rules.push({
test: /\.ts$/,
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('ts-loader')
Expand All @@ -43,14 +47,25 @@ export function webpackFinal(config) {
config.performance = {
hints: false
};
config.optimization.minimizer = [
new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true
}
})
];
return config;
}
export const staticDirs = ['public'];
export const framework = {
name: '@storybook/html-webpack5',
options: {
builder: {
useSWC: true
}
}
name: getAbsolutePath('@storybook/html-webpack5')
};

export const docs = {
autodocs: false
};

function getAbsolutePath(value) {
return dirname(require.resolve(join(value, 'package.json')));
}
2 changes: 1 addition & 1 deletion packages/nimble-components/.storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
Override the default favicon used in the Storybook in the browser tab.
-->
<link rel="icon" href="favicon.ico" sizes="any">
<link rel="icon" href="favicon.ico" sizes="any">
2 changes: 1 addition & 1 deletion packages/nimble-components/.storybook/manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addons } from '@storybook/addons';
import { addons } from '@storybook/manager-api';
import theme from './theme';

addons.setConfig({
fredvisser marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
7 changes: 6 additions & 1 deletion packages/nimble-components/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const parameters = {
'Tests',
['Docs'],
'Internal',
['Docs'],
'Patterns',
['Docs']
]
}
Expand Down Expand Up @@ -74,10 +76,13 @@ const createOrUpdateBackgroundWorkaround = style => {
// Storybook background plugin does not support mdx
// Workaround based on: https://github.com/storybookjs/storybook/issues/13323#issuecomment-876296801
export default {
parameters,
decorators: [
(story, context) => {
const defaultBackgroundColorKey = context?.parameters?.backgrounds?.default;
const defaultBackgroundColor = context?.parameters?.backgrounds?.values?.find(v => v.name === defaultBackgroundColorKey)?.value;
const defaultBackgroundColor = context?.parameters?.backgrounds?.values?.find(
v => v.name === defaultBackgroundColorKey
)?.value;
const currentBackgroundColor = context?.globals?.backgrounds?.value ?? defaultBackgroundColor;
const style = `.docs-story {
background-color: ${currentBackgroundColor}
Expand Down
39 changes: 24 additions & 15 deletions packages/nimble-components/.storybook/theme.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
import { create } from '@storybook/theming/create';
import {
Black91,
Brand100,
Brand85,
Black75,
White
White,
Black7,
Black15,
DigitalGreenDark105,
Black30,
Black,
Black75
} from '@ni/nimble-tokens/dist/styledictionary/js/tokens';
import logo from './nimble-ui-logo.svg';

export default create({
base: 'light',

colorPrimary: Brand100,
colorSecondary: Black75,
colorPrimary: Brand85,
colorSecondary: DigitalGreenDark105,

// UI
appBg: 'white',
appContentBg: '#F4F4F4',
appBorderColor: 'grey',
appBorderRadius: 4,
appBg: White,
appContentBg: White,
appBorderColor: Black30,
appBorderRadius: 5,

// Typography
fontBase: '"Open Sans", sans-serif',
fontCode: 'monospace',

// Text colors
textColor: Black91,
textInverseColor: 'rgba(255,255,255,0.9)',
textInverseColor: Black15,
textMutedColor: Black75,

// Toolbar default and active colors
barTextColor: White,
barSelectedColor: White,
barHoverColor: Black15,
barSelectedColor: Black7,
barBg: Brand85,

// Form colors
inputBg: 'white',
inputBorder: 'silver',
inputTextColor: 'black',
buttonBg: White,
buttonBorder: Black75,
booleanBg: White,
booleanSelectedBg: Black30,
inputBg: White,
inputBorder: Black75,
inputTextColor: Black,
inputBorderRadius: 4,

brandTitle: 'Nimble components',
Expand Down
4 changes: 4 additions & 0 deletions packages/nimble-components/chromatic.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"projectId": "Project:60e89457a987cf003efc0a5b",
"storybookBaseDir": "packages/nimble-components"
}
29 changes: 16 additions & 13 deletions packages/nimble-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"devDependencies": {
"@babel/cli": "^7.13.16",
"@babel/core": "^7.20.12",
"@chromatic-com/storybook": "^1.2.25",
"@microsoft/fast-react-wrapper": "0.3.22",
"@ni/eslint-config-javascript": "^4.2.0",
"@ni/eslint-config-typescript": "^4.2.0",
Expand All @@ -117,18 +118,19 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@storybook/addon-a11y": "^7.6.13",
"@storybook/addon-actions": "^7.6.13",
"@storybook/addon-docs": "^7.6.13",
"@storybook/addon-essentials": "^7.6.13",
"@storybook/addon-interactions": "^7.6.13",
"@storybook/addon-links": "^7.6.13",
"@storybook/addons": "^7.6.13",
"@storybook/cli": "^7.6.13",
"@storybook/addon-a11y": "^8.0.4",
"@storybook/addon-actions": "^8.0.4",
"@storybook/addon-docs": "^8.0.4",
"@storybook/addon-essentials": "^8.0.4",
"@storybook/addon-interactions": "^8.0.4",
"@storybook/addon-links": "^8.0.4",
"@storybook/addon-webpack5-compiler-swc": "^1.0.2",
"@storybook/cli": "^8.0.4",
"@storybook/csf": "^0.1.2",
"@storybook/html": "^7.6.13",
"@storybook/html-webpack5": "^7.6.13",
"@storybook/theming": "^7.6.13",
"@storybook/html": "^8.0.4",
"@storybook/html-webpack5": "^8.0.4",
"@storybook/manager-api": "^8.0.4",
"@storybook/theming": "^8.0.4",
"@types/jasmine": "^5.1.4",
"@types/webpack-env": "^1.15.2",
"babel-loader": "^9.1.2",
Expand All @@ -154,12 +156,13 @@
"playwright": "1.42.0",
"prettier-eslint": "^16.3.0",
"prettier-eslint-cli": "^8.0.1",
"remark-gfm": "^3.0.1",
"remark-gfm": "^4.0.0",
"rollup": "^4.12.0",
"rollup-plugin-polyfill-node": "^0.13.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"source-map-loader": "^5.0.0",
"storybook": "^7.6.13",
"storybook": "^8.0.4",
"terser-webpack-plugin": "^5.3.10",
"ts-loader": "^9.2.5",
"typescript": "~4.9.5",
"webpack": "^5.75.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Meta, Story } from '@storybook/html';
import type { Meta, StoryFn } from '@storybook/html';
import { html, ViewTemplate, when } from '@microsoft/fast-element';
import { createStory } from '../../utilities/tests/storybook';
import {
Expand Down Expand Up @@ -46,19 +46,19 @@ const component = (
</${anchorTabsTag}>
`;

export const anchorTabsThemeMatrix: Story = createMatrixThemeStory(
export const anchorTabsThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [tabsToolbarState, disabledStates])
);

export const hiddenTabs: Story = createStory(
export const hiddenTabs: StoryFn = createStory(
hiddenWrapper(
html`<${anchorTabsTag} hidden>
<${anchorTabTag}>Tab One</${anchorTabTag}>
</${anchorTabsTag}>`
)
);

export const textCustomized: Story = createMatrixThemeStory(
export const textCustomized: StoryFn = createMatrixThemeStory(
textCustomizationWrapper(
html`
<${anchorTabsTag}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Story, Meta } from '@storybook/html';
import type { StoryFn, Meta } from '@storybook/html';
import { html, ViewTemplate, when } from '@microsoft/fast-element';
import { pascalCase } from '@microsoft/fast-web-utilities';
import { createStory } from '../../utilities/tests/storybook';
Expand Down Expand Up @@ -81,7 +81,7 @@ const component = (
<div style="height: var(${bannerGapSize.cssCustomProperty})"></div>
`;

export const bannerThemeMatrix: Story = createMatrixThemeStory(
export const bannerThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
severityStates,
actionStates,
Expand All @@ -90,7 +90,7 @@ export const bannerThemeMatrix: Story = createMatrixThemeStory(
])
);

export const hiddenBanner: Story = createStory(
export const hiddenBanner: StoryFn = createStory(
hiddenWrapper(
html`<${bannerTag} hidden>
<span slot="title">Hidden banner</span>
Expand Down
Loading
Loading