{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-time-picker",
  "type": "registry:ui",
  "title": "react-tw/time-picker.tsx",
  "description": "Carbon `TimePicker` as React + Tailwind components, the look of `<ui-time-picker>` on the headless `TimePicker`: a short 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/tw-field",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-skeleton",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/time-picker.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/time-picker.tsx",
      "content": "import { createContext, useContext, useMemo, type ChangeEvent, type ComponentProps, type ReactNode } from 'react';\nimport { TimePicker as TimePickerPrimitive } from '@purpurabog/ui/headless';\nimport { FieldLabel, FieldMessageLine, StatusIcon, fluidBoxClasses, fluidControlClasses, useFluid, useTextField, useFieldDisabled, fieldBoxClasses, fieldStateEdges, fieldDisabledState, fieldReadOnlyEdge, fieldInvalidRing, fieldTextSize } from './field.tsx';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\nimport { FluidSkeletonBox } from './skeleton.tsx';\n\n/**\n * Carbon `TimePicker` as React + Tailwind components, the look of `<ui-time-picker>` on the headless `TimePicker`: a short\n * \"hh:mm\" box in the code font (78px, 98.8px with a status icon) with `<TimePickerSelect>`s beside it,\n * 2px apart (AM / PM, time zone). Sizes sm 32 / md 40 (Carbon default) / lg 48px. Validation is the\n * app's (Carbon React): `pattern` (12-hour `h:mm` / `hh:mm` by default) takes part in the form's own\n * validation; set `invalid` + `invalidText` to show an error. `fluid` (or a `FluidForm` around it)\n * is Carbon `FluidTimePicker`: the box and each select as equal 64px columns, labels inside each.\n */\nexport type TimePickerSize = 'sm' | 'md' | 'lg';\n\n/** What the styled parts need to look right (a select also works on its own); the behaviour is the primitive's. */\ninterface TimePickerLookValue {\n    size: TimePickerSize;\n    readOnly: boolean;\n    fluid: boolean;\n}\n\nconst TimePickerContext = createContext<TimePickerLookValue>({ size: 'md', readOnly: false, fluid: false });\n\nconst HEIGHT = { sm: 'h-field-sm', md: 'h-field-md', lg: 'h-field-lg' } as const;\n\nexport interface TimePickerProps extends Omit<ComponentProps<'input'>, 'size'> {\n    label: ReactNode;\n    hideLabel?: boolean;\n    size?: TimePickerSize;\n    invalid?: boolean;\n    invalidText?: ReactNode;\n    warn?: boolean;\n    warnText?: ReactNode;\n    lang?: string;\n    /** `<TimePickerSelect>`s beside the box. */\n    children?: ReactNode;\n    /** Carbon `FluidTimePicker` (also set by `FluidForm`). */\n    fluid?: boolean;\n}\n\nexport function TimePicker({\n    label,\n    hideLabel,\n    size = 'md',\n    invalid,\n    invalidText,\n    warn,\n    warnText,\n    lang,\n    children,\n    className,\n    id,\n    value,\n    defaultValue,\n    onChange,\n    disabled: ownDisabled,\n    readOnly = false,\n    placeholder = 'hh:mm',\n    fluid: fluidProp,\n    ...rest\n}: Readonly<TimePickerProps>) {\n    const disabled = useFieldDisabled(ownDisabled);\n    const field = useTextField({ id, value, defaultValue, invalid, invalidText, warn, warnText, disabled, readOnly, lang });\n    const { message } = field;\n    const hasStatus = !!message && message.kind !== 'helper';\n    const fluid = useFluid(fluidProp);\n    const status = hasStatus ? message.kind : undefined;\n    const context = useMemo(() => ({ size, readOnly, fluid }), [size, readOnly, fluid]);\n    return (\n        <TimePickerPrimitive.Root disabled={disabled} readOnly={readOnly} invalid={field.showError}>\n            <TimePickerContext.Provider value={context}>\n                <div className={cn('block font-sans', fluid && fluidBoxClasses(status, readOnly), className)}>\n                    <FieldLabel htmlFor={field.id} hidden={hideLabel} disabled={disabled} fluid={fluid} className=\"block\">\n                        {label}\n                    </FieldLabel>\n                    {/* fluid: equal 64px columns that touch (the box, then each select) */}\n                    <div className={fluid ? 'grid auto-cols-[minmax(0,1fr)] grid-flow-col gap-0' : 'flex flex-wrap items-end gap-[2px]'}>\n                        <div className={cn('relative flex flex-col', fluid && 'static')}>\n                            <TimePickerPrimitive.Input\n                                {...rest}\n                                id={field.id}\n                                value={value}\n                                defaultValue={defaultValue}\n                                placeholder={placeholder}\n                                aria-describedby={field.messageId}\n                                onChange={(event: ChangeEvent<HTMLInputElement>) => {\n                                    field.onTyped(event.target.value);\n                                    onChange?.(event);\n                                }}\n                                className={cn(\n                                    'm-0 box-border flex items-center px-4',\n                                    // 78px (98.8px with a status icon) at Carbon's 14px; wider with a larger --ui-field-font-size, so \"12:59\" still fits\n                                    hasStatus ? 'w-[max(98.8px,calc(98.8em/14))]' : 'w-[max(78px,calc(78em/14))]',\n                                    HEIGHT[size],\n                                    fieldBoxClasses,\n                                    'text-ink type-code-lg',\n                                    fieldTextSize,\n                                    'outline-[length:var(--ui-field-focus-width,2px)] [outline-offset:calc(-1*var(--ui-field-focus-width,2px))] outline-transparent transition-[outline-color,background-color] duration-(--ui-duration-fast) ease-carbon',\n                                    'placeholder:text-ink-placeholder placeholder:opacity-100 focus:outline-focus focus:[box-shadow:var(--ui-field-focus-halo,none)]',\n                                    field.showError && fieldInvalidRing,\n                                    'disabled:cursor-not-allowed disabled:text-ink-disabled',\n                                    'read-only:not-disabled:bg-[var(--ui-field-readonly-background,transparent)]',\n                                    fieldStateEdges,\n                                    fluid && cn('h-16 w-full pt-8 pb-[13px] type-body-sm', fluidControlClasses(status)),\n                                )}\n                            />\n                            {/* fluid: static and untransformed, so the icon places itself against the box, in the message row */}\n                            <span className={cn('pointer-events-none flex place-items-center', fluid ? 'static' : 'absolute end-4 top-1/2 -translate-y-1/2')}>\n                                <StatusIcon kind={message?.kind} className={fluid ? 'absolute end-4 top-[72px]' : undefined} />\n                            </span>\n                        </div>\n                        {children}\n                    </div>\n                    <FieldMessageLine id={`${field.id}-message`} message={message} content={field.messageContent} disabled={disabled} fluid={fluid} />\n                </div>\n            </TimePickerContext.Provider>\n        </TimePickerPrimitive.Root>\n    );\n}\n\nexport interface TimePickerSelectProps extends Omit<ComponentProps<'select'>, 'size'> {\n    /** Accessible name (default: the translation's \"Open list of options\"). */\n    label?: string;\n    lang?: string;\n}\n\n/** Carbon `TimePickerSelect`: the compact native select beside the time box; size, read-only and disabled come from the picker. */\nexport function TimePickerSelect({ label, lang, className, children, ...rest }: Readonly<TimePickerSelectProps>) {\n    const picker = useContext(TimePickerContext);\n    const t = useTranslation(lang).field;\n    return (\n        <span className={cn('relative inline-flex justify-center font-sans', picker.fluid && 'block bg-surface-1', className)}>\n            <TimePickerPrimitive.Select\n                {...rest}\n                aria-label={label ?? t.timeSelect}\n                className={cn(\n                    'peer m-0 box-border w-auto min-w-0 cursor-pointer appearance-none ps-4 pe-12',\n                    HEIGHT[picker.size],\n                    fieldBoxClasses,\n                    'text-ink type-body-sm leading-none!',\n                    fieldTextSize,\n                    'outline-[length:var(--ui-field-focus-width,2px)] [outline-offset:calc(-1*var(--ui-field-focus-width,2px))] outline-transparent transition-[outline-color] duration-(--ui-duration-fast) ease-carbon focus:outline-focus focus:[box-shadow:var(--ui-field-focus-halo,none)]',\n                    'disabled:cursor-not-allowed disabled:text-ink-disabled',\n                    fieldDisabledState,\n                    picker.readOnly && cn('cursor-default bg-[var(--ui-field-readonly-background,transparent)]', fieldReadOnlyEdge),\n                    'forced-colors:border forced-colors:border-[FieldText]',\n                    // fluid: a 64px column, the value under its label\n                    picker.fluid && 'h-16 w-full bg-transparent pt-8 pe-8 pb-[13px] ps-4',\n                )}\n            >\n                {children}\n            </TimePickerPrimitive.Select>\n            <svg\n                viewBox=\"0 0 16 16\"\n                aria-hidden=\"true\"\n                className={cn('pointer-events-none absolute inset-y-0 end-4 h-full w-4 fill-ink peer-disabled:fill-icon-disabled', picker.readOnly && 'fill-icon-disabled', picker.fluid && 'top-[34px] bottom-auto end-3 h-4')}\n            >\n                <path d=\"M8 11 3 6l.7-.7L8 9.6l4.3-4.3.7.7z\" />\n            </svg>\n            {/* Carbon FluidTimePickerSelect: its own label inside the column (the select is named by aria-label) */}\n            {picker.fluid && label ? (\n                <span aria-hidden=\"true\" className=\"pointer-events-none absolute inset-x-4 top-[13px] overflow-hidden text-ellipsis whitespace-nowrap text-ink-muted type-caption\">\n                    {label}\n                </span>\n            ) : null}\n        </span>\n    );\n}\n\n/**\n * Carbon `FluidTimePickerSkeleton` (Carbon has no other time picker skeleton): the time box (25%), the AM / PM select\n * (25%) and the time zone select (50%), each a 64px fluid box with two bars; `isOnlyTwo` two halves. Hidden from assistive tech.\n */\nexport function TimePickerSkeleton({ isOnlyTwo = false, className, ...rest }: Readonly<ComponentProps<'div'> & { isOnlyTwo?: boolean }>) {\n    return (\n        <div {...rest} aria-hidden=\"true\" className={cn('flex h-16', className)}>\n            <FluidSkeletonBox className={isOnlyTwo ? 'w-1/2' : 'w-1/4'} />\n            <FluidSkeletonBox className={isOnlyTwo ? 'w-1/2' : 'w-1/4'} />\n            {isOnlyTwo ? null : <FluidSkeletonBox className=\"w-1/2\" />}\n        </div>\n    );\n}\n"
    }
  ]
}
