-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elements: Fix OTPInput selection logic, support single input (#2656)
* feat: OTP input selection fixes * chore(elements): Refactor OTPInput, move props generation into useInput(). Support single input mode * chore(repo): Add changeset * chore(elements): Add otp-playground for testing
- Loading branch information
Showing
5 changed files
with
239 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
53 changes: 53 additions & 0 deletions
53
packages/elements/examples/nextjs/app/otp-playground/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use client'; | ||
|
||
import { Field, Input, Label, SignIn, SignInStart } from '@clerk/elements'; | ||
import clsx from 'clsx'; | ||
import { AnimatePresence, motion } from 'framer-motion'; | ||
|
||
export default function Page() { | ||
return ( | ||
<SignIn> | ||
<SignInStart> | ||
<div className='h-dvh flex items-center justify-center bg-neutral-800'> | ||
<Field name='code'> | ||
<Label className='sr-only'>Label</Label> | ||
<Input | ||
className='flex gap-3 text-white isolate font-semibold text-2xl' | ||
data-1p-ignore | ||
type='otp' | ||
render={({ value, status }) => ( | ||
<div | ||
className={clsx( | ||
'relative flex h-14 w-12 items-center justify-center rounded-md bg-neutral-900 shadow-[0_10px_19px_4px_theme(colors.black/16%),_0_-10px_16px_-4px_theme(colors.white/4%),_0_0_0_1px_theme(colors.white/1%),_0_1px_0_0_theme(colors.white/2%)]', | ||
)} | ||
> | ||
<AnimatePresence> | ||
{value && ( | ||
<motion.span | ||
initial={{ opacity: 0, scale: 0.75 }} | ||
animate={{ opacity: 1, scale: 1 }} | ||
exit={{ opacity: 0, scale: 0.75 }} | ||
className='absolute inset-0 flex items-center justify-center text-white' | ||
> | ||
{value} | ||
</motion.span> | ||
)} | ||
{value} | ||
</AnimatePresence> | ||
|
||
{(status === 'cursor' || status === 'selected') && ( | ||
<motion.div | ||
layoutId='tab-trigger-underline' | ||
transition={{ duration: 0.2, type: 'spring', damping: 20, stiffness: 200 }} | ||
className='absolute inset-0 border border-sky-400 shadow-[0_0_8px_2px_theme(colors.sky.400/30%)] z-10 rounded-[inherit] bg-sky-400/10' | ||
/> | ||
)} | ||
</div> | ||
)} | ||
/> | ||
</Field> | ||
</div> | ||
</SignInStart> | ||
</SignIn> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.