@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.js
CHANGED
|
@@ -5025,6 +5025,7 @@ var OTPCodeInput = ({
|
|
|
5025
5025
|
const updateValue = (newDigits) => {
|
|
5026
5026
|
onChange(newDigits.join(""));
|
|
5027
5027
|
};
|
|
5028
|
+
const focusedIndexRef = React22.useRef(0);
|
|
5028
5029
|
const focusSlot = (index) => {
|
|
5029
5030
|
var _a;
|
|
5030
5031
|
if (index >= 0 && index < length) {
|
|
@@ -5067,20 +5068,22 @@ var OTPCodeInput = ({
|
|
|
5067
5068
|
e.preventDefault();
|
|
5068
5069
|
const pasted = e.clipboardData.getData("text").replace(/\D/g, "").slice(0, length);
|
|
5069
5070
|
if (!pasted) return;
|
|
5071
|
+
const startIndex = focusedIndexRef.current;
|
|
5070
5072
|
const newDigits = [...digits];
|
|
5071
|
-
for (let i = 0; i < pasted.length; i++) {
|
|
5072
|
-
newDigits[i] = pasted[i];
|
|
5073
|
+
for (let i = 0; i < pasted.length && startIndex + i < length; i++) {
|
|
5074
|
+
newDigits[startIndex + i] = pasted[i];
|
|
5073
5075
|
}
|
|
5074
5076
|
updateValue(newDigits);
|
|
5075
|
-
const
|
|
5076
|
-
focusSlot(
|
|
5077
|
+
const lastFilled = Math.min(startIndex + pasted.length, length) - 1;
|
|
5078
|
+
focusSlot(lastFilled < length - 1 ? lastFilled + 1 : lastFilled);
|
|
5077
5079
|
};
|
|
5078
|
-
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col", className), children: [
|
|
5080
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col items-center", className), children: [
|
|
5079
5081
|
/* @__PURE__ */ jsx(
|
|
5080
5082
|
"label",
|
|
5081
5083
|
{
|
|
5084
|
+
htmlFor: baseId,
|
|
5082
5085
|
className: cn(
|
|
5083
|
-
"text-sm text-muted-foreground mb-2",
|
|
5086
|
+
"self-start text-sm text-muted-foreground font-ui mb-2",
|
|
5084
5087
|
required && "after:content-['*'] after:text-primary after:ml-0.5"
|
|
5085
5088
|
),
|
|
5086
5089
|
children: label
|
|
@@ -5090,11 +5093,12 @@ var OTPCodeInput = ({
|
|
|
5090
5093
|
"div",
|
|
5091
5094
|
{
|
|
5092
5095
|
className: cn(
|
|
5093
|
-
"flex gap-2",
|
|
5096
|
+
"flex justify-center gap-2",
|
|
5094
5097
|
disabled && "opacity-50 pointer-events-none"
|
|
5095
5098
|
),
|
|
5096
5099
|
role: "group",
|
|
5097
5100
|
"aria-label": label,
|
|
5101
|
+
onPaste: handlePaste,
|
|
5098
5102
|
children: digits.map((digit, index) => /* @__PURE__ */ jsx(
|
|
5099
5103
|
"input",
|
|
5100
5104
|
{
|
|
@@ -5105,17 +5109,19 @@ var OTPCodeInput = ({
|
|
|
5105
5109
|
type: "text",
|
|
5106
5110
|
inputMode: "numeric",
|
|
5107
5111
|
pattern: "\\d*",
|
|
5108
|
-
maxLength:
|
|
5112
|
+
maxLength: 2,
|
|
5109
5113
|
value: digit,
|
|
5110
5114
|
autoComplete: index === 0 ? "one-time-code" : "off",
|
|
5111
5115
|
"aria-label": `${label} d\xEDgito ${index + 1} de ${length}`,
|
|
5112
5116
|
disabled,
|
|
5113
5117
|
onChange: (e) => handleChange(index, e.target.value),
|
|
5114
5118
|
onKeyDown: (e) => handleKeyDown(index, e),
|
|
5115
|
-
|
|
5116
|
-
|
|
5119
|
+
onFocus: (e) => {
|
|
5120
|
+
focusedIndexRef.current = index;
|
|
5121
|
+
e.target.select();
|
|
5122
|
+
},
|
|
5117
5123
|
className: cn(
|
|
5118
|
-
"w-
|
|
5124
|
+
"w-11 h-14 text-center text-lg rounded-lg border font-ui",
|
|
5119
5125
|
"bg-background text-foreground border-border",
|
|
5120
5126
|
"transition-colors",
|
|
5121
5127
|
"focus:outline-none focus:border-primary focus:ring-1 focus:ring-primary",
|
|
@@ -5126,7 +5132,7 @@ var OTPCodeInput = ({
|
|
|
5126
5132
|
))
|
|
5127
5133
|
}
|
|
5128
5134
|
),
|
|
5129
|
-
error && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-destructive", children: error })
|
|
5135
|
+
error && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-destructive font-ui self-start", children: error })
|
|
5130
5136
|
] });
|
|
5131
5137
|
};
|
|
5132
5138
|
OTPCodeInput.displayName = "OTPCodeInput";
|