{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "timezone-select",
  "type": "registry:ui",
  "title": "Timezone select",
  "description": "React time zone picker on Base UI Combobox: search by city, UTC offset or abbreviation, live local times, region groups and the user's zone pinned on top.",
  "author": "MiniDev UI <https://ui.minidev.pro>",
  "dependencies": [
    "@base-ui/react",
    "lucide-react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/ui/timezone-select.tsx",
      "type": "registry:ui",
      "target": "components/ui/timezone-select.tsx",
      "content": "\"use client\"\nimport * as React from \"react\"\nimport { Combobox as ComboboxPrimitive } from \"@base-ui/react/combobox\"\nimport { CheckIcon, ChevronsUpDownIcon } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\n\n/**\n * TimezoneSelect — a searchable IANA time zone picker that shows each zone's UTC offset and current local time.\n *\n * Use it in scheduling, settings and onboarding forms. Search by city (\"new york\"), zone id\n * (\"america/\"), offset (\"+5:30\", \"-8\") or abbreviation (\"PST\"). The user's own zone is pinned at\n * the top as Detected and is the default value. All data comes from the browser's `Intl` API, so\n * there is no time zone file to ship or update. Built on Base UI Combobox; for any other searchable\n * list use Combobox, and for languages use LanguagePicker.\n *\n * @example\n * const [tz, setTz] = React.useState(\"Europe/Berlin\")\n * <FormField id=\"tz\" label=\"Time zone\">\n *   <TimezoneSelect id=\"tz\" value={tz} onValueChange={setTz} />\n * </FormField>\n */\n\ntype TimezoneSelectProps = {\n  /** Controlled IANA zone id, e.g. \"America/New_York\". */\n  value?: string\n  /** Starting zone when uncontrolled. Defaults to the browser's zone (`Intl.DateTimeFormat().resolvedOptions().timeZone`). */\n  defaultValue?: string\n  /** Fires with the picked IANA zone id. */\n  onValueChange?: (timeZone: string) => void\n  /** Zone ids to offer. Defaults to every zone the browser knows (`Intl.supportedValuesOf(\"timeZone\")`). */\n  zones?: string[]\n  /** Show each zone's current local time in the list. */\n  showCurrentTime?: boolean\n  /** Group zones under their region (America, Europe...). When false, one list sorted by offset. */\n  groupByRegion?: boolean\n  /** Trigger text while nothing is selected. */\n  placeholder?: string\n  /** Disables the trigger. */\n  disabled?: boolean\n  /** Id for the trigger, so a `<label htmlFor>` or FormField can name it. */\n  id?: string\n  /** Submits the selected zone id under this name inside a `<form>`. */\n  name?: string\n  /** Requires a selection before the form submits. */\n  required?: boolean\n  /** Accessible name when there is no visible label. Defaults to \"Time zone\" when no `id` is passed. */\n  \"aria-label\"?: string\n  /** Classes for the trigger button (width defaults to w-72). */\n  className?: string\n}\n\ntype Zone = {\n  value: string\n  city: string\n  region: string\n  /** \"UTC+05:30\" */\n  offset: string\n  minutes: number\n  /** Short names from Intl, e.g. \"PST\", only when they are letters. */\n  abbr: string\n  time: string\n  search: string\n}\ntype Group = { label: string; items: Zone[] }\n\nconst formatters = new Map<string, Intl.DateTimeFormat>()\nconst fmt = (timeZone: string, kind: \"longOffset\" | \"short\" | \"time\", locale?: string) => {\n  const key = `${timeZone}|${kind}|${locale ?? \"\"}`\n  let f = formatters.get(key)\n  if (!f) {\n    f = new Intl.DateTimeFormat(\n      kind === \"short\" ? locale : kind === \"time\" ? undefined : \"en-US\",\n      kind === \"time\" ? { timeZone, hour: \"numeric\", minute: \"2-digit\" } : { timeZone, timeZoneName: kind }\n    )\n    formatters.set(key, f)\n  }\n  return f\n}\nconst zoneName = (timeZone: string, kind: \"longOffset\" | \"short\", now: number, locale?: string) =>\n  fmt(timeZone, kind, locale)\n    .formatToParts(now)\n    .find((p) => p.type === \"timeZoneName\")?.value ?? \"\"\n\n/** Builds one option. Unknown ids fall back to UTC+00:00 instead of throwing. */\nfunction toZone(value: string, now: number, withTime: boolean): Zone {\n  const parts = value.split(\"/\")\n  const city = parts[parts.length - 1].replace(/_/g, \" \")\n  const region = parts.length > 1 ? parts[0] : \"Other\"\n  let gmt = \"GMT\"\n  let abbr = \"\"\n  let time = \"\"\n  try {\n    gmt = zoneName(value, \"longOffset\", now)\n    // en-US knows US names (PST), the user's locale knows local ones (CET in de, IST in en-IN).\n    abbr = [...new Set([zoneName(value, \"short\", now, \"en-US\"), zoneName(value, \"short\", now)])].filter((a) => /^[A-Z]{2,5}$/.test(a)).join(\" \")\n    if (withTime) time = fmt(value, \"time\").format(now)\n  } catch {\n    // An id this browser does not know: keep it selectable, offset unknown.\n  }\n  const m = /GMT([+-])(\\d{2}):(\\d{2})/.exec(gmt)\n  const sign = m?.[1] ?? \"+\"\n  const hh = m?.[2] ?? \"00\"\n  const mm = m?.[3] ?? \"00\"\n  const minutes = (sign === \"-\" ? -1 : 1) * (Number(hh) * 60 + Number(mm))\n  const h = String(Number(hh))\n  // Every way people type an offset: +05:30, +5:30, +0530, +5 (whole hours only).\n  const offsets = [`${sign}${hh}:${mm}`, `${sign}${h}:${mm}`, `${sign}${hh}${mm}`, mm === \"00\" ? `${sign}${h}` : \"\"]\n  const search = [value.replace(/_/g, \" \"), ...offsets.flatMap((o) => (o ? [`utc${o}`, `gmt${o}`] : [])), abbr].join(\" \").toLowerCase()\n  return { value, city, region, offset: `UTC${sign}${hh}:${mm}`, minutes, abbr, time, search }\n}\n\nconst byOffset = (a: Zone, b: Zone) => a.minutes - b.minutes || a.city.localeCompare(b.city)\n\nconst noSubscribe = () => () => {}\nconst detectZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone\nconst allZones = () => {\n  const list = typeof Intl.supportedValuesOf === \"function\" ? Intl.supportedValuesOf(\"timeZone\") : []\n  return list.includes(\"UTC\") ? list : [...list, \"UTC\"]\n}\n\n/** Matches \"new york\", \"america/new\", \"+5:30\", \"utc-8\", \"pst\". An offset without minutes matches the whole hour: \"+5\" finds +05:00, +05:30 and +05:45, not +10:00. */\nconst filterZone = (zone: Zone, query: string) => {\n  const q = query.toLowerCase().replace(/_/g, \" \").replace(/\\s*([+-])\\s*/g, \"$1\").trim().replace(/^(utc|gmt)(?=[+-])/, \"\")\n  if (!q) return true\n  if (!/^[+-]\\d/.test(q)) return zone.search.includes(q)\n  const want = `utc${q}`\n  return zone.search.split(\" \").some((t) => (q.includes(\":\") ? t.startsWith(want) : t === want || t.startsWith(`${want}:`)))\n}\n\nconst toLabel = (z: Zone) => z.city\nconst toValue = (z: Zone) => z.value\nconst same = (a: Zone, b: Zone) => a.value === b.value\n\nfunction TimezoneSelect({\n  value,\n  defaultValue,\n  onValueChange,\n  zones,\n  showCurrentTime = true,\n  groupByRegion = true,\n  placeholder = \"Select a time zone\",\n  disabled,\n  id,\n  name,\n  required,\n  \"aria-label\": ariaLabel,\n  className,\n}: TimezoneSelectProps) {\n  // \"UTC\" on the server and during hydration, then the browser's zone: no mismatch, no effect.\n  const detected = React.useSyncExternalStore(noSubscribe, detectZone, () => \"UTC\")\n  const [inner, setInner] = React.useState(defaultValue)\n  const current = value ?? inner ?? detected\n  // Offsets and clock times are computed when the list opens, not on every render.\n  const [openedAt, setOpenedAt] = React.useState<number | null>(null)\n  const [stamp] = React.useState(() => Date.now())\n\n  const groups = React.useMemo<Group[]>(() => {\n    if (openedAt === null) return []\n    const ids = zones ?? allZones()\n    const list = (ids.includes(detected) ? ids : [...ids, detected]).filter((z) => z !== detected).map((z) => toZone(z, openedAt, showCurrentTime))\n    const pinned: Group = { label: \"Detected\", items: [toZone(detected, openedAt, showCurrentTime)] }\n    if (!groupByRegion) return [pinned, { label: \"All time zones\", items: list.sort(byOffset) }]\n    const map = new Map<string, Zone[]>()\n    for (const z of list) map.set(z.region, [...(map.get(z.region) ?? []), z])\n    return [pinned, ...[...map].sort(([a], [b]) => a.localeCompare(b)).map(([label, items]) => ({ label, items: items.sort(byOffset) }))]\n  }, [openedAt, zones, detected, groupByRegion, showCurrentTime])\n\n  const selected = React.useMemo(() => (current ? toZone(current, openedAt ?? stamp, false) : null), [current, openedAt, stamp])\n\n  return (\n    <div data-slot=\"timezone-select\">\n      <ComboboxPrimitive.Root\n        items={groups}\n        filter={filterZone}\n        value={selected}\n        onValueChange={(next: Zone | null) => {\n          if (!next) return\n          if (value === undefined) setInner(next.value)\n          onValueChange?.(next.value)\n        }}\n        onOpenChange={(open) => {\n          if (open) setOpenedAt(Date.now())\n        }}\n        itemToStringLabel={toLabel}\n        itemToStringValue={toValue}\n        isItemEqualToValue={same}\n        disabled={disabled}\n        name={name}\n        required={required}\n      >\n        <ComboboxPrimitive.Trigger\n          id={id}\n          aria-label={ariaLabel ?? (id ? undefined : \"Time zone\")}\n          className={cn(\n            \"inline-flex h-9 w-72 items-center justify-between gap-2 rounded-lg border border-border bg-surface px-3 text-sm text-fg\",\n            \"shadow-highlight outline-none transition-[border-color] duration-[70ms] ease-hairline\",\n            \"hover:border-fg-subtle focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-bg\",\n            \"data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n            className\n          )}\n        >\n          {selected ? (\n            <span className=\"flex min-w-0 items-baseline gap-2\">\n              <span className=\"truncate\">{selected.city}</span>\n              <span className=\"shrink-0 font-mono text-xs tabular-nums text-fg-subtle\">{selected.offset}</span>\n            </span>\n          ) : (\n            <span className=\"truncate text-fg-subtle\">{placeholder}</span>\n          )}\n          <ChevronsUpDownIcon aria-hidden className=\"size-4 shrink-0 text-fg-muted\" />\n        </ComboboxPrimitive.Trigger>\n        <ComboboxPrimitive.Portal>\n          <ComboboxPrimitive.Positioner align=\"start\" sideOffset={6} className=\"isolate z-50 outline-none\">\n            <ComboboxPrimitive.Popup\n              data-slot=\"timezone-select-content\"\n              aria-label={ariaLabel ?? \"Time zone\"}\n              className={cn(\n                \"w-(--anchor-width) min-w-80 max-w-(--available-width) origin-(--transform-origin) rounded-xl border border-border bg-raised p-1 text-fg shadow-overlay outline-none\",\n                \"duration-200 ease-hairline data-closed:duration-[160ms]\",\n                \"data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95\"\n              )}\n            >\n              <ComboboxPrimitive.Input\n                aria-label=\"Search time zones\"\n                placeholder=\"City, offset or abbreviation\"\n                className=\"mb-1 h-8 w-full rounded-md border border-border bg-surface px-2 text-sm text-fg outline-none placeholder:text-fg-subtle focus-visible:border-accent focus-visible:shadow-[0_0_0_3px_var(--accent-soft)]\"\n              />\n              <ComboboxPrimitive.Empty className=\"px-2 py-2 text-xs text-fg-muted empty:hidden\">No time zone matches</ComboboxPrimitive.Empty>\n              <ComboboxPrimitive.List className=\"max-h-[min(18rem,var(--available-height))] overflow-auto overscroll-contain scroll-py-1\">\n                {(group: Group) => (\n                  <ComboboxPrimitive.Group key={group.label} items={group.items} className=\"pb-1\">\n                    <ComboboxPrimitive.GroupLabel className=\"sticky top-0 z-10 bg-raised px-2.5 pt-2 pb-1 text-[11px] font-medium tracking-[0.02em] text-fg-subtle\">\n                      {group.label}\n                    </ComboboxPrimitive.GroupLabel>\n                    <ComboboxPrimitive.Collection>\n                      {(zone: Zone) => (\n                        <ComboboxPrimitive.Item\n                          key={zone.value}\n                          value={zone}\n                          className={cn(\n                            \"flex w-full cursor-default items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-sm outline-none select-none\",\n                            \"transition-[background-color] duration-[70ms] data-highlighted:bg-sunken\"\n                          )}\n                        >\n                          <span className=\"grid size-4 shrink-0 place-items-center\">\n                            <ComboboxPrimitive.ItemIndicator>\n                              <CheckIcon aria-hidden className=\"size-4 text-accent-fg\" />\n                            </ComboboxPrimitive.ItemIndicator>\n                          </span>\n                          <span className=\"min-w-0 flex-1 truncate\">\n                            {zone.city}\n                            {zone.abbr ? <span className=\"ml-1.5 text-xs text-fg-subtle\">{zone.abbr}</span> : null}\n                          </span>\n                          <span className=\"shrink-0 font-mono text-xs tabular-nums text-fg-muted\">{zone.offset}</span>\n                          {showCurrentTime ? (\n                            <span className=\"w-16 shrink-0 text-right font-mono text-xs tabular-nums text-fg-subtle\">{zone.time}</span>\n                          ) : null}\n                        </ComboboxPrimitive.Item>\n                      )}\n                    </ComboboxPrimitive.Collection>\n                  </ComboboxPrimitive.Group>\n                )}\n              </ComboboxPrimitive.List>\n            </ComboboxPrimitive.Popup>\n          </ComboboxPrimitive.Positioner>\n        </ComboboxPrimitive.Portal>\n      </ComboboxPrimitive.Root>\n    </div>\n  )\n}\n\nexport { TimezoneSelect }\nexport type { TimezoneSelectProps }\n"
    }
  ],
  "categories": [
    "forms"
  ],
  "docs": "import { TimezoneSelect } from \"@/components/ui/timezone-select\"\nNeeds the MiniDev tokens stylesheet (https://ui.minidev.pro/r/styles.css) imported after Tailwind.\nDocs: https://ui.minidev.pro/docs/timezone-select · Markdown for agents: https://ui.minidev.pro/docs/timezone-select.md",
  "meta": {
    "tier": "free",
    "kind": "ui",
    "category": "forms",
    "import": "@/components/ui/timezone-select",
    "npmImport": "minidev-ui-kit/ui/timezone-select",
    "exports": [
      "TimezoneSelect"
    ],
    "related": [
      "combobox",
      "language-picker"
    ],
    "docsUrl": "https://ui.minidev.pro/docs/timezone-select",
    "markdownUrl": "https://ui.minidev.pro/docs/timezone-select.md",
    "keywords": [
      "react timezone select",
      "timezone picker shadcn",
      "timezone combobox react"
    ]
  }
}
