@luxfi/ui 6.1.2 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accordion.cjs +213 -0
- package/dist/accordion.d.cts +74 -0
- package/dist/accordion.d.ts +74 -0
- package/dist/accordion.js +186 -0
- package/dist/alert.cjs +553 -0
- package/dist/alert.d.cts +30 -0
- package/dist/alert.d.ts +30 -0
- package/dist/alert.js +531 -0
- package/dist/avatar.cjs +149 -0
- package/dist/avatar.d.cts +25 -0
- package/dist/avatar.d.ts +25 -0
- package/dist/avatar.js +125 -0
- package/dist/badge.cjs +611 -0
- package/dist/badge.d.cts +23 -0
- package/dist/badge.d.ts +23 -0
- package/dist/badge.js +589 -0
- package/dist/bank.cjs +272 -0
- package/dist/bank.d.cts +76 -0
- package/dist/bank.d.ts +76 -0
- package/dist/bank.js +258 -0
- package/dist/button.cjs +689 -0
- package/dist/button.d.cts +52 -0
- package/dist/button.d.ts +52 -0
- package/dist/button.js +664 -0
- package/dist/checkbox.cjs +265 -0
- package/dist/checkbox.d.cts +31 -0
- package/dist/checkbox.d.ts +31 -0
- package/dist/checkbox.js +241 -0
- package/dist/close-button.cjs +73 -0
- package/dist/close-button.d.cts +9 -0
- package/dist/close-button.d.ts +9 -0
- package/dist/close-button.js +51 -0
- package/dist/collapsible.cjs +702 -0
- package/dist/collapsible.d.cts +23 -0
- package/dist/collapsible.d.ts +23 -0
- package/dist/collapsible.js +679 -0
- package/dist/color-mode.cjs +96 -0
- package/dist/color-mode.d.cts +25 -0
- package/dist/color-mode.d.ts +25 -0
- package/dist/color-mode.js +72 -0
- package/dist/dialog.cjs +279 -0
- package/dist/dialog.d.cts +66 -0
- package/dist/dialog.d.ts +66 -0
- package/dist/dialog.js +246 -0
- package/dist/drawer.cjs +207 -0
- package/dist/drawer.d.cts +36 -0
- package/dist/drawer.d.ts +36 -0
- package/dist/drawer.js +175 -0
- package/dist/empty-state.cjs +93 -0
- package/dist/empty-state.d.cts +13 -0
- package/dist/empty-state.d.ts +13 -0
- package/dist/empty-state.js +71 -0
- package/dist/expiration-selector.cjs +138 -0
- package/dist/expiration-selector.d.cts +16 -0
- package/dist/expiration-selector.d.ts +16 -0
- package/dist/expiration-selector.js +116 -0
- package/dist/field.cjs +183 -0
- package/dist/field.d.cts +24 -0
- package/dist/field.d.ts +24 -0
- package/dist/field.js +160 -0
- package/dist/greeks-display.cjs +114 -0
- package/dist/greeks-display.d.cts +14 -0
- package/dist/greeks-display.d.ts +14 -0
- package/dist/greeks-display.js +92 -0
- package/dist/heading.cjs +46 -0
- package/dist/heading.d.cts +10 -0
- package/dist/heading.d.ts +10 -0
- package/dist/heading.js +40 -0
- package/dist/icon-button.cjs +491 -0
- package/dist/icon-button.d.cts +33 -0
- package/dist/icon-button.d.ts +33 -0
- package/dist/icon-button.js +470 -0
- package/dist/image.cjs +572 -0
- package/dist/image.d.cts +57 -0
- package/dist/image.d.ts +57 -0
- package/dist/image.js +551 -0
- package/dist/index.cjs +7316 -0
- package/dist/index.d.cts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +7137 -0
- package/dist/input-group.cjs +155 -0
- package/dist/input-group.d.cts +17 -0
- package/dist/input-group.d.ts +17 -0
- package/dist/input-group.js +133 -0
- package/dist/input.cjs +65 -0
- package/dist/input.d.cts +11 -0
- package/dist/input.d.ts +11 -0
- package/dist/input.js +59 -0
- package/dist/link.cjs +630 -0
- package/dist/link.d.cts +37 -0
- package/dist/link.d.ts +37 -0
- package/dist/link.js +606 -0
- package/dist/menu.cjs +305 -0
- package/dist/menu.d.cts +84 -0
- package/dist/menu.d.ts +84 -0
- package/dist/menu.js +269 -0
- package/dist/option-chain.cjs +221 -0
- package/dist/option-chain.d.cts +37 -0
- package/dist/option-chain.d.ts +37 -0
- package/dist/option-chain.js +199 -0
- package/dist/option-position.cjs +164 -0
- package/dist/option-position.d.cts +29 -0
- package/dist/option-position.d.ts +29 -0
- package/dist/option-position.js +142 -0
- package/dist/pin-input.cjs +182 -0
- package/dist/pin-input.d.cts +25 -0
- package/dist/pin-input.d.ts +25 -0
- package/dist/pin-input.js +160 -0
- package/dist/pnl-diagram.cjs +453 -0
- package/dist/pnl-diagram.d.cts +11 -0
- package/dist/pnl-diagram.d.ts +11 -0
- package/dist/pnl-diagram.js +431 -0
- package/dist/popover.cjs +327 -0
- package/dist/popover.d.cts +73 -0
- package/dist/popover.d.ts +73 -0
- package/dist/popover.js +294 -0
- package/dist/progress-circle.cjs +152 -0
- package/dist/progress-circle.d.cts +47 -0
- package/dist/progress-circle.d.ts +47 -0
- package/dist/progress-circle.js +128 -0
- package/dist/progress.cjs +117 -0
- package/dist/progress.d.cts +28 -0
- package/dist/progress.d.ts +28 -0
- package/dist/progress.js +94 -0
- package/dist/provider.cjs +62 -0
- package/dist/provider.d.cts +7 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +40 -0
- package/dist/radio.cjs +177 -0
- package/dist/radio.d.cts +53 -0
- package/dist/radio.d.ts +53 -0
- package/dist/radio.js +153 -0
- package/dist/rating.cjs +80 -0
- package/dist/rating.d.cts +14 -0
- package/dist/rating.d.ts +14 -0
- package/dist/rating.js +58 -0
- package/dist/select.cjs +791 -0
- package/dist/select.d.cts +130 -0
- package/dist/select.d.ts +130 -0
- package/dist/select.js +757 -0
- package/dist/separator.cjs +57 -0
- package/dist/separator.d.cts +13 -0
- package/dist/separator.d.ts +13 -0
- package/dist/separator.js +51 -0
- package/dist/skeleton.cjs +370 -0
- package/dist/skeleton.d.cts +60 -0
- package/dist/skeleton.d.ts +60 -0
- package/dist/skeleton.js +346 -0
- package/dist/slider.cjs +138 -0
- package/dist/slider.d.cts +24 -0
- package/dist/slider.d.ts +24 -0
- package/dist/slider.js +115 -0
- package/dist/strategy-builder.cjs +373 -0
- package/dist/strategy-builder.d.cts +26 -0
- package/dist/strategy-builder.d.ts +26 -0
- package/dist/strategy-builder.js +351 -0
- package/dist/switch.cjs +163 -0
- package/dist/switch.d.cts +27 -0
- package/dist/switch.d.ts +27 -0
- package/dist/switch.js +140 -0
- package/dist/table.cjs +1044 -0
- package/dist/table.d.cts +107 -0
- package/dist/table.d.ts +107 -0
- package/dist/table.js +1013 -0
- package/dist/tabs.cjs +240 -0
- package/dist/tabs.d.cts +78 -0
- package/dist/tabs.d.ts +78 -0
- package/dist/tabs.js +213 -0
- package/dist/tag.cjs +651 -0
- package/dist/tag.d.cts +21 -0
- package/dist/tag.d.ts +21 -0
- package/dist/tag.js +628 -0
- package/dist/textarea.cjs +65 -0
- package/dist/textarea.d.cts +11 -0
- package/dist/textarea.d.ts +11 -0
- package/dist/textarea.js +59 -0
- package/dist/toaster.cjs +99 -0
- package/dist/toaster.d.cts +29 -0
- package/dist/toaster.d.ts +29 -0
- package/dist/toaster.js +96 -0
- package/dist/tooltip.cjs +171 -0
- package/dist/tooltip.d.cts +39 -0
- package/dist/tooltip.d.ts +39 -0
- package/dist/tooltip.js +148 -0
- package/dist/utils.cjs +11 -0
- package/dist/utils.d.cts +5 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +9 -0
- package/package.json +284 -85
- package/src/accordion.tsx +285 -0
- package/src/alert.tsx +221 -0
- package/src/avatar.tsx +174 -0
- package/src/badge.tsx +158 -0
- package/src/bank.tsx +325 -0
- package/src/button.tsx +411 -0
- package/src/checkbox.tsx +307 -0
- package/src/close-button.tsx +51 -0
- package/src/collapsible.tsx +126 -0
- package/src/color-mode.tsx +125 -0
- package/src/dialog.tsx +356 -0
- package/src/drawer.tsx +186 -0
- package/src/empty-state.tsx +97 -0
- package/src/expiration-selector.tsx +163 -0
- package/src/field.tsx +202 -0
- package/src/greeks-display.tsx +138 -0
- package/src/heading.tsx +55 -0
- package/src/icon-button.tsx +192 -0
- package/src/image.tsx +280 -0
- package/src/index.ts +268 -0
- package/src/input-group.tsx +159 -0
- package/src/input.tsx +60 -0
- package/src/link.tsx +326 -0
- package/src/menu.tsx +471 -0
- package/src/option-chain.tsx +261 -0
- package/src/option-position.tsx +200 -0
- package/src/pin-input.tsx +187 -0
- package/src/pnl-diagram.tsx +458 -0
- package/src/popover.tsx +400 -0
- package/src/progress-circle.tsx +180 -0
- package/src/progress.tsx +109 -0
- package/src/provider.tsx +12 -0
- package/src/radio.tsx +175 -0
- package/src/rating.tsx +79 -0
- package/src/select.tsx +696 -0
- package/src/separator.tsx +59 -0
- package/src/skeleton.tsx +302 -0
- package/src/slider.tsx +152 -0
- package/src/strategy-builder.tsx +466 -0
- package/src/switch.tsx +158 -0
- package/src/table.tsx +621 -0
- package/src/tabs.tsx +354 -0
- package/src/tag.tsx +159 -0
- package/src/textarea.tsx +60 -0
- package/src/toaster.tsx +117 -0
- package/src/tokens.css +438 -0
- package/src/tooltip.tsx +184 -0
- package/src/utils/cn.ts +7 -0
- package/src/utils.ts +6 -0
- package/tokens.css +438 -0
- package/README.md +0 -109
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var clsx = require('clsx');
|
|
6
|
+
var tailwindMerge = require('tailwind-merge');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
28
|
+
|
|
29
|
+
// src/pin-input.tsx
|
|
30
|
+
function cn(...inputs) {
|
|
31
|
+
return tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
32
|
+
}
|
|
33
|
+
var INPUT_BASE = [
|
|
34
|
+
"w-10 h-10",
|
|
35
|
+
"text-center text-sm font-medium",
|
|
36
|
+
"border-2 rounded-md",
|
|
37
|
+
"outline-none appearance-none",
|
|
38
|
+
"bg-[var(--color-input-bg)] text-[var(--color-input-fg)]",
|
|
39
|
+
"border-[var(--color-input-border)]",
|
|
40
|
+
"placeholder:text-[var(--color-input-placeholder)]",
|
|
41
|
+
"hover:border-[var(--color-input-border-hover)]",
|
|
42
|
+
"focus:border-[var(--color-input-border-focus)] focus:shadow-md",
|
|
43
|
+
"disabled:opacity-40"
|
|
44
|
+
].join(" ");
|
|
45
|
+
var INPUT_FILLED = "border-[var(--color-input-border)]";
|
|
46
|
+
var INPUT_INVALID = "border-[var(--color-border-error)] hover:border-[var(--color-border-error)]";
|
|
47
|
+
var PinInput = React__namespace.forwardRef(
|
|
48
|
+
function PinInput2(props, ref) {
|
|
49
|
+
const {
|
|
50
|
+
count = 6,
|
|
51
|
+
inputProps,
|
|
52
|
+
rootRef,
|
|
53
|
+
attached,
|
|
54
|
+
placeholder = " ",
|
|
55
|
+
value: controlledValue,
|
|
56
|
+
onValueChange,
|
|
57
|
+
onValueComplete,
|
|
58
|
+
disabled,
|
|
59
|
+
invalid,
|
|
60
|
+
otp,
|
|
61
|
+
name,
|
|
62
|
+
bgColor,
|
|
63
|
+
className
|
|
64
|
+
} = props;
|
|
65
|
+
const inputRefs = React__namespace.useRef([]);
|
|
66
|
+
const values = React__namespace.useMemo(
|
|
67
|
+
() => controlledValue ?? Array.from({ length: count }).fill(""),
|
|
68
|
+
[controlledValue, count]
|
|
69
|
+
);
|
|
70
|
+
const updateValue = React__namespace.useCallback((index, char) => {
|
|
71
|
+
const next = [...values];
|
|
72
|
+
next[index] = char;
|
|
73
|
+
onValueChange?.({ value: next });
|
|
74
|
+
if (next.every((v) => v.length > 0)) {
|
|
75
|
+
onValueComplete?.({ value: next });
|
|
76
|
+
}
|
|
77
|
+
}, [values, onValueChange, onValueComplete]);
|
|
78
|
+
const focusInput = React__namespace.useCallback((index) => {
|
|
79
|
+
const clamped = Math.max(0, Math.min(index, count - 1));
|
|
80
|
+
inputRefs.current[clamped]?.focus();
|
|
81
|
+
}, [count]);
|
|
82
|
+
const handleInput = React__namespace.useCallback((index, e) => {
|
|
83
|
+
const target = e.currentTarget;
|
|
84
|
+
const char = target.value.slice(-1);
|
|
85
|
+
updateValue(index, char);
|
|
86
|
+
if (char && index < count - 1) {
|
|
87
|
+
focusInput(index + 1);
|
|
88
|
+
}
|
|
89
|
+
}, [count, updateValue, focusInput]);
|
|
90
|
+
const handleKeyDown = React__namespace.useCallback((index, e) => {
|
|
91
|
+
if (e.key === "Backspace") {
|
|
92
|
+
if (values[index]) {
|
|
93
|
+
updateValue(index, "");
|
|
94
|
+
} else if (index > 0) {
|
|
95
|
+
updateValue(index - 1, "");
|
|
96
|
+
focusInput(index - 1);
|
|
97
|
+
}
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
} else if (e.key === "ArrowLeft" && index > 0) {
|
|
100
|
+
focusInput(index - 1);
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
} else if (e.key === "ArrowRight" && index < count - 1) {
|
|
103
|
+
focusInput(index + 1);
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
}
|
|
106
|
+
}, [count, values, updateValue, focusInput]);
|
|
107
|
+
const handlePaste = React__namespace.useCallback((e) => {
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
const pasted = e.clipboardData.getData("text/plain").trim();
|
|
110
|
+
if (!pasted) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const chars = pasted.slice(0, count).split("");
|
|
114
|
+
const next = [...values];
|
|
115
|
+
chars.forEach((char, i) => {
|
|
116
|
+
next[i] = char;
|
|
117
|
+
});
|
|
118
|
+
onValueChange?.({ value: next });
|
|
119
|
+
if (next.every((v) => v.length > 0)) {
|
|
120
|
+
onValueComplete?.({ value: next });
|
|
121
|
+
}
|
|
122
|
+
focusInput(Math.min(chars.length, count - 1));
|
|
123
|
+
}, [count, values, onValueChange, onValueComplete, focusInput]);
|
|
124
|
+
const handleFocus = React__namespace.useCallback((e) => {
|
|
125
|
+
e.currentTarget.select();
|
|
126
|
+
}, []);
|
|
127
|
+
const handleNoop = React__namespace.useCallback(() => {
|
|
128
|
+
}, []);
|
|
129
|
+
const setInputRef = React__namespace.useCallback((index) => (el) => {
|
|
130
|
+
inputRefs.current[index] = el;
|
|
131
|
+
}, []);
|
|
132
|
+
const onInputAtIndex = React__namespace.useCallback((index) => (e) => {
|
|
133
|
+
handleInput(index, e);
|
|
134
|
+
}, [handleInput]);
|
|
135
|
+
const onKeyDownAtIndex = React__namespace.useCallback((index) => (e) => {
|
|
136
|
+
handleKeyDown(index, e);
|
|
137
|
+
}, [handleKeyDown]);
|
|
138
|
+
const bgStyle = bgColor ? { backgroundColor: `var(--color-${bgColor.replace(/\./g, "-")})` } : void 0;
|
|
139
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: rootRef, className: cn("inline-flex items-center", attached ? "gap-0" : "gap-2", className), children: [
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
141
|
+
"input",
|
|
142
|
+
{
|
|
143
|
+
ref,
|
|
144
|
+
type: "hidden",
|
|
145
|
+
name,
|
|
146
|
+
value: values.join(""),
|
|
147
|
+
...inputProps
|
|
148
|
+
}
|
|
149
|
+
),
|
|
150
|
+
Array.from({ length: count }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
151
|
+
"input",
|
|
152
|
+
{
|
|
153
|
+
ref: setInputRef(index),
|
|
154
|
+
type: "text",
|
|
155
|
+
inputMode: "numeric",
|
|
156
|
+
autoComplete: otp ? "one-time-code" : "off",
|
|
157
|
+
pattern: "[0-9]*",
|
|
158
|
+
maxLength: 1,
|
|
159
|
+
placeholder,
|
|
160
|
+
disabled,
|
|
161
|
+
"aria-invalid": invalid || void 0,
|
|
162
|
+
value: values[index] || "",
|
|
163
|
+
className: cn(
|
|
164
|
+
INPUT_BASE,
|
|
165
|
+
values[index] && INPUT_FILLED,
|
|
166
|
+
invalid && INPUT_INVALID,
|
|
167
|
+
attached && index > 0 && "-ml-0.5"
|
|
168
|
+
),
|
|
169
|
+
style: bgStyle,
|
|
170
|
+
onInput: onInputAtIndex(index),
|
|
171
|
+
onKeyDown: onKeyDownAtIndex(index),
|
|
172
|
+
onPaste: handlePaste,
|
|
173
|
+
onFocus: handleFocus,
|
|
174
|
+
onChange: handleNoop
|
|
175
|
+
},
|
|
176
|
+
index
|
|
177
|
+
))
|
|
178
|
+
] });
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
exports.PinInput = PinInput;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface PinInputProps {
|
|
4
|
+
readonly rootRef?: React.Ref<HTMLDivElement>;
|
|
5
|
+
readonly count?: number;
|
|
6
|
+
readonly inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
|
|
7
|
+
readonly attached?: boolean;
|
|
8
|
+
readonly placeholder?: string;
|
|
9
|
+
readonly value?: Array<string>;
|
|
10
|
+
readonly onValueChange?: (details: {
|
|
11
|
+
value: Array<string>;
|
|
12
|
+
}) => void;
|
|
13
|
+
readonly onValueComplete?: (details: {
|
|
14
|
+
value: Array<string>;
|
|
15
|
+
}) => void;
|
|
16
|
+
readonly disabled?: boolean;
|
|
17
|
+
readonly invalid?: boolean;
|
|
18
|
+
readonly otp?: boolean;
|
|
19
|
+
readonly name?: string;
|
|
20
|
+
readonly bgColor?: string;
|
|
21
|
+
readonly className?: string;
|
|
22
|
+
}
|
|
23
|
+
declare const PinInput: React.ForwardRefExoticComponent<PinInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
24
|
+
|
|
25
|
+
export { PinInput, type PinInputProps };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface PinInputProps {
|
|
4
|
+
readonly rootRef?: React.Ref<HTMLDivElement>;
|
|
5
|
+
readonly count?: number;
|
|
6
|
+
readonly inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
|
|
7
|
+
readonly attached?: boolean;
|
|
8
|
+
readonly placeholder?: string;
|
|
9
|
+
readonly value?: Array<string>;
|
|
10
|
+
readonly onValueChange?: (details: {
|
|
11
|
+
value: Array<string>;
|
|
12
|
+
}) => void;
|
|
13
|
+
readonly onValueComplete?: (details: {
|
|
14
|
+
value: Array<string>;
|
|
15
|
+
}) => void;
|
|
16
|
+
readonly disabled?: boolean;
|
|
17
|
+
readonly invalid?: boolean;
|
|
18
|
+
readonly otp?: boolean;
|
|
19
|
+
readonly name?: string;
|
|
20
|
+
readonly bgColor?: string;
|
|
21
|
+
readonly className?: string;
|
|
22
|
+
}
|
|
23
|
+
declare const PinInput: React.ForwardRefExoticComponent<PinInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
24
|
+
|
|
25
|
+
export { PinInput, type PinInputProps };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { clsx } from 'clsx';
|
|
4
|
+
import { twMerge } from 'tailwind-merge';
|
|
5
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
// src/pin-input.tsx
|
|
8
|
+
function cn(...inputs) {
|
|
9
|
+
return twMerge(clsx(inputs));
|
|
10
|
+
}
|
|
11
|
+
var INPUT_BASE = [
|
|
12
|
+
"w-10 h-10",
|
|
13
|
+
"text-center text-sm font-medium",
|
|
14
|
+
"border-2 rounded-md",
|
|
15
|
+
"outline-none appearance-none",
|
|
16
|
+
"bg-[var(--color-input-bg)] text-[var(--color-input-fg)]",
|
|
17
|
+
"border-[var(--color-input-border)]",
|
|
18
|
+
"placeholder:text-[var(--color-input-placeholder)]",
|
|
19
|
+
"hover:border-[var(--color-input-border-hover)]",
|
|
20
|
+
"focus:border-[var(--color-input-border-focus)] focus:shadow-md",
|
|
21
|
+
"disabled:opacity-40"
|
|
22
|
+
].join(" ");
|
|
23
|
+
var INPUT_FILLED = "border-[var(--color-input-border)]";
|
|
24
|
+
var INPUT_INVALID = "border-[var(--color-border-error)] hover:border-[var(--color-border-error)]";
|
|
25
|
+
var PinInput = React.forwardRef(
|
|
26
|
+
function PinInput2(props, ref) {
|
|
27
|
+
const {
|
|
28
|
+
count = 6,
|
|
29
|
+
inputProps,
|
|
30
|
+
rootRef,
|
|
31
|
+
attached,
|
|
32
|
+
placeholder = " ",
|
|
33
|
+
value: controlledValue,
|
|
34
|
+
onValueChange,
|
|
35
|
+
onValueComplete,
|
|
36
|
+
disabled,
|
|
37
|
+
invalid,
|
|
38
|
+
otp,
|
|
39
|
+
name,
|
|
40
|
+
bgColor,
|
|
41
|
+
className
|
|
42
|
+
} = props;
|
|
43
|
+
const inputRefs = React.useRef([]);
|
|
44
|
+
const values = React.useMemo(
|
|
45
|
+
() => controlledValue ?? Array.from({ length: count }).fill(""),
|
|
46
|
+
[controlledValue, count]
|
|
47
|
+
);
|
|
48
|
+
const updateValue = React.useCallback((index, char) => {
|
|
49
|
+
const next = [...values];
|
|
50
|
+
next[index] = char;
|
|
51
|
+
onValueChange?.({ value: next });
|
|
52
|
+
if (next.every((v) => v.length > 0)) {
|
|
53
|
+
onValueComplete?.({ value: next });
|
|
54
|
+
}
|
|
55
|
+
}, [values, onValueChange, onValueComplete]);
|
|
56
|
+
const focusInput = React.useCallback((index) => {
|
|
57
|
+
const clamped = Math.max(0, Math.min(index, count - 1));
|
|
58
|
+
inputRefs.current[clamped]?.focus();
|
|
59
|
+
}, [count]);
|
|
60
|
+
const handleInput = React.useCallback((index, e) => {
|
|
61
|
+
const target = e.currentTarget;
|
|
62
|
+
const char = target.value.slice(-1);
|
|
63
|
+
updateValue(index, char);
|
|
64
|
+
if (char && index < count - 1) {
|
|
65
|
+
focusInput(index + 1);
|
|
66
|
+
}
|
|
67
|
+
}, [count, updateValue, focusInput]);
|
|
68
|
+
const handleKeyDown = React.useCallback((index, e) => {
|
|
69
|
+
if (e.key === "Backspace") {
|
|
70
|
+
if (values[index]) {
|
|
71
|
+
updateValue(index, "");
|
|
72
|
+
} else if (index > 0) {
|
|
73
|
+
updateValue(index - 1, "");
|
|
74
|
+
focusInput(index - 1);
|
|
75
|
+
}
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
} else if (e.key === "ArrowLeft" && index > 0) {
|
|
78
|
+
focusInput(index - 1);
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
} else if (e.key === "ArrowRight" && index < count - 1) {
|
|
81
|
+
focusInput(index + 1);
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
}
|
|
84
|
+
}, [count, values, updateValue, focusInput]);
|
|
85
|
+
const handlePaste = React.useCallback((e) => {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
const pasted = e.clipboardData.getData("text/plain").trim();
|
|
88
|
+
if (!pasted) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const chars = pasted.slice(0, count).split("");
|
|
92
|
+
const next = [...values];
|
|
93
|
+
chars.forEach((char, i) => {
|
|
94
|
+
next[i] = char;
|
|
95
|
+
});
|
|
96
|
+
onValueChange?.({ value: next });
|
|
97
|
+
if (next.every((v) => v.length > 0)) {
|
|
98
|
+
onValueComplete?.({ value: next });
|
|
99
|
+
}
|
|
100
|
+
focusInput(Math.min(chars.length, count - 1));
|
|
101
|
+
}, [count, values, onValueChange, onValueComplete, focusInput]);
|
|
102
|
+
const handleFocus = React.useCallback((e) => {
|
|
103
|
+
e.currentTarget.select();
|
|
104
|
+
}, []);
|
|
105
|
+
const handleNoop = React.useCallback(() => {
|
|
106
|
+
}, []);
|
|
107
|
+
const setInputRef = React.useCallback((index) => (el) => {
|
|
108
|
+
inputRefs.current[index] = el;
|
|
109
|
+
}, []);
|
|
110
|
+
const onInputAtIndex = React.useCallback((index) => (e) => {
|
|
111
|
+
handleInput(index, e);
|
|
112
|
+
}, [handleInput]);
|
|
113
|
+
const onKeyDownAtIndex = React.useCallback((index) => (e) => {
|
|
114
|
+
handleKeyDown(index, e);
|
|
115
|
+
}, [handleKeyDown]);
|
|
116
|
+
const bgStyle = bgColor ? { backgroundColor: `var(--color-${bgColor.replace(/\./g, "-")})` } : void 0;
|
|
117
|
+
return /* @__PURE__ */ jsxs("div", { ref: rootRef, className: cn("inline-flex items-center", attached ? "gap-0" : "gap-2", className), children: [
|
|
118
|
+
/* @__PURE__ */ jsx(
|
|
119
|
+
"input",
|
|
120
|
+
{
|
|
121
|
+
ref,
|
|
122
|
+
type: "hidden",
|
|
123
|
+
name,
|
|
124
|
+
value: values.join(""),
|
|
125
|
+
...inputProps
|
|
126
|
+
}
|
|
127
|
+
),
|
|
128
|
+
Array.from({ length: count }).map((_, index) => /* @__PURE__ */ jsx(
|
|
129
|
+
"input",
|
|
130
|
+
{
|
|
131
|
+
ref: setInputRef(index),
|
|
132
|
+
type: "text",
|
|
133
|
+
inputMode: "numeric",
|
|
134
|
+
autoComplete: otp ? "one-time-code" : "off",
|
|
135
|
+
pattern: "[0-9]*",
|
|
136
|
+
maxLength: 1,
|
|
137
|
+
placeholder,
|
|
138
|
+
disabled,
|
|
139
|
+
"aria-invalid": invalid || void 0,
|
|
140
|
+
value: values[index] || "",
|
|
141
|
+
className: cn(
|
|
142
|
+
INPUT_BASE,
|
|
143
|
+
values[index] && INPUT_FILLED,
|
|
144
|
+
invalid && INPUT_INVALID,
|
|
145
|
+
attached && index > 0 && "-ml-0.5"
|
|
146
|
+
),
|
|
147
|
+
style: bgStyle,
|
|
148
|
+
onInput: onInputAtIndex(index),
|
|
149
|
+
onKeyDown: onKeyDownAtIndex(index),
|
|
150
|
+
onPaste: handlePaste,
|
|
151
|
+
onFocus: handleFocus,
|
|
152
|
+
onChange: handleNoop
|
|
153
|
+
},
|
|
154
|
+
index
|
|
155
|
+
))
|
|
156
|
+
] });
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
export { PinInput };
|