-
Notifications
You must be signed in to change notification settings - Fork 39
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experience 8346: Add configuration for local instance of Storybook #8803
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
stories: [ | ||
"../src/**/*.stories.mdx", | ||
"../src/**/*.stories.@(js|jsx|ts|tsx)", | ||
], | ||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-interactions", | ||
"@storybook/addon-a11y", | ||
], | ||
framework: "@storybook/react", | ||
core: { | ||
builder: "@storybook/builder-webpack5", | ||
}, | ||
refs: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allows for composition with other/external Storybooks. Everything's still going through network requests so browsing external stories won't be as snappy as our own, but it's still nice to have everything in one place. |
||
trussworks: { | ||
title: "Trussworks Storybook", | ||
url: "https://trussworks.github.io/react-uswds/", | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { initializeWorker, mswDecorator } from "msw-storybook-addon"; | ||
import { CacheProvider } from "rest-hooks"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
import { HelmetProvider } from "react-helmet-async"; | ||
import MockDate from "mockdate"; | ||
|
||
import "../src/content/generated/global.out.css"; | ||
|
||
// mock all dates in stories to make sure we don't run into date-related inconsistencies | ||
MockDate.set("2023-01-01"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This'd be especially useful if we start using snapshots with Chromatic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious how this will interact with faker.js if we end up using it but something to worry about later. |
||
|
||
export const parameters = { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
controls: { | ||
matchers: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are included by default on installation, but they're useful! |
||
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
}, | ||
options: { | ||
storySort: { | ||
method: "alphabetical", | ||
order: [], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what the order should be yet since our component system is still in a limbo state. |
||
}, | ||
}, | ||
}; | ||
|
||
initializeWorker(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MSW isn't hooked up yet, but we might as well get it started 馃し |
||
|
||
function withRestHooksCacheProvider(Story) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add an all-in-one HOC like we do in tests, but I figure the granularity might be good. Not really an issue either way, though! |
||
return ( | ||
<CacheProvider> | ||
<Story /> | ||
</CacheProvider> | ||
); | ||
} | ||
|
||
function withRouter(Story) { | ||
return ( | ||
<BrowserRouter> | ||
<Story /> | ||
</BrowserRouter> | ||
); | ||
} | ||
|
||
function withHelmet(Story) { | ||
return ( | ||
<HelmetProvider> | ||
<Story /> | ||
</HelmetProvider> | ||
); | ||
} | ||
|
||
export const decorators = [ | ||
withHelmet, | ||
withRouter, | ||
withRestHooksCacheProvider, | ||
mswDecorator, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react"; | ||
import { ComponentMeta, ComponentStory } from "@storybook/react"; | ||
|
||
import { StaticAlert, StaticAlertType } from "./StaticAlert"; | ||
|
||
export default { | ||
title: "components/StaticAlert", | ||
component: StaticAlert, | ||
argTypes: { | ||
type: { | ||
control: { | ||
type: "radio", | ||
options: Object.values(StaticAlertType), | ||
}, | ||
}, | ||
}, | ||
} as ComponentMeta<typeof StaticAlert>; | ||
|
||
export const Default: ComponentStory<typeof StaticAlert> = (args) => ( | ||
<StaticAlert {...args} /> | ||
); | ||
Default.args = { | ||
type: StaticAlertType.Success, | ||
heading: "StaticAlert Heading", | ||
message: "This is the message of the StaticAlert", | ||
children: "Children are optional! (Try clearing me out)", | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from "react"; | ||
import { ComponentMeta, ComponentStory } from "@storybook/react"; | ||
|
||
import { USExtLink, USLink, USLinkButton } from "./USLink"; | ||
|
||
export default { | ||
title: "components/USLink", | ||
component: USLink, | ||
} as ComponentMeta<typeof USLink>; | ||
|
||
export const Default: ComponentStory<typeof USLink> = (args) => ( | ||
<USLink {...args} /> | ||
); | ||
Default.args = { | ||
className: "", | ||
children: "This is a link", | ||
}; | ||
|
||
export const Button: ComponentStory<typeof USLinkButton> = (args) => ( | ||
<USLinkButton {...args} /> | ||
); | ||
Button.args = { | ||
children: "This is a link styled as a button", | ||
secondary: false, | ||
base: false, | ||
inverse: false, | ||
unstyled: false, | ||
}; | ||
Button.argTypes = { | ||
accentStyle: { | ||
control: { | ||
type: "radio", | ||
options: ["", "cool", "warm"], | ||
}, | ||
}, | ||
size: { | ||
control: { | ||
type: "radio", | ||
options: ["", "big"], | ||
}, | ||
}, | ||
}; | ||
|
||
export const ExtLink: ComponentStory<typeof USExtLink> = (args) => ( | ||
<USExtLink {...args} /> | ||
); | ||
ExtLink.args = { | ||
className: "", | ||
children: "This is an external link", | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for later, but this might be a really nice package to see the states of different components without the need of dev tools: https://storybook.js.org/addons/storybook-addon-pseudo-states