@bitrise/bitkit-v2 0.3.322 → 0.3.323
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.
- package/dist/components/BitkitNativeSelect/BitkitNativeSelect.d.ts +22 -0
- package/dist/components/BitkitNativeSelect/BitkitNativeSelect.js +13 -2
- package/dist/components/BitkitNativeSelect/BitkitNativeSelect.js.map +1 -1
- package/dist/components/BitkitNumberInput/BitkitNumberInput.d.ts +27 -0
- package/dist/components/BitkitNumberInput/BitkitNumberInput.js +16 -2
- package/dist/components/BitkitNumberInput/BitkitNumberInput.js.map +1 -1
- package/dist/components/BitkitTextArea/BitkitTextArea.d.ts +34 -1
- package/dist/components/BitkitTextArea/BitkitTextArea.js +16 -2
- package/dist/components/BitkitTextArea/BitkitTextArea.js.map +1 -1
- package/dist/components/BitkitTextInput/BitkitTextInput.d.ts +42 -2
- package/dist/components/BitkitTextInput/BitkitTextInput.js +18 -3
- package/dist/components/BitkitTextInput/BitkitTextInput.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,15 +2,37 @@ import { NativeSelectRootProps } from '@chakra-ui/react/native-select';
|
|
|
2
2
|
import { ChangeEventHandler, ReactNode } from 'react';
|
|
3
3
|
import { BitkitFieldProps } from '../BitkitField/BitkitField.tsx';
|
|
4
4
|
export interface BitkitNativeSelectProps extends Omit<BitkitFieldProps, 'children' | 'disabled' | 'invalid' | 'onChange' | 'readOnly'> {
|
|
5
|
+
/** The `<option>` (and `<optgroup>`) elements to render inside the select. */
|
|
5
6
|
children: ReactNode;
|
|
7
|
+
/** Initially selected option value, for uncontrolled usage. */
|
|
6
8
|
defaultValue?: string;
|
|
9
|
+
/** Form field name submitted with the enclosing form. */
|
|
7
10
|
name?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Native `change` event of the underlying `<select>`. Reach for `onValueChange` when you only need
|
|
13
|
+
* the selected value.
|
|
14
|
+
*/
|
|
8
15
|
onChange?: ChangeEventHandler<HTMLSelectElement>;
|
|
16
|
+
/** Convenience change handler that receives the selected value directly, without `event.target.value`. */
|
|
17
|
+
onValueChange?: (value: string) => void;
|
|
18
|
+
/** Placeholder option shown while no value is selected. */
|
|
9
19
|
placeholder?: string;
|
|
20
|
+
/** Escape hatch for the underlying Chakra `NativeSelect.Root` wrapper. */
|
|
10
21
|
selectProps?: NativeSelectRootProps;
|
|
22
|
+
/** Field size — controls height and typography. */
|
|
11
23
|
size?: 'md' | 'lg';
|
|
24
|
+
/**
|
|
25
|
+
* Field state. `error`/`warning` are also implied by `errorText`/`warningText`; `disabled` and
|
|
26
|
+
* `readOnly` gate interaction.
|
|
27
|
+
*/
|
|
12
28
|
state?: 'disabled' | 'error' | 'readOnly' | 'warning';
|
|
29
|
+
/** Controlled selected value. Pair with `onValueChange` or the native `onChange`. */
|
|
13
30
|
value?: string;
|
|
14
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* A dropdown built on the native `<select>` — pass the `<option>` elements as children. Reflect the
|
|
34
|
+
* selection with `value` + `onValueChange` (or the native `onChange`); `selectProps` is the escape
|
|
35
|
+
* hatch for the underlying wrapper. Includes the standard label and helper/error/warning chrome.
|
|
36
|
+
*/
|
|
15
37
|
declare const BitkitNativeSelect: import('react').ForwardRefExoticComponent<BitkitNativeSelectProps & import('react').RefAttributes<HTMLSelectElement>>;
|
|
16
38
|
export default BitkitNativeSelect;
|
|
@@ -15,8 +15,13 @@ var FIELD_PROPS = [
|
|
|
15
15
|
"placeholder",
|
|
16
16
|
"value"
|
|
17
17
|
];
|
|
18
|
+
/**
|
|
19
|
+
* A dropdown built on the native `<select>` — pass the `<option>` elements as children. Reflect the
|
|
20
|
+
* selection with `value` + `onValueChange` (or the native `onChange`); `selectProps` is the escape
|
|
21
|
+
* hatch for the underlying wrapper. Includes the standard label and helper/error/warning chrome.
|
|
22
|
+
*/
|
|
18
23
|
var BitkitNativeSelect = forwardRef((props, ref) => {
|
|
19
|
-
const { children, selectProps, size = "md", state, ...rest } = props;
|
|
24
|
+
const { children, onValueChange, selectProps, size = "md", state, ...rest } = props;
|
|
20
25
|
const [nativeFieldProps, bitkitFieldProps] = splitProps(rest, [...FIELD_PROPS]);
|
|
21
26
|
const styles = useSlotRecipe({ key: "nativeSelect" })();
|
|
22
27
|
const hasWarning = state === "warning" || !!bitkitFieldProps.warningText;
|
|
@@ -31,6 +36,11 @@ var BitkitNativeSelect = forwardRef((props, ref) => {
|
|
|
31
36
|
size: size === "lg" ? "24" : "16",
|
|
32
37
|
css: styles.statusIcon
|
|
33
38
|
});
|
|
39
|
+
const { onChange: fieldOnChange, ...restFieldProps } = nativeFieldProps;
|
|
40
|
+
const handleChange = onValueChange || fieldOnChange ? (event) => {
|
|
41
|
+
onValueChange?.(event.target.value);
|
|
42
|
+
fieldOnChange?.(event);
|
|
43
|
+
} : void 0;
|
|
34
44
|
return /* @__PURE__ */ jsx(BitkitField, {
|
|
35
45
|
state,
|
|
36
46
|
...bitkitFieldProps,
|
|
@@ -41,7 +51,8 @@ var BitkitNativeSelect = forwardRef((props, ref) => {
|
|
|
41
51
|
children: [
|
|
42
52
|
/* @__PURE__ */ jsx(NativeSelect.Field, {
|
|
43
53
|
ref,
|
|
44
|
-
|
|
54
|
+
onChange: handleChange,
|
|
55
|
+
...restFieldProps,
|
|
45
56
|
children
|
|
46
57
|
}),
|
|
47
58
|
statusIcon,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitkitNativeSelect.js","names":[],"sources":["../../../lib/components/BitkitNativeSelect/BitkitNativeSelect.tsx"],"sourcesContent":["import { NativeSelect, type NativeSelectRootProps } from '@chakra-ui/react/native-select';\nimport { useSlotRecipe } from '@chakra-ui/react/styled-system';\nimport { splitProps } from '@zag-js/utils';\nimport { type ChangeEventHandler, forwardRef, type ReactNode } from 'react';\n\nimport { IconErrorCircleFilled, IconWarningYellow } from '../../icons';\nimport AssetSelectChevron from '../../utilities/AssetSelectChevron.tsx';\nimport BitkitField, { type BitkitFieldProps } from '../BitkitField/BitkitField.tsx';\n\nconst FIELD_PROPS = ['defaultValue', 'name', 'onChange', 'placeholder', 'value'] as const;\n\nexport interface BitkitNativeSelectProps extends Omit<\n BitkitFieldProps,\n 'children' | 'disabled' | 'invalid' | 'onChange' | 'readOnly'\n> {\n children: ReactNode;\n defaultValue?: string;\n name?: string;\n onChange?: ChangeEventHandler<HTMLSelectElement>;\n placeholder?: string;\n selectProps?: NativeSelectRootProps;\n size?: 'md' | 'lg';\n state?: 'disabled' | 'error' | 'readOnly' | 'warning';\n value?: string;\n}\n\nconst BitkitNativeSelect = forwardRef<HTMLSelectElement, BitkitNativeSelectProps>(\n (props: BitkitNativeSelectProps, ref) => {\n const { children, selectProps, size = 'md', state, ...rest } = props;\n const [nativeFieldProps, bitkitFieldProps] = splitProps(rest, [...FIELD_PROPS]);\n\n const recipe = useSlotRecipe({ key: 'nativeSelect' });\n const styles = recipe();\n\n const hasWarning = state === 'warning' || !!bitkitFieldProps.warningText;\n const isInvalid = state === 'error' || !!bitkitFieldProps.errorText;\n\n let statusIcon = undefined;\n if (isInvalid) {\n statusIcon = (\n <IconErrorCircleFilled size={size === 'lg' ? '24' : '16'} css={styles.statusIcon} color=\"icon/negative\" />\n );\n } else if (hasWarning) {\n statusIcon = <IconWarningYellow size={size === 'lg' ? '24' : '16'} css={styles.statusIcon} />;\n }\n\n return (\n <BitkitField state={state} {...bitkitFieldProps}>\n <NativeSelect.Root size={size} {...selectProps} className=\"group\">\n <NativeSelect.Field ref={ref} {...
|
|
1
|
+
{"version":3,"file":"BitkitNativeSelect.js","names":[],"sources":["../../../lib/components/BitkitNativeSelect/BitkitNativeSelect.tsx"],"sourcesContent":["import { NativeSelect, type NativeSelectRootProps } from '@chakra-ui/react/native-select';\nimport { useSlotRecipe } from '@chakra-ui/react/styled-system';\nimport { splitProps } from '@zag-js/utils';\nimport { type ChangeEventHandler, forwardRef, type ReactNode } from 'react';\n\nimport { IconErrorCircleFilled, IconWarningYellow } from '../../icons';\nimport AssetSelectChevron from '../../utilities/AssetSelectChevron.tsx';\nimport BitkitField, { type BitkitFieldProps } from '../BitkitField/BitkitField.tsx';\n\nconst FIELD_PROPS = ['defaultValue', 'name', 'onChange', 'placeholder', 'value'] as const;\n\nexport interface BitkitNativeSelectProps extends Omit<\n BitkitFieldProps,\n 'children' | 'disabled' | 'invalid' | 'onChange' | 'readOnly'\n> {\n /** The `<option>` (and `<optgroup>`) elements to render inside the select. */\n children: ReactNode;\n /** Initially selected option value, for uncontrolled usage. */\n defaultValue?: string;\n /** Form field name submitted with the enclosing form. */\n name?: string;\n /**\n * Native `change` event of the underlying `<select>`. Reach for `onValueChange` when you only need\n * the selected value.\n */\n onChange?: ChangeEventHandler<HTMLSelectElement>;\n /** Convenience change handler that receives the selected value directly, without `event.target.value`. */\n onValueChange?: (value: string) => void;\n /** Placeholder option shown while no value is selected. */\n placeholder?: string;\n /** Escape hatch for the underlying Chakra `NativeSelect.Root` wrapper. */\n selectProps?: NativeSelectRootProps;\n /** Field size — controls height 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 /** Controlled selected value. Pair with `onValueChange` or the native `onChange`. */\n value?: string;\n}\n\n/**\n * A dropdown built on the native `<select>` — pass the `<option>` elements as children. Reflect the\n * selection with `value` + `onValueChange` (or the native `onChange`); `selectProps` is the escape\n * hatch for the underlying wrapper. Includes the standard label and helper/error/warning chrome.\n */\nconst BitkitNativeSelect = forwardRef<HTMLSelectElement, BitkitNativeSelectProps>(\n (props: BitkitNativeSelectProps, ref) => {\n const { children, onValueChange, selectProps, size = 'md', state, ...rest } = props;\n const [nativeFieldProps, bitkitFieldProps] = splitProps(rest, [...FIELD_PROPS]);\n\n const recipe = useSlotRecipe({ key: 'nativeSelect' });\n const styles = recipe();\n\n const hasWarning = state === 'warning' || !!bitkitFieldProps.warningText;\n const isInvalid = state === 'error' || !!bitkitFieldProps.errorText;\n\n let statusIcon = undefined;\n if (isInvalid) {\n statusIcon = (\n <IconErrorCircleFilled size={size === 'lg' ? '24' : '16'} css={styles.statusIcon} color=\"icon/negative\" />\n );\n } else if (hasWarning) {\n statusIcon = <IconWarningYellow size={size === 'lg' ? '24' : '16'} css={styles.statusIcon} />;\n }\n\n // `onValueChange` fires alongside the native `onChange`, with the selected value.\n const { onChange: fieldOnChange, ...restFieldProps } = nativeFieldProps;\n const handleChange: ChangeEventHandler<HTMLSelectElement> | undefined =\n onValueChange || fieldOnChange\n ? (event) => {\n onValueChange?.(event.target.value);\n fieldOnChange?.(event);\n }\n : undefined;\n\n return (\n <BitkitField state={state} {...bitkitFieldProps}>\n <NativeSelect.Root size={size} {...selectProps} className=\"group\">\n <NativeSelect.Field ref={ref} onChange={handleChange} {...restFieldProps}>\n {children}\n </NativeSelect.Field>\n {statusIcon}\n <NativeSelect.Indicator asChild>\n <AssetSelectChevron pointerEvents=\"none\" />\n </NativeSelect.Indicator>\n </NativeSelect.Root>\n </BitkitField>\n );\n },\n);\n\nBitkitNativeSelect.displayName = 'BitkitNativeSelect';\n\nexport default BitkitNativeSelect;\n"],"mappings":";;;;;;;;;;AASA,IAAM,cAAc;CAAC;CAAgB;CAAQ;CAAY;CAAe;AAAO;;;;;;AAuC/E,IAAM,qBAAqB,YACxB,OAAgC,QAAQ;CACvC,MAAM,EAAE,UAAU,eAAe,aAAa,OAAO,MAAM,OAAO,GAAG,SAAS;CAC9E,MAAM,CAAC,kBAAkB,oBAAoB,WAAW,MAAM,CAAC,GAAG,WAAW,CAAC;CAG9E,MAAM,SADS,cAAc,EAAE,KAAK,eAAe,CACpC,CAAA,CAAO;CAEtB,MAAM,aAAa,UAAU,aAAa,CAAC,CAAC,iBAAiB;CAC7D,MAAM,YAAY,UAAU,WAAW,CAAC,CAAC,iBAAiB;CAE1D,IAAI,aAAa,KAAA;CACjB,IAAI,WACF,aACE,oBAAC,uBAAD;EAAuB,MAAM,SAAS,OAAO,OAAO;EAAM,KAAK,OAAO;EAAY,OAAM;CAAiB,CAAA;MAEtG,IAAI,YACT,aAAa,oBAAC,mBAAD;EAAmB,MAAM,SAAS,OAAO,OAAO;EAAM,KAAK,OAAO;CAAa,CAAA;CAI9F,MAAM,EAAE,UAAU,eAAe,GAAG,mBAAmB;CACvD,MAAM,eACJ,iBAAiB,iBACZ,UAAU;EACT,gBAAgB,MAAM,OAAO,KAAK;EAClC,gBAAgB,KAAK;CACvB,IACA,KAAA;CAEN,OACE,oBAAC,aAAD;EAAoB;EAAO,GAAI;YAC7B,qBAAC,aAAa,MAAd;GAAyB;GAAM,GAAI;GAAa,WAAU;aAA1D;IACE,oBAAC,aAAa,OAAd;KAAyB;KAAK,UAAU;KAAc,GAAI;KACvD;IACiB,CAAA;IACnB;IACD,oBAAC,aAAa,WAAd;KAAwB,SAAA;eACtB,oBAAC,oBAAD,EAAoB,eAAc,OAAQ,CAAA;IACpB,CAAA;GACP;;CACR,CAAA;AAEjB,CACF;AAEA,mBAAmB,cAAc"}
|
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
import { NumberInputRootProps } from '@chakra-ui/react/number-input';
|
|
2
2
|
import { BitkitFieldProps } from '../BitkitField/BitkitField';
|
|
3
3
|
export interface BitkitNumberInputProps extends Omit<BitkitFieldProps, 'children' | 'disabled' | 'invalid' | 'readOnly'> {
|
|
4
|
+
/** Initial value for uncontrolled usage (a string, as Ark tracks the value as a string). */
|
|
4
5
|
defaultValue?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Escape hatch for Ark's `NumberInput.Root` — options like `min`, `max`, `step`, or
|
|
8
|
+
* `formatOptions`, plus its detail-rich `onValueChange`. On conflict, values here win over the
|
|
9
|
+
* top-level `value`/`onValueChange`.
|
|
10
|
+
*/
|
|
5
11
|
inputProps?: NumberInputRootProps;
|
|
12
|
+
/**
|
|
13
|
+
* Convenience change handler that receives the value directly. For Ark's full details (including
|
|
14
|
+
* `valueAsNumber`), use `inputProps.onValueChange`. The object wins if both are set.
|
|
15
|
+
*/
|
|
16
|
+
onValueChange?: (value: string) => void;
|
|
17
|
+
/** Field size — controls height and typography. */
|
|
6
18
|
size?: 'md' | 'lg';
|
|
19
|
+
/**
|
|
20
|
+
* Field state. `error`/`warning` are also implied by `errorText`/`warningText`; `disabled` and
|
|
21
|
+
* `readOnly` gate interaction.
|
|
22
|
+
*/
|
|
7
23
|
state?: 'disabled' | 'error' | 'readOnly' | 'warning';
|
|
24
|
+
/**
|
|
25
|
+
* Controlled value (a string). Pair with `onValueChange`. Can also be supplied via `inputProps`,
|
|
26
|
+
* which wins on conflict.
|
|
27
|
+
*/
|
|
28
|
+
value?: string;
|
|
8
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* A numeric field with increment/decrement steppers, built on Ark's NumberInput. Reflect the value
|
|
32
|
+
* with `value` + `onValueChange` (a string), or start uncontrolled with `defaultValue`; use
|
|
33
|
+
* `inputProps` for Ark options like `min`/`max`/`step` and its detail-rich `onValueChange`. Includes
|
|
34
|
+
* the standard label and helper/error/warning chrome.
|
|
35
|
+
*/
|
|
9
36
|
declare const BitkitNumberInput: import('react').ForwardRefExoticComponent<BitkitNumberInputProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
10
37
|
export default BitkitNumberInput;
|
|
@@ -10,8 +10,14 @@ import { forwardRef } from "react";
|
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { NumberInput } from "@chakra-ui/react/number-input";
|
|
12
12
|
//#region lib/components/BitkitNumberInput/BitkitNumberInput.tsx
|
|
13
|
+
/**
|
|
14
|
+
* A numeric field with increment/decrement steppers, built on Ark's NumberInput. Reflect the value
|
|
15
|
+
* with `value` + `onValueChange` (a string), or start uncontrolled with `defaultValue`; use
|
|
16
|
+
* `inputProps` for Ark options like `min`/`max`/`step` and its detail-rich `onValueChange`. Includes
|
|
17
|
+
* the standard label and helper/error/warning chrome.
|
|
18
|
+
*/
|
|
13
19
|
var BitkitNumberInput = forwardRef((props, ref) => {
|
|
14
|
-
const { defaultValue, inputProps, size, state, ...fieldProps } = props;
|
|
20
|
+
const { defaultValue, inputProps, onValueChange, size, state, value, ...fieldProps } = props;
|
|
15
21
|
const hasWarning = state === "warning" || !!fieldProps.warningText;
|
|
16
22
|
const isInvalid = state === "error" || !!fieldProps.errorText;
|
|
17
23
|
let statusIcon = void 0;
|
|
@@ -20,6 +26,12 @@ var BitkitNumberInput = forwardRef((props, ref) => {
|
|
|
20
26
|
color: "icon/negative"
|
|
21
27
|
});
|
|
22
28
|
else if (hasWarning) statusIcon = /* @__PURE__ */ jsx(IconWarningYellow, { size: size === "lg" ? "24" : "16" });
|
|
29
|
+
const { onValueChange: rootOnValueChange, value: rootValue, ...restInputProps } = inputProps ?? {};
|
|
30
|
+
const resolvedValue = rootValue ?? value;
|
|
31
|
+
const handleValueChange = onValueChange || rootOnValueChange ? (details) => {
|
|
32
|
+
onValueChange?.(details.value);
|
|
33
|
+
rootOnValueChange?.(details);
|
|
34
|
+
} : void 0;
|
|
23
35
|
return /* @__PURE__ */ jsx(BitkitField, {
|
|
24
36
|
ref,
|
|
25
37
|
state,
|
|
@@ -27,8 +39,10 @@ var BitkitNumberInput = forwardRef((props, ref) => {
|
|
|
27
39
|
children: /* @__PURE__ */ jsxs(NumberInput.Root, {
|
|
28
40
|
css: statusIcon ? { "--control-width": rem(150) } : void 0,
|
|
29
41
|
defaultValue,
|
|
42
|
+
onValueChange: handleValueChange,
|
|
30
43
|
size,
|
|
31
|
-
|
|
44
|
+
value: resolvedValue,
|
|
45
|
+
...restInputProps,
|
|
32
46
|
children: [/* @__PURE__ */ jsxs(NumberInput.Control, { children: [
|
|
33
47
|
statusIcon && /* @__PURE__ */ jsx(Box, {
|
|
34
48
|
paddingInline: "12",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitkitNumberInput.js","names":[],"sources":["../../../lib/components/BitkitNumberInput/BitkitNumberInput.tsx"],"sourcesContent":["import { Box } from '@chakra-ui/react/box';\nimport { NumberInput, type NumberInputRootProps } from '@chakra-ui/react/number-input';\nimport { forwardRef } from 'react';\n\nimport { IconErrorCircleFilled, IconMinus, IconPlus, IconWarningYellow } from '../../icons';\nimport { triggerSeparatorStyle } from '../../theme/slot-recipes/NumberInput.recipe';\nimport { rem } from '../../theme/themeUtils';\nimport BitkitField, { type BitkitFieldProps } from '../BitkitField/BitkitField';\n\nexport interface BitkitNumberInputProps extends Omit<\n BitkitFieldProps,\n 'children' | 'disabled' | 'invalid' | 'readOnly'\n> {\n defaultValue?: string;\n inputProps?: NumberInputRootProps;\n size?: 'md' | 'lg';\n state?: 'disabled' | 'error' | 'readOnly' | 'warning';\n}\n\nconst BitkitNumberInput = forwardRef<HTMLDivElement, BitkitNumberInputProps>((props: BitkitNumberInputProps, ref) => {\n const { defaultValue, inputProps, size, state, ...fieldProps } = props;\n\n const hasWarning = state === 'warning' || !!fieldProps.warningText;\n const isInvalid = state === 'error' || !!fieldProps.errorText;\n\n let statusIcon = undefined;\n if (isInvalid) {\n statusIcon = <IconErrorCircleFilled size={size === 'lg' ? '24' : '16'} color=\"icon/negative\" />;\n } else if (hasWarning) {\n statusIcon = <IconWarningYellow size={size === 'lg' ? '24' : '16'} />;\n }\n\n return (\n <BitkitField ref={ref} state={state} {...fieldProps}>\n <NumberInput.Root\n css={statusIcon ? { '--control-width': rem(150) } : undefined}\n defaultValue={defaultValue}\n size={size}\n {...
|
|
1
|
+
{"version":3,"file":"BitkitNumberInput.js","names":[],"sources":["../../../lib/components/BitkitNumberInput/BitkitNumberInput.tsx"],"sourcesContent":["import { Box } from '@chakra-ui/react/box';\nimport { NumberInput, type NumberInputRootProps } from '@chakra-ui/react/number-input';\nimport { forwardRef } from 'react';\n\nimport { IconErrorCircleFilled, IconMinus, IconPlus, IconWarningYellow } from '../../icons';\nimport { triggerSeparatorStyle } from '../../theme/slot-recipes/NumberInput.recipe';\nimport { rem } from '../../theme/themeUtils';\nimport BitkitField, { type BitkitFieldProps } from '../BitkitField/BitkitField';\n\nexport interface BitkitNumberInputProps extends Omit<\n BitkitFieldProps,\n 'children' | 'disabled' | 'invalid' | 'readOnly'\n> {\n /** Initial value for uncontrolled usage (a string, as Ark tracks the value as a string). */\n defaultValue?: string;\n /**\n * Escape hatch for Ark's `NumberInput.Root` — options like `min`, `max`, `step`, or\n * `formatOptions`, plus its detail-rich `onValueChange`. On conflict, values here win over the\n * top-level `value`/`onValueChange`.\n */\n inputProps?: NumberInputRootProps;\n /**\n * Convenience change handler that receives the value directly. For Ark's full details (including\n * `valueAsNumber`), use `inputProps.onValueChange`. The object wins if both are set.\n */\n onValueChange?: (value: string) => void;\n /** Field size — controls height 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 /**\n * Controlled value (a string). Pair with `onValueChange`. Can also be supplied via `inputProps`,\n * which wins on conflict.\n */\n value?: string;\n}\n\n/**\n * A numeric field with increment/decrement steppers, built on Ark's NumberInput. Reflect the value\n * with `value` + `onValueChange` (a string), or start uncontrolled with `defaultValue`; use\n * `inputProps` for Ark options like `min`/`max`/`step` and its detail-rich `onValueChange`. Includes\n * the standard label and helper/error/warning chrome.\n */\nconst BitkitNumberInput = forwardRef<HTMLDivElement, BitkitNumberInputProps>((props: BitkitNumberInputProps, ref) => {\n const { defaultValue, inputProps, onValueChange, size, state, value, ...fieldProps } = props;\n\n const hasWarning = state === 'warning' || !!fieldProps.warningText;\n const isInvalid = state === 'error' || !!fieldProps.errorText;\n\n let statusIcon = undefined;\n if (isInvalid) {\n statusIcon = <IconErrorCircleFilled size={size === 'lg' ? '24' : '16'} color=\"icon/negative\" />;\n } else if (hasWarning) {\n statusIcon = <IconWarningYellow size={size === 'lg' ? '24' : '16'} />;\n }\n\n // `value` / `onValueChange` may come in at the top level or via `inputProps` — the object wins on\n // conflict. The top-level `onValueChange` gets the string value; `inputProps.onValueChange` still\n // fires with Ark's full details.\n const { onValueChange: rootOnValueChange, value: rootValue, ...restInputProps } = inputProps ?? {};\n const resolvedValue = rootValue ?? value;\n const handleValueChange: NumberInputRootProps['onValueChange'] =\n onValueChange || rootOnValueChange\n ? (details) => {\n onValueChange?.(details.value);\n rootOnValueChange?.(details);\n }\n : undefined;\n\n return (\n <BitkitField ref={ref} state={state} {...fieldProps}>\n <NumberInput.Root\n css={statusIcon ? { '--control-width': rem(150) } : undefined}\n defaultValue={defaultValue}\n onValueChange={handleValueChange}\n size={size}\n value={resolvedValue}\n {...restInputProps}\n >\n <NumberInput.Control>\n {statusIcon && (\n <Box paddingInline=\"12\" display=\"flex\" alignItems=\"center\" justifyContent=\"center\">\n {statusIcon}\n </Box>\n )}\n <NumberInput.DecrementTrigger _before={statusIcon ? triggerSeparatorStyle : undefined}>\n <IconMinus size={size === 'lg' ? '24' : '16'} />\n </NumberInput.DecrementTrigger>\n <NumberInput.IncrementTrigger>\n <IconPlus size={size === 'lg' ? '24' : '16'} />\n </NumberInput.IncrementTrigger>\n </NumberInput.Control>\n <NumberInput.Input />\n </NumberInput.Root>\n </BitkitField>\n );\n});\n\nBitkitNumberInput.displayName = 'BitkitNumberInput';\n\nexport default BitkitNumberInput;\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8CA,IAAM,oBAAoB,YAAoD,OAA+B,QAAQ;CACnH,MAAM,EAAE,cAAc,YAAY,eAAe,MAAM,OAAO,OAAO,GAAG,eAAe;CAEvF,MAAM,aAAa,UAAU,aAAa,CAAC,CAAC,WAAW;CACvD,MAAM,YAAY,UAAU,WAAW,CAAC,CAAC,WAAW;CAEpD,IAAI,aAAa,KAAA;CACjB,IAAI,WACF,aAAa,oBAAC,uBAAD;EAAuB,MAAM,SAAS,OAAO,OAAO;EAAM,OAAM;CAAiB,CAAA;MACzF,IAAI,YACT,aAAa,oBAAC,mBAAD,EAAmB,MAAM,SAAS,OAAO,OAAO,KAAO,CAAA;CAMtE,MAAM,EAAE,eAAe,mBAAmB,OAAO,WAAW,GAAG,mBAAmB,cAAc,CAAC;CACjG,MAAM,gBAAgB,aAAa;CACnC,MAAM,oBACJ,iBAAiB,qBACZ,YAAY;EACX,gBAAgB,QAAQ,KAAK;EAC7B,oBAAoB,OAAO;CAC7B,IACA,KAAA;CAEN,OACE,oBAAC,aAAD;EAAkB;EAAY;EAAO,GAAI;YACvC,qBAAC,YAAY,MAAb;GACE,KAAK,aAAa,EAAE,mBAAmB,IAAI,GAAG,EAAE,IAAI,KAAA;GACtC;GACd,eAAe;GACT;GACN,OAAO;GACP,GAAI;aANN,CAQE,qBAAC,YAAY,SAAb,EAAA,UAAA;IACG,cACC,oBAAC,KAAD;KAAK,eAAc;KAAK,SAAQ;KAAO,YAAW;KAAS,gBAAe;eACvE;IACE,CAAA;IAEP,oBAAC,YAAY,kBAAb;KAA8B,SAAS,aAAa,wBAAwB,KAAA;eAC1E,oBAAC,WAAD,EAAW,MAAM,SAAS,OAAO,OAAO,KAAO,CAAA;IACnB,CAAA;IAC9B,oBAAC,YAAY,kBAAb,EAAA,UACE,oBAAC,UAAD,EAAU,MAAM,SAAS,OAAO,OAAO,KAAO,CAAA,EAClB,CAAA;GACX,EAAA,CAAA,GACrB,oBAAC,YAAY,OAAb,CAAoB,CAAA,CACJ;;CACP,CAAA;AAEjB,CAAC;AAED,kBAAkB,cAAc"}
|
|
@@ -1,13 +1,46 @@
|
|
|
1
1
|
import { TextareaProps } from '@chakra-ui/react/textarea';
|
|
2
|
+
import { ChangeEventHandler } from 'react';
|
|
2
3
|
import { BitkitFieldProps } from '../BitkitField/BitkitField';
|
|
3
|
-
export interface BitkitTextAreaProps extends Omit<BitkitFieldProps, 'children' | 'state'> {
|
|
4
|
+
export interface BitkitTextAreaProps extends Omit<BitkitFieldProps, 'children' | 'onChange' | 'state' | 'value'> {
|
|
5
|
+
/** Grow the field to fit its content instead of showing a scrollbar. */
|
|
4
6
|
autoresize?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Native change event — the same handler you could put on `textareaProps`, promoted to the top
|
|
9
|
+
* level. Reach for `onValueChange` when you only need the value. If both this and
|
|
10
|
+
* `textareaProps.onChange` are set, `textareaProps.onChange` wins (it's the same event).
|
|
11
|
+
*/
|
|
12
|
+
onChange?: ChangeEventHandler<HTMLTextAreaElement>;
|
|
13
|
+
/** Convenience change handler that receives the value directly, without `event.target.value`. */
|
|
14
|
+
onValueChange?: (value: string) => void;
|
|
15
|
+
/** Placeholder text shown while the field is empty. */
|
|
5
16
|
placeholder?: string;
|
|
17
|
+
/** Whether the user can drag to resize: `vertical` (default) allows height changes, `none` locks it. */
|
|
6
18
|
resize?: 'none' | 'vertical';
|
|
19
|
+
/** Number of visible text lines — sets the field's starting/minimum height (default 3). */
|
|
7
20
|
rows?: number;
|
|
21
|
+
/** Field size — controls height and typography. */
|
|
8
22
|
size?: 'md' | 'lg';
|
|
23
|
+
/**
|
|
24
|
+
* Field state. `error`/`warning` are also implied by `errorText`/`warningText`; `disabled` and
|
|
25
|
+
* `readOnly` gate interaction.
|
|
26
|
+
*/
|
|
9
27
|
state?: 'disabled' | 'error' | 'readOnly' | 'warning';
|
|
28
|
+
/**
|
|
29
|
+
* Escape hatch for the underlying Chakra `Textarea` — extra native attributes or a spread
|
|
30
|
+
* `{...register()}`. On conflict, values here win over the top-level `value`/`onChange`.
|
|
31
|
+
*/
|
|
10
32
|
textareaProps?: TextareaProps;
|
|
33
|
+
/**
|
|
34
|
+
* Controlled value. Pair with `onValueChange` or `onChange`. Can also be supplied via
|
|
35
|
+
* `textareaProps`, which wins on conflict.
|
|
36
|
+
*/
|
|
37
|
+
value?: string;
|
|
11
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* A multi-line text field wrapping the native `<textarea>`, with a label and helper/error/warning
|
|
41
|
+
* text. Height is `rows`-based (default 3); unless `resize="none"` the user can drag to grow it, and
|
|
42
|
+
* `autoresize` grows it to fit its content. Reflect the value with `value` + `onValueChange` (or the
|
|
43
|
+
* native `onChange`); `textareaProps` is the escape hatch for any other native attribute.
|
|
44
|
+
*/
|
|
12
45
|
declare const BitkitTextArea: import('react').ForwardRefExoticComponent<BitkitTextAreaProps & import('react').RefAttributes<HTMLTextAreaElement>>;
|
|
13
46
|
export default BitkitTextArea;
|
|
@@ -7,8 +7,14 @@ import { forwardRef } from "react";
|
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { Textarea } from "@chakra-ui/react/textarea";
|
|
9
9
|
//#region lib/components/BitkitTextArea/BitkitTextArea.tsx
|
|
10
|
+
/**
|
|
11
|
+
* A multi-line text field wrapping the native `<textarea>`, with a label and helper/error/warning
|
|
12
|
+
* text. Height is `rows`-based (default 3); unless `resize="none"` the user can drag to grow it, and
|
|
13
|
+
* `autoresize` grows it to fit its content. Reflect the value with `value` + `onValueChange` (or the
|
|
14
|
+
* native `onChange`); `textareaProps` is the escape hatch for any other native attribute.
|
|
15
|
+
*/
|
|
10
16
|
var BitkitTextArea = forwardRef((props, ref) => {
|
|
11
|
-
const { autoresize, placeholder, resize, rows = 3, size = "lg", state, textareaProps, ...fieldProps } = props;
|
|
17
|
+
const { autoresize, onChange, onValueChange, placeholder, resize, rows = 3, size = "lg", state, textareaProps, value, ...fieldProps } = props;
|
|
12
18
|
const isInvalid = state === "error" || !!fieldProps.errorText;
|
|
13
19
|
const hasWarning = state === "warning" || !!fieldProps.warningText;
|
|
14
20
|
const iconSize = size === "md" ? "16" : "24";
|
|
@@ -23,7 +29,13 @@ var BitkitTextArea = forwardRef((props, ref) => {
|
|
|
23
29
|
size: iconSize,
|
|
24
30
|
...iconInset
|
|
25
31
|
}) : null;
|
|
26
|
-
const { css: consumerCss, ...restTextareaProps } = textareaProps ?? {};
|
|
32
|
+
const { css: consumerCss, onChange: textareaOnChange, value: textareaValue, ...restTextareaProps } = textareaProps ?? {};
|
|
33
|
+
const resolvedValue = textareaValue ?? value;
|
|
34
|
+
const nativeOnChange = textareaOnChange ?? onChange;
|
|
35
|
+
const handleChange = onValueChange || nativeOnChange ? (event) => {
|
|
36
|
+
onValueChange?.(event.target.value);
|
|
37
|
+
nativeOnChange?.(event);
|
|
38
|
+
} : void 0;
|
|
27
39
|
const textareaCss = statusIcon != null ? [{ paddingInlineEnd }, consumerCss] : consumerCss;
|
|
28
40
|
return /* @__PURE__ */ jsx(BitkitField, {
|
|
29
41
|
state,
|
|
@@ -34,10 +46,12 @@ var BitkitTextArea = forwardRef((props, ref) => {
|
|
|
34
46
|
ref,
|
|
35
47
|
autoresize,
|
|
36
48
|
css: textareaCss,
|
|
49
|
+
onChange: handleChange,
|
|
37
50
|
placeholder,
|
|
38
51
|
resize,
|
|
39
52
|
rows,
|
|
40
53
|
size,
|
|
54
|
+
value: resolvedValue,
|
|
41
55
|
...restTextareaProps
|
|
42
56
|
}), statusIcon]
|
|
43
57
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitkitTextArea.js","names":[],"sources":["../../../lib/components/BitkitTextArea/BitkitTextArea.tsx"],"sourcesContent":["import { Box } from '@chakra-ui/react/box';\nimport { Textarea, type TextareaProps } from '@chakra-ui/react/textarea';\nimport { forwardRef } from 'react';\n\nimport { IconErrorCircleFilled, IconWarningYellow } from '../../icons';\nimport { textareaStatusIcon } from '../../theme/recipes/Textarea.recipe';\nimport BitkitField, { type BitkitFieldProps } from '../BitkitField/BitkitField';\n\nexport interface BitkitTextAreaProps extends Omit<BitkitFieldProps, 'children' | 'state'> {\n autoresize?: boolean;\n placeholder?: string;\n resize?: 'none' | 'vertical';\n rows?: number;\n size?: 'md' | 'lg';\n state?: 'disabled' | 'error' | 'readOnly' | 'warning';\n textareaProps?: TextareaProps;\n}\n\nconst BitkitTextArea = forwardRef<HTMLTextAreaElement, BitkitTextAreaProps>((props, ref) => {\n const {
|
|
1
|
+
{"version":3,"file":"BitkitTextArea.js","names":[],"sources":["../../../lib/components/BitkitTextArea/BitkitTextArea.tsx"],"sourcesContent":["import { Box } from '@chakra-ui/react/box';\nimport { Textarea, type TextareaProps } from '@chakra-ui/react/textarea';\nimport { type ChangeEventHandler, forwardRef } from 'react';\n\nimport { IconErrorCircleFilled, IconWarningYellow } from '../../icons';\nimport { textareaStatusIcon } from '../../theme/recipes/Textarea.recipe';\nimport BitkitField, { type BitkitFieldProps } from '../BitkitField/BitkitField';\n\nexport interface BitkitTextAreaProps extends Omit<BitkitFieldProps, 'children' | 'onChange' | 'state' | 'value'> {\n /** Grow the field to fit its content instead of showing a scrollbar. */\n autoresize?: boolean;\n /**\n * Native change event — the same handler you could put on `textareaProps`, promoted to the top\n * level. Reach for `onValueChange` when you only need the value. If both this and\n * `textareaProps.onChange` are set, `textareaProps.onChange` wins (it's the same event).\n */\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n /** Convenience change handler that receives the value directly, without `event.target.value`. */\n onValueChange?: (value: string) => void;\n /** Placeholder text shown while the field is empty. */\n placeholder?: string;\n /** Whether the user can drag to resize: `vertical` (default) allows height changes, `none` locks it. */\n resize?: 'none' | 'vertical';\n /** Number of visible text lines — sets the field's starting/minimum height (default 3). */\n rows?: number;\n /** Field size — controls height 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 /**\n * Escape hatch for the underlying Chakra `Textarea` — extra native attributes or a spread\n * `{...register()}`. On conflict, values here win over the top-level `value`/`onChange`.\n */\n textareaProps?: TextareaProps;\n /**\n * Controlled value. Pair with `onValueChange` or `onChange`. Can also be supplied via\n * `textareaProps`, which wins on conflict.\n */\n value?: string;\n}\n\n/**\n * A multi-line text field wrapping the native `<textarea>`, with a label and helper/error/warning\n * text. Height is `rows`-based (default 3); unless `resize=\"none\"` the user can drag to grow it, and\n * `autoresize` grows it to fit its content. Reflect the value with `value` + `onValueChange` (or the\n * native `onChange`); `textareaProps` is the escape hatch for any other native attribute.\n */\nconst BitkitTextArea = forwardRef<HTMLTextAreaElement, BitkitTextAreaProps>((props, ref) => {\n const {\n autoresize,\n onChange,\n onValueChange,\n placeholder,\n resize,\n rows = 3,\n size = 'lg',\n state,\n textareaProps,\n value,\n ...fieldProps\n } = props;\n\n const isInvalid = state === 'error' || !!fieldProps.errorText;\n const hasWarning = state === 'warning' || !!fieldProps.warningText;\n const iconSize = size === 'md' ? '16' : '24';\n\n const { paddingInlineEnd, ...iconInset } = textareaStatusIcon[size];\n const statusIcon = isInvalid ? (\n <IconErrorCircleFilled color=\"icon/negative\" position=\"absolute\" size={iconSize} {...iconInset} />\n ) : hasWarning ? (\n <IconWarningYellow position=\"absolute\" size={iconSize} {...iconInset} />\n ) : null;\n\n // `value` / `onChange` may come in at the top level or via `textareaProps` — the object wins on\n // conflict (natural for a spread `{...register()}`). `onValueChange` always fires with the value.\n const {\n css: consumerCss,\n onChange: textareaOnChange,\n value: textareaValue,\n ...restTextareaProps\n } = textareaProps ?? {};\n const resolvedValue = textareaValue ?? value;\n const nativeOnChange = textareaOnChange ?? onChange;\n const handleChange: ChangeEventHandler<HTMLTextAreaElement> | undefined =\n onValueChange || nativeOnChange\n ? (event) => {\n onValueChange?.(event.target.value);\n nativeOnChange?.(event);\n }\n : undefined;\n\n const textareaCss = statusIcon != null ? [{ paddingInlineEnd }, consumerCss] : consumerCss;\n\n return (\n <BitkitField state={state} {...fieldProps}>\n <Box position=\"relative\">\n <Textarea\n ref={ref}\n autoresize={autoresize}\n css={textareaCss}\n onChange={handleChange}\n placeholder={placeholder}\n resize={resize}\n rows={rows}\n size={size}\n value={resolvedValue}\n {...restTextareaProps}\n />\n {statusIcon}\n </Box>\n </BitkitField>\n );\n});\n\nBitkitTextArea.displayName = 'BitkitTextArea';\n\nexport default BitkitTextArea;\n"],"mappings":";;;;;;;;;;;;;;;AAkDA,IAAM,iBAAiB,YAAsD,OAAO,QAAQ;CAC1F,MAAM,EACJ,YACA,UACA,eACA,aACA,QACA,OAAO,GACP,OAAO,MACP,OACA,eACA,OACA,GAAG,eACD;CAEJ,MAAM,YAAY,UAAU,WAAW,CAAC,CAAC,WAAW;CACpD,MAAM,aAAa,UAAU,aAAa,CAAC,CAAC,WAAW;CACvD,MAAM,WAAW,SAAS,OAAO,OAAO;CAExC,MAAM,EAAE,kBAAkB,GAAG,cAAc,mBAAmB;CAC9D,MAAM,aAAa,YACjB,oBAAC,uBAAD;EAAuB,OAAM;EAAgB,UAAS;EAAW,MAAM;EAAU,GAAI;CAAY,CAAA,IAC/F,aACF,oBAAC,mBAAD;EAAmB,UAAS;EAAW,MAAM;EAAU,GAAI;CAAY,CAAA,IACrE;CAIJ,MAAM,EACJ,KAAK,aACL,UAAU,kBACV,OAAO,eACP,GAAG,sBACD,iBAAiB,CAAC;CACtB,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,iBAAiB,oBAAoB;CAC3C,MAAM,eACJ,iBAAiB,kBACZ,UAAU;EACT,gBAAgB,MAAM,OAAO,KAAK;EAClC,iBAAiB,KAAK;CACxB,IACA,KAAA;CAEN,MAAM,cAAc,cAAc,OAAO,CAAC,EAAE,iBAAiB,GAAG,WAAW,IAAI;CAE/E,OACE,oBAAC,aAAD;EAAoB;EAAO,GAAI;YAC7B,qBAAC,KAAD;GAAK,UAAS;aAAd,CACE,oBAAC,UAAD;IACO;IACO;IACZ,KAAK;IACL,UAAU;IACG;IACL;IACF;IACA;IACN,OAAO;IACP,GAAI;GACL,CAAA,GACA,UACE;;CACM,CAAA;AAEjB,CAAC;AAED,eAAe,cAAc"}
|
|
@@ -1,20 +1,60 @@
|
|
|
1
1
|
import { InputProps } from '@chakra-ui/react/input';
|
|
2
2
|
import { InputAddonProps } from '@chakra-ui/react/input-addon';
|
|
3
|
-
import { ReactNode } from 'react';
|
|
3
|
+
import { ChangeEventHandler, ReactNode } from 'react';
|
|
4
4
|
import { BitkitFieldProps } from '../BitkitField/BitkitField';
|
|
5
|
-
export interface BitkitTextInputProps extends Omit<BitkitFieldProps, 'children' | 'state'> {
|
|
5
|
+
export interface BitkitTextInputProps extends Omit<BitkitFieldProps, 'children' | 'onChange' | 'state' | 'value'> {
|
|
6
|
+
/**
|
|
7
|
+
* Show a live character counter (`length/maxLength`) next to the label. Requires `maxLength` and a
|
|
8
|
+
* known `value`.
|
|
9
|
+
*/
|
|
6
10
|
counter?: boolean;
|
|
11
|
+
/** Content attached to the trailing edge, outside the input border (e.g. a unit label or button). */
|
|
7
12
|
endAddon?: ReactNode;
|
|
13
|
+
/** Props forwarded to the trailing `InputAddon` wrapper. */
|
|
8
14
|
endAddonProps?: InputAddonProps;
|
|
15
|
+
/** Inline content rendered inside the input, at the trailing edge (e.g. an icon or reveal button). */
|
|
9
16
|
endElement?: ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Escape hatch for the underlying Chakra `Input` — extra native attributes or a spread
|
|
19
|
+
* `{...register()}`. On conflict, values here win over the top-level `value`/`onChange`.
|
|
20
|
+
*/
|
|
10
21
|
inputProps?: InputProps;
|
|
22
|
+
/** Maximum number of characters accepted; also feeds the optional `counter`. */
|
|
11
23
|
maxLength?: HTMLInputElement['maxLength'];
|
|
24
|
+
/**
|
|
25
|
+
* Native change event — the same handler you could put on `inputProps`, promoted to the top level.
|
|
26
|
+
* Reach for `onValueChange` when you only need the value. If both this and `inputProps.onChange` are
|
|
27
|
+
* set, `inputProps.onChange` wins (it's the same event, so they shouldn't both be set).
|
|
28
|
+
*/
|
|
29
|
+
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
30
|
+
/** Convenience change handler that receives the value directly, without `event.target.value`. */
|
|
31
|
+
onValueChange?: (value: string) => void;
|
|
32
|
+
/** Placeholder text shown while the field is empty. */
|
|
12
33
|
placeholder?: string;
|
|
34
|
+
/** Field size — controls height and typography. */
|
|
13
35
|
size?: 'md' | 'lg';
|
|
36
|
+
/** Content attached to the leading edge, outside the input border (e.g. a unit label or button). */
|
|
14
37
|
startAddon?: ReactNode;
|
|
38
|
+
/** Props forwarded to the leading `InputAddon` wrapper. */
|
|
15
39
|
startAddonProps?: InputAddonProps;
|
|
40
|
+
/** Inline content rendered inside the input, at the leading edge (e.g. an icon). */
|
|
16
41
|
startElement?: ReactNode;
|
|
42
|
+
/**
|
|
43
|
+
* Field state. `error`/`warning` are also implied by `errorText`/`warningText`; `disabled` and
|
|
44
|
+
* `readOnly` gate interaction.
|
|
45
|
+
*/
|
|
17
46
|
state?: 'disabled' | 'error' | 'readOnly' | 'warning';
|
|
47
|
+
/**
|
|
48
|
+
* Controlled value. Pair with `onValueChange` or `onChange`. Can also be supplied via `inputProps`,
|
|
49
|
+
* which wins on conflict.
|
|
50
|
+
*/
|
|
51
|
+
value?: string;
|
|
18
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* A single-line text field wrapping the native `<input>`, with a label and helper/error/warning
|
|
55
|
+
* text. Reflect the value with `value` + `onValueChange` (or the native `onChange`); `inputProps` is
|
|
56
|
+
* the escape hatch for any other native attribute. `startAddon`/`endAddon` sit outside the border,
|
|
57
|
+
* `startElement`/`endElement` inline inside it, and `counter` pairs with `maxLength`.
|
|
58
|
+
*/
|
|
19
59
|
declare const BitkitTextInput: import('react').ForwardRefExoticComponent<BitkitTextInputProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
20
60
|
export default BitkitTextInput;
|
|
@@ -9,8 +9,14 @@ import { Group } from "@chakra-ui/react/group";
|
|
|
9
9
|
import { Input } from "@chakra-ui/react/input";
|
|
10
10
|
import { InputAddon } from "@chakra-ui/react/input-addon";
|
|
11
11
|
//#region lib/components/BitkitTextInput/BitkitTextInput.tsx
|
|
12
|
+
/**
|
|
13
|
+
* A single-line text field wrapping the native `<input>`, with a label and helper/error/warning
|
|
14
|
+
* text. Reflect the value with `value` + `onValueChange` (or the native `onChange`); `inputProps` is
|
|
15
|
+
* the escape hatch for any other native attribute. `startAddon`/`endAddon` sit outside the border,
|
|
16
|
+
* `startElement`/`endElement` inline inside it, and `counter` pairs with `maxLength`.
|
|
17
|
+
*/
|
|
12
18
|
var BitkitTextInput = forwardRef((props, ref) => {
|
|
13
|
-
const { counter, endAddon, endAddonProps, endElement, inputProps, maxLength, placeholder, size = "lg", startAddon, startAddonProps, startElement, state, ...rest } = props;
|
|
19
|
+
const { counter, endAddon, endAddonProps, endElement, inputProps, maxLength, onChange, onValueChange, placeholder, size = "lg", startAddon, startAddonProps, startElement, state, value, ...rest } = props;
|
|
14
20
|
const styles = useSlotRecipe({ key: "textInput" })({ size });
|
|
15
21
|
const iconSize = size === "md" ? "16" : "24";
|
|
16
22
|
const addonSize = size === "md" ? "md" : "lg";
|
|
@@ -22,7 +28,14 @@ var BitkitTextInput = forwardRef((props, ref) => {
|
|
|
22
28
|
size: iconSize
|
|
23
29
|
});
|
|
24
30
|
else if (hasWarning) statusIcon = /* @__PURE__ */ jsx(IconWarningYellow, { size: iconSize });
|
|
25
|
-
const
|
|
31
|
+
const { onChange: inputOnChange, value: inputValue, ...restInputProps } = inputProps ?? {};
|
|
32
|
+
const resolvedValue = inputValue ?? value;
|
|
33
|
+
const nativeOnChange = inputOnChange ?? onChange;
|
|
34
|
+
const handleChange = onValueChange || nativeOnChange ? (event) => {
|
|
35
|
+
onValueChange?.(event.target.value);
|
|
36
|
+
nativeOnChange?.(event);
|
|
37
|
+
} : void 0;
|
|
38
|
+
const counterText = counter && maxLength && resolvedValue !== void 0 ? `${resolvedValue.toString().length}/${maxLength}` : void 0;
|
|
26
39
|
const stateAttrs = {
|
|
27
40
|
"data-disabled": state === "disabled" ? "" : void 0,
|
|
28
41
|
"data-invalid": isInvalid ? "" : void 0,
|
|
@@ -58,8 +71,10 @@ var BitkitTextInput = forwardRef((props, ref) => {
|
|
|
58
71
|
/* @__PURE__ */ jsx(Input, {
|
|
59
72
|
css: styles.input,
|
|
60
73
|
maxLength,
|
|
74
|
+
onChange: handleChange,
|
|
61
75
|
placeholder,
|
|
62
|
-
|
|
76
|
+
value: resolvedValue,
|
|
77
|
+
...restInputProps,
|
|
63
78
|
unstyled: true
|
|
64
79
|
}),
|
|
65
80
|
statusIcon != null && /* @__PURE__ */ jsx(Box, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitkitTextInput.js","names":[],"sources":["../../../lib/components/BitkitTextInput/BitkitTextInput.tsx"],"sourcesContent":["import { Box } from '@chakra-ui/react/box';\nimport { Group } from '@chakra-ui/react/group';\nimport { Input, type InputProps } from '@chakra-ui/react/input';\nimport { InputAddon, type InputAddonProps } from '@chakra-ui/react/input-addon';\nimport { useSlotRecipe } from '@chakra-ui/react/styled-system';\nimport { forwardRef, type ReactNode } from 'react';\n\nimport { IconErrorCircleFilled, IconWarningYellow } from '../../icons';\nimport BitkitField, { type BitkitFieldProps } from '../BitkitField/BitkitField';\n\nexport interface BitkitTextInputProps extends Omit<BitkitFieldProps, 'children' | 'state'> {\n counter?: boolean;\n endAddon?: ReactNode;\n endAddonProps?: InputAddonProps;\n endElement?: ReactNode;\n inputProps?: InputProps;\n maxLength?: HTMLInputElement['maxLength'];\n placeholder?: string;\n size?: 'md' | 'lg';\n startAddon?: ReactNode;\n startAddonProps?: InputAddonProps;\n startElement?: ReactNode;\n state?: 'disabled' | 'error' | 'readOnly' | 'warning';\n}\n\nconst BitkitTextInput = forwardRef<HTMLDivElement, BitkitTextInputProps>((props, ref) => {\n const {\n counter,\n endAddon,\n endAddonProps,\n endElement,\n inputProps,\n maxLength,\n placeholder,\n size = 'lg',\n startAddon,\n startAddonProps,\n startElement,\n state,\n ...rest\n } = props;\n\n const recipe = useSlotRecipe({ key: 'textInput' });\n const styles = recipe({ size });\n\n const iconSize = size === 'md' ? '16' : '24';\n const addonSize = size === 'md' ? 'md' : 'lg';\n\n const hasWarning = state === 'warning' || !!rest.warningText;\n const isInvalid = state === 'error' || !!rest.errorText;\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 counterText =\n counter && maxLength &&
|
|
1
|
+
{"version":3,"file":"BitkitTextInput.js","names":[],"sources":["../../../lib/components/BitkitTextInput/BitkitTextInput.tsx"],"sourcesContent":["import { Box } from '@chakra-ui/react/box';\nimport { Group } from '@chakra-ui/react/group';\nimport { Input, type InputProps } from '@chakra-ui/react/input';\nimport { InputAddon, type InputAddonProps } from '@chakra-ui/react/input-addon';\nimport { useSlotRecipe } from '@chakra-ui/react/styled-system';\nimport { type ChangeEventHandler, forwardRef, type ReactNode } from 'react';\n\nimport { IconErrorCircleFilled, IconWarningYellow } from '../../icons';\nimport BitkitField, { type BitkitFieldProps } from '../BitkitField/BitkitField';\n\nexport interface BitkitTextInputProps extends Omit<BitkitFieldProps, 'children' | 'onChange' | 'state' | 'value'> {\n /**\n * Show a live character counter (`length/maxLength`) next to the label. Requires `maxLength` and a\n * known `value`.\n */\n counter?: boolean;\n /** Content attached to the trailing edge, outside the input border (e.g. a unit label or button). */\n endAddon?: ReactNode;\n /** Props forwarded to the trailing `InputAddon` wrapper. */\n endAddonProps?: InputAddonProps;\n /** Inline content rendered inside the input, at the trailing edge (e.g. an icon or reveal button). */\n endElement?: ReactNode;\n /**\n * Escape hatch for the underlying Chakra `Input` — extra native attributes or a spread\n * `{...register()}`. On conflict, values here win over the top-level `value`/`onChange`.\n */\n inputProps?: InputProps;\n /** Maximum number of characters accepted; also feeds the optional `counter`. */\n maxLength?: HTMLInputElement['maxLength'];\n /**\n * Native change event — the same handler you could put on `inputProps`, promoted to the top level.\n * Reach for `onValueChange` when you only need the value. If both this and `inputProps.onChange` are\n * set, `inputProps.onChange` wins (it's the same event, so they shouldn't both be set).\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /** Convenience change handler that receives the value directly, without `event.target.value`. */\n onValueChange?: (value: string) => void;\n /** Placeholder text shown while the field is empty. */\n placeholder?: string;\n /** Field size — controls height and typography. */\n size?: 'md' | 'lg';\n /** Content attached to the leading edge, outside the input border (e.g. a unit label or button). */\n startAddon?: ReactNode;\n /** Props forwarded to the leading `InputAddon` wrapper. */\n startAddonProps?: InputAddonProps;\n /** Inline content rendered inside the input, at the leading edge (e.g. an icon). */\n startElement?: ReactNode;\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 /**\n * Controlled value. Pair with `onValueChange` or `onChange`. Can also be supplied via `inputProps`,\n * which wins on conflict.\n */\n value?: string;\n}\n\n/**\n * A single-line text field wrapping the native `<input>`, with a label and helper/error/warning\n * text. Reflect the value with `value` + `onValueChange` (or the native `onChange`); `inputProps` is\n * the escape hatch for any other native attribute. `startAddon`/`endAddon` sit outside the border,\n * `startElement`/`endElement` inline inside it, and `counter` pairs with `maxLength`.\n */\nconst BitkitTextInput = forwardRef<HTMLDivElement, BitkitTextInputProps>((props, ref) => {\n const {\n counter,\n endAddon,\n endAddonProps,\n endElement,\n inputProps,\n maxLength,\n onChange,\n onValueChange,\n placeholder,\n size = 'lg',\n startAddon,\n startAddonProps,\n startElement,\n state,\n value,\n ...rest\n } = props;\n\n const recipe = useSlotRecipe({ key: 'textInput' });\n const styles = recipe({ size });\n\n const iconSize = size === 'md' ? '16' : '24';\n const addonSize = size === 'md' ? 'md' : 'lg';\n\n const hasWarning = state === 'warning' || !!rest.warningText;\n const isInvalid = state === 'error' || !!rest.errorText;\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 // `value` / `onChange` may come in at the top level or via `inputProps` — the object wins on\n // conflict (natural for a spread `{...register()}`). `onValueChange` always fires with the value.\n const { onChange: inputOnChange, value: inputValue, ...restInputProps } = inputProps ?? {};\n const resolvedValue = inputValue ?? value;\n const nativeOnChange = inputOnChange ?? onChange;\n const handleChange: ChangeEventHandler<HTMLInputElement> | undefined =\n onValueChange || nativeOnChange\n ? (event) => {\n onValueChange?.(event.target.value);\n nativeOnChange?.(event);\n }\n : undefined;\n\n const counterText =\n counter && maxLength && resolvedValue !== undefined ? `${resolvedValue.toString().length}/${maxLength}` : undefined;\n\n const stateAttrs = {\n 'data-disabled': state === 'disabled' ? '' : undefined,\n 'data-invalid': isInvalid ? '' : undefined,\n 'data-readonly': state === 'readOnly' ? '' : undefined,\n };\n\n return (\n <BitkitField counterText={counterText} ref={ref} state={state} {...rest}>\n <Group attached width=\"100%\">\n {startAddon != null && (\n <InputAddon position=\"start\" size={addonSize} {...stateAttrs} {...startAddonProps}>\n {startAddon}\n </InputAddon>\n )}\n <Box css={styles.field} data-has-end-element={endElement != null ? '' : undefined} flex=\"1\" {...stateAttrs}>\n {startElement != null && (\n <Box css={styles.element} {...stateAttrs}>\n {startElement}\n </Box>\n )}\n <Input\n css={styles.input}\n maxLength={maxLength}\n onChange={handleChange}\n placeholder={placeholder}\n value={resolvedValue}\n {...restInputProps}\n unstyled\n />\n {statusIcon != null && (\n <Box css={styles.element} {...stateAttrs}>\n {statusIcon}\n </Box>\n )}\n {endElement != null && (\n <Box css={styles.element} {...stateAttrs}>\n {endElement}\n </Box>\n )}\n </Box>\n {endAddon != null && (\n <InputAddon position=\"end\" size={addonSize} {...stateAttrs} {...endAddonProps}>\n {endAddon}\n </InputAddon>\n )}\n </Group>\n </BitkitField>\n );\n});\n\nBitkitTextInput.displayName = 'BitkitTextInput';\n\nexport default BitkitTextInput;\n"],"mappings":";;;;;;;;;;;;;;;;;AAiEA,IAAM,kBAAkB,YAAkD,OAAO,QAAQ;CACvF,MAAM,EACJ,SACA,UACA,eACA,YACA,YACA,WACA,UACA,eACA,aACA,OAAO,MACP,YACA,iBACA,cACA,OACA,OACA,GAAG,SACD;CAGJ,MAAM,SADS,cAAc,EAAE,KAAK,YAAY,CACjC,CAAA,CAAO,EAAE,KAAK,CAAC;CAE9B,MAAM,WAAW,SAAS,OAAO,OAAO;CACxC,MAAM,YAAY,SAAS,OAAO,OAAO;CAEzC,MAAM,aAAa,UAAU,aAAa,CAAC,CAAC,KAAK;CACjD,MAAM,YAAY,UAAU,WAAW,CAAC,CAAC,KAAK;CAE9C,IAAI,aAAwB;CAC5B,IAAI,WACF,aAAa,oBAAC,uBAAD;EAAuB,OAAM;EAAgB,MAAM;CAAW,CAAA;MACtE,IAAI,YACT,aAAa,oBAAC,mBAAD,EAAmB,MAAM,SAAW,CAAA;CAKnD,MAAM,EAAE,UAAU,eAAe,OAAO,YAAY,GAAG,mBAAmB,cAAc,CAAC;CACzF,MAAM,gBAAgB,cAAc;CACpC,MAAM,iBAAiB,iBAAiB;CACxC,MAAM,eACJ,iBAAiB,kBACZ,UAAU;EACT,gBAAgB,MAAM,OAAO,KAAK;EAClC,iBAAiB,KAAK;CACxB,IACA,KAAA;CAEN,MAAM,cACJ,WAAW,aAAa,kBAAkB,KAAA,IAAY,GAAG,cAAc,SAAS,CAAC,CAAC,OAAO,GAAG,cAAc,KAAA;CAE5G,MAAM,aAAa;EACjB,iBAAiB,UAAU,aAAa,KAAK,KAAA;EAC7C,gBAAgB,YAAY,KAAK,KAAA;EACjC,iBAAiB,UAAU,aAAa,KAAK,KAAA;CAC/C;CAEA,OACE,oBAAC,aAAD;EAA0B;EAAkB;EAAY;EAAO,GAAI;YACjE,qBAAC,OAAD;GAAO,UAAA;GAAS,OAAM;aAAtB;IACG,cAAc,QACb,oBAAC,YAAD;KAAY,UAAS;KAAQ,MAAM;KAAW,GAAI;KAAY,GAAI;eAC/D;IACS,CAAA;IAEd,qBAAC,KAAD;KAAK,KAAK,OAAO;KAAO,wBAAsB,cAAc,OAAO,KAAK,KAAA;KAAW,MAAK;KAAI,GAAI;eAAhG;MACG,gBAAgB,QACf,oBAAC,KAAD;OAAK,KAAK,OAAO;OAAS,GAAI;iBAC3B;MACE,CAAA;MAEP,oBAAC,OAAD;OACE,KAAK,OAAO;OACD;OACX,UAAU;OACG;OACb,OAAO;OACP,GAAI;OACJ,UAAA;MACD,CAAA;MACA,cAAc,QACb,oBAAC,KAAD;OAAK,KAAK,OAAO;OAAS,GAAI;iBAC3B;MACE,CAAA;MAEN,cAAc,QACb,oBAAC,KAAD;OAAK,KAAK,OAAO;OAAS,GAAI;iBAC3B;MACE,CAAA;KAEJ;;IACJ,YAAY,QACX,oBAAC,YAAD;KAAY,UAAS;KAAM,MAAM;KAAW,GAAI;KAAY,GAAI;eAC7D;IACS,CAAA;GAET;;CACI,CAAA;AAEjB,CAAC;AAED,gBAAgB,cAAc"}
|