@bitrise/bitkit-v2 0.3.544-beta.3449 → 0.3.544-beta.3451
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -30,7 +30,8 @@ var BitkitPinInput = forwardRef((props, ref) => {
|
|
|
30
30
|
});
|
|
31
31
|
const hasWarning = state === "warning" || !!fieldProps.warningText;
|
|
32
32
|
const isInvalid = state === "error" || !!fieldProps.errorText;
|
|
33
|
-
const
|
|
33
|
+
const isReadOnly = state === "readOnly";
|
|
34
|
+
const isRequired = fieldProps.required ?? !isReadOnly;
|
|
34
35
|
const iconSize = size === "lg" ? "24" : "16";
|
|
35
36
|
let describedBy;
|
|
36
37
|
if (fieldProps.errorText) describedBy = fieldIds.errorText;
|
|
@@ -42,10 +43,11 @@ var BitkitPinInput = forwardRef((props, ref) => {
|
|
|
42
43
|
});
|
|
43
44
|
else if (hasWarning) statusIcon = /* @__PURE__ */ jsx(IconWarningYellow, { size: iconSize });
|
|
44
45
|
const handleValueChange = (details) => {
|
|
46
|
+
if (isReadOnly) return;
|
|
45
47
|
setCurrentValue(details.valueAsString);
|
|
46
48
|
onValueChange?.(details.valueAsString);
|
|
47
49
|
};
|
|
48
|
-
const handleValueComplete = onValueComplete ? (details) => onValueComplete(details.valueAsString) : void 0;
|
|
50
|
+
const handleValueComplete = onValueComplete && !isReadOnly ? (details) => onValueComplete(details.valueAsString) : void 0;
|
|
49
51
|
const cells = toCells(currentValue, count);
|
|
50
52
|
return /* @__PURE__ */ jsx(BitkitField, {
|
|
51
53
|
ref,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitkitPinInput.js","names":[],"sources":["../../../lib/components/BitkitPinInput/BitkitPinInput.tsx"],"sourcesContent":["import { useControllableState } from '@chakra-ui/react/hooks';\nimport { PinInput, type PinInputRootProps } from '@chakra-ui/react/pin-input';\nimport { forwardRef, type ReactNode, useId } from 'react';\n\nimport { IconErrorCircleFilled, IconWarningYellow } from '../../icons';\nimport BitkitField, { type BitkitFieldProps } from '../BitkitField/BitkitField';\n\nconst toCells = (value: string, count: number) => Array.from({ length: count }, (_, index) => value[index] ?? '');\n\nconst stripSeparators = (value: string) => value.replace(/[\\s-]/g, '');\n\nexport interface BitkitPinInputProps extends Omit<\n BitkitFieldProps,\n 'children' | 'counterText' | 'defaultValue' | 'disabled' | 'invalid' | 'optional' | 'readOnly'\n> {\n /** Number of characters (and input cells). */\n count?: number;\n /** Initial value for uncontrolled usage, as a single string (e.g. `'123'`). */\n defaultValue?: string;\n /**\n * Escape hatch for Ark's `PinInput.Root` — options like `pattern`, `sanitizeValue`, `autoSubmit`,\n * `blurOnComplete` or `name`. `sanitizeValue` defaults to stripping whitespace and dashes from a\n * pasted code, so `123 456` and `123-456` are accepted.\n */\n inputProps?: Omit<\n PinInputRootProps,\n | 'count'\n | 'defaultValue'\n | 'disabled'\n | 'ids'\n | 'invalid'\n | 'mask'\n | 'onValueChange'\n | 'onValueComplete'\n | 'otp'\n | 'placeholder'\n | 'readOnly'\n | 'required'\n | 'size'\n | 'type'\n | 'value'\n >;\n /** Mask the entered characters, like `type=\"password\"`. */\n masked?: boolean;\n /** Called with the whole value as a string whenever a cell changes. */\n onValueChange?: (value: string) => void;\n /** Called with the whole value once every cell is filled. */\n onValueComplete?: (value: string) => void;\n /** Hint the browser to autofill a one-time code from SMS or email (`autocomplete=\"one-time-code\"`). */\n otp?: boolean;\n /** Field size — controls the cell size and typography. */\n size?: 'md' | 'lg';\n /**\n * Field state. `error`/`warning` are also implied by `errorText`/`warningText`; `disabled` and\n * `readOnly` gate interaction.\n */\n state?: 'disabled' | 'error' | 'readOnly' | 'warning';\n /** Which characters each cell accepts. */\n type?: 'alphabetic' | 'alphanumeric' | 'numeric';\n /** Controlled value, as a single string. Pair with `onValueChange`. */\n value?: string;\n}\n\n/**\n * A row of single-character cells for verification codes and PINs, built on Ark's PinInput. The\n * value is a plain string — control it with `value` + `onValueChange`, or start uncontrolled with\n * `defaultValue`; `onValueComplete` fires once every cell is filled. `count` sets the number of\n * cells. Includes the standard label and helper/error/warning chrome.\n */\nconst BitkitPinInput = forwardRef<HTMLDivElement, BitkitPinInputProps>((props, ref) => {\n const {\n count = 6,\n defaultValue,\n inputProps,\n masked,\n onValueChange,\n onValueComplete,\n otp,\n size = 'lg',\n state,\n type = 'numeric',\n value,\n ...fieldProps\n } = props;\n\n const id = useId();\n const getCellId = (index: number | string) => `${id}-cell-${index}`;\n const fieldIds = {\n control: getCellId(0),\n errorText: `${id}-error-text`,\n helperText: `${id}-helper-text`,\n label: `${id}-label`,\n };\n\n const [currentValue, setCurrentValue] = useControllableState({ defaultValue: defaultValue ?? '', value });\n\n const hasWarning = state === 'warning' || !!fieldProps.warningText;\n const isInvalid = state === 'error' || !!fieldProps.errorText;\n const isRequired = fieldProps.required ??
|
|
1
|
+
{"version":3,"file":"BitkitPinInput.js","names":[],"sources":["../../../lib/components/BitkitPinInput/BitkitPinInput.tsx"],"sourcesContent":["import { useControllableState } from '@chakra-ui/react/hooks';\nimport { PinInput, type PinInputRootProps } from '@chakra-ui/react/pin-input';\nimport { forwardRef, type ReactNode, useId } from 'react';\n\nimport { IconErrorCircleFilled, IconWarningYellow } from '../../icons';\nimport BitkitField, { type BitkitFieldProps } from '../BitkitField/BitkitField';\n\nconst toCells = (value: string, count: number) => Array.from({ length: count }, (_, index) => value[index] ?? '');\n\nconst stripSeparators = (value: string) => value.replace(/[\\s-]/g, '');\n\nexport interface BitkitPinInputProps extends Omit<\n BitkitFieldProps,\n 'children' | 'counterText' | 'defaultValue' | 'disabled' | 'invalid' | 'optional' | 'readOnly'\n> {\n /** Number of characters (and input cells). */\n count?: number;\n /** Initial value for uncontrolled usage, as a single string (e.g. `'123'`). */\n defaultValue?: string;\n /**\n * Escape hatch for Ark's `PinInput.Root` — options like `pattern`, `sanitizeValue`, `autoSubmit`,\n * `blurOnComplete` or `name`. `sanitizeValue` defaults to stripping whitespace and dashes from a\n * pasted code, so `123 456` and `123-456` are accepted.\n */\n inputProps?: Omit<\n PinInputRootProps,\n | 'count'\n | 'defaultValue'\n | 'disabled'\n | 'ids'\n | 'invalid'\n | 'mask'\n | 'onValueChange'\n | 'onValueComplete'\n | 'otp'\n | 'placeholder'\n | 'readOnly'\n | 'required'\n | 'size'\n | 'type'\n | 'value'\n >;\n /** Mask the entered characters, like `type=\"password\"`. */\n masked?: boolean;\n /** Called with the whole value as a string whenever a cell changes. */\n onValueChange?: (value: string) => void;\n /** Called with the whole value once every cell is filled. */\n onValueComplete?: (value: string) => void;\n /** Hint the browser to autofill a one-time code from SMS or email (`autocomplete=\"one-time-code\"`). */\n otp?: boolean;\n /** Field size — controls the cell size and typography. */\n size?: 'md' | 'lg';\n /**\n * Field state. `error`/`warning` are also implied by `errorText`/`warningText`; `disabled` and\n * `readOnly` gate interaction.\n */\n state?: 'disabled' | 'error' | 'readOnly' | 'warning';\n /** Which characters each cell accepts. */\n type?: 'alphabetic' | 'alphanumeric' | 'numeric';\n /** Controlled value, as a single string. Pair with `onValueChange`. */\n value?: string;\n}\n\n/**\n * A row of single-character cells for verification codes and PINs, built on Ark's PinInput. The\n * value is a plain string — control it with `value` + `onValueChange`, or start uncontrolled with\n * `defaultValue`; `onValueComplete` fires once every cell is filled. `count` sets the number of\n * cells. Includes the standard label and helper/error/warning chrome.\n */\nconst BitkitPinInput = forwardRef<HTMLDivElement, BitkitPinInputProps>((props, ref) => {\n const {\n count = 6,\n defaultValue,\n inputProps,\n masked,\n onValueChange,\n onValueComplete,\n otp,\n size = 'lg',\n state,\n type = 'numeric',\n value,\n ...fieldProps\n } = props;\n\n const id = useId();\n const getCellId = (index: number | string) => `${id}-cell-${index}`;\n const fieldIds = {\n control: getCellId(0),\n errorText: `${id}-error-text`,\n helperText: `${id}-helper-text`,\n label: `${id}-label`,\n };\n\n const [currentValue, setCurrentValue] = useControllableState({ defaultValue: defaultValue ?? '', value });\n\n const hasWarning = state === 'warning' || !!fieldProps.warningText;\n const isInvalid = state === 'error' || !!fieldProps.errorText;\n const isReadOnly = state === 'readOnly';\n const isRequired = fieldProps.required ?? !isReadOnly;\n const iconSize = size === 'lg' ? '24' : '16';\n\n let describedBy: string | undefined;\n if (fieldProps.errorText) {\n describedBy = fieldIds.errorText;\n } else if (fieldProps.helperText || fieldProps.warningText) {\n describedBy = fieldIds.helperText;\n }\n\n let statusIcon: ReactNode = null;\n if (isInvalid) {\n statusIcon = <IconErrorCircleFilled color=\"icon/negative\" size={iconSize} />;\n } else if (hasWarning) {\n statusIcon = <IconWarningYellow size={iconSize} />;\n }\n\n const handleValueChange: PinInputRootProps['onValueChange'] = (details) => {\n if (isReadOnly) {\n return;\n }\n setCurrentValue(details.valueAsString);\n onValueChange?.(details.valueAsString);\n };\n\n const handleValueComplete: PinInputRootProps['onValueComplete'] =\n onValueComplete && !isReadOnly ? (details) => onValueComplete(details.valueAsString) : undefined;\n\n const cells = toCells(currentValue, count);\n\n return (\n <BitkitField ref={ref} state={state} {...fieldProps} ids={fieldIds}>\n <PinInput.Root\n count={count}\n key={count}\n mask={masked}\n onValueChange={handleValueChange}\n onValueComplete={handleValueComplete}\n otp={otp}\n placeholder=\"\"\n sanitizeValue={stripSeparators}\n size={size}\n type={type}\n value={cells}\n {...inputProps}\n ids={{ hiddenInput: `${id}-hidden-input`, input: getCellId, label: fieldIds.label }}\n required={false}\n >\n <PinInput.HiddenInput />\n <PinInput.Control>\n {cells.map((_, index) => (\n <PinInput.Input\n aria-describedby={describedBy}\n aria-labelledby={fieldProps.label ? `${fieldIds.label} ${getCellId(index)}` : undefined}\n index={index}\n // eslint-disable-next-line react/no-array-index-key\n key={index}\n required={isRequired}\n />\n ))}\n </PinInput.Control>\n {statusIcon}\n </PinInput.Root>\n </BitkitField>\n );\n});\n\nBitkitPinInput.displayName = 'BitkitPinInput';\n\nexport default BitkitPinInput;\n"],"mappings":";;;;;;;;AAOA,IAAM,WAAW,OAAe,UAAkB,MAAM,KAAK,EAAE,QAAQ,MAAM,IAAI,GA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