@codefast/ui 0.3.10 → 0.3.11-canary.1
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 +32 -0
- package/README.md +277 -167
- package/dist/components/accordion.d.ts +4 -4
- package/dist/components/accordion.js +5 -5
- package/dist/components/alert-dialog.d.ts +11 -11
- package/dist/components/alert-dialog.js +9 -9
- package/dist/components/alert.d.ts +5 -5
- package/dist/components/alert.js +5 -5
- package/dist/components/aspect-ratio.d.ts +2 -2
- package/dist/components/avatar.d.ts +2 -2
- package/dist/components/avatar.js +3 -3
- package/dist/components/badge.d.ts +3 -3
- package/dist/components/badge.js +7 -7
- package/dist/components/breadcrumb.d.ts +8 -8
- package/dist/components/breadcrumb.js +6 -8
- package/dist/components/button-group.d.ts +5 -5
- package/dist/components/button-group.js +8 -8
- package/dist/components/button.d.ts +6 -6
- package/dist/components/button.js +17 -17
- package/dist/components/calendar.d.ts +5 -5
- package/dist/components/calendar.js +35 -35
- package/dist/components/card.d.ts +8 -8
- package/dist/components/card.js +7 -7
- package/dist/components/carousel.d.ts +10 -10
- package/dist/components/carousel.js +20 -20
- package/dist/components/chart.d.ts +12 -11
- package/dist/components/chart.js +42 -42
- package/dist/components/checkbox-cards.d.ts +2 -2
- package/dist/components/checkbox-cards.js +2 -2
- package/dist/components/checkbox-group.d.ts +2 -2
- package/dist/components/checkbox-group.js +2 -2
- package/dist/components/checkbox.d.ts +2 -2
- package/dist/components/checkbox.js +1 -1
- package/dist/components/collapsible.d.ts +2 -2
- package/dist/components/command.d.ts +4 -4
- package/dist/components/command.js +10 -10
- package/dist/components/context-menu.d.ts +4 -4
- package/dist/components/context-menu.js +10 -10
- package/dist/components/dialog.d.ts +10 -10
- package/dist/components/dialog.js +12 -12
- package/dist/components/drawer.d.ts +9 -9
- package/dist/components/drawer.js +9 -9
- package/dist/components/dropdown-menu.d.ts +4 -4
- package/dist/components/dropdown-menu.js +10 -10
- package/dist/components/empty.d.ts +9 -9
- package/dist/components/empty.js +10 -10
- package/dist/components/field.d.ts +14 -14
- package/dist/components/field.js +17 -17
- package/dist/components/form.d.ts +10 -10
- package/dist/components/form.js +8 -8
- package/dist/components/hover-card.d.ts +2 -2
- package/dist/components/hover-card.js +3 -3
- package/dist/components/input-group.d.ts +15 -15
- package/dist/components/input-group.js +20 -20
- package/dist/components/input-number.d.ts +2 -2
- package/dist/components/input-number.js +7 -7
- package/dist/components/input-otp.d.ts +6 -6
- package/dist/components/input-otp.js +4 -4
- package/dist/components/input-password.d.ts +3 -3
- package/dist/components/input-password.js +6 -6
- package/dist/components/input-search.d.ts +3 -3
- package/dist/components/input-search.js +4 -4
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +1 -1
- package/dist/components/item.d.ts +12 -12
- package/dist/components/item.js +23 -23
- package/dist/components/kbd.d.ts +3 -3
- package/dist/components/kbd.js +2 -2
- package/dist/components/label.d.ts +2 -2
- package/dist/components/label.js +1 -1
- package/dist/components/menubar.d.ts +4 -4
- package/dist/components/menubar.js +13 -13
- package/dist/components/native-select.d.ts +4 -4
- package/dist/components/native-select.js +2 -2
- package/dist/components/navigation-menu.d.ts +2 -2
- package/dist/components/navigation-menu.js +10 -10
- package/dist/components/pagination.d.ts +10 -10
- package/dist/components/pagination.js +6 -6
- package/dist/components/popover.d.ts +3 -3
- package/dist/components/popover.js +3 -3
- package/dist/components/progress-circle.d.ts +5 -5
- package/dist/components/progress-circle.js +22 -22
- package/dist/components/progress.d.ts +2 -2
- package/dist/components/progress.js +2 -2
- package/dist/components/radio-cards.d.ts +2 -2
- package/dist/components/radio-cards.js +3 -3
- package/dist/components/radio-group.d.ts +2 -2
- package/dist/components/radio-group.js +3 -3
- package/dist/components/radio.d.ts +2 -2
- package/dist/components/radio.js +1 -1
- package/dist/components/resizable.d.ts +2 -2
- package/dist/components/resizable.js +3 -3
- package/dist/components/scroll-area.d.ts +5 -5
- package/dist/components/scroll-area.js +31 -31
- package/dist/components/select.d.ts +5 -5
- package/dist/components/select.js +9 -9
- package/dist/components/separator.d.ts +5 -5
- package/dist/components/separator.js +9 -9
- package/dist/components/sheet.d.ts +9 -9
- package/dist/components/sheet.js +17 -17
- package/dist/components/sidebar.d.ts +31 -31
- package/dist/components/sidebar.js +65 -65
- package/dist/components/skeleton.d.ts +2 -2
- package/dist/components/skeleton.js +1 -1
- package/dist/components/slider.d.ts +2 -2
- package/dist/components/slider.js +4 -4
- package/dist/components/sonner.d.ts +3 -3
- package/dist/components/sonner.js +4 -4
- package/dist/components/spinner.d.ts +2 -2
- package/dist/components/spinner.js +5 -5
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +2 -2
- package/dist/components/table.d.ts +9 -9
- package/dist/components/table.js +8 -8
- package/dist/components/tabs.d.ts +2 -2
- package/dist/components/tabs.js +4 -4
- package/dist/components/textarea.d.ts +2 -2
- package/dist/components/textarea.js +1 -1
- package/dist/components/toggle-group.d.ts +4 -4
- package/dist/components/toggle-group.js +5 -5
- package/dist/components/toggle.d.ts +3 -3
- package/dist/components/toggle.js +8 -8
- package/dist/components/tooltip.d.ts +3 -3
- package/dist/components/tooltip.js +2 -2
- package/dist/css/preset.css +4 -4
- package/dist/css/style.css +3 -3
- package/dist/hooks/use-copy-to-clipboard.d.ts +1 -1
- package/dist/hooks/use-copy-to-clipboard.js +1 -1
- package/dist/hooks/use-media-query.js +3 -3
- package/dist/hooks/use-mutation-observer.d.ts +1 -1
- package/dist/hooks/use-pagination.js +1 -1
- package/dist/index.d.ts +130 -130
- package/dist/primitives/checkbox-group.d.ts +11 -11
- package/dist/primitives/checkbox-group.js +3 -3
- package/dist/primitives/input-number.d.ts +8 -8
- package/dist/primitives/input-number.js +46 -46
- package/dist/primitives/input.d.ts +4 -4
- package/dist/primitives/input.js +7 -7
- package/dist/primitives/progress-circle.d.ts +7 -7
- package/dist/primitives/progress-circle.js +8 -8
- package/package.json +111 -189
- package/dist/components/accordion.cjs +0 -98
- package/dist/components/alert-dialog.cjs +0 -156
- package/dist/components/alert.cjs +0 -84
- package/dist/components/aspect-ratio.cjs +0 -44
- package/dist/components/avatar.cjs +0 -66
- package/dist/components/badge.cjs +0 -67
- package/dist/components/breadcrumb.cjs +0 -127
- package/dist/components/button-group.cjs +0 -87
- package/dist/components/button.cjs +0 -92
- package/dist/components/calendar.cjs +0 -151
- package/dist/components/card.cjs +0 -105
- package/dist/components/carousel.cjs +0 -211
- package/dist/components/chart.cjs +0 -251
- package/dist/components/checkbox-cards.cjs +0 -70
- package/dist/components/checkbox-group.cjs +0 -64
- package/dist/components/checkbox.cjs +0 -54
- package/dist/components/collapsible.cjs +0 -62
- package/dist/components/command.cjs +0 -168
- package/dist/components/context-menu.cjs +0 -219
- package/dist/components/dialog.cjs +0 -165
- package/dist/components/drawer.cjs +0 -144
- package/dist/components/dropdown-menu.cjs +0 -222
- package/dist/components/empty.cjs +0 -113
- package/dist/components/field.cjs +0 -194
- package/dist/components/form.cjs +0 -152
- package/dist/components/hover-card.cjs +0 -78
- package/dist/components/input-group.cjs +0 -156
- package/dist/components/input-number.cjs +0 -99
- package/dist/components/input-otp.cjs +0 -102
- package/dist/components/input-password.cjs +0 -72
- package/dist/components/input-search.cjs +0 -81
- package/dist/components/input.cjs +0 -46
- package/dist/components/item.cjs +0 -186
- package/dist/components/kbd.cjs +0 -54
- package/dist/components/label.cjs +0 -46
- package/dist/components/menubar.cjs +0 -233
- package/dist/components/native-select.cjs +0 -75
- package/dist/components/navigation-menu.cjs +0 -146
- package/dist/components/pagination.cjs +0 -138
- package/dist/components/popover.cjs +0 -87
- package/dist/components/progress-circle.cjs +0 -185
- package/dist/components/progress.cjs +0 -53
- package/dist/components/radio-cards.cjs +0 -67
- package/dist/components/radio-group.cjs +0 -60
- package/dist/components/radio.cjs +0 -48
- package/dist/components/resizable.cjs +0 -72
- package/dist/components/scroll-area.cjs +0 -141
- package/dist/components/select.cjs +0 -181
- package/dist/components/separator.cjs +0 -83
- package/dist/components/sheet.cjs +0 -185
- package/dist/components/sidebar.cjs +0 -507
- package/dist/components/skeleton.cjs +0 -44
- package/dist/components/slider.cjs +0 -80
- package/dist/components/sonner.cjs +0 -58
- package/dist/components/spinner.cjs +0 -76
- package/dist/components/switch.cjs +0 -50
- package/dist/components/table.cjs +0 -118
- package/dist/components/tabs.cjs +0 -76
- package/dist/components/textarea.cjs +0 -44
- package/dist/components/toggle-group.cjs +0 -91
- package/dist/components/toggle.cjs +0 -72
- package/dist/components/tooltip.cjs +0 -91
- package/dist/hooks/use-animated-value.cjs +0 -75
- package/dist/hooks/use-copy-to-clipboard.cjs +0 -58
- package/dist/hooks/use-is-mobile.cjs +0 -40
- package/dist/hooks/use-media-query.cjs +0 -57
- package/dist/hooks/use-mutation-observer.cjs +0 -57
- package/dist/hooks/use-pagination.cjs +0 -93
- package/dist/index.cjs +0 -1081
- package/dist/primitives/checkbox-group.cjs +0 -151
- package/dist/primitives/input-number.cjs +0 -439
- package/dist/primitives/input.cjs +0 -99
- package/dist/primitives/progress-circle.cjs +0 -199
|
@@ -4,7 +4,7 @@ import { createContextScope } from "@radix-ui/react-context";
|
|
|
4
4
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
5
5
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
6
6
|
import { Field, Root, createInputScope } from "./input.js";
|
|
7
|
-
const NUMBER_INPUT_NAME =
|
|
7
|
+
const NUMBER_INPUT_NAME = "InputNumber";
|
|
8
8
|
const [createInputNumberContext, createInputNumberScope] = createContextScope(NUMBER_INPUT_NAME, [
|
|
9
9
|
createInputScope
|
|
10
10
|
]);
|
|
@@ -13,7 +13,7 @@ const [InputNumberContextProvider, useInputNumberContext] = createInputNumberCon
|
|
|
13
13
|
function InputNumber(numberInputProps) {
|
|
14
14
|
const { __scopeInputNumber, ariaDecrementLabel, ariaIncrementLabel, defaultValue, formatOptions = {
|
|
15
15
|
minimumFractionDigits: 0,
|
|
16
|
-
style:
|
|
16
|
+
style: "decimal"
|
|
17
17
|
}, id, locale, max, min, onChange, step = 1, value: valueProperty, ...props } = numberInputProps;
|
|
18
18
|
const inputScope = useInputScope(__scopeInputNumber);
|
|
19
19
|
const inputRef = useRef(null);
|
|
@@ -26,20 +26,20 @@ function InputNumber(numberInputProps) {
|
|
|
26
26
|
locale
|
|
27
27
|
]);
|
|
28
28
|
const formatValue = useCallback((inputValue)=>{
|
|
29
|
-
if (void 0 === inputValue || Number.isNaN(inputValue)) return
|
|
29
|
+
if (void 0 === inputValue || Number.isNaN(inputValue)) return "";
|
|
30
30
|
return new Intl.NumberFormat(locale, formatOptions).format(inputValue);
|
|
31
31
|
}, [
|
|
32
32
|
formatOptions,
|
|
33
33
|
locale
|
|
34
34
|
]);
|
|
35
35
|
const parseValue = useCallback((inputValue)=>{
|
|
36
|
-
if (
|
|
37
|
-
if (
|
|
38
|
-
const cleanedValue = inputValue.trim().replaceAll(/[^\d.,\-()]/g,
|
|
39
|
-
if (
|
|
36
|
+
if ("number" == typeof inputValue) return clamp(inputValue, min, max);
|
|
37
|
+
if ("string" != typeof inputValue) return NaN;
|
|
38
|
+
const cleanedValue = inputValue.trim().replaceAll(/[^\d.,\-()]/g, "");
|
|
39
|
+
if ("" === cleanedValue) return NaN;
|
|
40
40
|
const normalizedValue = normalizeInputValue(cleanedValue, thousandSeparator, decimalSeparator);
|
|
41
41
|
let parsedValue = Number.parseFloat(normalizedValue);
|
|
42
|
-
if (
|
|
42
|
+
if ("percent" === formatOptions.style) parsedValue /= 100;
|
|
43
43
|
return Number.isNaN(parsedValue) ? 0 : clamp(parsedValue, min, max);
|
|
44
44
|
}, [
|
|
45
45
|
decimalSeparator,
|
|
@@ -116,7 +116,7 @@ function InputNumber(numberInputProps) {
|
|
|
116
116
|
})
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
|
-
const NUMBER_INPUT_FIELD_NAME =
|
|
119
|
+
const NUMBER_INPUT_FIELD_NAME = "InputNumberField";
|
|
120
120
|
function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }) {
|
|
121
121
|
const inputScope = useInputScope(__scopeInputNumber);
|
|
122
122
|
const { defaultValue, disabled, formatValue, id, inputRef, max, min, onChange, onDecrement, onDecrementToMin, onIncrement, onIncrementToMax, parseValue, readOnly, step, value } = useInputNumberContext(NUMBER_INPUT_FIELD_NAME, __scopeInputNumber);
|
|
@@ -132,19 +132,19 @@ function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }) {
|
|
|
132
132
|
]);
|
|
133
133
|
const handleKeyDown = useCallback((event)=>{
|
|
134
134
|
switch(event.key){
|
|
135
|
-
case
|
|
135
|
+
case "ArrowUp":
|
|
136
136
|
onIncrement();
|
|
137
137
|
event.preventDefault();
|
|
138
138
|
break;
|
|
139
|
-
case
|
|
139
|
+
case "PageUp":
|
|
140
140
|
onIncrementToMax();
|
|
141
141
|
event.preventDefault();
|
|
142
142
|
break;
|
|
143
|
-
case
|
|
143
|
+
case "ArrowDown":
|
|
144
144
|
onDecrement();
|
|
145
145
|
event.preventDefault();
|
|
146
146
|
break;
|
|
147
|
-
case
|
|
147
|
+
case "PageDown":
|
|
148
148
|
onDecrementToMin();
|
|
149
149
|
event.preventDefault();
|
|
150
150
|
break;
|
|
@@ -159,23 +159,23 @@ function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }) {
|
|
|
159
159
|
]);
|
|
160
160
|
const handleKeyDownPrevent = useCallback((event)=>{
|
|
161
161
|
switch(event.key){
|
|
162
|
-
case
|
|
163
|
-
case
|
|
164
|
-
case
|
|
165
|
-
case
|
|
166
|
-
case
|
|
167
|
-
case
|
|
168
|
-
case
|
|
169
|
-
case
|
|
170
|
-
case
|
|
171
|
-
case
|
|
172
|
-
case
|
|
173
|
-
case
|
|
174
|
-
case
|
|
175
|
-
case
|
|
176
|
-
case
|
|
177
|
-
case
|
|
178
|
-
case
|
|
162
|
+
case "ArrowUp":
|
|
163
|
+
case "ArrowDown":
|
|
164
|
+
case "ArrowLeft":
|
|
165
|
+
case "ArrowRight":
|
|
166
|
+
case "PageUp":
|
|
167
|
+
case "PageDown":
|
|
168
|
+
case "Tab":
|
|
169
|
+
case "Escape":
|
|
170
|
+
case "Enter":
|
|
171
|
+
case "Backspace":
|
|
172
|
+
case "Delete":
|
|
173
|
+
case "Home":
|
|
174
|
+
case "End":
|
|
175
|
+
case ".":
|
|
176
|
+
case ",":
|
|
177
|
+
case "-":
|
|
178
|
+
case "%":
|
|
179
179
|
return;
|
|
180
180
|
default:
|
|
181
181
|
if (isNumberKey(event.key) || isModifierKey(event) || isFunctionKey(event.key)) return;
|
|
@@ -184,7 +184,7 @@ function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }) {
|
|
|
184
184
|
}, []);
|
|
185
185
|
const handleKeyDownEnter = useCallback((event)=>{
|
|
186
186
|
const inputElement = inputRef.current;
|
|
187
|
-
if (
|
|
187
|
+
if ("Enter" !== event.key || !inputElement) return;
|
|
188
188
|
const numericValue = parseValue(inputElement.value);
|
|
189
189
|
const formattedValue = formatValue(numericValue);
|
|
190
190
|
if (formattedValue !== inputElement.value) inputElement.value = formattedValue;
|
|
@@ -212,9 +212,9 @@ function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }) {
|
|
|
212
212
|
else onDecrement();
|
|
213
213
|
};
|
|
214
214
|
const inputElement = inputRef.current;
|
|
215
|
-
inputElement?.addEventListener(
|
|
215
|
+
inputElement?.addEventListener("wheel", handleWheel);
|
|
216
216
|
return ()=>{
|
|
217
|
-
inputElement?.removeEventListener(
|
|
217
|
+
inputElement?.removeEventListener("wheel", handleWheel);
|
|
218
218
|
};
|
|
219
219
|
}, [
|
|
220
220
|
onIncrement,
|
|
@@ -238,9 +238,9 @@ function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }) {
|
|
|
238
238
|
onChange(parseValue(defaultValue));
|
|
239
239
|
};
|
|
240
240
|
const form = inputElement.form;
|
|
241
|
-
form?.addEventListener(
|
|
241
|
+
form?.addEventListener("reset", handleReset);
|
|
242
242
|
return ()=>{
|
|
243
|
-
form?.removeEventListener(
|
|
243
|
+
form?.removeEventListener("reset", handleReset);
|
|
244
244
|
};
|
|
245
245
|
}, [
|
|
246
246
|
defaultValue,
|
|
@@ -264,7 +264,7 @@ function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }) {
|
|
|
264
264
|
...props
|
|
265
265
|
});
|
|
266
266
|
}
|
|
267
|
-
const NUMBER_STEPPER_BUTTON_NAME =
|
|
267
|
+
const NUMBER_STEPPER_BUTTON_NAME = "NumberStepperButton";
|
|
268
268
|
function NumberStepperButton({ __scopeInputNumber, operation, ...props }) {
|
|
269
269
|
const { ariaDecrementLabel, ariaIncrementLabel, disabled, id, max, min, onDecrement, onIncrement, value } = useInputNumberContext(NUMBER_STEPPER_BUTTON_NAME, __scopeInputNumber);
|
|
270
270
|
const isDisabled = useMemo(()=>{
|
|
@@ -294,7 +294,7 @@ function NumberStepperButton({ __scopeInputNumber, operation, ...props }) {
|
|
|
294
294
|
}
|
|
295
295
|
}, []);
|
|
296
296
|
const handlePointerDown = useCallback(()=>{
|
|
297
|
-
const action =
|
|
297
|
+
const action = "increment" === operation ? onIncrement : onDecrement;
|
|
298
298
|
startActionInterval(action);
|
|
299
299
|
}, [
|
|
300
300
|
onDecrement,
|
|
@@ -306,9 +306,9 @@ function NumberStepperButton({ __scopeInputNumber, operation, ...props }) {
|
|
|
306
306
|
event.preventDefault();
|
|
307
307
|
}, []);
|
|
308
308
|
const handleKeyDown = useCallback((event)=>{
|
|
309
|
-
if (
|
|
309
|
+
if ("Enter" === event.key || " " === event.key) {
|
|
310
310
|
event.preventDefault();
|
|
311
|
-
const action =
|
|
311
|
+
const action = "increment" === operation ? onIncrement : onDecrement;
|
|
312
312
|
action();
|
|
313
313
|
}
|
|
314
314
|
}, [
|
|
@@ -318,7 +318,7 @@ function NumberStepperButton({ __scopeInputNumber, operation, ...props }) {
|
|
|
318
318
|
]);
|
|
319
319
|
return /*#__PURE__*/ jsx("button", {
|
|
320
320
|
"aria-controls": id,
|
|
321
|
-
"aria-label":
|
|
321
|
+
"aria-label": "increment" === operation ? ariaIncrementLabel : ariaDecrementLabel,
|
|
322
322
|
"aria-live": "polite",
|
|
323
323
|
disabled: isDisabled,
|
|
324
324
|
type: "button",
|
|
@@ -351,11 +351,11 @@ function chain(...callbacks) {
|
|
|
351
351
|
function getNumberFormatSeparators(locale) {
|
|
352
352
|
const numberFormat = new Intl.NumberFormat(locale);
|
|
353
353
|
const parts = numberFormat.formatToParts(12345.6);
|
|
354
|
-
let thousandSeparator =
|
|
355
|
-
let decimalSeparator =
|
|
354
|
+
let thousandSeparator = "";
|
|
355
|
+
let decimalSeparator = "";
|
|
356
356
|
for (const part of parts){
|
|
357
|
-
if (
|
|
358
|
-
if (
|
|
357
|
+
if ("group" === part.type) thousandSeparator = part.value;
|
|
358
|
+
if ("decimal" === part.type) decimalSeparator = part.value;
|
|
359
359
|
if (thousandSeparator && decimalSeparator) break;
|
|
360
360
|
}
|
|
361
361
|
return {
|
|
@@ -364,13 +364,13 @@ function getNumberFormatSeparators(locale) {
|
|
|
364
364
|
};
|
|
365
365
|
}
|
|
366
366
|
function normalizeInputValue(value, thousandSeparator, decimalSeparator) {
|
|
367
|
-
return value.replaceAll(new RegExp(`\\${thousandSeparator}`,
|
|
367
|
+
return value.replaceAll(new RegExp(`\\${thousandSeparator}`, "g"), "").replace(new RegExp(`\\${decimalSeparator}`), ".").replaceAll(/[()]/g, "-");
|
|
368
368
|
}
|
|
369
369
|
function isModifierKey(event) {
|
|
370
370
|
return event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
371
371
|
}
|
|
372
372
|
function isFunctionKey(key) {
|
|
373
|
-
return key.startsWith(
|
|
373
|
+
return key.startsWith("F") && key.length > 1;
|
|
374
374
|
}
|
|
375
375
|
function isNumberKey(key) {
|
|
376
376
|
return !Number.isNaN(Number(key));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Scope } from
|
|
2
|
-
import type { ComponentProps, JSX, PropsWithChildren, ReactNode } from
|
|
1
|
+
import type { Scope } from "@radix-ui/react-context";
|
|
2
|
+
import type { ComponentProps, JSX, PropsWithChildren, ReactNode } from "react";
|
|
3
3
|
/**
|
|
4
4
|
* Type for adding scope to component props
|
|
5
5
|
*/
|
|
@@ -42,7 +42,7 @@ interface InputBehaviorProps {
|
|
|
42
42
|
/**
|
|
43
43
|
* Position of the loading spinner - either before or after the input
|
|
44
44
|
*/
|
|
45
|
-
loaderPosition?:
|
|
45
|
+
loaderPosition?: "prefix" | "suffix";
|
|
46
46
|
/**
|
|
47
47
|
* Whether the input is in the loading state
|
|
48
48
|
*/
|
|
@@ -60,7 +60,7 @@ declare function Input(inputProps: ScopedProps<InputProps>): JSX.Element;
|
|
|
60
60
|
/**
|
|
61
61
|
* Props for the InputField component
|
|
62
62
|
*/
|
|
63
|
-
type InputFieldProps = ComponentProps<
|
|
63
|
+
type InputFieldProps = ComponentProps<"input">;
|
|
64
64
|
declare function InputField({ __scopeInput, ...props }: ScopedProps<InputFieldProps>): JSX.Element;
|
|
65
65
|
export { createInputScope, InputField as Field, Input, InputField, Input as Root };
|
|
66
66
|
export type { InputFieldProps, InputProps };
|
package/dist/primitives/input.js
CHANGED
|
@@ -2,20 +2,20 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
3
3
|
import { createContextScope } from "@radix-ui/react-context";
|
|
4
4
|
import { useRef } from "react";
|
|
5
|
-
const INPUT_NAME =
|
|
5
|
+
const INPUT_NAME = "Input";
|
|
6
6
|
const [createInputContext, createInputScope] = createContextScope(INPUT_NAME);
|
|
7
7
|
const [InputContextProvider, useInputContext] = createInputContext(INPUT_NAME);
|
|
8
8
|
function Input(inputProps) {
|
|
9
|
-
const { __scopeInput, children, disabled, loaderPosition =
|
|
9
|
+
const { __scopeInput, children, disabled, loaderPosition = "prefix", loading, prefix, readOnly, spinner, suffix, ...props } = inputProps;
|
|
10
10
|
const inputRef = useRef(null);
|
|
11
11
|
const handlePointerDown = (event)=>{
|
|
12
12
|
const target = event.target;
|
|
13
|
-
if (
|
|
13
|
+
if ("input" === target.tagName.toLowerCase() || target.closest("input, a, button")) return void event.stopPropagation();
|
|
14
14
|
const inputElement = inputRef.current;
|
|
15
15
|
if (!inputElement) return;
|
|
16
16
|
if (document.activeElement === inputElement) return void event.preventDefault();
|
|
17
17
|
requestAnimationFrame(()=>{
|
|
18
|
-
if (
|
|
18
|
+
if ("file" === inputElement.type) return void inputElement.click();
|
|
19
19
|
if (document.activeElement !== inputElement) inputElement.focus();
|
|
20
20
|
});
|
|
21
21
|
};
|
|
@@ -31,14 +31,14 @@ function Input(inputProps) {
|
|
|
31
31
|
onPointerDown: handlePointerDown,
|
|
32
32
|
...props,
|
|
33
33
|
children: [
|
|
34
|
-
loading &&
|
|
34
|
+
loading && "prefix" === loaderPosition ? spinner : prefix,
|
|
35
35
|
children,
|
|
36
|
-
loading &&
|
|
36
|
+
loading && "suffix" === loaderPosition ? spinner : suffix
|
|
37
37
|
]
|
|
38
38
|
})
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
-
const INPUT_FIELD_NAME =
|
|
41
|
+
const INPUT_FIELD_NAME = "InputField";
|
|
42
42
|
function InputField({ __scopeInput, ...props }) {
|
|
43
43
|
const { disabled, inputRef, readOnly } = useInputContext(INPUT_FIELD_NAME, __scopeInput);
|
|
44
44
|
const composedInputRef = useComposedRefs(inputRef);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Scope } from
|
|
2
|
-
import type { ComponentProps, ReactNode } from
|
|
1
|
+
import type { Scope } from "@radix-ui/react-context";
|
|
2
|
+
import type { ComponentProps, ReactNode } from "react";
|
|
3
3
|
type ScopedProps<P> = P & {
|
|
4
4
|
__scopeProgressCircle?: Scope;
|
|
5
5
|
};
|
|
@@ -71,35 +71,35 @@ interface ProgressCircleProviderProps {
|
|
|
71
71
|
* ```
|
|
72
72
|
*/
|
|
73
73
|
declare function ProgressCircleProvider({ __scopeProgressCircle, children, formatValue, id: propertyId, max, min, size, startAngle, strokeWidth, thresholds, value, }: ScopedProps<ProgressCircleProviderProps>): ReactNode;
|
|
74
|
-
type ProgressCircleProps = ComponentProps<
|
|
74
|
+
type ProgressCircleProps = ComponentProps<"div">;
|
|
75
75
|
/**
|
|
76
76
|
* Root component for the progress circle
|
|
77
77
|
*
|
|
78
78
|
* Serves as a wrapper for other progress circle components.
|
|
79
79
|
*/
|
|
80
80
|
declare function ProgressCircle({ __scopeProgressCircle, ...props }: ScopedProps<ProgressCircleProps>): ReactNode;
|
|
81
|
-
type ProgressCircleSVGProps = ComponentProps<
|
|
81
|
+
type ProgressCircleSVGProps = ComponentProps<"svg">;
|
|
82
82
|
/**
|
|
83
83
|
* SVG container for the progress circle
|
|
84
84
|
*
|
|
85
85
|
* Renders the SVG with accessibility attributes and supports indeterminate state.
|
|
86
86
|
*/
|
|
87
87
|
declare function ProgressCircleSVG({ __scopeProgressCircle, ...props }: ScopedProps<ProgressCircleSVGProps>): ReactNode;
|
|
88
|
-
type ProgressCircleTrackProps = ComponentProps<
|
|
88
|
+
type ProgressCircleTrackProps = ComponentProps<"circle">;
|
|
89
89
|
/**
|
|
90
90
|
* Background circle for the progress indicator
|
|
91
91
|
*
|
|
92
92
|
* Renders the static track of the progress circle.
|
|
93
93
|
*/
|
|
94
94
|
declare function ProgressCircleTrack({ __scopeProgressCircle, ...props }: ScopedProps<ProgressCircleTrackProps>): ReactNode;
|
|
95
|
-
type ProgressCircleIndicatorProps = ComponentProps<
|
|
95
|
+
type ProgressCircleIndicatorProps = ComponentProps<"circle">;
|
|
96
96
|
/**
|
|
97
97
|
* Foreground circle showing progress
|
|
98
98
|
*
|
|
99
99
|
* Renders the dynamic progress indicator with stroke dash properties.
|
|
100
100
|
*/
|
|
101
101
|
declare function ProgressCircleIndicator({ __scopeProgressCircle, ...props }: ScopedProps<ProgressCircleIndicatorProps>): ReactNode;
|
|
102
|
-
interface ProgressCircleValueProps extends Omit<ComponentProps<
|
|
102
|
+
interface ProgressCircleValueProps extends Omit<ComponentProps<"div">, "children"> {
|
|
103
103
|
children?: ((context: {
|
|
104
104
|
value: number | undefined;
|
|
105
105
|
valueText: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createContextScope } from "@radix-ui/react-context";
|
|
4
4
|
import { useId, useMemo } from "react";
|
|
5
|
-
const PROGRESS_CIRCLE_PROVIDER_NAME =
|
|
5
|
+
const PROGRESS_CIRCLE_PROVIDER_NAME = "ProgressCircleProvider";
|
|
6
6
|
const [createProgressCircleContext, createProgressCircleScope] = createContextScope(PROGRESS_CIRCLE_PROVIDER_NAME);
|
|
7
7
|
const [ProgressCircleContextProvider, useProgressCircleContext] = createProgressCircleContext(PROGRESS_CIRCLE_PROVIDER_NAME);
|
|
8
8
|
function ProgressCircleProvider({ __scopeProgressCircle, children, formatValue, id: propertyId, max = 100, min = 0, size = 48, startAngle = -90, strokeWidth = 4, thresholds, value }) {
|
|
@@ -64,7 +64,7 @@ function ProgressCircle({ __scopeProgressCircle, ...props }) {
|
|
|
64
64
|
...props
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
const PROGRESS_CIRCLE_SVG_NAME =
|
|
67
|
+
const PROGRESS_CIRCLE_SVG_NAME = "ProgressCircleSVG";
|
|
68
68
|
function ProgressCircleSVG({ __scopeProgressCircle, ...props }) {
|
|
69
69
|
const { clampedValue, id, max, min, size, valueText } = useProgressCircleContext(PROGRESS_CIRCLE_SVG_NAME, __scopeProgressCircle);
|
|
70
70
|
return /*#__PURE__*/ jsx("svg", {
|
|
@@ -81,7 +81,7 @@ function ProgressCircleSVG({ __scopeProgressCircle, ...props }) {
|
|
|
81
81
|
...props
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
-
const PROGRESS_CIRCLE_TRACK_NAME =
|
|
84
|
+
const PROGRESS_CIRCLE_TRACK_NAME = "ProgressCircleTrack";
|
|
85
85
|
function ProgressCircleTrack({ __scopeProgressCircle, ...props }) {
|
|
86
86
|
const { center, radius, strokeWidth, threshold } = useProgressCircleContext(PROGRESS_CIRCLE_TRACK_NAME, __scopeProgressCircle);
|
|
87
87
|
return /*#__PURE__*/ jsx("circle", {
|
|
@@ -89,12 +89,12 @@ function ProgressCircleTrack({ __scopeProgressCircle, ...props }) {
|
|
|
89
89
|
cy: center,
|
|
90
90
|
fill: "transparent",
|
|
91
91
|
r: radius,
|
|
92
|
-
stroke: threshold?.background ??
|
|
92
|
+
stroke: threshold?.background ?? "currentColor",
|
|
93
93
|
strokeWidth: strokeWidth,
|
|
94
94
|
...props
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
const PROGRESS_CIRCLE_INDICATOR_NAME =
|
|
97
|
+
const PROGRESS_CIRCLE_INDICATOR_NAME = "ProgressCircleIndicator";
|
|
98
98
|
function ProgressCircleIndicator({ __scopeProgressCircle, ...props }) {
|
|
99
99
|
const { center, circumference, radius, rotationTransform, strokeDashoffset, strokeWidth, threshold } = useProgressCircleContext(PROGRESS_CIRCLE_INDICATOR_NAME, __scopeProgressCircle);
|
|
100
100
|
return /*#__PURE__*/ jsx("circle", {
|
|
@@ -102,7 +102,7 @@ function ProgressCircleIndicator({ __scopeProgressCircle, ...props }) {
|
|
|
102
102
|
cy: center,
|
|
103
103
|
fill: "transparent",
|
|
104
104
|
r: radius,
|
|
105
|
-
stroke: threshold?.color ??
|
|
105
|
+
stroke: threshold?.color ?? "currentColor",
|
|
106
106
|
strokeDasharray: circumference,
|
|
107
107
|
strokeDashoffset: strokeDashoffset,
|
|
108
108
|
strokeLinecap: "round",
|
|
@@ -111,10 +111,10 @@ function ProgressCircleIndicator({ __scopeProgressCircle, ...props }) {
|
|
|
111
111
|
...props
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
-
const PROGRESS_CIRCLE_VALUE_NAME =
|
|
114
|
+
const PROGRESS_CIRCLE_VALUE_NAME = "ProgressCircleValue";
|
|
115
115
|
function ProgressCircleValue({ __scopeProgressCircle, children, ...props }) {
|
|
116
116
|
const { clampedValue, valueText } = useProgressCircleContext(PROGRESS_CIRCLE_VALUE_NAME, __scopeProgressCircle);
|
|
117
|
-
if (
|
|
117
|
+
if ("function" == typeof children) return children({
|
|
118
118
|
value: clampedValue,
|
|
119
119
|
valueText
|
|
120
120
|
});
|