{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "modal-14",
  "title": "Payment record",
  "description": "Time entries with their total, the earnings breakdown with the take-home figure, an invoice export and a paid status",
  "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/theme.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-14.tsx",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport {\n  CheckIcon,\n  ClockIcon,\n  DownloadIcon,\n  BriefcaseIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Chip } from '@/registry/ndeko/ui/chip';\n\nimport {\n  ActionButton,\n  useTimedAction,\n  type ActionLabels,\n} from './_parts/action-button';\nimport {\n  ModalDescription,\n  ModalFooter,\n  ModalHeader,\n  ModalPreview,\n  ModalTitle,\n} from './_parts/modal-frame';\nimport { Swap } from './_parts/swap';\n\ntype TimeEntry = { id: string; task: string; date: string; minutes: number };\n\nconst ENTRIES: TimeEntry[] = [\n  {\n    id: 'entry-1',\n    task: 'Design system audit',\n    date: 'Mon 5 Oct',\n    minutes: 270,\n  },\n  {\n    id: 'entry-2',\n    task: 'Onboarding screens',\n    date: 'Wed 7 Oct',\n    minutes: 90,\n  },\n  {\n    id: 'entry-3',\n    task: 'Review with the client',\n    date: 'Fri 9 Oct',\n    minutes: 120,\n  },\n];\n\nconst HOURLY_RATE = 62;\n\nconst FEE_PERCENT = 10;\n\nconst MINUTES_PER_HOUR = 60;\n\nconst CLIENT_GEM = { '--gem': 'var(--info)' } as React.CSSProperties;\n\nconst MONEY = new Intl.NumberFormat('en-US', {\n  style: 'currency',\n  currency: 'USD',\n});\n\nconst EXPORT_LABELS: ActionLabels = {\n  idle: 'Export invoice',\n  working: 'Exporting',\n  done: 'Exported',\n};\n\nfunction durationOf(minutes: number) {\n  const hours = Math.floor(minutes / MINUTES_PER_HOUR);\n  const rest = minutes % MINUTES_PER_HOUR;\n  const paddedRest = String(rest).padStart(2, '0');\n  return `${hours}h ${paddedRest}m`;\n}\n\nfunction totalMinutesOf(entries: TimeEntry[]) {\n  let total = 0;\n  for (const entry of entries) {\n    total += entry.minutes;\n  }\n  return total;\n}\n\nfunction paymentLabelsOf(isPaid: boolean): ActionLabels {\n  if (isPaid) {\n    return { idle: 'Mark as unpaid', working: 'Saving', done: 'Saved' };\n  }\n  return { idle: 'Mark as paid', working: 'Saving', done: 'Saved' };\n}\n\nfunction StatusChip({ isPaid }: { isPaid: boolean }) {\n  const statusKey = String(isPaid);\n\n  return (\n    <Swap swapKey={statusKey}>\n      {isPaid && (\n        <Chip color='var(--success)'>\n          <CheckIcon strokeWidth={2.5} />\n          Paid\n        </Chip>\n      )}\n      {!isPaid && (\n        <Chip color='var(--warning)'>\n          <ClockIcon strokeWidth={2.25} />\n          Pending\n        </Chip>\n      )}\n    </Swap>\n  );\n}\n\nfunction EntriesTable({ totalMinutes }: { totalMinutes: number }) {\n  return (\n    <div className='bg-foreground/[0.04] overflow-hidden rounded-xl'>\n      <table className='w-full text-[13px]'>\n        <caption className='sr-only'>Time entries of the invoice</caption>\n        <thead>\n          <tr className='hairline-b border-border text-muted-foreground text-xs'>\n            <th scope='col' className='px-3 py-2 text-left font-medium'>\n              Task\n            </th>\n            <th scope='col' className='px-3 py-2 text-left font-medium'>\n              Date\n            </th>\n            <th scope='col' className='px-3 py-2 text-right font-medium'>\n              Time\n            </th>\n          </tr>\n        </thead>\n        <tbody>\n          {ENTRIES.map((entry) => (\n            <tr key={entry.id} className='hairline-b border-border'>\n              <td className='w-full max-w-0 truncate px-3 py-2.5'>\n                {entry.task}\n              </td>\n              <td className='text-muted-foreground px-3 py-2.5 whitespace-nowrap'>\n                {entry.date}\n              </td>\n              <td className='px-3 py-2.5 text-right whitespace-nowrap tabular-nums'>\n                {durationOf(entry.minutes)}\n              </td>\n            </tr>\n          ))}\n        </tbody>\n        <tfoot>\n          <tr>\n            <th\n              scope='row'\n              colSpan={2}\n              className='px-3 py-2.5 text-left font-medium'\n            >\n              Total\n            </th>\n            <td className='px-3 py-2.5 text-right font-medium whitespace-nowrap tabular-nums'>\n              {durationOf(totalMinutes)}\n            </td>\n          </tr>\n        </tfoot>\n      </table>\n    </div>\n  );\n}\n\nfunction PaymentRecordContent() {\n  const [isPaid, setIsPaid] = useState(false);\n  const payment = useTimedAction();\n  const exporting = useTimedAction();\n  const totalMinutes = totalMinutesOf(ENTRIES);\n  const hours = totalMinutes / MINUTES_PER_HOUR;\n  const earned = hours * HOURLY_RATE;\n  const fee = (earned * FEE_PERCENT) / 100;\n  const takeHome = earned - fee;\n  const paymentLabels = paymentLabelsOf(isPaid);\n\n  function togglePaid() {\n    payment.run(() => {\n      setIsPaid((previous) => !previous);\n    });\n  }\n\n  function exportInvoice() {\n    exporting.run(() => {});\n  }\n\n  return (\n    <>\n      <ModalHeader>\n        <ModalTitle>Payment record</ModalTitle>\n        <ModalDescription>Invoice INV-2026-118 · October 2026</ModalDescription>\n      </ModalHeader>\n      <dl className='grid grid-cols-2 gap-4'>\n        <div className='flex min-w-0 flex-col gap-1'>\n          <dt className='text-muted-foreground text-xs'>Client</dt>\n          <dd className='flex min-w-0 items-center gap-2 text-[13px] font-medium'>\n            <span\n              style={CLIENT_GEM}\n              className='gem-plate flex size-5 shrink-0 items-center justify-center rounded-[5px]'\n            >\n              <BriefcaseIcon className='size-3' strokeWidth={2.25} />\n            </span>\n            <span className='truncate'>Fernwick Studio</span>\n          </dd>\n        </div>\n        <div className='flex min-w-0 flex-col gap-1'>\n          <dt className='text-muted-foreground text-xs'>Job</dt>\n          <dd className='truncate text-[13px] font-medium'>Product design</dd>\n        </div>\n      </dl>\n      <div className='flex flex-wrap items-center gap-1.5'>\n        <StatusChip isPaid={isPaid} />\n        <Chip color='var(--info)'>{`Hourly · ${MONEY.format(HOURLY_RATE)}`}</Chip>\n      </div>\n      <EntriesTable totalMinutes={totalMinutes} />\n      <dl className='flex flex-col gap-2 text-[13px]'>\n        <div className='flex items-baseline justify-between gap-4'>\n          <dt className='text-muted-foreground'>\n            {`${hours} h × ${MONEY.format(HOURLY_RATE)}`}\n          </dt>\n          <dd className='tabular-nums'>{MONEY.format(earned)}</dd>\n        </div>\n        <div className='flex items-baseline justify-between gap-4'>\n          <dt className='text-muted-foreground'>\n            {`Platform fee, ${FEE_PERCENT}%`}\n          </dt>\n          <dd className='tabular-nums'>{`−${MONEY.format(fee)}`}</dd>\n        </div>\n        <div className='flex items-end justify-between gap-4 pt-2'>\n          <dt className='flex flex-col gap-0.5'>\n            <span className='font-medium'>Take-home</span>\n            <span className='text-muted-foreground text-xs'>\n              Illustrative figures\n            </span>\n          </dt>\n          <dd className='text-2xl font-semibold tabular-nums'>\n            {MONEY.format(takeHome)}\n          </dd>\n        </div>\n      </dl>\n      <ModalFooter>\n        <ActionButton\n          variant='outline'\n          state={payment.state}\n          labels={paymentLabels}\n          onClick={togglePaid}\n        />\n        <ActionButton\n          state={exporting.state}\n          labels={EXPORT_LABELS}\n          idleIcon={<DownloadIcon />}\n          onClick={exportInvoice}\n        />\n      </ModalFooter>\n    </>\n  );\n}\n\nexport default function Modal14() {\n  return (\n    <ModalPreview triggerLabel='Open payment record' size='md'>\n      <PaymentRecordContent />\n    </ModalPreview>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/modal/modal-14.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/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"
}