import { type ComponentProps, type ReactElement, type ReactNode, type RefObject } from 'react'; /** * Unstyled Carbon for IBM Products `EditInPlace`, the behaviour without a single class: a value shown as plain text in * an `Input` that is edited right where it is, inside a `Group` that hears focus move between the field and its * buttons. Focus or typing starts editing; the `Action`s `save` (enabled once the value changed and is valid) and * `cancel` (once it changed) show while editing, `edit` at rest; a press of one keeps the focus in the field. Enter saves and keeps * editing (with nothing to save it stops editing, the focus staying); Escape puts the value back; leaving the group * saves a valid change and otherwise puts the value back. Read-only: nothing is edited, a click on the field opens * the read-only note (`noteOpen` of the context, for your popover). `InvalidText` shows its text while `invalid` and * describes the field (`aria-describedby`). * * State shows as data attributes to style on: `data-editing`, `data-invalid` and `data-readonly` on `Group` and * `Input`; `data-disabled` on an `Action`. * * ```tsx * * * * ✎ * × * ✓ * * Enter a title * * ``` */ export interface RootProps { /** Controlled value (pair with `onValueChange`). */ value?: string; defaultValue?: string; /** Every keystroke, and the value put back on cancel. */ onValueChange?: (value: string) => void; /** A change was saved (Save, Enter, leaving it). */ onSave?: (value: string) => void; /** The value was put back (Cancel, Escape, leaving it without a valid change). */ onCancel?: (value: string) => void; /** Blocks saving (`aria-invalid` on the field). */ invalid?: boolean; /** Shown, not edited. */ readOnly?: boolean; children?: ReactNode; } /** What the buttons offer: Edit at rest, Cancel / Save while editing, the note while read-only. */ export type EditInPlaceMode = 'rest' | 'editing' | 'readonly'; interface EditInPlaceContextValue { /** Ids for the field and its error (`${id}input`, `${id}error`; yours when you give them). */ id: string; /** The id of the `InvalidText` shown (it describes the field), else undefined. */ errorId: string | undefined; setErrorId: (id: string | undefined) => void; value: string; editing: boolean; mode: EditInPlaceMode; canSave: boolean; canCancel: boolean; invalid: boolean; readOnly: boolean; /** The read-only note is open (a click on a read-only field opens it). */ noteOpen: boolean; setNoteOpen: (open: boolean) => void; input: RefObject; /** Starts editing (not read-only), keeping the value it started from. */ begin: () => void; /** Saves the value (the next cancel puts this one back). */ save: () => void; /** Puts the value back to where editing started or was last saved. */ cancel: () => void; /** Focus back in the field with the caret at the end, once the value is rendered. */ refocus: () => void; /** The parts' handlers. */ typed: (text: string) => void; leave: () => void; stopEditing: () => void; } /** The state of the enclosing `EditInPlace.Root` (editing, canSave, noteOpen …). */ export declare function useEditInPlaceContext(part?: string): EditInPlaceContextValue; /** Holds the value, the editing state and the value editing started from; renders only its children. */ export declare function Root({ value: valueProp, defaultValue, onValueChange, onSave, onCancel, invalid, readOnly, children }: Readonly): import("react").JSX.Element; /** The box around the field and its buttons: focus coming in starts editing, focus leaving all of it saves or puts back. */ export declare function Group(props: Readonly>): import("react").JSX.Element; /** The text field: Enter saves (or stops editing), Escape puts the value back; a click on a read-only one opens the note. */ export declare function Input({ ref, id, ...rest }: Readonly, 'value' | 'defaultValue' | 'type' | 'readOnly'>>): import("react").JSX.Element; /** The error text (Carbon `invalidText`): shown while the Root is `invalid`, describing the field. */ export declare function InvalidText({ id, ...rest }: Readonly>): import("react").JSX.Element | null; export type ActionRenderProps = ComponentProps<'button'> & { 'data-disabled'?: string; }; export interface ActionProps extends Omit, 'type'> { /** * `edit` (at rest: focuses the field, which starts editing), `cancel` (while editing, once the value changed: puts * it back) or `save` (while editing, once it changed and is valid: saves); the last two keep editing. */ action: 'edit' | 'cancel' | 'save'; /** Render your own button with these props, e.g. a styled icon button. */ render?: (props: ActionRenderProps) => ReactElement; } /** * One of the buttons, shown in its mode only (one part for all three, so a button turning into another keeps its * element); a press keeps the focus in the field (its mousedown is cancelled). */ export declare function Action({ action, render, ...rest }: Readonly): import("react").JSX.Element | null; export {};