@gv-tech/ui-web 2.6.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 (56) hide show
  1. package/package.json +88 -0
  2. package/src/accordion.tsx +58 -0
  3. package/src/alert-dialog.tsx +121 -0
  4. package/src/alert.tsx +49 -0
  5. package/src/aspect-ratio.tsx +7 -0
  6. package/src/avatar.tsx +40 -0
  7. package/src/badge.tsx +34 -0
  8. package/src/breadcrumb.tsx +105 -0
  9. package/src/button.tsx +47 -0
  10. package/src/calendar.tsx +163 -0
  11. package/src/card.tsx +46 -0
  12. package/src/carousel.tsx +234 -0
  13. package/src/chart.tsx +296 -0
  14. package/src/checkbox.tsx +31 -0
  15. package/src/collapsible.tsx +15 -0
  16. package/src/command.tsx +154 -0
  17. package/src/context-menu.tsx +208 -0
  18. package/src/dialog.tsx +95 -0
  19. package/src/drawer.tsx +110 -0
  20. package/src/dropdown-menu.tsx +212 -0
  21. package/src/form.tsx +160 -0
  22. package/src/hooks/use-theme.ts +15 -0
  23. package/src/hooks/use-toast.ts +189 -0
  24. package/src/hover-card.tsx +35 -0
  25. package/src/index.ts +474 -0
  26. package/src/input.tsx +23 -0
  27. package/src/label.tsx +21 -0
  28. package/src/lib/utils.ts +6 -0
  29. package/src/menubar.tsx +244 -0
  30. package/src/navigation-menu.tsx +143 -0
  31. package/src/pagination.tsx +107 -0
  32. package/src/popover.tsx +45 -0
  33. package/src/progress.tsx +28 -0
  34. package/src/radio-group.tsx +41 -0
  35. package/src/resizable.tsx +59 -0
  36. package/src/scroll-area.tsx +42 -0
  37. package/src/search.tsx +87 -0
  38. package/src/select.tsx +169 -0
  39. package/src/separator.tsx +24 -0
  40. package/src/setupTests.ts +114 -0
  41. package/src/sheet.tsx +136 -0
  42. package/src/skeleton.tsx +10 -0
  43. package/src/slider.tsx +27 -0
  44. package/src/sonner.tsx +32 -0
  45. package/src/switch.tsx +31 -0
  46. package/src/table.tsx +104 -0
  47. package/src/tabs.tsx +62 -0
  48. package/src/text.tsx +55 -0
  49. package/src/textarea.tsx +25 -0
  50. package/src/theme-provider.tsx +15 -0
  51. package/src/theme-toggle.tsx +92 -0
  52. package/src/toast.tsx +111 -0
  53. package/src/toaster.tsx +27 -0
  54. package/src/toggle-group.tsx +55 -0
  55. package/src/toggle.tsx +24 -0
  56. package/src/tooltip.tsx +51 -0
