Skip to content

Commit

Permalink
feat(doc): add ui component to storybook (wraft#13)
Browse files Browse the repository at this point in the history
* feat(doc): add errorBoundary storybook component

* feat(doc): add drawer storybook component

* fix: update ErrorBoundary

* feat(doc): add link Storybook component

* feat(doc): add onConfirm and onClose props to Modal component

* feat(doc): add modal storybook component

* feat(doc): add showPageSize and pageSizeLabel props to Paginate component

* feat(doc): add paginate storybook component

* fix(doc): export SkeletonProps interface in Skeleton component

* feat(doc): add skeleton storybook component

* feat(doc): add table storybook component

* feat(doc): add spinner storybook component

* refactor(doc): update spinner storybook component

* refactor(doc): update storybook component and styling in stories


* refactor(doc): Removed recent changes and restored the previous logic

* refactor(doc): Removed recent changes

* refactor(doc): Removed recent changes and restored the previous logic

* feat(doc): update skeleton storybook component

* refactor(doc): Removed recent changes and restored the previous logic

* feat(doc): update paginate  storybook component
  • Loading branch information
shahidvs authored Dec 31, 2024
1 parent 3e57e1a commit 37d1bf6
Show file tree
Hide file tree
Showing 13 changed files with 802 additions and 48 deletions.
2 changes: 1 addition & 1 deletion packages/ui/src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button } from ".";

