@ptengine/design-components 0.3.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/README.md +309 -0
- package/components.json +21 -0
- package/dist/components/ui/accordion.d.ts +8 -0
- package/dist/components/ui/accordion.d.ts.map +1 -0
- package/dist/components/ui/alert-dialog.d.ts +21 -0
- package/dist/components/ui/alert-dialog.d.ts.map +1 -0
- package/dist/components/ui/alert.d.ts +9 -0
- package/dist/components/ui/alert.d.ts.map +1 -0
- package/dist/components/ui/aspect-ratio.d.ts +4 -0
- package/dist/components/ui/aspect-ratio.d.ts.map +1 -0
- package/dist/components/ui/attachment.d.ts +26 -0
- package/dist/components/ui/attachment.d.ts.map +1 -0
- package/dist/components/ui/avatar.d.ts +10 -0
- package/dist/components/ui/avatar.d.ts.map +1 -0
- package/dist/components/ui/badge.d.ts +10 -0
- package/dist/components/ui/badge.d.ts.map +1 -0
- package/dist/components/ui/breadcrumb.d.ts +22 -0
- package/dist/components/ui/breadcrumb.d.ts.map +1 -0
- package/dist/components/ui/bubble.d.ts +19 -0
- package/dist/components/ui/bubble.d.ts.map +1 -0
- package/dist/components/ui/button-group.d.ts +13 -0
- package/dist/components/ui/button-group.d.ts.map +1 -0
- package/dist/components/ui/button.d.ts +13 -0
- package/dist/components/ui/button.d.ts.map +1 -0
- package/dist/components/ui/calendar.d.ts +9 -0
- package/dist/components/ui/calendar.d.ts.map +1 -0
- package/dist/components/ui/card.d.ts +9 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/carousel.d.ts +23 -0
- package/dist/components/ui/carousel.d.ts.map +1 -0
- package/dist/components/ui/chart.d.ts +63 -0
- package/dist/components/ui/chart.d.ts.map +1 -0
- package/dist/components/ui/checkbox.d.ts +5 -0
- package/dist/components/ui/checkbox.d.ts.map +1 -0
- package/dist/components/ui/collapsible.d.ts +6 -0
- package/dist/components/ui/collapsible.d.ts.map +1 -0
- package/dist/components/ui/command.d.ts +81 -0
- package/dist/components/ui/command.d.ts.map +1 -0
- package/dist/components/ui/context-menu.d.ts +28 -0
- package/dist/components/ui/context-menu.d.ts.map +1 -0
- package/dist/components/ui/dialog.d.ts +22 -0
- package/dist/components/ui/dialog.d.ts.map +1 -0
- package/dist/components/ui/direction.d.ts +8 -0
- package/dist/components/ui/direction.d.ts.map +1 -0
- package/dist/components/ui/drawer.d.ts +23 -0
- package/dist/components/ui/drawer.d.ts.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +28 -0
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/components/ui/empty.d.ts +13 -0
- package/dist/components/ui/empty.d.ts.map +1 -0
- package/dist/components/ui/field.d.ts +25 -0
- package/dist/components/ui/field.d.ts.map +1 -0
- package/dist/components/ui/hover-card.d.ts +7 -0
- package/dist/components/ui/hover-card.d.ts.map +1 -0
- package/dist/components/ui/input-group.d.ts +13 -0
- package/dist/components/ui/input-group.d.ts.map +1 -0
- package/dist/components/ui/input-otp.d.ts +35 -0
- package/dist/components/ui/input-otp.d.ts.map +1 -0
- package/dist/components/ui/input.d.ts +5 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/item.d.ts +24 -0
- package/dist/components/ui/item.d.ts.map +1 -0
- package/dist/components/ui/kbd.d.ts +5 -0
- package/dist/components/ui/kbd.d.ts.map +1 -0
- package/dist/components/ui/label.d.ts +6 -0
- package/dist/components/ui/label.d.ts.map +1 -0
- package/dist/components/ui/marker.d.ts +13 -0
- package/dist/components/ui/marker.d.ts.map +1 -0
- package/dist/components/ui/menubar.d.ts +29 -0
- package/dist/components/ui/menubar.d.ts.map +1 -0
- package/dist/components/ui/message-scroller.d.ts +26 -0
- package/dist/components/ui/message-scroller.d.ts.map +1 -0
- package/dist/components/ui/message.d.ts +11 -0
- package/dist/components/ui/message.d.ts.map +1 -0
- package/dist/components/ui/native-select.d.ts +4 -0
- package/dist/components/ui/native-select.d.ts.map +1 -0
- package/dist/components/ui/navigation-menu.d.ts +13 -0
- package/dist/components/ui/navigation-menu.d.ts.map +1 -0
- package/dist/components/ui/pagination.d.ts +35 -0
- package/dist/components/ui/pagination.d.ts.map +1 -0
- package/dist/components/ui/popover.d.ts +8 -0
- package/dist/components/ui/popover.d.ts.map +1 -0
- package/dist/components/ui/progress.d.ts +5 -0
- package/dist/components/ui/progress.d.ts.map +1 -0
- package/dist/components/ui/radio-group.d.ts +6 -0
- package/dist/components/ui/radio-group.d.ts.map +1 -0
- package/dist/components/ui/resizable.d.ts +24 -0
- package/dist/components/ui/resizable.d.ts.map +1 -0
- package/dist/components/ui/scroll-area.d.ts +6 -0
- package/dist/components/ui/scroll-area.d.ts.map +1 -0
- package/dist/components/ui/search-input.d.ts +23 -0
- package/dist/components/ui/search-input.d.ts.map +1 -0
- package/dist/components/ui/select.d.ts +14 -0
- package/dist/components/ui/select.d.ts.map +1 -0
- package/dist/components/ui/separator.d.ts +5 -0
- package/dist/components/ui/separator.d.ts.map +1 -0
- package/dist/components/ui/sheet.d.ts +28 -0
- package/dist/components/ui/sheet.d.ts.map +1 -0
- package/dist/components/ui/sidebar.d.ts +70 -0
- package/dist/components/ui/sidebar.d.ts.map +1 -0
- package/dist/components/ui/skeleton.d.ts +4 -0
- package/dist/components/ui/skeleton.d.ts.map +1 -0
- package/dist/components/ui/slider.d.ts +5 -0
- package/dist/components/ui/slider.d.ts.map +1 -0
- package/dist/components/ui/sonner.d.ts +6 -0
- package/dist/components/ui/sonner.d.ts.map +1 -0
- package/dist/components/ui/spinner.d.ts +7 -0
- package/dist/components/ui/spinner.d.ts.map +1 -0
- package/dist/components/ui/switch.d.ts +5 -0
- package/dist/components/ui/switch.d.ts.map +1 -0
- package/dist/components/ui/table.d.ts +11 -0
- package/dist/components/ui/table.d.ts.map +1 -0
- package/dist/components/ui/tabs.d.ts +13 -0
- package/dist/components/ui/tabs.d.ts.map +1 -0
- package/dist/components/ui/textarea.d.ts +5 -0
- package/dist/components/ui/textarea.d.ts.map +1 -0
- package/dist/components/ui/toggle-group.d.ts +13 -0
- package/dist/components/ui/toggle-group.d.ts.map +1 -0
- package/dist/components/ui/toggle.d.ts +13 -0
- package/dist/components/ui/toggle.d.ts.map +1 -0
- package/dist/components/ui/tooltip.d.ts +8 -0
- package/dist/components/ui/tooltip.d.ts.map +1 -0
- package/dist/hooks/use-mobile.d.ts +2 -0
- package/dist/hooks/use-mobile.d.ts.map +1 -0
- package/dist/index.cjs +82 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20969 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/llms.txt +173 -0
- package/package.json +125 -0
- package/src/components/ui/accordion.tsx +51 -0
- package/src/components/ui/alert-dialog.tsx +115 -0
- package/src/components/ui/alert.tsx +48 -0
- package/src/components/ui/aspect-ratio.tsx +5 -0
- package/src/components/ui/attachment.tsx +186 -0
- package/src/components/ui/avatar.tsx +57 -0
- package/src/components/ui/badge.tsx +40 -0
- package/src/components/ui/breadcrumb.tsx +101 -0
- package/src/components/ui/bubble.tsx +123 -0
- package/src/components/ui/button-group.tsx +74 -0
- package/src/components/ui/button.tsx +64 -0
- package/src/components/ui/calendar.tsx +63 -0
- package/src/components/ui/card.tsx +55 -0
- package/src/components/ui/carousel.tsx +252 -0
- package/src/components/ui/chart.tsx +323 -0
- package/src/components/ui/checkbox.tsx +26 -0
- package/src/components/ui/collapsible.tsx +9 -0
- package/src/components/ui/command.tsx +136 -0
- package/src/components/ui/context-menu.tsx +187 -0
- package/src/components/ui/dialog.tsx +103 -0
- package/src/components/ui/direction.tsx +15 -0
- package/src/components/ui/drawer.tsx +98 -0
- package/src/components/ui/dropdown-menu.tsx +186 -0
- package/src/components/ui/empty.tsx +75 -0
- package/src/components/ui/field.tsx +175 -0
- package/src/components/ui/hover-card.tsx +27 -0
- package/src/components/ui/input-group.tsx +80 -0
- package/src/components/ui/input-otp.tsx +67 -0
- package/src/components/ui/input.tsx +24 -0
- package/src/components/ui/item.tsx +118 -0
- package/src/components/ui/kbd.tsx +21 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/marker.tsx +67 -0
- package/src/components/ui/menubar.tsx +218 -0
- package/src/components/ui/message-scroller.tsx +206 -0
- package/src/components/ui/message.tsx +85 -0
- package/src/components/ui/native-select.tsx +29 -0
- package/src/components/ui/navigation-menu.tsx +120 -0
- package/src/components/ui/pagination.tsx +108 -0
- package/src/components/ui/popover.tsx +31 -0
- package/src/components/ui/progress.tsx +23 -0
- package/src/components/ui/radio-group.tsx +36 -0
- package/src/components/ui/resizable.tsx +40 -0
- package/src/components/ui/scroll-area.tsx +44 -0
- package/src/components/ui/search-input.tsx +97 -0
- package/src/components/ui/select.tsx +151 -0
- package/src/components/ui/separator.tsx +24 -0
- package/src/components/ui/sheet.tsx +124 -0
- package/src/components/ui/sidebar.tsx +704 -0
- package/src/components/ui/skeleton.tsx +9 -0
- package/src/components/ui/slider.tsx +41 -0
- package/src/components/ui/sonner.tsx +45 -0
- package/src/components/ui/spinner.tsx +21 -0
- package/src/components/ui/switch.tsx +27 -0
- package/src/components/ui/table.tsx +95 -0
- package/src/components/ui/tabs.tsx +119 -0
- package/src/components/ui/textarea.tsx +23 -0
- package/src/components/ui/toggle-group.tsx +55 -0
- package/src/components/ui/toggle.tsx +40 -0
- package/src/components/ui/tooltip.tsx +30 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/index.ts +414 -0
- package/src/lib/utils.ts +7 -0
- package/src/styles/tokens.css +360 -0
- package/tailwind.preset.js +235 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
3
|
+
import { DayPicker } from 'react-day-picker';
|
|
4
|
+
|
|
5
|
+
import { cn } from '../../lib/utils';
|
|
6
|
+
import { buttonVariants } from './button';
|
|
7
|
+
|
|
8
|
+
export type CalendarProps = React.ComponentProps<typeof DayPicker>;
|
|
9
|
+
|
|
10
|
+
function Calendar({ className, classNames, showOutsideDays = true, ...props }: CalendarProps) {
|
|
11
|
+
return (
|
|
12
|
+
<DayPicker
|
|
13
|
+
showOutsideDays={showOutsideDays}
|
|
14
|
+
className={cn('p-[12px]', className)}
|
|
15
|
+
classNames={{
|
|
16
|
+
months: 'flex flex-col sm:flex-row space-y-[16px] sm:space-x-[16px] sm:space-y-0',
|
|
17
|
+
month: 'space-y-[16px]',
|
|
18
|
+
caption: 'flex justify-center pt-[4px] relative items-center',
|
|
19
|
+
caption_label: 'text-[14px] leading-[20px] font-medium text-foreground',
|
|
20
|
+
nav: 'space-x-[4px] flex items-center',
|
|
21
|
+
nav_button: cn(buttonVariants({ variant: 'secondary' }), 'h-[24px] w-[24px] p-0'),
|
|
22
|
+
nav_button_previous: 'absolute left-[4px]',
|
|
23
|
+
nav_button_next: 'absolute right-[4px]',
|
|
24
|
+
table: 'w-full border-collapse space-y-[4px]',
|
|
25
|
+
head_row: 'flex',
|
|
26
|
+
head_cell: 'w-[32px] rounded-[var(--pt-radius-md)] text-[12px] leading-[16px] font-normal text-muted-foreground',
|
|
27
|
+
row: 'flex w-full mt-[8px]',
|
|
28
|
+
cell: cn(
|
|
29
|
+
'relative p-0 text-center text-[14px] leading-[20px] focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-range-end)]:rounded-r-[var(--pt-radius-md)]',
|
|
30
|
+
props.mode === 'range'
|
|
31
|
+
? '[&:has(>.day-range-end)]:rounded-r-[var(--pt-radius-md)] [&:has(>.day-range-start)]:rounded-l-[var(--pt-radius-md)] first:[&:has([aria-selected])]:rounded-l-[var(--pt-radius-md)] last:[&:has([aria-selected])]:rounded-r-[var(--pt-radius-md)]'
|
|
32
|
+
: '[&:has([aria-selected])]:rounded-[var(--pt-radius-md)]'
|
|
33
|
+
),
|
|
34
|
+
day: cn(
|
|
35
|
+
buttonVariants({ variant: 'ghost' }),
|
|
36
|
+
'h-[32px] w-[32px] p-0 font-normal aria-selected:opacity-100'
|
|
37
|
+
),
|
|
38
|
+
day_range_start: 'day-range-start',
|
|
39
|
+
day_range_end: 'day-range-end',
|
|
40
|
+
day_selected:
|
|
41
|
+
'bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground',
|
|
42
|
+
day_today: 'bg-accent text-accent-foreground',
|
|
43
|
+
day_outside: 'day-outside text-muted-foreground',
|
|
44
|
+
day_disabled: 'text-muted-foreground opacity-50',
|
|
45
|
+
day_range_middle: 'aria-selected:bg-accent aria-selected:text-accent-foreground',
|
|
46
|
+
day_hidden: 'invisible',
|
|
47
|
+
...classNames
|
|
48
|
+
}}
|
|
49
|
+
components={{
|
|
50
|
+
IconLeft: ({ className, ...props }) => (
|
|
51
|
+
<ChevronLeft className={cn('h-[16px] w-[16px]', className)} {...props} />
|
|
52
|
+
),
|
|
53
|
+
IconRight: ({ className, ...props }) => (
|
|
54
|
+
<ChevronRight className={cn('h-[16px] w-[16px]', className)} {...props} />
|
|
55
|
+
)
|
|
56
|
+
}}
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
Calendar.displayName = 'Calendar';
|
|
62
|
+
|
|
63
|
+
export { Calendar };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { cn } from '../../lib/utils';
|
|
4
|
+
|
|
5
|
+
const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
6
|
+
({ className, ...props }, ref) => (
|
|
7
|
+
<div
|
|
8
|
+
ref={ref}
|
|
9
|
+
className={cn('rounded-[12px] border bg-card text-card-foreground', className)}
|
|
10
|
+
{...props}
|
|
11
|
+
/>
|
|
12
|
+
)
|
|
13
|
+
);
|
|
14
|
+
Card.displayName = 'Card';
|
|
15
|
+
|
|
16
|
+
const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
17
|
+
({ className, ...props }, ref) => (
|
|
18
|
+
<div ref={ref} className={cn('flex flex-col space-y-[6px] p-[24px]', className)} {...props} />
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
CardHeader.displayName = 'CardHeader';
|
|
22
|
+
|
|
23
|
+
const CardTitle = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
24
|
+
({ className, ...props }, ref) => (
|
|
25
|
+
<div
|
|
26
|
+
ref={ref}
|
|
27
|
+
className={cn('font-semibold leading-none tracking-tight', className)}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
CardTitle.displayName = 'CardTitle';
|
|
33
|
+
|
|
34
|
+
const CardDescription = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
35
|
+
({ className, ...props }, ref) => (
|
|
36
|
+
<div ref={ref} className={cn('text-[14px] leading-[20px] text-muted-foreground', className)} {...props} />
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
CardDescription.displayName = 'CardDescription';
|
|
40
|
+
|
|
41
|
+
const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
42
|
+
({ className, ...props }, ref) => (
|
|
43
|
+
<div ref={ref} className={cn('p-[24px] pt-0', className)} {...props} />
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
CardContent.displayName = 'CardContent';
|
|
47
|
+
|
|
48
|
+
const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
49
|
+
({ className, ...props }, ref) => (
|
|
50
|
+
<div ref={ref} className={cn('flex items-center p-[24px] pt-0', className)} {...props} />
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
CardFooter.displayName = 'CardFooter';
|
|
54
|
+
|
|
55
|
+
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import useEmblaCarousel, { type UseEmblaCarouselType } from 'embla-carousel-react';
|
|
3
|
+
import { ArrowLeft, ArrowRight } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
import { cn } from '../../lib/utils';
|
|
6
|
+
import { Button } from './button';
|
|
7
|
+
|
|
8
|
+
type CarouselApi = UseEmblaCarouselType[1];
|
|
9
|
+
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
|
|
10
|
+
type CarouselOptions = UseCarouselParameters[0];
|
|
11
|
+
type CarouselPlugin = UseCarouselParameters[1];
|
|
12
|
+
|
|
13
|
+
type CarouselProps = {
|
|
14
|
+
opts?: CarouselOptions;
|
|
15
|
+
plugins?: CarouselPlugin;
|
|
16
|
+
orientation?: 'horizontal' | 'vertical';
|
|
17
|
+
setApi?: (api: CarouselApi) => void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type CarouselContextProps = {
|
|
21
|
+
carouselRef: ReturnType<typeof useEmblaCarousel>[0];
|
|
22
|
+
api: ReturnType<typeof useEmblaCarousel>[1];
|
|
23
|
+
scrollPrev: () => void;
|
|
24
|
+
scrollNext: () => void;
|
|
25
|
+
canScrollPrev: boolean;
|
|
26
|
+
canScrollNext: boolean;
|
|
27
|
+
} & CarouselProps;
|
|
28
|
+
|
|
29
|
+
const CarouselContext = React.createContext<CarouselContextProps | null>(null);
|
|
30
|
+
|
|
31
|
+
function useCarousel() {
|
|
32
|
+
const context = React.useContext(CarouselContext);
|
|
33
|
+
|
|
34
|
+
if (!context) {
|
|
35
|
+
throw new Error('useCarousel must be used within a <Carousel />');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return context;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const Carousel = React.forwardRef<
|
|
42
|
+
HTMLDivElement,
|
|
43
|
+
React.HTMLAttributes<HTMLDivElement> & CarouselProps
|
|
44
|
+
>(({ orientation = 'horizontal', opts, setApi, plugins, className, children, ...props }, ref) => {
|
|
45
|
+
const [carouselRef, api] = useEmblaCarousel(
|
|
46
|
+
{
|
|
47
|
+
...opts,
|
|
48
|
+
axis: orientation === 'horizontal' ? 'x' : 'y'
|
|
49
|
+
},
|
|
50
|
+
plugins
|
|
51
|
+
);
|
|
52
|
+
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
|
53
|
+
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
|
54
|
+
|
|
55
|
+
const onSelect = React.useCallback((api: CarouselApi) => {
|
|
56
|
+
if (!api) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
setCanScrollPrev(api.canScrollPrev());
|
|
61
|
+
setCanScrollNext(api.canScrollNext());
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
const scrollPrev = React.useCallback(() => {
|
|
65
|
+
api?.scrollPrev();
|
|
66
|
+
}, [api]);
|
|
67
|
+
|
|
68
|
+
const scrollNext = React.useCallback(() => {
|
|
69
|
+
api?.scrollNext();
|
|
70
|
+
}, [api]);
|
|
71
|
+
|
|
72
|
+
const handleKeyDown = React.useCallback(
|
|
73
|
+
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
74
|
+
if (event.key === 'ArrowLeft') {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
scrollPrev();
|
|
77
|
+
} else if (event.key === 'ArrowRight') {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
scrollNext();
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
[scrollPrev, scrollNext]
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
React.useEffect(() => {
|
|
86
|
+
if (!api || !setApi) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
setApi(api);
|
|
91
|
+
}, [api, setApi]);
|
|
92
|
+
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
if (!api) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
onSelect(api);
|
|
99
|
+
api.on('reInit', onSelect);
|
|
100
|
+
api.on('select', onSelect);
|
|
101
|
+
|
|
102
|
+
return () => {
|
|
103
|
+
api?.off('select', onSelect);
|
|
104
|
+
};
|
|
105
|
+
}, [api, onSelect]);
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<CarouselContext.Provider
|
|
109
|
+
value={{
|
|
110
|
+
carouselRef,
|
|
111
|
+
api: api,
|
|
112
|
+
opts,
|
|
113
|
+
orientation: orientation || (opts?.axis === 'y' ? 'vertical' : 'horizontal'),
|
|
114
|
+
scrollPrev,
|
|
115
|
+
scrollNext,
|
|
116
|
+
canScrollPrev,
|
|
117
|
+
canScrollNext
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
<div
|
|
121
|
+
ref={ref}
|
|
122
|
+
onKeyDownCapture={handleKeyDown}
|
|
123
|
+
className={cn('relative', className)}
|
|
124
|
+
role="region"
|
|
125
|
+
aria-roledescription="carousel"
|
|
126
|
+
{...props}
|
|
127
|
+
>
|
|
128
|
+
{children}
|
|
129
|
+
</div>
|
|
130
|
+
</CarouselContext.Provider>
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
Carousel.displayName = 'Carousel';
|
|
134
|
+
|
|
135
|
+
const CarouselContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
136
|
+
({ className, ...props }, ref) => {
|
|
137
|
+
const { carouselRef, orientation } = useCarousel();
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<div ref={carouselRef} className="overflow-hidden">
|
|
141
|
+
<div
|
|
142
|
+
ref={ref}
|
|
143
|
+
className={cn(
|
|
144
|
+
'flex',
|
|
145
|
+
orientation === 'horizontal' ? '-ml-[16px]' : '-mt-[16px] flex-col',
|
|
146
|
+
className
|
|
147
|
+
)}
|
|
148
|
+
{...props}
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
CarouselContent.displayName = 'CarouselContent';
|
|
155
|
+
|
|
156
|
+
const CarouselItem = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
|
157
|
+
({ className, ...props }, ref) => {
|
|
158
|
+
const { orientation } = useCarousel();
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<div
|
|
162
|
+
ref={ref}
|
|
163
|
+
role="group"
|
|
164
|
+
aria-roledescription="slide"
|
|
165
|
+
className={cn(
|
|
166
|
+
'min-w-0 shrink-0 grow-0 basis-full',
|
|
167
|
+
orientation === 'horizontal' ? 'pl-[16px]' : 'pt-[16px]',
|
|
168
|
+
className
|
|
169
|
+
)}
|
|
170
|
+
{...props}
|
|
171
|
+
/>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
CarouselItem.displayName = 'CarouselItem';
|
|
176
|
+
|
|
177
|
+
const CarouselPrevious = React.forwardRef<
|
|
178
|
+
HTMLButtonElement,
|
|
179
|
+
React.ComponentProps<typeof Button> & { label?: string }
|
|
180
|
+
>(
|
|
181
|
+
(
|
|
182
|
+
{ className, variant = 'secondary', size = 'icon', label = 'Previous slide', ...props },
|
|
183
|
+
ref
|
|
184
|
+
) => {
|
|
185
|
+
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<Button
|
|
189
|
+
ref={ref}
|
|
190
|
+
variant={variant}
|
|
191
|
+
size={size}
|
|
192
|
+
className={cn(
|
|
193
|
+
'absolute h-[32px] w-[32px] rounded-full',
|
|
194
|
+
orientation === 'horizontal'
|
|
195
|
+
? '-left-[48px] top-1/2 -translate-y-1/2'
|
|
196
|
+
: '-top-[48px] left-1/2 -translate-x-1/2 rotate-90',
|
|
197
|
+
className
|
|
198
|
+
)}
|
|
199
|
+
disabled={!canScrollPrev}
|
|
200
|
+
onClick={scrollPrev}
|
|
201
|
+
{...props}
|
|
202
|
+
>
|
|
203
|
+
<ArrowLeft className="h-[16px] w-[16px]" />
|
|
204
|
+
<span className="sr-only">{label}</span>
|
|
205
|
+
</Button>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
CarouselPrevious.displayName = 'CarouselPrevious';
|
|
210
|
+
|
|
211
|
+
const CarouselNext = React.forwardRef<
|
|
212
|
+
HTMLButtonElement,
|
|
213
|
+
React.ComponentProps<typeof Button> & { label?: string }
|
|
214
|
+
>(
|
|
215
|
+
(
|
|
216
|
+
{ className, variant = 'secondary', size = 'icon', label = 'Next slide', ...props },
|
|
217
|
+
ref
|
|
218
|
+
) => {
|
|
219
|
+
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
<Button
|
|
223
|
+
ref={ref}
|
|
224
|
+
variant={variant}
|
|
225
|
+
size={size}
|
|
226
|
+
className={cn(
|
|
227
|
+
'absolute h-[32px] w-[32px] rounded-full',
|
|
228
|
+
orientation === 'horizontal'
|
|
229
|
+
? '-right-[48px] top-1/2 -translate-y-1/2'
|
|
230
|
+
: '-bottom-[48px] left-1/2 -translate-x-1/2 rotate-90',
|
|
231
|
+
className
|
|
232
|
+
)}
|
|
233
|
+
disabled={!canScrollNext}
|
|
234
|
+
onClick={scrollNext}
|
|
235
|
+
{...props}
|
|
236
|
+
>
|
|
237
|
+
<ArrowRight className="h-[16px] w-[16px]" />
|
|
238
|
+
<span className="sr-only">{label}</span>
|
|
239
|
+
</Button>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
);
|
|
243
|
+
CarouselNext.displayName = 'CarouselNext';
|
|
244
|
+
|
|
245
|
+
export {
|
|
246
|
+
type CarouselApi,
|
|
247
|
+
Carousel,
|
|
248
|
+
CarouselContent,
|
|
249
|
+
CarouselItem,
|
|
250
|
+
CarouselPrevious,
|
|
251
|
+
CarouselNext
|
|
252
|
+
};
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as RechartsPrimitive from 'recharts';
|
|
3
|
+
|
|
4
|
+
import { cn } from '../../lib/utils';
|
|
5
|
+
|
|
6
|
+
const THEMES = { light: '', dark: '.dark' } as const;
|
|
7
|
+
|
|
8
|
+
export type ChartConfig = {
|
|
9
|
+
[k in string]: {
|
|
10
|
+
label?: React.ReactNode;
|
|
11
|
+
icon?: React.ComponentType;
|
|
12
|
+
} & (
|
|
13
|
+
| { color?: string; theme?: never }
|
|
14
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type ChartContextProps = {
|
|
19
|
+
config: ChartConfig;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null);
|
|
23
|
+
|
|
24
|
+
function useChart() {
|
|
25
|
+
const context = React.useContext(ChartContext);
|
|
26
|
+
|
|
27
|
+
if (!context) {
|
|
28
|
+
throw new Error('useChart must be used within a <ChartContainer />');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return context;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const ChartContainer = React.forwardRef<
|
|
35
|
+
HTMLDivElement,
|
|
36
|
+
React.ComponentProps<'div'> & {
|
|
37
|
+
config: ChartConfig;
|
|
38
|
+
children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>['children'];
|
|
39
|
+
}
|
|
40
|
+
>(({ id, className, children, config, ...props }, ref) => {
|
|
41
|
+
const uniqueId = React.useId();
|
|
42
|
+
const chartId = `chart-${id || uniqueId.replace(/:/g, '')}`;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<ChartContext.Provider value={{ config }}>
|
|
46
|
+
<div
|
|
47
|
+
data-chart={chartId}
|
|
48
|
+
ref={ref}
|
|
49
|
+
className={cn(
|
|
50
|
+
"flex aspect-video justify-center text-[13px] leading-[20px] [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",
|
|
51
|
+
className
|
|
52
|
+
)}
|
|
53
|
+
{...props}
|
|
54
|
+
>
|
|
55
|
+
<ChartStyle id={chartId} config={config} />
|
|
56
|
+
<RechartsPrimitive.ResponsiveContainer>{children}</RechartsPrimitive.ResponsiveContainer>
|
|
57
|
+
</div>
|
|
58
|
+
</ChartContext.Provider>
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
ChartContainer.displayName = 'Chart';
|
|
62
|
+
|
|
63
|
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
64
|
+
const colorConfig = Object.entries(config).filter(([, config]) => config.theme || config.color);
|
|
65
|
+
|
|
66
|
+
if (!colorConfig.length) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<style
|
|
72
|
+
dangerouslySetInnerHTML={{
|
|
73
|
+
__html: Object.entries(THEMES)
|
|
74
|
+
.map(
|
|
75
|
+
([theme, prefix]) => `
|
|
76
|
+
${prefix} [data-chart=${id}] {
|
|
77
|
+
${colorConfig
|
|
78
|
+
.map(([key, itemConfig]) => {
|
|
79
|
+
const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] || itemConfig.color;
|
|
80
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
81
|
+
})
|
|
82
|
+
.join('\n')}
|
|
83
|
+
}
|
|
84
|
+
`
|
|
85
|
+
)
|
|
86
|
+
.join('\n')
|
|
87
|
+
}}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
93
|
+
|
|
94
|
+
const ChartTooltipContent = React.forwardRef<
|
|
95
|
+
HTMLDivElement,
|
|
96
|
+
React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
97
|
+
React.ComponentProps<'div'> & {
|
|
98
|
+
hideLabel?: boolean;
|
|
99
|
+
hideIndicator?: boolean;
|
|
100
|
+
indicator?: 'line' | 'dot' | 'dashed';
|
|
101
|
+
nameKey?: string;
|
|
102
|
+
labelKey?: string;
|
|
103
|
+
}
|
|
104
|
+
>(
|
|
105
|
+
(
|
|
106
|
+
{
|
|
107
|
+
active,
|
|
108
|
+
payload,
|
|
109
|
+
className,
|
|
110
|
+
indicator = 'dot',
|
|
111
|
+
hideLabel = false,
|
|
112
|
+
hideIndicator = false,
|
|
113
|
+
label,
|
|
114
|
+
labelFormatter,
|
|
115
|
+
labelClassName,
|
|
116
|
+
formatter,
|
|
117
|
+
color,
|
|
118
|
+
nameKey,
|
|
119
|
+
labelKey
|
|
120
|
+
},
|
|
121
|
+
ref
|
|
122
|
+
) => {
|
|
123
|
+
const { config } = useChart();
|
|
124
|
+
|
|
125
|
+
const tooltipLabel = React.useMemo(() => {
|
|
126
|
+
if (hideLabel || !payload?.length) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const [item] = payload;
|
|
131
|
+
const key = `${labelKey || item.dataKey || item.name || 'value'}`;
|
|
132
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
133
|
+
const value =
|
|
134
|
+
!labelKey && typeof label === 'string'
|
|
135
|
+
? config[label as keyof typeof config]?.label || label
|
|
136
|
+
: itemConfig?.label;
|
|
137
|
+
|
|
138
|
+
if (labelFormatter) {
|
|
139
|
+
return (
|
|
140
|
+
<div className={cn('font-medium', labelClassName)}>
|
|
141
|
+
{labelFormatter(value, payload)}
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!value) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return <div className={cn('font-medium', labelClassName)}>{value}</div>;
|
|
151
|
+
}, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
|
|
152
|
+
|
|
153
|
+
if (!active || !payload?.length) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const nestLabel = payload.length === 1 && indicator !== 'dot';
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<div
|
|
161
|
+
ref={ref}
|
|
162
|
+
className={cn(
|
|
163
|
+
'grid min-w-[8rem] items-start gap-[6px] rounded-[var(--pt-radius)] border bg-background px-[10px] py-[6px] text-[13px] leading-[20px] shadow-xl',
|
|
164
|
+
className
|
|
165
|
+
)}
|
|
166
|
+
>
|
|
167
|
+
{!nestLabel ? tooltipLabel : null}
|
|
168
|
+
<div className="grid gap-[6px]">
|
|
169
|
+
{payload.map((item, index) => {
|
|
170
|
+
const key = `${nameKey || item.name || item.dataKey || 'value'}`;
|
|
171
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
172
|
+
const indicatorColor = color || item.payload.fill || item.color;
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<div
|
|
176
|
+
key={item.dataKey}
|
|
177
|
+
className={cn(
|
|
178
|
+
'flex w-full flex-wrap items-stretch gap-[8px] [&>svg]:h-[10px] [&>svg]:w-[10px] [&>svg]:text-muted-foreground',
|
|
179
|
+
indicator === 'dot' && 'items-center'
|
|
180
|
+
)}
|
|
181
|
+
>
|
|
182
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
183
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
184
|
+
) : (
|
|
185
|
+
<>
|
|
186
|
+
{itemConfig?.icon ? (
|
|
187
|
+
<itemConfig.icon />
|
|
188
|
+
) : (
|
|
189
|
+
!hideIndicator && (
|
|
190
|
+
<div
|
|
191
|
+
className={cn(
|
|
192
|
+
'shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]',
|
|
193
|
+
{
|
|
194
|
+
'h-[10px] w-[10px]': indicator === 'dot',
|
|
195
|
+
'w-[4px]': indicator === 'line',
|
|
196
|
+
'w-0 border-[1.5px] border-dashed bg-transparent':
|
|
197
|
+
indicator === 'dashed',
|
|
198
|
+
'my-[2px]': nestLabel && indicator === 'dashed'
|
|
199
|
+
}
|
|
200
|
+
)}
|
|
201
|
+
style={
|
|
202
|
+
{
|
|
203
|
+
'--color-bg': indicatorColor,
|
|
204
|
+
'--color-border': indicatorColor
|
|
205
|
+
} as React.CSSProperties
|
|
206
|
+
}
|
|
207
|
+
/>
|
|
208
|
+
)
|
|
209
|
+
)}
|
|
210
|
+
<div
|
|
211
|
+
className={cn(
|
|
212
|
+
'flex flex-1 justify-between leading-none',
|
|
213
|
+
nestLabel ? 'items-end' : 'items-center'
|
|
214
|
+
)}
|
|
215
|
+
>
|
|
216
|
+
<div className="grid gap-[6px]">
|
|
217
|
+
{nestLabel ? tooltipLabel : null}
|
|
218
|
+
<span className="text-muted-foreground">
|
|
219
|
+
{itemConfig?.label || item.name}
|
|
220
|
+
</span>
|
|
221
|
+
</div>
|
|
222
|
+
{item.value && (
|
|
223
|
+
<span className="font-mono font-medium tabular-nums text-foreground">
|
|
224
|
+
{item.value.toLocaleString()}
|
|
225
|
+
</span>
|
|
226
|
+
)}
|
|
227
|
+
</div>
|
|
228
|
+
</>
|
|
229
|
+
)}
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
})}
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
);
|
|
238
|
+
ChartTooltipContent.displayName = 'ChartTooltip';
|
|
239
|
+
|
|
240
|
+
const ChartLegend = RechartsPrimitive.Legend;
|
|
241
|
+
|
|
242
|
+
const ChartLegendContent = React.forwardRef<
|
|
243
|
+
HTMLDivElement,
|
|
244
|
+
React.ComponentProps<'div'> &
|
|
245
|
+
Pick<RechartsPrimitive.LegendProps, 'payload' | 'verticalAlign'> & {
|
|
246
|
+
hideIcon?: boolean;
|
|
247
|
+
nameKey?: string;
|
|
248
|
+
}
|
|
249
|
+
>(({ className, hideIcon = false, payload, verticalAlign = 'bottom', nameKey }, ref) => {
|
|
250
|
+
const { config } = useChart();
|
|
251
|
+
|
|
252
|
+
if (!payload?.length) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return (
|
|
257
|
+
<div
|
|
258
|
+
ref={ref}
|
|
259
|
+
className={cn(
|
|
260
|
+
'flex items-center justify-center gap-[16px]',
|
|
261
|
+
verticalAlign === 'top' ? 'pb-[12px]' : 'pt-[12px]',
|
|
262
|
+
className
|
|
263
|
+
)}
|
|
264
|
+
>
|
|
265
|
+
{payload.map(item => {
|
|
266
|
+
const key = `${nameKey || item.dataKey || 'value'}`;
|
|
267
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<div
|
|
271
|
+
key={item.value}
|
|
272
|
+
className="flex items-center gap-[6px] text-foreground [&>svg]:h-[12px] [&>svg]:w-[12px] [&>svg]:text-muted-foreground"
|
|
273
|
+
>
|
|
274
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
275
|
+
<itemConfig.icon />
|
|
276
|
+
) : (
|
|
277
|
+
<div
|
|
278
|
+
className="h-[8px] w-[8px] shrink-0 rounded-[2px]"
|
|
279
|
+
style={{ backgroundColor: item.color }}
|
|
280
|
+
/>
|
|
281
|
+
)}
|
|
282
|
+
{itemConfig?.label}
|
|
283
|
+
</div>
|
|
284
|
+
);
|
|
285
|
+
})}
|
|
286
|
+
</div>
|
|
287
|
+
);
|
|
288
|
+
});
|
|
289
|
+
ChartLegendContent.displayName = 'ChartLegend';
|
|
290
|
+
|
|
291
|
+
function getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {
|
|
292
|
+
if (typeof payload !== 'object' || payload === null) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const payloadPayload =
|
|
297
|
+
'payload' in payload && typeof payload.payload === 'object' && payload.payload !== null
|
|
298
|
+
? payload.payload
|
|
299
|
+
: undefined;
|
|
300
|
+
|
|
301
|
+
let configLabelKey: string = key;
|
|
302
|
+
|
|
303
|
+
if (key in payload && typeof payload[key as keyof typeof payload] === 'string') {
|
|
304
|
+
configLabelKey = payload[key as keyof typeof payload] as string;
|
|
305
|
+
} else if (
|
|
306
|
+
payloadPayload &&
|
|
307
|
+
key in payloadPayload &&
|
|
308
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === 'string'
|
|
309
|
+
) {
|
|
310
|
+
configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return configLabelKey in config ? config[configLabelKey] : config[key as keyof typeof config];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export {
|
|
317
|
+
ChartContainer,
|
|
318
|
+
ChartTooltip,
|
|
319
|
+
ChartTooltipContent,
|
|
320
|
+
ChartLegend,
|
|
321
|
+
ChartLegendContent,
|
|
322
|
+
ChartStyle
|
|
323
|
+
};
|