{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "consequences",
  "title": "Consequences",
  "description": "A list of what a confirmation will remove, with counts and names that collapse to \"and N more\". Pass it to TypeToConfirm or ConfirmDialog through their consequences prop.",
  "files": [
    {
      "path": "components/ui/sureui/consequences.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ntype ConsequencesVariant = \"default\" | \"destructive\"\n\nfunction mutedText(variant?: ConsequencesVariant) {\n  return variant === \"destructive\"\n    ? \"text-[color-mix(in_oklab,var(--muted-foreground)_85%,var(--foreground))]\"\n    : \"text-muted-foreground\"\n}\n\ninterface ConsequencesListOptions {\n  limit?: number\n  expandable?: boolean\n  moreLabel?: (hidden: number) => string\n  lessLabel?: string\n}\n\ninterface Consequence {\n  label: React.ReactNode\n  count?: number\n  from?: React.ReactNode\n  to?: React.ReactNode\n  names?: string[]\n  icon?: React.ReactNode\n  description?: React.ReactNode\n}\n\ninterface ConsequencesItemProps\n  extends Omit<React.ComponentProps<\"li\">, \"children\">, Consequence {}\n\ninterface ConsequencesProps\n  extends Omit<React.ComponentProps<\"div\">, \"title\">, ConsequencesListOptions {\n  subject?: React.ReactNode\n  subjectDescription?: React.ReactNode\n  title?: React.ReactNode\n  items?: Consequence[]\n  variant?: \"default\" | \"destructive\"\n  children?: React.ReactNode\n}\n\nconst defaults = {\n  limit: 3,\n  expandable: true,\n  moreLabel: (hidden: number) => `and ${hidden} more`,\n  lessLabel: \"Show less\",\n}\n\nconst ConsequencesContext = React.createContext<\n  Required<ConsequencesListOptions> & { variant: ConsequencesVariant }\n>({ ...defaults, variant: \"default\" })\n\nfunction Consequences(props: ConsequencesProps) {\n  const {\n    subject,\n    subjectDescription,\n    title,\n    items,\n    variant = \"default\",\n    limit = defaults.limit,\n    expandable = defaults.expandable,\n    moreLabel = defaults.moreLabel,\n    lessLabel = defaults.lessLabel,\n    className,\n    children,\n    ...rest\n  } = props\n  const titleId = React.useId()\n\n  return (\n    <ConsequencesContext.Provider\n      value={{ limit, expandable, moreLabel, lessLabel, variant }}\n    >\n      <div\n        data-slot=\"consequences\"\n        data-variant={variant}\n        className={cn(\n          \"overflow-hidden rounded-xl bg-card text-sm text-card-foreground ring-1 ring-foreground/10\",\n          variant === \"destructive\" &&\n            \"bg-destructive/3 ring-destructive/20 dark:bg-destructive/5\",\n          className\n        )}\n        {...rest}\n      >\n        {subject && (\n          <div\n            data-slot=\"consequences-subject\"\n            className=\"grid gap-0.5 border-b px-3 py-2.5\"\n          >\n            <div className=\"leading-5 font-medium break-words\">{subject}</div>\n            {subjectDescription && (\n              <div\n                className={cn(\n                  \"text-xs leading-4 text-pretty\",\n                  mutedText(variant)\n                )}\n              >\n                {subjectDescription}\n              </div>\n            )}\n          </div>\n        )}\n        {title && (\n          <div\n            id={titleId}\n            data-slot=\"consequences-title\"\n            className={cn(\n              \"border-b bg-muted/50 px-3 py-2 font-medium\",\n              variant === \"destructive\" &&\n                \"border-destructive/15 bg-destructive/10 text-[color-mix(in_oklab,var(--destructive)_80%,var(--foreground))] dark:bg-destructive/20\"\n            )}\n          >\n            {title}\n          </div>\n        )}\n        <ul\n          role=\"list\"\n          data-slot=\"consequences-list\"\n          aria-labelledby={title ? titleId : undefined}\n          className={cn(\n            \"divide-y\",\n            variant === \"destructive\" && \"divide-destructive/12\"\n          )}\n        >\n          {items?.map((item, index) => (\n            <ConsequencesItem key={index} {...item} />\n          ))}\n          {children}\n        </ul>\n      </div>\n    </ConsequencesContext.Provider>\n  )\n}\n\nfunction ConsequencesItem(props: ConsequencesItemProps) {\n  const {\n    label,\n    count,\n    from,\n    to,\n    names = [],\n    icon,\n    description,\n    className,\n    ...rest\n  } = props\n  const context = React.useContext(ConsequencesContext)\n  const [expanded, setExpanded] = React.useState(false)\n  const namesId = React.useId()\n  const max = Math.max(0, context.limit)\n  const canExpand = context.expandable && names.length > max\n  const shown = expanded ? names : names.slice(0, max)\n  const hidden =\n    names.length > 0 ? Math.max(count ?? 0, names.length) - shown.length : 0\n  const more = context.moreLabel\n\n  const total = count ?? (names.length > 0 ? names.length : undefined)\n  const hasNames = shown.length > 0 || hidden > 0\n\n  return (\n    <li\n      data-slot=\"consequences-item\"\n      className={cn(\n        \"grid gap-x-3 gap-y-0.5 px-3 py-2.5\",\n        icon\n          ? \"grid-cols-[auto_minmax(0,1fr)_auto]\"\n          : \"grid-cols-[minmax(0,1fr)_auto]\",\n        className\n      )}\n      {...rest}\n    >\n      {icon && (\n        <span\n          aria-hidden=\"true\"\n          className={cn(\n            \"col-start-1 row-span-3 row-start-1 flex h-5 items-center text-muted-foreground [&_svg]:size-4\",\n            context.variant === \"destructive\" && \"text-destructive\"\n          )}\n        >\n          {icon}\n        </span>\n      )}\n      <span className={cn(\"leading-5\", icon ? \"col-start-2\" : \"col-start-1\")}>\n        {label}\n      </span>\n      {to !== undefined ? (\n        <span\n          data-slot=\"consequences-change\"\n          className={cn(\n            \"row-start-1 flex flex-wrap items-baseline justify-end gap-x-1.5 text-right leading-5\",\n            icon ? \"col-start-3\" : \"col-start-2\"\n          )}\n        >\n          {from !== undefined && (\n            <>\n              <span className=\"sr-only\">, from </span>\n              <span className={mutedText(context.variant)}>{from}</span>\n              <span aria-hidden=\"true\" className={mutedText(context.variant)}>\n                →\n              </span>\n            </>\n          )}\n          <span className=\"sr-only\">{from !== undefined ? \" to \" : \", \"}</span>\n          <span className=\"font-medium\">{to}</span>\n        </span>\n      ) : (\n        total !== undefined && (\n          <span\n            data-slot=\"consequences-count\"\n            className={cn(\n              \"row-start-1 text-right leading-5 font-medium tabular-nums\",\n              icon ? \"col-start-3\" : \"col-start-2\"\n            )}\n          >\n            <span className=\"sr-only\">, </span>\n            {total}\n          </span>\n        )\n      )}\n      {hasNames && <span className=\"sr-only\">: </span>}\n      {hasNames && (\n        <span\n          id={namesId}\n          data-slot=\"consequences-names\"\n          className={cn(\n            \"text-xs leading-4 text-pretty break-words\",\n            mutedText(context.variant),\n            icon ? \"col-start-2\" : \"col-start-1\"\n          )}\n        >\n          {shown.map((name, index) => (\n            <React.Fragment key={index}>\n              {index > 0 && \", \"}\n              <span className=\"whitespace-nowrap\">{name}</span>\n            </React.Fragment>\n          ))}\n          {hidden > 0 &&\n            !(canExpand && !expanded) &&\n            `${shown.length > 0 ? \" \" : \"\"}${more(hidden)}`}\n          {canExpand && (\n            <>\n              {\" \"}\n              <button\n                type=\"button\"\n                aria-expanded={expanded}\n                aria-controls={namesId}\n                className=\"rounded-sm py-1 font-medium text-foreground underline-offset-4 outline-none hover:underline focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n                onClick={() => setExpanded((open) => !open)}\n              >\n                {expanded ? context.lessLabel : more(hidden)}\n              </button>\n            </>\n          )}\n        </span>\n      )}\n      {description && (\n        <span\n          className={cn(\n            \"text-xs leading-4 text-pretty\",\n            mutedText(context.variant),\n            icon ? \"col-start-2\" : \"col-start-1\"\n          )}\n        >\n          {description}\n        </span>\n      )}\n    </li>\n  )\n}\n\nexport {\n  Consequences,\n  ConsequencesItem,\n  type Consequence,\n  type ConsequencesItemProps,\n  type ConsequencesProps,\n}\n",
      "type": "registry:ui",
      "target": "@ui/sureui/consequences.tsx"
    }
  ],
  "categories": [
    "confirmation",
    "list"
  ],
  "type": "registry:ui"
}