@planetaexo/design-system 0.4.16 → 0.4.17
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/index.cjs +18 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5046,6 +5046,7 @@ var OTPCodeInput = ({
|
|
|
5046
5046
|
const updateValue = (newDigits) => {
|
|
5047
5047
|
onChange(newDigits.join(""));
|
|
5048
5048
|
};
|
|
5049
|
+
const focusedIndexRef = React22__namespace.useRef(0);
|
|
5049
5050
|
const focusSlot = (index) => {
|
|
5050
5051
|
var _a;
|
|
5051
5052
|
if (index >= 0 && index < length) {
|
|
@@ -5088,20 +5089,22 @@ var OTPCodeInput = ({
|
|
|
5088
5089
|
e.preventDefault();
|
|
5089
5090
|
const pasted = e.clipboardData.getData("text").replace(/\D/g, "").slice(0, length);
|
|
5090
5091
|
if (!pasted) return;
|
|
5092
|
+
const startIndex = focusedIndexRef.current;
|
|
5091
5093
|
const newDigits = [...digits];
|
|
5092
|
-
for (let i = 0; i < pasted.length; i++) {
|
|
5093
|
-
newDigits[i] = pasted[i];
|
|
5094
|
+
for (let i = 0; i < pasted.length && startIndex + i < length; i++) {
|
|
5095
|
+
newDigits[startIndex + i] = pasted[i];
|
|
5094
5096
|
}
|
|
5095
5097
|
updateValue(newDigits);
|
|
5096
|
-
const
|
|
5097
|
-
focusSlot(
|
|
5098
|
+
const lastFilled = Math.min(startIndex + pasted.length, length) - 1;
|
|
5099
|
+
focusSlot(lastFilled < length - 1 ? lastFilled + 1 : lastFilled);
|
|
5098
5100
|
};
|
|
5099
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col", className), children: [
|
|
5101
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col items-center", className), children: [
|
|
5100
5102
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5101
5103
|
"label",
|
|
5102
5104
|
{
|
|
5105
|
+
htmlFor: baseId,
|
|
5103
5106
|
className: cn(
|
|
5104
|
-
"text-sm text-muted-foreground mb-2",
|
|
5107
|
+
"self-start text-sm text-muted-foreground font-ui mb-2",
|
|
5105
5108
|
required && "after:content-['*'] after:text-primary after:ml-0.5"
|
|
5106
5109
|
),
|
|
5107
5110
|
children: label
|
|
@@ -5111,11 +5114,12 @@ var OTPCodeInput = ({
|
|
|
5111
5114
|
"div",
|
|
5112
5115
|
{
|
|
5113
5116
|
className: cn(
|
|
5114
|
-
"flex gap-2",
|
|
5117
|
+
"flex justify-center gap-2",
|
|
5115
5118
|
disabled && "opacity-50 pointer-events-none"
|
|
5116
5119
|
),
|
|
5117
5120
|
role: "group",
|
|
5118
5121
|
"aria-label": label,
|
|
5122
|
+
onPaste: handlePaste,
|
|
5119
5123
|
children: digits.map((digit, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
5120
5124
|
"input",
|
|
5121
5125
|
{
|
|
@@ -5126,17 +5130,19 @@ var OTPCodeInput = ({
|
|
|
5126
5130
|
type: "text",
|
|
5127
5131
|
inputMode: "numeric",
|
|
5128
5132
|
pattern: "\\d*",
|
|
5129
|
-
maxLength:
|
|
5133
|
+
maxLength: 2,
|
|
5130
5134
|
value: digit,
|
|
5131
5135
|
autoComplete: index === 0 ? "one-time-code" : "off",
|
|
5132
5136
|
"aria-label": `${label} d\xEDgito ${index + 1} de ${length}`,
|
|
5133
5137
|
disabled,
|
|
5134
5138
|
onChange: (e) => handleChange(index, e.target.value),
|
|
5135
5139
|
onKeyDown: (e) => handleKeyDown(index, e),
|
|
5136
|
-
|
|
5137
|
-
|
|
5140
|
+
onFocus: (e) => {
|
|
5141
|
+
focusedIndexRef.current = index;
|
|
5142
|
+
e.target.select();
|
|
5143
|
+
},
|
|
5138
5144
|
className: cn(
|
|
5139
|
-
"w-
|
|
5145
|
+
"w-11 h-14 text-center text-lg rounded-lg border font-ui",
|
|
5140
5146
|
"bg-background text-foreground border-border",
|
|
5141
5147
|
"transition-colors",
|
|
5142
5148
|
"focus:outline-none focus:border-primary focus:ring-1 focus:ring-primary",
|
|
@@ -5147,7 +5153,7 @@ var OTPCodeInput = ({
|
|
|
5147
5153
|
))
|
|
5148
5154
|
}
|
|
5149
5155
|
),
|
|
5150
|
-
error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-destructive", children: error })
|
|
5156
|
+
error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-destructive font-ui self-start", children: error })
|
|
5151
5157
|
] });
|
|
5152
5158
|
};
|
|
5153
5159
|
OTPCodeInput.displayName = "OTPCodeInput";
|