Skip to content

Commit

Permalink
feat: update styles to match figma
Browse files Browse the repository at this point in the history
  • Loading branch information
RobChangCA committed Nov 22, 2024
1 parent bad935e commit eba0a4e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
10 changes: 8 additions & 2 deletions account-kit/react/src/components/otp-input/otp-input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ export const TestTyping: Story = {
await userEvent.type(inputs[2], "3");
await userEvent.type(inputs[3], "4");
await userEvent.type(inputs[4], "5");
await userEvent.type(inputs[5], "6");

// Verify values
expect(inputs[0]).toHaveValue("1");
expect(inputs[1]).toHaveValue("2");
expect(inputs[2]).toHaveValue("3");
expect(inputs[3]).toHaveValue("4");
expect(inputs[4]).toHaveValue("5");
expect(inputs[5]).toHaveValue("6");
},
};

Expand All @@ -59,7 +61,7 @@ export const TestPasting: Story = {

// Simulate paste event
const clipboardData = new DataTransfer();
clipboardData.setData("text/plain", "12345");
clipboardData.setData("text/plain", "123456");

const pasteEvent = new ClipboardEvent("paste", {
clipboardData,
Expand All @@ -75,6 +77,7 @@ export const TestPasting: Story = {
expect(inputs[2]).toHaveValue("3");
expect(inputs[3]).toHaveValue("4");
expect(inputs[4]).toHaveValue("5");
expect(inputs[5]).toHaveValue("6");
});
},
};
Expand All @@ -99,8 +102,11 @@ export const TestKeyboardNavigation: Story = {
// Test backspace
await userEvent.type(inputs[0], "1");
await userEvent.keyboard("{Backspace}");
await userEvent.keyboard("{Backspace}");
expect(inputs[0]).toHaveValue("");
expect(document.activeElement).toBe(inputs[0]);
await userEvent.type(inputs[0], "1");
await userEvent.keyboard("23456");
},
};

Expand Down Expand Up @@ -134,7 +140,7 @@ export const TestErrorState: Story = {
// Check for error message
await waitFor(() => {
const errorMessage = canvas.getByText(
/Paste does not match the code structure/i
/The code you entered is incorrect/i
);
expect(errorMessage).toBeInTheDocument();
});
Expand Down
26 changes: 13 additions & 13 deletions account-kit/react/src/components/otp-input/otp-input.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useEffect, useRef, useState } from "react";
import { ls } from "../../strings.js";

export type OTPCodeType = [string, string, string, string, string];
export const initialValue: OTPCodeType = ["", "", "", "", ""];
const OTP_LENGTH = 5;
export type OTPCodeType = [string, string, string, string, string, string];
export const initialValue: OTPCodeType = ["", "", "", "", "", ""];
const OTP_LENGTH = 6;
type OTPInputProps = {
errorText?: string;
value: OTPCodeType;
Expand Down Expand Up @@ -91,9 +92,7 @@ export const OTPInput: React.FC<OTPInputProps> = ({
if (isOTPCodeType(pasteData)) {
setValue(pasteData);
} else {
setErrorText(
"Paste does not match the code structure, please copy the entire code"
);
setErrorText(ls.error.otp.invalid);
}
};

Expand Down Expand Up @@ -122,7 +121,7 @@ export const OTPInput: React.FC<OTPInputProps> = ({
};

return (
<div>
<div className="flex flex-col gap-2 items-center">
{/* Input for autocomplete, visibility hidden */}
<input
className="invisible h-0 w-0 p-[0] m-[-1px]"
Expand All @@ -133,13 +132,12 @@ export const OTPInput: React.FC<OTPInputProps> = ({
onChange={(e) => setAutoComplete(e.target.value)}
onClick={handleReset}
/>
<div>
<label>Code</label>
</div>
<div className="flex gap-2">
<div className="flex gap-2.5">
{initialValue.map((_, i) => (
<input
className="border h-7 w-7 rounded text-center"
className={`border w-8 bg-bg-surface-default h-10 rounded text-center focus:outline-active ${
!!errorText && "border-fg-critical"
}`}
ref={(el) => (refs.current[i] = el)}
tabIndex={i + 1}
type="text"
Expand All @@ -161,7 +159,9 @@ export const OTPInput: React.FC<OTPInputProps> = ({
/>
))}
</div>
{errorText && <p className="text-red-500">{errorText}</p>}
{errorText && (
<p className="text-fg-critical text-sm text-center">{errorText}</p>
)}
</div>
);
};
3 changes: 3 additions & 0 deletions account-kit/react/src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const STRINGS = {
},
},
},
otp: {
invalid: "The code you entered is incorrect",
},
},
oauthContactSupport: {
title: "Need help?",
Expand Down

0 comments on commit eba0a4e

Please sign in to comment.