feat: add drawer playground

This commit is contained in:
p-sw 2024-08-04 14:59:36 +09:00
parent da1a53ba29
commit c5bf58b558
3 changed files with 62 additions and 22 deletions

View File

@ -1,26 +1,13 @@
import { TabProvider, TabTrigger, TabContent, TabList } from "@pswui/Tabs";
import { Story } from "@/components/Story";
import { LoadedCode, GITHUB_COMP, GITHUB_COMP_PREVIEW, GITHUB_STORY } from '@/components/LoadedCode';
import { DrawerDemo } from "./DrawerBlocks/Preview";
import Examples from "./DrawerBlocks/Examples";
import Playground from "./DrawerBlocks/Playground";
# Drawer
Displays a panel that slides out from the edge of the screen, typically used for navigation or additional content.
<TabProvider defaultName="preview">
<TabList>
<TabTrigger name="preview">Preview</TabTrigger>
<TabTrigger name="code">Code</TabTrigger>
</TabList>
<TabContent name="preview">
<Story layout="centered">
<DrawerDemo />
</Story>
</TabContent>
<TabContent name="code">
<LoadedCode from={GITHUB_COMP_PREVIEW("Drawer")} />
</TabContent>
</TabProvider>
<Playground />
## Installation
@ -41,7 +28,7 @@ import {
DrawerHeader,
DrawerBody,
DrawerFooter,
} from "@components/Drawer";
} from "@components/Drawer";
```
```html
@ -68,7 +55,7 @@ import {
```
> Note:
>
>
> DrawerTrigger and DrawerClose will merge its onClick event handler to its children.
> Also, there is no default element for those.
> So you always have to provide the clickable children for DialogTrigger and DialogClose.

View File

@ -0,0 +1,34 @@
import type { TEMPLATE } from "@/components/LoadedCode";
import { usePgProps } from "@/components/PgHooks";
import { PlaygroundLayout } from "@/components/Playground";
import { DrawerDemo, type DrawerDemoPlaygroundProps } from "./Preview";
interface TemplateProps extends TEMPLATE, DrawerDemoPlaygroundProps {}
export default function DrawerPlayground() {
const [props, control] = usePgProps<TemplateProps>({
DrawerRootProps: {
closeThreshold: {
type: "number",
value: 0.3,
},
},
DrawerContentProps: {
position: {
type: "select",
options: ["top", "bottom", "left", "right"],
value: "left",
},
},
});
return (
<PlaygroundLayout
compName="Drawer"
control={control}
props={props}
>
<DrawerDemo {...props} />
</PlaygroundLayout>
);
}

View File

@ -9,15 +9,34 @@ import {
DrawerRoot,
DrawerTrigger,
} from "@pswui/Drawer";
export const DrawerDemo = () => {
/* remove */
export interface DrawerDemoPlaygroundProps {
DrawerRootProps: {
closeThreshold: number;
};
DrawerContentProps: {
position: "top" | "bottom" | "left" | "right";
};
}
/* end */
/* replace */
export function DrawerDemo({
DrawerRootProps,
DrawerContentProps,
}: DrawerDemoPlaygroundProps) {
/* with
export function DrawerDemo() {
*/
return (
<DrawerRoot>
<DrawerRoot closeThreshold={DrawerRootProps.closeThreshold}>
<DrawerTrigger>
<Button>Open Drawer</Button>
</DrawerTrigger>
<DrawerOverlay className="z-[99]">
<DrawerContent className="max-w-[320px]">
<DrawerContent
className="max-w-[320px]"
position={DrawerContentProps.position}
>
<DrawerHeader>
<h1 className="text-2xl font-bold">Drawer</h1>
</DrawerHeader>
@ -37,4 +56,4 @@ export const DrawerDemo = () => {
</DrawerOverlay>
</DrawerRoot>
);
};
}