forked from rajun/ar-test
feat: add login story step
This commit is contained in:
parent
61c62afe6d
commit
34af16d550
61
app/components/auth/showcase/story-step.tsx
Normal file
61
app/components/auth/showcase/story-step.tsx
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
import { Text } from '~/components/ui/text';
|
||||||
|
import { LOGIN_STORY_STEP_MS, type LoginStoryStep } from '~/data/auth/constants';
|
||||||
|
import { cn } from '~/lib/utils';
|
||||||
|
|
||||||
|
const shell = cva('relative flex cursor-pointer overflow-hidden text-left ring-1 ring-inset transition-colors duration-200', {
|
||||||
|
variants: {
|
||||||
|
layout: {
|
||||||
|
card: 'w-full gap-4 rounded-card-sm px-4 pt-3.5 pb-4 hover:bg-surface-dialog',
|
||||||
|
pill: 'h-[38px] items-center gap-2 whitespace-nowrap rounded-full px-3.5',
|
||||||
|
},
|
||||||
|
active: { true: 'bg-surface', false: '' },
|
||||||
|
},
|
||||||
|
compoundVariants: [
|
||||||
|
{ layout: 'card', active: true, className: 'ring-border-dialog' },
|
||||||
|
{ layout: 'card', active: false, className: 'ring-transparent' },
|
||||||
|
{ layout: 'pill', active: true, className: 'ring-border-control' },
|
||||||
|
{ layout: 'pill', active: false, className: 'ring-border-divider' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
interface StoryStepProps {
|
||||||
|
step: LoginStoryStep;
|
||||||
|
// card: number, title and description (wide layout); pill: number and title
|
||||||
|
layout: 'card' | 'pill';
|
||||||
|
active: boolean;
|
||||||
|
// Restarts the progress bar
|
||||||
|
cycle: number;
|
||||||
|
onSelect: () => void;
|
||||||
|
onComplete: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function StoryStep({ step, layout, active, cycle, onSelect, onComplete }: StoryStepProps) {
|
||||||
|
const card = layout === 'card';
|
||||||
|
return (
|
||||||
|
<button type='button' aria-current={active ? 'step' : undefined} onClick={onSelect} className={shell({ layout, active })}>
|
||||||
|
<Text as='span' variant='mono' tone={active ? 'primary' : 'placeholder'} className={cn(card && 'pt-0.5')}>
|
||||||
|
{step.number}
|
||||||
|
</Text>
|
||||||
|
{card ? (
|
||||||
|
<span className='flex min-w-0 flex-col gap-1'>
|
||||||
|
<Text as='span' variant='subheading' tone={active ? 'default' : 'subtle'}>{step.title}</Text>
|
||||||
|
<Text as='span' variant='body' tone={active ? 'secondary' : 'placeholder'}>{step.description}</Text>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<Text as='span' variant='label' tone={active ? 'default' : 'subtle'}>{step.title}</Text>
|
||||||
|
)}
|
||||||
|
{/* Fills over one step; its end moves the story on. With reduced motion it shows full and the story waits for clicks. */}
|
||||||
|
{active && (
|
||||||
|
<span aria-hidden='true' className={cn('absolute bottom-0 h-0.5 overflow-hidden rounded-full bg-border-divider', card ? 'inset-x-4' : 'inset-x-3.5')}>
|
||||||
|
<span
|
||||||
|
key={cycle}
|
||||||
|
onAnimationEnd={onComplete}
|
||||||
|
className='block h-full origin-left animate-story-progress bg-primary motion-reduce:animate-none'
|
||||||
|
style={{ animationDuration: `${LOGIN_STORY_STEP_MS}ms` }}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user