const meta: Meta<typeof Button> = {
component: Button,
title: "Forms/Button",
title: "Action/Button",
argTypes: {
variant: {
control: "select",
Expand Down
99 changes: 99 additions & 0 deletions packages/ui/src/components/Drawer/Drawer.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Meta, StoryObj } from "@storybook/react";
import React from "react";

import { Button } from "../Button";

import { Drawer, DrawerOptions, useDrawer } from "./index";

export default {
title: "Overlay/Drawer",
component: Drawer,
decorators: [
(Story) => (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<Story />
</div>
),
],
parameters: {
layout: "centered",
},
argTypes: {
placement: {
control: {
type: "select",
},
options: ["top", "right", "bottom", "left"],
description: "Position of the drawer",
defaultValue: "right",
},
withBackdrop: {
control: {
type: "boolean",
},
description: "Show backdrop behind drawer",
defaultValue: true,
},
hideOnInteractOutside: {
control: {
type: "boolean",
},
description: "Close drawer when clicking outside",
defaultValue: true,
},
},
tags: ["autodocs"],
} as Meta<DrawerOptions>;

const DrawerDemo: React.FC<Partial<DrawerOptions>> = ({
placement = "right",
withBackdrop = true,
hideOnInteractOutside = true,
}) => {
const dialog = useDrawer();

return (
<>
<Button variant="primary" onClick={dialog.show}>
Open Drawer
</Button>
<Drawer
store={dialog}
placement={placement as DrawerOptions["placement"]}
withBackdrop={withBackdrop}
hideOnInteractOutside={hideOnInteractOutside}
>
<Drawer.Header>
<Drawer.Title>Drawer Title</Drawer.Title>
<button onClick={dialog.hide}></button>
</Drawer.Header>
<div style={{ padding: "2rem" }}>
<h4
style={{
marginBottom: "1rem",
fontSize: "1.125rem",
fontWeight: 500,
}}
>
Drawer Content
</h4>
<p>This is the content of the drawer. You can put anything here.</p>
</div>
</Drawer>
</>
);
};

export const Default: StoryObj<DrawerOptions> = {
render: () => <DrawerDemo />,
};

export const LeftPlacement: StoryObj<DrawerOptions> = {
render: () => <DrawerDemo placement="left" />,
};
56 changes: 26 additions & 30 deletions packages/ui/src/components/Drawer/styles.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import styled, { th } from '@xstyled/emotion';
import styled, { th } from "@xstyled/emotion";

import type { Placement } from '.';
import type { Placement } from ".";

const getPlacementStyle = (placement: Placement) => {
switch (placement) {
case 'top':
case "top":
return {
top: '0 !important',
top: "0 !important",
right: 0,
left: 0,
transform: 'translateY(-100%)',
transform: "translateY(-100%)",
};
case 'right':
case "right":
return {
top: '0 !important',
top: "0 !important",
right: 0,
bottom: 0,
transform: 'translateX(100%)',
transform: "translateX(100%)",
};
case 'bottom':
case "bottom":
return {
right: 0,
bottom: 0,
left: 0,
transform: 'translateY(100%)',
transform: "translateY(100%)",
};
case 'left':
case "left":
return {
top: '0 !important',
top: "0 !important",
bottom: 0,
left: 0,
transform: 'translateX(-100%)',
transform: "translateX(-100%)",
};
}
};
Expand Down Expand Up @@ -82,33 +82,29 @@ export const Drawer: any = styled.div`

// `

export const Backdrop: any =
styled.div <
any >
`
position: fixed;
top: 0;
right: 0;
left: 0;
bottom: 0;
opacity: 0;
transition: opacity 150ms ease-in-out;
background-color: rgba(0, 0, 0, 0.35);
${({ hideOnInteractOutside }) =>
hideOnInteractOutside &&
`
export const Backdrop: any = styled.div<any>`
position: fixed;
top: 0;
right: 0;
left: 0;
bottom: 0;
opacity: 0;
transition: opacity 150ms ease-in-out;
background-color: rgba(0, 0, 0, 0.35);
${({ hideOnInteractOutside }) =>
hideOnInteractOutside &&
`
cursor: pointer;
&[data-enter] {
opacity: 1;
}
`};
`;

export const Title: any = styled.divBox`
// padding: 0px 32px;
${th('drawers.title')};
${th("drawers.title")};
`;

export const Header: any = styled.divBox`
Expand Down
56 changes: 56 additions & 0 deletions packages/ui/src/components/ErrorBoundary/ErrorBoundary.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { Meta, StoryObj } from "@storybook/react";
import React from "react";

import ErrorBoundary from ".";

interface ErrorBoundaryComponentProps {
children: React.ReactNode;
message?: string;
}

const ErrorThrowingComponent = () => {
throw new Error("This is a test error.");
};

const NormalComponent = () => <div>Everything is working fine!</div>;

const meta: Meta<ErrorBoundaryComponentProps> = {
title: "Layout/ErrorBoundary",
component: ErrorBoundary,
tags: ["autodocs"],
argTypes: {
children: {
control: false,
},
message: {
control: { type: "text" },
description: "Custom error message to display",
},
},
};

export default meta;

type Story = StoryObj<ErrorBoundaryComponentProps>;

export const Default: Story = {
render: (args) => (
<ErrorBoundary {...args}>
<NormalComponent />
</ErrorBoundary>
),
args: {
message: "Something went wrong.",
},
};

export const WithError: Story = {
render: (args) => (
<ErrorBoundary {...args}>
<ErrorThrowingComponent />
</ErrorBoundary>
),
args: {
message: "Something went wrong.",
},
};
113 changes: 113 additions & 0 deletions packages/ui/src/components/Link/Link.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import type { Meta, StoryObj } from "@storybook/react";
import { HomeIcon, ArrowRightIcon } from "@wraft/icon";

import { Link } from "./index";

const meta: Meta<typeof Link> = {
title: "Action/Link",
component: Link,
parameters: {
layout: "centered",
},
tags: ["autodocs"],
argTypes: {
variant: {
control: { type: "select" },
options: ["primary", "secondary", "outlined", "disabled", "googleLogin"],
},
size: {
control: { type: "select" },
options: ["xxs", "xs", "sm", "md", "lg", "full"],
},
type: {
control: "radio",
options: ["link", "button"],
},
disabled: {
control: { type: "boolean" },
},
},
};

export default meta;
type Story = StoryObj<typeof Link>;

const Template: Story = {
args: {
type: "link",
},
};

export const SimpleLink: Story = {
...Template,
args: {
...Template.args,
children: "Click here to learn more",
variant: "outlined",
type: "link",
},
};

export const ButtonLink: Story = {
...Template,
args: {
...Template.args,
children: (
<span style={{ display: "flex", alignItems: "center", gap: "8px" }}>
Get Started
<ArrowRightIcon />
</span>
),
variant: "outlined",
type: "button",
size: "md",
},
};

export const IconLink: Story = {
...Template,
args: {
...Template.args,
children: (
<span style={{ display: "flex", alignItems: "center", gap: "8px" }}>
<HomeIcon />
View Documentation
</span>
),
variant: "outlined",
type: "link",
size: "sm",
},
};

export const DisabledLink: Story = {
...Template,
args: {
...Template.args,
children: "Not Available",
variant: "disabled",
type: "link",
disabled: true,
},
};

export const LinkVariant: Story = {
args: {
type: "link",
},
decorators: [
(Story, context) => (
<div style={{ display: "flex", flexDirection: "column", gap: "1rem" }}>
<Link {...context.args} variant="outlined" type="link">
Outlined Link
</Link>
<Link {...context.args} variant="primary" type="button">
Primary Button Link
</Link>
<Link {...context.args} variant="secondary" type="link">
Secondary Link
</Link>
</div>
),
],
};
Loading

0 comments on commit 37d1bf6

Please sign in to comment.