@@ -0,0 +1,163 @@
1
+ import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
2
+ import * as React from 'react';
3
+ import { DayButton, DayPicker, getDefaultClassNames } from 'react-day-picker';
4
+
5
+ import { CalendarBaseProps } from '@gv-tech/ui-core';
6
+ import { Button, buttonVariants } from './button';
7
+ import { cn } from './lib/utils';
8
+
9
+ function Calendar({
10
+ className,
11
+ classNames,
12
+ showOutsideDays = true,
13
+ captionLayout = 'label',
14
+ buttonVariant = 'ghost',
15
+ formatters,
16
+ components,
17
+ ...props
18
+ }: React.ComponentProps<typeof DayPicker> &
19
+ CalendarBaseProps & {
20
+ buttonVariant?: React.ComponentProps<typeof Button>['variant'];
21
+ }) {
22
+ const defaultClassNames = getDefaultClassNames();
23
+
24
+ return (
25
+ <DayPicker
26
+ showOutsideDays={showOutsideDays}
27
+ className={cn(
28
+ 'bg-background group/calendar p-3 [--cell-size:2.5rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent',
29
+ String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
30
+ String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
31
+ 'relative',
32
+ className,
33
+ )}
34
+ captionLayout={captionLayout}
35
+ formatters={{
36
+ formatMonthDropdown: (date) => date.toLocaleString('default', { month: 'short' }),
37
+ ...formatters,
38
+ }}
39
+ classNames={{
40
+ root: cn('w-fit', defaultClassNames.root),
41
+ months: cn('relative flex flex-col gap-4 md:flex-row', defaultClassNames.months),
42
+ month: cn('flex w-full flex-col gap-4', defaultClassNames.month),
43
+ nav: cn(
44
+ 'absolute inset-x-0 top-2 flex items-center justify-between pointer-events-none px-2',
45
+ defaultClassNames.nav,
46
+ ),
47
+ button_previous: cn(
48
+ buttonVariants({ variant: buttonVariant }),
49
+ 'h-7 w-7 select-none p-0 aria-disabled:opacity-50 pointer-events-auto',
50
+ defaultClassNames.button_previous,
51
+ ),
52
+ button_next: cn(
53
+ buttonVariants({ variant: buttonVariant }),
54
+ 'h-7 w-7 select-none p-0 aria-disabled:opacity-50 pointer-events-auto',
55
+ defaultClassNames.button_next,
56
+ ),
57
+ month_caption: cn(
58
+ 'flex h-[--cell-size] w-full items-center justify-center text-sm font-medium',
59
+ defaultClassNames.month_caption,
60
+ ),
61
+ dropdowns: cn(
62
+ 'flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium',
63
+ defaultClassNames.dropdowns,
64
+ ),
65
+ dropdown_root: cn(
66
+ 'has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border',
67
+ defaultClassNames.dropdown_root,
68
+ ),
69
+ dropdown: cn('bg-popover absolute inset-0 opacity-0', defaultClassNames.dropdown),
70
+ caption_label: cn(
71
+ 'select-none font-medium',
72
+ captionLayout === 'label'
73
+ ? 'text-sm'
74
+ : '[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5',
75
+ defaultClassNames.caption_label,
76
+ ),
77
+ table: 'w-full border-collapse grow',
78
+ weekdays: cn('flex', defaultClassNames.weekdays),
79
+ weekday: cn(
80
+ 'text-muted-foreground pt-1 flex-1 select-none rounded-md text-[0.8rem] font-normal uppercase',
81
+ defaultClassNames.weekday,
82
+ ),
83
+ week: cn('flex w-full mt-2', defaultClassNames.week),
84
+ week_number_header: cn('w-[--cell-size] select-none', defaultClassNames.week_number_header),
85
+ week_number: cn('text-muted-foreground select-none text-[0.8rem]', defaultClassNames.week_number),
86
+ day: cn(
87
+ 'group/day relative flex aspect-square h-10 w-10 select-none items-center justify-center p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md',
88
+ defaultClassNames.day,
89
+ ),
90
+ range_start: cn('bg-accent rounded-l-md', defaultClassNames.range_start),
91
+ range_middle: cn('rounded-none', defaultClassNames.range_middle),
92
+ range_end: cn('bg-accent rounded-r-md', defaultClassNames.range_end),
93
+ today: cn(
94
+ 'bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none',
95
+ defaultClassNames.today,
96
+ ),
97
+ outside: cn('text-muted-foreground aria-selected:text-muted-foreground', defaultClassNames.outside),
98
+ disabled: cn('text-muted-foreground opacity-50', defaultClassNames.disabled),
99
+ hidden: cn('invisible', defaultClassNames.hidden),
100
+ ...classNames,
101
+ }}
102
+ components={{
103
+ Root: ({ className, rootRef, ...props }) => {
104
+ return <div data-slot="calendar" ref={rootRef} className={cn(className)} {...props} />;
105
+ },
106
+ Chevron: ({ className, orientation, ...props }) => {
107
+ if (orientation === 'left') {
108
+ return <ChevronLeftIcon className={cn('size-4', className)} {...props} />;
109
+ }
110
+
111
+ if (orientation === 'right') {
112
+ return <ChevronRightIcon className={cn('size-4', className)} {...props} />;
113
+ }
114
+
115
+ return <ChevronDownIcon className={cn('size-4', className)} {...props} />;
116
+ },
117
+ DayButton: CalendarDayButton,
118
+ WeekNumber: ({ children, ...props }) => {
119
+ return (
120
+ <td {...props}>
121
+ <div className="flex size-[--cell-size] items-center justify-center text-center">{children}</div>
122
+ </td>
123
+ );
124
+ },
125
+ ...components,
126
+ }}
127
+ {...props}
128
+ />
129
+ );
130
+ }
131
+
132
+ function CalendarDayButton({ className, day, modifiers, ...props }: React.ComponentProps<typeof DayButton>) {
133
+ const defaultClassNames = getDefaultClassNames();
134
+
135
+ const ref = React.useRef<HTMLButtonElement>(null);
136
+ React.useEffect(() => {
137
+ if (modifiers.focused) ref.current?.focus();
138
+ }, [modifiers.focused]);
139
+
140
+ return (
141
+ <Button
142
+ ref={ref}
143
+ variant="ghost"
144
+ size="icon"
145
+ data-day={day.date.toLocaleDateString()}
146
+ data-selected-single={
147
+ modifiers.selected && !modifiers.range_start && !modifiers.range_end && !modifiers.range_middle
148
+ }
149
+ data-range-start={modifiers.range_start}
150
+ data-range-end={modifiers.range_end}
151
+ data-range-middle={modifiers.range_middle}
152
+ className={cn(
153
+ 'data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 flex aspect-square h-full w-full min-w-[--cell-size] items-center justify-center font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] [&>span]:text-xs [&>span]:opacity-70',
154
+ defaultClassNames.day,
155
+ className,
156
+ )}
157
+ {...props}
158
+ />
159
+ );
160
+ }
161
+
162
+ export { Calendar, CalendarDayButton };
163
+ export type { CalendarBaseProps as CalendarProps };
package/src/card.tsx ADDED
@@ -0,0 +1,46 @@
1
+ import * as React from 'react';
2
+
3
+ import type { CardBaseProps } from '@gv-tech/ui-core';
4
+ import { cn } from './lib/utils';
5
+
6
+ export interface CardProps extends React.HTMLAttributes<HTMLDivElement>, CardBaseProps {}
7
+
8
+ const Card = React.forwardRef<HTMLDivElement, CardProps>(({ className, ...props }, ref) => (
9
+ <div ref={ref} className={cn('rounded-xl border bg-card text-card-foreground shadow', className)} {...props} />
10
+ ));
11
+ Card.displayName = 'Card';
12
+
13
+ const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
14
+ ({ className, ...props }, ref) => (
15
+ <div ref={ref} className={cn('flex flex-col space-y-1.5 p-6', className)} {...props} />
16
+ ),
17
+ );
18
+ CardHeader.displayName = 'CardHeader';
19
+
20
+ const CardTitle = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
21
+ ({ className, ...props }, ref) => (
22
+ <div ref={ref} className={cn('font-semibold leading-none tracking-tight', className)} {...props} />
23
+ ),
24
+ );
25
+ CardTitle.displayName = 'CardTitle';
26
+
27
+ const CardDescription = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
28
+ ({ className, ...props }, ref) => (
29
+ <div ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
30
+ ),
31
+ );
32
+ CardDescription.displayName = 'CardDescription';
33
+
34
+ const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
35
+ ({ className, ...props }, ref) => <div ref={ref} className={cn('p-6 pt-0', className)} {...props} />,
36
+ );
37
+ CardContent.displayName = 'CardContent';
38
+
39
+ const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
40
+ ({ className, ...props }, ref) => (
41
+ <div ref={ref} className={cn('flex items-center p-6 pt-0', className)} {...props} />
42
+ ),
43
+ );
44
+ CardFooter.displayName = 'CardFooter';
45
+
46
+ export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle };
@@ -0,0 +1,234 @@
1
+ import useEmblaCarousel, { type UseEmblaCarouselType } from 'embla-carousel-react';
2
+ import { ArrowLeft, ArrowRight } from 'lucide-react';
3
+ import * as React from 'react';
4
+
5
+ import {
6
+ CarouselBaseProps,
7
+ CarouselContentBaseProps,
8
+ CarouselItemBaseProps,
9
+ CarouselNextBaseProps,
10
+ CarouselPreviousBaseProps,
11
+ } from '@gv-tech/ui-core';
12
+ import { Button } from './button';
13
+ import { cn } from './lib/utils';
14
+
15
+ type CarouselApi = UseEmblaCarouselType[1];
16
+ type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
17
+ type CarouselOptions = UseCarouselParameters[0];
18
+ type CarouselPlugin = UseCarouselParameters[1];
19
+
20
+ type CarouselProps = React.HTMLAttributes<HTMLDivElement> &
21
+ CarouselBaseProps & {
22
+ opts?: CarouselOptions;
23
+ plugins?: CarouselPlugin;
24
+ setApi?: (api: CarouselApi) => void;
25
+ };
26
+
27
+ type CarouselContextProps = {
28
+ carouselRef: ReturnType<typeof useEmblaCarousel>[0];
29
+ api: ReturnType<typeof useEmblaCarousel>[1];
30
+ scrollPrev: () => void;
31
+ scrollNext: () => void;
32
+ canScrollPrev: boolean;
33
+ canScrollNext: boolean;
34
+ } & CarouselProps;
35
+
36
+ const CarouselContext = React.createContext<CarouselContextProps | null>(null);
37
+
38
+ function useCarousel() {
39
+ const context = React.useContext(CarouselContext);
40
+
41
+ if (!context) {
42
+ throw new Error('useCarousel must be used within a <Carousel />');
43
+ }
44
+
45
+ return context;
46
+ }
47
+
48
+ const Carousel = React.forwardRef<HTMLDivElement, CarouselProps>(
49
+ ({ orientation = 'horizontal', opts, setApi, plugins, className, children, ...props }, ref) => {
50
+ const [carouselRef, api] = useEmblaCarousel(
51
+ {
52
+ ...opts,
53
+ axis: orientation === 'horizontal' ? 'x' : 'y',
54
+ },
55
+ plugins,
56
+ );
57
+ const [canScrollPrev, setCanScrollPrev] = React.useState(false);
58
+ const [canScrollNext, setCanScrollNext] = React.useState(false);
59
+
60
+ const onSelect = React.useCallback((api: CarouselApi) => {
61
+ if (!api) {
62
+ return;
63
+ }
64
+
65
+ setCanScrollPrev(api.canScrollPrev());
66
+ setCanScrollNext(api.canScrollNext());
67
+ }, []);
68
+
69
+ const scrollPrev = React.useCallback(() => {
70
+ api?.scrollPrev();
71
+ }, [api]);
72
+
73
+ const scrollNext = React.useCallback(() => {
74
+ api?.scrollNext();
75
+ }, [api]);
76
+
77
+ const handleKeyDown = React.useCallback(
78
+ (event: React.KeyboardEvent<HTMLDivElement>) => {
79
+ if (event.key === 'ArrowLeft') {
80
+ event.preventDefault();
81
+ scrollPrev();
82
+ } else if (event.key === 'ArrowRight') {
83
+ event.preventDefault();
84
+ scrollNext();
85
+ }
86
+ },
87
+ [scrollPrev, scrollNext],
88
+ );
89
+
90
+ React.useEffect(() => {
91
+ if (!api || !setApi) {
92
+ return;
93
+ }
94
+
95
+ setApi(api);
96
+ }, [api, setApi]);
97
+
98
+ React.useEffect(() => {
99
+ if (!api) {
100
+ return;
101
+ }
102
+
103
+ onSelect(api);
104
+ api.on('reInit', onSelect);
105
+ api.on('select', onSelect);
106
+
107
+ return () => {
108
+ api?.off('select', onSelect);
109
+ };
110
+ }, [api, onSelect]);
111
+
112
+ return (
113
+ <CarouselContext.Provider
114
+ value={{
115
+ carouselRef,
116
+ api: api,
117
+ opts,
118
+ orientation: orientation || (opts?.axis === 'y' ? 'vertical' : 'horizontal'),
119
+ scrollPrev,
120
+ scrollNext,
121
+ canScrollPrev,
122
+ canScrollNext,
123
+ }}
124
+ >
125
+ <div
126
+ ref={ref}
127
+ onKeyDownCapture={handleKeyDown}
128
+ className={cn('relative', className)}
129
+ role="region"
130
+ aria-roledescription="carousel"
131
+ {...props}
132
+ >
133
+ {children}
134
+ </div>
135
+ </CarouselContext.Provider>
136
+ );
137
+ },
138
+ );
139
+ Carousel.displayName = 'Carousel';
140
+
141
+ const CarouselContent = React.forwardRef<
142
+ HTMLDivElement,
143
+ React.HTMLAttributes<HTMLDivElement> & CarouselContentBaseProps
144
+ >(({ className, ...props }, ref) => {
145
+ const { carouselRef, orientation } = useCarousel();
146
+
147
+ return (
148
+ <div ref={carouselRef} className="overflow-hidden">
149
+ <div
150
+ ref={ref}
151
+ className={cn('flex', orientation === 'horizontal' ? '-ml-4' : '-mt-4 flex-col', className)}
152
+ {...props}
153
+ />
154
+ </div>
155
+ );
156
+ });
157
+ CarouselContent.displayName = 'CarouselContent';
158
+
159
+ const CarouselItem = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement> & CarouselItemBaseProps>(
160
+ ({ className, ...props }, ref) => {
161
+ const { orientation } = useCarousel();
162
+
163
+ return (
164
+ <div
165
+ ref={ref}
166
+ role="group"
167
+ aria-roledescription="slide"
168
+ className={cn('min-w-0 shrink-0 grow-0 basis-full', orientation === 'horizontal' ? 'pl-4' : 'pt-4', className)}
169
+ {...props}
170
+ />
171
+ );
172
+ },
173
+ );
174
+ CarouselItem.displayName = 'CarouselItem';
175
+
176
+ const CarouselPrevious = React.forwardRef<
177
+ HTMLButtonElement,
178
+ React.ComponentProps<typeof Button> & CarouselPreviousBaseProps
179
+ >(({ className, variant = 'outline', size = 'icon', ...props }, ref) => {
180
+ const { orientation, scrollPrev, canScrollPrev } = useCarousel();
181
+
182
+ return (
183
+ <Button
184
+ ref={ref}
185
+ variant={variant}
186
+ size={size}
187
+ className={cn(
188
+ 'absolute h-8 w-8 rounded-full',
189
+ orientation === 'horizontal'
190
+ ? '-left-12 top-1/2 -translate-y-1/2'
191
+ : '-top-12 left-1/2 -translate-x-1/2 rotate-90',
192
+ className,
193
+ )}
194
+ disabled={!canScrollPrev}
195
+ onClick={scrollPrev}
196
+ {...props}
197
+ >
198
+ <ArrowLeft className="h-4 w-4" />
199
+ <span className="sr-only">Previous slide</span>
200
+ </Button>
201
+ );
202
+ });
203
+ CarouselPrevious.displayName = 'CarouselPrevious';
204
+
205
+ const CarouselNext = React.forwardRef<HTMLButtonElement, React.ComponentProps<typeof Button> & CarouselNextBaseProps>(
206
+ ({ className, variant = 'outline', size = 'icon', ...props }, ref) => {
207
+ const { orientation, scrollNext, canScrollNext } = useCarousel();
208
+
209
+ return (
210
+ <Button
211
+ ref={ref}
212
+ variant={variant}
213
+ size={size}
214
+ className={cn(
215
+ 'absolute h-8 w-8 rounded-full',
216
+ orientation === 'horizontal'
217
+ ? '-right-12 top-1/2 -translate-y-1/2'
218
+ : '-bottom-12 left-1/2 -translate-x-1/2 rotate-90',
219
+ className,
220
+ )}
221
+ disabled={!canScrollNext}
222
+ onClick={scrollNext}
223
+ {...props}
224
+ >
225
+ <ArrowRight className="h-4 w-4" />
226
+ <span className="sr-only">Next slide</span>
227
+ </Button>
228
+ );
229
+ },
230
+ );
231
+ CarouselNext.displayName = 'CarouselNext';
232
+
233
+ export { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, type CarouselApi };
234
+ export type { CarouselProps };