key-value
diceui-radix/key-valueFreeComponent
diceui/radix publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/key-value.jsonSource
1"use client";23import { PlusIcon, XIcon } from "lucide-react";4import { Slot as SlotPrimitive } from "radix-ui";5import * as React from "react";6import { useComposedRefs } from "@/lib/compose-refs";7import { cn } from "@/lib/utils";8import { VisuallyHiddenInput } from "@/registry/bases/radix/components/visually-hidden-input";9import { useAsRef } from "@/registry/bases/radix/hooks/use-as-ref";10import { useIsomorphicLayoutEffect } from "@/registry/bases/radix/hooks/use-isomorphic-layout-effect";11import { useLazyRef } from "@/registry/bases/radix/hooks/use-lazy-ref";12import { Button } from "@/registry/bases/radix/ui/button";13import { Input } from "@/registry/bases/radix/ui/input";14import { Textarea } from "@/registry/bases/radix/ui/textarea";1516const ROOT_NAME = "KeyValue";17const LIST_NAME = "KeyValueList";18const ITEM_NAME = "KeyValueItem";19const KEY_INPUT_NAME = "KeyValueKeyInput";20const VALUE_INPUT_NAME = "KeyValueValueInput";21const REMOVE_NAME = "KeyValueRemove";22const ADD_NAME = "KeyValueAdd";23const ERROR_NAME = "KeyValueError";2425type Orientation = "vertical" | "horizontal";26type Field = "key" | "value";2728interface DivProps extends React.ComponentProps<"div"> {29 asChild?: boolean;30}3132type RootElement = React.ComponentRef<typeof KeyValue>;33type KeyInputElement = React.ComponentRef<typeof KeyValueKeyInput>;34type RemoveElement = React.ComponentRef<typeof KeyValueRemove>;35type AddElement = React.ComponentRef<typeof KeyValueAdd>;3637function getErrorId(rootId: string, itemId: string, field: Field) {38 return `${rootId}-${itemId}-${field}-error`;39}4041function removeQuotes(string: string, shouldStrip: boolean): string {42 if (!shouldStrip) return string;4344 const trimmed = string.trim();45 if (46 (trimmed.startsWith('"') && trimmed.endsWith('"')) ||47 (trimmed.startsWith("'") && trimmed.endsWith("'"))48 ) {49 return trimmed.slice(1, -1);50 }51 return trimmed;52}5354interface Store {55 subscribe: (callback: () => void) => () => void;56 getState: () => KeyValueState;57 setState: <K extends keyof KeyValueState>(58 key: K,59 value: KeyValueState[K],60 ) => void;61 notify: () => void;62}6364function useStore<T>(65 selector: (state: KeyValueState) => T,66 ogStore?: Store | null,67): T {68 const contextStore = React.useContext(StoreContext);6970 const store = ogStore ?? contextStore;7172 if (!store) {73 throw new Error(`\`useStore\` must be used within \`${ROOT_NAME}\``);74 }7576 const getSnapshot = React.useCallback(77 () => selector(store.getState()),78// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from diceui/radix
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/radix | Components | Free | 1 dep · 2 files | |
| angle-sliderangle-slider | diceui/radix | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/radix | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/radix | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/radix | Components | Free | 1 dep | |
| checkbox-groupcheckbox-group | diceui/radix | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/radix | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/radix | Components | Free | no deps |
