@codefast/ui 0.3.9 → 0.3.10
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 +11 -0
- package/dist/components/accordion.cjs +97 -1
- package/dist/components/accordion.d.ts +4 -4
- package/dist/components/accordion.js +51 -1
- package/dist/components/alert-dialog.cjs +155 -1
- package/dist/components/alert-dialog.d.ts +11 -11
- package/dist/components/alert-dialog.js +94 -1
- package/dist/components/alert.cjs +84 -1
- package/dist/components/alert.d.ts +5 -5
- package/dist/components/alert.js +41 -1
- package/dist/components/aspect-ratio.cjs +43 -1
- package/dist/components/aspect-ratio.d.ts +2 -2
- package/dist/components/aspect-ratio.js +9 -1
- package/dist/components/avatar.cjs +65 -1
- package/dist/components/avatar.d.ts +2 -2
- package/dist/components/avatar.js +25 -1
- package/dist/components/badge.cjs +66 -1
- package/dist/components/badge.d.ts +3 -3
- package/dist/components/badge.js +29 -1
- package/dist/components/breadcrumb.cjs +126 -1
- package/dist/components/breadcrumb.d.ts +8 -8
- package/dist/components/breadcrumb.js +74 -1
- package/dist/components/button-group.cjs +86 -1
- package/dist/components/button-group.d.ts +5 -5
- package/dist/components/button-group.js +43 -1
- package/dist/components/button.cjs +92 -1
- package/dist/components/button.d.ts +6 -6
- package/dist/components/button.js +55 -1
- package/dist/components/calendar.cjs +150 -1
- package/dist/components/calendar.d.ts +12 -19
- package/dist/components/calendar.js +113 -1
- package/dist/components/card.cjs +105 -1
- package/dist/components/card.d.ts +8 -8
- package/dist/components/card.js +53 -1
- package/dist/components/carousel.cjs +210 -1
- package/dist/components/carousel.d.ts +10 -10
- package/dist/components/carousel.js +151 -1
- package/dist/components/chart.cjs +250 -3
- package/dist/components/chart.d.ts +9 -9
- package/dist/components/chart.js +198 -3
- package/dist/components/checkbox-cards.cjs +69 -1
- package/dist/components/checkbox-cards.d.ts +2 -2
- package/dist/components/checkbox-cards.js +32 -1
- package/dist/components/checkbox-group.cjs +63 -1
- package/dist/components/checkbox-group.d.ts +2 -2
- package/dist/components/checkbox-group.js +26 -1
- package/dist/components/checkbox.cjs +53 -1
- package/dist/components/checkbox.d.ts +2 -2
- package/dist/components/checkbox.js +19 -1
- package/dist/components/collapsible.cjs +61 -1
- package/dist/components/collapsible.d.ts +2 -2
- package/dist/components/collapsible.js +21 -1
- package/dist/components/command.cjs +167 -1
- package/dist/components/command.d.ts +4 -4
- package/dist/components/command.js +106 -1
- package/dist/components/context-menu.cjs +218 -1
- package/dist/components/context-menu.d.ts +4 -4
- package/dist/components/context-menu.js +142 -1
- package/dist/components/dialog.cjs +164 -1
- package/dist/components/dialog.d.ts +10 -10
- package/dist/components/dialog.js +106 -1
- package/dist/components/drawer.cjs +143 -1
- package/dist/components/drawer.d.ts +9 -9
- package/dist/components/drawer.js +85 -1
- package/dist/components/dropdown-menu.cjs +221 -1
- package/dist/components/dropdown-menu.d.ts +4 -4
- package/dist/components/dropdown-menu.js +145 -1
- package/dist/components/empty.cjs +113 -1
- package/dist/components/empty.d.ts +9 -9
- package/dist/components/empty.js +61 -1
- package/dist/components/field.cjs +193 -1
- package/dist/components/field.d.ts +14 -14
- package/dist/components/field.js +129 -1
- package/dist/components/form.cjs +151 -1
- package/dist/components/form.d.ts +10 -10
- package/dist/components/form.js +96 -1
- package/dist/components/hover-card.cjs +77 -1
- package/dist/components/hover-card.d.ts +2 -2
- package/dist/components/hover-card.js +34 -1
- package/dist/components/input-group.cjs +155 -1
- package/dist/components/input-group.d.ts +15 -15
- package/dist/components/input-group.js +97 -1
- package/dist/components/input-number.cjs +98 -1
- package/dist/components/input-number.d.ts +2 -2
- package/dist/components/input-number.js +64 -1
- package/dist/components/input-otp.cjs +101 -1
- package/dist/components/input-otp.d.ts +6 -6
- package/dist/components/input-otp.js +49 -1
- package/dist/components/input-password.cjs +71 -1
- package/dist/components/input-password.d.ts +3 -3
- package/dist/components/input-password.js +37 -1
- package/dist/components/input-search.cjs +80 -1
- package/dist/components/input-search.d.ts +3 -3
- package/dist/components/input-search.js +46 -1
- package/dist/components/input.cjs +45 -1
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +11 -1
- package/dist/components/item.cjs +186 -1
- package/dist/components/item.d.ts +12 -12
- package/dist/components/item.js +119 -1
- package/dist/components/kbd.cjs +54 -1
- package/dist/components/kbd.d.ts +3 -3
- package/dist/components/kbd.js +17 -1
- package/dist/components/label.cjs +45 -1
- package/dist/components/label.d.ts +2 -2
- package/dist/components/label.js +11 -1
- package/dist/components/menubar.cjs +232 -1
- package/dist/components/menubar.d.ts +4 -4
- package/dist/components/menubar.js +153 -1
- package/dist/components/native-select.cjs +75 -1
- package/dist/components/native-select.d.ts +4 -4
- package/dist/components/native-select.js +35 -1
- package/dist/components/navigation-menu.cjs +146 -2
- package/dist/components/navigation-menu.d.ts +2 -2
- package/dist/components/navigation-menu.js +94 -2
- package/dist/components/pagination.cjs +138 -1
- package/dist/components/pagination.d.ts +10 -10
- package/dist/components/pagination.js +86 -1
- package/dist/components/popover.cjs +86 -1
- package/dist/components/popover.d.ts +3 -3
- package/dist/components/popover.js +40 -1
- package/dist/components/progress-circle.cjs +184 -1
- package/dist/components/progress-circle.d.ts +5 -5
- package/dist/components/progress-circle.js +147 -1
- package/dist/components/progress.cjs +52 -1
- package/dist/components/progress.d.ts +2 -2
- package/dist/components/progress.js +18 -1
- package/dist/components/radio-cards.cjs +66 -1
- package/dist/components/radio-cards.d.ts +2 -2
- package/dist/components/radio-cards.js +29 -1
- package/dist/components/radio-group.cjs +59 -1
- package/dist/components/radio-group.d.ts +2 -2
- package/dist/components/radio-group.js +22 -1
- package/dist/components/radio.cjs +47 -1
- package/dist/components/radio.d.ts +2 -2
- package/dist/components/radio.js +13 -1
- package/dist/components/resizable.cjs +71 -1
- package/dist/components/resizable.d.ts +8 -8
- package/dist/components/resizable.js +31 -1
- package/dist/components/scroll-area.cjs +140 -1
- package/dist/components/scroll-area.d.ts +5 -5
- package/dist/components/scroll-area.js +100 -1
- package/dist/components/select.cjs +180 -1
- package/dist/components/select.d.ts +5 -5
- package/dist/components/select.js +119 -1
- package/dist/components/separator.cjs +82 -1
- package/dist/components/separator.d.ts +5 -5
- package/dist/components/separator.js +42 -1
- package/dist/components/sheet.cjs +184 -1
- package/dist/components/sheet.d.ts +9 -9
- package/dist/components/sheet.js +123 -1
- package/dist/components/sidebar.cjs +506 -1
- package/dist/components/sidebar.d.ts +31 -31
- package/dist/components/sidebar.js +400 -1
- package/dist/components/skeleton.cjs +44 -1
- package/dist/components/skeleton.d.ts +2 -2
- package/dist/components/skeleton.js +10 -1
- package/dist/components/slider.cjs +79 -1
- package/dist/components/slider.d.ts +2 -2
- package/dist/components/slider.js +45 -1
- package/dist/components/sonner.cjs +57 -1
- package/dist/components/sonner.d.ts +3 -3
- package/dist/components/sonner.js +17 -1
- package/dist/components/spinner.cjs +75 -1
- package/dist/components/spinner.d.ts +2 -2
- package/dist/components/spinner.js +41 -1
- package/dist/components/switch.cjs +49 -1
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +15 -1
- package/dist/components/table.cjs +118 -1
- package/dist/components/table.d.ts +9 -9
- package/dist/components/table.js +63 -1
- package/dist/components/tabs.cjs +75 -1
- package/dist/components/tabs.d.ts +3 -3
- package/dist/components/tabs.js +32 -1
- package/dist/components/textarea.cjs +44 -1
- package/dist/components/textarea.d.ts +2 -2
- package/dist/components/textarea.js +10 -1
- package/dist/components/toggle-group.cjs +90 -1
- package/dist/components/toggle-group.d.ts +10 -12
- package/dist/components/toggle-group.js +53 -1
- package/dist/components/toggle.cjs +71 -1
- package/dist/components/toggle.d.ts +10 -12
- package/dist/components/toggle.js +34 -1
- package/dist/components/tooltip.cjs +90 -1
- package/dist/components/tooltip.d.ts +3 -3
- package/dist/components/tooltip.js +44 -1
- package/dist/css/amber.css +95 -1
- package/dist/css/blue.css +95 -1
- package/dist/css/cyan.css +95 -1
- package/dist/css/emerald.css +95 -1
- package/dist/css/fuchsia.css +95 -1
- package/dist/css/gray.css +95 -1
- package/dist/css/green.css +95 -1
- package/dist/css/indigo.css +95 -1
- package/dist/css/lime.css +95 -1
- package/dist/css/neutral.css +95 -1
- package/dist/css/orange.css +95 -1
- package/dist/css/pink.css +95 -1
- package/dist/css/preset.css +118 -1
- package/dist/css/purple.css +95 -1
- package/dist/css/red.css +95 -1
- package/dist/css/rose.css +95 -1
- package/dist/css/sky.css +95 -1
- package/dist/css/slate.css +95 -1
- package/dist/css/stone.css +95 -1
- package/dist/css/style.css +3 -1
- package/dist/css/teal.css +95 -1
- package/dist/css/violet.css +95 -1
- package/dist/css/yellow.css +95 -1
- package/dist/css/zinc.css +95 -1
- package/dist/hooks/use-animated-value.cjs +74 -1
- package/dist/hooks/use-animated-value.d.ts +9 -10
- package/dist/hooks/use-animated-value.js +40 -1
- package/dist/hooks/use-copy-to-clipboard.cjs +57 -1
- package/dist/hooks/use-copy-to-clipboard.d.ts +18 -1
- package/dist/hooks/use-copy-to-clipboard.js +23 -1
- package/dist/hooks/use-is-mobile.cjs +39 -1
- package/dist/hooks/use-is-mobile.d.ts +15 -6
- package/dist/hooks/use-is-mobile.js +5 -1
- package/dist/hooks/use-media-query.cjs +56 -1
- package/dist/hooks/use-media-query.d.ts +11 -3
- package/dist/hooks/use-media-query.js +22 -1
- package/dist/hooks/use-mutation-observer.cjs +56 -1
- package/dist/hooks/use-mutation-observer.d.ts +8 -12
- package/dist/hooks/use-mutation-observer.js +22 -1
- package/dist/hooks/use-pagination.cjs +92 -1
- package/dist/hooks/use-pagination.d.ts +12 -10
- package/dist/hooks/use-pagination.js +55 -1
- package/dist/index.cjs +1081 -1
- package/dist/index.d.ts +130 -131
- package/dist/index.js +69 -1
- package/dist/primitives/checkbox-group.cjs +151 -1
- package/dist/primitives/checkbox-group.d.ts +11 -11
- package/dist/primitives/checkbox-group.js +99 -1
- package/dist/primitives/input-number.cjs +439 -1
- package/dist/primitives/input-number.d.ts +8 -8
- package/dist/primitives/input-number.js +381 -1
- package/dist/primitives/input.cjs +99 -1
- package/dist/primitives/input.d.ts +4 -4
- package/dist/primitives/input.js +53 -1
- package/dist/primitives/progress-circle.cjs +198 -1
- package/dist/primitives/progress-circle.d.ts +7 -7
- package/dist/primitives/progress-circle.js +128 -1
- package/package.json +385 -38
|
@@ -1 +1,381 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
3
|
+
import { createContextScope } from "@radix-ui/react-context";
|
|
4
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
5
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
6
|
+
import { Field, Root, createInputScope } from "./input.js";
|
|
7
|
+
const NUMBER_INPUT_NAME = 'InputNumber';
|
|
8
|
+
const [createInputNumberContext, createInputNumberScope] = createContextScope(NUMBER_INPUT_NAME, [
|
|
9
|
+
createInputScope
|
|
10
|
+
]);
|
|
11
|
+
const useInputScope = createInputScope();
|
|
12
|
+
const [InputNumberContextProvider, useInputNumberContext] = createInputNumberContext(NUMBER_INPUT_NAME);
|
|
13
|
+
function InputNumber(numberInputProps) {
|
|
14
|
+
const { __scopeInputNumber, ariaDecrementLabel, ariaIncrementLabel, defaultValue, formatOptions = {
|
|
15
|
+
minimumFractionDigits: 0,
|
|
16
|
+
style: 'decimal'
|
|
17
|
+
}, id, locale, max, min, onChange, step = 1, value: valueProperty, ...props } = numberInputProps;
|
|
18
|
+
const inputScope = useInputScope(__scopeInputNumber);
|
|
19
|
+
const inputRef = useRef(null);
|
|
20
|
+
const [value, setValue] = useControllableState({
|
|
21
|
+
defaultProp: defaultValue,
|
|
22
|
+
onChange,
|
|
23
|
+
prop: valueProperty
|
|
24
|
+
});
|
|
25
|
+
const { decimalSeparator, thousandSeparator } = useMemo(()=>getNumberFormatSeparators(locale), [
|
|
26
|
+
locale
|
|
27
|
+
]);
|
|
28
|
+
const formatValue = useCallback((inputValue)=>{
|
|
29
|
+
if (void 0 === inputValue || Number.isNaN(inputValue)) return '';
|
|
30
|
+
return new Intl.NumberFormat(locale, formatOptions).format(inputValue);
|
|
31
|
+
}, [
|
|
32
|
+
formatOptions,
|
|
33
|
+
locale
|
|
34
|
+
]);
|
|
35
|
+
const parseValue = useCallback((inputValue)=>{
|
|
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
|
+
const normalizedValue = normalizeInputValue(cleanedValue, thousandSeparator, decimalSeparator);
|
|
41
|
+
let parsedValue = Number.parseFloat(normalizedValue);
|
|
42
|
+
if ('percent' === formatOptions.style) parsedValue /= 100;
|
|
43
|
+
return Number.isNaN(parsedValue) ? 0 : clamp(parsedValue, min, max);
|
|
44
|
+
}, [
|
|
45
|
+
decimalSeparator,
|
|
46
|
+
formatOptions.style,
|
|
47
|
+
max,
|
|
48
|
+
min,
|
|
49
|
+
thousandSeparator
|
|
50
|
+
]);
|
|
51
|
+
const changeNumberValue = useCallback((operation)=>{
|
|
52
|
+
const inputElement = inputRef.current;
|
|
53
|
+
if (!inputElement || props.disabled || props.readOnly) return;
|
|
54
|
+
const currentValue = parseValue(inputElement.value) || 0;
|
|
55
|
+
const newValue = clamp(operation(currentValue), min, max);
|
|
56
|
+
inputElement.value = formatValue(newValue);
|
|
57
|
+
setValue(newValue);
|
|
58
|
+
}, [
|
|
59
|
+
props.disabled,
|
|
60
|
+
formatValue,
|
|
61
|
+
max,
|
|
62
|
+
min,
|
|
63
|
+
parseValue,
|
|
64
|
+
props.readOnly,
|
|
65
|
+
setValue
|
|
66
|
+
]);
|
|
67
|
+
const handleIncrement = useCallback(()=>{
|
|
68
|
+
changeNumberValue((number)=>number + step);
|
|
69
|
+
}, [
|
|
70
|
+
changeNumberValue,
|
|
71
|
+
step
|
|
72
|
+
]);
|
|
73
|
+
const handleDecrement = useCallback(()=>{
|
|
74
|
+
changeNumberValue((number)=>number - step);
|
|
75
|
+
}, [
|
|
76
|
+
changeNumberValue,
|
|
77
|
+
step
|
|
78
|
+
]);
|
|
79
|
+
const handleIncrementToMax = useCallback(()=>{
|
|
80
|
+
changeNumberValue((number)=>max ?? number + step);
|
|
81
|
+
}, [
|
|
82
|
+
changeNumberValue,
|
|
83
|
+
max,
|
|
84
|
+
step
|
|
85
|
+
]);
|
|
86
|
+
const handleDecrementToMin = useCallback(()=>{
|
|
87
|
+
changeNumberValue((number)=>min ?? number - step);
|
|
88
|
+
}, [
|
|
89
|
+
changeNumberValue,
|
|
90
|
+
min,
|
|
91
|
+
step
|
|
92
|
+
]);
|
|
93
|
+
return /*#__PURE__*/ jsx(InputNumberContextProvider, {
|
|
94
|
+
ariaDecrementLabel: ariaDecrementLabel,
|
|
95
|
+
ariaIncrementLabel: ariaIncrementLabel,
|
|
96
|
+
defaultValue: defaultValue,
|
|
97
|
+
disabled: props.disabled,
|
|
98
|
+
formatOptions: formatOptions,
|
|
99
|
+
formatValue: formatValue,
|
|
100
|
+
id: id,
|
|
101
|
+
inputRef: inputRef,
|
|
102
|
+
max: max,
|
|
103
|
+
min: min,
|
|
104
|
+
parseValue: parseValue,
|
|
105
|
+
readOnly: props.readOnly,
|
|
106
|
+
scope: __scopeInputNumber,
|
|
107
|
+
value: value,
|
|
108
|
+
onChange: setValue,
|
|
109
|
+
onDecrement: handleDecrement,
|
|
110
|
+
onDecrementToMin: handleDecrementToMin,
|
|
111
|
+
onIncrement: handleIncrement,
|
|
112
|
+
onIncrementToMax: handleIncrementToMax,
|
|
113
|
+
children: /*#__PURE__*/ jsx(Root, {
|
|
114
|
+
...inputScope,
|
|
115
|
+
...props
|
|
116
|
+
})
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const NUMBER_INPUT_FIELD_NAME = 'InputNumberField';
|
|
120
|
+
function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }) {
|
|
121
|
+
const inputScope = useInputScope(__scopeInputNumber);
|
|
122
|
+
const { defaultValue, disabled, formatValue, id, inputRef, max, min, onChange, onDecrement, onDecrementToMin, onIncrement, onIncrementToMax, parseValue, readOnly, step, value } = useInputNumberContext(NUMBER_INPUT_FIELD_NAME, __scopeInputNumber);
|
|
123
|
+
const handleBlur = useCallback((event)=>{
|
|
124
|
+
const numericValue = parseValue(event.target.value);
|
|
125
|
+
const formattedValue = formatValue(numericValue);
|
|
126
|
+
if (formattedValue !== event.target.value) event.target.value = formattedValue;
|
|
127
|
+
onChange(numericValue);
|
|
128
|
+
}, [
|
|
129
|
+
formatValue,
|
|
130
|
+
onChange,
|
|
131
|
+
parseValue
|
|
132
|
+
]);
|
|
133
|
+
const handleKeyDown = useCallback((event)=>{
|
|
134
|
+
switch(event.key){
|
|
135
|
+
case 'ArrowUp':
|
|
136
|
+
onIncrement();
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
break;
|
|
139
|
+
case 'PageUp':
|
|
140
|
+
onIncrementToMax();
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
break;
|
|
143
|
+
case 'ArrowDown':
|
|
144
|
+
onDecrement();
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
break;
|
|
147
|
+
case 'PageDown':
|
|
148
|
+
onDecrementToMin();
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
break;
|
|
151
|
+
default:
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}, [
|
|
155
|
+
onIncrement,
|
|
156
|
+
onIncrementToMax,
|
|
157
|
+
onDecrement,
|
|
158
|
+
onDecrementToMin
|
|
159
|
+
]);
|
|
160
|
+
const handleKeyDownPrevent = useCallback((event)=>{
|
|
161
|
+
switch(event.key){
|
|
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
|
+
return;
|
|
180
|
+
default:
|
|
181
|
+
if (isNumberKey(event.key) || isModifierKey(event) || isFunctionKey(event.key)) return;
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
}
|
|
184
|
+
}, []);
|
|
185
|
+
const handleKeyDownEnter = useCallback((event)=>{
|
|
186
|
+
const inputElement = inputRef.current;
|
|
187
|
+
if ('Enter' !== event.key || !inputElement) return;
|
|
188
|
+
const numericValue = parseValue(inputElement.value);
|
|
189
|
+
const formattedValue = formatValue(numericValue);
|
|
190
|
+
if (formattedValue !== inputElement.value) inputElement.value = formattedValue;
|
|
191
|
+
onChange(numericValue);
|
|
192
|
+
}, [
|
|
193
|
+
formatValue,
|
|
194
|
+
inputRef,
|
|
195
|
+
onChange,
|
|
196
|
+
parseValue
|
|
197
|
+
]);
|
|
198
|
+
const combinedKeyDownHandler = useCallback((event)=>{
|
|
199
|
+
composeEventHandlers(onKeyDown, chain(handleKeyDownPrevent, handleKeyDown, handleKeyDownEnter))(event);
|
|
200
|
+
}, [
|
|
201
|
+
onKeyDown,
|
|
202
|
+
handleKeyDown,
|
|
203
|
+
handleKeyDownEnter,
|
|
204
|
+
handleKeyDownPrevent
|
|
205
|
+
]);
|
|
206
|
+
useEffect(()=>{
|
|
207
|
+
const handleWheel = (event)=>{
|
|
208
|
+
const inputElement = inputRef.current;
|
|
209
|
+
if (!inputElement || disabled || readOnly || document.activeElement !== inputElement) return;
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
if (event.deltaY > 0) onIncrement();
|
|
212
|
+
else onDecrement();
|
|
213
|
+
};
|
|
214
|
+
const inputElement = inputRef.current;
|
|
215
|
+
inputElement?.addEventListener('wheel', handleWheel);
|
|
216
|
+
return ()=>{
|
|
217
|
+
inputElement?.removeEventListener('wheel', handleWheel);
|
|
218
|
+
};
|
|
219
|
+
}, [
|
|
220
|
+
onIncrement,
|
|
221
|
+
onDecrement,
|
|
222
|
+
inputRef,
|
|
223
|
+
disabled,
|
|
224
|
+
readOnly
|
|
225
|
+
]);
|
|
226
|
+
useEffect(()=>{
|
|
227
|
+
const inputElement = inputRef.current;
|
|
228
|
+
if (inputElement && inputElement !== document.activeElement) inputElement.value = formatValue(value);
|
|
229
|
+
}, [
|
|
230
|
+
formatValue,
|
|
231
|
+
inputRef,
|
|
232
|
+
value
|
|
233
|
+
]);
|
|
234
|
+
useEffect(()=>{
|
|
235
|
+
const inputElement = inputRef.current;
|
|
236
|
+
if (!inputElement) return;
|
|
237
|
+
const handleReset = ()=>{
|
|
238
|
+
onChange(parseValue(defaultValue));
|
|
239
|
+
};
|
|
240
|
+
const form = inputElement.form;
|
|
241
|
+
form?.addEventListener('reset', handleReset);
|
|
242
|
+
return ()=>{
|
|
243
|
+
form?.removeEventListener('reset', handleReset);
|
|
244
|
+
};
|
|
245
|
+
}, [
|
|
246
|
+
defaultValue,
|
|
247
|
+
inputRef,
|
|
248
|
+
onChange,
|
|
249
|
+
parseValue
|
|
250
|
+
]);
|
|
251
|
+
return /*#__PURE__*/ jsx(Field, {
|
|
252
|
+
ref: inputRef,
|
|
253
|
+
defaultValue: formatValue(value),
|
|
254
|
+
disabled: disabled,
|
|
255
|
+
id: id,
|
|
256
|
+
inputMode: "decimal",
|
|
257
|
+
max: max,
|
|
258
|
+
min: min,
|
|
259
|
+
readOnly: readOnly,
|
|
260
|
+
step: step,
|
|
261
|
+
onBlur: composeEventHandlers(onBlur, handleBlur),
|
|
262
|
+
onKeyDown: combinedKeyDownHandler,
|
|
263
|
+
...inputScope,
|
|
264
|
+
...props
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const NUMBER_STEPPER_BUTTON_NAME = 'NumberStepperButton';
|
|
268
|
+
function NumberStepperButton({ __scopeInputNumber, operation, ...props }) {
|
|
269
|
+
const { ariaDecrementLabel, ariaIncrementLabel, disabled, id, max, min, onDecrement, onIncrement, value } = useInputNumberContext(NUMBER_STEPPER_BUTTON_NAME, __scopeInputNumber);
|
|
270
|
+
const isDisabled = useMemo(()=>{
|
|
271
|
+
const atMin = void 0 !== min && void 0 !== value && value <= min;
|
|
272
|
+
const atMax = void 0 !== max && void 0 !== value && value >= max;
|
|
273
|
+
return (disabled ?? atMin) || atMax;
|
|
274
|
+
}, [
|
|
275
|
+
min,
|
|
276
|
+
max,
|
|
277
|
+
value,
|
|
278
|
+
disabled
|
|
279
|
+
]);
|
|
280
|
+
const timeoutIdRef = useRef(null);
|
|
281
|
+
const startActionInterval = useCallback((callback)=>{
|
|
282
|
+
const interval = 100;
|
|
283
|
+
const repeatAction = ()=>{
|
|
284
|
+
callback();
|
|
285
|
+
timeoutIdRef.current = setTimeout(repeatAction, interval);
|
|
286
|
+
};
|
|
287
|
+
callback();
|
|
288
|
+
timeoutIdRef.current = setTimeout(repeatAction, 2 * interval);
|
|
289
|
+
}, []);
|
|
290
|
+
const clearActionInterval = useCallback(()=>{
|
|
291
|
+
if (timeoutIdRef.current) {
|
|
292
|
+
clearTimeout(timeoutIdRef.current);
|
|
293
|
+
timeoutIdRef.current = null;
|
|
294
|
+
}
|
|
295
|
+
}, []);
|
|
296
|
+
const handlePointerDown = useCallback(()=>{
|
|
297
|
+
const action = 'increment' === operation ? onIncrement : onDecrement;
|
|
298
|
+
startActionInterval(action);
|
|
299
|
+
}, [
|
|
300
|
+
onDecrement,
|
|
301
|
+
onIncrement,
|
|
302
|
+
operation,
|
|
303
|
+
startActionInterval
|
|
304
|
+
]);
|
|
305
|
+
const handleContextMenu = useCallback((event)=>{
|
|
306
|
+
event.preventDefault();
|
|
307
|
+
}, []);
|
|
308
|
+
const handleKeyDown = useCallback((event)=>{
|
|
309
|
+
if ('Enter' === event.key || ' ' === event.key) {
|
|
310
|
+
event.preventDefault();
|
|
311
|
+
const action = 'increment' === operation ? onIncrement : onDecrement;
|
|
312
|
+
action();
|
|
313
|
+
}
|
|
314
|
+
}, [
|
|
315
|
+
onDecrement,
|
|
316
|
+
onIncrement,
|
|
317
|
+
operation
|
|
318
|
+
]);
|
|
319
|
+
return /*#__PURE__*/ jsx("button", {
|
|
320
|
+
"aria-controls": id,
|
|
321
|
+
"aria-label": 'increment' === operation ? ariaIncrementLabel : ariaDecrementLabel,
|
|
322
|
+
"aria-live": "polite",
|
|
323
|
+
disabled: isDisabled,
|
|
324
|
+
type: "button",
|
|
325
|
+
onContextMenu: handleContextMenu,
|
|
326
|
+
onKeyDown: handleKeyDown,
|
|
327
|
+
onPointerCancel: clearActionInterval,
|
|
328
|
+
onPointerDown: handlePointerDown,
|
|
329
|
+
onPointerLeave: clearActionInterval,
|
|
330
|
+
onPointerUp: clearActionInterval,
|
|
331
|
+
...props
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
function InputNumberIncrementButton(props) {
|
|
335
|
+
return /*#__PURE__*/ jsx(NumberStepperButton, {
|
|
336
|
+
operation: "increment",
|
|
337
|
+
...props
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
function InputNumberDecrementButton(props) {
|
|
341
|
+
return /*#__PURE__*/ jsx(NumberStepperButton, {
|
|
342
|
+
operation: "decrement",
|
|
343
|
+
...props
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function chain(...callbacks) {
|
|
347
|
+
return (...args)=>{
|
|
348
|
+
for (const callback of callbacks)callback(...args);
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function getNumberFormatSeparators(locale) {
|
|
352
|
+
const numberFormat = new Intl.NumberFormat(locale);
|
|
353
|
+
const parts = numberFormat.formatToParts(12345.6);
|
|
354
|
+
let thousandSeparator = '';
|
|
355
|
+
let decimalSeparator = '';
|
|
356
|
+
for (const part of parts){
|
|
357
|
+
if ('group' === part.type) thousandSeparator = part.value;
|
|
358
|
+
if ('decimal' === part.type) decimalSeparator = part.value;
|
|
359
|
+
if (thousandSeparator && decimalSeparator) break;
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
decimalSeparator,
|
|
363
|
+
thousandSeparator
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function normalizeInputValue(value, thousandSeparator, decimalSeparator) {
|
|
367
|
+
return value.replaceAll(new RegExp(`\\${thousandSeparator}`, 'g'), '').replace(new RegExp(`\\${decimalSeparator}`), '.').replaceAll(/[()]/g, '-');
|
|
368
|
+
}
|
|
369
|
+
function isModifierKey(event) {
|
|
370
|
+
return event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
|
|
371
|
+
}
|
|
372
|
+
function isFunctionKey(key) {
|
|
373
|
+
return key.startsWith('F') && key.length > 1;
|
|
374
|
+
}
|
|
375
|
+
function isNumberKey(key) {
|
|
376
|
+
return !Number.isNaN(Number(key));
|
|
377
|
+
}
|
|
378
|
+
function clamp(value, min = -1 / 0, max = 1 / 0) {
|
|
379
|
+
return Math.min(Math.max(value, min), max);
|
|
380
|
+
}
|
|
381
|
+
export { InputNumberDecrementButton as DecrementButton, InputNumberField as Field, InputNumberIncrementButton as IncrementButton, InputNumber, InputNumberDecrementButton, InputNumberField, InputNumberIncrementButton, InputNumber as Root, createInputNumberScope };
|
|
@@ -1 +1,99 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
InputField: ()=>InputField,
|
|
28
|
+
Input: ()=>Input,
|
|
29
|
+
Field: ()=>InputField,
|
|
30
|
+
createInputScope: ()=>createInputScope,
|
|
31
|
+
Root: ()=>Input
|
|
32
|
+
});
|
|
33
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
34
|
+
const react_compose_refs_namespaceObject = require("@radix-ui/react-compose-refs");
|
|
35
|
+
const react_context_namespaceObject = require("@radix-ui/react-context");
|
|
36
|
+
const external_react_namespaceObject = require("react");
|
|
37
|
+
const INPUT_NAME = 'Input';
|
|
38
|
+
const [createInputContext, createInputScope] = (0, react_context_namespaceObject.createContextScope)(INPUT_NAME);
|
|
39
|
+
const [InputContextProvider, useInputContext] = createInputContext(INPUT_NAME);
|
|
40
|
+
function Input(inputProps) {
|
|
41
|
+
const { __scopeInput, children, disabled, loaderPosition = 'prefix', loading, prefix, readOnly, spinner, suffix, ...props } = inputProps;
|
|
42
|
+
const inputRef = (0, external_react_namespaceObject.useRef)(null);
|
|
43
|
+
const handlePointerDown = (event)=>{
|
|
44
|
+
const target = event.target;
|
|
45
|
+
if ('input' === target.tagName.toLowerCase() || target.closest('input, a, button')) return void event.stopPropagation();
|
|
46
|
+
const inputElement = inputRef.current;
|
|
47
|
+
if (!inputElement) return;
|
|
48
|
+
if (document.activeElement === inputElement) return void event.preventDefault();
|
|
49
|
+
requestAnimationFrame(()=>{
|
|
50
|
+
if ('file' === inputElement.type) return void inputElement.click();
|
|
51
|
+
if (document.activeElement !== inputElement) inputElement.focus();
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(InputContextProvider, {
|
|
55
|
+
disabled: disabled,
|
|
56
|
+
inputRef: inputRef,
|
|
57
|
+
readOnly: readOnly,
|
|
58
|
+
scope: __scopeInput,
|
|
59
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
60
|
+
"data-disabled": disabled,
|
|
61
|
+
"data-readonly": readOnly,
|
|
62
|
+
role: "presentation",
|
|
63
|
+
onPointerDown: handlePointerDown,
|
|
64
|
+
...props,
|
|
65
|
+
children: [
|
|
66
|
+
loading && 'prefix' === loaderPosition ? spinner : prefix,
|
|
67
|
+
children,
|
|
68
|
+
loading && 'suffix' === loaderPosition ? spinner : suffix
|
|
69
|
+
]
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const INPUT_FIELD_NAME = 'InputField';
|
|
74
|
+
function InputField({ __scopeInput, ...props }) {
|
|
75
|
+
const { disabled, inputRef, readOnly } = useInputContext(INPUT_FIELD_NAME, __scopeInput);
|
|
76
|
+
const composedInputRef = (0, react_compose_refs_namespaceObject.useComposedRefs)(inputRef);
|
|
77
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("input", {
|
|
78
|
+
ref: composedInputRef,
|
|
79
|
+
disabled: disabled,
|
|
80
|
+
readOnly: readOnly,
|
|
81
|
+
type: "text",
|
|
82
|
+
...props
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
exports.Field = __webpack_exports__.Field;
|
|
86
|
+
exports.Input = __webpack_exports__.Input;
|
|
87
|
+
exports.InputField = __webpack_exports__.InputField;
|
|
88
|
+
exports.Root = __webpack_exports__.Root;
|
|
89
|
+
exports.createInputScope = __webpack_exports__.createInputScope;
|
|
90
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
91
|
+
"Field",
|
|
92
|
+
"Input",
|
|
93
|
+
"InputField",
|
|
94
|
+
"Root",
|
|
95
|
+
"createInputScope"
|
|
96
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
97
|
+
Object.defineProperty(exports, '__esModule', {
|
|
98
|
+
value: true
|
|
99
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
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
|
@@ -1 +1,53 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
3
|
+
import { createContextScope } from "@radix-ui/react-context";
|
|
4
|
+
import { useRef } from "react";
|
|
5
|
+
const INPUT_NAME = 'Input';
|
|
6
|
+
const [createInputContext, createInputScope] = createContextScope(INPUT_NAME);
|
|
7
|
+
const [InputContextProvider, useInputContext] = createInputContext(INPUT_NAME);
|
|
8
|
+
function Input(inputProps) {
|
|
9
|
+
const { __scopeInput, children, disabled, loaderPosition = 'prefix', loading, prefix, readOnly, spinner, suffix, ...props } = inputProps;
|
|
10
|
+
const inputRef = useRef(null);
|
|
11
|
+
const handlePointerDown = (event)=>{
|
|
12
|
+
const target = event.target;
|
|
13
|
+
if ('input' === target.tagName.toLowerCase() || target.closest('input, a, button')) return void event.stopPropagation();
|
|
14
|
+
const inputElement = inputRef.current;
|
|
15
|
+
if (!inputElement) return;
|
|
16
|
+
if (document.activeElement === inputElement) return void event.preventDefault();
|
|
17
|
+
requestAnimationFrame(()=>{
|
|
18
|
+
if ('file' === inputElement.type) return void inputElement.click();
|
|
19
|
+
if (document.activeElement !== inputElement) inputElement.focus();
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
return /*#__PURE__*/ jsx(InputContextProvider, {
|
|
23
|
+
disabled: disabled,
|
|
24
|
+
inputRef: inputRef,
|
|
25
|
+
readOnly: readOnly,
|
|
26
|
+
scope: __scopeInput,
|
|
27
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
28
|
+
"data-disabled": disabled,
|
|
29
|
+
"data-readonly": readOnly,
|
|
30
|
+
role: "presentation",
|
|
31
|
+
onPointerDown: handlePointerDown,
|
|
32
|
+
...props,
|
|
33
|
+
children: [
|
|
34
|
+
loading && 'prefix' === loaderPosition ? spinner : prefix,
|
|
35
|
+
children,
|
|
36
|
+
loading && 'suffix' === loaderPosition ? spinner : suffix
|
|
37
|
+
]
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const INPUT_FIELD_NAME = 'InputField';
|
|
42
|
+
function InputField({ __scopeInput, ...props }) {
|
|
43
|
+
const { disabled, inputRef, readOnly } = useInputContext(INPUT_FIELD_NAME, __scopeInput);
|
|
44
|
+
const composedInputRef = useComposedRefs(inputRef);
|
|
45
|
+
return /*#__PURE__*/ jsx("input", {
|
|
46
|
+
ref: composedInputRef,
|
|
47
|
+
disabled: disabled,
|
|
48
|
+
readOnly: readOnly,
|
|
49
|
+
type: "text",
|
|
50
|
+
...props
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export { InputField as Field, Input, InputField, Input as Root, createInputScope };
|