@codefast/ui 0.3.16-canary.1 → 0.3.16-canary.3
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/CHANGELOG.md +30 -0
- package/README.md +1 -1
- package/dist/components/accordion.mjs +2 -2
- package/dist/components/alert-dialog.d.mts +1 -1
- package/dist/components/alert-dialog.mjs +4 -4
- package/dist/components/alert.d.mts +3 -13
- package/dist/components/alert.mjs +3 -23
- package/dist/components/badge.d.mts +3 -15
- package/dist/components/badge.mjs +2 -44
- package/dist/components/breadcrumb.mjs +1 -1
- package/dist/components/button-group.d.mts +3 -13
- package/dist/components/button-group.mjs +3 -24
- package/dist/components/button.d.mts +3 -25
- package/dist/components/button.mjs +2 -72
- package/dist/components/calendar.mjs +2 -1
- package/dist/components/carousel.d.mts +1 -2
- package/dist/components/chart.d.mts +2 -4
- package/dist/components/checkbox.mjs +2 -2
- package/dist/components/context-menu.mjs +2 -2
- package/dist/components/dialog.d.mts +1 -1
- package/dist/components/dialog.mjs +4 -4
- package/dist/components/drawer.d.mts +1 -1
- package/dist/components/drawer.mjs +2 -2
- package/dist/components/dropdown-menu.mjs +2 -2
- package/dist/components/empty.d.mts +3 -13
- package/dist/components/empty.mjs +3 -18
- package/dist/components/field.d.mts +3 -14
- package/dist/components/field.mjs +3 -32
- package/dist/components/form.d.mts +2 -4
- package/dist/components/hover-card.mjs +1 -1
- package/dist/components/input-group.d.mts +4 -31
- package/dist/components/input-group.mjs +3 -90
- package/dist/components/input-number.mjs +4 -4
- package/dist/components/input-otp.mjs +2 -2
- package/dist/components/input.mjs +1 -1
- package/dist/components/item.d.mts +4 -29
- package/dist/components/item.mjs +3 -56
- package/dist/components/menubar.mjs +2 -2
- package/dist/components/native-select.mjs +1 -1
- package/dist/components/navigation-menu.d.mts +1 -6
- package/dist/components/navigation-menu.mjs +8 -15
- package/dist/components/pagination.d.mts +1 -1
- package/dist/components/pagination.mjs +1 -1
- package/dist/components/popover.mjs +1 -1
- package/dist/components/progress-circle.d.mts +3 -47
- package/dist/components/progress-circle.mjs +2 -47
- package/dist/components/progress.mjs +1 -1
- package/dist/components/radio-group.mjs +1 -1
- package/dist/components/radio.mjs +1 -1
- package/dist/components/scroll-area.d.mts +3 -19
- package/dist/components/scroll-area.mjs +4 -61
- package/dist/components/select.d.mts +1 -1
- package/dist/components/select.mjs +3 -3
- package/dist/components/separator.d.mts +3 -18
- package/dist/components/separator.mjs +3 -23
- package/dist/components/sheet.d.mts +6 -18
- package/dist/components/sheet.mjs +6 -49
- package/dist/components/sidebar.d.mts +4 -19
- package/dist/components/sidebar.mjs +10 -46
- package/dist/components/skeleton.mjs +1 -1
- package/dist/components/slider.mjs +1 -1
- package/dist/components/spinner.mjs +1 -1
- package/dist/components/switch.mjs +2 -2
- package/dist/components/table.mjs +1 -1
- package/dist/components/tabs.mjs +1 -1
- package/dist/components/textarea.mjs +1 -1
- package/dist/components/toggle-group.d.mts +3 -2
- package/dist/components/toggle-group.mjs +1 -1
- package/dist/components/toggle.d.mts +2 -21
- package/dist/components/toggle.mjs +2 -39
- package/dist/components/tooltip.mjs +1 -1
- package/dist/index.d.mts +31 -16
- package/dist/index.mjs +30 -15
- package/dist/lib/utils.d.mts +1 -12
- package/dist/lib/utils.mjs +1 -9
- package/dist/primitives/checkbox-group.d.mts +1 -2
- package/dist/primitives/input-number.d.mts +1 -2
- package/dist/primitives/input.d.mts +1 -2
- package/dist/primitives/progress-circle.d.mts +1 -2
- package/dist/variants/alert.d.mts +18 -0
- package/dist/variants/alert.mjs +25 -0
- package/dist/variants/badge.d.mts +20 -0
- package/dist/variants/badge.mjs +46 -0
- package/dist/variants/button-group.d.mts +18 -0
- package/dist/variants/button-group.mjs +26 -0
- package/dist/variants/button.d.mts +30 -0
- package/dist/variants/button.mjs +76 -0
- package/dist/variants/empty.d.mts +18 -0
- package/dist/variants/empty.mjs +20 -0
- package/dist/variants/field.d.mts +19 -0
- package/dist/variants/field.mjs +34 -0
- package/dist/variants/input-group.d.mts +43 -0
- package/dist/variants/input-group.mjs +93 -0
- package/dist/variants/item.d.mts +37 -0
- package/dist/variants/item.mjs +60 -0
- package/dist/variants/navigation-menu.d.mts +13 -0
- package/dist/variants/navigation-menu.mjs +12 -0
- package/dist/variants/progress-circle.d.mts +52 -0
- package/dist/variants/progress-circle.mjs +49 -0
- package/dist/variants/scroll-area.d.mts +24 -0
- package/dist/variants/scroll-area.mjs +63 -0
- package/dist/variants/separator.d.mts +23 -0
- package/dist/variants/separator.mjs +25 -0
- package/dist/variants/sheet.d.mts +20 -0
- package/dist/variants/sheet.mjs +50 -0
- package/dist/variants/sidebar.d.mts +23 -0
- package/dist/variants/sidebar.mjs +42 -0
- package/dist/variants/toggle.d.mts +23 -0
- package/dist/variants/toggle.mjs +43 -0
- package/package.json +169 -21
- package/src/components/accordion.tsx +156 -0
- package/src/components/alert-dialog.tsx +314 -0
- package/src/components/alert.tsx +86 -0
- package/src/components/aspect-ratio.tsx +28 -0
- package/src/components/avatar.tsx +84 -0
- package/src/components/badge.tsx +38 -0
- package/src/components/breadcrumb.tsx +197 -0
- package/src/components/button-group.tsx +107 -0
- package/src/components/button.tsx +66 -0
- package/src/components/calendar.tsx +277 -0
- package/src/components/card.tsx +175 -0
- package/src/components/carousel.tsx +367 -0
- package/src/components/chart.tsx +587 -0
- package/src/components/checkbox-cards.tsx +92 -0
- package/src/components/checkbox-group.tsx +83 -0
- package/src/components/checkbox.tsx +65 -0
- package/src/components/collapsible.tsx +60 -0
- package/src/components/command.tsx +311 -0
- package/src/components/context-menu.tsx +489 -0
- package/src/components/dialog.tsx +295 -0
- package/src/components/drawer.tsx +271 -0
- package/src/components/dropdown-menu.tsx +498 -0
- package/src/components/empty.tsx +169 -0
- package/src/components/field.tsx +362 -0
- package/src/components/form.tsx +300 -0
- package/src/components/hover-card.tsx +116 -0
- package/src/components/input-group.tsx +224 -0
- package/src/components/input-number.tsx +161 -0
- package/src/components/input-otp.tsx +151 -0
- package/src/components/input-password.tsx +74 -0
- package/src/components/input-search.tsx +98 -0
- package/src/components/input.tsx +52 -0
- package/src/components/item.tsx +280 -0
- package/src/components/kbd.tsx +59 -0
- package/src/components/label.tsx +44 -0
- package/src/components/menubar.tsx +531 -0
- package/src/components/native-select.tsx +96 -0
- package/src/components/navigation-menu.tsx +295 -0
- package/src/components/pagination.tsx +204 -0
- package/src/components/popover.tsx +139 -0
- package/src/components/progress-circle.tsx +203 -0
- package/src/components/progress.tsx +54 -0
- package/src/components/radio-cards.tsx +85 -0
- package/src/components/radio-group.tsx +79 -0
- package/src/components/radio.tsx +61 -0
- package/src/components/resizable.tsx +99 -0
- package/src/components/scroll-area.tsx +115 -0
- package/src/components/select.tsx +319 -0
- package/src/components/separator.tsx +74 -0
- package/src/components/sheet.tsx +278 -0
- package/src/components/sidebar.tsx +1056 -0
- package/src/components/skeleton.tsx +37 -0
- package/src/components/slider.tsx +95 -0
- package/src/components/sonner.tsx +47 -0
- package/src/components/spinner.tsx +75 -0
- package/src/components/switch.tsx +66 -0
- package/src/components/table.tsx +200 -0
- package/src/components/tabs.tsx +128 -0
- package/src/components/textarea.tsx +49 -0
- package/src/components/toggle-group.tsx +141 -0
- package/src/components/toggle.tsx +39 -0
- package/src/components/tooltip.tsx +141 -0
- package/src/css/amber.css +59 -22
- package/src/css/blue.css +59 -22
- package/src/css/cyan.css +59 -22
- package/src/css/emerald.css +59 -22
- package/src/css/fuchsia.css +59 -22
- package/src/css/gray.css +59 -22
- package/src/css/green.css +59 -22
- package/src/css/indigo.css +59 -22
- package/src/css/lime.css +59 -22
- package/src/css/neutral.css +59 -22
- package/src/css/orange.css +59 -22
- package/src/css/pink.css +59 -22
- package/src/css/preset.css +32 -13
- package/src/css/purple.css +59 -22
- package/src/css/red.css +59 -22
- package/src/css/rose.css +59 -22
- package/src/css/sky.css +59 -22
- package/src/css/slate.css +59 -22
- package/src/css/stone.css +59 -22
- package/src/css/teal.css +59 -22
- package/src/css/violet.css +59 -22
- package/src/css/yellow.css +59 -22
- package/src/css/zinc.css +59 -22
- package/src/hooks/use-animated-value.ts +97 -0
- package/src/hooks/use-copy-to-clipboard.ts +63 -0
- package/src/hooks/use-is-mobile.ts +27 -0
- package/src/hooks/use-media-query.ts +71 -0
- package/src/hooks/use-mutation-observer.ts +54 -0
- package/src/hooks/use-pagination.ts +166 -0
- package/src/index.ts +720 -0
- package/src/lib/utils.ts +5 -0
- package/src/primitives/checkbox-group.tsx +360 -0
- package/src/primitives/input-number.tsx +1013 -0
- package/src/primitives/input.tsx +243 -0
- package/src/primitives/progress-circle.tsx +537 -0
- package/src/variants/alert.ts +45 -0
- package/src/variants/badge.ts +66 -0
- package/src/variants/button-group.ts +49 -0
- package/src/variants/button.ts +93 -0
- package/src/variants/empty.ts +43 -0
- package/src/variants/field.ts +50 -0
- package/src/variants/input-group.ts +132 -0
- package/src/variants/item.ts +90 -0
- package/src/variants/navigation-menu.ts +32 -0
- package/src/variants/progress-circle.ts +47 -0
- package/src/variants/scroll-area.ts +79 -0
- package/src/variants/separator.ts +41 -0
- package/src/variants/sheet.ts +70 -0
- package/src/variants/sidebar.ts +61 -0
- package/src/variants/toggle.ts +59 -0
- package/dist/node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/clsx.d.mts +0 -6
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import type { Scope } from "@radix-ui/react-context";
|
|
2
|
+
import type {
|
|
3
|
+
ComponentProps,
|
|
4
|
+
JSX,
|
|
5
|
+
PointerEventHandler,
|
|
6
|
+
PropsWithChildren,
|
|
7
|
+
ReactNode,
|
|
8
|
+
RefObject,
|
|
9
|
+
} from "react";
|
|
10
|
+
|
|
11
|
+
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
12
|
+
import { createContextScope } from "@radix-ui/react-context";
|
|
13
|
+
import { useRef } from "react";
|
|
14
|
+
|
|
15
|
+
/* -----------------------------------------------------------------------------
|
|
16
|
+
* Component: Input
|
|
17
|
+
* -------------------------------------------------------------------------- */
|
|
18
|
+
|
|
19
|
+
const INPUT_NAME = "Input";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Type for adding scope to component props
|
|
23
|
+
*/
|
|
24
|
+
type ScopedProps<P> = P & {
|
|
25
|
+
/**
|
|
26
|
+
* Scope for the Input component context
|
|
27
|
+
*/
|
|
28
|
+
__scopeInput?: Scope;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const [createInputContext, createInputScope] = createContextScope(INPUT_NAME);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Context value for the Input component
|
|
35
|
+
*/
|
|
36
|
+
interface InputContextValue {
|
|
37
|
+
/**
|
|
38
|
+
* Reference to the input element
|
|
39
|
+
*/
|
|
40
|
+
inputRef: RefObject<HTMLInputElement | null>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether the input is disabled
|
|
44
|
+
*/
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Whether the input is in read-only mode
|
|
49
|
+
*/
|
|
50
|
+
readOnly?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const [InputContextProvider, useInputContext] = createInputContext<InputContextValue>(INPUT_NAME);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Props for styling and appearance of the Input component
|
|
57
|
+
*/
|
|
58
|
+
interface InputVisualProps {
|
|
59
|
+
/**
|
|
60
|
+
* CSS class name for the input container
|
|
61
|
+
*/
|
|
62
|
+
className?: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Element to display before the input
|
|
66
|
+
*/
|
|
67
|
+
prefix?: ReactNode;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Custom spinner element for loading state
|
|
71
|
+
*/
|
|
72
|
+
spinner?: ReactNode;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Element to display after the input
|
|
76
|
+
*/
|
|
77
|
+
suffix?: ReactNode;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Props for the behavior and state of the Input component
|
|
82
|
+
*/
|
|
83
|
+
interface InputBehaviorProps {
|
|
84
|
+
/**
|
|
85
|
+
* Whether the input is disabled
|
|
86
|
+
*/
|
|
87
|
+
disabled?: boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Position of the loading spinner - either before or after the input
|
|
91
|
+
*/
|
|
92
|
+
loaderPosition?: "prefix" | "suffix";
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Whether the input is in the loading state
|
|
96
|
+
*/
|
|
97
|
+
loading?: boolean;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Whether the input is in read-only mode
|
|
101
|
+
*/
|
|
102
|
+
readOnly?: boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Combined props for the Input component
|
|
107
|
+
*
|
|
108
|
+
* @since 0.3.16-canary.0
|
|
109
|
+
*/
|
|
110
|
+
type InputProps = PropsWithChildren<InputBehaviorProps & InputVisualProps>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @since 0.3.16-canary.0
|
|
114
|
+
*/
|
|
115
|
+
function Input(inputProps: ScopedProps<InputProps>): JSX.Element {
|
|
116
|
+
const {
|
|
117
|
+
__scopeInput,
|
|
118
|
+
children,
|
|
119
|
+
disabled,
|
|
120
|
+
loaderPosition = "prefix",
|
|
121
|
+
loading,
|
|
122
|
+
prefix,
|
|
123
|
+
readOnly,
|
|
124
|
+
spinner,
|
|
125
|
+
suffix,
|
|
126
|
+
...props
|
|
127
|
+
} = inputProps;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Reference to the input element
|
|
131
|
+
*/
|
|
132
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Handles pointer down events on the input container
|
|
136
|
+
* Focuses the input element when clicking on the container
|
|
137
|
+
*
|
|
138
|
+
* @param event - The pointer event object
|
|
139
|
+
*/
|
|
140
|
+
const handlePointerDown: PointerEventHandler<HTMLDivElement> = (event) => {
|
|
141
|
+
const target = event.target as HTMLElement;
|
|
142
|
+
|
|
143
|
+
// Skip handling when clicking directly on input, links, buttons, or other interactive elements
|
|
144
|
+
// This prevents interference with native input/link/button behavior
|
|
145
|
+
if (target.tagName.toLowerCase() === "input" || target.closest("input, a, button")) {
|
|
146
|
+
event.stopPropagation();
|
|
147
|
+
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const inputElement = inputRef.current;
|
|
152
|
+
|
|
153
|
+
if (!inputElement) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Key solution: If input already has focus, only prevent default behavior
|
|
158
|
+
// This prevents the focus from being lost when clicking on the container padding
|
|
159
|
+
// and eliminates the flickering effect
|
|
160
|
+
if (document.activeElement === inputElement) {
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Only attempt to focus the input if it's not already focused
|
|
167
|
+
requestAnimationFrame(() => {
|
|
168
|
+
// Special handling for file inputs - trigger the file selection dialog
|
|
169
|
+
if (inputElement.type === "file") {
|
|
170
|
+
inputElement.click();
|
|
171
|
+
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Only focus the input if it doesn't already have focus
|
|
176
|
+
// This avoids unnecessary re-focusing which can cause UI flickers
|
|
177
|
+
if (document.activeElement !== inputElement) {
|
|
178
|
+
inputElement.focus();
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<InputContextProvider
|
|
185
|
+
disabled={disabled}
|
|
186
|
+
inputRef={inputRef}
|
|
187
|
+
readOnly={readOnly}
|
|
188
|
+
scope={__scopeInput}
|
|
189
|
+
>
|
|
190
|
+
<div
|
|
191
|
+
data-disabled={disabled}
|
|
192
|
+
data-readonly={readOnly}
|
|
193
|
+
role="presentation"
|
|
194
|
+
onPointerDown={handlePointerDown}
|
|
195
|
+
{...props}
|
|
196
|
+
>
|
|
197
|
+
{loading && loaderPosition === "prefix" ? spinner : prefix}
|
|
198
|
+
{children}
|
|
199
|
+
{loading && loaderPosition === "suffix" ? spinner : suffix}
|
|
200
|
+
</div>
|
|
201
|
+
</InputContextProvider>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* -----------------------------------------------------------------------------
|
|
206
|
+
* Component: InputField
|
|
207
|
+
* -------------------------------------------------------------------------- */
|
|
208
|
+
|
|
209
|
+
const INPUT_FIELD_NAME = "InputField";
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Props for the InputField component
|
|
213
|
+
*
|
|
214
|
+
* @since 0.3.16-canary.0
|
|
215
|
+
*/
|
|
216
|
+
type InputFieldProps = ComponentProps<"input">;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @since 0.3.16-canary.0
|
|
220
|
+
*/
|
|
221
|
+
function InputField({ __scopeInput, ...props }: ScopedProps<InputFieldProps>): JSX.Element {
|
|
222
|
+
/**
|
|
223
|
+
* Context values from parent Input component
|
|
224
|
+
*/
|
|
225
|
+
const { disabled, inputRef, readOnly } = useInputContext(INPUT_FIELD_NAME, __scopeInput);
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Combined ref that syncs with the parent's inputRef
|
|
229
|
+
*/
|
|
230
|
+
const composedInputRef = useComposedRefs(inputRef);
|
|
231
|
+
|
|
232
|
+
return (
|
|
233
|
+
<input ref={composedInputRef} disabled={disabled} readOnly={readOnly} type="text" {...props} />
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* -----------------------------------------------------------------------------
|
|
238
|
+
* Exports
|
|
239
|
+
* -------------------------------------------------------------------------- */
|
|
240
|
+
|
|
241
|
+
export { createInputScope, InputField as Field, Input, InputField, Input as Root };
|
|
242
|
+
|
|
243
|
+
export type { InputFieldProps, InputProps };
|