BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/diceui/base/key-value

key-value

diceui-base/key-value
FreeComponent

diceui/base publishes no description for this item.

Install it

npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/base-vega/key-value.json

Source

ui/key-value.tsxraw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/base-vega/key-value.json · first 6 KB
1"use client";
2
3import { mergeProps } from "@base-ui/react/merge-props";
4import { useRender } from "@base-ui/react/use-render";
5import { PlusIcon, XIcon } from "lucide-react";
6import * as React from "react";
7import { cn } from "@/lib/utils";
8import { VisuallyHiddenInput } from "@/registry/bases/base/components/visually-hidden-input";
9import { useAsRef } from "@/registry/bases/base/hooks/use-as-ref";
10import { useIsomorphicLayoutEffect } from "@/registry/bases/base/hooks/use-isomorphic-layout-effect";
11import { useLazyRef } from "@/registry/bases/base/hooks/use-lazy-ref";
12import { useComposedRefs } from "@/registry/bases/base/lib/compose-refs";
13import { Button } from "@/registry/bases/base/ui/button";
14import { Input } from "@/registry/bases/base/ui/input";
15import { Textarea } from "@/registry/bases/base/ui/textarea";
16
17const ROOT_NAME = "KeyValue";
18const LIST_NAME = "KeyValueList";
19const ITEM_NAME = "KeyValueItem";
20const KEY_INPUT_NAME = "KeyValueKeyInput";
21const VALUE_INPUT_NAME = "KeyValueValueInput";
22const REMOVE_NAME = "KeyValueRemove";
23const ADD_NAME = "KeyValueAdd";
24const ERROR_NAME = "KeyValueError";
25
26type Orientation = "vertical" | "horizontal";
27type Field = "key" | "value";
28
29interface DivProps
30 extends React.ComponentProps<"div">,
31 useRender.ComponentProps<"div"> {}
32
33type RootElement = HTMLDivElement;
34type KeyInputElement = HTMLInputElement;
35type RemoveElement = HTMLButtonElement;
36type AddElement = HTMLButtonElement;
37
38function getErrorId(rootId: string, itemId: string, field: Field) {
39 return `${rootId}-${itemId}-${field}-error`;
40}
41
42function removeQuotes(string: string, shouldStrip: boolean): string {
43 if (!shouldStrip) return string;
44
45 const trimmed = string.trim();
46 if (
47 (trimmed.startsWith('"') && trimmed.endsWith('"')) ||
48 (trimmed.startsWith("'") && trimmed.endsWith("'"))
49 ) {
50 return trimmed.slice(1, -1);
51 }
52 return trimmed;
53}
54
55interface Store {
56 subscribe: (callback: () => void) => () => void;
57 getState: () => KeyValueState;
58 setState: <K extends keyof KeyValueState>(
59 key: K,
60 value: KeyValueState[K],
61 ) => void;
62 notify: () => void;
63}
64
65function useStore<T>(
66 selector: (state: KeyValueState) => T,
67 ogStore?: Store | null,
68): T {
69 const contextStore = React.useContext(StoreContext);
70
71 const store = ogStore ?? contextStore;
72
73 if (!store) {
74 throw new Error(`\`useStore\` must be used within \`${ROOT_NAME}\``);
75 }
76
77 const getSnapshot = React.useCallback(
78 () => selector(store.getState()),
79// … truncated

What it pulls in

npm packages

  • @base-ui/react

Other registry items

  • button
  • input
  • textarea
  • @diceui/use-as-ref
  • @diceui/use-isomorphic-layout-effect
  • @diceui/use-lazy-ref

Files it writes

  • ui/key-value.tsx
  • components/visually-hidden-input.tsx
  • lib/compose-refs.ts

Facts

Registry
diceui/base
Type
registry:ui
Access
Free
Files written
3
Licence
the repository states none
First indexed
2026-08-09
Last confirmed
2 days ago

Go to the source

www.diceui.com sadmann7/diceui on GitHub Raw registry item This item as JSON

More from diceui/base

All 192 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
action-baraction-bardiceui/baseComponentsFree1 dep
angle-sliderangle-sliderdiceui/baseComponentsFree1 dep · 3 files
avatar-groupavatar-groupdiceui/baseComponentsFree1 dep
badge-overflowbadge-overflowdiceui/baseComponentsFree1 dep · 2 files
bannerbannerdiceui/baseComponentsFree1 dep
circular-progresscircular-progressdiceui/baseComponentsFree1 dep
client-onlyclient-onlydiceui/baseComponentsFreeno deps
color-pickercolor-pickerdiceui/baseComponentsFree1 dep · 2 files
BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studios

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex