Skip to content

Commit

Permalink
Upgrade to storybook 8 (#293)
Browse files Browse the repository at this point in the history
* Upgrade to storybook 8

* Upgrade to storybook 8

* Upgrade to storybook 8

* fix failing build

* patch version
  • Loading branch information
KaranAtTeamForm authored Jun 14, 2024
1 parent 3516f1c commit 0a76dd6
Show file tree
Hide file tree
Showing 56 changed files with 4,617 additions and 4,731 deletions.
35 changes: 19 additions & 16 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"env": {
"es": {
"presets": [
["@babel/preset-env", { "modules": false }],
"@babel/preset-react"
]
}
},
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-class-properties",
"babel-plugin-styled-components",
"react-docgen"
]
}
"env": {
"es": {
"presets": [
["@babel/preset-env", { "modules": false }],
["@babel/preset-react", { "runtime": "automatic" }]
]
}
},
"presets": [
"@babel/preset-env",
["@babel/preset-react", { "runtime": "automatic" }]
],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-class-properties",
"babel-plugin-styled-components",
"react-docgen"
]
}
2 changes: 1 addition & 1 deletion .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
chromatic-deployment:
runs-on: ubuntu-latest
steps:
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.12.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
actions: write
steps:
- uses: actions/checkout@v2
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.12.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Use Node.js 18
- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20.12.2
Expand Down
23 changes: 16 additions & 7 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
module.exports = {
stories: ["../lib/**/*.@(mdx|stories.@(js))"],

addons: [
"@storybook/addon-docs",
"@storybook/addon-links",
"@storybook/addon-viewport",
"@storybook/addon-knobs",
"@storybook/addon-a11y",
"@storybook/addon-toolbars",
"@storybook/components",
"@storybook/api",
"@storybook/addon-mdx-gfm",
"@storybook/manager-api",
"@storybook/core-events"
"@storybook/core-events",
"@chromatic-com/storybook",
"@storybook/preset-create-react-app",
"@storybook/addon-webpack5-compiler-babel"
],

framework: {
name: "@storybook/react-webpack5",
options: {}
},
docs: {
autodocs: "docs"
}

swc: () => ({
jsc: {
transform: {
react: {
runtime: "automatic"
}
}
}
})
};
74 changes: 42 additions & 32 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState, useEffect, Suspense } from "react";
import { DocsPage, DocsContainer as BaseContainer } from "@storybook/blocks";
import { library } from "@fortawesome/fontawesome-svg-core";
import { far } from "@fortawesome/free-regular-svg-icons";
Expand Down Expand Up @@ -26,46 +26,55 @@ const FlexItem = styled.div`
const getThemeName = (context) =>
get(context, "parameters.theme") || get(context, "globals.theme");

const getTheme = (context) => {
const themeName = getThemeName(context);
const getTheme = (themeName) => {
return themeName === "default" ? systemtheme : systemThemeCollapsed;
};

const ThemeDecorator = (storyFn, context) => {
const themeName = getThemeName(context);
const storyTheme = getTheme(context);
const withThemeDecorator = (storyFn, context) => {
const [finalThemeName, setFinalThemeName] = useState("default");
const [storyTheme, setStoryTheme] = useState(systemtheme);

useEffect(() => {
const themeName = getThemeName(context);
setStoryTheme(getTheme(themeName));
setFinalThemeName(themeName);
}, [get(context, "parameters.theme"), get(context, "globals.theme")]);

switch (themeName) {
switch (finalThemeName) {
case "side-by-side":
return (
<FlexWrapper>
<FlexItem key="default">
<ThemeProvider theme={systemtheme}>
<>
<GlobalStyles />
{storyFn()}
</>
</ThemeProvider>
</FlexItem>
<FlexItem key="collapsed">
<ThemeProvider theme={systemThemeCollapsed}>
<>
<GlobalStyles />
{storyFn()}
</>
</ThemeProvider>
</FlexItem>
</FlexWrapper>
<Suspense fallback={<div>Loading Themed Component</div>}>
<FlexWrapper>
<FlexItem key="default">
<ThemeProvider theme={systemtheme}>
<>
<GlobalStyles />
{storyFn()}
</>
</ThemeProvider>
</FlexItem>
<FlexItem key="collapsed">
<ThemeProvider theme={systemThemeCollapsed}>
<>
<GlobalStyles />
{storyFn()}
</>
</ThemeProvider>
</FlexItem>
</FlexWrapper>
</Suspense>
);

default:
return (
<ThemeProvider theme={storyTheme}>
<>
<GlobalStyles />
{storyFn()}
</>
</ThemeProvider>
<Suspense fallback={<div>Loading Themed Component</div>}>
<ThemeProvider theme={storyTheme}>
<>
<GlobalStyles />
{storyFn()}
</>
</ThemeProvider>
</Suspense>
);
}
};
Expand All @@ -77,6 +86,7 @@ export const globalTypes = {
defaultValue: "default",
toolbar: {
icon: "sidebar",
dynamicTitle: true,
items: [
{ value: "default", title: "Default theme" },
{ value: "collapsed", title: "Collapsed theme" },
Expand All @@ -96,7 +106,7 @@ export const DocsContainer = ({ children, context }) => {
);
};

export const decorators = [ThemeDecorator];
export const decorators = [withThemeDecorator];
export const parameters = {
options: {
showRoots: true
Expand Down
10 changes: 5 additions & 5 deletions lib/01-Intro.stories.mdx → lib/01-Intro.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Meta } from "@storybook/addon-docs";
import { Meta } from "@storybook/blocks";

<Meta title="Intro" />

Expand Down Expand Up @@ -52,8 +52,8 @@ As an alternative to `npm link` you can run `npm run dist` and then copy the `es

