{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings",
  "title": "Settings",
  "description": "Primitives for settings pages: owner, admin, member and viewer roles with what each can do and a menu to pick one, a row that puts a label and description beside its control, connected, needs attention, paused and not connected statuses each with an icon and label, secret masking, a copy button that announces itself, and relative and UTC date formatting.",
  "registryDependencies": [
    "button",
    "dropdown-menu",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/settings.tsx",
      "content": "'use client'\n\nimport {\n  StatusLabel,\n  type StatusTone,\n} from '@/registry/components/dashboardblocks/status-label'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { type ComponentProps, type ReactNode, useEffect, useRef, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuGroup,\n  DropdownMenuLabel,\n  DropdownMenuRadioGroup,\n  DropdownMenuRadioItem,\n  DropdownMenuTrigger,\n} from '@/components/ui/dropdown-menu'\n\nimport { cn } from '@/lib/utils'\n\ntype Role = 'owner' | 'admin' | 'member' | 'viewer'\n\nconst roleConfig: Record<Role, { description: string; label: string }> = {\n  admin: { description: 'Manage members, billing and settings', label: 'Admin' },\n  member: { description: 'Create and edit dashboards', label: 'Member' },\n  owner: { description: 'Full access, including deleting the workspace', label: 'Owner' },\n  viewer: { description: 'View dashboards only', label: 'Viewer' },\n}\n\nconst roleOrder: Role[] = ['owner', 'admin', 'member', 'viewer']\n\ninterface RoleMenuProps {\n  className?: string\n  label: string\n  onValueChange: (role: Role) => void\n  /** @default ['admin', 'member', 'viewer'] */\n  roles?: Role[]\n  value: Role\n}\n\nfunction RoleMenu({\n  className,\n  label,\n  onValueChange,\n  roles = ['admin', 'member', 'viewer'],\n  value,\n}: RoleMenuProps) {\n  return (\n    <DropdownMenu modal={false}>\n      <DropdownMenuTrigger asChild>\n        <Button\n          variant='outline'\n          size='sm'\n          className={cn('justify-between', className)}\n          aria-label={`${label}: ${roleConfig[value].label}`}\n        >\n          {roleConfig[value].label}\n          <IconPlaceholder\n            lucide='ChevronDownIcon'\n            tabler='IconChevronDown'\n            hugeicons='ArrowDownIcon'\n            phosphor='CaretDownIcon'\n            remixicon='RiArrowDownSLine'\n            data-icon='inline-end'\n          />\n        </Button>\n      </DropdownMenuTrigger>\n      <DropdownMenuContent align='end' className='w-64'>\n        <DropdownMenuGroup>\n          <DropdownMenuLabel>Role</DropdownMenuLabel>\n          <DropdownMenuRadioGroup\n            value={value}\n            onValueChange={(next) => onValueChange(next as Role)}\n          >\n            {roles.map((role) => (\n              <DropdownMenuRadioItem key={role} value={role}>\n                <span className='flex flex-col gap-0.5'>\n                  <span>{roleConfig[role].label}</span>\n                  <span className='text-muted-foreground text-xs'>\n                    {roleConfig[role].description}\n                  </span>\n                </span>\n              </DropdownMenuRadioItem>\n            ))}\n          </DropdownMenuRadioGroup>\n        </DropdownMenuGroup>\n      </DropdownMenuContent>\n    </DropdownMenu>\n  )\n}\n\ninterface SettingsRowProps {\n  children: ReactNode\n  className?: string\n  description?: ReactNode\n  /** Give the control `aria-labelledby` this id, or `aria-describedby` for the description. */\n  id?: string\n  label: ReactNode\n}\n\nfunction SettingsRow({ children, className, description, id, label }: SettingsRowProps) {\n  return (\n    <div\n      className={cn(\n        'flex flex-col gap-3 @md:flex-row @md:items-center @md:justify-between @md:gap-6',\n        className,\n      )}\n    >\n      <div className='flex min-w-0 flex-col gap-0.5'>\n        <span id={id} className='text-sm font-medium'>\n          {label}\n        </span>\n        {description && (\n          <span\n            id={id ? `${id}-description` : undefined}\n            className='text-muted-foreground text-sm break-words'\n          >\n            {description}\n          </span>\n        )}\n      </div>\n      <div className='flex shrink-0 items-center gap-2'>{children}</div>\n    </div>\n  )\n}\n\ntype ConnectionStatus =\n  | 'connected'\n  | 'disconnected'\n  | 'error'\n  | 'importing'\n  | 'paused'\n  | 'revoked'\n\nconst connectionStatusConfig: Record<\n  ConnectionStatus,\n  { icon: ReactNode; label: string; tone: StatusTone }\n> = {\n  connected: {\n    tone: 'good',\n    icon: (\n      <IconPlaceholder\n        lucide='CircleCheckIcon'\n        tabler='IconCircleCheck'\n        hugeicons='CheckmarkCircle02Icon'\n        phosphor='CheckCircleIcon'\n        remixicon='RiCheckboxCircleLine'\n        aria-hidden\n      />\n    ),\n    label: 'Connected',\n  },\n  disconnected: {\n    tone: 'neutral',\n    icon: (\n      <IconPlaceholder\n        lucide='CircleDashedIcon'\n        tabler='IconCircleDashed'\n        hugeicons='DashedLineCircleIcon'\n        phosphor='CircleDashedIcon'\n        remixicon='RiLoaderLine'\n        aria-hidden\n      />\n    ),\n    label: 'Not connected',\n  },\n  error: {\n    tone: 'bad',\n    icon: (\n      <IconPlaceholder\n        lucide='TriangleAlertIcon'\n        tabler='IconAlertTriangle'\n        hugeicons='Alert02Icon'\n        phosphor='WarningIcon'\n        remixicon='RiErrorWarningLine'\n        aria-hidden\n      />\n    ),\n    label: 'Needs attention',\n  },\n  importing: {\n    tone: 'info',\n    icon: (\n      <IconPlaceholder\n        lucide='Loader2Icon'\n        tabler='IconLoader'\n        hugeicons='Loading03Icon'\n        phosphor='SpinnerIcon'\n        remixicon='RiLoaderLine'\n        aria-hidden\n        className='animate-spin motion-reduce:animate-none'\n      />\n    ),\n    label: 'Importing',\n  },\n  paused: {\n    tone: 'warning',\n    icon: (\n      <IconPlaceholder\n        lucide='CirclePauseIcon'\n        tabler='IconPlayerPause'\n        hugeicons='PauseIcon'\n        phosphor='PauseCircleIcon'\n        remixicon='RiPauseCircleLine'\n        aria-hidden\n      />\n    ),\n    label: 'Paused',\n  },\n  revoked: {\n    tone: 'bad',\n    icon: (\n      <IconPlaceholder\n        lucide='UnlinkIcon'\n        tabler='IconUnlink'\n        hugeicons='Unlink01Icon'\n        phosphor='LinkBreakIcon'\n        remixicon='RiLinkUnlink'\n        aria-hidden\n      />\n    ),\n    label: 'Access removed',\n  },\n}\n\nfunction ConnectionStatusLabel({\n  className,\n  label,\n  status,\n}: {\n  className?: string\n  label?: string\n  status: ConnectionStatus\n}) {\n  const config = connectionStatusConfig[status]\n  return (\n    <StatusLabel tone={config.tone} className={className} indicator={config.icon}>\n      {label ?? config.label}\n    </StatusLabel>\n  )\n}\n\ninterface ConnectionRowProps extends Omit<ComponentProps<'div'>, 'title'> {\n  /** Buttons for what can be done now: Connect, Reconnect, Disconnect. */\n  actions?: ReactNode\n  /** What it does, or what's wrong, in a sentence. */\n  description?: ReactNode\n  /** Drawn in a square at the start of the row. */\n  logo?: ReactNode\n  /** The service's name, or a link to its page. */\n  name: ReactNode\n  status: ConnectionStatus\n  /** In place of the status's own word, such as \"Signed out\" for `revoked`. */\n  statusLabel?: string\n}\n\nfunction ConnectionRow({\n  actions,\n  children,\n  className,\n  description,\n  logo,\n  name,\n  status,\n  statusLabel,\n  ...props\n}: ConnectionRowProps) {\n  return (\n    <div\n      data-slot='connection-row'\n      className={cn('flex flex-wrap items-start gap-x-3 gap-y-2 py-3', className)}\n      {...props}\n    >\n      {logo}\n      <div className='flex min-w-0 flex-1 basis-48 flex-col gap-0.5'>\n        <span className='flex flex-wrap items-baseline gap-x-2'>\n          <span className='min-w-0 text-sm font-medium'>{name}</span>\n          <ConnectionStatusLabel label={statusLabel} status={status} />\n        </span>\n        {description && (\n          <div className='text-muted-foreground in-data-open:text-foreground/70 text-sm text-pretty'>\n            {description}\n          </div>\n        )}\n        {children}\n      </div>\n      {actions && <div className='flex shrink-0 flex-wrap gap-2'>{actions}</div>}\n    </div>\n  )\n}\n\nfunction maskSecret(secret: string, prefixLength = 8) {\n  if (secret.length <= prefixLength + 4) return '••••'\n  return `${secret.slice(0, prefixLength)}…${secret.slice(-4)}`\n}\n\nfunction useCopyToClipboard(timeout = 2000) {\n  const [copied, setCopied] = useState(false)\n  const timer = useRef<ReturnType<typeof setTimeout>>(undefined)\n\n  useEffect(() => () => clearTimeout(timer.current), [])\n\n  const copy = async (text: string) => {\n    try {\n      await navigator.clipboard.writeText(text)\n    } catch {\n      return false\n    }\n    setCopied(true)\n    clearTimeout(timer.current)\n    timer.current = setTimeout(() => setCopied(false), timeout)\n    return true\n  }\n\n  return { copied, copy }\n}\n\nfunction CopyButton({\n  className,\n  label = 'Copy',\n  value,\n}: {\n  className?: string\n  label?: string\n  value: string\n}) {\n  const { copied, copy } = useCopyToClipboard()\n  return (\n    <Button\n      type='button'\n      variant='ghost'\n      size='icon-sm'\n      className={className}\n      aria-label={label}\n      onClick={() => void copy(value)}\n    >\n      {copied ? (\n        <IconPlaceholder\n          lucide='CheckIcon'\n          tabler='IconCheck'\n          hugeicons='Tick02Icon'\n          phosphor='CheckIcon'\n          remixicon='RiCheckLine'\n          aria-hidden\n        />\n      ) : (\n        <IconPlaceholder\n          lucide='CopyIcon'\n          tabler='IconCopy'\n          hugeicons='Copy01Icon'\n          phosphor='CopyIcon'\n          remixicon='RiFileCopyLine'\n          aria-hidden\n        />\n      )}\n      <span role='status' className='sr-only'>\n        {copied ? 'Copied' : ''}\n      </span>\n    </Button>\n  )\n}\n\nfunction daysBetween(from: Date, to: Date) {\n  return Math.floor((to.getTime() - from.getTime()) / 86_400_000)\n}\n\nexport {\n  ConnectionRow,\n  ConnectionStatusLabel,\n  CopyButton,\n  RoleMenu,\n  SettingsRow,\n  connectionStatusConfig,\n  daysBetween,\n  maskSecret,\n  roleConfig,\n  roleOrder,\n  useCopyToClipboard,\n}\n\nexport type {\n  ConnectionRowProps,\n  ConnectionStatus,\n  Role,\n  RoleMenuProps,\n  SettingsRowProps,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/settings.tsx"
    }
  ],
  "type": "registry:component"
}
