@auto-engineer/generate-react-client 1.64.0 → 1.65.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/CHANGELOG.md +21 -0
- package/dist/starter/.storybook/main.ts +17 -22
- package/dist/starter/.storybook/manager-head.html +31 -31
- package/dist/starter/.storybook/manager.ts +133 -133
- package/dist/starter/.storybook/preview-head.html +12 -12
- package/dist/starter/.storybook/preview.tsx +79 -79
- package/dist/starter/biome.json +126 -0
- package/dist/starter/codegen.ts +11 -11
- package/dist/starter/components.json +27 -27
- package/dist/starter/package.json +86 -80
- package/dist/starter/public/mockServiceWorker.js +261 -261
- package/dist/starter/scripts/build-component-db.ts +17 -20
- package/dist/starter/src/App.tsx +15 -17
- package/dist/starter/src/components/ui/Accordion.stories.tsx +35 -35
- package/dist/starter/src/components/ui/Accordion.tsx +33 -33
- package/dist/starter/src/components/ui/Alert.stories.tsx +15 -15
- package/dist/starter/src/components/ui/Alert.tsx +32 -32
- package/dist/starter/src/components/ui/AlertDialog.stories.tsx +50 -50
- package/dist/starter/src/components/ui/AlertDialog.tsx +114 -115
- package/dist/starter/src/components/ui/AspectRatio.stories.tsx +20 -20
- package/dist/starter/src/components/ui/AspectRatio.tsx +1 -1
- package/dist/starter/src/components/ui/Avatar.stories.tsx +27 -27
- package/dist/starter/src/components/ui/Avatar.tsx +63 -63
- package/dist/starter/src/components/ui/Badge.stories.tsx +14 -14
- package/dist/starter/src/components/ui/Badge.tsx +27 -27
- package/dist/starter/src/components/ui/Breadcrumb.stories.tsx +38 -38
- package/dist/starter/src/components/ui/Breadcrumb.tsx +63 -62
- package/dist/starter/src/components/ui/Button.stories.tsx +55 -55
- package/dist/starter/src/components/ui/Button.tsx +49 -49
- package/dist/starter/src/components/ui/ButtonGroup.stories.tsx +17 -17
- package/dist/starter/src/components/ui/ButtonGroup.tsx +52 -53
- package/dist/starter/src/components/ui/Calendar.stories.tsx +20 -19
- package/dist/starter/src/components/ui/Calendar.tsx +142 -143
- package/dist/starter/src/components/ui/Card.stories.tsx +29 -29
- package/dist/starter/src/components/ui/Card.tsx +31 -31
- package/dist/starter/src/components/ui/Carousel.stories.tsx +41 -41
- package/dist/starter/src/components/ui/Carousel.tsx +171 -172
- package/dist/starter/src/components/ui/Chart.stories.tsx +21 -21
- package/dist/starter/src/components/ui/Chart.tsx +244 -247
- package/dist/starter/src/components/ui/Checkbox.stories.tsx +11 -11
- package/dist/starter/src/components/ui/Checkbox.tsx +18 -18
- package/dist/starter/src/components/ui/Collapsible.stories.tsx +40 -40
- package/dist/starter/src/components/ui/Collapsible.tsx +3 -3
- package/dist/starter/src/components/ui/Combobox.stories.tsx +48 -48
- package/dist/starter/src/components/ui/Combobox.tsx +204 -205
- package/dist/starter/src/components/ui/Command.stories.tsx +55 -55
- package/dist/starter/src/components/ui/Command.tsx +102 -103
- package/dist/starter/src/components/ui/ContextMenu.stories.tsx +52 -52
- package/dist/starter/src/components/ui/ContextMenu.tsx +151 -151
- package/dist/starter/src/components/ui/DesignSystem-Colors.stories.tsx +92 -92
- package/dist/starter/src/components/ui/DesignSystem-Layout.stories.tsx +139 -139
- package/dist/starter/src/components/ui/DesignSystem-Overview.stories.tsx +676 -657
- package/dist/starter/src/components/ui/DesignSystem-Typography.stories.tsx +59 -59
- package/dist/starter/src/components/ui/Dialog.stories.tsx +56 -56
- package/dist/starter/src/components/ui/Dialog.tsx +97 -98
- package/dist/starter/src/components/ui/Direction.stories.tsx +20 -20
- package/dist/starter/src/components/ui/Direction.tsx +7 -7
- package/dist/starter/src/components/ui/Drawer.stories.tsx +54 -54
- package/dist/starter/src/components/ui/Drawer.tsx +70 -70
- package/dist/starter/src/components/ui/DropdownMenu.stories.tsx +58 -58
- package/dist/starter/src/components/ui/DropdownMenu.tsx +157 -157
- package/dist/starter/src/components/ui/Empty.stories.tsx +22 -22
- package/dist/starter/src/components/ui/Empty.tsx +58 -58
- package/dist/starter/src/components/ui/Field.stories.tsx +31 -31
- package/dist/starter/src/components/ui/Field.tsx +180 -181
- package/dist/starter/src/components/ui/Form.stories.tsx +29 -29
- package/dist/starter/src/components/ui/Form.tsx +93 -96
- package/dist/starter/src/components/ui/HoverCard.stories.tsx +34 -34
- package/dist/starter/src/components/ui/HoverCard.tsx +21 -21
- package/dist/starter/src/components/ui/Input.stories.tsx +18 -18
- package/dist/starter/src/components/ui/Input.tsx +14 -14
- package/dist/starter/src/components/ui/InputGroup.stories.tsx +34 -34
- package/dist/starter/src/components/ui/InputGroup.tsx +110 -111
- package/dist/starter/src/components/ui/InputOTP.stories.tsx +28 -28
- package/dist/starter/src/components/ui/InputOTP.tsx +43 -43
- package/dist/starter/src/components/ui/Item.stories.tsx +45 -45
- package/dist/starter/src/components/ui/Item.tsx +113 -114
- package/dist/starter/src/components/ui/Kbd.stories.tsx +31 -31
- package/dist/starter/src/components/ui/Kbd.tsx +11 -11
- package/dist/starter/src/components/ui/Label.stories.tsx +62 -62
- package/dist/starter/src/components/ui/Label.tsx +26 -25
- package/dist/starter/src/components/ui/Menubar.stories.tsx +62 -62
- package/dist/starter/src/components/ui/Menubar.tsx +173 -173
- package/dist/starter/src/components/ui/NativeSelect.stories.tsx +26 -26
- package/dist/starter/src/components/ui/NativeSelect.tsx +29 -29
- package/dist/starter/src/components/ui/NavigationMenu.stories.tsx +64 -64
- package/dist/starter/src/components/ui/NavigationMenu.tsx +103 -103
- package/dist/starter/src/components/ui/Pagination.stories.tsx +61 -61
- package/dist/starter/src/components/ui/Pagination.tsx +69 -71
- package/dist/starter/src/components/ui/Popover.stories.tsx +38 -38
- package/dist/starter/src/components/ui/Popover.tsx +25 -25
- package/dist/starter/src/components/ui/Progress.stories.tsx +9 -9
- package/dist/starter/src/components/ui/Progress.tsx +14 -14
- package/dist/starter/src/components/ui/RadioGroup.stories.tsx +35 -35
- package/dist/starter/src/components/ui/RadioGroup.tsx +19 -19
- package/dist/starter/src/components/ui/Resizable.stories.tsx +54 -54
- package/dist/starter/src/components/ui/Resizable.tsx +29 -29
- package/dist/starter/src/components/ui/ScrollArea.stories.tsx +27 -27
- package/dist/starter/src/components/ui/ScrollArea.tsx +34 -34
- package/dist/starter/src/components/ui/Select.stories.tsx +43 -43
- package/dist/starter/src/components/ui/Select.tsx +120 -120
- package/dist/starter/src/components/ui/Separator.stories.tsx +27 -27
- package/dist/starter/src/components/ui/Separator.tsx +17 -17
- package/dist/starter/src/components/ui/Sheet.stories.tsx +53 -53
- package/dist/starter/src/components/ui/Sheet.tsx +69 -69
- package/dist/starter/src/components/ui/Sidebar.stories.tsx +77 -77
- package/dist/starter/src/components/ui/Sidebar.tsx +563 -564
- package/dist/starter/src/components/ui/Skeleton.stories.tsx +25 -25
- package/dist/starter/src/components/ui/Skeleton.tsx +1 -1
- package/dist/starter/src/components/ui/Slider.stories.tsx +5 -5
- package/dist/starter/src/components/ui/Slider.tsx +45 -44
- package/dist/starter/src/components/ui/Sonner.stories.tsx +32 -32
- package/dist/starter/src/components/ui/Sonner.tsx +23 -23
- package/dist/starter/src/components/ui/Spinner.stories.tsx +8 -8
- package/dist/starter/src/components/ui/Spinner.tsx +1 -1
- package/dist/starter/src/components/ui/Switch.stories.tsx +16 -17
- package/dist/starter/src/components/ui/Switch.tsx +24 -24
- package/dist/starter/src/components/ui/Table.stories.tsx +50 -50
- package/dist/starter/src/components/ui/Table.tsx +45 -45
- package/dist/starter/src/components/ui/Tabs.stories.tsx +39 -39
- package/dist/starter/src/components/ui/Tabs.tsx +47 -47
- package/dist/starter/src/components/ui/Textarea.stories.tsx +9 -9
- package/dist/starter/src/components/ui/Textarea.tsx +11 -11
- package/dist/starter/src/components/ui/Toast.stories.tsx +77 -77
- package/dist/starter/src/components/ui/Toast.tsx +75 -75
- package/dist/starter/src/components/ui/Toaster.tsx +17 -19
- package/dist/starter/src/components/ui/Toggle.stories.tsx +20 -20
- package/dist/starter/src/components/ui/Toggle.tsx +26 -26
- package/dist/starter/src/components/ui/ToggleGroup.stories.tsx +41 -41
- package/dist/starter/src/components/ui/ToggleGroup.tsx +61 -62
- package/dist/starter/src/components/ui/Tooltip.stories.tsx +26 -26
- package/dist/starter/src/components/ui/Tooltip.tsx +24 -24
- package/dist/starter/src/gql/execute.ts +1 -1
- package/dist/starter/src/gql/fragment-masking.ts +1 -1
- package/dist/starter/src/gql/graphql.ts +3 -0
- package/dist/starter/src/hooks/use-mobile.ts +11 -11
- package/dist/starter/src/hooks/use-toast.ts +135 -135
- package/dist/starter/src/index.css +105 -105
- package/dist/starter/src/lib/utils.ts +1 -1
- package/dist/starter/src/main.tsx +4 -1
- package/dist/starter/tsconfig.app.json +24 -24
- package/dist/starter/tsconfig.json +8 -8
- package/dist/starter/vite.config.ts +38 -37
- package/package.json +3 -3
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import * as React from 'react';
|
|
4
3
|
import { cva, type VariantProps } from 'class-variance-authority';
|
|
5
4
|
import { XIcon } from 'lucide-react';
|
|
6
5
|
import { Toast as ToastPrimitive } from 'radix-ui';
|
|
6
|
+
import type * as React from 'react';
|
|
7
7
|
|
|
8
8
|
import { cn } from '@/lib/utils';
|
|
9
9
|
|
|
@@ -11,98 +11,98 @@ import { cn } from '@/lib/utils';
|
|
|
11
11
|
|
|
12
12
|
/** Provides the toast context for managing toast state and swipe behavior. */
|
|
13
13
|
function ToastProvider({ ...props }: React.ComponentProps<typeof ToastPrimitive.Provider>) {
|
|
14
|
-
|
|
14
|
+
return <ToastPrimitive.Provider data-slot="toast-provider" {...props} />;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/** The fixed-position viewport where toasts are rendered, positioned at bottom-right on larger screens. */
|
|
18
18
|
function ToastViewport({ className, ...props }: React.ComponentProps<typeof ToastPrimitive.Viewport>) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
return (
|
|
20
|
+
<ToastPrimitive.Viewport
|
|
21
|
+
data-slot="toast-viewport"
|
|
22
|
+
className={cn(
|
|
23
|
+
'fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]',
|
|
24
|
+
className,
|
|
25
|
+
)}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const toastVariants = cva(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
'group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full',
|
|
33
|
+
{
|
|
34
|
+
variants: {
|
|
35
|
+
variant: {
|
|
36
|
+
default: 'border bg-background text-foreground',
|
|
37
|
+
destructive: 'destructive group border-destructive bg-destructive text-destructive-foreground',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
defaultVariants: {
|
|
41
|
+
variant: 'default',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
44
|
);
|
|
45
45
|
|
|
46
46
|
/** An individual toast notification with default or destructive variant styling. */
|
|
47
47
|
function Toast({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
className,
|
|
49
|
+
variant,
|
|
50
|
+
...props
|
|
51
51
|
}: React.ComponentProps<typeof ToastPrimitive.Root> & VariantProps<typeof toastVariants>) {
|
|
52
|
-
|
|
52
|
+
return <ToastPrimitive.Root data-slot="toast" className={cn(toastVariants({ variant }), className)} {...props} />;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/** An action button displayed within a toast, such as "Undo" or "Retry". */
|
|
56
56
|
function ToastAction({ className, ...props }: React.ComponentProps<typeof ToastPrimitive.Action>) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
return (
|
|
58
|
+
<ToastPrimitive.Action
|
|
59
|
+
data-slot="toast-action"
|
|
60
|
+
className={cn(
|
|
61
|
+
'inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive',
|
|
62
|
+
className,
|
|
63
|
+
)}
|
|
64
|
+
{...props}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/** A close button positioned in the top-right corner of a toast, visible on hover. */
|
|
70
70
|
function ToastClose({ className, ...props }: React.ComponentProps<typeof ToastPrimitive.Close>) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
return (
|
|
72
|
+
<ToastPrimitive.Close
|
|
73
|
+
data-slot="toast-close"
|
|
74
|
+
className={cn(
|
|
75
|
+
'absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600',
|
|
76
|
+
className,
|
|
77
|
+
)}
|
|
78
|
+
toast-close=""
|
|
79
|
+
{...props}
|
|
80
|
+
>
|
|
81
|
+
<XIcon className="h-4 w-4" />
|
|
82
|
+
</ToastPrimitive.Close>
|
|
83
|
+
);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/** The bold heading text of a toast notification. */
|
|
87
87
|
function ToastTitle({ className, ...props }: React.ComponentProps<typeof ToastPrimitive.Title>) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
return (
|
|
89
|
+
<ToastPrimitive.Title
|
|
90
|
+
data-slot="toast-title"
|
|
91
|
+
className={cn('text-sm font-semibold [&+div]:text-xs', className)}
|
|
92
|
+
{...props}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/** The secondary descriptive text of a toast notification. */
|
|
98
98
|
function ToastDescription({ className, ...props }: React.ComponentProps<typeof ToastPrimitive.Description>) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
return (
|
|
100
|
+
<ToastPrimitive.Description
|
|
101
|
+
data-slot="toast-description"
|
|
102
|
+
className={cn('text-sm opacity-90', className)}
|
|
103
|
+
{...props}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;
|
|
@@ -110,14 +110,14 @@ type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;
|
|
|
110
110
|
type ToastActionElement = React.ReactElement<typeof ToastAction>;
|
|
111
111
|
|
|
112
112
|
export {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
113
|
+
type ToastProps,
|
|
114
|
+
type ToastActionElement,
|
|
115
|
+
ToastProvider,
|
|
116
|
+
ToastViewport,
|
|
117
|
+
Toast,
|
|
118
|
+
ToastTitle,
|
|
119
|
+
ToastDescription,
|
|
120
|
+
ToastClose,
|
|
121
|
+
ToastAction,
|
|
122
|
+
toastVariants,
|
|
123
123
|
};
|
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useToast } from '@/hooks/use-toast';
|
|
4
3
|
import { Toast, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport } from '@/components/ui/Toast';
|
|
4
|
+
import { useToast } from '@/hooks/use-toast';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Renders all active toasts from the useToast hook into a fixed-position viewport.
|
|
8
8
|
* Place once at the app root to enable imperative toast notifications via the useToast hook.
|
|
9
9
|
*/
|
|
10
10
|
function Toaster() {
|
|
11
|
-
|
|
11
|
+
const { toasts } = useToast();
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
</ToastProvider>
|
|
29
|
-
);
|
|
13
|
+
return (
|
|
14
|
+
<ToastProvider>
|
|
15
|
+
{toasts.map(({ id, title, description, action, ...props }) => (
|
|
16
|
+
<Toast key={id} {...props}>
|
|
17
|
+
<div className="grid gap-1">
|
|
18
|
+
{title && <ToastTitle>{title}</ToastTitle>}
|
|
19
|
+
{description && <ToastDescription>{description}</ToastDescription>}
|
|
20
|
+
</div>
|
|
21
|
+
{action}
|
|
22
|
+
<ToastClose />
|
|
23
|
+
</Toast>
|
|
24
|
+
))}
|
|
25
|
+
<ToastViewport />
|
|
26
|
+
</ToastProvider>
|
|
27
|
+
);
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
export { Toaster };
|
|
@@ -3,42 +3,42 @@ import { BoldIcon } from 'lucide-react';
|
|
|
3
3
|
import { Toggle } from '@/components/ui/Toggle';
|
|
4
4
|
|
|
5
5
|
const meta: Meta<typeof Toggle> = {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
title: 'UI Components/Toggle',
|
|
7
|
+
component: Toggle,
|
|
8
8
|
};
|
|
9
9
|
export default meta;
|
|
10
10
|
type Story = StoryObj<typeof Toggle>;
|
|
11
11
|
|
|
12
12
|
/** Shows a toggle button with a bold icon in the default ghost variant. */
|
|
13
13
|
export const Default: Story = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
args: {
|
|
15
|
+
'aria-label': 'Toggle bold',
|
|
16
|
+
children: <BoldIcon />,
|
|
17
|
+
},
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
/** Shows the outline variant with a visible border. */
|
|
21
21
|
export const Outline: Story = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
args: {
|
|
23
|
+
variant: 'outline',
|
|
24
|
+
'aria-label': 'Toggle bold',
|
|
25
|
+
children: <BoldIcon />,
|
|
26
|
+
},
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/** Shows a toggle with a text label instead of an icon. */
|
|
30
30
|
export const WithText: Story = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
args: {
|
|
32
|
+
'aria-label': 'Toggle italic',
|
|
33
|
+
children: 'Italic',
|
|
34
|
+
},
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
/** Shows a toggle in its initially pressed (on) state. */
|
|
38
38
|
export const Pressed: Story = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
args: {
|
|
40
|
+
defaultPressed: true,
|
|
41
|
+
'aria-label': 'Toggle bold',
|
|
42
|
+
children: <BoldIcon />,
|
|
43
|
+
},
|
|
44
44
|
};
|
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import * as React from 'react';
|
|
4
3
|
import { cva, type VariantProps } from 'class-variance-authority';
|
|
5
4
|
import { Toggle as TogglePrimitive } from 'radix-ui';
|
|
5
|
+
import type * as React from 'react';
|
|
6
6
|
|
|
7
7
|
import { cn } from '@/lib/utils';
|
|
8
8
|
|
|
9
9
|
const toggleVariants = cva(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
"inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium hover:bg-muted hover:text-muted-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] outline-none transition-[color,box-shadow] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap",
|
|
11
|
+
{
|
|
12
|
+
variants: {
|
|
13
|
+
variant: {
|
|
14
|
+
default: 'bg-transparent',
|
|
15
|
+
outline: 'border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground',
|
|
16
|
+
},
|
|
17
|
+
size: {
|
|
18
|
+
default: 'h-9 px-2 min-w-9',
|
|
19
|
+
sm: 'h-8 px-1.5 min-w-8',
|
|
20
|
+
lg: 'h-10 px-2.5 min-w-10',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: {
|
|
24
|
+
variant: 'default',
|
|
25
|
+
size: 'default',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
28
|
);
|
|
29
29
|
|
|
30
30
|
/** A two-state button for toolbar controls. Has "default" (ghost) and "outline" variants in sm/default/lg sizes. */
|
|
31
31
|
function Toggle({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
className,
|
|
33
|
+
variant,
|
|
34
|
+
size,
|
|
35
|
+
...props
|
|
36
36
|
}: React.ComponentProps<typeof TogglePrimitive.Root> & VariantProps<typeof toggleVariants>) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
return (
|
|
38
|
+
<TogglePrimitive.Root data-slot="toggle" className={cn(toggleVariants({ variant, size, className }))} {...props} />
|
|
39
|
+
);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export { Toggle, toggleVariants };
|
|
@@ -3,59 +3,59 @@ import { BoldIcon, ItalicIcon, UnderlineIcon } from 'lucide-react';
|
|
|
3
3
|
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/ToggleGroup';
|
|
4
4
|
|
|
5
5
|
const meta: Meta<typeof ToggleGroup> = {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
title: 'UI Components/ToggleGroup',
|
|
7
|
+
component: ToggleGroup,
|
|
8
8
|
};
|
|
9
9
|
export default meta;
|
|
10
10
|
type Story = StoryObj<typeof ToggleGroup>;
|
|
11
11
|
|
|
12
12
|
/** Shows a single-selection toggle group where only one item can be active at a time. */
|
|
13
13
|
export const Single: Story = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
render: () => (
|
|
15
|
+
<ToggleGroup type="single">
|
|
16
|
+
<ToggleGroupItem value="bold" aria-label="Toggle bold">
|
|
17
|
+
<BoldIcon />
|
|
18
|
+
</ToggleGroupItem>
|
|
19
|
+
<ToggleGroupItem value="italic" aria-label="Toggle italic">
|
|
20
|
+
<ItalicIcon />
|
|
21
|
+
</ToggleGroupItem>
|
|
22
|
+
<ToggleGroupItem value="underline" aria-label="Toggle underline">
|
|
23
|
+
<UnderlineIcon />
|
|
24
|
+
</ToggleGroupItem>
|
|
25
|
+
</ToggleGroup>
|
|
26
|
+
),
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/** Shows a multi-selection toggle group with bold and italic pre-selected. */
|
|
30
30
|
export const Multiple: Story = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
render: () => (
|
|
32
|
+
<ToggleGroup type="multiple" defaultValue={['bold', 'italic']}>
|
|
33
|
+
<ToggleGroupItem value="bold" aria-label="Toggle bold">
|
|
34
|
+
<BoldIcon />
|
|
35
|
+
</ToggleGroupItem>
|
|
36
|
+
<ToggleGroupItem value="italic" aria-label="Toggle italic">
|
|
37
|
+
<ItalicIcon />
|
|
38
|
+
</ToggleGroupItem>
|
|
39
|
+
<ToggleGroupItem value="underline" aria-label="Toggle underline">
|
|
40
|
+
<UnderlineIcon />
|
|
41
|
+
</ToggleGroupItem>
|
|
42
|
+
</ToggleGroup>
|
|
43
|
+
),
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
/** Shows a toggle group using the outline variant with visible borders. */
|
|
47
47
|
export const Outline: Story = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
render: () => (
|
|
49
|
+
<ToggleGroup type="single" variant="outline">
|
|
50
|
+
<ToggleGroupItem value="bold" aria-label="Toggle bold">
|
|
51
|
+
<BoldIcon />
|
|
52
|
+
</ToggleGroupItem>
|
|
53
|
+
<ToggleGroupItem value="italic" aria-label="Toggle italic">
|
|
54
|
+
<ItalicIcon />
|
|
55
|
+
</ToggleGroupItem>
|
|
56
|
+
<ToggleGroupItem value="underline" aria-label="Toggle underline">
|
|
57
|
+
<UnderlineIcon />
|
|
58
|
+
</ToggleGroupItem>
|
|
59
|
+
</ToggleGroup>
|
|
60
|
+
),
|
|
61
61
|
};
|
|
@@ -1,83 +1,82 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import type { VariantProps } from 'class-variance-authority';
|
|
5
4
|
import { ToggleGroup as ToggleGroupPrimitive } from 'radix-ui';
|
|
6
|
-
|
|
7
|
-
import { cn } from '@/lib/utils';
|
|
5
|
+
import * as React from 'react';
|
|
8
6
|
import { toggleVariants } from '@/components/ui/Toggle';
|
|
7
|
+
import { cn } from '@/lib/utils';
|
|
9
8
|
|
|
10
9
|
const ToggleGroupContext = React.createContext<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
VariantProps<typeof toggleVariants> & {
|
|
11
|
+
spacing?: number;
|
|
12
|
+
}
|
|
14
13
|
>({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
size: 'default',
|
|
15
|
+
variant: 'default',
|
|
16
|
+
spacing: 0,
|
|
18
17
|
});
|
|
19
18
|
|
|
20
19
|
/** A group of toggles where one (`type="single"`) or multiple (`type="multiple"`) can be active. */
|
|
21
20
|
function ToggleGroup({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
className,
|
|
22
|
+
variant,
|
|
23
|
+
size,
|
|
24
|
+
/** Controls gap between items. When 0, items are visually joined with shared borders. */
|
|
25
|
+
spacing = 0,
|
|
26
|
+
children,
|
|
27
|
+
...props
|
|
29
28
|
}: React.ComponentProps<typeof ToggleGroupPrimitive.Root> &
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
VariantProps<typeof toggleVariants> & {
|
|
30
|
+
spacing?: number;
|
|
31
|
+
}) {
|
|
32
|
+
return (
|
|
33
|
+
<ToggleGroupPrimitive.Root
|
|
34
|
+
data-slot="toggle-group"
|
|
35
|
+
data-variant={variant}
|
|
36
|
+
data-size={size}
|
|
37
|
+
data-spacing={spacing}
|
|
38
|
+
style={{ '--gap': spacing } as React.CSSProperties}
|
|
39
|
+
className={cn(
|
|
40
|
+
'group/toggle-group flex w-fit items-center gap-[--spacing(var(--gap))] rounded-md data-[spacing=default]:data-[variant=outline]:shadow-xs',
|
|
41
|
+
className,
|
|
42
|
+
)}
|
|
43
|
+
{...props}
|
|
44
|
+
>
|
|
45
|
+
<ToggleGroupContext.Provider value={{ variant, size, spacing }}>{children}</ToggleGroupContext.Provider>
|
|
46
|
+
</ToggleGroupPrimitive.Root>
|
|
47
|
+
);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
/** An individual toggle button within a ToggleGroup. Inherits variant and size from the parent group context. */
|
|
52
51
|
function ToggleGroupItem({
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
className,
|
|
53
|
+
children,
|
|
54
|
+
variant,
|
|
55
|
+
size,
|
|
56
|
+
...props
|
|
58
57
|
}: React.ComponentProps<typeof ToggleGroupPrimitive.Item> & VariantProps<typeof toggleVariants>) {
|
|
59
|
-
|
|
58
|
+
const context = React.useContext(ToggleGroupContext);
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
60
|
+
return (
|
|
61
|
+
<ToggleGroupPrimitive.Item
|
|
62
|
+
data-slot="toggle-group-item"
|
|
63
|
+
data-variant={context.variant || variant}
|
|
64
|
+
data-size={context.size || size}
|
|
65
|
+
data-spacing={context.spacing}
|
|
66
|
+
className={cn(
|
|
67
|
+
toggleVariants({
|
|
68
|
+
variant: context.variant || variant,
|
|
69
|
+
size: context.size || size,
|
|
70
|
+
}),
|
|
71
|
+
'w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10',
|
|
72
|
+
'data-[spacing=0]:rounded-none data-[spacing=0]:shadow-none data-[spacing=0]:first:rounded-l-md data-[spacing=0]:last:rounded-r-md data-[spacing=0]:data-[variant=outline]:border-l-0 data-[spacing=0]:data-[variant=outline]:first:border-l',
|
|
73
|
+
className,
|
|
74
|
+
)}
|
|
75
|
+
{...props}
|
|
76
|
+
>
|
|
77
|
+
{children}
|
|
78
|
+
</ToggleGroupPrimitive.Item>
|
|
79
|
+
);
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
export { ToggleGroup, ToggleGroupItem };
|