Skip to content
Merged
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
160 changes: 160 additions & 0 deletions src/components/MUI/DataDisplay/SvgIcon.stories.tsx
Comment thread
zoharma marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import type { Meta, StoryObj } from "@storybook/react";
import { SvgIcon, IconButton, Stack } from "../MuiWrapped";

const meta: Meta<typeof SvgIcon> = {
title: "MUI/Data Display/SvgIcon",
component: SvgIcon,
tags: ["autodocs"],
parameters: {
controls: { expanded: true },
layout: "padded",
},
argTypes: {
color: {
control: "select",
options: [
"inherit",
"primary",
"secondary",
"action",
"disabled",
"error",
"info",
"success",
"warning",
],
description: "Applies theme color",
},
fontSize: {
control: "select",
options: ["inherit", "small", "medium", "large"],
description: "Applies theme size preset",
},
viewBox: {
control: "text",
description: "ViewBox for the SVG; default is '0 0 24 24'",
},
inheritViewBox: {
control: "boolean",
description:
"If true, use the viewBox of the child SVG element rather than the default",
},
titleAccess: {
control: "text",
description:
"Adds a <title> element for accessibility (sets role='img' if provided)",
},
sx: {
control: "object",
description: "MUI `sx` prop",
},
},
args: {
color: "primary",
fontSize: "medium",
viewBox: "0 0 24 24",
inheritViewBox: false,
titleAccess: "Down arrow",
sx: undefined,
},
};
export default meta;

type Story = StoryObj<typeof meta>;

const d = "M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z";

export const Basic: Story = {
render: (args) => <SvgIcon {...args}>{<path d={d} />}</SvgIcon>,
};

export const Sizes: Story = {
render: (args) => (
<Stack direction="row" spacing={2} alignItems="center">
<SvgIcon {...args} fontSize="small">
{<path d={d} />}
</SvgIcon>
<SvgIcon {...args} fontSize="medium">
{<path d={d} />}
</SvgIcon>
<SvgIcon {...args} fontSize="large">
{<path d={d} />}
</SvgIcon>
<div style={{ fontSize: 32, display: "flex", alignItems: "center" }}>
<SvgIcon {...args} fontSize="inherit">
{<path d={d} />}
</SvgIcon>
</div>
</Stack>
),
};

export const Colors: Story = {
render: (args) => (
<Stack direction="row" spacing={2} alignItems="center">
<SvgIcon {...args} color="inherit">
{<path d={d} />}
</SvgIcon>
<SvgIcon {...args} color="primary">
{<path d={d} />}
</SvgIcon>
<SvgIcon {...args} color="secondary">
{<path d={d} />}
</SvgIcon>
<SvgIcon {...args} color="error">
{<path d={d} />}
</SvgIcon>
<SvgIcon {...args} color="warning">
{<path d={d} />}
</SvgIcon>
<SvgIcon {...args} color="info">
{<path d={d} />}
</SvgIcon>
<SvgIcon {...args} color="success">
{<path d={d} />}
</SvgIcon>
<SvgIcon {...args} color="action">
{<path d={d} />}
</SvgIcon>
<SvgIcon {...args} color="disabled">
{<path d={d} />}
</SvgIcon>
</Stack>
),
};

export const CustomViewBoxAndInherit: Story = {
args: {
viewBox: "0 0 48 48",
inheritViewBox: false,
titleAccess: "Custom viewBox icon",
},
render: (args) => (
<Stack direction="row" spacing={4} alignItems="center">
<SvgIcon {...args}>{<path d={d} />}</SvgIcon>
<SvgIcon {...args} inheritViewBox>
<svg viewBox="0 0 32 32">
<path d="M16 2l-6 10h4v8h4v-8h4L16 2z" />
</svg>
</SvgIcon>
</Stack>
),
};

export const InIconButton: Story = {
args: { color: "primary" },
render: (_args) => (
<Stack direction="row" spacing={2}>
<IconButton color="primary" aria-label="download">
<SvgIcon viewBox="0 0 24 24">
<path d="M5 20h14v-2H5v2zm7-18v12l4-4 1.41 1.41L12 18l-5.41-5.59L8 10l4 4V2h2z" />
</SvgIcon>
</IconButton>
<IconButton color="secondary" aria-label="arrow down">
<SvgIcon>
<path d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z" />
</SvgIcon>
</IconButton>
</Stack>
),
};
94 changes: 94 additions & 0 deletions src/components/MUI/Feedback/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type { Meta, StoryObj } from "@storybook/react";
import { Tooltip, IconButton } from "../MuiWrapped";
import InfoIcon from "@mui/icons-material/Info";

