UNPKG

@pagopa/mui-italia

Version:

[Material-UI](https://mui.com/core/) theme inspired by [Bootstrap Italia](https://italia.github.io/bootstrap-italia/).

62 lines (61 loc) 2.8 kB
import { ReactNode } from 'react'; /** * CodeInput Props * * @typedef {Object} CodeInputProps * @property {number} length - Required number of characters for the code * @property {(value: string) => void} onChange - Callback triggered on every input change * @property {'text' | 'numeric'} [inputMode] - Input mode applied to the internal HTML input element. * Useful for customizing the keyboard on mobile devices. * - 'text': shows the default alphanumeric keyboard. * - 'numeric': shows a numeric keypad (recommended for numeric codes). * Default: 'text'. * @property {string} value - Current code value, could be used for a controlled behaviour * @property {boolean} [readOnly=false] - If `true`, the input is non-editable but still accessible for screen readers * @property {string} [id] - Optional ID for the input. If not provided, a unique one is generated * @property {string} [name] - Optional name of the input field * @property {boolean} [encrypted=false] - If `true`, hides the actual characters using dots instead * @property {boolean} [error=false] - Displays error state layout * @property {string} [helperText] - Helper text, displayed below the input * @property {string} [ariaLabel] - Aria label associated to the input * @property {string} [ariaLabelledby] - ID of an element that labels the input (for accessibility) * @property {string} [ariaDescribedby] - ID of an element providing additional description (e.g. helper text) */ export interface CodeInputProps { length: number; onChange: (value: string) => void; inputMode?: 'text' | 'numeric'; label?: ReactNode; value?: string; readOnly?: boolean; id?: string; name?: string; encrypted?: boolean; error?: boolean; helperText?: string; ariaLabel?: string; ariaLabelledby?: string; ariaDescribedby?: string; } /** * CodeInput – React component for entering OTP or PIN codes. * * Displays a sequence of visually separated character boxes, simulating individual inputs, * with a hidden `input` field handling the real input logic. * It supports both controlled and uncontrolled usage. * * @component * @example * ```tsx * <CodeInput * value={code} * onChange={(val, status) => setCode(val)} * length={6} * error={hasError} * helperText="Enter the code" * encrypted * /> * ``` */ declare const CodeInput: ({ length, onChange, inputMode, label, value, readOnly, id: idProp, name, encrypted, error, helperText, ariaLabel, ariaLabelledby, ariaDescribedby, }: CodeInputProps) => import("react/jsx-runtime").JSX.Element; export default CodeInput;