{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "modal-06",
  "title": "Manage access",
  "description": "A role on a segmented control sets the permission switches, and changing one marks the access as custom with a way back",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chip.json",
    "https://ui.ndekocode.dev/r/dialog.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/switch.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/toggle-group.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/modal/modal-06.tsx",
      "content": "'use client';\n\nimport { useId, useState } from 'react';\n\nimport { InfoIcon, RotateCcwIcon, SendIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Chip } from '@/registry/ndeko/ui/chip';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Switch } from '@/registry/ndeko/ui/switch';\n\nimport { ActionButton, useTimedAction } from './_parts/action-button';\nimport { ChoiceSegments, type SegmentOption } from './_parts/choice-segments';\nimport { isEmail } from './_parts/invite-emails';\nimport {\n  ModalCloseButton,\n  ModalDescription,\n  ModalFooter,\n  ModalHeader,\n  ModalPreview,\n  ModalTitle,\n} from './_parts/modal-frame';\nimport { Swap } from './_parts/swap';\n\ntype Role = 'admin' | 'editor' | 'viewer';\n\ntype PermissionId = 'create' | 'edit' | 'delete' | 'invite' | 'reports';\n\ntype Permissions = Record<PermissionId, boolean>;\n\nconst ROLE_OPTIONS: SegmentOption<Role>[] = [\n  { value: 'admin', label: 'Admin' },\n  { value: 'editor', label: 'Editor' },\n  { value: 'viewer', label: 'Viewer' },\n];\n\nconst PERMISSIONS: { id: PermissionId; label: string; line: string }[] = [\n  {\n    id: 'create',\n    label: 'Create tasks',\n    line: 'Adds tasks and sub-tasks to any project',\n  },\n  {\n    id: 'edit',\n    label: 'Edit the tasks of others',\n    line: 'Changes their status, dates and assignees',\n  },\n  {\n    id: 'delete',\n    label: 'Delete tasks',\n    line: 'Removes tasks for good, with their time',\n  },\n  {\n    id: 'invite',\n    label: 'Invite people',\n    line: 'Sends invitations to the workspace',\n  },\n  {\n    id: 'reports',\n    label: 'See reports',\n    line: 'Opens the time and payment reports',\n  },\n];\n\nconst PRESETS: Record<Role, Permissions> = {\n  admin: {\n    create: true,\n    edit: true,\n    delete: true,\n    invite: true,\n    reports: true,\n  },\n  editor: {\n    create: true,\n    edit: true,\n    delete: false,\n    invite: false,\n    reports: true,\n  },\n  viewer: {\n    create: false,\n    edit: false,\n    delete: false,\n    invite: false,\n    reports: true,\n  },\n};\n\nconst PERMISSION_IDS: PermissionId[] = PERMISSIONS.map(\n  (permission) => permission.id\n);\n\nfunction roleLabelOf(role: Role) {\n  const option = ROLE_OPTIONS.find((candidate) => candidate.value === role);\n  return option?.label ?? role;\n}\n\nfunction differsFromPreset(permissions: Permissions, role: Role) {\n  const preset = PRESETS[role];\n  return PERMISSION_IDS.some((id) => permissions[id] !== preset[id]);\n}\n\nfunction PermissionRow({\n  label,\n  line,\n  checked,\n  onCheckedChange,\n}: {\n  label: string;\n  line: string;\n  checked: boolean;\n  onCheckedChange: (checked: boolean) => void;\n}) {\n  const switchId = useId();\n\n  return (\n    <div className='flex items-center justify-between gap-4 py-1.5'>\n      <div className='flex min-w-0 flex-col gap-0.5'>\n        <label htmlFor={switchId} className='text-[13px] font-medium'>\n          {label}\n        </label>\n        <p className='text-muted-foreground text-xs'>{line}</p>\n      </div>\n      <Switch\n        id={switchId}\n        checked={checked}\n        onCheckedChange={onCheckedChange}\n      />\n    </div>\n  );\n}\n\nfunction ManageAccess() {\n  const [email, setEmail] = useState('');\n  const [role, setRole] = useState<Role>('editor');\n  const [permissions, setPermissions] = useState<Permissions>(PRESETS.editor);\n  const [error, setError] = useState<string | null>(null);\n  const [sentLine, setSentLine] = useState<string | null>(null);\n  const action = useTimedAction();\n  const emailId = useId();\n  const hintId = useId();\n  const roleLabel = roleLabelOf(role);\n  const isCustom = differsFromPreset(permissions, role);\n  const hasError = Boolean(error);\n  const hasSentLine = Boolean(sentLine);\n  const hint = error ?? 'They get an e-mail invitation to join';\n  const permissionsKey = String(isCustom);\n\n  function changeEmail(event: React.ChangeEvent<HTMLInputElement>) {\n    setEmail(event.target.value);\n    setError(null);\n  }\n\n  function changeRole(nextRole: Role) {\n    setRole(nextRole);\n    setPermissions(PRESETS[nextRole]);\n  }\n\n  function resetPermissions() {\n    setPermissions(PRESETS[role]);\n  }\n\n  function changePermission(id: PermissionId, checked: boolean) {\n    setPermissions((previous) => ({ ...previous, [id]: checked }));\n  }\n\n  function commitSend() {\n    const address = email.trim().toLowerCase();\n    setSentLine(`Invitation sent to ${address} as ${roleLabel}`);\n    setEmail('');\n  }\n\n  function send(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    const address = email.trim().toLowerCase();\n    if (!isEmail(address)) {\n      setError('Enter an address like name@company.com');\n      return;\n    }\n    action.run(commitSend);\n  }\n\n  return (\n    <form onSubmit={send} className='flex flex-col gap-5' noValidate>\n      <ModalHeader>\n        <ModalTitle>Manage access</ModalTitle>\n        <ModalDescription>\n          Invite someone and choose exactly what they can do\n        </ModalDescription>\n      </ModalHeader>\n      <div className='flex flex-col gap-1.5'>\n        <label htmlFor={emailId} className='text-[13px] font-medium'>\n          E-mail address\n        </label>\n        <Input\n          id={emailId}\n          type='email'\n          autoComplete='off'\n          placeholder='name@company.com'\n          value={email}\n          aria-invalid={hasError}\n          aria-describedby={hintId}\n          onChange={changeEmail}\n        />\n        <p\n          id={hintId}\n          className={cn(\n            'flex items-center gap-1.5 text-xs',\n            hasError && 'text-destructive-ink',\n            !hasError && 'text-muted-foreground'\n          )}\n        >\n          <InfoIcon className='size-3.5 shrink-0' />\n          <Swap swapKey={hint} kind='label'>\n            {hint}\n          </Swap>\n        </p>\n      </div>\n      <div className='flex flex-col gap-2'>\n        <span className='text-[13px] font-medium'>Role</span>\n        <ChoiceSegments\n          label='Role'\n          value={role}\n          options={ROLE_OPTIONS}\n          onValueChange={changeRole}\n        />\n      </div>\n      <div className='flex flex-col gap-1'>\n        <div className='flex min-h-7 items-center justify-between gap-3'>\n          <span className='text-[13px] font-medium'>Permissions</span>\n          <Swap swapKey={permissionsKey} kind='label'>\n            {isCustom && (\n              <span className='flex items-center gap-1'>\n                <Chip color='var(--warning)'>Custom</Chip>\n                <Button\n                  variant='ghost'\n                  size='sm'\n                  onClick={resetPermissions}\n                  className='text-muted-foreground'\n                >\n                  <RotateCcwIcon />\n                  {`Reset to ${roleLabel}`}\n                </Button>\n              </span>\n            )}\n            {!isCustom && (\n              <span className='text-muted-foreground text-xs'>\n                {`Set by the ${roleLabel} role`}\n              </span>\n            )}\n          </Swap>\n        </div>\n        {PERMISSIONS.map((permission) => {\n          function changeThis(checked: boolean) {\n            changePermission(permission.id, checked);\n          }\n\n          return (\n            <PermissionRow\n              key={permission.id}\n              label={permission.label}\n              line={permission.line}\n              checked={permissions[permission.id]}\n              onCheckedChange={changeThis}\n            />\n          );\n        })}\n      </div>\n      <AnimatedSize>\n        {hasSentLine && (\n          <Swap\n            swapKey={sentLine ?? ''}\n            kind='label'\n            className='text-muted-foreground flex min-w-0 text-xs'\n            contentClassName='max-w-full min-w-0 whitespace-normal'\n          >\n            {sentLine}\n          </Swap>\n        )}\n      </AnimatedSize>\n      <ModalFooter>\n        <ModalCloseButton variant='ghost'>Cancel</ModalCloseButton>\n        <ActionButton\n          type='submit'\n          state={action.state}\n          idleIcon={<SendIcon />}\n          labels={{\n            idle: 'Send invitation',\n            working: 'Sending',\n            done: 'Sent',\n          }}\n        />\n      </ModalFooter>\n    </form>\n  );\n}\n\nexport default function Modal06() {\n  return (\n    <ModalPreview triggerLabel='Open the access dialog' size='md'>\n      <ManageAccess />\n    </ModalPreview>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/modal-06.tsx"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/action-button.tsx",
      "content": "'use client';\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { CheckIcon, LoaderCircleIcon } from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button, type ButtonProps } from '@/registry/ndeko/ui/button';\n\nimport { Swap } from './swap';\n\nexport type ActionState = 'idle' | 'working' | 'done';\n\nexport type ActionLabels = Record<ActionState, string>;\n\nconst WORKING_MS = 800;\n\nconst DONE_MS = 1600;\n\n/** The life of an action that takes a moment: working, then done for a beat, then ready again. The change is committed when the work ends. */\nexport function useTimedAction() {\n  const [state, setState] = useState<ActionState>('idle');\n  const commitRef = useRef<(() => void) | null>(null);\n\n  useEffect(() => {\n    if (state === 'working') {\n      const timeout = window.setTimeout(() => {\n        const commit = commitRef.current;\n        commitRef.current = null;\n        if (commit) {\n          commit();\n        }\n        setState('done');\n      }, WORKING_MS);\n      return () => window.clearTimeout(timeout);\n    }\n    if (state === 'done') {\n      const timeout = window.setTimeout(() => {\n        setState('idle');\n      }, DONE_MS);\n      return () => window.clearTimeout(timeout);\n    }\n  }, [state]);\n\n  function run(commit: () => void) {\n    if (state !== 'idle') {\n      return;\n    }\n    commitRef.current = commit;\n    setState('working');\n  }\n\n  const isBusy = state !== 'idle';\n\n  return { state, run, isBusy };\n}\n\nfunction iconOf(state: ActionState, idleIcon: React.ReactNode) {\n  if (state === 'working') {\n    return <LoaderCircleIcon className='animate-spin' />;\n  }\n  if (state === 'done') {\n    return <CheckIcon />;\n  }\n  return idleIcon;\n}\n\ntype ActionButtonProps = Omit<ButtonProps, 'children'> & {\n  state: ActionState;\n  labels: ActionLabels;\n  idleIcon?: React.ReactNode;\n};\n\n/** One button that becomes its next state: its icon swaps, its label crossfades and its width follows the new label. */\nexport function ActionButton({\n  state,\n  labels,\n  idleIcon,\n  ...props\n}: ActionButtonProps) {\n  const icon = iconOf(state, idleIcon);\n  const hasIcon = Boolean(icon);\n  const label = labels[state];\n  const isWorking = state === 'working';\n  const isDone = state === 'done';\n\n  return (\n    <>\n      <Button aria-busy={isWorking} {...props}>\n        {hasIcon && <Swap swapKey={state}>{icon}</Swap>}\n        <AnimatedSize axis='width' as='span'>\n          <Swap swapKey={label} kind='label'>\n            {label}\n          </Swap>\n        </AnimatedSize>\n      </Button>\n      <span className='sr-only' role='status'>\n        {isDone && labels.done}\n      </span>\n    </>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/action-button.tsx"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/choice-segments.tsx",
      "content": "'use client';\n\nimport type { Icon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { ToggleGroup, ToggleGroupItem } from '@/registry/ndeko/ui/toggle-group';\n\nexport type SegmentOption<Value extends string> = {\n  value: Value;\n  label: string;\n  icon?: Icon;\n};\n\nconst THUMB =\n  'bg-card shadow-[0_1px_2px_rgb(0_0_0/0.08)] hairline-ring ring-foreground/10 dark:bg-foreground/[0.09] dark:ring-foreground/15';\n\ntype ChoiceSegmentsProps<Value extends string> = {\n  value: Value;\n  options: SegmentOption<Value>[];\n  onValueChange: (value: Value) => void;\n  /** Names the group for screen readers when no visible label points at it. */\n  label: string;\n  className?: string;\n};\n\n/** One choice out of a few on a segmented track: a raised thumb travels to the picked segment. */\nexport function ChoiceSegments<Value extends string>({\n  value,\n  options,\n  onValueChange,\n  label,\n  className,\n}: ChoiceSegmentsProps<Value>) {\n  const pressedValues = [value];\n\n  function changeValue(nextValues: unknown[]) {\n    const [nextValue] = nextValues;\n    const option = options.find((candidate) => candidate.value === nextValue);\n    if (option) {\n      onValueChange(option.value);\n    }\n  }\n\n  return (\n    <ToggleGroup\n      aria-label={label}\n      value={pressedValues}\n      onValueChange={changeValue}\n      travel\n      size='sm'\n      indicatorClassName={THUMB}\n      className={cn('bg-foreground/[0.05] w-full rounded-lg p-0.5', className)}\n    >\n      {options.map((option) => {\n        const OptionGlyph = option.icon;\n\n        return (\n          <ToggleGroupItem\n            key={option.value}\n            value={option.value}\n            className='flex-1 rounded-md'\n          >\n            {OptionGlyph && <OptionGlyph />}\n            {option.label}\n          </ToggleGroupItem>\n        );\n      })}\n    </ToggleGroup>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/choice-segments.tsx"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/invite-emails.ts",
      "content": "import {\n  AlertCircleIcon,\n  ClockIcon,\n  UserIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\n\n/** What sending does to an address: a new invitation, the e-mail again for a pending one, nothing for a member or a typo. */\nexport type AddressState = 'new' | 'pending' | 'member' | 'invalid';\n\nexport type AddressEntry = { email: string; state: AddressState };\n\nexport type AddressLook = { color: string; icon: Icon | null; hint: string };\n\nexport const ADDRESS_LOOK: Record<AddressState, AddressLook> = {\n  new: { color: 'var(--muted-foreground)', icon: null, hint: '' },\n  pending: {\n    color: 'var(--warning)',\n    icon: ClockIcon,\n    hint: 'Already invited: they get the e-mail again',\n  },\n  member: {\n    color: 'var(--muted-foreground)',\n    icon: UserIcon,\n    hint: 'Already in the team: not invited again',\n  },\n  invalid: {\n    color: 'var(--destructive)',\n    icon: AlertCircleIcon,\n    hint: 'Not a valid e-mail address',\n  },\n};\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nconst TOKEN_SEPARATORS = /[\\s,;<>\"'()]+/;\n\nexport function isEmail(value: string) {\n  return EMAIL_PATTERN.test(value);\n}\n\nfunction normalizeAddress(value: string) {\n  const trimmed = value.trim();\n  return trimmed.toLowerCase();\n}\n\n/**\n * The addresses in what was typed or pasted, without repeats. When the text holds an address, the words around it\n * are names copied from a mail client and are left out.\n */\nexport function splitAddresses(text: string) {\n  const tokens = text.split(TOKEN_SEPARATORS);\n  const holdsAnAddress = text.includes('@');\n  const addresses: string[] = [];\n  for (const token of tokens) {\n    const address = normalizeAddress(token);\n    const isEmpty = address.length === 0;\n    const isNameAround = holdsAnAddress && !address.includes('@');\n    const isRepeat = addresses.includes(address);\n    if (isEmpty || isNameAround || isRepeat) {\n      continue;\n    }\n    addresses.push(address);\n  }\n  return addresses;\n}\n\nexport function mergeAddresses(current: string[], added: string[]) {\n  const merged = [...current];\n  for (const address of added) {\n    if (!merged.includes(address)) {\n      merged.push(address);\n    }\n  }\n  return merged;\n}\n\nexport type AddressContext = {\n  memberEmails: ReadonlySet<string>;\n  pendingEmails: ReadonlySet<string>;\n};\n\nexport function stateOfAddress(\n  email: string,\n  context: AddressContext\n): AddressState {\n  if (!isEmail(email)) {\n    return 'invalid';\n  }\n  if (context.memberEmails.has(email)) {\n    return 'member';\n  }\n  if (context.pendingEmails.has(email)) {\n    return 'pending';\n  }\n  return 'new';\n}\n\nexport function isSendable(state: AddressState) {\n  const isNew = state === 'new';\n  const isPending = state === 'pending';\n  return isNew || isPending;\n}\n\nexport function countOf(entries: AddressEntry[], state: AddressState) {\n  return entries.filter((entry) => entry.state === state).length;\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/invite-emails.ts"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/modal-frame.tsx",
      "content": "'use client';\n\nimport { createContext, useContext } from 'react';\n\nimport { SquareArrowOutUpRightIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button, type ButtonProps } from '@/registry/ndeko/ui/button';\nimport {\n  Dialog,\n  DialogClose,\n  DialogContent,\n  DialogDescription,\n  DialogTitle,\n  DialogTrigger,\n} from '@/registry/ndeko/ui/dialog';\n\n/** Where a modal's content is drawn: open in the page as a preview, or inside the real dialog. */\nexport type ModalHost = 'preview' | 'dialog';\n\nconst ModalHostContext = createContext<ModalHost>('preview');\n\nexport function useModalHost() {\n  return useContext(ModalHostContext);\n}\n\nexport type ModalSize = 'sm' | 'md' | 'lg' | 'xl';\n\nconst SIZE_CLASS: Record<ModalSize, string> = {\n  sm: 'max-w-sm',\n  md: 'max-w-md',\n  lg: 'max-w-lg',\n  xl: 'max-w-[44rem]',\n};\n\nconst TITLE = 'text-lg leading-tight font-semibold text-balance';\n\nconst DESCRIPTION = 'text-muted-foreground text-[13px]';\n\nconst BODY = 'flex flex-col gap-4';\n\ntype ModalTextProps = { className?: string; children: React.ReactNode };\n\nexport function ModalTitle({ className, children }: ModalTextProps) {\n  const host = useModalHost();\n  if (host === 'dialog') {\n    return <DialogTitle className={className}>{children}</DialogTitle>;\n  }\n  return <h2 className={cn(TITLE, className)}>{children}</h2>;\n}\n\nexport function ModalDescription({ className, children }: ModalTextProps) {\n  const host = useModalHost();\n  if (host === 'dialog') {\n    return (\n      <DialogDescription className={className}>{children}</DialogDescription>\n    );\n  }\n  return <p className={cn(DESCRIPTION, className)}>{children}</p>;\n}\n\n/** Leaves room for the dialog's close button, so the preview and the dialog lay out the same. */\nexport function ModalHeader({\n  className,\n  ...props\n}: React.ComponentProps<'div'>) {\n  return (\n    <div className={cn('flex flex-col gap-1.5 pr-8', className)} {...props} />\n  );\n}\n\nexport function ModalFooter({\n  className,\n  ...props\n}: React.ComponentProps<'div'>) {\n  return (\n    <div\n      className={cn(\n        'flex flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-end',\n        className\n      )}\n      {...props}\n    />\n  );\n}\n\n/** Closes the dialog. In the preview it stays a plain button that runs its own action, if any. */\nexport function ModalCloseButton({ children, ...props }: ButtonProps) {\n  const host = useModalHost();\n  if (host === 'dialog') {\n    return <DialogClose render={<Button {...props} />}>{children}</DialogClose>;\n  }\n  return <Button {...props}>{children}</Button>;\n}\n\ntype ModalPreviewProps = {\n  /** The content, drawn twice: open in the page, and inside the dialog the trigger opens. */\n  children: React.ReactNode;\n  triggerLabel: string;\n  size?: ModalSize;\n  className?: string;\n};\n\n/** Shows a modal open and whole on the page, with a small trigger that opens the same content in the real dialog. */\nexport function ModalPreview({\n  children,\n  triggerLabel,\n  size = 'md',\n  className,\n}: ModalPreviewProps) {\n  const sizeClass = SIZE_CLASS[size];\n\n  return (\n    <div className='flex w-full flex-col items-center gap-4'>\n      <ModalHostContext.Provider value='preview'>\n        <div\n          className={cn(\n            'surface-raised w-full rounded-2xl p-6 text-left',\n            sizeClass,\n            className\n          )}\n        >\n          <AnimatedSize contentClassName={BODY}>{children}</AnimatedSize>\n        </div>\n      </ModalHostContext.Provider>\n      <Dialog>\n        <DialogTrigger render={<Button variant='outline' size='sm' />}>\n          <SquareArrowOutUpRightIcon />\n          {triggerLabel}\n        </DialogTrigger>\n        <DialogContent className={cn(sizeClass, className)}>\n          <ModalHostContext.Provider value='dialog'>\n            {children}\n          </ModalHostContext.Provider>\n        </DialogContent>\n      </Dialog>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/modal-frame.tsx"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/motion.ts",
      "content": "import type { Transition, Variants } from 'motion/react';\n\nexport const SWAP_TRANSITION: Transition = {\n  duration: 0.15,\n  ease: [0.2, 0, 0, 1],\n};\n\nconst MORPH_SPRING: Transition = { type: 'spring', bounce: 0, duration: 0.3 };\n\nconst INSTANT: Transition = { duration: 0 };\n\nconst PRESENCE_IN: Transition = { duration: 0.2, ease: [0.23, 1, 0.32, 1] };\n\nconst PRESENCE_OUT: Transition = { duration: 0.14, ease: [0.23, 1, 0.32, 1] };\n\nconst ICON_SWAP: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst LABEL_SWAP: Variants = {\n  enter: { opacity: 0, filter: 'blur(2px)' },\n  visible: { opacity: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, filter: 'blur(2px)' },\n};\n\nconst FADE_SWAP: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nconst ROW_PRESENCE: Variants = {\n  hidden: {\n    height: 0,\n    opacity: 0,\n    overflow: 'hidden',\n    transition: PRESENCE_OUT,\n  },\n  shown: {\n    height: 'auto',\n    opacity: 1,\n    transition: PRESENCE_IN,\n    transitionEnd: { overflow: 'visible' },\n  },\n};\n\nconst ROW_FADE: Variants = {\n  hidden: { opacity: 0, transition: PRESENCE_OUT },\n  shown: { opacity: 1, transition: PRESENCE_IN },\n};\n\nconst CHIP_PRESENCE: Variants = {\n  hidden: { opacity: 0, scale: 0.9, transition: PRESENCE_OUT },\n  shown: { opacity: 1, scale: 1, transition: PRESENCE_IN },\n};\n\nexport type SwapKind = 'icon' | 'label';\n\nexport function swapVariantsOf(\n  shouldReduceMotion: boolean | null,\n  kind: SwapKind = 'icon'\n) {\n  if (shouldReduceMotion) {\n    return FADE_SWAP;\n  }\n  if (kind === 'label') {\n    return LABEL_SWAP;\n  }\n  return ICON_SWAP;\n}\n\n/** A row added to or removed from a list: its height opens or collapses, so the rows after it slide. */\nexport function rowVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return ROW_FADE;\n  }\n  return ROW_PRESENCE;\n}\n\nexport function chipVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return ROW_FADE;\n  }\n  return CHIP_PRESENCE;\n}\n\nexport function morphOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return MORPH_SPRING;\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/motion.ts"
    },
    {
      "path": "registry/ndeko/components/modal/_parts/swap.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport { SWAP_TRANSITION, swapVariantsOf, type SwapKind } from './motion';\n\ntype SwapProps = {\n  /** Changes when the content becomes another: the old one leaves while the new one arrives in its place. */\n  swapKey: string;\n  kind?: SwapKind;\n  className?: string;\n  /** Classes of the moving content, for example `min-w-0 max-w-full` so a long text can truncate inside. */\n  contentClassName?: string;\n  children: React.ReactNode;\n};\n\nexport function Swap({\n  swapKey,\n  kind = 'icon',\n  className,\n  contentClassName,\n  children,\n}: SwapProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = swapVariantsOf(shouldReduceMotion, kind);\n\n  return (\n    <span className={cn('relative inline-flex items-center', className)}>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={swapKey}\n          className={cn(\n            'inline-flex items-center gap-[inherit] whitespace-nowrap',\n            contentClassName\n          )}\n          variants={variants}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          transition={SWAP_TRANSITION}\n        >\n          {children}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/_parts/swap.tsx"
    }
  ],
  "categories": [
    "components",
    "modal"
  ],
  "type": "registry:component"
}