@mbao01/common 0.0.7 → 0.0.8
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/dist/types/components/Avatar/types.d.ts +1 -0
- package/dist/types/components/Badge/types.d.ts +1 -0
- package/dist/types/components/Breadcrumbs/types.d.ts +1 -0
- package/dist/types/components/Combobox/Combobox.d.ts +2 -0
- package/dist/types/components/Combobox/index.d.ts +1 -0
- package/dist/types/components/Combobox/types.d.ts +19 -0
- package/dist/types/components/Command/Command.d.ts +67 -0
- package/dist/types/components/Command/constants.d.ts +11 -0
- package/dist/types/components/Command/index.d.ts +1 -0
- package/dist/types/components/Command/types.d.ts +8 -0
- package/dist/types/components/Description/types.d.ts +1 -0
- package/dist/types/components/Dialog/Dialog.d.ts +22 -0
- package/dist/types/components/Dialog/constants.d.ts +7 -0
- package/dist/types/components/Dialog/index.d.ts +1 -0
- package/dist/types/components/Dialog/types.d.ts +11 -0
- package/dist/types/components/Form/Checkbox/Checkbox.d.ts +6 -0
- package/dist/types/components/Form/Checkbox/constants.d.ts +4 -0
- package/dist/types/components/Form/Checkbox/index.d.ts +1 -0
- package/dist/types/components/Form/Checkbox/types.d.ts +4 -0
- package/dist/types/components/Form/Input/Input.d.ts +7 -0
- package/dist/types/components/Form/Input/constants.d.ts +6 -0
- package/dist/types/components/Form/Input/index.d.ts +1 -0
- package/dist/types/components/Form/Input/types.d.ts +4 -0
- package/dist/types/components/Form/Phone/Phone.d.ts +17 -0
- package/dist/types/components/Form/Phone/constants.d.ts +2 -0
- package/dist/types/components/Form/Phone/index.d.ts +1 -0
- package/dist/types/components/Form/Phone/types.d.ts +8 -0
- package/dist/types/components/Form/Radio/Radio.d.ts +6 -0
- package/dist/types/components/Form/Radio/constants.d.ts +4 -0
- package/dist/types/components/Form/Radio/index.d.ts +1 -0
- package/dist/types/components/Form/Radio/types.d.ts +4 -0
- package/dist/types/components/Form/Range/Range.d.ts +8 -0
- package/dist/types/components/Form/Range/constants.d.ts +6 -0
- package/dist/types/components/Form/Range/index.d.ts +1 -0
- package/dist/types/components/Form/Range/types.d.ts +4 -0
- package/dist/types/components/Form/Select/Select.d.ts +27 -0
- package/dist/types/components/Form/Select/constants.d.ts +17 -0
- package/dist/types/components/Form/Select/index.d.ts +1 -0
- package/dist/types/components/Form/Select/types.d.ts +7 -0
- package/dist/types/components/Form/Slider/Slider.d.ts +15 -0
- package/dist/types/components/Form/Slider/constants.d.ts +15 -0
- package/dist/types/components/Form/Slider/index.d.ts +1 -0
- package/dist/types/components/Form/Slider/types.d.ts +5 -0
- package/dist/types/components/Form/Switch/Switch.d.ts +6 -0
- package/dist/types/components/Form/Switch/constants.d.ts +4 -0
- package/dist/types/components/Form/Switch/index.d.ts +1 -0
- package/dist/types/components/Form/Switch/types.d.ts +4 -0
- package/dist/types/components/Form/TextField/TextField.d.ts +10 -0
- package/dist/types/components/Form/TextField/constants.d.ts +1 -0
- package/dist/types/components/Form/TextField/index.d.ts +1 -0
- package/dist/types/components/Form/TextField/types.d.ts +6 -0
- package/dist/types/components/Form/Textarea/Textarea.d.ts +8 -0
- package/dist/types/components/Form/Textarea/constants.d.ts +6 -0
- package/dist/types/components/Form/Textarea/index.d.ts +1 -0
- package/dist/types/components/Form/Textarea/types.d.ts +4 -0
- package/dist/types/components/Form/components/FormControl/FormControl.d.ts +2 -0
- package/dist/types/components/Form/components/FormControl/constants.d.ts +1 -0
- package/dist/types/components/Form/components/FormControl/index.d.ts +1 -0
- package/dist/types/components/Form/components/FormControl/types.d.ts +9 -0
- package/dist/types/components/Form/components/Label/Label.d.ts +7 -0
- package/dist/types/components/Form/components/Label/constants.d.ts +1 -0
- package/dist/types/components/Form/components/Label/index.d.ts +1 -0
- package/dist/types/components/Form/components/Label/types.d.ts +6 -0
- package/dist/types/components/Form/index.d.ts +11 -0
- package/dist/types/components/Loading/types.d.ts +1 -0
- package/dist/types/components/Popover/Popover.d.ts +9 -0
- package/dist/types/components/Popover/constants.d.ts +1 -0
- package/dist/types/components/Popover/index.d.ts +1 -0
- package/dist/types/components/Popover/types.d.ts +6 -0
- package/dist/types/components/Progress/types.d.ts +1 -0
- package/dist/types/components/Separator/types.d.ts +1 -0
- package/dist/types/components/Skeleton/types.d.ts +1 -0
- package/dist/types/components/Text/Text.d.ts +2 -2
- package/dist/types/components/Text/types.d.ts +6 -2
- package/dist/types/components/Tooltip/types.d.ts +1 -0
- package/dist/types/index.d.ts +6 -0
- package/package.json +21 -13
- package/src/components/Combobox/Combobox.tsx +82 -0
- package/src/components/Combobox/index.ts +1 -0
- package/src/components/Combobox/types.ts +21 -0
- package/src/components/Command/Command.tsx +142 -0
- package/src/components/Command/constants.ts +39 -0
- package/src/components/Command/index.ts +1 -0
- package/src/components/Command/types.ts +16 -0
- package/src/components/Dialog/Dialog.tsx +105 -0
- package/src/components/Dialog/constants.ts +27 -0
- package/src/components/Dialog/index.ts +1 -0
- package/src/components/Dialog/types.ts +40 -0
- package/src/components/Form/Checkbox/Checkbox.tsx +18 -0
- package/src/components/Form/Checkbox/constants.ts +21 -0
- package/src/components/Form/Checkbox/index.ts +1 -0
- package/src/components/Form/Checkbox/types.ts +8 -0
- package/src/components/Form/Input/Input.tsx +18 -0
- package/src/components/Form/Input/constants.ts +37 -0
- package/src/components/Form/Input/index.ts +1 -0
- package/src/components/Form/Input/types.ts +8 -0
- package/src/components/Form/Phone/Phone.tsx +120 -0
- package/src/components/Form/Phone/constants.ts +7 -0
- package/src/components/Form/Phone/index.ts +1 -0
- package/src/components/Form/Phone/types.ts +12 -0
- package/src/components/Form/Radio/Radio.tsx +18 -0
- package/src/components/Form/Radio/constants.ts +21 -0
- package/src/components/Form/Radio/index.ts +1 -0
- package/src/components/Form/Radio/types.ts +8 -0
- package/src/components/Form/Range/Range.tsx +22 -0
- package/src/components/Form/Range/constants.ts +31 -0
- package/src/components/Form/Range/index.ts +1 -0
- package/src/components/Form/Range/types.ts +8 -0
- package/src/components/Form/Select/Select.tsx +151 -0
- package/src/components/Form/Select/constants.ts +80 -0
- package/src/components/Form/Select/index.ts +1 -0
- package/src/components/Form/Select/types.ts +18 -0
- package/src/components/Form/Slider/Slider.tsx +43 -0
- package/src/components/Form/Slider/constants.ts +87 -0
- package/src/components/Form/Slider/index.ts +1 -0
- package/src/components/Form/Slider/types.ts +16 -0
- package/src/components/Form/Switch/Switch.tsx +19 -0
- package/src/components/Form/Switch/constants.ts +21 -0
- package/src/components/Form/Switch/index.ts +1 -0
- package/src/components/Form/Switch/types.ts +8 -0
- package/src/components/Form/TextField/TextField.tsx +37 -0
- package/src/components/Form/TextField/constants.ts +5 -0
- package/src/components/Form/TextField/index.ts +1 -0
- package/src/components/Form/TextField/types.ts +7 -0
- package/src/components/Form/Textarea/Textarea.tsx +22 -0
- package/src/components/Form/Textarea/constants.ts +37 -0
- package/src/components/Form/Textarea/index.ts +1 -0
- package/src/components/Form/Textarea/types.ts +8 -0
- package/src/components/Form/components/FormControl/FormControl.tsx +21 -0
- package/src/components/Form/components/FormControl/constants.ts +3 -0
- package/src/components/Form/components/FormControl/index.ts +1 -0
- package/src/components/Form/components/FormControl/types.ts +13 -0
- package/src/components/Form/components/Label/Label.tsx +22 -0
- package/src/components/Form/components/Label/constants.ts +3 -0
- package/src/components/Form/components/Label/index.ts +1 -0
- package/src/components/Form/components/Label/types.ts +10 -0
- package/src/components/Form/index.ts +11 -0
- package/src/components/Popover/Popover.tsx +30 -0
- package/src/components/Popover/constants.ts +5 -0
- package/src/components/Popover/index.ts +1 -0
- package/src/components/Popover/types.ts +12 -0
- package/src/components/Text/Text.tsx +3 -3
- package/src/components/Text/types.ts +8 -5
- package/src/index.ts +7 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
3
|
+
import { PopoverProps } from "./types";
|
|
4
|
+
declare const Popover: {
|
|
5
|
+
(props: PopoverProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
Content: React.ForwardRefExoticComponent<Omit<PopoverPrimitive.PopoverContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & import("class-variance-authority").VariantProps<(props?: import("class-variance-authority/types").ClassProp | undefined) => string> & React.RefAttributes<HTMLDivElement>>;
|
|
7
|
+
Trigger: React.ForwardRefExoticComponent<PopoverPrimitive.PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
8
|
+
};
|
|
9
|
+
export { Popover };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPopoverContentClasses: (props?: import("class-variance-authority/types").ClassProp | undefined) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Popover } from "./Popover";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
3
|
+
import { type VariantProps } from "../../libs";
|
|
4
|
+
import { getPopoverContentClasses } from "./constants";
|
|
5
|
+
export type PopoverProps = React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Root>;
|
|
6
|
+
export type PopoverContentProps = React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content> & VariantProps<typeof getPopoverContentClasses>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const Text: ({ as, size, variant, children, className, ...props }: TextProps) => import("react/jsx-runtime").JSX.Element;
|
|
1
|
+
import type { As, TextProps } from "./types";
|
|
2
|
+
export declare const Text: <T extends As>({ as, size, variant, children, className, ...props }: TextProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { type VariantProps } from "../../libs";
|
|
2
3
|
import { getTextClasses } from "./constants";
|
|
3
|
-
export type
|
|
4
|
-
|
|
4
|
+
export type As = "h1" | "h2" | "h3" | "h4" | "h5" | "p" | "span";
|
|
5
|
+
type AllowedElements = Pick<JSX.IntrinsicElements, As>;
|
|
6
|
+
export type TextProps<T extends As> = React.HTMLAttributes<HTMLElement & AllowedElements[T]> & VariantProps<typeof getTextClasses> & {
|
|
7
|
+
as?: As;
|
|
5
8
|
};
|
|
9
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,7 +10,13 @@ export * from "./components/Progress";
|
|
|
10
10
|
export * from "./components/Separator";
|
|
11
11
|
export * from "./components/Text";
|
|
12
12
|
/** data input */
|
|
13
|
+
export * from "./components/Form";
|
|
14
|
+
export * from "./components/Combobox";
|
|
13
15
|
/** feedback */
|
|
14
16
|
export * from "./components/Loading";
|
|
15
17
|
export * from "./components/Skeleton";
|
|
16
18
|
export * from "./components/Tooltip";
|
|
19
|
+
/** composable */
|
|
20
|
+
export * from "./components/Dialog";
|
|
21
|
+
export * from "./components/Command";
|
|
22
|
+
export * from "./components/Popover";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbao01/common",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Ayomide Bakare",
|
|
7
7
|
"license": "MIT",
|
|
@@ -61,27 +61,35 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@radix-ui/react-avatar": "^1.0.4",
|
|
64
|
+
"@radix-ui/react-checkbox": "^1.0.4",
|
|
65
|
+
"@radix-ui/react-dialog": "^1.0.5",
|
|
64
66
|
"@radix-ui/react-icons": "^1.3.0",
|
|
67
|
+
"@radix-ui/react-label": "^2.0.2",
|
|
68
|
+
"@radix-ui/react-popover": "^1.0.7",
|
|
65
69
|
"@radix-ui/react-progress": "^1.0.3",
|
|
70
|
+
"@radix-ui/react-select": "^2.0.0",
|
|
66
71
|
"@radix-ui/react-separator": "^1.0.3",
|
|
72
|
+
"@radix-ui/react-slider": "^1.1.2",
|
|
67
73
|
"@radix-ui/react-slot": "^1.0.2",
|
|
68
74
|
"@radix-ui/react-tooltip": "^1.0.7",
|
|
69
75
|
"class-variance-authority": "^0.7.0",
|
|
70
76
|
"clsx": "^2.1.0",
|
|
77
|
+
"cmdk": "^1.0.0",
|
|
71
78
|
"daisyui": "^4.6.2",
|
|
79
|
+
"react-international-phone": "^4.2.6",
|
|
72
80
|
"tailwind-merge": "^2.2.1",
|
|
73
81
|
"tailwindcss-animate": "^1.0.7"
|
|
74
82
|
},
|
|
75
83
|
"devDependencies": {
|
|
76
|
-
"@storybook/addon-essentials": "^
|
|
77
|
-
"@storybook/addon-interactions": "^
|
|
78
|
-
"@storybook/addon-links": "^
|
|
79
|
-
"@storybook/addon-onboarding": "^
|
|
80
|
-
"@storybook/addon-themes": "^
|
|
81
|
-
"@storybook/blocks": "^
|
|
82
|
-
"@storybook/react": "^
|
|
83
|
-
"@storybook/react-vite": "^
|
|
84
|
-
"@storybook/test": "^
|
|
84
|
+
"@storybook/addon-essentials": "^8.0.6",
|
|
85
|
+
"@storybook/addon-interactions": "^8.0.6",
|
|
86
|
+
"@storybook/addon-links": "^8.0.6",
|
|
87
|
+
"@storybook/addon-onboarding": "^8.0.6",
|
|
88
|
+
"@storybook/addon-themes": "^8.0.6",
|
|
89
|
+
"@storybook/blocks": "^8.0.6",
|
|
90
|
+
"@storybook/react": "^8.0.6",
|
|
91
|
+
"@storybook/react-vite": "^8.0.6",
|
|
92
|
+
"@storybook/test": "^8.0.6",
|
|
85
93
|
"@testing-library/jest-dom": "^6.4.2",
|
|
86
94
|
"@testing-library/react": "^14.2.1",
|
|
87
95
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -98,14 +106,14 @@
|
|
|
98
106
|
"eslint-plugin-react": "^7.33.2",
|
|
99
107
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
100
108
|
"eslint-plugin-react-refresh": "^0.4.5",
|
|
101
|
-
"eslint-plugin-storybook": "^0.
|
|
109
|
+
"eslint-plugin-storybook": "^0.8.0",
|
|
102
110
|
"jsdom": "^23.2.0",
|
|
103
111
|
"path": "^0.12.7",
|
|
104
112
|
"postcss": "^8.4.35",
|
|
105
113
|
"react": "^18.2.0",
|
|
106
114
|
"react-dom": "^18.2.0",
|
|
107
115
|
"react-router-dom": "^6.22.0",
|
|
108
|
-
"storybook": "^
|
|
116
|
+
"storybook": "^8.0.6",
|
|
109
117
|
"tailwindcss": "^3.4.1",
|
|
110
118
|
"typescript": "^5.3.3",
|
|
111
119
|
"vite": "^5.1.1",
|
|
@@ -117,5 +125,5 @@
|
|
|
117
125
|
"react-dom": "^18.2.0",
|
|
118
126
|
"typescript": "^5.2.2"
|
|
119
127
|
},
|
|
120
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "b7bb9c19b245e54a221c02998dc7ec6815cead56"
|
|
121
129
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { CaretSortIcon, CheckIcon } from "@radix-ui/react-icons";
|
|
5
|
+
import type { ComboboxProps, Item } from "./types";
|
|
6
|
+
import { cn } from "../../utilities";
|
|
7
|
+
import { Command } from "../Command";
|
|
8
|
+
import { Popover } from "../Popover";
|
|
9
|
+
import { Button } from "../Button";
|
|
10
|
+
|
|
11
|
+
export const Combobox = <T extends Item>({
|
|
12
|
+
label,
|
|
13
|
+
items,
|
|
14
|
+
classes,
|
|
15
|
+
emptyText,
|
|
16
|
+
placeholder,
|
|
17
|
+
getItemValue = (item: T) => item.value as string,
|
|
18
|
+
getItemLabel = (item: T) => item.label as string,
|
|
19
|
+
}: ComboboxProps<T>) => {
|
|
20
|
+
const [open, setOpen] = React.useState(false);
|
|
21
|
+
const [value, setValue] = React.useState<string | number | null>(null);
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
23
|
+
const [_, setItem] = React.useState<T | null>(null);
|
|
24
|
+
|
|
25
|
+
const currentItem = items?.find((item) => getItemValue(item) === value);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
29
|
+
<Popover.Trigger asChild>
|
|
30
|
+
<Button
|
|
31
|
+
outline
|
|
32
|
+
role="combobox"
|
|
33
|
+
aria-expanded={open}
|
|
34
|
+
className={cn("justify-between", classes?.trigger)}
|
|
35
|
+
>
|
|
36
|
+
{value && currentItem ? getItemLabel(currentItem) : label}
|
|
37
|
+
<CaretSortIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
|
38
|
+
</Button>
|
|
39
|
+
</Popover.Trigger>
|
|
40
|
+
<Popover.Content className={cn("w-[200px] p-0", classes?.popoverContent)}>
|
|
41
|
+
<Command className={cn(classes?.content)}>
|
|
42
|
+
<Command.Input
|
|
43
|
+
placeholder={placeholder}
|
|
44
|
+
className={cn(classes?.input)}
|
|
45
|
+
/>
|
|
46
|
+
<Command.Empty className={cn(classes?.empty)}>
|
|
47
|
+
{emptyText}
|
|
48
|
+
</Command.Empty>
|
|
49
|
+
<Command.List>
|
|
50
|
+
<Command.Group className={cn(classes?.group)}>
|
|
51
|
+
{items?.map((item) => (
|
|
52
|
+
<Command.Item
|
|
53
|
+
key={getItemValue(item)}
|
|
54
|
+
value={getItemValue(item)}
|
|
55
|
+
onSelect={(currentValue) => {
|
|
56
|
+
setValue(currentValue === value ? null : currentValue);
|
|
57
|
+
setItem(item);
|
|
58
|
+
setOpen(false);
|
|
59
|
+
}}
|
|
60
|
+
className={cn(
|
|
61
|
+
{
|
|
62
|
+
"bg-base-300": value === getItemValue(item),
|
|
63
|
+
},
|
|
64
|
+
classes?.item
|
|
65
|
+
)}
|
|
66
|
+
>
|
|
67
|
+
<CheckIcon
|
|
68
|
+
className={cn(
|
|
69
|
+
"mr-2 h-4 w-4",
|
|
70
|
+
value === getItemValue(item) ? "opacity-100" : "opacity-0"
|
|
71
|
+
)}
|
|
72
|
+
/>
|
|
73
|
+
{getItemLabel(item)}
|
|
74
|
+
</Command.Item>
|
|
75
|
+
))}
|
|
76
|
+
</Command.Group>
|
|
77
|
+
</Command.List>
|
|
78
|
+
</Command>
|
|
79
|
+
</Popover.Content>
|
|
80
|
+
</Popover>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Combobox } from "./Combobox";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
export type Item = Record<string, any>;
|
|
3
|
+
|
|
4
|
+
export type ComboboxProps<T extends Item> = {
|
|
5
|
+
label: string;
|
|
6
|
+
items: T[];
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
emptyText?: string;
|
|
9
|
+
getItemValue?: (item: T) => string;
|
|
10
|
+
getItemLabel?: (item: T) => string;
|
|
11
|
+
classes?: Partial<{
|
|
12
|
+
root: string;
|
|
13
|
+
trigger: string;
|
|
14
|
+
content: string;
|
|
15
|
+
input: string;
|
|
16
|
+
empty: string;
|
|
17
|
+
group: string;
|
|
18
|
+
item: string;
|
|
19
|
+
popoverContent: string;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/* eslint-disable react/prop-types */
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Command as CommandPrimitive } from "cmdk";
|
|
5
|
+
import { MagnifyingGlassIcon } from "@radix-ui/react-icons";
|
|
6
|
+
import type {
|
|
7
|
+
CommandProps,
|
|
8
|
+
CommandDialogProps,
|
|
9
|
+
CommandInputProps,
|
|
10
|
+
} from "./types";
|
|
11
|
+
import { Dialog } from "../Dialog";
|
|
12
|
+
import { cn } from "../../utilities";
|
|
13
|
+
import {
|
|
14
|
+
getDialogContentClasses,
|
|
15
|
+
getCommandClasses,
|
|
16
|
+
getCommandDialogClasses,
|
|
17
|
+
getCommandEmptyClasses,
|
|
18
|
+
getCommandInputClasses,
|
|
19
|
+
getCommandInputWrapperClasses,
|
|
20
|
+
getCommandListClasses,
|
|
21
|
+
getCommandGroupClasses,
|
|
22
|
+
getCommandSeparatorClasses,
|
|
23
|
+
getCommandItemClasses,
|
|
24
|
+
getCommandShortcutClasses,
|
|
25
|
+
} from "./constants";
|
|
26
|
+
|
|
27
|
+
const Command = ({ className, ...props }: CommandProps) => (
|
|
28
|
+
<CommandPrimitive className={cn(getCommandClasses(), className)} {...props} />
|
|
29
|
+
);
|
|
30
|
+
Command.displayName = CommandPrimitive.displayName;
|
|
31
|
+
|
|
32
|
+
const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
|
|
33
|
+
return (
|
|
34
|
+
<Dialog {...props}>
|
|
35
|
+
<Dialog.Content className={cn(getDialogContentClasses())}>
|
|
36
|
+
<Command className={cn(getCommandDialogClasses())}>{children}</Command>
|
|
37
|
+
</Dialog.Content>
|
|
38
|
+
</Dialog>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const CommandInput = React.forwardRef<
|
|
43
|
+
React.ElementRef<typeof CommandPrimitive.Input>,
|
|
44
|
+
CommandInputProps
|
|
45
|
+
>(({ className, ...props }, ref) => (
|
|
46
|
+
// eslint-disable-next-line react/no-unknown-property
|
|
47
|
+
<div className={cn(getCommandInputWrapperClasses())} cmdk-input-wrapper="">
|
|
48
|
+
<MagnifyingGlassIcon className="mr-2 h-4 w-4 shrink-0 opacity-50" />
|
|
49
|
+
<CommandPrimitive.Input
|
|
50
|
+
ref={ref}
|
|
51
|
+
className={cn(getCommandInputClasses(), className)}
|
|
52
|
+
{...props}
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
));
|
|
56
|
+
|
|
57
|
+
CommandInput.displayName = CommandPrimitive.Input.displayName;
|
|
58
|
+
|
|
59
|
+
const CommandList = React.forwardRef<
|
|
60
|
+
React.ElementRef<typeof CommandPrimitive.List>,
|
|
61
|
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
|
|
62
|
+
>(({ className, ...props }, ref) => (
|
|
63
|
+
<CommandPrimitive.List
|
|
64
|
+
ref={ref}
|
|
65
|
+
className={cn(getCommandListClasses(), className)}
|
|
66
|
+
{...props}
|
|
67
|
+
/>
|
|
68
|
+
));
|
|
69
|
+
|
|
70
|
+
CommandList.displayName = CommandPrimitive.List.displayName;
|
|
71
|
+
|
|
72
|
+
const CommandEmpty = React.forwardRef<
|
|
73
|
+
React.ElementRef<typeof CommandPrimitive.Empty>,
|
|
74
|
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
|
|
75
|
+
>(({ className, ...props }, ref) => (
|
|
76
|
+
<CommandPrimitive.Empty
|
|
77
|
+
ref={ref}
|
|
78
|
+
className={cn(getCommandEmptyClasses(), className)}
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
));
|
|
82
|
+
|
|
83
|
+
CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
|
|
84
|
+
|
|
85
|
+
const CommandGroup = React.forwardRef<
|
|
86
|
+
React.ElementRef<typeof CommandPrimitive.Group>,
|
|
87
|
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
|
|
88
|
+
>(({ className, ...props }, ref) => (
|
|
89
|
+
<CommandPrimitive.Group
|
|
90
|
+
ref={ref}
|
|
91
|
+
className={cn(getCommandGroupClasses(), className)}
|
|
92
|
+
{...props}
|
|
93
|
+
/>
|
|
94
|
+
));
|
|
95
|
+
|
|
96
|
+
CommandGroup.displayName = CommandPrimitive.Group.displayName;
|
|
97
|
+
|
|
98
|
+
const CommandSeparator = React.forwardRef<
|
|
99
|
+
React.ElementRef<typeof CommandPrimitive.Separator>,
|
|
100
|
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
|
|
101
|
+
>(({ className, ...props }, ref) => (
|
|
102
|
+
<CommandPrimitive.Separator
|
|
103
|
+
ref={ref}
|
|
104
|
+
className={cn(getCommandSeparatorClasses(), className)}
|
|
105
|
+
{...props}
|
|
106
|
+
/>
|
|
107
|
+
));
|
|
108
|
+
CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
|
|
109
|
+
|
|
110
|
+
const CommandItem = React.forwardRef<
|
|
111
|
+
React.ElementRef<typeof CommandPrimitive.Item>,
|
|
112
|
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
|
|
113
|
+
>(({ className, ...props }, ref) => (
|
|
114
|
+
<CommandPrimitive.Item
|
|
115
|
+
ref={ref}
|
|
116
|
+
className={cn(getCommandItemClasses(), className)}
|
|
117
|
+
{...props}
|
|
118
|
+
/>
|
|
119
|
+
));
|
|
120
|
+
|
|
121
|
+
CommandItem.displayName = CommandPrimitive.Item.displayName;
|
|
122
|
+
|
|
123
|
+
const CommandShortcut = ({
|
|
124
|
+
className,
|
|
125
|
+
...props
|
|
126
|
+
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
|
127
|
+
return (
|
|
128
|
+
<span className={cn(getCommandShortcutClasses(), className)} {...props} />
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
CommandShortcut.displayName = "CommandShortcut";
|
|
132
|
+
|
|
133
|
+
Command.Dialog = CommandDialog;
|
|
134
|
+
Command.Input = CommandInput;
|
|
135
|
+
Command.List = CommandList;
|
|
136
|
+
Command.Empty = CommandEmpty;
|
|
137
|
+
Command.Group = CommandGroup;
|
|
138
|
+
Command.Item = CommandItem;
|
|
139
|
+
Command.Shortcut = CommandShortcut;
|
|
140
|
+
Command.Separator = CommandSeparator;
|
|
141
|
+
|
|
142
|
+
export { Command };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { cva } from "../../libs";
|
|
2
|
+
|
|
3
|
+
export const getCommandClasses = cva(
|
|
4
|
+
"flex h-full w-full flex-col overflow-hidden rounded-md text-base-content"
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
export const getDialogContentClasses = cva("overflow-hidden p-0 shadow-lg");
|
|
8
|
+
|
|
9
|
+
export const getCommandDialogClasses = cva(
|
|
10
|
+
"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5"
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const getCommandInputWrapperClasses = cva(
|
|
14
|
+
"flex items-center border-b px-3"
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const getCommandInputClasses = cva(
|
|
18
|
+
"flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50"
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const getCommandListClasses = cva(
|
|
22
|
+
"max-h-[300px] overflow-y-auto overflow-x-hidden"
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const getCommandEmptyClasses = cva("py-6 text-center text-sm");
|
|
26
|
+
|
|
27
|
+
export const getCommandGroupClasses = cva(
|
|
28
|
+
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground"
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export const getCommandSeparatorClasses = cva("-mx-1 h-px bg-border");
|
|
32
|
+
|
|
33
|
+
export const getCommandItemClasses = cva(
|
|
34
|
+
"relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors aria-selected:bg-base-300 aria-selected:text-base-content aria-disabled:underline aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-disabled:cursor-default"
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export const getCommandShortcutClasses = cva(
|
|
38
|
+
"ml-auto text-xs tracking-widest text-muted-foreground"
|
|
39
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Command } from "./Command";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Command as CommandPrimitive } from "cmdk";
|
|
2
|
+
import { type DialogProps } from "../Dialog/types";
|
|
3
|
+
import { type VariantProps } from "../../libs";
|
|
4
|
+
import { getCommandClasses, getCommandInputClasses } from "./constants";
|
|
5
|
+
|
|
6
|
+
export type CommandProps = React.ComponentPropsWithoutRef<
|
|
7
|
+
typeof CommandPrimitive
|
|
8
|
+
> &
|
|
9
|
+
VariantProps<typeof getCommandClasses>;
|
|
10
|
+
|
|
11
|
+
export type CommandInputProps = React.ComponentPropsWithoutRef<
|
|
12
|
+
typeof CommandPrimitive.Input
|
|
13
|
+
> &
|
|
14
|
+
VariantProps<typeof getCommandInputClasses>;
|
|
15
|
+
|
|
16
|
+
export type CommandDialogProps = DialogProps;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
5
|
+
import { Cross2Icon } from "@radix-ui/react-icons";
|
|
6
|
+
import type {
|
|
7
|
+
DialogProps,
|
|
8
|
+
DialogFooterProps,
|
|
9
|
+
DialogHeaderProps,
|
|
10
|
+
DialogTitleProps,
|
|
11
|
+
DialogDescriptionProps,
|
|
12
|
+
DialogOverlayProps,
|
|
13
|
+
DialogContentProps,
|
|
14
|
+
} from "./types";
|
|
15
|
+
import { cn } from "../../utilities";
|
|
16
|
+
import {
|
|
17
|
+
getDialogCloseClasses,
|
|
18
|
+
getDialogContentClasses,
|
|
19
|
+
getDialogDescriptionClasses,
|
|
20
|
+
getDialogFooterClasses,
|
|
21
|
+
getDialogHeaderClasses,
|
|
22
|
+
getDialogOverlayClasses,
|
|
23
|
+
getDialogTitleClasses,
|
|
24
|
+
} from "./constants";
|
|
25
|
+
|
|
26
|
+
const Dialog = (props: DialogProps) => <DialogPrimitive.Root {...props} />;
|
|
27
|
+
|
|
28
|
+
const DialogOverlay = React.forwardRef<
|
|
29
|
+
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
|
30
|
+
DialogOverlayProps
|
|
31
|
+
>(({ className, ...props }, ref) => (
|
|
32
|
+
<DialogPrimitive.Overlay
|
|
33
|
+
ref={ref}
|
|
34
|
+
className={cn(getDialogOverlayClasses(), className)}
|
|
35
|
+
{...props}
|
|
36
|
+
/>
|
|
37
|
+
));
|
|
38
|
+
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
|
39
|
+
|
|
40
|
+
const DialogContent = React.forwardRef<
|
|
41
|
+
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
42
|
+
DialogContentProps
|
|
43
|
+
>(({ className, children, ...props }, ref) => (
|
|
44
|
+
<DialogPrimitive.Portal>
|
|
45
|
+
<DialogOverlay />
|
|
46
|
+
<DialogPrimitive.Content
|
|
47
|
+
ref={ref}
|
|
48
|
+
className={cn(getDialogContentClasses(), className)}
|
|
49
|
+
{...props}
|
|
50
|
+
>
|
|
51
|
+
{children}
|
|
52
|
+
<DialogPrimitive.Close className={cn(getDialogCloseClasses())}>
|
|
53
|
+
<Cross2Icon className="h-4 w-4" />
|
|
54
|
+
<span className="sr-only">Close</span>
|
|
55
|
+
</DialogPrimitive.Close>
|
|
56
|
+
</DialogPrimitive.Content>
|
|
57
|
+
</DialogPrimitive.Portal>
|
|
58
|
+
));
|
|
59
|
+
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
|
60
|
+
|
|
61
|
+
const DialogHeader = ({ className, ...props }: DialogHeaderProps) => (
|
|
62
|
+
<div className={cn(getDialogHeaderClasses(), className)} {...props} />
|
|
63
|
+
);
|
|
64
|
+
DialogHeader.displayName = "DialogHeader";
|
|
65
|
+
|
|
66
|
+
const DialogFooter = ({ className, ...props }: DialogFooterProps) => (
|
|
67
|
+
<div className={cn(getDialogFooterClasses(), className)} {...props} />
|
|
68
|
+
);
|
|
69
|
+
DialogFooter.displayName = "DialogFooter";
|
|
70
|
+
|
|
71
|
+
const DialogTitle = React.forwardRef<
|
|
72
|
+
React.ElementRef<typeof DialogPrimitive.Title>,
|
|
73
|
+
DialogTitleProps
|
|
74
|
+
>(({ className, ...props }, ref) => (
|
|
75
|
+
<DialogPrimitive.Title
|
|
76
|
+
ref={ref}
|
|
77
|
+
className={cn(getDialogTitleClasses(), className)}
|
|
78
|
+
{...props}
|
|
79
|
+
/>
|
|
80
|
+
));
|
|
81
|
+
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
|
82
|
+
|
|
83
|
+
const DialogDescription = React.forwardRef<
|
|
84
|
+
React.ElementRef<typeof DialogPrimitive.Description>,
|
|
85
|
+
DialogDescriptionProps
|
|
86
|
+
>(({ className, ...props }, ref) => (
|
|
87
|
+
<DialogPrimitive.Description
|
|
88
|
+
ref={ref}
|
|
89
|
+
className={cn(getDialogDescriptionClasses(), className)}
|
|
90
|
+
{...props}
|
|
91
|
+
/>
|
|
92
|
+
));
|
|
93
|
+
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
|
94
|
+
|
|
95
|
+
Dialog.Trigger = DialogPrimitive.Trigger;
|
|
96
|
+
Dialog.Portal = DialogPrimitive.Portal;
|
|
97
|
+
Dialog.Close = DialogPrimitive.Close;
|
|
98
|
+
Dialog.Header = DialogHeader;
|
|
99
|
+
Dialog.Title = DialogTitle;
|
|
100
|
+
Dialog.Description = DialogDescription;
|
|
101
|
+
Dialog.Content = DialogContent;
|
|
102
|
+
Dialog.Footer = DialogFooter;
|
|
103
|
+
Dialog.Overlay = DialogOverlay;
|
|
104
|
+
|
|
105
|
+
export { Dialog };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { cva } from "../../libs";
|
|
2
|
+
|
|
3
|
+
export const getDialogOverlayClasses = cva(
|
|
4
|
+
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
export const getDialogContentClasses = cva(
|
|
8
|
+
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-base-100 p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg"
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export const getDialogHeaderClasses = cva(
|
|
12
|
+
"flex flex-col space-y-1.5 text-center sm:text-left"
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const getDialogFooterClasses = cva(
|
|
16
|
+
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2"
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const getDialogTitleClasses = cva(
|
|
20
|
+
"text-lg font-semibold leading-none tracking-tight"
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const getDialogDescriptionClasses = cva("text-sm text-muted-foreground");
|
|
24
|
+
|
|
25
|
+
export const getDialogCloseClasses = cva(
|
|
26
|
+
"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"
|
|
27
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Dialog } from "./Dialog";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
2
|
+
import { type VariantProps } from "../../libs";
|
|
3
|
+
import {
|
|
4
|
+
getDialogContentClasses,
|
|
5
|
+
getDialogDescriptionClasses,
|
|
6
|
+
getDialogFooterClasses,
|
|
7
|
+
getDialogHeaderClasses,
|
|
8
|
+
getDialogOverlayClasses,
|
|
9
|
+
getDialogTitleClasses,
|
|
10
|
+
} from "./constants";
|
|
11
|
+
|
|
12
|
+
export type DialogProps = React.ComponentPropsWithoutRef<
|
|
13
|
+
typeof DialogPrimitive.Root
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
export type DialogOverlayProps = React.ComponentPropsWithoutRef<
|
|
17
|
+
typeof DialogPrimitive.Overlay
|
|
18
|
+
> &
|
|
19
|
+
VariantProps<typeof getDialogOverlayClasses>;
|
|
20
|
+
|
|
21
|
+
export type DialogContentProps = React.ComponentPropsWithoutRef<
|
|
22
|
+
typeof DialogPrimitive.Content
|
|
23
|
+
> &
|
|
24
|
+
VariantProps<typeof getDialogContentClasses>;
|
|
25
|
+
|
|
26
|
+
export type DialogHeaderProps = React.HTMLAttributes<HTMLDivElement> &
|
|
27
|
+
VariantProps<typeof getDialogHeaderClasses>;
|
|
28
|
+
|
|
29
|
+
export type DialogFooterProps = React.HTMLAttributes<HTMLDivElement> &
|
|
30
|
+
VariantProps<typeof getDialogFooterClasses>;
|
|
31
|
+
|
|
32
|
+
export type DialogTitleProps = React.ComponentPropsWithoutRef<
|
|
33
|
+
typeof DialogPrimitive.Title
|
|
34
|
+
> &
|
|
35
|
+
VariantProps<typeof getDialogTitleClasses>;
|
|
36
|
+
|
|
37
|
+
export type DialogDescriptionProps = React.ComponentPropsWithoutRef<
|
|
38
|
+
typeof DialogPrimitive.Description
|
|
39
|
+
> &
|
|
40
|
+
VariantProps<typeof getDialogDescriptionClasses>;
|