{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file-item",
  "type": "registry:ui",
  "title": "FileItem",
  "description": "One file in a list — thumbnail, title, a secondary line, and the trailing control: a spinner while loading, the remove button once done, the warning icon on error.",
  "dependencies": [
    "@remixicon/react@^4.9.0",
    "class-variance-authority@^0.7.1"
  ],
  "registryDependencies": [
    "https://wideset.co/r/icon-button.json",
    "https://wideset.co/r/motion.json",
    "https://wideset.co/r/styles.json",
    "https://wideset.co/r/thumbnail.json",
    "https://wideset.co/r/utils.json"
  ],
  "files": [
    {
      "path": "src/components/file-upload/FileItem.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/file-upload/FileItem.tsx",
      "content": "'use client';\n\nimport { RiDeleteBinLine, RiErrorWarningFill } from '@remixicon/react';\nimport { Children, forwardRef, isValidElement, type ReactNode } from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { useDefaultMotion } from '@/lib/wideset/motion/MotionProvider';\nimport { IconButton } from '../button/IconButton';\nimport type { FileItemProps, FileItemWithSubComponents } from './FileItem.types';\nimport { fileItemContentVariants, fileItemVariants } from './FileItem.variants';\nimport { FileItemDescription } from './FileItemDescription';\nimport { FileItemLoading } from './FileItemLoading';\nimport { FileItemThumbnail } from './FileItemThumbnail';\nimport { FileItemTitle } from './FileItemTitle';\n\ntype Slots = {\n  thumbnail: ReactNode[];\n  info: ReactNode[];\n  loading: ReactNode[];\n  /** Anything else — lands under the row, in the message area. */\n  rest: ReactNode[];\n  /** Plain-text title, for the remove button's default label. */\n  titleText?: string;\n};\n\n/**\n * Sorts children into Figma's slots by which part they are. Wrapping a part in\n * your own component hides it from this — pass the parts directly.\n */\nconst sortChildren = (children: ReactNode): Slots => {\n  const slots: Slots = { thumbnail: [], info: [], loading: [], rest: [] };\n\n  Children.toArray(children).forEach((child) => {\n    if (isValidElement(child)) {\n      if (child.type === FileItemThumbnail) return slots.thumbnail.push(child);\n      if (child.type === FileItemTitle) {\n        const text = (child.props as { children?: ReactNode }).children;\n        if (typeof text === 'string') slots.titleText = text;\n        return slots.info.push(child);\n      }\n      if (child.type === FileItemDescription) return slots.info.push(child);\n      if (child.type === FileItemLoading) return slots.loading.push(child);\n    }\n    slots.rest.push(child);\n  });\n\n  return slots;\n};\n\n/**\n * One file: thumbnail, title, a secondary line, and the trailing control — a\n * spinner while loading, the remove `IconButton` once done, the warning icon\n * on error.\n */\nconst FileItem = forwardRef<HTMLDivElement, FileItemProps>(\n  (\n    {\n      variant,\n      isLoading = false,\n      hasError = false,\n      error,\n      onRemove,\n      removeLabel,\n      defaultMotion,\n      className,\n      children,\n      ...props\n    },\n    ref,\n  ) => {\n    const motion = useDefaultMotion(defaultMotion);\n    const slots = sortChildren(children);\n    const isError = hasError || !!error;\n    // Error wins: a failed upload is not in flight, whatever `isLoading` says.\n    const loading = !isError && (isLoading || slots.loading.length > 0);\n    const state = isError ? 'error' : loading ? 'uploading' : 'success';\n    const showRemove = !loading && !!onRemove;\n    const showMessage = !!error || slots.rest.length > 0;\n\n    return (\n      <div\n        ref={ref}\n        data-slot=\"file-item\"\n        className={cn(fileItemVariants({ variant, state }), className)}\n        {...props}\n      >\n        <div className={fileItemContentVariants({ state })}>\n          {slots.thumbnail}\n\n          <div className=\"gap-ws-2 flex min-w-0 flex-1 flex-col\">{slots.info}</div>\n\n          {(loading || isError || showRemove) && (\n            <div className=\"gap-ws-7 flex shrink-0 items-center\">\n              {loading && (slots.loading.length > 0 ? slots.loading : <FileItemLoading />)}\n              {isError && (\n                <RiErrorWarningFill\n                  aria-hidden=\"true\"\n                  focusable=\"false\"\n                  className=\"size-ws-control-md text-ws-semantic-negative shrink-0\"\n                />\n              )}\n              {showRemove && (\n                // Figma: an `Icon Button` instance — Variant=Secondary, Style=Ghost, Size=Small.\n                <IconButton\n                  icon={RiDeleteBinLine}\n                  variant=\"secondary\"\n                  preset=\"ghost\"\n                  size=\"sm\"\n                  onClick={onRemove}\n                  defaultMotion={motion}\n                  aria-label={\n                    removeLabel ?? (slots.titleText ? `Remove ${slots.titleText}` : 'Remove file')\n                  }\n                />\n              )}\n            </div>\n          )}\n        </div>\n\n        {showMessage && (\n          <div className=\"gap-ws-3 flex flex-col\">\n            {error && (\n              <span className=\"typography-label-strong-sm text-ws-semantic-negative\">{error}</span>\n            )}\n            {slots.rest}\n          </div>\n        )}\n      </div>\n    );\n  },\n) as FileItemWithSubComponents;\n\nFileItem.displayName = 'FileItem';\nFileItem.Thumbnail = FileItemThumbnail;\nFileItem.Title = FileItemTitle;\nFileItem.Description = FileItemDescription;\nFileItem.Loading = FileItemLoading;\n\nexport { FileItem };\n"
    },
    {
      "path": "src/components/file-upload/FileItem.types.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/file-upload/FileItem.types.ts",
      "content": "import type { VariantProps } from 'class-variance-authority';\nimport type {\n  ComponentProps,\n  ForwardRefExoticComponent,\n  HTMLAttributes,\n  PropsWithoutRef,\n  ReactNode,\n  RefAttributes,\n} from 'react';\n\nimport type { MotionProps } from '@/lib/wideset/motion/Motion.types';\nimport type { ThumbnailProps } from '../thumbnail/Thumbnail.types';\nimport type { fileItemVariants } from './FileItem.variants';\nimport type { FileItemDescription } from './FileItemDescription';\nimport type { FileItemLoading } from './FileItemLoading';\nimport type { FileItemThumbnail } from './FileItemThumbnail';\nimport type { FileItemTitle } from './FileItemTitle';\n\n/** A file row with metadata and upload feedback. */\nexport type FileItemProps = ComponentProps<'div'> &\n  Pick<VariantProps<typeof fileItemVariants>, 'variant'> &\n  MotionProps & {\n    /**\n     * The upload is in flight: a spinner replaces the remove button and the\n     * row takes Figma's wider `Uploading` gap. Same as placing `FileItem.Loading`.\n     */\n    isLoading?: boolean;\n    /** The upload failed: danger tint (contained) and a warning icon. Figma's `Type=Error`. */\n    hasError?: boolean;\n    /** Error headline under the row, in the negative colour. Implies `hasError`. */\n    error?: ReactNode;\n    /** Shows the remove button (hidden while loading). */\n    onRemove?: () => void;\n    /** Accessible label for the remove button. Defaults to `Remove <title>`. */\n    removeLabel?: string;\n  };\n\n/** A file preview inferred from its name, MIME type, or explicit content. */\nexport type FileItemThumbnailProps = ThumbnailProps & {\n  /**\n   * File name. When no `type`, `src`, `text` or `icon` is given, the file\n   * kind is read off its extension — `report.pdf` shows the PDF tile.\n   */\n  name?: string;\n  /** MIME type of the file; takes precedence over the extension when inferring the kind. */\n  mimeType?: string;\n};\n\n/** The primary title text. */\nexport type FileItemTitleProps = HTMLAttributes<HTMLSpanElement>;\n\n/** Several children are separated by a thin vertical rule — `1.2 MB | 2 seconds left`. */\nexport type FileItemDescriptionProps = HTMLAttributes<HTMLSpanElement>;\n\n/** An upload-in-progress indicator. */\nexport type FileItemLoadingProps = HTMLAttributes<HTMLSpanElement>;\n\nexport type FileItemWithSubComponents = ForwardRefExoticComponent<\n  PropsWithoutRef<FileItemProps> & RefAttributes<HTMLDivElement>\n> & {\n  Thumbnail: typeof FileItemThumbnail;\n  Title: typeof FileItemTitle;\n  Description: typeof FileItemDescription;\n  Loading: typeof FileItemLoading;\n};\n"
    },
    {
      "path": "src/components/file-upload/FileItem.variants.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/file-upload/FileItem.variants.ts",
      "content": "import { cva } from 'class-variance-authority';\n\nexport const fileItemVariants = cva('gap-ws-7 flex flex-col', {\n  variants: {\n    variant: {\n      uncontained: '',\n      contained: 'rounded-ws-container-md py-ws-7 pr-ws-7 pl-ws-9',\n    },\n    state: {\n      uploading: '',\n      success: '',\n      error: '',\n    },\n  },\n  defaultVariants: {\n    variant: 'contained',\n    state: 'success',\n  },\n  compoundVariants: [\n    {\n      variant: 'contained',\n      state: 'uploading',\n      className: 'bg-ws-dynamic-tertiary-alpha-strong-default',\n    },\n    {\n      variant: 'contained',\n      state: 'success',\n      className: 'bg-ws-dynamic-tertiary-alpha-strong-default',\n    },\n    {\n      variant: 'contained',\n      state: 'error',\n      className: 'bg-ws-dynamic-danger-alpha-strong-default',\n    },\n  ],\n});\n\n/* The row gap is state-dependent in Figma: `Gap/9` (16px) while uploading,\n   `Gap/7` (12px) once the upload has settled into success or error. */\nexport const fileItemContentVariants = cva('flex items-center', {\n  variants: {\n    state: {\n      uploading: 'gap-ws-9',\n      success: 'gap-ws-7',\n      error: 'gap-ws-7',\n    },\n  },\n  defaultVariants: {\n    state: 'success',\n  },\n});\n"
    },
    {
      "path": "src/components/file-upload/FileItemDescription.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/file-upload/FileItemDescription.tsx",
      "content": "'use client';\n\nimport { Children, Fragment } from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport type { FileItemDescriptionProps } from './FileItem.types';\n\n/**\n * The secondary line under the title — size, time left. Each child is one\n * item; items are separated by Figma's 16px vertical rule.\n */\nexport const FileItemDescription = ({\n  className,\n  children,\n  ...props\n}: FileItemDescriptionProps) => {\n  const items = Children.toArray(children).filter((item) => item !== '');\n\n  return (\n    <span\n      data-slot=\"file-item-description\"\n      className={cn(\n        'typography-label-sm text-ws-static-subtle gap-ws-5 flex items-center',\n        className,\n      )}\n      {...props}\n    >\n      {items.map((item, index) => (\n        <Fragment key={index}>\n          {index > 0 && (\n            <span\n              aria-hidden=\"true\"\n              className=\"border-ws-static-base h-ws-9 w-0 shrink-0 border-l\"\n            />\n          )}\n          <span className=\"truncate\">{item}</span>\n        </Fragment>\n      ))}\n    </span>\n  );\n};\n\nFileItemDescription.displayName = 'FileItem.Description';\n"
    },
    {
      "path": "src/components/file-upload/FileItemLoading.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/file-upload/FileItemLoading.tsx",
      "content": "'use client';\n\nimport { cn } from '@/lib/wideset/utils';\n\nimport type { FileItemLoadingProps } from './FileItem.types';\nimport { FileItemSpinner } from './FileItemSpinner';\n\n/**\n * The upload spinner — a 16px glyph centred in the same 32px box the remove\n * button occupies, so the row's right edge does not shift when one replaces\n * the other. `FileItem` places it for you when `isLoading` is set.\n */\nexport const FileItemLoading = ({ className, ...props }: FileItemLoadingProps) => (\n  <span\n    data-slot=\"file-item-loading\"\n    className={cn('size-ws-14 flex shrink-0 items-center justify-center', className)}\n    {...props}\n  >\n    <FileItemSpinner\n      aria-hidden=\"true\"\n      focusable=\"false\"\n      className=\"size-ws-control-sm text-ws-dynamic-secondary-default animate-spin\"\n    />\n  </span>\n);\n\nFileItemLoading.displayName = 'FileItem.Loading';\n"
    },
    {
      "path": "src/components/file-upload/FileItemSpinner.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/file-upload/FileItemSpinner.tsx",
      "content": "'use client';\n\nimport type { SVGProps } from 'react';\n\n/**\n * Two-tone loading spinner: a 40%-opacity ring with a solid quarter arc on top.\n * Kept local because Remix Icon has no two-tone loader — every `Ri*` spinner is\n * a single flat shape, which reads very differently once it is animating.\n */\nconst FileItemSpinner = (props: SVGProps<SVGSVGElement>) => (\n  <svg\n    xmlns=\"http://www.w3.org/2000/svg\"\n    width=\"1em\"\n    height=\"1em\"\n    fill=\"none\"\n    viewBox=\"8 8 16 16\"\n    {...props}\n  >\n    <path\n      fill=\"currentColor\"\n      d=\"M16 24a8 8 0 1 1 8-8 8.01 8.01 0 0 1-8 8m0-14a6 6 0 1 0 0 12 6 6 0 0 0 0-12\"\n      opacity={0.4}\n    />\n    <path fill=\"currentColor\" d=\"M16 8v2a6.006 6.006 0 0 1 6 6h2a8.01 8.01 0 0 0-8-8\" />\n  </svg>\n);\n\nexport { FileItemSpinner };\n"
    },
    {
      "path": "src/components/file-upload/FileItemThumbnail.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/file-upload/FileItemThumbnail.tsx",
      "content": "'use client';\n\nimport { forwardRef } from 'react';\n\nimport { Thumbnail } from '../thumbnail/Thumbnail';\nimport { getThumbnailType } from '../thumbnail/Thumbnail.logic';\nimport type { ThumbnailProps } from '../thumbnail/Thumbnail.types';\nimport type { FileItemThumbnailProps } from './FileItem.types';\n\n/**\n * The tile at the start of the row — a `Thumbnail` at Figma's 32px (`lg`).\n * Hand it the file `name` and the kind is read off the extension; or pass any\n * `Thumbnail` content prop (`src`, `type`, `icon`, `text`) to pin it.\n */\nexport const FileItemThumbnail = forwardRef<HTMLDivElement, FileItemThumbnailProps>(\n  ({ name, mimeType, size = 'lg', ...props }, ref) => {\n    const { type, src, text, icon } = props;\n    const inferred =\n      !type && !src && text === undefined && !icon && name\n        ? getThumbnailType(name, mimeType)\n        : undefined;\n    const thumbnailProps = (inferred ? { ...props, type: inferred } : props) as ThumbnailProps;\n\n    return <Thumbnail ref={ref} data-slot=\"file-item-thumbnail\" size={size} {...thumbnailProps} />;\n  },\n);\n\nFileItemThumbnail.displayName = 'FileItem.Thumbnail';\n"
    },
    {
      "path": "src/components/file-upload/FileItemTitle.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/file-upload/FileItemTitle.tsx",
      "content": "'use client';\n\nimport { cn } from '@/lib/wideset/utils';\n\nimport type { FileItemTitleProps } from './FileItem.types';\n\n/** The file name. `Label/Strong/Small` in `Static/Text/Strong`, truncated on one line. */\nexport const FileItemTitle = ({ className, ...props }: FileItemTitleProps) => (\n  <span\n    data-slot=\"file-item-title\"\n    className={cn('typography-label-strong-sm text-ws-static-strong truncate', className)}\n    {...props}\n  />\n);\n\nFileItemTitle.displayName = 'FileItem.Title';\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "commit": "8bb3627"
  }
}
