1"use client";
2
3import {
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";
14
15const 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";
24
25type Direction = "ltr" | "rtl";
26
27interface DivProps extends React.ComponentProps<"div"> {
28 asChild?: boolean;
29}
30
31type RootElement = React.ComponentRef<typeof Editable>;
32type PreviewElement = React.ComponentRef<typeof EditablePreview>;
33type SubmitElement = React.ComponentRef<typeof EditableSubmit>;
34type InputElement = React.ComponentRef<typeof EditableInput>;
35
36interface StoreState {
37 value: string;
38 editing: boolean;
39}
40
41interface 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}
47
48const StoreContext = React.createContext<Store | null>(null);
49
50function 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}
57
58function useStore<T>(
59 selector: (state: StoreState) => T,
60 ogStore?: Store | null,
61): T {
62 const contextStore = React.useContext(StoreContext);
63
64 const store = ogStore ?? contextStore;
65
66 if (!store) {
67 throw new Error(`\`useStore\` must be used within \`${ROOT_NAME}\``);
68 }
69
70 const getSnapshot = React.useCallback(
71 () => selector(store.getState()),
72 [store, selector],
73 );
74
75 return React.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);
76}
77
78interface 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 onEnterKeyDown?: (event: KeyboardEvent) => void;
87 onEscapeKeyDown?: (event: KeyboardEvent) => void;
88 dir?: Direction;
89 maxLength?: number;
90 placeholder?: string;
91 triggerMode: "click" | "dblclick" | "focus";
92 autosize: boolean;
93 disabled?: boolean;
94 readOnly?: boolean;
95 required?: boolean;
96 invalid?: boolean;
97}
98
99const EditableContext = React.createContext<EditableContextValue | null>(null);
100
101function useEditableContext(consumerName: string) {
102 const context = React.useContext(EditableContext);
103 if (!context) {
104 throw new Error(`\`${consumerName}\` must be used within \`${ROOT_NAME}\``);
105 }
106 return context;
107}
108
109interface EditableProps extends Omit<DivProps, "onSubmit"> {
110 id?: string;
111 defaultValue?: string;
112 value?: string;
113 onValueChange?: (value: string) => void;
114 defaultEditing?: boolean;
115 editing?: boolean;
116 onEditingChange?: (editing: boolean) => void;
117 onCancel?: () => void;
118 onEdit?: () => void;
119 onSubmit?: (value: string) => void;
120 onEscapeKeyDown?: (event: KeyboardEvent) => void;
121 onEnterKeyDown?: (event: KeyboardEvent) => void;
122 dir?: Direction;
123 maxLength?: number;
124 name?: string;
125 placeholder?: string;
126 triggerMode?: EditableContextValue["triggerMode"];
127 autosize?: boolean;
128 disabled?: boolean;
129 readOnly?: boolean;
130 required?: boolean;
131 invalid?: boolean;
132}
133
134function Editable(props: EditableProps) {
135 const {
136 value: valueProp,
137 defaultValue = "",
138 defaultEditing,
139 editing: editingProp,
140 onValueChange,
141 onEditingChange,
142 onCancel: onCancelProp,
143 onEdit: onEditProp,
144 onSubmit: onSubmitProp,
145 onEscapeKeyDown,
146 onEnterKeyDown,
147 dir: dirProp,
148 maxLength,
149 name,
150 placeholder,
151 triggerMode = "click",
152 asChild,
153 autosize = false,
154 disabled,
155 required,
156 readOnly,
157 invalid,
158 className,
159 id,
160 ref,
161 ...rootProps
162 } = props;
163
164 const instanceId = React.useId();
165 const rootId = id ?? instanceId;
166
167 const inputId = React.useId();
168 const labelId = React.useId();
169
170 const dir = DirectionPrimitive.useDirection(dirProp);
171
172 const previousValueRef = React.useRef(defaultValue);
173
174 const [formTrigger, setFormTrigger] = React.useState<RootElement | null>(
175 null,
176 );
177 const composedRef = useComposedRefs(ref, (node) => setFormTrigger(node));
178 const isFormControl = formTrigger ? !!formTrigger.closest("form") : true;
179
180 const listenersRef = useLazyRef(() => new Set<() => void>());
181 const stateRef = useLazyRef<StoreState>(() => ({
182 value: valueProp ?? defaultValue,
183 editing: editingProp ?? defaultEditing ?? false,
184 }));
185
186 const propsRef = useAsRef({
187 onValueChange,
188 onEditingChange,
189 onCancel: onCancelProp,
190 onEdit: onEditProp,
191 onSubmit: onSubmitProp,
192 onEscapeKeyDown,
193 onEnterKeyDown,
194 });
195
196 const store = React.useMemo<Store>(() => {
197 return {
198 subscribe: (cb) => {
199 listenersRef.current.add(cb);
200 return () => listenersRef.current.delete(cb);
201 },
202 getState: () => stateRef.current,
203 setState: (key, value) => {
204 if (Object.is(stateRef.current[key], value)) return;
205
206 if (key === "value" && typeof value === "string") {
207 stateRef.current.value = value;
208 propsRef.current.onValueChange?.(value);
209 } else if (key === "editing" && typeof value === "boolean") {
210 stateRef.current.editing = value;
211 propsRef.current.onEditingChange?.(value);
212 } else {
213 stateRef.current[key] = value;
214 }
215
216 store.notify();
217 },
218 notify: () => {
219 for (const cb of listenersRef.current) {
220 cb();
221 }
222 },
223 };
224 }, [listenersRef, stateRef, propsRef]);
225
226 const value = useStore((state) => state.value, store);
227
228 useIsomorphicLayoutEffect(() => {
229 if (valueProp !== undefined) {
230 store.setState("value", valueProp);
231 }
232 }, [valueProp]);
233
234 useIsomorphicLayoutEffect(() => {
235 if (editingProp !== undefined) {
236 store.setState("editing", editingProp);
237 }
238 }, [editingProp]);
239
240 const onCancel = React.useCallback(() => {
241 const prevValue = previousValueRef.current;
242 store.setState("value", prevValue);
243 store.setState("editing", false);
244 propsRef.current.onCancel?.();
245 }, [store, propsRef]);
246
247 const onEdit = React.useCallback(() => {
248 const currentValue = store.getState().value;
249 previousValueRef.current = currentValue;
250 store.setState("editing", true);
251 propsRef.current.onEdit?.();
252 }, [store, propsRef]);
253
254 const onSubmit = React.useCallback(
255 (newValue: string) => {
256 store.setState("value", newValue);
257 store.setState("editing", false);
258 propsRef.current.onSubmit?.(newValue);
259 },
260 [store, propsRef],
261 );
262
263 const contextValue = React.useMemo<EditableContextValue>(
264 () => ({
265 rootId,
266 inputId,
267 labelId,
268 defaultValue,
269 onSubmit,
270 onEdit,
271 onCancel,
272 onEscapeKeyDown,
273 onEnterKeyDown,
274 dir,
275 maxLength,
276 placeholder,
277 triggerMode,
278 autosize,
279 disabled,
280 readOnly,
281 required,
282 invalid,
283 }),
284 [
285 rootId,
286 inputId,
287 labelId,
288 defaultValue,
289 onSubmit,
290 onCancel,
291 onEdit,
292 onEscapeKeyDown,
293 onEnterKeyDown,
294 dir,
295 maxLength,
296 placeholder,
297 triggerMode,
298 autosize,
299 disabled,
300 required,
301 readOnly,
302 invalid,
303 ],
304 );
305
306 const RootPrimitive = asChild ? SlotPrimitive.Slot : "div";
307
308 return (
309 <StoreContext.Provider value={store}>
310 <EditableContext.Provider value={contextValue}>
311 <RootPrimitive
312 data-slot="editable"
313 {...rootProps}
314 id={id}
315 ref={composedRef}
316 className={cn("flex min-w-0 flex-col gap-2", className)}
317 />
318 {isFormControl && (
319 <VisuallyHiddenInput
320 type="hidden"
321 control={formTrigger}
322 name={name}
323 value={value}
324 disabled={disabled}
325 readOnly={readOnly}
326 required={required}
327 />
328 )}
329 </EditableContext.Provider>
330 </StoreContext.Provider>
331 );
332}
333
334interface EditableLabelProps extends React.ComponentProps<"label"> {
335 asChild?: boolean;
336}
337
338function EditableLabel(props: EditableLabelProps) {
339 const { asChild, className, children, ref, ...labelProps } = props;
340 const context = useEditableContext(LABEL_NAME);
341
342 const LabelPrimitive = asChild ? SlotPrimitive.Slot : "label";
343
344 return (
345 <LabelPrimitive
346 data-disabled={context.disabled ? "" : undefined}
347 data-invalid={context.invalid ? "" : undefined}
348 data-required={context.required ? "" : undefined}
349 data-slot="editable-label"
350 {...labelProps}
351 ref={ref}
352 id={context.labelId}
353 htmlFor={context.inputId}
354 className={cn(
355 "font-medium text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 data-required:after:ml-0.5 data-required:after:text-destructive data-required:after:content-['*']",
356 className,
357 )}
358 >
359 {children}
360 </LabelPrimitive>
361 );
362}
363
364interface EditableAreaProps extends React.ComponentProps<"div"> {
365 asChild?: boolean;
366}
367
368function EditableArea(props: EditableAreaProps) {
369 const { asChild, className, ref, ...areaProps } = props;
370 const context = useEditableContext(AREA_NAME);
371 const editing = useStore((state) => state.editing);
372
373 const AreaPrimitive = asChild ? SlotPrimitive.Slot : "div";
374
375 return (
376 <AreaPrimitive
377 role="group"
378 data-disabled={context.disabled ? "" : undefined}
379 data-editing={editing ? "" : undefined}
380 data-slot="editable-area"
381 dir={context.dir}
382 {...areaProps}
383 ref={ref}
384 className={cn(
385 "relative inline-block min-w-0 data-disabled:cursor-not-allowed data-disabled:opacity-50",
386 className,
387 )}
388 />
389 );
390}
391
392interface EditablePreviewProps extends React.ComponentProps<"div"> {
393 asChild?: boolean;
394}
395
396function EditablePreview(props: EditablePreviewProps) {
397 const {
398 onClick: onClickProp,
399 onDoubleClick: onDoubleClickProp,
400 onFocus: onFocusProp,
401 onKeyDown: onKeyDownProp,
402 asChild,
403 className,
404 ref,
405 ...previewProps
406 } = props;
407
408 const context = useEditableContext(PREVIEW_NAME);
409 const value = useStore((state) => state.value);
410 const editing = useStore((state) => state.editing);
411
412 const propsRef = useAsRef({
413 onClick: onClickProp,
414 onDoubleClick: onDoubleClickProp,
415 onFocus: onFocusProp,
416 onKeyDown: onKeyDownProp,
417 });
418
419 const onTrigger = React.useCallback(() => {
420 if (context.disabled || context.readOnly) return;
421 context.onEdit();
422 }, [context.onEdit, context.disabled, context.readOnly]);
423
424 const onClick = React.useCallback(
425 (event: React.MouseEvent<PreviewElement>) => {
426 propsRef.current.onClick?.(event);
427 if (event.defaultPrevented || context.triggerMode !== "click") return;
428
429 onTrigger();
430 },
431 [propsRef, onTrigger, context.triggerMode],
432 );
433
434 const onDoubleClick = React.useCallback(
435 (event: React.MouseEvent<PreviewElement>) => {
436 propsRef.current.onDoubleClick?.(event);
437 if (event.defaultPrevented || context.triggerMode !== "dblclick") return;
438
439 onTrigger();
440 },
441 [propsRef, onTrigger, context.triggerMode],
442 );
443
444 const onFocus = React.useCallback(
445 (event: React.FocusEvent<PreviewElement>) => {
446 propsRef.current.onFocus?.(event);
447 if (event.defaultPrevented || context.triggerMode !== "focus") return;
448
449 onTrigger();
450 },
451 [propsRef, onTrigger, context.triggerMode],
452 );
453
454 const onKeyDown = React.useCallback(
455 (event: React.KeyboardEvent<PreviewElement>) => {
456 propsRef.current.onKeyDown?.(event);
457 if (event.defaultPrevented) return;
458
459 if (event.key === "Enter") {
460 const nativeEvent = event.nativeEvent;
461 if (context.onEnterKeyDown) {
462 context.onEnterKeyDown(nativeEvent);
463 if (nativeEvent.defaultPrevented) return;
464 }
465 onTrigger();
466 }
467 },
468 [propsRef, onTrigger, context.onEnterKeyDown],
469 );
470
471 const PreviewPrimitive = asChild ? SlotPrimitive.Slot : "div";
472
473 if (editing || context.readOnly) return null;
474
475 return (
476 <PreviewPrimitive
477 role="button"
478 aria-disabled={context.disabled || context.readOnly}
479 data-empty={!value ? "" : undefined}
480 data-disabled={context.disabled ? "" : undefined}
481 data-readonly={context.readOnly ? "" : undefined}
482 data-slot="editable-preview"
483 tabIndex={context.disabled || context.readOnly ? undefined : 0}
484 {...previewProps}
485 ref={ref}
486 onClick={onClick}
487 onDoubleClick={onDoubleClick}
488 onFocus={onFocus}
489 onKeyDown={onKeyDown}
490 className={cn(
491 "cursor-text truncate rounded-sm border border-transparent py-1 text-base focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring data-disabled:cursor-not-allowed data-readonly:cursor-default data-empty:text-muted-foreground data-disabled:opacity-50 md:text-sm",
492 className,
493 )}
494 >
495 {value || context.placeholder}
496 </PreviewPrimitive>
497 );
498}
499
500interface EditableInputProps extends React.ComponentProps<"input"> {
501 asChild?: boolean;
502 maxLength?: number;
503}
504
505function EditableInput(props: EditableInputProps) {
506 const {
507 onBlur: onBlurProp,
508 onChange: onChangeProp,
509 onKeyDown: onKeyDownProp,
510 asChild,
511 className,
512 disabled,
513 readOnly,
514 required,
515 maxLength,
516 ref,
517 ...inputProps
518 } = props;
519
520 const context = useEditableContext(INPUT_NAME);
521 const store = useStoreContext(INPUT_NAME);
522 const value = useStore((state) => state.value);
523 const editing = useStore((state) => state.editing);
524 const inputRef = React.useRef<InputElement>(null);
525 const composedRef = useComposedRefs(ref, inputRef);
526
527 const propsRef = useAsRef({
528 onBlur: onBlurProp,
529 onChange: onChangeProp,
530 onKeyDown: onKeyDownProp,
531 });
532
533 const isDisabled = disabled || context.disabled;
534 const isReadOnly = readOnly || context.readOnly;
535 const isRequired = required || context.required;
536
537 const onAutosize = React.useCallback(
538 (target: InputElement) => {
539 if (!context.autosize) return;
540
541 if (target instanceof HTMLTextAreaElement) {
542 target.style.height = "0";
543 target.style.height = `${target.scrollHeight}px`;
544 } else {
545 target.style.width = "0";
546 target.style.width = `${target.scrollWidth + 4}px`;
547 }
548 },
549 [context.autosize],
550 );
551
552 const onBlur = React.useCallback(
553 (event: React.FocusEvent<InputElement>) => {
554 if (isDisabled || isReadOnly) return;
555
556 propsRef.current.onBlur?.(event);
557 if (event.defaultPrevented) return;
558
559 const relatedTarget = event.relatedTarget;
560
561 const isAction =
562 relatedTarget instanceof HTMLElement &&
563 (relatedTarget.closest(`[data-slot="editable-trigger"]`) ||
564 relatedTarget.closest(`[data-slot="editable-cancel"]`));
565
566 if (!isAction) {
567 context.onSubmit(value);
568 }
569 },
570 [value, context.onSubmit, propsRef, isDisabled, isReadOnly],
571 );
572
573 const onChange = React.useCallback(
574 (event: React.ChangeEvent<InputElement>) => {
575 if (isDisabled || isReadOnly) return;
576
577 propsRef.current.onChange?.(event);
578 if (event.defaultPrevented) return;
579
580 store.setState("value", event.target.value);
581 onAutosize(event.target);
582 },
583 [store, propsRef, onAutosize, isDisabled, isReadOnly],
584 );
585
586 const onKeyDown = React.useCallback(
587 (event: React.KeyboardEvent<InputElement>) => {
588 if (isDisabled || isReadOnly) return;
589
590 propsRef.current.onKeyDown?.(event);
591 if (event.defaultPrevented) return;
592
593 if (event.key === "Escape") {
594 const nativeEvent = event.nativeEvent;
595 if (context.onEscapeKeyDown) {
596 context.onEscapeKeyDown(nativeEvent);
597 if (nativeEvent.defaultPrevented) return;
598 }
599 context.onCancel();
600 } else if (event.key === "Enter") {
601 context.onSubmit(value);
602 }
603 },
604 [
605 value,
606 context.onSubmit,
607 context.onCancel,
608 context.onEscapeKeyDown,
609 propsRef,
610 isDisabled,
611 isReadOnly,
612 ],
613 );
614
615 useIsomorphicLayoutEffect(() => {
616 if (!editing || isDisabled || isReadOnly || !inputRef.current) return;
617
618 const frameId = window.requestAnimationFrame(() => {
619 if (!inputRef.current) return;
620
621 inputRef.current.focus();
622 inputRef.current.select();
623 onAutosize(inputRef.current);
624 });
625
626 return () => {
627 window.cancelAnimationFrame(frameId);
628 };
629 }, [editing, onAutosize, isDisabled, isReadOnly]);
630
631 const InputPrimitive = asChild ? SlotPrimitive.Slot : "input";
632
633 if (!editing && !isReadOnly) return null;
634
635 return (
636 <InputPrimitive
637 aria-required={isRequired}
638 aria-invalid={context.invalid}
639 data-slot="editable-input"
640 dir={context.dir}
641 disabled={isDisabled}
642 readOnly={isReadOnly}
643 required={isRequired}
644 {...inputProps}
645 id={context.inputId}
646 aria-labelledby={context.labelId}
647 ref={composedRef}
648 maxLength={maxLength}
649 placeholder={context.placeholder}
650 value={value}
651 onBlur={onBlur}
652 onChange={onChange}
653 onKeyDown={onKeyDown}
654 className={cn(
655 "flex rounded-sm border border-input bg-transparent py-1 text-base shadow-xs transition-colors file:border-0 file:bg-transparent file:font-medium file:text-foreground file:text-sm placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
656 context.autosize ? "w-auto" : "w-full",
657 className,
658 )}
659 />
660 );
661}
662
663interface EditableTriggerProps extends React.ComponentProps<"button"> {
664 asChild?: boolean;
665 forceMount?: boolean;
666}
667
668function EditableTrigger(props: EditableTriggerProps) {
669 const { asChild, forceMount = false, ref, ...triggerProps } = props;
670 const context = useEditableContext(TRIGGER_NAME);
671 const editing = useStore((state) => state.editing);
672
673 const onTrigger = React.useCallback(() => {
674 if (context.disabled || context.readOnly) return;
675 context.onEdit();
676 }, [context.disabled, context.readOnly, context.onEdit]);
677
678 const TriggerPrimitive = asChild ? SlotPrimitive.Slot : "button";
679
680 if (!forceMount && (editing || context.readOnly)) return null;
681
682 return (
683 <TriggerPrimitive
684 type="button"
685 aria-controls={context.rootId}
686 aria-disabled={context.disabled || context.readOnly}
687 data-disabled={context.disabled ? "" : undefined}
688 data-readonly={context.readOnly ? "" : undefined}
689 data-slot="editable-trigger"
690 {...triggerProps}
691 ref={ref}
692 onClick={context.triggerMode === "click" ? onTrigger : undefined}
693 onDoubleClick={context.triggerMode === "dblclick" ? onTrigger : undefined}
694 />
695 );
696}
697
698interface EditableToolbarProps extends React.ComponentProps<"div"> {
699 asChild?: boolean;
700 orientation?: "horizontal" | "vertical";
701}
702
703function EditableToolbar(props: EditableToolbarProps) {
704 const {
705 asChild,
706 className,
707 orientation = "horizontal",
708 ref,
709 ...toolbarProps
710 } = props;
711 const context = useEditableContext(TOOLBAR_NAME);
712
713 const ToolbarPrimitive = asChild ? SlotPrimitive.Slot : "div";
714
715 return (
716 <ToolbarPrimitive
717 role="toolbar"
718 aria-controls={context.rootId}
719 aria-orientation={orientation}
720 data-slot="editable-toolbar"
721 dir={context.dir}
722 {...toolbarProps}
723 ref={ref}
724 className={cn(
725 "flex items-center gap-2",
726 orientation === "vertical" && "flex-col",
727 className,
728 )}
729 />
730 );
731}
732
733interface EditableCancelProps extends React.ComponentProps<"button"> {
734 asChild?: boolean;
735}
736
737function EditableCancel(props: EditableCancelProps) {
738 const { onClick: onClickProp, asChild, ref, ...cancelProps } = props;
739 const context = useEditableContext(CANCEL_NAME);
740 const editing = useStore((state) => state.editing);
741
742 const propsRef = useAsRef({
743 onClick: onClickProp,
744 });
745
746 const onClick = React.useCallback(
747 (event: React.MouseEvent<HTMLButtonElement>) => {
748 if (context.disabled || context.readOnly) return;
749
750 propsRef.current.onClick?.(event);
751 if (event.defaultPrevented) return;
752
753 context.onCancel();
754 },
755 [propsRef, context.onCancel, context.disabled, context.readOnly],
756 );
757
758 const CancelPrimitive = asChild ? SlotPrimitive.Slot : "button";
759
760 if (!editing && !context.readOnly) return null;
761
762 return (
763 <CancelPrimitive
764 type="button"
765 aria-controls={context.rootId}
766 data-slot="editable-cancel"
767 {...cancelProps}
768 onClick={onClick}
769 ref={ref}
770 />
771 );
772}
773
774interface EditableSubmitProps extends React.ComponentProps<"button"> {
775 asChild?: boolean;
776}
777
778function EditableSubmit(props: EditableSubmitProps) {
779 const { onClick: onClickProp, asChild, ref, ...submitProps } = props;
780 const context = useEditableContext(SUBMIT_NAME);
781 const value = useStore((state) => state.value);
782 const editing = useStore((state) => state.editing);
783
784 const propsRef = useAsRef({
785 onClick: onClickProp,
786 });
787
788 const onClick = React.useCallback(
789 (event: React.MouseEvent<SubmitElement>) => {
790 if (context.disabled || context.readOnly) return;
791
792 propsRef.current.onClick?.(event);
793 if (event.defaultPrevented) return;
794
795 context.onSubmit(value);
796 },
797 [propsRef, context.onSubmit, value, context.disabled, context.readOnly],
798 );
799
800 const SubmitPrimitive = asChild ? SlotPrimitive.Slot : "button";
801
802 if (!editing && !context.readOnly) return null;
803
804 return (
805 <SubmitPrimitive
806 type="button"
807 aria-controls={context.rootId}
808 data-slot="editable-submit"
809 {...submitProps}
810 ref={ref}
811 onClick={onClick}
812 />
813 );
814}
815
816export {
817 Editable,
818 EditableArea,
819 EditableCancel,
820 EditableInput,
821 EditableLabel,
822 EditablePreview,
823 type EditableProps,
824 EditableSubmit,
825 EditableToolbar,
826 EditableTrigger,
827 useStore as useEditable,
828};
829