@payfit/unity-components
Version:
47 lines (46 loc) • 2.03 kB
TypeScript
import { InlineFieldGroupMode } from '../InlineFieldGroup.context.js';
export interface UseInlineFieldGroupModeProps {
/**
* Controlled mode value. When provided, the component operates in controlled mode.
*/
mode?: InlineFieldGroupMode;
/**
* Default mode value for uncontrolled mode.
* @default 'read'
*/
defaultMode?: InlineFieldGroupMode;
/**
* Callback fired when mode changes.
*/
onModeChange?: (mode: InlineFieldGroupMode) => void;
/**
* Callback to intercept and potentially prevent mode changes.
* Return `false` to prevent the mode transition.
* Return `true` or `undefined` to allow the transition.
*/
shouldModeChange?: (fromMode: InlineFieldGroupMode, toMode: InlineFieldGroupMode) => boolean | undefined;
}
export interface UseInlineFieldGroupModeReturn {
/** Current mode value */
mode: InlineFieldGroupMode;
/** Switch to edit mode */
enterEditMode: () => void;
/** Exit edit mode (return to read mode) */
exitEditMode: () => void;
/** Check if component is in controlled mode */
isControlled: boolean;
}
/**
* Hook to manage the mode state (read/edit) for InlineFieldGroup.
* Supports both controlled and uncontrolled modes, following the pattern
* established by NavGroup.tsx
* @param props - Configuration for the mode hook
* @param props.mode - Controlled mode value. When provided, the component operates in controlled mode.
* @param props.defaultMode - Default mode value for uncontrolled mode.
* @param props.onModeChange - Callback fired when mode changes.
* @param props.shouldModeChange - Callback to intercept and potentially prevent mode changes.
* Return `false` to prevent the mode transition.
* Return `true` or `undefined` to allow the transition.
* @returns Mode state and handlers
*/
export declare function useInlineFieldGroupMode({ mode: controlledMode, defaultMode, onModeChange, shouldModeChange, }: UseInlineFieldGroupModeProps): UseInlineFieldGroupModeReturn;