{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "onboarding",
  "title": "Onboarding",
  "description": "Primitives for first-run setup: a full-page frame with step progress and Back, Skip and Continue actions that moves focus to each new step, an invite list of email and role rows that splits pasted lists and checks for invalid and duplicate addresses, action rows for quick starts, and a URL slug helper.",
  "registryDependencies": [
    "button",
    "field",
    "input",
    "https://www.dashboardblocks.com/r/radix/option-select.json",
    "https://www.dashboardblocks.com/r/radix/forms.json",
    "https://www.dashboardblocks.com/r/radix/link.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/onboarding.tsx",
      "content": "'use client'\n\nimport { isEmail } from '@/registry/components/dashboardblocks/forms'\nimport { Link } from '@/registry/components/dashboardblocks/link'\nimport { OptionSelect } from '@/registry/components/dashboardblocks/option-select'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport {\n  type ClipboardEvent,\n  type FormEvent,\n  type ReactNode,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { FieldError } from '@/components/ui/field'\nimport { Input } from '@/components/ui/input'\n\nimport { cn } from '@/lib/utils'\n\ninterface OnboardingLayoutProps {\n  aside?: ReactNode\n  brand: ReactNode\n  children: ReactNode\n  className?: string\n  description?: ReactNode\n  footer?: ReactNode\n  /** Wraps the content and footer in a form, so Enter and a submit button in the footer run it. */\n  onSubmit?: (event: FormEvent<HTMLFormElement>) => void\n  progress?: ReactNode\n  step?: number | string\n  title: ReactNode\n}\n\nfunction OnboardingLayout({\n  aside,\n  brand,\n  children,\n  className,\n  description,\n  footer,\n  onSubmit,\n  progress,\n  step,\n  title,\n}: OnboardingLayoutProps) {\n  const headingRef = useRef<HTMLHeadingElement>(null)\n  const shownStep = useRef(step)\n\n  useEffect(() => {\n    if (shownStep.current === step) return\n    shownStep.current = step\n    headingRef.current?.focus()\n  }, [step])\n\n  const body = (\n    <>\n      {progress && <div className='mb-8'>{progress}</div>}\n      <div className='mb-8 flex flex-col gap-2'>\n        <h1\n          ref={headingRef}\n          tabIndex={-1}\n          className='text-xl font-semibold tracking-tight text-balance outline-none sm:text-2xl'\n        >\n          {title}\n        </h1>\n        {description && (\n          <p className='text-muted-foreground text-pretty'>{description}</p>\n        )}\n      </div>\n      <div className='flex-1'>{children}</div>\n      {footer && (\n        <div\n          data-floating-bar\n          className='bg-background sticky bottom-0 z-10 mt-8 border-t py-4'\n        >\n          {footer}\n        </div>\n      )}\n    </>\n  )\n  const bodyClassName =\n    'mx-auto flex w-full max-w-xl flex-1 flex-col pt-4 sm:mb-12 sm:flex-none sm:pt-10'\n\n  return (\n    <div className={cn('bg-background flex min-h-svh flex-col', className)}>\n      <header className='flex h-16 shrink-0 items-center justify-between gap-4 px-4 sm:px-6'>\n        <div className='flex min-w-0 items-center gap-2 text-sm font-medium'>{brand}</div>\n        {aside && (\n          <div className='text-muted-foreground flex min-w-0 items-center gap-3 text-sm'>\n            {aside}\n          </div>\n        )}\n      </header>\n      <main className='flex flex-1 flex-col px-4 sm:px-6'>\n        {onSubmit ? (\n          <form method='post' noValidate onSubmit={onSubmit} className={bodyClassName}>\n            {body}\n          </form>\n        ) : (\n          <div className={bodyClassName}>{body}</div>\n        )}\n      </main>\n    </div>\n  )\n}\n\ninterface OnboardingActionsProps {\n  /** @default 'Back' */\n  backLabel?: string\n  className?: string\n  /** @default 'Continue' */\n  continueLabel?: string\n  /** Leave out on the first step to hide Back. */\n  onBack?: () => void\n  /** Leave out to make Continue submit the form. */\n  onContinue?: () => void\n  /** Leave out to hide Skip. */\n  onSkip?: () => void\n  /** Disables the buttons and shows `pendingLabel` while the step saves. */\n  pending?: boolean\n  /** @default 'Saving' */\n  pendingLabel?: string\n  /** @default 'Skip for now' */\n  skipLabel?: string\n}\n\nfunction OnboardingActions({\n  backLabel = 'Back',\n  className,\n  continueLabel = 'Continue',\n  onBack,\n  onContinue,\n  onSkip,\n  pending = false,\n  pendingLabel = 'Saving',\n  skipLabel = 'Skip for now',\n}: OnboardingActionsProps) {\n  return (\n    <div className={cn('flex items-center gap-2', className)}>\n      {onBack && (\n        <Button type='button' variant='ghost' disabled={pending} onClick={onBack}>\n          {backLabel}\n        </Button>\n      )}\n      <div className='ml-auto flex items-center gap-2'>\n        {onSkip && (\n          <Button type='button' variant='ghost' disabled={pending} onClick={onSkip}>\n            {skipLabel}\n          </Button>\n        )}\n        <Button\n          type={onContinue ? 'button' : 'submit'}\n          disabled={pending}\n          onClick={onContinue}\n        >\n          {pending ? pendingLabel : continueLabel}\n          {!pending && (\n            <IconPlaceholder\n              lucide='ArrowRightIcon'\n              tabler='IconArrowRight'\n              hugeicons='ArrowRight01Icon'\n              phosphor='ArrowRightIcon'\n              remixicon='RiArrowRightLine'\n              data-icon='inline-end'\n            />\n          )}\n        </Button>\n      </div>\n    </div>\n  )\n}\n\ninterface Invite {\n  email: string\n  id: string\n  role: string\n}\n\ninterface InviteListProps {\n  /** @default 'Add another' */\n  addLabel?: string\n  className?: string\n  errors?: Partial<Record<string, string>>\n  /** Starts each email input's id, `${id}-${invite.id}`, so validation can focus a row. */\n  id?: string\n  max?: number\n  onValueChange: (invites: Invite[]) => void\n  /** @default 'name@company.com' */\n  placeholder?: string\n  roles: { label: string; value: string }[]\n  /** Keep at least one row. */\n  value: Invite[]\n}\n\nfunction InviteList({\n  addLabel = 'Add another',\n  className,\n  errors = {},\n  id,\n  max = 10,\n  onValueChange,\n  placeholder = 'name@company.com',\n  roles,\n  value,\n}: InviteListProps) {\n  const baseId = useId()\n  const created = useRef(0)\n  const focusNext = useRef<string | null>(null)\n  const [announcement, setAnnouncement] = useState('')\n\n  const emailId = (invite: Invite) => `${id ?? baseId}-${invite.id}`\n\n  useEffect(() => {\n    if (!focusNext.current) return\n    document.getElementById(focusNext.current)?.focus()\n    focusNext.current = null\n  }, [value])\n\n  function createInvite(email: string, role: string): Invite {\n    created.current += 1\n    return { email, id: `${baseId}-new-${created.current}`, role }\n  }\n\n  function update(index: number, change: Partial<Invite>) {\n    onValueChange(\n      value.map((invite, i) => (i === index ? { ...invite, ...change } : invite)),\n    )\n  }\n\n  function add() {\n    const role = value.at(-1)?.role ?? roles[0]?.value ?? ''\n    const invite = createInvite('', role)\n    focusNext.current = emailId(invite)\n    onValueChange([...value, invite])\n  }\n\n  function remove(index: number) {\n    const next = value.filter((_, i) => i !== index)\n    focusNext.current = emailId(next[Math.min(index, next.length - 1)])\n    onValueChange(next)\n    setAnnouncement(\n      value[index].email\n        ? `Removed ${value[index].email}`\n        : `Removed invite ${index + 1}`,\n    )\n  }\n\n  function paste(event: ClipboardEvent<HTMLInputElement>, index: number) {\n    const emails = event.clipboardData\n      .getData('text')\n      .split(/[\\s,;]+/)\n      .map((part) => part.replace(/^<|>$/g, ''))\n      .filter(Boolean)\n    if (emails.length < 2) return\n    event.preventDefault()\n    const current = value[index]\n    const room = max - value.length + 1\n    const added = emails\n      .slice(0, room)\n      .map((email, i) =>\n        i === 0 ? { ...current, email } : createInvite(email, current.role),\n      )\n    onValueChange([...value.slice(0, index), ...added, ...value.slice(index + 1)])\n    setAnnouncement(\n      emails.length > room\n        ? `Added ${added.length} of ${emails.length} addresses. You can invite up to ${max} people at once.`\n        : `Added ${added.length} addresses`,\n    )\n  }\n\n  return (\n    <div className={cn('@container', className)}>\n      <div className='grid grid-cols-[minmax(0,1fr)_6.5rem_auto] gap-x-2 gap-y-3 @sm:grid-cols-[minmax(0,1fr)_8rem_auto]'>\n        <span aria-hidden className='text-sm font-medium'>\n          Email\n        </span>\n        <span aria-hidden className='col-span-2 text-sm font-medium'>\n          Role\n        </span>\n        <ul className='col-span-full grid grid-cols-subgrid gap-y-3'>\n          {value.map((invite, index) => {\n            const inputId = emailId(invite)\n            const error = errors[invite.id]\n            const label = invite.email.trim() || `invite ${index + 1}`\n            return (\n              <li\n                key={invite.id}\n                className='col-span-full grid grid-cols-subgrid items-start gap-y-2'\n              >\n                <Input\n                  id={inputId}\n                  type='email'\n                  autoComplete='off'\n                  spellCheck={false}\n                  aria-label={`Email ${index + 1}`}\n                  aria-invalid={error ? true : undefined}\n                  aria-describedby={error ? `${inputId}-error` : undefined}\n                  placeholder={placeholder}\n                  value={invite.email}\n                  onChange={(event) => update(index, { email: event.target.value })}\n                  onPaste={(event) => paste(event, index)}\n                />\n                <OptionSelect\n                  className='w-full'\n                  aria-label={`Role for ${label}`}\n                  value={invite.role}\n                  options={roles}\n                  onValueChange={(role) => update(index, { role })}\n                />\n                <Button\n                  type='button'\n                  variant='ghost'\n                  size='icon'\n                  aria-label={`Remove ${label}`}\n                  className={cn(value.length === 1 && 'invisible')}\n                  onClick={() => remove(index)}\n                >\n                  <IconPlaceholder\n                    lucide='XIcon'\n                    tabler='IconX'\n                    hugeicons='Cancel01Icon'\n                    phosphor='XIcon'\n                    remixicon='RiCloseLine'\n                  />\n                </Button>\n                <FieldError id={`${inputId}-error`} className='col-span-full'>\n                  {error}\n                </FieldError>\n              </li>\n            )\n          })}\n        </ul>\n        <Button\n          type='button'\n          variant='outline'\n          size='sm'\n          className='col-span-full justify-self-start'\n          disabled={value.length >= max}\n          onClick={add}\n        >\n          <IconPlaceholder\n            lucide='PlusIcon'\n            tabler='IconPlus'\n            hugeicons='PlusSignIcon'\n            phosphor='PlusIcon'\n            remixicon='RiAddLine'\n            data-icon='inline-start'\n          />\n          {addLabel}\n        </Button>\n      </div>\n      <p role='status' className='sr-only'>\n        {announcement}\n      </p>\n    </div>\n  )\n}\n\nfunction getInviteErrors(\n  invites: Invite[],\n  {\n    invited = [],\n    members = [],\n    workspaceName = 'the workspace',\n  }: { invited?: string[]; members?: string[]; workspaceName?: string } = {},\n) {\n  const errors: Partial<Record<string, string>> = {}\n  const memberEmails = new Set(members.map((email) => email.toLowerCase()))\n  const invitedEmails = new Set(invited.map((email) => email.toLowerCase()))\n  const seen = new Set<string>()\n  for (const invite of invites) {\n    const email = invite.email.trim().toLowerCase()\n    if (!email) continue\n    if (!isEmail(email)) {\n      errors[invite.id] = 'Enter an email address like name@example.com.'\n    } else if (memberEmails.has(email)) {\n      errors[invite.id] = `${invite.email.trim()} is already in ${workspaceName}.`\n    } else if (invitedEmails.has(email)) {\n      errors[invite.id] = `${invite.email.trim()} already has an invite waiting.`\n    } else if (seen.has(email)) {\n      errors[invite.id] = 'You’ve already added this address.'\n    }\n    seen.add(email)\n  }\n  return errors\n}\n\nfunction getFilledInvites(invites: Invite[]) {\n  return invites\n    .map((invite) => ({ ...invite, email: invite.email.trim() }))\n    .filter((invite) => invite.email)\n}\n\ninterface ActionCardProps {\n  badge?: ReactNode\n  className?: string\n  description?: ReactNode\n  href?: string\n  icon?: ReactNode\n  meta?: ReactNode\n  onClick?: () => void\n  title: string\n}\n\nfunction ActionCard({\n  badge,\n  className,\n  description,\n  href,\n  icon,\n  meta,\n  onClick,\n  title,\n}: ActionCardProps) {\n  const id = useId()\n  const target = (\n    <>\n      <span aria-hidden className='absolute inset-0' />\n      {title}\n    </>\n  )\n  const describedBy = description ? `${id}-description` : undefined\n  return (\n    <div\n      data-slot='action-card'\n      className={cn(\n        'group/action has-[:focus-visible]:ring-ring/50 relative flex h-full items-start gap-3 border-t pt-3 pb-1 has-[:focus-visible]:ring-3',\n        className,\n      )}\n    >\n      {icon && (\n        <span\n          aria-hidden\n          className='text-muted-foreground group-hover/action:text-foreground mt-0.5 flex shrink-0 transition-colors [&_svg]:size-5'\n        >\n          {icon}\n        </span>\n      )}\n      <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n        <span className='flex flex-wrap items-baseline gap-x-2'>\n          {href ? (\n            <Link\n              href={href}\n              onClick={onClick}\n              aria-describedby={describedBy}\n              className='text-sm font-medium underline-offset-4 outline-none group-hover/action:underline'\n            >\n              {target}\n            </Link>\n          ) : (\n            <button\n              type='button'\n              onClick={onClick}\n              aria-describedby={describedBy}\n              className='text-left text-sm font-medium underline-offset-4 outline-none group-hover/action:underline'\n            >\n              {target}\n            </button>\n          )}\n          {badge && <span className='text-muted-foreground text-xs'>{badge}</span>}\n        </span>\n        {description && (\n          <p id={describedBy} className='text-muted-foreground text-sm text-pretty'>\n            {description}\n          </p>\n        )}\n        {meta && <p className='text-muted-foreground text-sm'>{meta}</p>}\n      </div>\n      <IconPlaceholder\n        lucide='ArrowRightIcon'\n        tabler='IconArrowRight'\n        hugeicons='ArrowRight01Icon'\n        phosphor='ArrowRightIcon'\n        remixicon='RiArrowRightLine'\n        aria-hidden\n        className='text-muted-foreground group-hover/action:text-foreground mt-0.5 size-4 shrink-0 transition-[color,translate] group-hover/action:translate-x-0.5 motion-reduce:transition-none'\n      />\n    </div>\n  )\n}\n\n/** \"Fernhill & Co.\" → \"fernhill-co\": lowercase letters, numbers and single dashes, for a URL. */\nfunction slugify(text: string, maxLength = 32) {\n  return text\n    .normalize('NFKD')\n    .replace(/[̀-ͯ]/g, '')\n    .toLowerCase()\n    .replace(/[^a-z0-9]+/g, '-')\n    .slice(0, maxLength)\n    .replace(/^-+|-+$/g, '')\n}\n\nexport {\n  ActionCard,\n  getFilledInvites,\n  getInviteErrors,\n  InviteList,\n  OnboardingActions,\n  OnboardingLayout,\n  slugify,\n}\n\nexport type {\n  ActionCardProps,\n  Invite,\n  InviteListProps,\n  OnboardingActionsProps,\n  OnboardingLayoutProps,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/onboarding.tsx"
    }
  ],
  "type": "registry:component"
}
