@regardio/react 0.5.7 → 0.7.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/dist/background-slideshow/index.d.mts +34 -0
- package/dist/background-slideshow/index.mjs +110 -0
- package/dist/blurry-gradient/index.d.mts +16 -0
- package/dist/blurry-gradient/index.mjs +93 -0
- package/dist/button/index.d.mts +2 -0
- package/dist/button/index.mjs +3 -0
- package/dist/button-BiSQpBbc.mjs +129 -0
- package/dist/carousel/index.d.mts +74 -0
- package/dist/carousel/index.mjs +136 -0
- package/dist/checkbox/index.d.mts +28 -0
- package/dist/checkbox/index.mjs +70 -0
- package/dist/checkbox-group/index.d.mts +16 -0
- package/dist/checkbox-group/index.mjs +29 -0
- package/dist/chunk-BTpB_u-K.mjs +18 -0
- package/dist/countdown/index.d.mts +4 -0
- package/dist/countdown/index.mjs +58 -0
- package/dist/field/index.d.mts +68 -0
- package/dist/field/index.mjs +115 -0
- package/dist/fieldset/index.d.mts +34 -0
- package/dist/fieldset/index.mjs +61 -0
- package/dist/form/index.d.mts +21 -0
- package/dist/form/index.mjs +31 -0
- package/dist/generic-error/index.d.mts +44 -0
- package/dist/generic-error/index.mjs +57 -0
- package/dist/grid/index.d.mts +101 -0
- package/dist/grid/index.mjs +219 -0
- package/dist/heading/index.d.mts +27 -0
- package/dist/heading/index.mjs +28 -0
- package/dist/highlight/index.d.mts +17 -0
- package/dist/highlight/index.mjs +35 -0
- package/dist/hooks/use-current-route-data.d.mts +8 -0
- package/dist/hooks/use-current-route-data.mjs +22 -0
- package/dist/hooks/{use-focus-search.d.ts → use-focus-search.d.mts} +4 -3
- package/dist/hooks/use-focus-search.mjs +23 -0
- package/dist/hooks/use-matches-data.d.mts +10 -0
- package/dist/hooks/use-matches-data.mjs +23 -0
- package/dist/hooks/use-media-query.d.mts +9 -0
- package/dist/hooks/use-media-query.mjs +28 -0
- package/dist/hooks/use-mobile.d.mts +4 -0
- package/dist/hooks/use-mobile.mjs +22 -0
- package/dist/hooks/use-nonce.d.mts +6 -0
- package/dist/hooks/use-nonce.mjs +13 -0
- package/dist/hooks/use-orientation.d.mts +12 -0
- package/dist/hooks/use-orientation.mjs +32 -0
- package/dist/hooks/use-user.d.mts +53 -0
- package/dist/hooks/use-user.mjs +39 -0
- package/dist/icon-button/index.d.mts +28 -0
- package/dist/icon-button/index.mjs +36 -0
- package/dist/if/index.d.mts +13 -0
- package/dist/if/index.mjs +21 -0
- package/dist/iframe/index.d.mts +11 -0
- package/dist/iframe/index.mjs +15 -0
- package/dist/index-Bj5_XfEC.d.mts +29 -0
- package/dist/index-C_evL5vG.d.mts +35 -0
- package/dist/input/index.d.mts +2 -0
- package/dist/input/index.mjs +3 -0
- package/dist/input-CtR6aRVi.mjs +73 -0
- package/dist/link/index.d.mts +71 -0
- package/dist/link/index.mjs +129 -0
- package/dist/list/index.d.mts +72 -0
- package/dist/list/index.mjs +54 -0
- package/dist/markdown-container/index.d.mts +23 -0
- package/dist/markdown-container/index.mjs +71 -0
- package/dist/password-input/index.d.mts +23 -0
- package/dist/password-input/index.mjs +92 -0
- package/dist/picture/index.d.mts +39 -0
- package/dist/picture/index.mjs +3 -0
- package/dist/picture-DkX3W5zl.mjs +69 -0
- package/dist/protected-email/index.d.mts +24 -0
- package/dist/protected-email/index.mjs +37 -0
- package/dist/radio/index.d.mts +28 -0
- package/dist/radio/index.mjs +72 -0
- package/dist/radio-group/index.d.mts +16 -0
- package/dist/radio-group/index.mjs +29 -0
- package/dist/slider/index.d.mts +63 -0
- package/dist/slider/index.mjs +133 -0
- package/dist/switch/index.d.mts +29 -0
- package/dist/switch/index.mjs +87 -0
- package/dist/text/index.d.mts +25 -0
- package/dist/text/index.mjs +32 -0
- package/dist/text-EQC4zJbE.mjs +52 -0
- package/dist/toggle/index.d.mts +25 -0
- package/dist/toggle/index.mjs +82 -0
- package/dist/utils/author/index.d.mts +4 -0
- package/dist/utils/author/index.mjs +26 -0
- package/dist/utils/text/{index.d.ts → index.d.mts} +9 -8
- package/dist/utils/text/index.mjs +3 -0
- package/package.json +131 -83
- package/src/background-slideshow/background-slideshow.tsx +1 -2
- package/src/blurry-gradient/blurry-gradient.tsx +1 -1
- package/src/button/button.stories.tsx +161 -0
- package/src/button/button.test.tsx +73 -0
- package/src/button/button.tsx +118 -0
- package/src/button/index.ts +2 -0
- package/src/carousel/carousel-content.tsx +17 -14
- package/src/carousel/carousel-item.tsx +18 -18
- package/src/carousel/carousel-next.tsx +22 -17
- package/src/carousel/carousel-previous.tsx +22 -17
- package/src/carousel/carousel-root.tsx +91 -86
- package/src/checkbox/checkbox.stories.tsx +118 -0
- package/src/checkbox/checkbox.tsx +102 -0
- package/src/checkbox/index.ts +2 -0
- package/src/checkbox-group/checkbox-group.tsx +40 -0
- package/src/checkbox-group/index.ts +2 -0
- package/src/countdown/countdown.tsx +1 -1
- package/src/field/field.stories.tsx +105 -0
- package/src/field/field.test.tsx +61 -0
- package/src/field/field.tsx +186 -0
- package/src/field/index.ts +12 -0
- package/src/fieldset/fieldset.stories.tsx +204 -0
- package/src/fieldset/fieldset.test.tsx +63 -0
- package/src/fieldset/fieldset.tsx +86 -0
- package/src/fieldset/index.ts +7 -0
- package/src/form/form.stories.tsx +230 -0
- package/src/form/form.test.tsx +68 -0
- package/src/form/form.tsx +38 -0
- package/src/form/index.ts +2 -0
- package/src/generic-error/generic-error.tsx +2 -3
- package/src/grid/grid-item.tsx +77 -36
- package/src/grid/grid-root.tsx +49 -22
- package/src/heading/heading.tsx +7 -3
- package/src/highlight/highlight.tsx +1 -1
- package/src/hooks/use-current-route-data.ts +4 -2
- package/src/hooks/use-focus-search.ts +3 -1
- package/src/hooks/use-matches-data.ts +2 -0
- package/src/hooks/use-media-query.ts +2 -0
- package/src/hooks/use-mobile.ts +3 -1
- package/src/hooks/use-nonce.ts +3 -3
- package/src/hooks/use-orientation.ts +2 -0
- package/src/hooks/use-user.tsx +3 -2
- package/src/icon-button/icon-button.stories.tsx +128 -7
- package/src/icon-button/icon-button.test.tsx +152 -0
- package/src/icon-button/icon-button.tsx +43 -9
- package/src/if/if.tsx +3 -1
- package/src/input/index.ts +2 -0
- package/src/input/input.stories.tsx +151 -0
- package/src/input/input.test.tsx +65 -0
- package/src/input/input.tsx +113 -0
- package/src/link/link.tsx +4 -3
- package/src/list/list-item.tsx +10 -13
- package/src/list/list-root-context.ts +3 -3
- package/src/list/list-root.tsx +10 -13
- package/src/password-input/index.ts +1 -1
- package/src/password-input/password-input.tsx +104 -27
- package/src/protected-email/protected-email.tsx +6 -1
- package/src/radio/index.ts +2 -0
- package/src/radio/radio.tsx +103 -0
- package/src/radio-group/index.ts +2 -0
- package/src/radio-group/radio-group.tsx +40 -0
- package/src/slider/index.ts +18 -0
- package/src/slider/slider.tsx +201 -0
- package/src/switch/index.ts +2 -0
- package/src/switch/switch.stories.tsx +118 -0
- package/src/switch/switch.tsx +112 -0
- package/src/text/text.tsx +6 -1
- package/src/toggle/index.ts +2 -0
- package/src/toggle/toggle.stories.tsx +232 -0
- package/src/toggle/toggle.test.tsx +149 -0
- package/src/toggle/toggle.tsx +88 -0
- package/src/utils/text/text.tsx +8 -16
- package/dist/background-slideshow/index.d.ts +0 -24
- package/dist/background-slideshow/index.js +0 -165
- package/dist/blurry-gradient/index.d.ts +0 -16
- package/dist/blurry-gradient/index.js +0 -128
- package/dist/carousel/index.d.ts +0 -36
- package/dist/carousel/index.js +0 -171
- package/dist/countdown/index.d.ts +0 -5
- package/dist/countdown/index.js +0 -73
- package/dist/generic-error/index.d.ts +0 -43
- package/dist/generic-error/index.js +0 -47
- package/dist/grid/index.d.ts +0 -1196
- package/dist/grid/index.js +0 -239
- package/dist/heading/index.d.ts +0 -24
- package/dist/heading/index.js +0 -99
- package/dist/highlight/index.d.ts +0 -13
- package/dist/highlight/index.js +0 -59
- package/dist/hooks/use-current-route-data.d.ts +0 -7
- package/dist/hooks/use-current-route-data.js +0 -16
- package/dist/hooks/use-focus-search.js +0 -19
- package/dist/hooks/use-matches-data.d.ts +0 -9
- package/dist/hooks/use-matches-data.js +0 -15
- package/dist/hooks/use-media-query.d.ts +0 -8
- package/dist/hooks/use-media-query.js +0 -20
- package/dist/hooks/use-mobile.d.ts +0 -3
- package/dist/hooks/use-mobile.js +0 -19
- package/dist/hooks/use-nonce.d.ts +0 -7
- package/dist/hooks/use-nonce.js +0 -8
- package/dist/hooks/use-orientation.d.ts +0 -11
- package/dist/hooks/use-orientation.js +0 -29
- package/dist/hooks/use-user.d.ts +0 -50
- package/dist/hooks/use-user.js +0 -25
- package/dist/icon-button/index.d.ts +0 -9
- package/dist/icon-button/index.js +0 -17
- package/dist/if/index.d.ts +0 -10
- package/dist/if/index.js +0 -24
- package/dist/iframe/index.d.ts +0 -10
- package/dist/iframe/index.js +0 -17
- package/dist/link/index.d.ts +0 -55
- package/dist/link/index.js +0 -195
- package/dist/list/index.d.ts +0 -69
- package/dist/list/index.js +0 -65
- package/dist/markdown-container/index.d.ts +0 -22
- package/dist/markdown-container/index.js +0 -128
- package/dist/password-input/index.d.ts +0 -11
- package/dist/password-input/index.js +0 -46
- package/dist/picture/index.d.ts +0 -38
- package/dist/picture/index.js +0 -68
- package/dist/protected-email/index.d.ts +0 -20
- package/dist/protected-email/index.js +0 -30
- package/dist/text/index.d.ts +0 -20
- package/dist/text/index.js +0 -38
- package/dist/utils/author/index.d.ts +0 -3
- package/dist/utils/author/index.js +0 -33
- package/dist/utils/text/index.js +0 -73
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Button as BaseUIButton } from '@base-ui/react/button';
|
|
2
|
+
import { tv } from '@regardio/tailwind/utils';
|
|
3
|
+
import type { ComponentProps } from 'react';
|
|
4
|
+
|
|
5
|
+
const buttonVariants = {
|
|
6
|
+
destructive: [
|
|
7
|
+
'bg-red-600',
|
|
8
|
+
'text-white',
|
|
9
|
+
'border-red-600',
|
|
10
|
+
'hover:bg-red-700',
|
|
11
|
+
'hover:border-red-700',
|
|
12
|
+
'focus-visible:ring-2',
|
|
13
|
+
'focus-visible:ring-red-500',
|
|
14
|
+
'focus-visible:ring-offset-2',
|
|
15
|
+
],
|
|
16
|
+
ghost: [
|
|
17
|
+
'bg-transparent',
|
|
18
|
+
'text-gray-900',
|
|
19
|
+
'border-transparent',
|
|
20
|
+
'hover:bg-gray-100',
|
|
21
|
+
'hover:border-transparent',
|
|
22
|
+
'focus-visible:ring-2',
|
|
23
|
+
'focus-visible:ring-gray-500',
|
|
24
|
+
'focus-visible:ring-offset-2',
|
|
25
|
+
],
|
|
26
|
+
outline: [
|
|
27
|
+
'bg-transparent',
|
|
28
|
+
'text-gray-900',
|
|
29
|
+
'border-gray-300',
|
|
30
|
+
'hover:bg-gray-50',
|
|
31
|
+
'hover:border-gray-400',
|
|
32
|
+
'focus-visible:ring-2',
|
|
33
|
+
'focus-visible:ring-gray-500',
|
|
34
|
+
'focus-visible:ring-offset-2',
|
|
35
|
+
],
|
|
36
|
+
primary: [
|
|
37
|
+
'bg-blue-600',
|
|
38
|
+
'text-white',
|
|
39
|
+
'border-blue-600',
|
|
40
|
+
'hover:bg-blue-700',
|
|
41
|
+
'hover:border-blue-700',
|
|
42
|
+
'focus-visible:ring-2',
|
|
43
|
+
'focus-visible:ring-blue-500',
|
|
44
|
+
'focus-visible:ring-offset-2',
|
|
45
|
+
],
|
|
46
|
+
secondary: [
|
|
47
|
+
'bg-gray-100',
|
|
48
|
+
'text-gray-900',
|
|
49
|
+
'border-gray-300',
|
|
50
|
+
'hover:bg-gray-200',
|
|
51
|
+
'hover:border-gray-400',
|
|
52
|
+
'focus-visible:ring-2',
|
|
53
|
+
'focus-visible:ring-gray-500',
|
|
54
|
+
'focus-visible:ring-offset-2',
|
|
55
|
+
],
|
|
56
|
+
} as const;
|
|
57
|
+
|
|
58
|
+
const buttonSizes = {
|
|
59
|
+
'2xl': ['px-10', 'py-5', 'text-2xl', 'font-medium', 'rounded-lg'],
|
|
60
|
+
lg: ['px-6', 'py-3', 'text-lg', 'font-medium', 'rounded-lg'],
|
|
61
|
+
md: ['px-4', 'py-2', 'text-base', 'font-medium', 'rounded-md'],
|
|
62
|
+
sm: ['px-3', 'py-1.5', 'text-sm', 'font-medium', 'rounded-md'],
|
|
63
|
+
xl: ['px-8', 'py-4', 'text-xl', 'font-medium', 'rounded-lg'],
|
|
64
|
+
} as const;
|
|
65
|
+
|
|
66
|
+
const button = tv({
|
|
67
|
+
base: [
|
|
68
|
+
'inline-flex',
|
|
69
|
+
'items-center',
|
|
70
|
+
'justify-center',
|
|
71
|
+
'border',
|
|
72
|
+
'transition-colors',
|
|
73
|
+
'duration-200',
|
|
74
|
+
'ease-in-out',
|
|
75
|
+
'disabled:opacity-50',
|
|
76
|
+
'disabled:cursor-not-allowed',
|
|
77
|
+
'disabled:pointer-events-none',
|
|
78
|
+
],
|
|
79
|
+
defaultVariants: {
|
|
80
|
+
size: 'md',
|
|
81
|
+
variant: 'primary',
|
|
82
|
+
},
|
|
83
|
+
variants: {
|
|
84
|
+
size: buttonSizes,
|
|
85
|
+
variant: buttonVariants,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export type ButtonVariant = keyof typeof buttonVariants;
|
|
90
|
+
export type ButtonSize = keyof typeof buttonSizes;
|
|
91
|
+
|
|
92
|
+
export interface ButtonProps extends Omit<ComponentProps<typeof BaseUIButton>, 'className'> {
|
|
93
|
+
variant?: ButtonVariant;
|
|
94
|
+
size?: ButtonSize;
|
|
95
|
+
className?: string;
|
|
96
|
+
type?: 'button' | 'submit' | 'reset';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const Button = ({
|
|
100
|
+
children,
|
|
101
|
+
className,
|
|
102
|
+
variant,
|
|
103
|
+
size,
|
|
104
|
+
...props
|
|
105
|
+
}: ButtonProps): React.JSX.Element => {
|
|
106
|
+
return (
|
|
107
|
+
<BaseUIButton
|
|
108
|
+
className={button({
|
|
109
|
+
className,
|
|
110
|
+
size,
|
|
111
|
+
variant,
|
|
112
|
+
})}
|
|
113
|
+
{...props}
|
|
114
|
+
>
|
|
115
|
+
{children}
|
|
116
|
+
</BaseUIButton>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export interface CarouselContentProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
5
|
+
}
|
|
4
6
|
|
|
5
|
-
export const CarouselContent =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
export const CarouselContent = function CarouselContent({
|
|
8
|
+
className,
|
|
9
|
+
ref,
|
|
10
|
+
...props
|
|
11
|
+
}: CarouselContentProps): React.JSX.Element {
|
|
12
|
+
return (
|
|
13
|
+
<div
|
|
14
|
+
className={className}
|
|
15
|
+
ref={ref}
|
|
16
|
+
{...props}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { forwardRef, type HTMLAttributes } from 'react';
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
4
2
|
|
|
5
3
|
export interface CarouselItemProps extends HTMLAttributes<HTMLDivElement> {
|
|
6
4
|
'aria-label'?: string;
|
|
5
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
export const CarouselItem =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
export const CarouselItem = function CarouselItem({
|
|
9
|
+
className,
|
|
10
|
+
ref,
|
|
11
|
+
...props
|
|
12
|
+
}: CarouselItemProps): React.JSX.Element {
|
|
13
|
+
return (
|
|
14
|
+
// biome-ignore lint/a11y/useSemanticElements: False positive
|
|
15
|
+
<div
|
|
16
|
+
aria-roledescription="slide"
|
|
17
|
+
className={className}
|
|
18
|
+
ref={ref}
|
|
19
|
+
role="group"
|
|
20
|
+
{...props}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { HTMLAttributes } from 'react';
|
|
4
|
+
import { Button } from '../button';
|
|
4
5
|
import { useCarousel } from './carousel-root';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export interface CarouselNextProps extends HTMLAttributes<HTMLButtonElement> {
|
|
8
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
9
|
+
}
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
export const CarouselNext = function CarouselNext({
|
|
12
|
+
className,
|
|
13
|
+
ref,
|
|
14
|
+
...props
|
|
15
|
+
}: CarouselNextProps): React.JSX.Element {
|
|
16
|
+
const { canScrollNext, scrollNext } = useCarousel();
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Button
|
|
20
|
+
className={className}
|
|
21
|
+
disabled={!canScrollNext}
|
|
22
|
+
onClick={scrollNext}
|
|
23
|
+
ref={ref}
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import type { HTMLAttributes } from 'react';
|
|
4
|
+
import { Button } from '../button';
|
|
4
5
|
import { useCarousel } from './carousel-root';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export interface CarouselPreviousProps extends HTMLAttributes<HTMLButtonElement> {
|
|
8
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
9
|
+
}
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
export const CarouselPrevious = function CarouselPrevious({
|
|
12
|
+
className,
|
|
13
|
+
ref,
|
|
14
|
+
...props
|
|
15
|
+
}: CarouselPreviousProps): React.JSX.Element {
|
|
16
|
+
const { canScrollPrev, scrollPrev } = useCarousel();
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Button
|
|
20
|
+
className={className}
|
|
21
|
+
disabled={!canScrollPrev}
|
|
22
|
+
onClick={scrollPrev}
|
|
23
|
+
ref={ref}
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -4,7 +4,6 @@ import type { EmblaCarouselType, EmblaOptionsType } from 'embla-carousel';
|
|
|
4
4
|
import useEmblaCarousel from 'embla-carousel-react';
|
|
5
5
|
import {
|
|
6
6
|
createContext,
|
|
7
|
-
forwardRef,
|
|
8
7
|
type HTMLAttributes,
|
|
9
8
|
type KeyboardEvent,
|
|
10
9
|
useCallback,
|
|
@@ -25,7 +24,7 @@ interface CarouselContextValue {
|
|
|
25
24
|
|
|
26
25
|
const CarouselContext = createContext<CarouselContextValue | null>(null);
|
|
27
26
|
|
|
28
|
-
export function useCarousel() {
|
|
27
|
+
export function useCarousel(): CarouselContextValue {
|
|
29
28
|
const context = useContext(CarouselContext);
|
|
30
29
|
if (!context) {
|
|
31
30
|
throw new Error('useCarousel must be used within a <Carousel.Root />');
|
|
@@ -37,91 +36,97 @@ export interface CarouselRootProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
37
36
|
opts?: EmblaOptionsType;
|
|
38
37
|
setApi?: (api: CarouselApi) => void;
|
|
39
38
|
orientation?: 'horizontal' | 'vertical';
|
|
39
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export const CarouselRoot =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
export const CarouselRoot = function CarouselRoot({
|
|
43
|
+
children,
|
|
44
|
+
className,
|
|
45
|
+
opts,
|
|
46
|
+
orientation = 'horizontal',
|
|
47
|
+
setApi,
|
|
48
|
+
ref,
|
|
49
|
+
...props
|
|
50
|
+
}: CarouselRootProps): React.JSX.Element {
|
|
51
|
+
const [emblaRef, emblaApi] = useEmblaCarousel({
|
|
52
|
+
...opts,
|
|
53
|
+
axis: orientation === 'horizontal' ? 'x' : 'y',
|
|
54
|
+
});
|
|
55
|
+
const [canScrollPrev, setCanScrollPrev] = useState(false);
|
|
56
|
+
const [canScrollNext, setCanScrollNext] = useState(false);
|
|
57
|
+
|
|
58
|
+
const onSelect = useCallback((api: CarouselApi) => {
|
|
59
|
+
if (!api) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
setCanScrollPrev(api.canScrollPrev());
|
|
63
|
+
setCanScrollNext(api.canScrollNext());
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
const scrollPrev = useCallback(() => {
|
|
67
|
+
emblaApi?.scrollPrev();
|
|
68
|
+
}, [emblaApi]);
|
|
69
|
+
|
|
70
|
+
const scrollNext = useCallback(() => {
|
|
71
|
+
emblaApi?.scrollNext();
|
|
72
|
+
}, [emblaApi]);
|
|
73
|
+
|
|
74
|
+
const handleKeyDown = useCallback(
|
|
75
|
+
(event: KeyboardEvent<HTMLDivElement>) => {
|
|
76
|
+
if (event.key === 'ArrowLeft') {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
scrollPrev();
|
|
79
|
+
} else if (event.key === 'ArrowRight') {
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
scrollNext();
|
|
54
82
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
emblaApi?.off('select', onSelect);
|
|
98
|
-
};
|
|
99
|
-
}, [emblaApi, onSelect]);
|
|
100
|
-
|
|
101
|
-
return (
|
|
102
|
-
<CarouselContext.Provider
|
|
103
|
-
value={{
|
|
104
|
-
api: emblaApi,
|
|
105
|
-
canScrollNext,
|
|
106
|
-
canScrollPrev,
|
|
107
|
-
scrollNext,
|
|
108
|
-
scrollPrev,
|
|
109
|
-
}}
|
|
83
|
+
},
|
|
84
|
+
[scrollPrev, scrollNext],
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (!emblaApi || !setApi) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
setApi(emblaApi);
|
|
92
|
+
}, [emblaApi, setApi]);
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!emblaApi) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
onSelect(emblaApi);
|
|
100
|
+
emblaApi.on('reInit', onSelect);
|
|
101
|
+
emblaApi.on('select', onSelect);
|
|
102
|
+
|
|
103
|
+
return () => {
|
|
104
|
+
emblaApi?.off('select', onSelect);
|
|
105
|
+
};
|
|
106
|
+
}, [emblaApi, onSelect]);
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<CarouselContext.Provider
|
|
110
|
+
value={{
|
|
111
|
+
api: emblaApi,
|
|
112
|
+
canScrollNext,
|
|
113
|
+
canScrollPrev,
|
|
114
|
+
scrollNext,
|
|
115
|
+
scrollPrev,
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
<section
|
|
119
|
+
aria-label="Carousel"
|
|
120
|
+
aria-roledescription="carousel"
|
|
121
|
+
className={className}
|
|
122
|
+
onKeyDownCapture={handleKeyDown}
|
|
123
|
+
ref={ref}
|
|
124
|
+
{...props}
|
|
110
125
|
>
|
|
111
|
-
<
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
>
|
|
119
|
-
<div ref={emblaRef}>
|
|
120
|
-
<div>{children}</div>
|
|
121
|
-
</div>
|
|
122
|
-
</section>
|
|
123
|
-
</CarouselContext.Provider>
|
|
124
|
-
);
|
|
125
|
-
},
|
|
126
|
-
);
|
|
127
|
-
CarouselRoot.displayName = 'CarouselRoot';
|
|
126
|
+
<div ref={emblaRef}>
|
|
127
|
+
<div>{children}</div>
|
|
128
|
+
</div>
|
|
129
|
+
</section>
|
|
130
|
+
</CarouselContext.Provider>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Field } from '../field';
|
|
4
|
+
import { Checkbox } from './checkbox';
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof Checkbox.Root> = {
|
|
7
|
+
argTypes: {
|
|
8
|
+
disabled: {
|
|
9
|
+
control: 'boolean',
|
|
10
|
+
description: 'Disable the checkbox',
|
|
11
|
+
},
|
|
12
|
+
size: {
|
|
13
|
+
control: 'select',
|
|
14
|
+
description: 'Checkbox size',
|
|
15
|
+
options: ['sm', 'md', 'lg'],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
component: Checkbox.Root,
|
|
19
|
+
parameters: {
|
|
20
|
+
layout: 'centered',
|
|
21
|
+
},
|
|
22
|
+
tags: ['autodocs'],
|
|
23
|
+
title: 'Components/Checkbox',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default meta;
|
|
27
|
+
type Story = StoryObj<typeof meta>;
|
|
28
|
+
|
|
29
|
+
export const Default: Story = {
|
|
30
|
+
render: () => (
|
|
31
|
+
<Checkbox.Root>
|
|
32
|
+
<Checkbox.Indicator />
|
|
33
|
+
</Checkbox.Root>
|
|
34
|
+
),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const Checked: Story = {
|
|
38
|
+
render: () => (
|
|
39
|
+
<Checkbox.Root defaultChecked>
|
|
40
|
+
<Checkbox.Indicator />
|
|
41
|
+
</Checkbox.Root>
|
|
42
|
+
),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const Small: Story = {
|
|
46
|
+
render: () => (
|
|
47
|
+
<Checkbox.Root size="sm">
|
|
48
|
+
<Checkbox.Indicator />
|
|
49
|
+
</Checkbox.Root>
|
|
50
|
+
),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const Large: Story = {
|
|
54
|
+
render: () => (
|
|
55
|
+
<Checkbox.Root size="lg">
|
|
56
|
+
<Checkbox.Indicator />
|
|
57
|
+
</Checkbox.Root>
|
|
58
|
+
),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const Disabled: Story = {
|
|
62
|
+
render: () => (
|
|
63
|
+
<Checkbox.Root disabled>
|
|
64
|
+
<Checkbox.Indicator />
|
|
65
|
+
</Checkbox.Root>
|
|
66
|
+
),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const WithLabel: Story = {
|
|
70
|
+
render: () => (
|
|
71
|
+
<Field.Root>
|
|
72
|
+
<Field.Label>
|
|
73
|
+
<Checkbox.Root>
|
|
74
|
+
<Checkbox.Indicator />
|
|
75
|
+
</Checkbox.Root>
|
|
76
|
+
Accept terms and conditions
|
|
77
|
+
</Field.Label>
|
|
78
|
+
</Field.Root>
|
|
79
|
+
),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const Controlled: Story = {
|
|
83
|
+
render: () => {
|
|
84
|
+
const [checked, setChecked] = useState(false);
|
|
85
|
+
return (
|
|
86
|
+
<div className="space-y-4">
|
|
87
|
+
<Field.Root>
|
|
88
|
+
<Field.Label>
|
|
89
|
+
<Checkbox.Root
|
|
90
|
+
checked={checked}
|
|
91
|
+
onCheckedChange={setChecked}
|
|
92
|
+
>
|
|
93
|
+
<Checkbox.Indicator />
|
|
94
|
+
</Checkbox.Root>
|
|
95
|
+
Subscribe to newsletter
|
|
96
|
+
</Field.Label>
|
|
97
|
+
</Field.Root>
|
|
98
|
+
<p className="text-sm text-gray-600">Status: {checked ? 'Subscribed' : 'Not subscribed'}</p>
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const AllSizes: Story = {
|
|
105
|
+
render: () => (
|
|
106
|
+
<div className="flex items-center gap-4">
|
|
107
|
+
<Checkbox.Root size="sm">
|
|
108
|
+
<Checkbox.Indicator />
|
|
109
|
+
</Checkbox.Root>
|
|
110
|
+
<Checkbox.Root size="md">
|
|
111
|
+
<Checkbox.Indicator />
|
|
112
|
+
</Checkbox.Root>
|
|
113
|
+
<Checkbox.Root size="lg">
|
|
114
|
+
<Checkbox.Indicator />
|
|
115
|
+
</Checkbox.Root>
|
|
116
|
+
</div>
|
|
117
|
+
),
|
|
118
|
+
};
|