editable
diceui-base/editableFreeComponent
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/editable.jsonSource
1"use client";23import { mergeProps } from "@base-ui/react/merge-props";4import { useRender } from "@base-ui/react/use-render";5import * as React from "react";6import { useComposedRefs } from "@/lib/compose-refs";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 { useDirection } from "@/registry/bases/base/ui/direction";1314const ROOT_NAME = "Editable";15const LABEL_NAME = "EditableLabel";16const AREA_NAME = "EditableArea";17const PREVIEW_NAME = "EditablePreview";18const INPUT_NAME = "EditableInput";19const TRIGGER_NAME = "EditableTrigger";20const TOOLBAR_NAME = "EditableToolbar";21const CANCEL_NAME = "EditableCancel";22const SUBMIT_NAME = "EditableSubmit";2324type Direction = "ltr" | "rtl";2526type RootElement = React.ComponentRef<typeof Editable>;2728interface StoreState {29 value: string;30 editing: boolean;31}3233interface Store {34 subscribe: (callback: () => void) => () => void;35 getState: () => StoreState;36 setState: <K extends keyof StoreState>(key: K, value: StoreState[K]) => void;37 notify: () => void;38}3940const StoreContext = React.createContext<Store | null>(null);4142function useStoreContext(consumerName: string) {43 const context = React.useContext(StoreContext);44 if (!context) {45 throw new Error(`\`${consumerName}\` must be used within \`${ROOT_NAME}\``);46 }47 return context;48}4950function useStore<T>(51 selector: (state: StoreState) => T,52 ogStore?: Store | null,53): T {54 const contextStore = React.useContext(StoreContext);5556 const store = ogStore ?? contextStore;5758 if (!store) {59 throw new Error(`\`useStore\` must be used within \`${ROOT_NAME}\``);60 }6162 const getSnapshot = React.useCallback(63 () => selector(store.getState()),64 [store, selector],65 );6667 return React.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);68}6970interface EditableContextValue {71 rootId: string;72 inputId: string;73 labelId: string;74 defaultValue: string;75 onCancel: () => void;76 onEdit: () => void;77 onSubmit: (value: string) => void;78 onEnterKeyDown?: (event: KeyboardEvent) => void;79 onEscapeKeyDown?: (event: KeyboardEvent) => void;80 dir?: Direction;81 maxLength?: number;82 placeholder?: string;83// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from diceui/base
All 192 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/base | Components | Free | 1 dep | |
| angle-sliderangle-slider | diceui/base | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/base | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/base | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/base | Components | Free | 1 dep | |
| circular-progresscircular-progress | diceui/base | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/base | Components | Free | no deps | |
| color-pickercolor-picker | diceui/base | Components | Free | 1 dep · 2 files |
