Skip to content

Commit

Permalink
feat(block): add tabs color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Sep 5, 2024
1 parent f299272 commit e1c0b5a
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 0 deletions.
25 changes: 25 additions & 0 deletions blocks/color-scheme-tabs-basic/ColorSchemeTabsBasic.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react";
import type { Meta, StoryObj } from "@storybook/react";
import googleFont from "../../.storybook/decorators/googleFont";
import storyDialog from "../../.storybook/decorators/storyDialog";
import Usage from "./usage.mdx";
import { ColorSchemeTabsBasic } from "./index";

const meta = {
title: "Color Scheme/Tabs/Basic",
component: ColorSchemeTabsBasic,
parameters: {
layout: "centered",
githubUsername: "siriwatknp", // (optional) Your github username. If provided, your avatar will be displayed in the story toolbar
},
decorators: [storyDialog(Usage), googleFont([])],
} satisfies Meta<typeof ColorSchemeTabsBasic>;

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

export const Basic: Story = {
render: () => <ColorSchemeTabsBasic />,
};


166 changes: 166 additions & 0 deletions blocks/color-scheme-tabs-basic/ColorSchemeTabsBasic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import React from "react";
import Box from "@mui/material/Box";
import FormControlLabel from "@mui/material/FormControlLabel";
import Radio, { radioClasses } from "@mui/material/Radio";
import RadioGroup from "@mui/material/RadioGroup";
import { useColorScheme } from "@mui/material/styles";

function System() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16" />
</svg>
);
}

function DarkMode() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
</svg>
);
}

function LightMode() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="4" />
<path d="M12 3v1" />
<path d="M12 20v1" />
<path d="M3 12h1" />
<path d="M20 12h1" />
<path d="m18.364 5.636-.707.707" />
<path d="m6.343 17.657-.707.707" />
<path d="m5.636 5.636.707.707" />
<path d="m17.657 17.657.707.707" />
</svg>
);
}

export function ColorSchemeTabsBasic() {
const { mode, setMode } = useColorScheme();
if (!mode) {
return (
<Box
sx={{
display: "grid",
alignItems: "center",
height: "44px",
gap: 1,
opacity: 0.5,
gridTemplateColumns: "repeat(3, 44px)",
placeItems: "center",
"& svg": {
transform: "scale(0.8)",
},
}}
>
<div>
<LightMode />
</div>
<div>
<System />
</div>
<div>
<DarkMode />
</div>
</Box>
);
}
return (
<RadioGroup
defaultValue="system"
row
aria-label="Color scheme"
name="color-scheme-segmented-control"
sx={{
display: "flex",
gap: 1,
"& svg": { transform: "scale(0.8)", transition: "0.2s" },
[`& .${radioClasses.checked} svg`]: { transform: "scale(1)" },
[`& .${radioClasses.root}`]: {
width: 44,
height: 44,
border: "1px solid transparent",
borderRadius: "8px",
[`&.${radioClasses.checked}`]: {
border: "1px solid",
borderColor: "divider",
color: "text.primary",
},
},
"& label": { margin: 0 },
}}
onChange={(event) => {
setMode(event.target.value as "light" | "system" | "dark");
}}
>
<FormControlLabel
value="light"
control={
<Radio
color="default"
disableTouchRipple
checkedIcon={<LightMode />}
icon={<LightMode />}
/>
}
label=""
/>
<FormControlLabel
value="system"
control={
<Radio
color="default"
disableTouchRipple
checkedIcon={<System />}
icon={<System />}
/>
}
label=""
/>
<FormControlLabel
value="dark"
control={
<Radio
color="default"
disableTouchRipple
checkedIcon={<DarkMode />}
icon={<DarkMode />}
/>
}
label=""
/>
</RadioGroup>
);
}
1 change: 1 addition & 0 deletions blocks/color-scheme-tabs-basic/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ColorSchemeTabsBasic";
14 changes: 14 additions & 0 deletions blocks/color-scheme-tabs-basic/usage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Meta, Source } from "@storybook/blocks";
import raw from "./ColorSchemeTabsBasic?raw";

<Meta title="ColorScheme/Tabs/Basic" />

## CLI

```sh
npx mui-treasury@latest clone color-scheme-tabs-basic
```

## ColorSchemeTabsBasic

<Source code={raw} language="tsx" />

0 comments on commit e1c0b5a

Please sign in to comment.