@sqlrooms/ui 0.0.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.
Files changed (164) hide show
  1. package/.turbo/turbo-build.log +8 -0
  2. package/.turbo/turbo-lint.log +10 -0
  3. package/CHANGELOG.md +8 -0
  4. package/LICENSE.md +9 -0
  5. package/components.json +21 -0
  6. package/dist/components/DefaultErrorBoundary.d.ts +2 -0
  7. package/dist/components/DefaultErrorBoundary.d.ts.map +1 -0
  8. package/dist/components/DefaultErrorBoundary.js +1 -0
  9. package/dist/components/ProgressModal.d.ts +10 -0
  10. package/dist/components/ProgressModal.d.ts.map +1 -0
  11. package/dist/components/ProgressModal.js +7 -0
  12. package/dist/components/accordion.d.ts +8 -0
  13. package/dist/components/accordion.d.ts.map +1 -0
  14. package/dist/components/accordion.js +13 -0
  15. package/dist/components/alert.d.ts +9 -0
  16. package/dist/components/alert.d.ts.map +1 -0
  17. package/dist/components/alert.js +22 -0
  18. package/dist/components/badge.d.ts +10 -0
  19. package/dist/components/badge.d.ts.map +1 -0
  20. package/dist/components/badge.js +20 -0
  21. package/dist/components/breadcrumb.d.ts +20 -0
  22. package/dist/components/breadcrumb.d.ts.map +1 -0
  23. package/dist/components/breadcrumb.js +23 -0
  24. package/dist/components/button.d.ts +12 -0
  25. package/dist/components/button.d.ts.map +1 -0
  26. package/dist/components/button.js +33 -0
  27. package/dist/components/card.d.ts +9 -0
  28. package/dist/components/card.d.ts.map +1 -0
  29. package/dist/components/card.js +16 -0
  30. package/dist/components/checkbox.d.ts +5 -0
  31. package/dist/components/checkbox.d.ts.map +1 -0
  32. package/dist/components/checkbox.js +8 -0
  33. package/dist/components/dialog.d.ts +20 -0
  34. package/dist/components/dialog.d.ts.map +1 -0
  35. package/dist/components/dialog.js +22 -0
  36. package/dist/components/dropdown-menu.d.ts +28 -0
  37. package/dist/components/dropdown-menu.d.ts.map +1 -0
  38. package/dist/components/dropdown-menu.js +35 -0
  39. package/dist/components/editable-text.d.ts +53 -0
  40. package/dist/components/editable-text.d.ts.map +1 -0
  41. package/dist/components/editable-text.js +87 -0
  42. package/dist/components/error-boundary.d.ts +19 -0
  43. package/dist/components/error-boundary.d.ts.map +1 -0
  44. package/dist/components/error-boundary.js +26 -0
  45. package/dist/components/error-pane.d.ts +13 -0
  46. package/dist/components/error-pane.d.ts.map +1 -0
  47. package/dist/components/error-pane.js +12 -0
  48. package/dist/components/form.d.ts +24 -0
  49. package/dist/components/form.d.ts.map +1 -0
  50. package/dist/components/form.js +62 -0
  51. package/dist/components/index.d.ts +2 -0
  52. package/dist/components/index.d.ts.map +1 -0
  53. package/dist/components/index.js +1 -0
  54. package/dist/components/input.d.ts +4 -0
  55. package/dist/components/input.d.ts.map +1 -0
  56. package/dist/components/input.js +8 -0
  57. package/dist/components/label.d.ts +6 -0
  58. package/dist/components/label.d.ts.map +1 -0
  59. package/dist/components/label.js +9 -0
  60. package/dist/components/popover.d.ts +8 -0
  61. package/dist/components/popover.d.ts.map +1 -0
  62. package/dist/components/popover.js +10 -0
  63. package/dist/components/progress-modal.d.ts +10 -0
  64. package/dist/components/progress-modal.d.ts.map +1 -0
  65. package/dist/components/progress-modal.js +8 -0
  66. package/dist/components/progress.d.ts +5 -0
  67. package/dist/components/progress.d.ts.map +1 -0
  68. package/dist/components/progress.js +7 -0
  69. package/dist/components/resizable.d.ts +24 -0
  70. package/dist/components/resizable.d.ts.map +1 -0
  71. package/dist/components/resizable.js +8 -0
  72. package/dist/components/select.d.ts +14 -0
  73. package/dist/components/select.d.ts.map +1 -0
  74. package/dist/components/select.js +26 -0
  75. package/dist/components/skeleton-pane.d.ts +10 -0
  76. package/dist/components/skeleton-pane.d.ts.map +1 -0
  77. package/dist/components/skeleton-pane.js +17 -0
  78. package/dist/components/skeleton.d.ts +3 -0
  79. package/dist/components/skeleton.d.ts.map +1 -0
  80. package/dist/components/skeleton.js +6 -0
  81. package/dist/components/spinner-pane.d.ts +10 -0
  82. package/dist/components/spinner-pane.d.ts.map +1 -0
  83. package/dist/components/spinner-pane.js +17 -0
  84. package/dist/components/spinner.d.ts +8 -0
  85. package/dist/components/spinner.d.ts.map +1 -0
  86. package/dist/components/spinner.js +9 -0
  87. package/dist/components/switch.d.ts +5 -0
  88. package/dist/components/switch.d.ts.map +1 -0
  89. package/dist/components/switch.js +7 -0
  90. package/dist/components/table.d.ts +20 -0
  91. package/dist/components/table.d.ts.map +1 -0
  92. package/dist/components/table.js +20 -0
  93. package/dist/components/tabs.d.ts +8 -0
  94. package/dist/components/tabs.d.ts.map +1 -0
  95. package/dist/components/tabs.js +12 -0
  96. package/dist/components/textarea.d.ts +4 -0
  97. package/dist/components/textarea.d.ts.map +1 -0
  98. package/dist/components/textarea.js +8 -0
  99. package/dist/components/toast.d.ts +16 -0
  100. package/dist/components/toast.d.ts.map +1 -0
  101. package/dist/components/toast.js +33 -0
  102. package/dist/components/toaster.d.ts +2 -0
  103. package/dist/components/toaster.d.ts.map +1 -0
  104. package/dist/components/toaster.js +9 -0
  105. package/dist/components/tooltip.d.ts +8 -0
  106. package/dist/components/tooltip.d.ts.map +1 -0
  107. package/dist/components/tooltip.js +10 -0
  108. package/dist/hooks/use-toast.d.ts +45 -0
  109. package/dist/hooks/use-toast.d.ts.map +1 -0
  110. package/dist/hooks/use-toast.js +128 -0
  111. package/dist/hooks/useDisclosure.d.ts +9 -0
  112. package/dist/hooks/useDisclosure.d.ts.map +1 -0
  113. package/dist/hooks/useDisclosure.js +14 -0
  114. package/dist/index.d.ts +36 -0
  115. package/dist/index.d.ts.map +1 -0
  116. package/dist/index.js +35 -0
  117. package/dist/lib/utils.d.ts +3 -0
  118. package/dist/lib/utils.d.ts.map +1 -0
  119. package/dist/lib/utils.js +5 -0
  120. package/dist/tailwind-preset.css +68 -0
  121. package/dist/tailwind-preset.d.ts +5 -0
  122. package/dist/tailwind-preset.d.ts.map +1 -0
  123. package/dist/tailwind-preset.js +50 -0
  124. package/dist/tsconfig.tsbuildinfo +1 -0
  125. package/eslint.config.js +4 -0
  126. package/package.json +59 -0
  127. package/src/components/accordion.tsx +55 -0
  128. package/src/components/alert.tsx +59 -0
  129. package/src/components/badge.tsx +34 -0
  130. package/src/components/breadcrumb.tsx +115 -0
  131. package/src/components/button.tsx +55 -0
  132. package/src/components/card.tsx +76 -0
  133. package/src/components/checkbox.tsx +28 -0
  134. package/src/components/dialog.tsx +120 -0
  135. package/src/components/dropdown-menu.tsx +199 -0
  136. package/src/components/editable-text.tsx +199 -0
  137. package/src/components/error-boundary.tsx +48 -0
  138. package/src/components/error-pane.tsx +81 -0
  139. package/src/components/form.tsx +176 -0
  140. package/src/components/input.tsx +22 -0
  141. package/src/components/label.tsx +24 -0
  142. package/src/components/popover.tsx +31 -0
  143. package/src/components/progress-modal.tsx +33 -0
  144. package/src/components/progress.tsx +26 -0
  145. package/src/components/resizable.tsx +43 -0
  146. package/src/components/select.tsx +157 -0
  147. package/src/components/skeleton-pane.tsx +45 -0
  148. package/src/components/skeleton.tsx +12 -0
  149. package/src/components/spinner-pane.tsx +44 -0
  150. package/src/components/spinner.tsx +16 -0
  151. package/src/components/switch.tsx +27 -0
  152. package/src/components/table.tsx +136 -0
  153. package/src/components/tabs.tsx +53 -0
  154. package/src/components/textarea.tsx +21 -0
  155. package/src/components/toast.tsx +127 -0
  156. package/src/components/toaster.tsx +33 -0
  157. package/src/components/tooltip.tsx +29 -0
  158. package/src/hooks/use-toast.ts +191 -0
  159. package/src/hooks/useDisclosure.ts +26 -0
  160. package/src/index.ts +35 -0
  161. package/src/lib/utils.ts +6 -0
  162. package/src/tailwind-preset.css +68 -0
  163. package/src/tailwind-preset.ts +55 -0
  164. package/tsconfig.json +12 -0
