editable
diceui-radix/editableFreeComponent
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/editable.jsonSource
1"use client";23import {4 Direction as DirectionPrimitive,5 Slot as SlotPrimitive,6} from "radix-ui";7import * as React from "react";8import { useComposedRefs } from "@/lib/compose-refs";9import { cn } from "@/lib/utils";10import { VisuallyHiddenInput } from "@/registry/bases/radix/components/visually-hidden-input";11import { useAsRef } from "@/registry/bases/radix/hooks/use-as-ref";12import { useIsomorphicLayoutEffect } from "@/registry/bases/radix/hooks/use-isomorphic-layout-effect";13import { useLazyRef } from "@/registry/bases/radix/hooks/use-lazy-ref";1415const ROOT_NAME = "Editable";16const LABEL_NAME = "EditableLabel";17const AREA_NAME = "EditableArea";18const PREVIEW_NAME = "EditablePreview";19const INPUT_NAME = "EditableInput";20const TRIGGER_NAME = "EditableTrigger";21const TOOLBAR_NAME = "EditableToolbar";22const CANCEL_NAME = "EditableCancel";23const SUBMIT_NAME = "EditableSubmit";2425type Direction = "ltr" | "rtl";2627interface DivProps extends React.ComponentProps<"div"> {28 asChild?: boolean;29}3031type RootElement = React.ComponentRef<typeof Editable>;32type PreviewElement = React.ComponentRef<typeof EditablePreview>;33type SubmitElement = React.ComponentRef<typeof EditableSubmit>;34type InputElement = React.ComponentRef<typeof EditableInput>;3536interface StoreState {37 value: string;38 editing: boolean;39}4041interface Store {42 subscribe: (callback: () => void) => () => void;43 getState: () => StoreState;44 setState: <K extends keyof StoreState>(key: K, value: StoreState[K]) => void;45 notify: () => void;46}4748const StoreContext = React.createContext<Store | null>(null);4950function useStoreContext(consumerName: string) {51 const context = React.useContext(StoreContext);52 if (!context) {53 throw new Error(`\`${consumerName}\` must be used within \`${ROOT_NAME}\``);54 }55 return context;56}5758function useStore<T>(59 selector: (state: StoreState) => T,60 ogStore?: Store | null,61): T {62 const contextStore = React.useContext(StoreContext);6364 const store = ogStore ?? contextStore;6566 if (!store) {67 throw new Error(`\`useStore\` must be used within \`${ROOT_NAME}\``);68 }6970 const getSnapshot = React.useCallback(71 () => selector(store.getState()),72 [store, selector],73 );7475 return React.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);76}7778interface EditableContextValue {79 rootId: string;80 inputId: string;81 labelId: string;82 defaultValue: string;83 onCancel: () => void;84 onEdit: () => void;85 onSubmit: (value: string) => void;86// … 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 |
