{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-truncated-text",
  "type": "registry:ui",
  "title": "react-tw/truncated-text.tsx",
  "description": "Carbon for IBM Products `TruncatedText` as React + Tailwind, the look and rules of `<ui-truncated-text>`: `value` cut Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/core-position",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-tooltip",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/truncated-text.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/truncated-text.tsx",
      "content": "import type { ComponentProps } from 'react';\nimport type { Placement } from '../core/position.ts';\nimport { TruncatedText as TruncatedPrimitive } from '@purpurabog/ui/headless';\nimport { Tooltip } from './tooltip.tsx';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\n\nexport type TruncatedTextType = 'tooltip' | 'expand';\n\nexport interface TruncatedTextProps extends Omit<ComponentProps<'div'>, 'children'> {\n    /** The text. */\n    value: string;\n    /** Lines shown before the ellipsis; 0 = all. */\n    lines?: number;\n    /** What a truncated text offers: the whole text in a tooltip, or a toggle that expands it. */\n    type?: TruncatedTextType;\n    /** The tooltip's side (Carbon `align`). */\n    placement?: Placement;\n    /** The expand toggle's text (default \"View more\", translated). */\n    expandLabel?: string;\n    /** The collapse toggle's text (default \"View less\", translated). */\n    collapseLabel?: string;\n    /** Controlled: whether an expandable text shows in full. */\n    expanded?: boolean;\n    defaultExpanded?: boolean;\n    onExpandedChange?: (expanded: boolean) => void;\n    lang?: string;\n}\n\nconst CONTENT = 'overflow-hidden text-clip whitespace-normal line-clamp-(--truncated-text-lines)';\nconst FOCUS = 'focus-visible:rounded-[var(--ui-link-focus-radius,0px)] focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:[outline-offset:var(--ui-focus-offset,-2px)] focus-visible:outline-focus focus-visible:outline-solid';\n\n/**\n * Carbon for IBM Products `TruncatedText` as React + Tailwind, the look and rules of `<ui-truncated-text>`: `value` cut\n * to `lines` lines with an ellipsis. Only when it doesn't fit: `type=\"tooltip\"` makes it a button showing the whole\n * text in a tooltip (and named by it); `type=\"expand\"` adds a \"View more\" / \"View less\" toggle under it that opens\n * the rest, animating the height. The text takes the font of where it sits. The behaviour is the headless TruncatedText.\n */\nexport function TruncatedText({ value, lines = 2, type = 'tooltip', placement = 'top', expandLabel, collapseLabel, expanded, defaultExpanded = false, onExpandedChange, lang, className, ...rest }: Readonly<TruncatedTextProps>) {\n    return (\n        <TruncatedPrimitive.Root {...rest} value={value} lines={lines} expanded={expanded} defaultExpanded={defaultExpanded} onExpandedChange={onExpandedChange} className={cn('block w-full', className)}>\n            <TruncatedBody type={type} placement={placement} expandLabel={expandLabel} collapseLabel={collapseLabel} lang={lang} />\n        </TruncatedPrimitive.Root>\n    );\n}\n\n/** The text (a tooltip button around it when cut) and the expand toggle, inside the primitive (they follow its state). */\nfunction TruncatedBody({ type, placement, expandLabel, collapseLabel, lang }: Readonly<Required<Pick<TruncatedTextProps, 'type' | 'placement'>> & Pick<TruncatedTextProps, 'expandLabel' | 'collapseLabel' | 'lang'>>) {\n    const t = useTranslation(lang).common;\n    const { value, overflowing, expanded } = TruncatedPrimitive.useTruncatedTextContext();\n    const text = <TruncatedPrimitive.Content className={CONTENT} />;\n    let body = text;\n    if (type === 'tooltip' && overflowing) {\n        body = (\n            <Tooltip text={value} asLabel placement={placement} className=\"block\">\n                <button type=\"button\" className={cn('block w-full cursor-default border-0 bg-transparent p-0 text-inherit [font:inherit] [text-align:inherit] tracking-[inherit]', FOCUS)}>\n                    {text}\n                </button>\n            </Tooltip>\n        );\n    }\n    return (\n        <>\n            {body}\n            {type === 'expand' ? (\n                <TruncatedPrimitive.Toggle className={cn('cursor-pointer border-none bg-transparent px-0.5 py-0 text-link [font:inherit] tracking-[inherit]', FOCUS)}>\n                    {expanded ? collapseLabel || t.viewLess : expandLabel || t.viewMore}\n                </TruncatedPrimitive.Toggle>\n            ) : null}\n        </>\n    );\n}\n"
    }
  ]
}
