{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "block-modal-stepper",
  "type": "registry:block",
  "title": "Stepper modal",
  "description": "A setup in steps in a modal: the steps down the left with their state, the current step’s form beside them.",
  "dependencies": [
    "@remixicon/react@^4.9.0"
  ],
  "registryDependencies": [
    "https://wideset.co/r/block-styles.json",
    "https://wideset.co/r/button.json",
    "https://wideset.co/r/checkbox.json",
    "https://wideset.co/r/form-field.json",
    "https://wideset.co/r/modal.json",
    "https://wideset.co/r/progress-stepper.json",
    "https://wideset.co/r/select.json",
    "https://wideset.co/r/text-input.json",
    "https://wideset.co/r/utils.json"
  ],
  "files": [
    {
      "path": "src/blocks/modal-stepper/card-brand.tsx",
      "type": "registry:file",
      "target": "blocks/wideset/modal-stepper/card-brand.tsx",
      "content": "'use client';\n\n// TODO(custom): card brand mark in a field's suffix; Wideset has no payment-brand entity (Figma's Text Input \"Entity\" suffix holds a Payment image) and blocks ship no logo artwork.\nimport { RiVisaLine } from '@remixicon/react';\n\n/**\n * The card's brand in the card number field's suffix: Figma's 24px Payment entity, drawn as the\n * Remix mark on the inverse tile instead of logo artwork. Static here: a payment provider's field\n * reports the brand as the number is typed, so swap the mark on that.\n */\nexport function CardBrand() {\n  return (\n    <span\n      role=\"img\"\n      aria-label=\"Visa\"\n      className=\"bg-ws-static-inverse-background text-ws-static-inverse-strong rounded-ws-control-sm size-ws-12 flex shrink-0 items-center justify-center\"\n    >\n      <RiVisaLine aria-hidden=\"true\" className=\"size-ws-10\" />\n    </span>\n  );\n}\n"
    },
    {
      "path": "src/blocks/modal-stepper/data.ts",
      "type": "registry:file",
      "target": "blocks/wideset/modal-stepper/data.ts",
      "content": "/** The product the account is set up for. */\nexport const PRODUCT = 'Orbit';\n\n/** Where the links lead: replace with your routes. */\nexport const ROUTES = {\n  terms: '#terms',\n};\n\n/** The countries a card can be billed in; the first is preselected. */\nexport const COUNTRIES = [\n  { value: 'us', label: 'United States' },\n  { value: 'ca', label: 'Canada' },\n  { value: 'de', label: 'Germany' },\n  { value: 'nl', label: 'Netherlands' },\n  { value: 'pl', label: 'Poland' },\n  { value: 'gb', label: 'United Kingdom' },\n];\n\n/**\n * The setup's steps, in order. The title names the step in the list and heads its form; the\n * description is the line under that heading.\n */\nexport const STEPS = [\n  { title: 'Personal information', description: 'Your name and how your team reaches you.' },\n  {\n    title: 'Payment information',\n    description: `By providing your card information, you allow ${PRODUCT} to charge your card for future payments in accordance with their terms.`,\n  },\n  { title: 'Organization', description: 'The workspace your projects live in.' },\n  { title: 'Invite team', description: 'The people you work with, and what each can do.' },\n  { title: 'Review', description: 'A last look before the account is ready.' },\n];\n\n/** The step the setup opens on and the only one with a form here: the card. */\nexport const PAYMENT_STEP = 1;\n"
    },
    {
      "path": "src/blocks/modal-stepper/index.tsx",
      "type": "registry:file",
      "target": "blocks/wideset/modal-stepper/index.tsx",
      "content": "'use client';\n\nimport '@/styles/wideset-blocks.css';\n\nimport { Button } from '@/components/ui/wideset/button/Button';\nimport { useState } from 'react';\n\nimport { SetupAccountModal } from './setup-account-modal';\n\n/** Stepper modal: a setup in steps over the page, here over an empty page that reopens it. */\nexport default function ModalStepperBlock() {\n  const [open, setOpen] = useState(true);\n\n  return (\n    <div className=\"ws-block-utility bg-ws-static-foreground flex h-dvh items-center justify-center\">\n      <Button variant=\"secondary\" preset=\"border\" onClick={() => setOpen(true)}>\n        Set up account\n      </Button>\n      <SetupAccountModal open={open} onOpenChange={setOpen} />\n    </div>\n  );\n}\n"
    },
    {
      "path": "src/blocks/modal-stepper/keyboard-hints.tsx",
      "type": "registry:file",
      "target": "blocks/wideset/modal-stepper/keyboard-hints.tsx",
      "content": "'use client';\n\n// TODO(custom): keyboard hints (a key chip and what it does) and the keys they name; Wideset has no Kbd / shortcut component, so the key is the box of Button `xs` Border drawn by hand.\nimport {\n  type RemixiconComponentType,\n  RiArrowDownSLine,\n  RiArrowLeftLine,\n  RiArrowUpSLine,\n} from '@remixicon/react';\nimport { cn } from '@/lib/wideset/utils';\nimport type { KeyboardEvent, ReactNode } from 'react';\n\n/**\n * The hints in the modal's footer strip, as Figma draws them: moving through the modal, going\n * back to where it was opened from, and closing. Esc is the Modal's own; `modalKeys` wires the\n * other two on `Modal.Content`, so every hint does what it says.\n */\nexport function KeyboardHints() {\n  return (\n    <>\n      <div className=\"gap-ws-12 flex items-center\">\n        <Hint\n          keys={\n            <span className=\"gap-ws-3 flex\">\n              <Key icon={RiArrowUpSLine} name=\"Up arrow\" />\n              <Key icon={RiArrowDownSLine} name=\"Down arrow\" />\n            </span>\n          }\n        >\n          Navigate\n        </Hint>\n        <Hint keys={<Key icon={RiArrowLeftLine} name=\"Left arrow\" />}>Return to parent</Hint>\n      </div>\n      <Hint keys={<Key>esc</Key>}>Close</Hint>\n    </>\n  );\n}\n\n/** One hint: the keys, then what they do. */\nfunction Hint({ keys, children }: { keys: ReactNode; children: string }) {\n  return (\n    <span className=\"gap-ws-5 typography-body-md text-ws-static-subtle flex items-center\">\n      {keys}\n      {children}\n    </span>\n  );\n}\n\n/** A key as a `kbd`, 24px high. An icon key names itself for screen readers. */\nfunction Key({\n  icon: Icon,\n  name,\n  children,\n}: {\n  icon?: RemixiconComponentType;\n  name?: string;\n  children?: string;\n}) {\n  return (\n    <kbd\n      className={cn(\n        'font-ws-body border-ws-dynamic-secondary-default bg-ws-static-highlight-subtle shadow-ws-controls-control rounded-ws-control-md h-ws-12 typography-caption-strong-md text-ws-dynamic-secondary-default flex items-center justify-center border',\n        Icon ? 'w-ws-12' : 'px-ws-5',\n      )}\n    >\n      {Icon ? (\n        <>\n          <Icon aria-hidden=\"true\" className=\"size-ws-8 shrink-0\" />\n          <span className=\"sr-only\">{name}</span>\n        </>\n      ) : (\n        children\n      )}\n    </kbd>\n  );\n}\n\n/** Places where the arrows already mean something: a list, a choice, tabs, a menu, a number. */\nconst OWN_ARROWS =\n  'textarea, select, [role=\"combobox\"], [aria-haspopup], [role=\"listbox\"], [role=\"radiogroup\"], [role=\"radio\"], [role=\"tablist\"], [role=\"tab\"], [role=\"menu\"], [role=\"slider\"], input[type=\"number\"], input[type=\"range\"]';\n\nconst FOCUSABLE =\n  'a[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/** In a text field the caret moves with Left, unless it stands at the very start. */\nconst caretAtStart = (target: Element) =>\n  !(target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) ||\n  (target.selectionStart === 0 && target.selectionEnd === 0);\n\n/**\n * The keys the hints name, for `Modal.Content`'s `onKeyDown`: Up and Down move to the previous or\n * next control in the modal, Left goes back with `onBack`. Neither takes a key from a place that\n * uses it (a select, a radio group, tabs, a list, a menu), nor one already handled; Left in a text\n * field only once the caret is at its start, so it still moves the caret.\n */\nexport function modalKeys(onBack: () => void) {\n  return (event: KeyboardEvent<HTMLElement>) => {\n    const { key, target, currentTarget } = event;\n    if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n    if (!(target instanceof Element) || target.closest(OWN_ARROWS)) return;\n    if (key === 'ArrowUp' || key === 'ArrowDown') {\n      const controls = [...currentTarget.querySelectorAll<HTMLElement>(FOCUSABLE)].filter(\n        (element) => element.getClientRects().length > 0,\n      );\n      const next =\n        controls[controls.indexOf(target as HTMLElement) + (key === 'ArrowDown' ? 1 : -1)];\n      if (!next) return;\n      event.preventDefault();\n      next.focus();\n    } else if (key === 'ArrowLeft' && !event.shiftKey && caretAtStart(target)) {\n      event.preventDefault();\n      onBack();\n    }\n  };\n}\n"
    },
    {
      "path": "src/blocks/modal-stepper/payment-form.tsx",
      "type": "registry:file",
      "target": "blocks/wideset/modal-stepper/payment-form.tsx",
      "content": "'use client';\n\nimport { Checkbox } from '@/components/ui/wideset/checkbox/Checkbox';\nimport { FormField } from '@/components/ui/wideset/form-field/FormField';\nimport { Select } from '@/components/ui/wideset/select/Select';\nimport { TextInput } from '@/components/ui/wideset/text-input/TextInput';\nimport { type ChangeEvent, type FormEvent, useState } from 'react';\n\nimport { CardBrand } from './card-brand';\nimport { COUNTRIES, PRODUCT, ROUTES } from './data';\nimport { TextLink } from './text-link';\n\nexport type PaymentValues = {\n  number: string;\n  expiry: string;\n  cvc: string;\n  country: string;\n  zip: string;\n  email: string;\n  terms: boolean;\n};\n\ntype Field = keyof PaymentValues;\n\n/** Every field is required: what its error says when it is left empty. */\nconst REQUIRED: Record<Field, string> = {\n  number: 'Enter the card number.',\n  expiry: 'Enter the expiration date.',\n  cvc: 'Enter the security code.',\n  country: 'Choose a country.',\n  zip: 'Enter the ZIP code.',\n  email: 'Enter a billing e-mail.',\n  terms: 'Accept the terms to continue.',\n};\n\nconst filled = (value: string | boolean) =>\n  typeof value === 'string' ? value.trim() !== '' : value;\n\ntype PaymentFormProps = {\n  /** The form's id: the submit button sits in the modal's footer and points at it with `form`. */\n  id: string;\n  /** Called with the values once every field is filled. */\n  onSubmit: (values: PaymentValues) => void;\n};\n\n/**\n * The payment form: a card, where it is billed and the consent to charge it. Fields are\n * controlled; submitting names every empty field at the field and moves focus to the first. It\n * draws no button of its own, so the modal's footer can hold the actions. Nothing here talks to a\n * payment provider: swap the card fields for the provider's own when you connect one.\n */\nexport function PaymentForm({ id, onSubmit }: PaymentFormProps) {\n  const [values, setValues] = useState<PaymentValues>({\n    number: '',\n    expiry: '',\n    cvc: '',\n    country: COUNTRIES[0].value,\n    zip: '',\n    email: '',\n    terms: false,\n  });\n  const [errors, setErrors] = useState<Partial<Record<Field, string>>>({});\n\n  const set = <F extends Field>(field: F, value: PaymentValues[F]) => {\n    setValues((all) => ({ ...all, [field]: value }));\n    setErrors((all) => ({ ...all, [field]: undefined }));\n  };\n\n  const submit = (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault();\n    const empty = (Object.keys(REQUIRED) as Field[]).filter((field) => !filled(values[field]));\n    setErrors(Object.fromEntries(empty.map((field) => [field, REQUIRED[field]])));\n    if (empty.length) document.getElementById(`${id}-${empty[0]}`)?.focus();\n    else onSubmit(values);\n  };\n\n  /** What every text field shares: its id, value, change handler and error look. */\n  const text = (field: Exclude<Field, 'country' | 'terms'>) => ({\n    id: `${id}-${field}`,\n    name: field,\n    required: true,\n    value: values[field],\n    variant: errors[field] ? ('danger' as const) : ('primary' as const),\n    onChange: (event: ChangeEvent<HTMLInputElement>) => set(field, event.target.value),\n  });\n\n  return (\n    <form id={id} noValidate onSubmit={submit} className=\"gap-ws-11 flex flex-col\">\n      <FormField label=\"Card number\" htmlFor={`${id}-number`} errorText={errors.number}>\n        <TextInput\n          {...text('number')}\n          inputMode=\"numeric\"\n          autoComplete=\"cc-number\"\n          placeholder=\"1234 1234 1234 1234\"\n        >\n          <TextInput.Input />\n          <TextInput.Suffix>\n            <CardBrand />\n          </TextInput.Suffix>\n        </TextInput>\n      </FormField>\n      <div className=\"gap-ws-9 grid grid-cols-2\">\n        <FormField label=\"Expiration date\" htmlFor={`${id}-expiry`} errorText={errors.expiry}>\n          <TextInput\n            {...text('expiry')}\n            inputMode=\"numeric\"\n            autoComplete=\"cc-exp\"\n            placeholder=\"MM / YY\"\n          />\n        </FormField>\n        <FormField label=\"Security code\" htmlFor={`${id}-cvc`} errorText={errors.cvc}>\n          <TextInput {...text('cvc')} inputMode=\"numeric\" autoComplete=\"cc-csc\" placeholder=\"CVC\" />\n        </FormField>\n      </div>\n      <div className=\"gap-ws-9 grid grid-cols-2\">\n        <FormField\n          label=\"Country\"\n          htmlFor={`${id}-country`}\n          tooltip=\"Where the card is billed. It sets the tax on your invoices.\"\n          errorText={errors.country}\n        >\n          <Select\n            id={`${id}-country`}\n            name=\"country\"\n            className=\"w-full\"\n            options={COUNTRIES}\n            placeholder=\"Choose a country\"\n            clearable\n            required\n            value={values.country}\n            onValueChange={(value) => set('country', value)}\n            variant={errors.country ? 'danger' : 'primary'}\n          />\n        </FormField>\n        <FormField label=\"ZIP code\" htmlFor={`${id}-zip`} errorText={errors.zip}>\n          <TextInput {...text('zip')} autoComplete=\"postal-code\" placeholder=\"12345\" />\n        </FormField>\n      </div>\n      <FormField label=\"Billing email\" htmlFor={`${id}-email`} errorText={errors.email}>\n        <TextInput\n          {...text('email')}\n          type=\"email\"\n          autoComplete=\"email\"\n          placeholder=\"e.g. finance@lumenstudio.co\"\n        />\n      </FormField>\n      {/*\n        FormField draws the consent's error under the box. The checkbox carries its own label, so\n        the field's label row is empty: `gap-0` takes back the gap it would leave above the box.\n      */}\n      <FormField label={null} errorText={errors.terms} className=\"gap-0\">\n        <Checkbox\n          id={`${id}-terms`}\n          name=\"terms\"\n          required\n          checked={values.terms}\n          onCheckedChange={(checked) => set('terms', checked === true)}\n          variant={errors.terms ? 'danger' : 'primary'}\n        >\n          <Checkbox.Label>\n            I agree to the {PRODUCT} <TextLink href={ROUTES.terms}>Terms &amp; Conditions</TextLink>\n          </Checkbox.Label>\n        </Checkbox>\n      </FormField>\n    </form>\n  );\n}\n"
    },
    {
      "path": "src/blocks/modal-stepper/setup-account-modal.tsx",
      "type": "registry:file",
      "target": "blocks/wideset/modal-stepper/setup-account-modal.tsx",
      "content": "'use client';\n\nimport { Button } from '@/components/ui/wideset/button/Button';\nimport { Modal } from '@/components/ui/wideset/modal/Modal';\nimport { ProgressStepper } from '@/components/ui/wideset/progress-stepper/ProgressStepper';\nimport { useId, useState } from 'react';\n\nimport { PAYMENT_STEP, STEPS } from './data';\nimport { KeyboardHints, modalKeys } from './keyboard-hints';\nimport { PaymentForm } from './payment-form';\n\ntype SetupAccountModalProps = {\n  open: boolean;\n  onOpenChange: (open: boolean) => void;\n};\n\n/**\n * Figma's Modal `Type=Stepper`: a setup done in order. The steps run down the left with their\n * state (done, current, still ahead) and lead back to a finished one; the current step's heading,\n * form and actions sit beside them, and the keyboard hints run under both. Each step is a form\n * the footer's button submits by id, so a step moves on only once it is valid. Only the payment\n * step has its form here; the others are yours to fill. Up and Down move between the fields;\n * Left goes back a step, and from the first one back to the page.\n */\nexport function SetupAccountModal({ open, onOpenChange }: SetupAccountModalProps) {\n  const id = useId();\n  const [step, setStep] = useState(PAYMENT_STEP);\n  const next = () => (step < STEPS.length - 1 ? setStep(step + 1) : onOpenChange(false));\n\n  return (\n    <Modal open={open} onOpenChange={onOpenChange}>\n      <Modal.Content\n        className=\"ws-block-utility max-w-[60rem]\"\n        onOpenAutoFocus={(event) => {\n          // Start in the step's first field when it has one; otherwise the Modal picks.\n          const field = document.getElementById(`${id}-number`);\n          if (!field) return;\n          event.preventDefault();\n          field.focus();\n        }}\n        onKeyDown={modalKeys(() => (step > 0 ? setStep(step - 1) : onOpenChange(false)))}\n      >\n        <div className=\"flex min-h-0 flex-1\">\n          <nav\n            aria-labelledby={`${id}-setup`}\n            className=\"border-ws-static-base gap-ws-11 p-ws-11 flex w-[16.25rem] shrink-0 flex-col border-r\"\n          >\n            <p id={`${id}-setup`} className=\"typography-subtitle-xs text-ws-static-strong h-ws-13\">\n              Set up account\n            </p>\n            {/*\n              Composed, so each step can fill its row as in Figma (`w-full`: the array form sizes a\n              step to its title). A step ahead stays closed until the ones before it are done.\n            */}\n            <ProgressStepper orientation=\"vertical\" activeStep={step} onStepChange={setStep}>\n              {STEPS.map(({ title }, index) => (\n                <ProgressStepper.Step\n                  key={title}\n                  step={index}\n                  title={title}\n                  orientation=\"vertical\"\n                  status={index < step ? 'completed' : index === step ? 'active' : 'incomplete'}\n                  disabled={index > step}\n                  className=\"w-full\"\n                />\n              ))}\n            </ProgressStepper>\n          </nav>\n          <div className=\"flex min-w-0 flex-1 flex-col\">\n            {/* Figma's Header with Divider off: the form follows its heading without a line. */}\n            <Modal.Header className=\"border-b-0\">\n              <Modal.Title>{STEPS[step].title}</Modal.Title>\n              <Modal.Description>{STEPS[step].description}</Modal.Description>\n            </Modal.Header>\n            <Modal.Body>\n              {step === PAYMENT_STEP ? (\n                <PaymentForm id={id} onSubmit={next} />\n              ) : (\n                <form\n                  id={id}\n                  onSubmit={(event) => {\n                    event.preventDefault();\n                    next();\n                  }}\n                >\n                  <p className=\"typography-body-md text-ws-static-subtle\">Nothing here yet.</p>\n                </form>\n              )}\n            </Modal.Body>\n            <Modal.Footer className=\"items-center\">\n              <p className=\"typography-body-md text-ws-static-subtle mr-ws-9 min-w-0 flex-1 tabular-nums\">\n                Step {step + 1} of {STEPS.length}\n              </p>\n              <Modal.Close asChild>\n                <Button variant=\"secondary\" preset=\"border\">\n                  Cancel\n                </Button>\n              </Modal.Close>\n              <Button type=\"submit\" form={id}>\n                {step < STEPS.length - 1 ? 'Continue' : 'Finish setup'}\n              </Button>\n            </Modal.Footer>\n          </div>\n        </div>\n        <Modal.Footer variant=\"extension\" className=\"items-center\">\n          <KeyboardHints />\n        </Modal.Footer>\n      </Modal.Content>\n    </Modal>\n  );\n}\n"
    },
    {
      "path": "src/blocks/modal-stepper/text-link.tsx",
      "type": "registry:file",
      "target": "blocks/wideset/modal-stepper/text-link.tsx",
      "content": "'use client';\n\n// TODO(custom): a link inside a sentence; Wideset has no inline text link (LinkButton is a control with its own padding and height).\nimport { cn } from '@/lib/wideset/utils';\nimport type { AnchorHTMLAttributes } from 'react';\n\n/**\n * A link inside a sentence, as Figma draws the terms link: the sentence's own type in the primary\n * colour. The underline comes on hover and focus.\n */\nexport function TextLink({\n  className,\n  children,\n  ...props\n}: AnchorHTMLAttributes<HTMLAnchorElement>) {\n  return (\n    <a\n      className={cn(\n        'text-ws-dynamic-primary-default hover:text-ws-dynamic-primary-hover active:text-ws-dynamic-primary-pressed rounded-ws-control-sm focus-visible:wds-focus-visible outline-ws-dynamic-primary-strong-default decoration-from-font hover:underline focus-visible:underline',\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </a>\n  );\n}\n"
    }
  ],
  "meta": {
    "version": "1.1.0",
    "commit": "a734f9f0"
  }
}
