@thangnqdev/ui 0.2.0 → 0.2.2
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/LICENSE +21 -21
- package/README.md +144 -142
- package/bin/cli.js +125 -0
- package/dist/bento/index.cjs.map +1 -1
- package/dist/bento/index.js +2 -2
- package/dist/buttons/index.cjs.map +1 -1
- package/dist/buttons/index.js +3 -3
- package/dist/{chunk-77KTYOMQ.js → chunk-2OXZK6IP.js} +3 -3
- package/dist/chunk-2OXZK6IP.js.map +1 -0
- package/dist/{chunk-4CRFNALF.js → chunk-4GNFT2ZJ.js} +7 -7
- package/dist/chunk-4GNFT2ZJ.js.map +1 -0
- package/dist/{chunk-2YJBW4E2.js → chunk-4S6L5V7X.js} +2 -2
- package/dist/chunk-4S6L5V7X.js.map +1 -0
- package/dist/{chunk-I2FQBMVW.js → chunk-66VWUJEI.js} +3 -3
- package/dist/chunk-66VWUJEI.js.map +1 -0
- package/dist/{chunk-YOCGBORV.js → chunk-7NMB2Y64.js} +4 -4
- package/dist/chunk-7NMB2Y64.js.map +1 -0
- package/dist/{chunk-V52JOSDF.js → chunk-A7P3O5Z5.js} +3 -3
- package/dist/chunk-A7P3O5Z5.js.map +1 -0
- package/dist/{chunk-ME4XILG5.js → chunk-ATYGDTMK.js} +5 -5
- package/dist/chunk-ATYGDTMK.js.map +1 -0
- package/dist/{chunk-S6XJMYME.js → chunk-C4SUXMI3.js} +3 -3
- package/dist/chunk-C4SUXMI3.js.map +1 -0
- package/dist/{chunk-EXFR2BFJ.js → chunk-DUPPPGXY.js} +7 -7
- package/dist/chunk-DUPPPGXY.js.map +1 -0
- package/dist/{chunk-I5O2WCGF.js → chunk-EU2LPUYP.js} +3 -3
- package/dist/chunk-EU2LPUYP.js.map +1 -0
- package/dist/{chunk-D7FB3TCA.js → chunk-GXI2H5XA.js} +3 -3
- package/dist/chunk-GXI2H5XA.js.map +1 -0
- package/dist/{chunk-ADO3SVUA.js → chunk-IABPUCAQ.js} +2 -2
- package/dist/chunk-IABPUCAQ.js.map +1 -0
- package/dist/{chunk-PC5SZFZC.js → chunk-JOKEKOP3.js} +8 -8
- package/dist/chunk-JOKEKOP3.js.map +1 -0
- package/dist/{chunk-GXWB6BSY.js → chunk-KUQWUTZA.js} +4 -4
- package/dist/chunk-KUQWUTZA.js.map +1 -0
- package/dist/{chunk-ZEDXARXW.js → chunk-U3J4UPV3.js} +2 -2
- package/dist/chunk-U3J4UPV3.js.map +1 -0
- package/dist/{chunk-DSEL7ELZ.js → chunk-VE2PNSDQ.js} +4 -4
- package/dist/chunk-VE2PNSDQ.js.map +1 -0
- package/dist/{chunk-YJ64RI7J.js → chunk-WAFHC4DQ.js} +3 -3
- package/dist/chunk-WAFHC4DQ.js.map +1 -0
- package/dist/{chunk-W5WNWTQC.js → chunk-YJ67WYVW.js} +5 -5
- package/dist/chunk-YJ67WYVW.js.map +1 -0
- package/dist/{chunk-4MS6ZHFQ.js → chunk-Z427NPMU.js} +7 -7
- package/dist/chunk-Z427NPMU.js.map +1 -0
- package/dist/core/index.cjs +4 -4
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +2 -2
- package/dist/data-display/index.cjs.map +1 -1
- package/dist/data-display/index.js +5 -5
- package/dist/feedback/index.cjs.map +1 -1
- package/dist/feedback/index.js +2 -2
- package/dist/forms/index.cjs.map +1 -1
- package/dist/forms/index.js +8 -8
- package/dist/glass/index.cjs.map +1 -1
- package/dist/glass/index.js +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -19
- package/dist/layout/index.cjs.map +1 -1
- package/dist/layout/index.js +2 -2
- package/dist/navigation/index.cjs.map +1 -1
- package/dist/navigation/index.js +6 -6
- package/dist/overlays/index.cjs.map +1 -1
- package/dist/overlays/index.js +7 -7
- package/dist/reset.css +45 -45
- package/dist/tokens.css +11 -11
- package/dist/typography/index.cjs.map +1 -1
- package/dist/typography/index.js +4 -4
- package/llms.txt +3 -3
- package/package.json +166 -159
- package/scripts/postinstall.js +125 -0
- package/src/bento/BentoCard.tsx +140 -140
- package/src/bento/BentoGrid.tsx +50 -50
- package/src/bento/index.ts +2 -2
- package/src/bento/tokens.css +46 -46
- package/src/buttons/Button.tsx +104 -104
- package/src/buttons/ButtonGroup.tsx +43 -43
- package/src/buttons/IconButton.tsx +79 -79
- package/src/buttons/SplitButton.tsx +186 -186
- package/src/buttons/ToggleButton.tsx +157 -157
- package/src/buttons/index.ts +5 -5
- package/src/buttons/tokens.css +6 -6
- package/src/core/ThemeProvider.tsx +133 -133
- package/src/core/index.ts +2 -2
- package/src/core/tokens.css +134 -134
- package/src/data-display/Accordion.tsx +147 -147
- package/src/data-display/Avatar.tsx +134 -134
- package/src/data-display/Card.tsx +112 -112
- package/src/data-display/Chip.tsx +74 -74
- package/src/data-display/DataTablePro.tsx +534 -534
- package/src/data-display/StatCard.tsx +60 -60
- package/src/data-display/Table.tsx +74 -74
- package/src/data-display/Timeline.tsx +62 -62
- package/src/data-display/TreeView.tsx +279 -279
- package/src/data-display/tokens.css +4 -4
- package/src/feedback/Alert.tsx +80 -80
- package/src/feedback/EmptyState.tsx +45 -45
- package/src/feedback/Skeleton.tsx +66 -66
- package/src/feedback/Spinner.tsx +65 -65
- package/src/feedback/index.ts +5 -5
- package/src/feedback/tokens.css +4 -4
- package/src/forms/Checkbox.tsx +149 -149
- package/src/forms/CheckboxGroup.tsx +76 -76
- package/src/forms/Combobox.tsx +512 -512
- package/src/forms/DatePicker.tsx +784 -784
- package/src/forms/FileUpload.tsx +266 -266
- package/src/forms/FormField.tsx +115 -115
- package/src/forms/Input.tsx +151 -151
- package/src/forms/NumberInput.tsx +262 -262
- package/src/forms/PasswordInput.tsx +35 -35
- package/src/forms/PinInput.tsx +139 -139
- package/src/forms/Radio.tsx +142 -142
- package/src/forms/RangeSlider.tsx +237 -237
- package/src/forms/SearchInput.tsx +34 -34
- package/src/forms/Select.tsx +103 -103
- package/src/forms/Slider.tsx +85 -85
- package/src/forms/Textarea.tsx +114 -114
- package/src/forms/tokens.css +6 -6
- package/src/glass/GlassButton.tsx +59 -59
- package/src/glass/GlassCard.tsx +71 -71
- package/src/glass/index.ts +3 -3
- package/src/glass/tokens.css +81 -81
- package/src/index.ts +26 -26
- package/src/layout/AspectRatio.tsx +39 -39
- package/src/layout/Container.tsx +53 -53
- package/src/layout/Divider.tsx +61 -61
- package/src/layout/Flex.tsx +79 -79
- package/src/layout/Grid.tsx +124 -124
- package/src/layout/PageLayout.tsx +59 -59
- package/src/layout/Section.tsx +47 -47
- package/src/layout/Spacer.tsx +30 -30
- package/src/layout/Stack.tsx +88 -88
- package/src/layout/tokens.css +8 -8
- package/src/navigation/Breadcrumb.tsx +73 -73
- package/src/navigation/CommandPalette.tsx +142 -142
- package/src/navigation/DropdownMenu.tsx +244 -244
- package/src/navigation/Pagination.tsx +114 -114
- package/src/navigation/Stepper.tsx +93 -93
- package/src/navigation/Tabs.tsx +265 -265
- package/src/navigation/index.ts +6 -6
- package/src/navigation/tokens.css +4 -4
- package/src/overlays/AlertDialog.tsx +63 -63
- package/src/overlays/BottomSheet.tsx +143 -143
- package/src/overlays/ContextMenu.tsx +161 -161
- package/src/overlays/Drawer.tsx +160 -160
- package/src/overlays/FocusTrap.tsx +122 -122
- package/src/overlays/Modal.tsx +296 -296
- package/src/overlays/Popover.tsx +156 -156
- package/src/overlays/Portal.tsx +23 -23
- package/src/overlays/Toast.tsx +175 -175
- package/src/overlays/Tooltip.tsx +125 -125
- package/src/overlays/tokens.css +8 -8
- package/src/registry/components.ts +1368 -1368
- package/src/styles/components.css +39 -39
- package/src/styles/index.css +5 -5
- package/src/styles/reset.css +45 -45
- package/src/styles/tokens.css +11 -11
- package/src/typography/Blockquote.tsx +32 -32
- package/src/typography/Code.tsx +89 -89
- package/src/typography/Heading.tsx +56 -56
- package/src/typography/Kbd.tsx +25 -25
- package/src/typography/Label.tsx +47 -47
- package/src/typography/Link.tsx +56 -56
- package/src/typography/Text.tsx +62 -62
- package/src/typography/index.ts +7 -7
- package/src/typography/tokens.css +5 -5
- package/src/utils/cn.ts +6 -6
- package/src/utils/scroll-lock.ts +19 -19
- package/src/utils/useControllableState.ts +54 -54
- package/ui-contract.json +1 -1
- package/dist/chunk-2YJBW4E2.js.map +0 -1
- package/dist/chunk-4CRFNALF.js.map +0 -1
- package/dist/chunk-4MS6ZHFQ.js.map +0 -1
- package/dist/chunk-77KTYOMQ.js.map +0 -1
- package/dist/chunk-ADO3SVUA.js.map +0 -1
- package/dist/chunk-D7FB3TCA.js.map +0 -1
- package/dist/chunk-DSEL7ELZ.js.map +0 -1
- package/dist/chunk-EXFR2BFJ.js.map +0 -1
- package/dist/chunk-GXWB6BSY.js.map +0 -1
- package/dist/chunk-I2FQBMVW.js.map +0 -1
- package/dist/chunk-I5O2WCGF.js.map +0 -1
- package/dist/chunk-ME4XILG5.js.map +0 -1
- package/dist/chunk-PC5SZFZC.js.map +0 -1
- package/dist/chunk-S6XJMYME.js.map +0 -1
- package/dist/chunk-V52JOSDF.js.map +0 -1
- package/dist/chunk-W5WNWTQC.js.map +0 -1
- package/dist/chunk-YJ64RI7J.js.map +0 -1
- package/dist/chunk-YOCGBORV.js.map +0 -1
- package/dist/chunk-ZEDXARXW.js.map +0 -1
package/src/forms/FormField.tsx
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import React, { createContext, useContext, useId, forwardRef } from 'react';
|
|
2
|
-
import { cn } from '../utils/cn';
|
|
3
|
-
import { Label, LabelProps } from '../typography/Label';
|
|
4
|
-
|
|
5
|
-
interface FormFieldContextValue {
|
|
6
|
-
id: string;
|
|
7
|
-
labelId: string;
|
|
8
|
-
descriptionId: string;
|
|
9
|
-
errorId: string;
|
|
10
|
-
isRequired?: boolean;
|
|
11
|
-
isInvalid?: boolean;
|
|
12
|
-
isDisabled?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const FormFieldContext = createContext<FormFieldContextValue | null>(null);
|
|
16
|
-
|
|
17
|
-
export function useFormField() {
|
|
18
|
-
const context = useContext(FormFieldContext);
|
|
19
|
-
return context;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface FormFieldProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
23
|
-
isRequired?: boolean;
|
|
24
|
-
isInvalid?: boolean;
|
|
25
|
-
isDisabled?: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const FormField = forwardRef<HTMLDivElement, FormFieldProps>(
|
|
29
|
-
({ className, isRequired, isInvalid, isDisabled, children, ...props }, ref) => {
|
|
30
|
-
const generatedId = useId();
|
|
31
|
-
const id = props.id || generatedId;
|
|
32
|
-
const labelId = `${id}-label`;
|
|
33
|
-
const descriptionId = `${id}-description`;
|
|
34
|
-
const errorId = `${id}-error`;
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<FormFieldContext.Provider
|
|
38
|
-
value={{
|
|
39
|
-
id,
|
|
40
|
-
labelId,
|
|
41
|
-
descriptionId,
|
|
42
|
-
errorId,
|
|
43
|
-
isRequired,
|
|
44
|
-
isInvalid,
|
|
45
|
-
isDisabled,
|
|
46
|
-
}}
|
|
47
|
-
>
|
|
48
|
-
<div ref={ref} className={cn('space-y-1.5 w-full', className)} {...props}>
|
|
49
|
-
{children}
|
|
50
|
-
</div>
|
|
51
|
-
</FormFieldContext.Provider>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
FormField.displayName = 'FormField';
|
|
56
|
-
|
|
57
|
-
export const FormLabel = forwardRef<HTMLLabelElement, LabelProps>(
|
|
58
|
-
({ className, required, children, ...props }, ref) => {
|
|
59
|
-
const context = useFormField();
|
|
60
|
-
const isRequired = required ?? context?.isRequired;
|
|
61
|
-
const isError = context?.isInvalid;
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<Label
|
|
65
|
-
ref={ref}
|
|
66
|
-
id={context?.labelId}
|
|
67
|
-
htmlFor={context?.id}
|
|
68
|
-
required={isRequired}
|
|
69
|
-
error={isError}
|
|
70
|
-
className={className}
|
|
71
|
-
{...props}
|
|
72
|
-
>
|
|
73
|
-
{children}
|
|
74
|
-
</Label>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
FormLabel.displayName = 'FormLabel';
|
|
79
|
-
|
|
80
|
-
export const FormHelperText = forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
|
|
81
|
-
({ className, children, ...props }, ref) => {
|
|
82
|
-
const context = useFormField();
|
|
83
|
-
return (
|
|
84
|
-
<p
|
|
85
|
-
ref={ref}
|
|
86
|
-
id={context?.descriptionId}
|
|
87
|
-
className={cn('text-xs text-[var(--ui-text-muted)]', className)}
|
|
88
|
-
{...props}
|
|
89
|
-
>
|
|
90
|
-
{children}
|
|
91
|
-
</p>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
FormHelperText.displayName = 'FormHelperText';
|
|
96
|
-
|
|
97
|
-
export const FormErrorMessage = forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
|
|
98
|
-
({ className, children, ...props }, ref) => {
|
|
99
|
-
const context = useFormField();
|
|
100
|
-
if (!context?.isInvalid && !children) return null;
|
|
101
|
-
|
|
102
|
-
return (
|
|
103
|
-
<p
|
|
104
|
-
ref={ref}
|
|
105
|
-
id={context?.errorId}
|
|
106
|
-
role="alert"
|
|
107
|
-
className={cn('text-xs font-medium text-[var(--ui-error)]', className)}
|
|
108
|
-
{...props}
|
|
109
|
-
>
|
|
110
|
-
{children}
|
|
111
|
-
</p>
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
FormErrorMessage.displayName = 'FormErrorMessage';
|
|
1
|
+
import React, { createContext, useContext, useId, forwardRef } from 'react';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
import { Label, LabelProps } from '../typography/Label';
|
|
4
|
+
|
|
5
|
+
interface FormFieldContextValue {
|
|
6
|
+
id: string;
|
|
7
|
+
labelId: string;
|
|
8
|
+
descriptionId: string;
|
|
9
|
+
errorId: string;
|
|
10
|
+
isRequired?: boolean;
|
|
11
|
+
isInvalid?: boolean;
|
|
12
|
+
isDisabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const FormFieldContext = createContext<FormFieldContextValue | null>(null);
|
|
16
|
+
|
|
17
|
+
export function useFormField() {
|
|
18
|
+
const context = useContext(FormFieldContext);
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface FormFieldProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
23
|
+
isRequired?: boolean;
|
|
24
|
+
isInvalid?: boolean;
|
|
25
|
+
isDisabled?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const FormField = forwardRef<HTMLDivElement, FormFieldProps>(
|
|
29
|
+
({ className, isRequired, isInvalid, isDisabled, children, ...props }, ref) => {
|
|
30
|
+
const generatedId = useId();
|
|
31
|
+
const id = props.id || generatedId;
|
|
32
|
+
const labelId = `${id}-label`;
|
|
33
|
+
const descriptionId = `${id}-description`;
|
|
34
|
+
const errorId = `${id}-error`;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<FormFieldContext.Provider
|
|
38
|
+
value={{
|
|
39
|
+
id,
|
|
40
|
+
labelId,
|
|
41
|
+
descriptionId,
|
|
42
|
+
errorId,
|
|
43
|
+
isRequired,
|
|
44
|
+
isInvalid,
|
|
45
|
+
isDisabled,
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
<div ref={ref} className={cn('space-y-1.5 w-full', className)} {...props}>
|
|
49
|
+
{children}
|
|
50
|
+
</div>
|
|
51
|
+
</FormFieldContext.Provider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
FormField.displayName = 'FormField';
|
|
56
|
+
|
|
57
|
+
export const FormLabel = forwardRef<HTMLLabelElement, LabelProps>(
|
|
58
|
+
({ className, required, children, ...props }, ref) => {
|
|
59
|
+
const context = useFormField();
|
|
60
|
+
const isRequired = required ?? context?.isRequired;
|
|
61
|
+
const isError = context?.isInvalid;
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Label
|
|
65
|
+
ref={ref}
|
|
66
|
+
id={context?.labelId}
|
|
67
|
+
htmlFor={context?.id}
|
|
68
|
+
required={isRequired}
|
|
69
|
+
error={isError}
|
|
70
|
+
className={className}
|
|
71
|
+
{...props}
|
|
72
|
+
>
|
|
73
|
+
{children}
|
|
74
|
+
</Label>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
FormLabel.displayName = 'FormLabel';
|
|
79
|
+
|
|
80
|
+
export const FormHelperText = forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
|
|
81
|
+
({ className, children, ...props }, ref) => {
|
|
82
|
+
const context = useFormField();
|
|
83
|
+
return (
|
|
84
|
+
<p
|
|
85
|
+
ref={ref}
|
|
86
|
+
id={context?.descriptionId}
|
|
87
|
+
className={cn('text-xs text-[var(--ui-text-muted)]', className)}
|
|
88
|
+
{...props}
|
|
89
|
+
>
|
|
90
|
+
{children}
|
|
91
|
+
</p>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
FormHelperText.displayName = 'FormHelperText';
|
|
96
|
+
|
|
97
|
+
export const FormErrorMessage = forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
|
|
98
|
+
({ className, children, ...props }, ref) => {
|
|
99
|
+
const context = useFormField();
|
|
100
|
+
if (!context?.isInvalid && !children) return null;
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<p
|
|
104
|
+
ref={ref}
|
|
105
|
+
id={context?.errorId}
|
|
106
|
+
role="alert"
|
|
107
|
+
className={cn('text-xs font-medium text-[var(--ui-error)]', className)}
|
|
108
|
+
{...props}
|
|
109
|
+
>
|
|
110
|
+
{children}
|
|
111
|
+
</p>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
FormErrorMessage.displayName = 'FormErrorMessage';
|
package/src/forms/Input.tsx
CHANGED
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
import React, { forwardRef, useState } from 'react';
|
|
2
|
-
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
-
import { X } from 'lucide-react';
|
|
4
|
-
import { useFormField } from './FormField';
|
|
5
|
-
import { cn } from '../utils/cn';
|
|
6
|
-
|
|
7
|
-
export const inputVariants = cva(
|
|
8
|
-
'w-full rounded-[var(--ui-radius-md)] border bg-[var(--ui-bg-surface)]/70 backdrop-blur-md text-[var(--ui-text-primary)] placeholder:text-[var(--ui-text-muted)] transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ui-primary)]/70 focus-visible:border-[var(--ui-primary)] focus-visible:shadow-[0_0_16px_rgba(99,102,241,0.2)] disabled:cursor-not-allowed disabled:opacity-50 shadow-inner',
|
|
9
|
-
{
|
|
10
|
-
variants: {
|
|
11
|
-
size: {
|
|
12
|
-
sm: 'h-8 px-2.5 text-xs',
|
|
13
|
-
md: 'h-10 px-3.5 text-sm',
|
|
14
|
-
lg: 'h-12 px-4 text-base',
|
|
15
|
-
},
|
|
16
|
-
variant: {
|
|
17
|
-
default: 'border-[var(--ui-border-default)] hover:border-[var(--ui-border-strong)]',
|
|
18
|
-
filled: 'bg-[var(--ui-bg-secondary)] border-transparent hover:bg-[var(--ui-bg-tertiary)]',
|
|
19
|
-
},
|
|
20
|
-
isInvalid: {
|
|
21
|
-
true: 'border-[var(--ui-error)] focus-visible:ring-[var(--ui-error)]/70 focus-visible:shadow-[0_0_16px_rgba(244,63,94,0.25)]',
|
|
22
|
-
false: '',
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
defaultVariants: {
|
|
26
|
-
size: 'md',
|
|
27
|
-
variant: 'default',
|
|
28
|
-
isInvalid: false,
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
export interface InputProps
|
|
34
|
-
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'>,
|
|
35
|
-
VariantProps<typeof inputVariants> {
|
|
36
|
-
prefixIcon?: React.ReactNode;
|
|
37
|
-
suffixIcon?: React.ReactNode;
|
|
38
|
-
clearable?: boolean;
|
|
39
|
-
onClear?: () => void;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
43
|
-
(
|
|
44
|
-
{
|
|
45
|
-
className,
|
|
46
|
-
type = 'text',
|
|
47
|
-
size,
|
|
48
|
-
variant,
|
|
49
|
-
isInvalid: customInvalid,
|
|
50
|
-
prefixIcon,
|
|
51
|
-
suffixIcon,
|
|
52
|
-
clearable,
|
|
53
|
-
onClear,
|
|
54
|
-
value,
|
|
55
|
-
onChange,
|
|
56
|
-
disabled,
|
|
57
|
-
id,
|
|
58
|
-
...props
|
|
59
|
-
},
|
|
60
|
-
ref
|
|
61
|
-
) => {
|
|
62
|
-
const formField = useFormField();
|
|
63
|
-
const isInvalid = customInvalid ?? formField?.isInvalid ?? false;
|
|
64
|
-
const isDisabled = disabled ?? formField?.isDisabled ?? false;
|
|
65
|
-
const inputId = id || formField?.id;
|
|
66
|
-
|
|
67
|
-
const isControlled = value !== undefined;
|
|
68
|
-
const [uncontrolledVal, setUncontrolledVal] = useState(
|
|
69
|
-
props.defaultValue !== undefined ? String(props.defaultValue) : ''
|
|
70
|
-
);
|
|
71
|
-
const innerRef = React.useRef<HTMLInputElement | null>(null);
|
|
72
|
-
|
|
73
|
-
const handleRef = (node: HTMLInputElement | null) => {
|
|
74
|
-
innerRef.current = node;
|
|
75
|
-
if (typeof ref === 'function') {
|
|
76
|
-
ref(node);
|
|
77
|
-
} else if (ref) {
|
|
78
|
-
(ref as React.MutableRefObject<HTMLInputElement | null>).current = node;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
83
|
-
if (!isControlled) {
|
|
84
|
-
setUncontrolledVal(e.target.value);
|
|
85
|
-
}
|
|
86
|
-
onChange?.(e);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const handleClear = () => {
|
|
90
|
-
if (!isControlled && innerRef.current) {
|
|
91
|
-
innerRef.current.value = '';
|
|
92
|
-
setUncontrolledVal('');
|
|
93
|
-
const event = new Event('input', { bubbles: true });
|
|
94
|
-
innerRef.current.dispatchEvent(event);
|
|
95
|
-
}
|
|
96
|
-
onClear?.();
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const hasValue = isControlled
|
|
100
|
-
? Boolean(value)
|
|
101
|
-
: Boolean(uncontrolledVal || innerRef.current?.value);
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<div className="relative w-full flex items-center">
|
|
105
|
-
{prefixIcon && (
|
|
106
|
-
<div className="absolute left-3 flex items-center pointer-events-none text-[var(--ui-text-muted)]">
|
|
107
|
-
{prefixIcon}
|
|
108
|
-
</div>
|
|
109
|
-
)}
|
|
110
|
-
|
|
111
|
-
<input
|
|
112
|
-
ref={handleRef}
|
|
113
|
-
id={inputId}
|
|
114
|
-
type={type}
|
|
115
|
-
disabled={isDisabled}
|
|
116
|
-
{...(isControlled ? { value } : {})}
|
|
117
|
-
onChange={handleChange}
|
|
118
|
-
aria-invalid={isInvalid}
|
|
119
|
-
aria-describedby={
|
|
120
|
-
isInvalid
|
|
121
|
-
? formField?.errorId
|
|
122
|
-
: formField?.descriptionId || undefined
|
|
123
|
-
}
|
|
124
|
-
className={cn(
|
|
125
|
-
inputVariants({ size, variant, isInvalid }),
|
|
126
|
-
prefixIcon && 'pl-9',
|
|
127
|
-
(suffixIcon || (clearable && hasValue)) && 'pr-9',
|
|
128
|
-
className
|
|
129
|
-
)}
|
|
130
|
-
{...props}
|
|
131
|
-
/>
|
|
132
|
-
|
|
133
|
-
<div className="absolute right-3 flex items-center gap-1 text-[var(--ui-text-muted)]">
|
|
134
|
-
{clearable && hasValue && !isDisabled && (
|
|
135
|
-
<button
|
|
136
|
-
type="button"
|
|
137
|
-
onClick={handleClear}
|
|
138
|
-
className="p-0.5 rounded-full hover:bg-[var(--ui-bg-tertiary)] hover:text-[var(--ui-text-primary)] transition-colors"
|
|
139
|
-
aria-label="Clear input"
|
|
140
|
-
>
|
|
141
|
-
<X className="w-3.5 h-3.5" />
|
|
142
|
-
</button>
|
|
143
|
-
)}
|
|
144
|
-
{suffixIcon && <span className="pointer-events-none flex items-center">{suffixIcon}</span>}
|
|
145
|
-
</div>
|
|
146
|
-
</div>
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
Input.displayName = 'Input';
|
|
1
|
+
import React, { forwardRef, useState } from 'react';
|
|
2
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import { X } from 'lucide-react';
|
|
4
|
+
import { useFormField } from './FormField';
|
|
5
|
+
import { cn } from '../utils/cn';
|
|
6
|
+
|
|
7
|
+
export const inputVariants = cva(
|
|
8
|
+
'w-full rounded-[var(--ui-radius-md)] border bg-[var(--ui-bg-surface)]/70 backdrop-blur-md text-[var(--ui-text-primary)] placeholder:text-[var(--ui-text-muted)] transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ui-primary)]/70 focus-visible:border-[var(--ui-primary)] focus-visible:shadow-[0_0_16px_rgba(99,102,241,0.2)] disabled:cursor-not-allowed disabled:opacity-50 shadow-inner',
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
size: {
|
|
12
|
+
sm: 'h-8 px-2.5 text-xs',
|
|
13
|
+
md: 'h-10 px-3.5 text-sm',
|
|
14
|
+
lg: 'h-12 px-4 text-base',
|
|
15
|
+
},
|
|
16
|
+
variant: {
|
|
17
|
+
default: 'border-[var(--ui-border-default)] hover:border-[var(--ui-border-strong)]',
|
|
18
|
+
filled: 'bg-[var(--ui-bg-secondary)] border-transparent hover:bg-[var(--ui-bg-tertiary)]',
|
|
19
|
+
},
|
|
20
|
+
isInvalid: {
|
|
21
|
+
true: 'border-[var(--ui-error)] focus-visible:ring-[var(--ui-error)]/70 focus-visible:shadow-[0_0_16px_rgba(244,63,94,0.25)]',
|
|
22
|
+
false: '',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
defaultVariants: {
|
|
26
|
+
size: 'md',
|
|
27
|
+
variant: 'default',
|
|
28
|
+
isInvalid: false,
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export interface InputProps
|
|
34
|
+
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'>,
|
|
35
|
+
VariantProps<typeof inputVariants> {
|
|
36
|
+
prefixIcon?: React.ReactNode;
|
|
37
|
+
suffixIcon?: React.ReactNode;
|
|
38
|
+
clearable?: boolean;
|
|
39
|
+
onClear?: () => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const Input = forwardRef<HTMLInputElement, InputProps>(
|
|
43
|
+
(
|
|
44
|
+
{
|
|
45
|
+
className,
|
|
46
|
+
type = 'text',
|
|
47
|
+
size,
|
|
48
|
+
variant,
|
|
49
|
+
isInvalid: customInvalid,
|
|
50
|
+
prefixIcon,
|
|
51
|
+
suffixIcon,
|
|
52
|
+
clearable,
|
|
53
|
+
onClear,
|
|
54
|
+
value,
|
|
55
|
+
onChange,
|
|
56
|
+
disabled,
|
|
57
|
+
id,
|
|
58
|
+
...props
|
|
59
|
+
},
|
|
60
|
+
ref
|
|
61
|
+
) => {
|
|
62
|
+
const formField = useFormField();
|
|
63
|
+
const isInvalid = customInvalid ?? formField?.isInvalid ?? false;
|
|
64
|
+
const isDisabled = disabled ?? formField?.isDisabled ?? false;
|
|
65
|
+
const inputId = id || formField?.id;
|
|
66
|
+
|
|
67
|
+
const isControlled = value !== undefined;
|
|
68
|
+
const [uncontrolledVal, setUncontrolledVal] = useState(
|
|
69
|
+
props.defaultValue !== undefined ? String(props.defaultValue) : ''
|
|
70
|
+
);
|
|
71
|
+
const innerRef = React.useRef<HTMLInputElement | null>(null);
|
|
72
|
+
|
|
73
|
+
const handleRef = (node: HTMLInputElement | null) => {
|
|
74
|
+
innerRef.current = node;
|
|
75
|
+
if (typeof ref === 'function') {
|
|
76
|
+
ref(node);
|
|
77
|
+
} else if (ref) {
|
|
78
|
+
(ref as React.MutableRefObject<HTMLInputElement | null>).current = node;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
83
|
+
if (!isControlled) {
|
|
84
|
+
setUncontrolledVal(e.target.value);
|
|
85
|
+
}
|
|
86
|
+
onChange?.(e);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const handleClear = () => {
|
|
90
|
+
if (!isControlled && innerRef.current) {
|
|
91
|
+
innerRef.current.value = '';
|
|
92
|
+
setUncontrolledVal('');
|
|
93
|
+
const event = new Event('input', { bubbles: true });
|
|
94
|
+
innerRef.current.dispatchEvent(event);
|
|
95
|
+
}
|
|
96
|
+
onClear?.();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const hasValue = isControlled
|
|
100
|
+
? Boolean(value)
|
|
101
|
+
: Boolean(uncontrolledVal || innerRef.current?.value);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<div className="relative w-full flex items-center">
|
|
105
|
+
{prefixIcon && (
|
|
106
|
+
<div className="absolute left-3 flex items-center pointer-events-none text-[var(--ui-text-muted)]">
|
|
107
|
+
{prefixIcon}
|
|
108
|
+
</div>
|
|
109
|
+
)}
|
|
110
|
+
|
|
111
|
+
<input
|
|
112
|
+
ref={handleRef}
|
|
113
|
+
id={inputId}
|
|
114
|
+
type={type}
|
|
115
|
+
disabled={isDisabled}
|
|
116
|
+
{...(isControlled ? { value } : {})}
|
|
117
|
+
onChange={handleChange}
|
|
118
|
+
aria-invalid={isInvalid}
|
|
119
|
+
aria-describedby={
|
|
120
|
+
isInvalid
|
|
121
|
+
? formField?.errorId
|
|
122
|
+
: formField?.descriptionId || undefined
|
|
123
|
+
}
|
|
124
|
+
className={cn(
|
|
125
|
+
inputVariants({ size, variant, isInvalid }),
|
|
126
|
+
prefixIcon && 'pl-9',
|
|
127
|
+
(suffixIcon || (clearable && hasValue)) && 'pr-9',
|
|
128
|
+
className
|
|
129
|
+
)}
|
|
130
|
+
{...props}
|
|
131
|
+
/>
|
|
132
|
+
|
|
133
|
+
<div className="absolute right-3 flex items-center gap-1 text-[var(--ui-text-muted)]">
|
|
134
|
+
{clearable && hasValue && !isDisabled && (
|
|
135
|
+
<button
|
|
136
|
+
type="button"
|
|
137
|
+
onClick={handleClear}
|
|
138
|
+
className="p-0.5 rounded-full hover:bg-[var(--ui-bg-tertiary)] hover:text-[var(--ui-text-primary)] transition-colors"
|
|
139
|
+
aria-label="Clear input"
|
|
140
|
+
>
|
|
141
|
+
<X className="w-3.5 h-3.5" />
|
|
142
|
+
</button>
|
|
143
|
+
)}
|
|
144
|
+
{suffixIcon && <span className="pointer-events-none flex items-center">{suffixIcon}</span>}
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
Input.displayName = 'Input';
|