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

Add storybook-addon-jsx #123

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const addons = [
"@storybook/addon-interactions",
"@storybook/addon-designs",
"@storybook/addon-themes",
"storybook-addon-jsx",
];

if (process.env.NODE_ENV === "development") {
Expand Down
2 changes: 2 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { withThemeByClassName } from "@storybook/addon-themes";
import { Decorator, Parameters } from "@storybook/react";
import { jsxDecorator } from "storybook-addon-jsx";

import "@fontsource/inconsolata/700.css";
import "@fontsource/inter/400.css";
Expand Down Expand Up @@ -30,4 +31,5 @@ export const decorators: Decorator[] = [
},
defaultTheme: "light",
}),
jsxDecorator,
];
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"resize-observer-polyfill": "^1.5.1",
"rimraf": "^5.0.1",
"storybook": "^7.4.2",
"storybook-addon-jsx": "^7.3.14",
"stylelint": "^15.10.3",
"stylelint-config-standard": "^34.0.0",
"stylelint-plugin-defensive-css": "^0.9.1",
Expand Down
109 changes: 76 additions & 33 deletions src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import React from "react";
import { Meta, StoryFn } from "@storybook/react";
import { Meta } from "@storybook/react";

import { Button as ButtonComponent } from "./Button";
import VisibilityOnIcon from "@vector-im/compound-design-tokens/icons/visibility-on.svg";

type Props = {
kind?: "primary" | "secondary" | "tertiary" | "destructive";
size?: "sm" | "lg";
};

export default {
title: "Button",
component: ButtonComponent,
Expand All @@ -34,42 +28,91 @@ export default {
options: ["sm", "lg"],
control: { type: "inline-radio" },
},
kind: {
options: ["primary", "secondary", "tertiary", "destructive"],
control: { type: "inline-radio" },
},
disabled: {
type: "boolean",
},
as: {
control: { type: "text" },
},
Icon: {
options: [undefined, "VisibilityOnIcon"],
mapping: {
VisibilityOnIcon: VisibilityOnIcon,
undefined: undefined,
},
control: { type: "inline-radio" },
},
},
args: {
size: "sm",
size: "lg",
as: undefined,
disabled: false,
children: "Click me!",
},
} as Meta<typeof ButtonComponent>;

const Template: StoryFn<typeof ButtonComponent> = ({ kind, size }: Props) => (
<div style={{ display: "flex", gap: 8 }}>
<ButtonComponent kind={kind} size={size}>
Click me!
</ButtonComponent>
<ButtonComponent Icon={VisibilityOnIcon} kind={kind} size={size}>
Click me!
</ButtonComponent>
<ButtonComponent as="a" href="#" kind={kind} size={size}>
Click me!
</ButtonComponent>
</div>
);
export const Default = {
args: {
// test component defaults
kind: undefined,
size: undefined,
},
};

export const Small = {
args: {
// test component defaults
kind: undefined,
size: "sm",
},
};

export const Primary = {
args: {
kind: "primary",
},
};

export const Secondary = {
args: {
kind: "secondary",
},
};

export const Primary = Template.bind({});
Primary.args = {
kind: "primary",
export const Tertiary = {
args: {
kind: "tertiary",
},
};

export const Secondary = Template.bind({});
Secondary.args = {
kind: "secondary",
export const Destructive = {
args: {
kind: "destructive",
},
};

export const Tertiary = Template.bind({});
Tertiary.args = {
kind: "tertiary",
export const WithIcon = {
args: {
...Primary.args,
Icon: VisibilityOnIcon,
},
};

export const Destructive = Template.bind({});
Destructive.args = {
kind: "destructive",
export const SmallWithIcon = {
args: {
...Primary.args,
size: "sm",
Icon: VisibilityOnIcon,
},
};

export const Disabled = {
args: {
...Primary.args,
disabled: true,
},
};
41 changes: 31 additions & 10 deletions src/components/Link/Link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,43 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import React from "react";
import { Meta, StoryFn } from "@storybook/react";
import { Meta } from "@storybook/react";

import { Link as LinkComponent } from "./Link";

export default {
title: "Link",
component: LinkComponent,
tags: ["autodocs"],
argTypes: {},
args: {},
argTypes: {
kind: {
options: ["primary", "critical"],
control: { type: "inline-radio" },
},
},
args: {
children: "Text link",
},
parameters: {
design: {
type: "figma",
url: "https://www.figma.com/file/rTaQE2nIUSLav4Tg3nozq7/Compound-Web-Components?type=design&node-id=645-3494&mode=design&t=NC76puFaYAA5i3V4-0",
},
},
} as Meta<typeof LinkComponent>;

const Template: StoryFn<typeof LinkComponent> = (args) => (
<LinkComponent {...args}>Text link</LinkComponent>
);

export const Round = Template.bind({});
Round.args = {};
export const Default = {
// no args, test default kind
};

export const Primary = {
args: {
kind: "primary",
},
};

export const Critical = {
args: {
kind: "critical",
},
};
18 changes: 15 additions & 3 deletions src/components/Link/Link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ import { describe, it, expect } from "vitest";
import { render } from "@testing-library/react";
import React from "react";

import { Link } from "./Link";
import Meta, { Default, Primary, Critical } from "./Link.stories";
import { composeStory } from "@storybook/react";

describe("Link", () => {
it("renders", () => {
const { asFragment } = render(<Link />);
it("renders a primary link by default", () => {
const Component = composeStory(Default, Meta);
const { asFragment } = render(<Component />);
expect(asFragment()).toMatchSnapshot();
});
it("renders a primary link", () => {
const Component = composeStory(Primary, Meta);
const { asFragment } = render(<Component />);
expect(asFragment()).toMatchSnapshot();
});
it("renders a critical link", () => {
const Component = composeStory(Critical, Meta);
const { asFragment } = render(<Component />);
expect(asFragment()).toMatchSnapshot();
});
});
30 changes: 28 additions & 2 deletions src/components/Link/__snapshots__/Link.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Link > renders 1`] = `
exports[`Link > renders a critical link 1`] = `
<DocumentFragment>
<a
class="_link_379d57"
data-kind="critical"
rel="noreferrer noopener"
>
Text link
</a>
</DocumentFragment>
`;

exports[`Link > renders a primary link 1`] = `
<DocumentFragment>
<a
class="_link_379d57"
data-kind="primary"
rel="noreferrer noopener"
>
Text link
</a>
</DocumentFragment>
`;

exports[`Link > renders a primary link by default 1`] = `
<DocumentFragment>
<a
class="_link_379d57"
data-kind="primary"
rel="noreferrer noopener"
/>
>
Text link
</a>
</DocumentFragment>
`;
Loading
Loading