Preferences Panel
tool-ui/preferences-panelFreeBlock
Compact settings panel for user preferences.
See it running
Open the demo on tool-ui
www.tool-ui.com/components/preferences-panelInstall it
npx shadcn@latest add https://www.tool-ui.com/r/preferences-panel.jsonSource
1"use client";23import { useCallback, useMemo } from "react";4import type {5 PreferencesPanelProps,6 PreferencesPanelReceiptProps,7 PreferencesValue,8 PreferenceItem,9 PreferenceSection,10} from "./schema";11import { ActionButtons } from "../shared/action-buttons";12import { normalizeActionsConfig } from "../shared/actions-config";13import { type Action } from "../shared/schema";14import { useControllableState } from "../shared/use-controllable-state";15import { useSignatureReset } from "../shared/use-signature-reset";1617import {18 cn,19 Switch,20 ToggleGroup,21 ToggleGroupItem,22 Select,23 SelectContent,24 SelectItem,25 SelectTrigger,26 SelectValue,27 Separator,28 Label,29} from "./_adapter";30import { Check, AlertCircle } from "lucide-react";31import { createPreferencesSectionSignature } from "./signature";3233function getInitialValue(item: PreferenceItem): string | boolean {34 switch (item.type) {35 case "switch":36 return item.defaultChecked ?? false;37 case "toggle":38 return item.defaultValue ?? item.options?.[0]?.value ?? "";39 case "select":40 return item.defaultSelected ?? item.selectOptions?.[0]?.value ?? "";41 }42}4344function formatDisplayValue(45 item: PreferenceItem,46 value: string | boolean,47): string {48 if (item.type === "switch") {49 return typeof value === "boolean" && value ? "On" : "Off";50 }5152 const stringValue = typeof value === "string" ? value : "";53 const options = item.type === "toggle" ? item.options : item.selectOptions;54 const option = options?.find((opt) => opt.value === stringValue);5556 return option?.label ?? stringValue;57}5859function computeInitialValues(sections: PreferenceSection[]): PreferencesValue {60 return sections.reduce<PreferencesValue>((acc, section) => {61 section.items.forEach((item) => {62 acc[item.id] = getInitialValue(item);63 });64 return acc;65 }, {});66}6768interface PreferenceControlProps {69 item: PreferenceItem;70 value: string | boolean;71 onChange: (value: string | boolean) => void;72 disabled?: boolean;73}7475function SwitchControl({76 id,77 checked,78 onChange,79 disabled,80 label,81}: {82 id: string;83 checked: boolean;84 onChange: (value: boolean) => void;85 disabled?: boolean;86 label: string;87}) {88 return (89 <Switch90 id={id}91 checked={checked}92 onCheckedChange={onChange}93 disabled={disabled}94 aria-label={label}95 />96 );97}9899function ToggleControl({100 value,101 options,102 onChange,103 disabled,104 label,105}: {106 value: string;107// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from tool-ui
All 27 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Approval Cardapproval-card | tool-ui | Blocks | Free | 2 deps · 11 files | |
| Audioaudio | tool-ui | Blocks | Free | 2 deps · 9 files | |
| Chartchart | tool-ui | Blocks | Free | 2 deps · 8 files | |
| Citationcitation | tool-ui | Blocks | Free | 2 deps · 15 files | |
| Code Blockcode-block | tool-ui | Blocks | Free | 3 deps · 11 files | |
| Code Diffcode-diff | tool-ui | Blocks | Free | 3 deps · 10 files | |
| Data Tabledata-table | tool-ui | Blocks | Free | 1 dep · 17 files | |
| Geo Mapgeo-map | tool-ui | Blocks | Free | 4 deps · 12 files |
