@phsa.tec/design-system-react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +7 -0
- package/.storybook/main.ts +16 -0
- package/.storybook/preview.ts +15 -0
- package/README.md +36 -0
- package/components.json +21 -0
- package/jest.config.ts +25 -0
- package/next.config.ts +7 -0
- package/package.json +88 -0
- package/postcss.config.mjs +8 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/next.svg +1 -0
- package/public/vercel.svg +1 -0
- package/public/window.svg +1 -0
- package/src/app/columns.tsx +178 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/fonts/GeistMonoVF.woff +0 -0
- package/src/app/fonts/GeistVF.woff +0 -0
- package/src/app/globals.css +94 -0
- package/src/app/layout.tsx +35 -0
- package/src/app/page.tsx +7 -0
- package/src/components/actions/AlertDialog/AlertDialog.tsx +45 -0
- package/src/components/actions/AlertDialog/alert-dialog.stories.tsx +21 -0
- package/src/components/actions/AlertDialog/index.ts +1 -0
- package/src/components/actions/Button/Button.stories.ts +38 -0
- package/src/components/actions/Button/Button.tsx +23 -0
- package/src/components/actions/Button/index.ts +1 -0
- package/src/components/actions/Collapsible/index.ts +1 -0
- package/src/components/actions/Dialog/Dialog.stories.tsx +70 -0
- package/src/components/actions/Dialog/Dialog.tsx +87 -0
- package/src/components/actions/Dialog/components/DialogWithActions/index.tsx +40 -0
- package/src/components/actions/Dialog/index.ts +1 -0
- package/src/components/actions/Steps/Steps.stories.tsx +25 -0
- package/src/components/actions/Steps/Steps.tsx +51 -0
- package/src/components/actions/Steps/index.ts +1 -0
- package/src/components/actions/index.ts +5 -0
- package/src/components/dataDisplay/Avatar/Avatar.stories.tsx +22 -0
- package/src/components/dataDisplay/Avatar/Avatar.tsx +21 -0
- package/src/components/dataDisplay/Avatar/index.ts +2 -0
- package/src/components/dataDisplay/Badge/Badge.stories.tsx +36 -0
- package/src/components/dataDisplay/Badge/index.ts +1 -0
- package/src/components/dataDisplay/Card/Card.stories.tsx +24 -0
- package/src/components/dataDisplay/Card/Card.tsx +34 -0
- package/src/components/dataDisplay/Card/index.ts +1 -0
- package/src/components/dataDisplay/DataPairList/DataPairList.tsx +56 -0
- package/src/components/dataDisplay/DataPairList/data-pair-list.stories.tsx +87 -0
- package/src/components/dataDisplay/DataPairList/index.ts +2 -0
- package/src/components/dataDisplay/DataPairList/types.ts +10 -0
- package/src/components/dataDisplay/DropDownMenu/index.ts +1 -0
- package/src/components/dataDisplay/ErrorMessage/ErrorMessage.tsx +6 -0
- package/src/components/dataDisplay/ErrorMessage/index.ts +1 -0
- package/src/components/dataDisplay/Icon/Icon.stories.tsx +21 -0
- package/src/components/dataDisplay/Icon/Icon.tsx +47 -0
- package/src/components/dataDisplay/Icon/index.ts +1 -0
- package/src/components/dataDisplay/Icon/types.ts +6 -0
- package/src/components/dataDisplay/Label/Label.stories.tsx +21 -0
- package/src/components/dataDisplay/Label/Label.tsx +10 -0
- package/src/components/dataDisplay/Label/index.ts +1 -0
- package/src/components/dataDisplay/Table/Table.tsx +173 -0
- package/src/components/dataDisplay/Table/columns.tsx +223 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-column-header.tsx +72 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-pagination.tsx +91 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-toolbar.tsx +17 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-view-options.tsx +58 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table.stories.tsx +118 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/index.tsx +136 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/types.ts +43 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-column-header.tsx +71 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-faceted-filter.tsx +147 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-pagination.tsx +97 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-row-actions.tsx +78 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-toolbar.tsx +60 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-view-options.tsx +59 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table.tsx +145 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data.ts +71 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/index.tsx +34 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/schema.ts +11 -0
- package/src/components/dataDisplay/Table/index.ts +2 -0
- package/src/components/dataDisplay/Table/table.stories.tsx +147 -0
- package/src/components/dataDisplay/Table/types.ts +15 -0
- package/src/components/dataDisplay/Tabs/Tabs.stories.tsx +34 -0
- package/src/components/dataDisplay/Tabs/Tabs.tsx +53 -0
- package/src/components/dataDisplay/Tabs/index.ts +1 -0
- package/src/components/dataDisplay/Text/Text.stories.tsx +66 -0
- package/src/components/dataDisplay/Text/Text.tsx +56 -0
- package/src/components/dataDisplay/Text/index.ts +1 -0
- package/src/components/dataDisplay/index.ts +8 -0
- package/src/components/dataInput/Input/components/Input/Input.stories.tsx +99 -0
- package/src/components/dataInput/Input/components/Input/InputBase.tsx +50 -0
- package/src/components/dataInput/Input/components/Input/__tests__/Input.test.tsx +100 -0
- package/src/components/dataInput/Input/components/Input/index.tsx +257 -0
- package/src/components/dataInput/Input/components/InputBase/__tests__/InputBase.test.tsx +120 -0
- package/src/components/dataInput/Input/components/InputBase/index.tsx +89 -0
- package/src/components/dataInput/Input/components/MaskInput/__tests__/mask-input.test.tsx +67 -0
- package/src/components/dataInput/Input/components/MaskInput/index.ts +1 -0
- package/src/components/dataInput/Input/components/MaskInput/mask-input.stories.tsx +59 -0
- package/src/components/dataInput/Input/components/MaskInput/mask-input.tsx +43 -0
- package/src/components/dataInput/Input/components/MultipleInput/MultipleInput.tsx +36 -0
- package/src/components/dataInput/Input/components/MultipleInput/MultipleInputBase.tsx +100 -0
- package/src/components/dataInput/Input/components/MultipleInput/MultipleMaskInput.tsx +35 -0
- package/src/components/dataInput/Input/components/MultipleInput/MultipleNumberInput.tsx +35 -0
- package/src/components/dataInput/Input/components/MultipleInput/index.ts +2 -0
- package/src/components/dataInput/Input/components/MultipleInput/multiple-input.stories.tsx +71 -0
- package/src/components/dataInput/Input/components/NumberInput/__tests__/number-input.test.tsx +95 -0
- package/src/components/dataInput/Input/components/NumberInput/index.ts +1 -0
- package/src/components/dataInput/Input/components/NumberInput/number-input.stories.tsx +76 -0
- package/src/components/dataInput/Input/components/NumberInput/number-input.tsx +68 -0
- package/src/components/dataInput/Input/index.ts +4 -0
- package/src/components/dataInput/Select/MultiSelect/MultiSelect.stories.tsx +119 -0
- package/src/components/dataInput/Select/MultiSelect/MultiSelectBase.tsx +135 -0
- package/src/components/dataInput/Select/MultiSelect/index.tsx +75 -0
- package/src/components/dataInput/Select/Select.stories.tsx +61 -0
- package/src/components/dataInput/Select/Select.tsx +73 -0
- package/src/components/dataInput/Select/SelectBase.tsx +58 -0
- package/src/components/dataInput/Select/index.ts +2 -0
- package/src/components/dataInput/Switch/Switch.stories.tsx +75 -0
- package/src/components/dataInput/Switch/Switch.tsx +52 -0
- package/src/components/dataInput/Switch/index.ts +1 -0
- package/src/components/dataInput/checkbox/Checkbox.tsx +57 -0
- package/src/components/dataInput/checkbox/Checkbox_old.tsx +58 -0
- package/src/components/dataInput/checkbox/Checkout.stories.tsx +62 -0
- package/src/components/dataInput/checkbox/index.ts +1 -0
- package/src/components/dataInput/form/Form.tsx +47 -0
- package/src/components/dataInput/form/index.ts +3 -0
- package/src/components/dataInput/index.ts +5 -0
- package/src/components/feedback/Spinner/index.ts +1 -0
- package/src/components/feedback/Toast/Toast.stories.tsx +45 -0
- package/src/components/feedback/Toast/index.ts +2 -0
- package/src/components/feedback/index.ts +2 -0
- package/src/components/index.ts +6 -0
- package/src/components/layout/Crud/components/Table/index.tsx +183 -0
- package/src/components/layout/Crud/components/Table/types.ts +15 -0
- package/src/components/layout/Crud/crud.stories.tsx +317 -0
- package/src/components/layout/Crud/hook/useCrudLayout/index.tsx +94 -0
- package/src/components/layout/Crud/hook/useRequest/index.tsx +156 -0
- package/src/components/layout/Crud/index.tsx +295 -0
- package/src/components/layout/Crud/store/CrudLayoutStore.ts +75 -0
- package/src/components/layout/Crud/types.ts +14 -0
- package/src/components/layout/Drawer/CustomDrawer/index.tsx +33 -0
- package/src/components/layout/Drawer/Drawer.stories.tsx +80 -0
- package/src/components/layout/Drawer/index.ts +2 -0
- package/src/components/layout/PageLayout/PageLayout.stories.tsx +42 -0
- package/src/components/layout/PageLayout/index.tsx +28 -0
- package/src/components/layout/Separator/index.ts +1 -0
- package/src/components/layout/Sheet/Sheet.stories.tsx +28 -0
- package/src/components/layout/Sheet/Sheet.tsx +22 -0
- package/src/components/layout/Sheet/index.ts +1 -0
- package/src/components/layout/Sidebar/Sidebar.stories.tsx +116 -0
- package/src/components/layout/Sidebar/Sidebar.tsx +50 -0
- package/src/components/layout/Sidebar/components/app-sidebar.tsx +203 -0
- package/src/components/layout/Sidebar/components/footer-sidebar.tsx +17 -0
- package/src/components/layout/Sidebar/components/header-sidebar.tsx +90 -0
- package/src/components/layout/Sidebar/components/menus.tsx +55 -0
- package/src/components/layout/Sidebar/components/nav-projects.tsx +88 -0
- package/src/components/layout/Sidebar/components/nav-user.tsx +114 -0
- package/src/components/layout/Sidebar/components/team-switcher.tsx +85 -0
- package/src/components/layout/Sidebar/index.ts +2 -0
- package/src/components/layout/Sidebar/provider/index.tsx +51 -0
- package/src/components/layout/Tabs/Tabs.tsx +51 -0
- package/src/components/layout/Tabs/index.ts +1 -0
- package/src/components/layout/Tabs/tabs.stories.tsx +57 -0
- package/src/components/layout/index.ts +6 -0
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.tsx +66 -0
- package/src/components/navigation/Breadcrumbs/index.ts +2 -0
- package/src/components/navigation/index.ts +1 -0
- package/src/components/ui/alert-dialog.tsx +141 -0
- package/src/components/ui/alert.tsx +59 -0
- package/src/components/ui/avatar.tsx +50 -0
- package/src/components/ui/badge.tsx +40 -0
- package/src/components/ui/breadcrumb.tsx +115 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/card.tsx +83 -0
- package/src/components/ui/checkbox.tsx +34 -0
- package/src/components/ui/collapsible.tsx +11 -0
- package/src/components/ui/command.tsx +153 -0
- package/src/components/ui/dialog.tsx +124 -0
- package/src/components/ui/drawer.tsx +117 -0
- package/src/components/ui/dropdown-menu.tsx +201 -0
- package/src/components/ui/form.tsx +179 -0
- package/src/components/ui/input.tsx +24 -0
- package/src/components/ui/label.tsx +30 -0
- package/src/components/ui/popover.tsx +33 -0
- package/src/components/ui/select.tsx +161 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/sheet.tsx +140 -0
- package/src/components/ui/sidebar.tsx +763 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/sonner.tsx +31 -0
- package/src/components/ui/spinner.tsx +54 -0
- package/src/components/ui/switch.tsx +33 -0
- package/src/components/ui/table.tsx +120 -0
- package/src/components/ui/tabs.tsx +55 -0
- package/src/components/ui/toast.tsx +130 -0
- package/src/components/ui/toaster.tsx +35 -0
- package/src/components/ui/tooltip.tsx +32 -0
- package/src/hooks/use-mobile.tsx +19 -0
- package/src/hooks/use-toast.ts +191 -0
- package/src/index.ts +1 -0
- package/src/lib/utils.ts +6 -0
- package/tailwind.config.ts +83 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Label } from "../../../components/ui/label";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
FormField,
|
|
6
|
+
FormItem,
|
|
7
|
+
FormLabel,
|
|
8
|
+
FormControl,
|
|
9
|
+
FormMessage,
|
|
10
|
+
FormDescription,
|
|
11
|
+
} from "../../../components/ui/form";
|
|
12
|
+
import { SelectBase, SelectBaseProps } from "./SelectBase";
|
|
13
|
+
import { useFormContext } from "react-hook-form";
|
|
14
|
+
import { cn } from "../../../lib/utils";
|
|
15
|
+
import { ErrorMessage } from "../../../components/dataDisplay/ErrorMessage/ErrorMessage";
|
|
16
|
+
|
|
17
|
+
export type SelectProps = SelectBaseProps & {
|
|
18
|
+
label?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
error?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
withoutForm?: boolean;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const Select = ({
|
|
26
|
+
name,
|
|
27
|
+
label,
|
|
28
|
+
description,
|
|
29
|
+
error,
|
|
30
|
+
className,
|
|
31
|
+
withoutForm,
|
|
32
|
+
options,
|
|
33
|
+
placeholder,
|
|
34
|
+
...props
|
|
35
|
+
}: SelectProps) => {
|
|
36
|
+
const form = useFormContext();
|
|
37
|
+
const hasForm = !!form && !!name;
|
|
38
|
+
|
|
39
|
+
if (!hasForm || withoutForm) {
|
|
40
|
+
return (
|
|
41
|
+
<div className={cn("space-y-2", className)}>
|
|
42
|
+
{label && <Label>{label}</Label>}
|
|
43
|
+
<SelectBase options={options} placeholder={placeholder} {...props} />
|
|
44
|
+
{description && (
|
|
45
|
+
<p className="text-sm text-muted-foreground">{description}</p>
|
|
46
|
+
)}
|
|
47
|
+
{error && <ErrorMessage>{error}</ErrorMessage>}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<FormField
|
|
54
|
+
control={form.control}
|
|
55
|
+
name={name!}
|
|
56
|
+
render={({ field }) => (
|
|
57
|
+
<FormItem className={className}>
|
|
58
|
+
{label && <FormLabel>{label}</FormLabel>}
|
|
59
|
+
<FormControl>
|
|
60
|
+
<SelectBase
|
|
61
|
+
options={options}
|
|
62
|
+
placeholder={placeholder}
|
|
63
|
+
{...props}
|
|
64
|
+
{...field}
|
|
65
|
+
/>
|
|
66
|
+
</FormControl>
|
|
67
|
+
{description && <FormDescription>{description}</FormDescription>}
|
|
68
|
+
<FormMessage />
|
|
69
|
+
</FormItem>
|
|
70
|
+
)}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import {
|
|
3
|
+
Select,
|
|
4
|
+
SelectProps,
|
|
5
|
+
SelectContent,
|
|
6
|
+
SelectItem,
|
|
7
|
+
SelectTrigger,
|
|
8
|
+
SelectValue,
|
|
9
|
+
} from "../../../components/ui/select";
|
|
10
|
+
|
|
11
|
+
export type SelectBaseProps = Omit<SelectProps, "onValueChange"> & {
|
|
12
|
+
options: {
|
|
13
|
+
value: string | number;
|
|
14
|
+
label: string;
|
|
15
|
+
}[];
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
className?: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
onChange?: (value: string) => void;
|
|
20
|
+
value?: string;
|
|
21
|
+
onChangeCallback?: (value: string) => void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const SelectBase = ({
|
|
25
|
+
options,
|
|
26
|
+
placeholder,
|
|
27
|
+
onChange = () => {},
|
|
28
|
+
onChangeCallback = () => {},
|
|
29
|
+
value,
|
|
30
|
+
...rest
|
|
31
|
+
}: SelectBaseProps) => {
|
|
32
|
+
const onSelect = useCallback(
|
|
33
|
+
(value: string) => {
|
|
34
|
+
onChange(value);
|
|
35
|
+
onChangeCallback(value);
|
|
36
|
+
},
|
|
37
|
+
[onChange, onChangeCallback]
|
|
38
|
+
);
|
|
39
|
+
return (
|
|
40
|
+
<Select
|
|
41
|
+
{...rest}
|
|
42
|
+
onValueChange={onSelect}
|
|
43
|
+
defaultValue={value}
|
|
44
|
+
value={value}
|
|
45
|
+
>
|
|
46
|
+
<SelectTrigger>
|
|
47
|
+
<SelectValue placeholder={placeholder} />
|
|
48
|
+
</SelectTrigger>
|
|
49
|
+
<SelectContent>
|
|
50
|
+
{options?.map((option, index: number) => (
|
|
51
|
+
<SelectItem key={index} value={String(option.value)}>
|
|
52
|
+
{option.label}
|
|
53
|
+
</SelectItem>
|
|
54
|
+
))}
|
|
55
|
+
</SelectContent>
|
|
56
|
+
</Select>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/nextjs";
|
|
2
|
+
import { Switch } from "./index";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Form } from "../form";
|
|
5
|
+
import { useForm } from "react-hook-form";
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof Switch> = {
|
|
8
|
+
title: "Data Input/Switch",
|
|
9
|
+
component: Switch,
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof Switch>;
|
|
15
|
+
|
|
16
|
+
const SwitchWithHooks = () => {
|
|
17
|
+
const [checked, setChecked] = useState(false);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Switch
|
|
21
|
+
label="Notifications"
|
|
22
|
+
checked={checked}
|
|
23
|
+
onCheckedChange={setChecked}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const Default: Story = {
|
|
29
|
+
render: () => <SwitchWithHooks />,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const WithoutLabel: Story = {
|
|
33
|
+
render: () => {
|
|
34
|
+
const [checked, setChecked] = useState(false);
|
|
35
|
+
|
|
36
|
+
return <Switch checked={checked} onCheckedChange={setChecked} />;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const Checked: Story = {
|
|
41
|
+
render: () => {
|
|
42
|
+
const [checked, setChecked] = useState(true);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Switch
|
|
46
|
+
label="Active status"
|
|
47
|
+
checked={checked}
|
|
48
|
+
onCheckedChange={setChecked}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const WithForm: Story = {
|
|
55
|
+
args: {
|
|
56
|
+
name: "switch",
|
|
57
|
+
label: "Terms and Conditions",
|
|
58
|
+
required: true,
|
|
59
|
+
},
|
|
60
|
+
decorators: [
|
|
61
|
+
(Story: React.ComponentType) => {
|
|
62
|
+
const form = useForm({
|
|
63
|
+
defaultValues: {
|
|
64
|
+
switch: true,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Form {...form}>
|
|
70
|
+
<Story />
|
|
71
|
+
</Form>
|
|
72
|
+
);
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Label } from "../../../components/ui/label";
|
|
2
|
+
import {
|
|
3
|
+
Switch as SwitchUI,
|
|
4
|
+
SwitchProps as SwitchUIProps,
|
|
5
|
+
} from "../../../components/ui/switch";
|
|
6
|
+
import { useFormContext } from "react-hook-form";
|
|
7
|
+
import {
|
|
8
|
+
FormControl,
|
|
9
|
+
FormField,
|
|
10
|
+
FormItem,
|
|
11
|
+
FormLabel,
|
|
12
|
+
} from "../../../components/ui/form";
|
|
13
|
+
import { cn } from "../../../lib/utils";
|
|
14
|
+
|
|
15
|
+
export type SwitchProps = SwitchUIProps & {
|
|
16
|
+
label?: string;
|
|
17
|
+
withoutForm?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function Switch({
|
|
21
|
+
label,
|
|
22
|
+
withoutForm,
|
|
23
|
+
className,
|
|
24
|
+
...props
|
|
25
|
+
}: SwitchProps) {
|
|
26
|
+
const form = useFormContext();
|
|
27
|
+
const hasForm = !!form && !withoutForm && !!props.name;
|
|
28
|
+
|
|
29
|
+
if (!hasForm)
|
|
30
|
+
return (
|
|
31
|
+
<div className="flex items-center space-x-2">
|
|
32
|
+
<SwitchUI {...props} />
|
|
33
|
+
{label && <Label htmlFor={props.id}>{label}</Label>}
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
return (
|
|
37
|
+
<FormField
|
|
38
|
+
control={form.control}
|
|
39
|
+
name={props.name ?? ""}
|
|
40
|
+
render={({ field }) => (
|
|
41
|
+
<FormItem
|
|
42
|
+
className={cn(className, "flex items-center space-x-2 space-y-0")}
|
|
43
|
+
>
|
|
44
|
+
<FormControl>
|
|
45
|
+
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
|
46
|
+
</FormControl>
|
|
47
|
+
<FormLabel>{label}</FormLabel>
|
|
48
|
+
</FormItem>
|
|
49
|
+
)}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Switch";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useFormContext } from "react-hook-form";
|
|
2
|
+
import {
|
|
3
|
+
Checkbox as CheckboxUI,
|
|
4
|
+
CheckboxProps as CheckboxUIProps,
|
|
5
|
+
} from "../../ui/checkbox";
|
|
6
|
+
import { Label } from "../../../components/ui/label";
|
|
7
|
+
|
|
8
|
+
import { FormControl, FormField, FormItem, FormLabel } from "../form";
|
|
9
|
+
|
|
10
|
+
import { ErrorMessage } from "../../../components/dataDisplay/ErrorMessage";
|
|
11
|
+
|
|
12
|
+
export type CheckboxProps = CheckboxUIProps & {
|
|
13
|
+
label: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
withoutForm?: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const Checkbox = ({
|
|
19
|
+
label,
|
|
20
|
+
error,
|
|
21
|
+
withoutForm,
|
|
22
|
+
...props
|
|
23
|
+
}: CheckboxProps) => {
|
|
24
|
+
const form = useFormContext();
|
|
25
|
+
|
|
26
|
+
const hasForm = !withoutForm && !!form && !!props.name;
|
|
27
|
+
if (!hasForm)
|
|
28
|
+
return (
|
|
29
|
+
<div className="flex items-center space-x-2">
|
|
30
|
+
<CheckboxUI {...props} />
|
|
31
|
+
{label && <Label htmlFor={props.id}>{label}</Label>}
|
|
32
|
+
{error && <ErrorMessage>{error}</ErrorMessage>}
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<FormField
|
|
38
|
+
control={form.control}
|
|
39
|
+
name={props.name ?? ""}
|
|
40
|
+
render={({ field }) => (
|
|
41
|
+
<FormItem className="flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4">
|
|
42
|
+
<FormControl>
|
|
43
|
+
<CheckboxUI
|
|
44
|
+
checked={field.value}
|
|
45
|
+
onCheckedChange={field.onChange}
|
|
46
|
+
/>
|
|
47
|
+
</FormControl>
|
|
48
|
+
{label && (
|
|
49
|
+
<div className="space-y-1 leading-none">
|
|
50
|
+
<FormLabel>{label}</FormLabel>
|
|
51
|
+
</div>
|
|
52
|
+
)}
|
|
53
|
+
</FormItem>
|
|
54
|
+
)}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Label } from "../../../components/ui/label";
|
|
2
|
+
import {
|
|
3
|
+
Checkbox as CheckboxUI,
|
|
4
|
+
CheckboxProps as CheckboxUIProps,
|
|
5
|
+
} from "../../ui/checkbox";
|
|
6
|
+
import { ErrorMessage } from "../../../components/dataDisplay/ErrorMessage";
|
|
7
|
+
import { FormControl } from "..";
|
|
8
|
+
import { FormField, FormItem, FormLabel } from "../form";
|
|
9
|
+
import { useFormContext } from "react-hook-form";
|
|
10
|
+
|
|
11
|
+
export type CheckboxProps = CheckboxUIProps & {
|
|
12
|
+
label: string;
|
|
13
|
+
error?: string;
|
|
14
|
+
withoutForm?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const Checkbox = ({
|
|
18
|
+
label,
|
|
19
|
+
error,
|
|
20
|
+
withoutForm,
|
|
21
|
+
...props
|
|
22
|
+
}: CheckboxProps) => {
|
|
23
|
+
const form = useFormContext();
|
|
24
|
+
|
|
25
|
+
const hasForm = !withoutForm && !!form && !!props.name;
|
|
26
|
+
// if (!hasForm)
|
|
27
|
+
// return (
|
|
28
|
+
// <div className="flex items-center space-x-2">
|
|
29
|
+
// <CheckboxUI {...props} />
|
|
30
|
+
// {label && <Label htmlFor={props.id}>{label}</Label>}
|
|
31
|
+
// {error && <ErrorMessage>{error}</ErrorMessage>}
|
|
32
|
+
// </div>
|
|
33
|
+
// );
|
|
34
|
+
|
|
35
|
+
return <></>;
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<FormField
|
|
39
|
+
control={form.control}
|
|
40
|
+
name={props.name ?? ""}
|
|
41
|
+
render={({ field }) => (
|
|
42
|
+
<FormItem className="flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4">
|
|
43
|
+
<FormControl>
|
|
44
|
+
<CheckboxUI
|
|
45
|
+
checked={field.value}
|
|
46
|
+
onCheckedChange={field.onChange}
|
|
47
|
+
/>
|
|
48
|
+
</FormControl>
|
|
49
|
+
{label && (
|
|
50
|
+
<div className="space-y-1 leading-none">
|
|
51
|
+
<FormLabel>{label}</FormLabel>
|
|
52
|
+
</div>
|
|
53
|
+
)}
|
|
54
|
+
</FormItem>
|
|
55
|
+
)}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/nextjs";
|
|
2
|
+
import { Checkbox } from "./Checkbox";
|
|
3
|
+
import { Form } from "../form";
|
|
4
|
+
import { useForm } from "react-hook-form";
|
|
5
|
+
|
|
6
|
+
type Story = StoryObj<typeof Checkbox>;
|
|
7
|
+
|
|
8
|
+
const meta = {
|
|
9
|
+
title: "Data Input/Checkbox",
|
|
10
|
+
component: Checkbox,
|
|
11
|
+
tags: ["autodocs"],
|
|
12
|
+
args: {
|
|
13
|
+
label: "Accept terms and conditions",
|
|
14
|
+
},
|
|
15
|
+
} satisfies Meta<typeof Checkbox>;
|
|
16
|
+
|
|
17
|
+
export default meta;
|
|
18
|
+
|
|
19
|
+
export const Default: Story = {
|
|
20
|
+
args: {
|
|
21
|
+
label: "Accept terms and conditions",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const Checked: Story = {
|
|
26
|
+
args: {
|
|
27
|
+
label: "Accept terms and conditions",
|
|
28
|
+
checked: true,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Disabled: Story = {
|
|
33
|
+
args: {
|
|
34
|
+
label: "Accept terms and conditions",
|
|
35
|
+
disabled: true,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const DisabledChecked: Story = {
|
|
40
|
+
args: {
|
|
41
|
+
label: "Accept terms and conditions",
|
|
42
|
+
disabled: true,
|
|
43
|
+
checked: true,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const WithForm: Story = {
|
|
48
|
+
args: {
|
|
49
|
+
label: "Accept terms and conditions",
|
|
50
|
+
},
|
|
51
|
+
decorators: [
|
|
52
|
+
(Story: React.ComponentType) => {
|
|
53
|
+
const form = useForm();
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Form {...form}>
|
|
57
|
+
<Story />
|
|
58
|
+
</Form>
|
|
59
|
+
);
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Checkbox";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import {
|
|
3
|
+
FormControl,
|
|
4
|
+
FormField,
|
|
5
|
+
FormItem,
|
|
6
|
+
FormLabel,
|
|
7
|
+
FormMessage,
|
|
8
|
+
} from "./index";
|
|
9
|
+
import {
|
|
10
|
+
ControllerRenderProps,
|
|
11
|
+
FieldValues,
|
|
12
|
+
useFormContext,
|
|
13
|
+
} from "react-hook-form";
|
|
14
|
+
|
|
15
|
+
export type FormContainerProps = {
|
|
16
|
+
name: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
render: (
|
|
19
|
+
props?: ControllerRenderProps<FieldValues, string>
|
|
20
|
+
) => React.ReactNode;
|
|
21
|
+
className?: string;
|
|
22
|
+
};
|
|
23
|
+
export const FormContainer = ({
|
|
24
|
+
name,
|
|
25
|
+
label,
|
|
26
|
+
className,
|
|
27
|
+
render = () => <></>,
|
|
28
|
+
}: FormContainerProps) => {
|
|
29
|
+
const form = useFormContext();
|
|
30
|
+
const control = useMemo(() => form?.control, [form]);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<FormField
|
|
34
|
+
control={control}
|
|
35
|
+
name={name}
|
|
36
|
+
render={({ field }) => (
|
|
37
|
+
<FormItem className={className}>
|
|
38
|
+
<FormItem className={className}>
|
|
39
|
+
{label && <FormLabel>{label}</FormLabel>}
|
|
40
|
+
<FormControl>{render && render(field)}</FormControl>
|
|
41
|
+
</FormItem>
|
|
42
|
+
<FormMessage />
|
|
43
|
+
</FormItem>
|
|
44
|
+
)}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../ui/spinner";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/nextjs";
|
|
3
|
+
import { fn } from "storybook/test";
|
|
4
|
+
import { Button } from "../../../components/actions";
|
|
5
|
+
import { Toaster, useToast } from "./index";
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: "DataInput/Toast",
|
|
9
|
+
component: Toaster,
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: "centered",
|
|
12
|
+
},
|
|
13
|
+
tags: ["autodocs"],
|
|
14
|
+
args: { onClick: fn() },
|
|
15
|
+
} satisfies Meta<typeof Toaster>;
|
|
16
|
+
|
|
17
|
+
export default meta;
|
|
18
|
+
type Story = StoryObj<typeof meta>;
|
|
19
|
+
|
|
20
|
+
export const Default: Story = {
|
|
21
|
+
args: {
|
|
22
|
+
title: "Success",
|
|
23
|
+
description: "This is a success message",
|
|
24
|
+
variant: "default",
|
|
25
|
+
},
|
|
26
|
+
argTypes: {
|
|
27
|
+
descritpion: { control: { type: "text" } },
|
|
28
|
+
title: { control: { type: "text" } },
|
|
29
|
+
variant: {
|
|
30
|
+
control: {
|
|
31
|
+
type: "select",
|
|
32
|
+
},
|
|
33
|
+
options: ["default", "success", "destructive"],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
render: (args) => {
|
|
37
|
+
const { toast } = useToast();
|
|
38
|
+
return (
|
|
39
|
+
<div className="w-[500px] h-[500px]">
|
|
40
|
+
<Button onClick={() => toast(args)}>Success</Button>
|
|
41
|
+
<Toaster />
|
|
42
|
+
</div>
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
};
|