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

docs(popover, progresscircle, radio, rating, sidenav): site docs to storybook #2883

Merged
merged 10 commits into from
Sep 5, 2024
Prev Previous commit
Next Next commit
feat(storybook): maintain unique name and id args in sizes arggrid
Radios displayed with the Sizes() template were no longer grouped and
showing a selected radio within in group, because they all had the same
name. This addition to the ArgGrid() function makes sure that the id and
name args used for attributes have a unique string appended when the
template is rendered multiple times within the grid.
  • Loading branch information
jawinn committed Sep 5, 2024
commit a43cdc1630080f5a80a0d937d0e32e5593a3a5c5
17 changes: 13 additions & 4 deletions .storybook/decorators/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,21 @@ export const ArgGrid = ({
return Container({
heading,
direction,
content: options.map((opt) => Container({
content: options.map((opt, index) => Container({
heading: labels[opt] ?? capitalize(opt),
level,
withBorder,
wrapperStyles,
content: Template({ ...args, [argKey]: opt }, context)
content: Template({
...args,
[argKey]: opt,
/**
* Make sure stories in the testing grid maintain a unique "name" and "id", by appending an additional string.
* Important for labels associated with a control by ID, and for groups of radios to maintain the same name.
*/
...(typeof args?.name !== "undefined" ? {name: `${args.name}-${argKey}-${index}`} : {}),
...(typeof args?.id !== "undefined" ? {id: `${args.id}-${argKey}-${index}`} : {}),
jawinn marked this conversation as resolved.
Show resolved Hide resolved
}, context)
})),
});
};
Expand All @@ -241,11 +250,11 @@ export const ArgGrid = ({
*/
export const Sizes = ({
withHeading = true,
withBorder = false,
withBorder = false,
...args
} = {}, context = {}) => {
return ArgGrid({
withBorder,
withBorder,
heading: withHeading ? "Sizing" : undefined,
argKey: "size",
options: context?.argTypes?.size?.options,
Expand Down