Timezone Select Radix Demo
lina/timezone-select-demo-radixFreeComponent
A demo showcasing the timezone select component using Lina based on Radix UI
Install it
npx shadcn@latest add https://lina.sameer.sh/r/timezone-select-demo-radix.jsonSource
1"use client";23import { useId, useMemo, useState } from "react";4import {5 Command,6 CommandEmpty,7 CommandGroup,8 CommandInput,9 CommandItem,10 CommandList,11} from "@/registry/radix-ui/examples/command";1213import { CheckIcon, ChevronDownIcon } from "lucide-react";1415import { Button } from "@/components/ui/button";16import { Label } from "@/components/ui/label";17import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";1819import { cn } from "@/lib/utils";2021export function TimezoneSelectExample() {22 const id = useId();23 const [open, setOpen] = useState<boolean>(false);24 const [value, setValue] = useState<string>("Asia/Calcutta");2526 const timezones = Intl.supportedValuesOf("timeZone");2728 const formattedTimezones = useMemo(() => {29 return timezones30 .map((timezone) => {31 const formatter = new Intl.DateTimeFormat("en", {32 timeZone: timezone,33 timeZoneName: "shortOffset",34 });35 const parts = formatter.formatToParts(new Date());36 const offset = parts.find((part) => part.type === "timeZoneName")?.value || "";37 const modifiedOffset = offset === "GMT" ? "GMT+0" : offset;3839 return {40 value: timezone,41 label: `(${modifiedOffset}) ${timezone.replace(/_/g, " ")}`,42 numericOffset: parseInt(offset.replace("GMT", "").replace("+", "") || "0"),43 };44 })45 .sort((a, b) => a.numericOffset - b.numericOffset);46 }, [timezones]);4748 return (49 <div className="*:not-first:mt-2">50 <Label htmlFor={id}>Timezone select with search</Label>51 <Popover open={open} onOpenChange={setOpen}>52 <PopoverTrigger asChild>53 <Button54 id={id}55 variant="outline"56 role="combobox"57 aria-expanded={open}58 className="bg-background hover:bg-background border-input w-full justify-between px-3 font-normal outline-offset-0 outline-none focus-visible:outline-[3px]"59 >60 <span className={cn("truncate", !value && "text-muted-foreground")}>61 {value ? formattedTimezones.find((timezone) => timezone.value === value)?.label : "Select timezone"}62 </span>63 <ChevronDownIcon size={16} className="text-muted-foreground/80 shrink-0" aria-hidden="true" />64 </Button>65 </PopoverTrigger>66// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from lina
All 10 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Command based on Lina's Base UI variantcommand-base | lina | Components | Free | 2 deps | |
| Command based on Lina's Radix UI variantcommand-radix | lina | Components | Free | 2 deps | |
| Horizontal Scroll Area Base Demohorizontal-scroll-demo-base | lina | Components | Free | no deps | |
| Horizontal Scroll Area Radix Demohorizontal-scroll-demo-radix | lina | Components | Free | no deps | |
| Base UI Adaptive Scroll Arealina-base | lina | Components | Free | 1 dep · 2 files | |
| Radix Adaptive Scroll Arealina-radix | lina | Components | Free | 1 dep · 2 files | |
| Timezone Select Base UI Demotimezone-select-demo-base | lina | Components | Free | 1 dep | |
| Vertical Scroll Area Base Demovertical-scroll-demo-base | lina | Components | Free | no deps |