@@ -0,0 +1,136 @@
1
+ import * as React from 'react';
2
+
3
+ import {cn} from '../lib/utils';
4
+
5
+ interface TableProps extends React.HTMLAttributes<HTMLTableElement> {
6
+ /**
7
+ * The overflow-auto in shadcn's Table component is there to handle tables that might be wider
8
+ * than their container - it's a common pattern to ensure wide tables can be scrolled horizontally
9
+ * without breaking the layout. This prop allows you to disable this behavior, because it might
10
+ * cause issues with sticky headers.
11
+ */
12
+ disableWrapper?: boolean;
13
+ }
14
+
15
+ const Table = React.forwardRef<HTMLTableElement, TableProps>(
16
+ ({className, disableWrapper, ...props}, ref) =>
17
+ disableWrapper ? (
18
+ <table
19
+ ref={ref}
20
+ className={cn('w-full caption-bottom text-sm', className)}
21
+ {...props}
22
+ />
23
+ ) : (
24
+ <div className="relative w-full overflow-auto">
25
+ <table
26
+ ref={ref}
27
+ className={cn('w-full caption-bottom text-sm', className)}
28
+ {...props}
29
+ />
30
+ </div>
31
+ ),
32
+ );
33
+ Table.displayName = 'Table';
34
+
35
+ const TableHeader = React.forwardRef<
36
+ HTMLTableSectionElement,
37
+ React.HTMLAttributes<HTMLTableSectionElement>
38
+ >(({className, ...props}, ref) => (
39
+ <thead ref={ref} className={cn('[&_tr]:border-b', className)} {...props} />
40
+ ));
41
+ TableHeader.displayName = 'TableHeader';
42
+
43
+ const TableBody = React.forwardRef<
44
+ HTMLTableSectionElement,
45
+ React.HTMLAttributes<HTMLTableSectionElement>
46
+ >(({className, ...props}, ref) => (
47
+ <tbody
48
+ ref={ref}
49
+ className={cn('[&_tr:last-child]:border-0', className)}
50
+ {...props}
51
+ />
52
+ ));
53
+ TableBody.displayName = 'TableBody';
54
+
55
+ const TableFooter = React.forwardRef<
56
+ HTMLTableSectionElement,
57
+ React.HTMLAttributes<HTMLTableSectionElement>
58
+ >(({className, ...props}, ref) => (
59
+ <tfoot
60
+ ref={ref}
61
+ className={cn(
62
+ 'border-t bg-muted/50 font-medium [&>tr]:last:border-b-0',
63
+ className,
64
+ )}
65
+ {...props}
66
+ />
67
+ ));
68
+ TableFooter.displayName = 'TableFooter';
69
+
70
+ const TableRow = React.forwardRef<
71
+ HTMLTableRowElement,
72
+ React.HTMLAttributes<HTMLTableRowElement>
73
+ >(({className, ...props}, ref) => (
74
+ <tr
75
+ ref={ref}
76
+ className={cn(
77
+ 'border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted',
78
+ className,
79
+ )}
80
+ {...props}
81
+ />
82
+ ));
83
+ TableRow.displayName = 'TableRow';
84
+
85
+ const TableHead = React.forwardRef<
86
+ HTMLTableCellElement,
87
+ React.ThHTMLAttributes<HTMLTableCellElement>
88
+ >(({className, ...props}, ref) => (
89
+ <th
90
+ ref={ref}
91
+ className={cn(
92
+ 'h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]',
93
+ className,
94
+ )}
95
+ {...props}
96
+ />
97
+ ));
98
+ TableHead.displayName = 'TableHead';
99
+
100
+ const TableCell = React.forwardRef<
101
+ HTMLTableCellElement,
102
+ React.TdHTMLAttributes<HTMLTableCellElement>
103
+ >(({className, ...props}, ref) => (
104
+ <td
105
+ ref={ref}
106
+ className={cn(
107
+ 'p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]',
108
+ className,
109
+ )}
110
+ {...props}
111
+ />
112
+ ));
113
+ TableCell.displayName = 'TableCell';
114
+
115
+ const TableCaption = React.forwardRef<
116
+ HTMLTableCaptionElement,
117
+ React.HTMLAttributes<HTMLTableCaptionElement>
118
+ >(({className, ...props}, ref) => (
119
+ <caption
120
+ ref={ref}
121
+ className={cn('mt-4 text-sm text-muted-foreground', className)}
122
+ {...props}
123
+ />
124
+ ));
125
+ TableCaption.displayName = 'TableCaption';
126
+
127
+ export {
128
+ Table,
129
+ TableHeader,
130
+ TableBody,
131
+ TableFooter,
132
+ TableHead,
133
+ TableRow,
134
+ TableCell,
135
+ TableCaption,
136
+ };
@@ -0,0 +1,53 @@
1
+ import * as React from 'react';
2
+ import * as TabsPrimitive from '@radix-ui/react-tabs';
3
+
4
+ import {cn} from '../lib/utils';
5
+
6
+ const Tabs = TabsPrimitive.Root;
7
+
8
+ const TabsList = React.forwardRef<
9
+ React.ElementRef<typeof TabsPrimitive.List>,
10
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
11
+ >(({className, ...props}, ref) => (
12
+ <TabsPrimitive.List
13
+ ref={ref}
14
+ className={cn(
15
+ 'inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground',
16
+ className,
17
+ )}
18
+ {...props}
19
+ />
20
+ ));
21
+ TabsList.displayName = TabsPrimitive.List.displayName;
22
+
23
+ const TabsTrigger = React.forwardRef<
24
+ React.ElementRef<typeof TabsPrimitive.Trigger>,
25
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
26
+ >(({className, ...props}, ref) => (
27
+ <TabsPrimitive.Trigger
28
+ ref={ref}
29
+ className={cn(
30
+ 'inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow',
31
+ className,
32
+ )}
33
+ {...props}
34
+ />
35
+ ));
36
+ TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;
37
+
38
+ const TabsContent = React.forwardRef<
39
+ React.ElementRef<typeof TabsPrimitive.Content>,
40
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
41
+ >(({className, ...props}, ref) => (
42
+ <TabsPrimitive.Content
43
+ ref={ref}
44
+ className={cn(
45
+ 'mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
46
+ className,
47
+ )}
48
+ {...props}
49
+ />
50
+ ));
51
+ TabsContent.displayName = TabsPrimitive.Content.displayName;
52
+
53
+ export {Tabs, TabsList, TabsTrigger, TabsContent};
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ import {cn} from '../lib/utils';
3
+
4
+ const Textarea = React.forwardRef<
5
+ HTMLTextAreaElement,
6
+ React.ComponentProps<'textarea'>
7
+ >(({className, ...props}, ref) => {
8
+ return (
9
+ <textarea
10
+ className={cn(
11
+ 'flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm',
12
+ className,
13
+ )}
14
+ ref={ref}
15
+ {...props}
16
+ />
17
+ );
18
+ });
19
+ Textarea.displayName = 'Textarea';
20
+
21
+ export {Textarea};
@@ -0,0 +1,127 @@
1
+ import * as React from 'react';
2
+ import * as ToastPrimitives from '@radix-ui/react-toast';
3
+ import {cva, type VariantProps} from 'class-variance-authority';
4
+ import {X} from 'lucide-react';
5
+
6
+ import {cn} from '../lib/utils';
7
+
8
+ const ToastProvider = ToastPrimitives.Provider;
9
+
10
+ const ToastViewport = React.forwardRef<
11
+ React.ElementRef<typeof ToastPrimitives.Viewport>,
12
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
13
+ >(({className, ...props}, ref) => (
14
+ <ToastPrimitives.Viewport
15
+ ref={ref}
16
+ className={cn(
17
+ '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]',
18
+ className,
19
+ )}
20
+ {...props}
21
+ />
22
+ ));
23
+ ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
24
+
25
+ const toastVariants = cva(
26
+ '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',
27
+ {
28
+ variants: {
29
+ variant: {
30
+ default: 'border bg-background text-foreground',
31
+ destructive:
32
+ 'destructive group border-destructive bg-destructive text-destructive-foreground',
33
+ },
34
+ },
35
+ defaultVariants: {
36
+ variant: 'default',
37
+ },
38
+ },
39
+ );
40
+
41
+ const Toast = React.forwardRef<
42
+ React.ElementRef<typeof ToastPrimitives.Root>,
43
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
44
+ VariantProps<typeof toastVariants>
45
+ >(({className, variant, ...props}, ref) => {
46
+ return (
47
+ <ToastPrimitives.Root
48
+ ref={ref}
49
+ className={cn(toastVariants({variant}), className)}
50
+ {...props}
51
+ />
52
+ );
53
+ });
54
+ Toast.displayName = ToastPrimitives.Root.displayName;
55
+
56
+ const ToastAction = React.forwardRef<
57
+ React.ElementRef<typeof ToastPrimitives.Action>,
58
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
59
+ >(({className, ...props}, ref) => (
60
+ <ToastPrimitives.Action
61
+ ref={ref}
62
+ className={cn(
63
+ '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',
64
+ className,
65
+ )}
66
+ {...props}
67
+ />
68
+ ));
69
+ ToastAction.displayName = ToastPrimitives.Action.displayName;
70
+
71
+ const ToastClose = React.forwardRef<
72
+ React.ElementRef<typeof ToastPrimitives.Close>,
73
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
74
+ >(({className, ...props}, ref) => (
75
+ <ToastPrimitives.Close
76
+ ref={ref}
77
+ className={cn(
78
+ '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',
79
+ className,
80
+ )}
81
+ toast-close=""
82
+ {...props}
83
+ >
84
+ <X className="h-4 w-4" />
85
+ </ToastPrimitives.Close>
86
+ ));
87
+ ToastClose.displayName = ToastPrimitives.Close.displayName;
88
+
89
+ const ToastTitle = React.forwardRef<
90
+ React.ElementRef<typeof ToastPrimitives.Title>,
91
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
92
+ >(({className, ...props}, ref) => (
93
+ <ToastPrimitives.Title
94
+ ref={ref}
95
+ className={cn('text-sm font-semibold [&+div]:text-xs', className)}
96
+ {...props}
97
+ />
98
+ ));
99
+ ToastTitle.displayName = ToastPrimitives.Title.displayName;
100
+
101
+ const ToastDescription = React.forwardRef<
102
+ React.ElementRef<typeof ToastPrimitives.Description>,
103
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
104
+ >(({className, ...props}, ref) => (
105
+ <ToastPrimitives.Description
106
+ ref={ref}
107
+ className={cn('text-sm opacity-90', className)}
108
+ {...props}
109
+ />
110
+ ));
111
+ ToastDescription.displayName = ToastPrimitives.Description.displayName;
112
+
113
+ type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;
114
+
115
+ type ToastActionElement = React.ReactElement<typeof ToastAction>;
116
+
117
+ export {
118
+ type ToastProps,
119
+ type ToastActionElement,
120
+ ToastProvider,
121
+ ToastViewport,
122
+ Toast,
123
+ ToastTitle,
124
+ ToastDescription,
125
+ ToastClose,
126
+ ToastAction,
127
+ };
@@ -0,0 +1,33 @@
1
+ import {useToast} from '../hooks/use-toast';
2
+ import {
3
+ Toast,
4
+ ToastClose,
5
+ ToastDescription,
6
+ ToastProvider,
7
+ ToastTitle,
8
+ ToastViewport,
9
+ } from './toast';
10
+
11
+ export function Toaster() {
12
+ const {toasts} = useToast();
13
+
14
+ return (
15
+ <ToastProvider>
16
+ {toasts.map(function ({id, title, description, action, ...props}) {
17
+ return (
18
+ <Toast key={id} {...props}>
19
+ <div className="grid gap-1">
20
+ {title && <ToastTitle>{title}</ToastTitle>}
21
+ {description && (
22
+ <ToastDescription>{description}</ToastDescription>
23
+ )}
24
+ </div>
25
+ {action}
26
+ <ToastClose />
27
+ </Toast>
28
+ );
29
+ })}
30
+ <ToastViewport />
31
+ </ToastProvider>
32
+ );
33
+ }
@@ -0,0 +1,29 @@
1
+ import * as React from 'react';
2
+ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
3
+ import {cn} from '../lib/utils';
4
+
5
+ const TooltipProvider = TooltipPrimitive.Provider;
6
+
7
+ const Tooltip = TooltipPrimitive.Root;
8
+
9
+ const TooltipTrigger = TooltipPrimitive.Trigger;
10
+
11
+ const TooltipContent = React.forwardRef<
12
+ React.ElementRef<typeof TooltipPrimitive.Content>,
13
+ React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
14
+ >(({className, sideOffset = 4, ...props}, ref) => (
15
+ <TooltipPrimitive.Portal>
16
+ <TooltipPrimitive.Content
17
+ ref={ref}
18
+ sideOffset={sideOffset}
19
+ className={cn(
20
+ 'z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
21
+ className,
22
+ )}
23
+ {...props}
24
+ />
25
+ </TooltipPrimitive.Portal>
26
+ ));
27
+ TooltipContent.displayName = TooltipPrimitive.Content.displayName;
28
+
29
+ export {Tooltip, TooltipTrigger, TooltipContent, TooltipProvider};
@@ -0,0 +1,191 @@
1
+ 'use client';
2
+
3
+ // Inspired by react-hot-toast library
4
+ import * as React from 'react';
5
+
6
+ import type {ToastActionElement, ToastProps} from '../components/toast';
7
+
8
+ const TOAST_LIMIT = 1;
9
+ const TOAST_REMOVE_DELAY = 1000000;
10
+
11
+ type ToasterToast = ToastProps & {
12
+ id: string;
13
+ title?: React.ReactNode;
14
+ description?: React.ReactNode;
15
+ action?: ToastActionElement;
16
+ };
17
+
18
+ const actionTypes = {
19
+ ADD_TOAST: 'ADD_TOAST',
20
+ UPDATE_TOAST: 'UPDATE_TOAST',
21
+ DISMISS_TOAST: 'DISMISS_TOAST',
22
+ REMOVE_TOAST: 'REMOVE_TOAST',
23
+ } as const;
24
+
25
+ let count = 0;
26
+
27
+ function genId() {
28
+ count = (count + 1) % Number.MAX_SAFE_INTEGER;
29
+ return count.toString();
30
+ }
31
+
32
+ type ActionType = typeof actionTypes;
33
+
34
+ type Action =
35
+ | {
36
+ type: ActionType['ADD_TOAST'];
37
+ toast: ToasterToast;
38
+ }
39
+ | {
40
+ type: ActionType['UPDATE_TOAST'];
41
+ toast: Partial<ToasterToast>;
42
+ }
43
+ | {
44
+ type: ActionType['DISMISS_TOAST'];
45
+ toastId?: ToasterToast['id'];
46
+ }
47
+ | {
48
+ type: ActionType['REMOVE_TOAST'];
49
+ toastId?: ToasterToast['id'];
50
+ };
51
+
52
+ interface State {
53
+ toasts: ToasterToast[];
54
+ }
55
+
56
+ const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
57
+
58
+ const addToRemoveQueue = (toastId: string) => {
59
+ if (toastTimeouts.has(toastId)) {
60
+ return;
61
+ }
62
+
63
+ const timeout = setTimeout(() => {
64
+ toastTimeouts.delete(toastId);
65
+ dispatch({
66
+ type: 'REMOVE_TOAST',
67
+ toastId: toastId,
68
+ });
69
+ }, TOAST_REMOVE_DELAY);
70
+
71
+ toastTimeouts.set(toastId, timeout);
72
+ };
73
+
74
+ export const reducer = (state: State, action: Action): State => {
75
+ switch (action.type) {
76
+ case 'ADD_TOAST':
77
+ return {
78
+ ...state,
79
+ toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
80
+ };
81
+
82
+ case 'UPDATE_TOAST':
83
+ return {
84
+ ...state,
85
+ toasts: state.toasts.map((t) =>
86
+ t.id === action.toast.id ? {...t, ...action.toast} : t,
87
+ ),
88
+ };
89
+
90
+ case 'DISMISS_TOAST': {
91
+ const {toastId} = action;
92
+
93
+ // ! Side effects ! - This could be extracted into a dismissToast() action,
94
+ // but I'll keep it here for simplicity
95
+ if (toastId) {
96
+ addToRemoveQueue(toastId);
97
+ } else {
98
+ state.toasts.forEach((toast) => {
99
+ addToRemoveQueue(toast.id);
100
+ });
101
+ }
102
+
103
+ return {
104
+ ...state,
105
+ toasts: state.toasts.map((t) =>
106
+ t.id === toastId || toastId === undefined
107
+ ? {
108
+ ...t,
109
+ open: false,
110
+ }
111
+ : t,
112
+ ),
113
+ };
114
+ }
115
+ case 'REMOVE_TOAST':
116
+ if (action.toastId === undefined) {
117
+ return {
118
+ ...state,
119
+ toasts: [],
120
+ };
121
+ }
122
+ return {
123
+ ...state,
124
+ toasts: state.toasts.filter((t) => t.id !== action.toastId),
125
+ };
126
+ }
127
+ };
128
+
129
+ const listeners: Array<(state: State) => void> = [];
130
+
131
+ let memoryState: State = {toasts: []};
132
+
133
+ function dispatch(action: Action) {
134
+ memoryState = reducer(memoryState, action);
135
+ listeners.forEach((listener) => {
136
+ listener(memoryState);
137
+ });
138
+ }
139
+
140
+ type Toast = Omit<ToasterToast, 'id'>;
141
+
142
+ function toast({...props}: Toast) {
143
+ const id = genId();
144
+
145
+ const update = (props: ToasterToast) =>
146
+ dispatch({
147
+ type: 'UPDATE_TOAST',
148
+ toast: {...props, id},
149
+ });
150
+ const dismiss = () => dispatch({type: 'DISMISS_TOAST', toastId: id});
151
+
152
+ dispatch({
153
+ type: 'ADD_TOAST',
154
+ toast: {
155
+ ...props,
156
+ id,
157
+ open: true,
158
+ onOpenChange: (open) => {
159
+ if (!open) dismiss();
160
+ },
161
+ },
162
+ });
163
+
164
+ return {
165
+ id: id,
166
+ dismiss,
167
+ update,
168
+ };
169
+ }
170
+
171
+ function useToast() {
172
+ const [state, setState] = React.useState<State>(memoryState);
173
+
174
+ React.useEffect(() => {
175
+ listeners.push(setState);
176
+ return () => {
177
+ const index = listeners.indexOf(setState);
178
+ if (index > -1) {
179
+ listeners.splice(index, 1);
180
+ }
181
+ };
182
+ }, [state]);
183
+
184
+ return {
185
+ ...state,
186
+ toast,
187
+ dismiss: (toastId?: string) => dispatch({type: 'DISMISS_TOAST', toastId}),
188
+ };
189
+ }
190
+
191
+ export {useToast, toast};
@@ -0,0 +1,26 @@
1
+ import {useState, useCallback} from 'react';
2
+
3
+ interface UseDisclosureReturn {
4
+ isOpen: boolean;
5
+ onOpen: () => void;
6
+ onClose: () => void;
7
+ onToggle: () => void;
8
+ }
9
+
10
+ export function useDisclosure(initialState = false): UseDisclosureReturn {
11
+ const [isOpen, setIsOpen] = useState(initialState);
12
+
13
+ const onOpen = useCallback(() => {
14
+ setIsOpen(true);
15
+ }, []);
16
+
17
+ const onClose = useCallback(() => {
18
+ setIsOpen(false);
19
+ }, []);
20
+
21
+ const onToggle = useCallback(() => {
22
+ setIsOpen((prev) => !prev);
23
+ }, []);
24
+
25
+ return {isOpen, onOpen, onClose, onToggle};
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,35 @@
1
+ export * from './components/accordion';
2
+ export * from './components/alert';
3
+ export * from './components/badge';
4
+ export * from './components/breadcrumb';
5
+ export * from './components/button';
6
+ export * from './components/card';
7
+ export * from './components/checkbox';
8
+ export * from './components/dialog';
9
+ export * from './components/dropdown-menu';
10
+ export * from './components/editable-text';
11
+ export * from './components/error-boundary';
12
+ export * from './components/error-pane';
13
+ export * from './components/form';
14
+ export * from './components/input';
15
+ export * from './components/label';
16
+ export * from './components/popover';
17
+ export * from './components/progress';
18
+ export * from './components/progress-modal';
19
+ export * from './components/resizable';
20
+ export * from './components/select';
21
+ export * from './components/skeleton';
22
+ export * from './components/skeleton-pane';
23
+ export * from './components/spinner';
24
+ export * from './components/spinner-pane';
25
+ export * from './components/switch';
26
+ export * from './components/table';
27
+ export * from './components/tabs';
28
+ export * from './components/textarea';
29
+ export * from './components/toast';
30
+ export * from './components/toaster';
31
+ export * from './components/tooltip';
32
+ export * from './hooks/use-toast';
33
+ export * from './hooks/useDisclosure';
34
+ export * from './lib/utils';
35
+ export * from './tailwind-preset';
@@ -0,0 +1,6 @@
1
+ import {clsx, type ClassValue} from 'clsx';
2
+ import {twMerge} from 'tailwind-merge';
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }