) => {
+ const { target } = e
+ const { previousElementSibling, value } = target
+
+ if (
+ previousElementSibling instanceof HTMLInputElement &&
+ previousElementSibling.value === ''
+ ) {
+ return previousElementSibling.focus()
+ }
+
+ target.setSelectionRange(0, value.length)
+ }
+
+ return (
+
+ {otpDigits.map((digit, index) => (
+ onChangeInternal(e, index)}
+ onFocus={handleFocus}
+ onKeyDown={handleKeyDown}
+ pattern="\d{1}"
+ type="text"
+ value={digit}
+ />
+ ))}
+
+ )
+}
+
+export default OtpInput
diff --git a/src/components/ui/input.tsx b/src/components/ui/input.tsx
index 49268ed..17e3977 100644
--- a/src/components/ui/input.tsx
+++ b/src/components/ui/input.tsx
@@ -7,21 +7,35 @@ export interface InputProps
const Input = React.forwardRef(
({ className, placeholder, type, ...props }, ref) => {
return (
-
-
-
- {placeholder}
-
-
+ <>
+ {placeholder ? (
+
+
+
+ {placeholder}
+
+
+ ) : (
+
+ )}
+ >
)
}
)
diff --git a/src/components/ui/theme-toggler.tsx b/src/components/ui/theme-toggler.tsx
index 86340d4..269ffcd 100644
--- a/src/components/ui/theme-toggler.tsx
+++ b/src/components/ui/theme-toggler.tsx
@@ -14,9 +14,9 @@ import * as React from 'react'
export function ThemeToggler() {
const { setTheme } = useTheme()
- const setLightTheme = () => setTheme('light')
- const setDarkTheme = () => setTheme('dark')
- const setSystemTheme = () => setTheme('system')
+ const setThemeLight = () => setTheme('light')
+ const setThemeDark = () => setTheme('dark')
+ const setThemeSystem = () => setTheme('system')
return (
@@ -28,11 +28,9 @@ export function ThemeToggler() {
- setLightTheme}>Light
- setDarkTheme}>Dark
- setSystemTheme}>
- System
-
+ Light
+ Dark
+ System
)
diff --git a/src/constants/auth.ts b/src/constants/auth.ts
new file mode 100644
index 0000000..ff63853
--- /dev/null
+++ b/src/constants/auth.ts
@@ -0,0 +1 @@
+export const LENGTH_OTP = 5
diff --git a/src/constants/index.ts b/src/constants/index.ts
index 94812ca..be93b81 100644
--- a/src/constants/index.ts
+++ b/src/constants/index.ts
@@ -1 +1,2 @@
export * from './env'
+export * from './auth'
diff --git a/src/utils/misc.ts b/src/utils/misc.ts
index 7c99475..2633d1c 100644
--- a/src/utils/misc.ts
+++ b/src/utils/misc.ts
@@ -8,3 +8,7 @@ export const getIconDimension = (size?: IconSize) => {
if (size) return ICON_SIZE[size]
return ICON_SIZE['md']
}
+
+export const isNumeric = (value: string) => {
+ return !isNaN(parseInt(value, 10))
+}