If you need to do `npm link` in your local environment you might encounter the following issues:

- https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react
- https://github.com/styled-components/styled-components/issues/2379
* https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react
* https://github.com/styled-components/styled-components/issues/2379

Both react and styled-components cause duplicate instance issue after npm link, to fix that we need to ensure both app project and lib project are sharing the same instance of them.

Expand Down Expand Up @@ -124,7 +124,7 @@ import { TabsContainer, Tab } from "orcs-design-system"

### Using Styled System props

The design system components are built with [Styled System](https://styled-system.com/) props. Generally, components can access the `space` and `layout` prop categories, with additional prop categories on a per-component basis. Check the _Properties_ section in a component's documentation to see what props it can use. Custom props will be listed in the props table.
The design system components are built with [Styled System](https://styled-system.com/) props. Generally, components can access the `space` and `layout` prop categories, with additional prop categories on a per-component basis. Check the *Properties* section in a component's documentation to see what props it can use. Custom props will be listed in the props table.

As a guide to using these props, see the [Styled System reference table](https://styled-system.com/table).

Expand Down Expand Up @@ -192,6 +192,6 @@ To run playroom, use this command: `npm run playroom`

This design system is intended to work correctly on all modern desktop and mobile browsers.

---
***

> "A design system is a living, funded product with a roadmap and backlog, serving an ecosystem." — Nathan Curtis
137 changes: 137 additions & 0 deletions lib/Colour.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import {
Meta,
ColorPalette,
ColorItem,
Story,
Canvas
} from "@storybook/addon-docs";
import { colors } from "./systemtheme";
import Flex from "./components/Flex";
import Colour from "./assets/Colour";
import Box from "./components/Box/";
import * as ColourStories from "./assets/Colour/Colour.stories";

<Meta of={ColourStories} />

# Colour

These are the colours used throughout the design system, defined in `systemtheme`. They can be referenced using the `color` prop for components that accept this prop, or through referencing the theme object.

## Main palette

<ColorPalette>
<ColorItem
title="Greyscale"
subtitle="Greyscale theme colours"
colors={[
colors.black,
colors.greyDarkest,
colors.greyDarker,
colors.greyDark,
colors.grey,
colors.greyLight,
colors.greyLighter,
colors.greyLightest,
colors.white
]}
/>
<ColorItem
title="Primary"
subtitle="Main theme colour"
colors={[
colors.primaryDarkest,
colors.primaryDarker,
colors.primaryDark,
colors.primary,
colors.primaryLight,
colors.primaryLighter,
colors.primaryLightest
]}
/>
<ColorItem
title="Secondary"
subtitle="Secondary theme colour"
colors={[
colors.secondaryDarkest,
colors.secondaryDarker,
colors.secondaryDark,
colors.secondary,
colors.secondaryLight,
colors.secondaryLighter,
colors.secondaryLightest
]}
/>
<ColorItem
title="Success"
subtitle="Success indicator colour"
colors={[
colors.successDarkest,
colors.successDarker,
colors.successDark,
colors.success,
colors.successLight,
colors.successLighter,
colors.successLightest
]}
/>
<ColorItem
title="Warning"
subtitle="Warning indicator colour"
colors={[
colors.warningDarkest,
colors.warningDarker,
colors.warningDark,
colors.warning,
colors.warningLight,
colors.warningLighter,
colors.warningLightest
]}
/>
<ColorItem
title="Danger"
subtitle="Danger indicator colour"
colors={[
colors.dangerDarkest,
colors.dangerDarker,
colors.dangerDark,
colors.danger,
colors.dangerLight,
colors.dangerLighter,
colors.dangerLightest
]}
/>
</ColorPalette>

## Monochrome opacities

For black and white colours at different opacities, use the following scales.

### Black opacity scale

<Canvas of={ColourStories.BlackOpacityScale} />

### White opacity scale

<Canvas of={ColourStories.WhiteOpacityScale} />

## Coloured opacities

### Primary opacity scale

<Canvas of={ColourStories.PrimaryOpacityScale} />

### Secondary opacity scale

<Canvas of={ColourStories.SecondaryOpacityScale} />

### Success opacity scale

<Canvas of={ColourStories.SuccessOpacityScale} />

### Warning opacity scale

<Canvas of={ColourStories.WarningOpacityScale} />

### Danger opacity scale

<Canvas of={ColourStories.DangerOpacityScale} />
Loading

0 comments on commit 0a76dd6

Please sign in to comment.