import { useState } from "react";
import { Plus } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input, SearchInput } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { ToggleButton } from "@/components/ui/toggle-button";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { SegmentedControl } from "@/components/ui/segmented-control";
import { ComboboxOption, useComboboxNavigation } from "@/components/ui/combobox";
import { ControlChevron } from "@/components/ui/control-chevron";
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
import { Sheet, SheetContent, SheetDescription, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { HoverHint, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TruncatedTextTooltip } from "@/components/ui/tooltip";
import { Disclosure } from "@/components/ui/disclosure";
import { ExpandableText } from "@/components/ui/expandable-text";
import { StreamingLabelSheen } from "@/components/ui/streaming-label-sheen";
import { ImageViewport } from "@/components/ui/image-viewport";
import { Sample, type ComponentExample } from "./example";
import { useGalleryTranslation } from "./i18n";
function Buttons() {
const { t } = useGalleryTranslation();
const [clicks, setClicks] = useState(0);
return
{(["default", "accent", "secondary", "outline", "ghost", "destructive", "link"] as const).map((variant) =>
setClicks((value) => value + 1)}>{variant} )}
setClicks((value) => value + 1)}>
{(["sm", "default", "control", "lg"] as const).map((size) =>
setClicks((value) => value + 1)}>{size} )}
{t("controls.common.unavailable")}
{t("controls.button.clicks", { count: clicks })}
;
}
function Inputs() {
const { t } = useGalleryTranslation();
return ;
}
function Textareas() {
const { t } = useGalleryTranslation();
return
;
}
function Switches() {
const { t } = useGalleryTranslation();
const [checked, setChecked] = useState(false);
return
{t("controls.toggle.enable")}
{t(checked ? "settings.values.enabled" : "settings.values.disabled", { ns: "common" })}
{}} label={t("controls.toggle.unavailableOn")} />
{}} label={t("controls.toggle.unavailableOff")} />
;
}
function Selects() {
const { t } = useGalleryTranslation();
const [value, setValue] = useState("default");
const labels: Record = { default: t("settings.values.default", { ns: "common" }), fast: t("controls.select.fast") };
return
{labels.default} {labels.fast}
{t("controls.common.unavailable")}
{labels.default}
{t("controls.common.selected", { value: labels[value] })}
;
}
function Segments() {
const { t } = useGalleryTranslation();
const [value, setValue] = useState("day");
const options = ["day", "week", "month"].map((period) => ({ value: period, label: t(`controls.segmented.${period}`) }));
return
{t("controls.segmented.selected", { value: t(`controls.segmented.${value}`) })}
;
}
function Comboboxes() {
const { t } = useGalleryTranslation();
const [query, setQuery] = useState("");
const [selected, setSelected] = useState("Alpha");
const [open, setOpen] = useState(false);
const values = ["Alpha", "Beta", "Gamma"].filter((name) => name.toLowerCase().includes(query.toLowerCase()));
const select = (value: string) => { setSelected(value); setQuery(value); setOpen(false); };
const navigation = useComboboxNavigation({ open, values, selectedValue: selected, onSelect: select, onClose: () => setOpen(false) });
return
setOpen(true)} onChange={(event) => { setQuery(event.target.value); setOpen(true); }} />
{open && values.length > 0 ?
{values.map((value) => {value} )}
: null}
{open && values.length === 0 ?
{t("controls.combobox.empty")}
: null}
{t("controls.combobox.selected", { value: selected })}
;
}
function Dialogs() {
const { t } = useGalleryTranslation();
const [open, setOpen] = useState(false);
const [name, setName] = useState("Nanobot");
const [draft, setDraft] = useState(name);
return ;
}
function Alerts() {
const { t } = useGalleryTranslation();
const [removed, setRemoved] = useState(false);
const [open, setOpen] = useState(false);
return
setOpen(true)}>{t("controls.alert.remove")}
{t("controls.alert.confirmTitle")}
{t("controls.alert.help")}
{t("settings.actions.cancel", { ns: "common" })}
setRemoved(true)}>{t("controls.alert.confirm")}
{t(removed ? "controls.alert.removed" : "controls.alert.available")}
;
}
function Sheets() {
const { t } = useGalleryTranslation();
return {t("controls.sheet.open")}
{t("controls.sheet.panelTitle")} {t("controls.sheet.help")}
;
}
function Popovers() {
const { t } = useGalleryTranslation();
return {t("controls.popover.open")}
{t("controls.popover.note")}
;
}
function Menus() {
const { t } = useGalleryTranslation();
const [density, setDensity] = useState("comfortable");
const [action, setAction] = useState("none");
return
{t("controls.menu.view")}
{t("controls.menu.layout")}
{t("controls.menu.comfortable")}
{t("controls.menu.compact")}
setAction("rename")}>{t("controls.menu.rename")}
{t("controls.menu.more")}
setAction("duplicate")}>{t("controls.menu.duplicate")}
{t("controls.common.unavailable")}
{t("controls.menu.status", { density: t(`controls.menu.${density}`), action: t(`controls.menu.${action}`) })}
;
}
function Tooltips() {
const { t } = useGalleryTranslation();
return
{t("controls.tooltip.primitive")}
{t("controls.tooltip.primitiveHelp")}
{t("controls.tooltip.hint")}
;
}
function TruncatedText() {
return
;
}
function Disclosures() {
const { t } = useGalleryTranslation();
return {t("controls.disclosure.show")}}
summaryClassName="rounded-control border p-3" contentClassName="space-y-3 p-3">
{t("controls.disclosure.help")}
;
}
function Expandable() {
const { t } = useGalleryTranslation();
const [expanded, setExpanded] = useState(false);
return
{"A longer activity description can stay compact while preserving its full text. Expand this example to read all of it, then collapse it again. The same paragraph remains mounted throughout the animation, so selection and layout do not jump between duplicate copies."}
setExpanded((value) => !value)}>{t(expanded ? "controls.expandable.less" : "controls.expandable.more")}
;
}
function StreamingLabels() {
const { t } = useGalleryTranslation();
const [active, setActive] = useState(true);
return
{t("controls.streaming.working")}
;
}
function ImageViewports() {
return
;
}
const base = "webui/src/components/ui/";
export const foundationExamples: ComponentExample[] = [
{ title: "controls.button.title", files: ["button"], Preview: Buttons,
description: "controls.button.description",
options: "controls.button.options",
code: 'Remove ' },
{ title: "controls.input.title", files: ["input"], Preview: Inputs,
description: "controls.input.description", options: "controls.input.options",
code: ' setName(event.target.value)} />' },
{ title: "controls.textarea.title", files: ["textarea"], Preview: Textareas,
description: "controls.textarea.description", options: "controls.textarea.options", code: '