const meta: Meta<typeof Tooltip> = {
title: "MUI/Feedback/Tooltip",
component: Tooltip,
tags: ["autodocs"],
parameters: { controls: { expanded: true }, layout: "padded" },
argTypes: {
title: { control: "text" },
placement: {
control: "select",
options: [
"bottom",
"bottom-start",
"bottom-end",
"top",
"top-start",
"top-end",
"left",
"left-start",
"left-end",
"right",
"right-start",
"right-end",
],
},
arrow: { control: "boolean" },
disableInteractive: { control: "boolean" },
},
args: {
title: "Tooltip",
placement: "top",
arrow: true,
disableInteractive: false,
},
};
export default meta;
type Story = StoryObj<typeof meta>;

export const Basic: Story = {
render: (args) => (
<Tooltip {...args} title={args.title!}>
<IconButton aria-label="info">
<InfoIcon />
</IconButton>
</Tooltip>
),
};

export const Placements: Story = {
render: (args) => (
<div
style={{
display: "grid",
gap: 12,
gridTemplateColumns: "repeat(3, minmax(0, 1fr))",
placeItems: "center",
}}
>
<Tooltip {...args} title={args.title!} placement="top">
<IconButton>
<InfoIcon />
</IconButton>
</Tooltip>
<Tooltip {...args} title={args.title!} placement="right">
<IconButton>
<InfoIcon />
</IconButton>
</Tooltip>
<Tooltip {...args} title={args.title!} placement="bottom">
<IconButton>
<InfoIcon />
</IconButton>
</Tooltip>
<Tooltip {...args} title={args.title!} placement="left">
<IconButton>
<InfoIcon />
</IconButton>
</Tooltip>
<Tooltip {...args} title={args.title!} placement="top-start">
<IconButton>
<InfoIcon />
</IconButton>
</Tooltip>
<Tooltip {...args} title={args.title!} placement="top-end">
<IconButton>
<InfoIcon />
</IconButton>
</Tooltip>
</div>
),
};
52 changes: 45 additions & 7 deletions src/components/MUI/Inputs/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react";
import type { ComponentProps } from "react";

import {
AddIcon,
Box,
Expand All @@ -10,7 +12,22 @@ import {
} from "../MuiWrapped";
import { muiDocsParameters } from "../../../../.storybook/muiDocsParameters";

const meta: Meta<typeof Button> = {
const icons = {
none: null,
save: <SaveIcon />,
add: <AddIcon />,
send: <SendIcon />,
delete: <DeleteIcon />,
};

type IconName = keyof typeof icons;

type ButtonStoryProps = ComponentProps<typeof Button> & {
icon: IconName;
iconPosition: "start" | "end";
};

const meta: Meta<ButtonStoryProps> = {
title: "MUI/Inputs/Button",
component: Button,
tags: ["autodocs"],
Expand All @@ -36,6 +53,15 @@ const meta: Meta<typeof Button> = {
control: "select",
options: ["small", "medium", "large"],
},
icon: {
control: "select",
options: Object.keys(icons),
},
iconPosition: {
control: "radio",
options: ["start", "end"],
if: { arg: "icon", neq: "none" },
},
href: { control: "text" },
rel: { control: "text" },
children: { name: "label", control: "text" },
Expand All @@ -45,6 +71,8 @@ const meta: Meta<typeof Button> = {
variant: "contained",
color: "primary",
size: "medium",
icon: "none",
iconPosition: "start",
disabled: false,
disableElevation: false,
fullWidth: false,
Expand All @@ -57,11 +85,21 @@ export default meta;
type Story = StoryObj<typeof meta>;

export const Basic: Story = {
render: (args) => (
<Button {...args} href={args.href || undefined} rel={args.rel || undefined}>
{args.children}
</Button>
),
render: ({ icon = "none", iconPosition = "start", ...args }) => {
const iconElement = icons[icon as IconName];

return (
<Button
{...args}
startIcon={iconPosition === "start" ? iconElement : undefined}
endIcon={iconPosition === "end" ? iconElement : undefined}
href={args.href || undefined}
rel={args.rel || undefined}
>
{args.children}
</Button>
);
},
};

export const Variants: Story = {
Expand All @@ -76,7 +114,7 @@ export const Variants: Story = {

export const Sizes: Story = {
render: (_args) => (
<Stack direction="row" spacing={1}>
<Stack direction="row" spacing={1} alignItems="center">
<Button size="small" variant="contained">
Small
</Button>
Expand Down
Loading
Loading