@mrshmllw/smores-react 16.10.7 → 16.11.1

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.
@@ -5,6 +5,7 @@ export interface Props extends CommonFieldProps {
5
5
  name?: string;
6
6
  value: string;
7
7
  decimalNumber?: boolean;
8
+ formatThousands?: boolean;
8
9
  onBlur?: (e: FocusEvent<HTMLInputElement>) => void;
9
10
  min?: number;
10
11
  max?: number;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, } from 'react';
2
+ import { forwardRef, useCallback, useLayoutEffect, useRef, } from 'react';
3
3
  import { Box } from '../Box';
4
4
  import { Field } from '../fields/Field';
5
5
  import { Input, InputLeadingIconContainer, } from '../fields/components/CommonInput';
@@ -8,17 +8,65 @@ import { getFieldAria } from '../fields/fieldAria';
8
8
  import { faSterlingSign } from '@awesome.me/kit-46ca99185c/icons/classic/regular';
9
9
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
10
10
  import { useTheme } from 'styled-components';
11
- export const CurrencyInput = forwardRef(function CurrencyInput({ id: idProp, placeholder, name, value, decimalNumber = true, onChange, onInputChange, onBlur, min, max, disabled = false, error = false, fallbackStyle, ...fieldProps }, ref) {
11
+ const DIGITS_DOT_OR_MINUS = /[\d.-]/;
12
+ const stripFormatting = (value) => {
13
+ const cleaned = value.replace(/(?!^)-|[^\d.-]/g, '');
14
+ const [integer, ...fraction] = cleaned.split('.');
15
+ return fraction.length ? `${integer}.${fraction.join('')}` : integer;
16
+ };
17
+ const addThousandsSeparators = (value) => {
18
+ if (!value)
19
+ return value;
20
+ const [integer, fraction] = value.split('.');
21
+ const grouped = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
22
+ return fraction === undefined ? grouped : `${grouped}.${fraction}`;
23
+ };
24
+ const countSignificant = (value) => value.replace(/[^\d.-]/g, '').length;
25
+ const caretAfterSignificant = (formatted, count) => {
26
+ let seen = 0;
27
+ for (let i = 0; i < formatted.length; i++) {
28
+ if (seen === count)
29
+ return i;
30
+ if (DIGITS_DOT_OR_MINUS.test(formatted[i]))
31
+ seen++;
32
+ }
33
+ return formatted.length;
34
+ };
35
+ export const CurrencyInput = forwardRef(function CurrencyInput({ id: idProp, placeholder, name, value, decimalNumber = true, formatThousands = false, onChange, onInputChange, onBlur, min, max, disabled = false, error = false, fallbackStyle, ...fieldProps }, ref) {
12
36
  const theme = useTheme();
13
37
  const id = useUniqueId(idProp);
14
38
  const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {
15
39
  ...fieldProps,
16
40
  error,
17
41
  });
42
+ const inputRef = useRef(null);
43
+ const pendingCaret = useRef(null);
44
+ const setInputRef = useCallback((node) => {
45
+ inputRef.current = node;
46
+ if (typeof ref === 'function')
47
+ ref(node);
48
+ else if (ref)
49
+ ref.current = node;
50
+ }, [ref]);
51
+ const displayValue = formatThousands ? addThousandsSeparators(value) : value;
52
+ const applyPendingCaret = () => {
53
+ const input = inputRef.current;
54
+ const pending = pendingCaret.current;
55
+ if (!input || !pending || input.value !== pending.value)
56
+ return;
57
+ pendingCaret.current = null;
58
+ if (input.ownerDocument.activeElement === input) {
59
+ input.setSelectionRange(pending.position, pending.position);
60
+ }
61
+ };
62
+ useLayoutEffect(applyPendingCaret);
18
63
  const formatCurrency = (value) => {
19
64
  const decimalIndex = value.indexOf('.');
20
65
  if (!decimalNumber) {
21
- return Math.trunc(Number(value)).toString();
66
+ const numberValue = Number(value);
67
+ return Number.isNaN(numberValue)
68
+ ? value
69
+ : Math.trunc(numberValue).toString();
22
70
  }
23
71
  if (decimalIndex >= 0 && value.length > decimalIndex + 1) {
24
72
  const fractionalString = value.substring(decimalIndex + 1).substring(0, 2);
@@ -36,23 +84,37 @@ export const CurrencyInput = forwardRef(function CurrencyInput({ id: idProp, pla
36
84
  return max.toString();
37
85
  return value;
38
86
  };
87
+ const normalise = (value) => {
88
+ const EMPTY_INPUT = '';
89
+ if (value === EMPTY_INPUT)
90
+ return value;
91
+ return applyMinMax(formatCurrency(value));
92
+ };
39
93
  const handleChange = (value) => {
40
94
  if (onChange === undefined)
41
95
  return;
42
- const EMPTY_INPUT = '';
43
- if (value === EMPTY_INPUT) {
44
- onChange(value);
45
- }
46
- else {
47
- const amount = formatCurrency(value);
48
- const normalisedValue = applyMinMax(amount);
49
- onChange(normalisedValue);
50
- }
96
+ onChange(normalise(value));
51
97
  };
52
- return (_jsx(Field, { ...fieldProps, htmlFor: id, error: error, assistiveTextId: assistiveTextId, errorMsgId: errorMsgId, children: _jsxs(Box, { flex: true, alignItems: "center", justifyContent: "flex-start", children: [_jsx(InputLeadingIconContainer, { $size: 20, $disabled: disabled, style: { top: '-1px' }, children: _jsx(FontAwesomeIcon, { icon: faSterlingSign, color: theme.color.text.subtle }) }), _jsx(Input, { ref: ref, $error: error, disabled: disabled, type: "number", id: id, name: name, placeholder: placeholder, value: value, $frontIcon: true, $fallbackStyle: fallbackStyle, onChange: (e) => {
53
- if (onChange)
98
+ return (_jsx(Field, { ...fieldProps, htmlFor: id, error: error, assistiveTextId: assistiveTextId, errorMsgId: errorMsgId, children: _jsxs(Box, { flex: true, alignItems: "center", justifyContent: "flex-start", children: [_jsx(InputLeadingIconContainer, { $size: 20, $disabled: disabled, style: { top: '-1px' }, children: _jsx(FontAwesomeIcon, { icon: faSterlingSign, color: disabled ? theme.color.icon.subtle : theme.color.text.subtle }) }), _jsx(Input, { ref: setInputRef, $error: error, disabled: disabled, type: formatThousands ? 'text' : 'number', inputMode: formatThousands ? 'decimal' : undefined, id: id, name: name, placeholder: placeholder, value: displayValue, $frontIcon: true, $fallbackStyle: fallbackStyle, onChange: (e) => {
99
+ if (formatThousands) {
100
+ const { value: typed, selectionStart } = e.currentTarget;
101
+ const raw = stripFormatting(typed);
102
+ const nextDisplay = addThousandsSeparators(onChange ? normalise(raw) : raw);
103
+ const significantBeforeCaret = countSignificant(typed.slice(0, selectionStart ?? typed.length));
104
+ pendingCaret.current = {
105
+ value: nextDisplay,
106
+ position: caretAfterSignificant(nextDisplay, significantBeforeCaret),
107
+ };
108
+ queueMicrotask(applyPendingCaret);
109
+ if (onChange)
110
+ handleChange(raw);
111
+ }
112
+ else if (onChange) {
54
113
  handleChange(e.currentTarget.value);
114
+ }
55
115
  onInputChange?.(e);
56
- }, onWheel: (e) => e.currentTarget.blur(), ...controlAria, onBlur: onBlur })] }) }));
116
+ }, onWheel: formatThousands
117
+ ? undefined
118
+ : (e) => e.currentTarget.blur(), ...controlAria, onBlur: onBlur })] }) }));
57
119
  });
58
120
  //# sourceMappingURL=CurrencyInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyInput.js","sourceRoot":"","sources":["../../src/CurrencyInput/CurrencyInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAKL,UAAU,GACX,MAAM,OAAO,CAAA;AAEd,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAGvC,OAAO,EACL,KAAK,EACL,yBAAyB,GAC1B,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kDAAkD,CAAA;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AA2B5C,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC,SAAS,aAAa,CAC5D,EACE,EAAE,EAAE,MAAM,EACV,WAAW,EACX,IAAI,EACJ,KAAK,EACL,aAAa,GAAG,IAAI,EACpB,QAAQ,EACR,aAAa,EACb,MAAM,EACN,GAAG,EACH,GAAG,EACH,QAAQ,GAAG,KAAK,EAChB,KAAK,GAAG,KAAK,EACb,aAAa,EACb,GAA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CAAC,CAAC,CAAC,CAAA;oBACpB,CAAC,EACD,OAAO,EAAE,CAAC,CAA+B,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,KAChE,WAAW,EACf,MAAM,EAAE,MAAM,GACd,IACE,GACA,CACT,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import {\n FocusEvent,\n FormEvent,\n ForwardedRef,\n WheelEvent,\n forwardRef,\n} from 'react'\n\nimport { Box } from '../Box'\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\n\nimport {\n Input,\n InputLeadingIconContainer,\n} from '../fields/components/CommonInput'\nimport { useUniqueId } from '../utils/id'\nimport { getFieldAria } from '../fields/fieldAria'\nimport { faSterlingSign } from '@awesome.me/kit-46ca99185c/icons/classic/regular'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { useTheme } from 'styled-components'\n\nexport interface Props extends CommonFieldProps {\n placeholder: string\n name?: string\n value: string\n decimalNumber?: boolean\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n min?: number\n max?: number\n}\n\n/** on change or on input required */\ntype InputProps =\n | {\n /** on change is required and on input optional */\n onChange: (e: string) => void\n onInputChange?: (e: FormEvent<HTMLInputElement>) => void\n }\n | {\n /** on input is required and on change optional */\n onChange?: (e: string) => void\n onInputChange: (e: FormEvent<HTMLInputElement>) => void\n }\n\nexport type CurrencyInputProps = Props & InputProps\n\nexport const CurrencyInput = forwardRef(function CurrencyInput(\n {\n id: idProp,\n placeholder,\n name,\n value,\n decimalNumber = true,\n onChange,\n onInputChange,\n onBlur,\n min,\n max,\n disabled = false,\n error = false,\n fallbackStyle,\n ...fieldProps\n }: CurrencyInputProps,\n ref: ForwardedRef<HTMLInputElement>,\n) {\n const theme = useTheme()\n const id = useUniqueId(idProp)\n const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {\n ...fieldProps,\n error,\n })\n\n const formatCurrency = (value: string) => {\n const decimalIndex = value.indexOf('.')\n\n if (!decimalNumber) {\n return Math.trunc(Number(value)).toString()\n }\n\n if (decimalIndex >= 0 && value.length > decimalIndex + 1) {\n const fractionalString = value.substring(decimalIndex + 1).substring(0, 2)\n return `${value.substring(0, decimalIndex)}.${fractionalString}`\n } else {\n return value\n }\n }\n\n const applyMinMax = (value: string) => {\n const numberValue = Number(value)\n if (min && numberValue < min) return min.toString()\n if (max && numberValue > max) return max.toString()\n return value\n }\n\n const handleChange = (value: string) => {\n if (onChange === undefined) return\n const EMPTY_INPUT = ''\n\n if (value === EMPTY_INPUT) {\n onChange(value)\n } else {\n const amount = formatCurrency(value)\n const normalisedValue = applyMinMax(amount)\n\n onChange(normalisedValue)\n }\n }\n\n return (\n <Field\n {...fieldProps}\n htmlFor={id}\n error={error}\n assistiveTextId={assistiveTextId}\n errorMsgId={errorMsgId}\n >\n <Box flex alignItems=\"center\" justifyContent=\"flex-start\">\n <InputLeadingIconContainer\n $size={20}\n $disabled={disabled}\n style={{ top: '-1px' }}\n >\n <FontAwesomeIcon\n icon={faSterlingSign}\n color={theme.color.text.subtle}\n />\n </InputLeadingIconContainer>\n <Input\n ref={ref}\n $error={error}\n disabled={disabled}\n type=\"number\"\n id={id}\n name={name}\n placeholder={placeholder}\n value={value}\n $frontIcon={true}\n $fallbackStyle={fallbackStyle}\n onChange={(e: FormEvent<HTMLInputElement>) => {\n if (onChange) handleChange(e.currentTarget.value)\n onInputChange?.(e)\n }}\n onWheel={(e: WheelEvent<HTMLInputElement>) => e.currentTarget.blur()}\n {...controlAria}\n onBlur={onBlur}\n />\n </Box>\n </Field>\n )\n})\n"]}
1
+ {"version":3,"file":"CurrencyInput.js","sourceRoot":"","sources":["../../src/CurrencyInput/CurrencyInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAKL,UAAU,EACV,WAAW,EACX,eAAe,EACf,MAAM,GACP,MAAM,OAAO,CAAA;AAEd,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,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WAAW;gCAClB,QAAQ,EAAE,qBAAqB,CAC7B,WAAW,EACX,sBAAsB,CACvB;6BACF,CAAA;4BACD,cAAc,CAAC,iBAAiB,CAAC,CAAA;4BACjC,IAAI,QAAQ;gCAAE,YAAY,CAAC,GAAG,CAAC,CAAA;wBACjC,CAAC;6BAAM,IAAI,QAAQ,EAAE,CAAC;4BACpB,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;wBACrC,CAAC;wBACD,aAAa,EAAE,CAAC,CAAC,CAAC,CAAA;oBACpB,CAAC,EACD,OAAO,EACL,eAAe;wBACb,CAAC,CAAC,SAAS;wBACX,CAAC,CAAC,CAAC,CAA+B,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,KAE7D,WAAW,EACf,MAAM,EAAE,MAAM,GACd,IACE,GACA,CACT,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import {\n FocusEvent,\n FormEvent,\n ForwardedRef,\n WheelEvent,\n forwardRef,\n useCallback,\n useLayoutEffect,\n useRef,\n} from 'react'\n\nimport { Box } from '../Box'\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\n\nimport {\n Input,\n InputLeadingIconContainer,\n} from '../fields/components/CommonInput'\nimport { useUniqueId } from '../utils/id'\nimport { getFieldAria } from '../fields/fieldAria'\nimport { faSterlingSign } from '@awesome.me/kit-46ca99185c/icons/classic/regular'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { useTheme } from 'styled-components'\n\nexport interface Props extends CommonFieldProps {\n placeholder: string\n name?: string\n value: string\n decimalNumber?: boolean\n formatThousands?: boolean\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n min?: number\n max?: number\n}\n\nconst DIGITS_DOT_OR_MINUS = /[\\d.-]/\n\nconst stripFormatting = (value: string) => {\n const cleaned = value.replace(/(?!^)-|[^\\d.-]/g, '')\n const [integer, ...fraction] = cleaned.split('.')\n return fraction.length ? `${integer}.${fraction.join('')}` : integer\n}\n\nconst addThousandsSeparators = (value: string) => {\n if (!value) return value\n const [integer, fraction] = value.split('.')\n const grouped = integer.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',')\n return fraction === undefined ? grouped : `${grouped}.${fraction}`\n}\n\nconst countSignificant = (value: string) => value.replace(/[^\\d.-]/g, '').length\n\nconst caretAfterSignificant = (formatted: string, count: number) => {\n let seen = 0\n for (let i = 0; i < formatted.length; i++) {\n if (seen === count) return i\n if (DIGITS_DOT_OR_MINUS.test(formatted[i])) seen++\n }\n return formatted.length\n}\n\n/** on change or on input required */\ntype InputProps =\n | {\n /** on change is required and on input optional */\n onChange: (e: string) => void\n onInputChange?: (e: FormEvent<HTMLInputElement>) => void\n }\n | {\n /** on input is required and on change optional */\n onChange?: (e: string) => void\n onInputChange: (e: FormEvent<HTMLInputElement>) => void\n }\n\nexport type CurrencyInputProps = Props & InputProps\n\nexport const CurrencyInput = forwardRef(function CurrencyInput(\n {\n id: idProp,\n placeholder,\n name,\n value,\n decimalNumber = true,\n formatThousands = false,\n onChange,\n onInputChange,\n onBlur,\n min,\n max,\n disabled = false,\n error = false,\n fallbackStyle,\n ...fieldProps\n }: CurrencyInputProps,\n ref: ForwardedRef<HTMLInputElement>,\n) {\n const theme = useTheme()\n const id = useUniqueId(idProp)\n const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {\n ...fieldProps,\n error,\n })\n const inputRef = useRef<HTMLInputElement | null>(null)\n const pendingCaret = useRef<{ value: string; position: number } | null>(null)\n\n const setInputRef = useCallback(\n (node: HTMLInputElement | null) => {\n inputRef.current = node\n if (typeof ref === 'function') ref(node)\n else if (ref) ref.current = node\n },\n [ref],\n )\n\n const displayValue = formatThousands ? addThousandsSeparators(value) : value\n\n const applyPendingCaret = () => {\n const input = inputRef.current\n const pending = pendingCaret.current\n if (!input || !pending || input.value !== pending.value) return\n pendingCaret.current = null\n if (input.ownerDocument.activeElement === input) {\n input.setSelectionRange(pending.position, pending.position)\n }\n }\n\n useLayoutEffect(applyPendingCaret)\n\n const formatCurrency = (value: string) => {\n const decimalIndex = value.indexOf('.')\n\n if (!decimalNumber) {\n const numberValue = Number(value)\n return Number.isNaN(numberValue)\n ? value\n : Math.trunc(numberValue).toString()\n }\n\n if (decimalIndex >= 0 && value.length > decimalIndex + 1) {\n const fractionalString = value.substring(decimalIndex + 1).substring(0, 2)\n return `${value.substring(0, decimalIndex)}.${fractionalString}`\n } else {\n return value\n }\n }\n\n const applyMinMax = (value: string) => {\n const numberValue = Number(value)\n if (min && numberValue < min) return min.toString()\n if (max && numberValue > max) return max.toString()\n return value\n }\n\n const normalise = (value: string) => {\n const EMPTY_INPUT = ''\n if (value === EMPTY_INPUT) return value\n return applyMinMax(formatCurrency(value))\n }\n\n const handleChange = (value: string) => {\n if (onChange === undefined) return\n onChange(normalise(value))\n }\n\n return (\n <Field\n {...fieldProps}\n htmlFor={id}\n error={error}\n assistiveTextId={assistiveTextId}\n errorMsgId={errorMsgId}\n >\n <Box flex alignItems=\"center\" justifyContent=\"flex-start\">\n <InputLeadingIconContainer\n $size={20}\n $disabled={disabled}\n style={{ top: '-1px' }}\n >\n <FontAwesomeIcon\n icon={faSterlingSign}\n color={disabled ? theme.color.icon.subtle : theme.color.text.subtle}\n />\n </InputLeadingIconContainer>\n <Input\n ref={setInputRef}\n $error={error}\n disabled={disabled}\n type={formatThousands ? 'text' : 'number'}\n inputMode={formatThousands ? 'decimal' : undefined}\n id={id}\n name={name}\n placeholder={placeholder}\n value={displayValue}\n $frontIcon={true}\n $fallbackStyle={fallbackStyle}\n onChange={(e: FormEvent<HTMLInputElement>) => {\n if (formatThousands) {\n const { value: typed, selectionStart } = e.currentTarget\n const raw = stripFormatting(typed)\n const nextDisplay = addThousandsSeparators(\n onChange ? normalise(raw) : raw,\n )\n const significantBeforeCaret = countSignificant(\n typed.slice(0, selectionStart ?? typed.length),\n )\n pendingCaret.current = {\n value: nextDisplay,\n position: caretAfterSignificant(\n nextDisplay,\n significantBeforeCaret,\n ),\n }\n queueMicrotask(applyPendingCaret)\n if (onChange) handleChange(raw)\n } else if (onChange) {\n handleChange(e.currentTarget.value)\n }\n onInputChange?.(e)\n }}\n onWheel={\n formatThousands\n ? undefined\n : (e: WheelEvent<HTMLInputElement>) => e.currentTarget.blur()\n }\n {...controlAria}\n onBlur={onBlur}\n />\n </Box>\n </Field>\n )\n})\n"]}
@@ -1 +1,2 @@
1
1
  export { CurrencyInput } from './CurrencyInput';
2
+ export type { CurrencyInputProps } from './CurrencyInput';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/CurrencyInput/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA","sourcesContent":["export { CurrencyInput } from './CurrencyInput'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/CurrencyInput/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA","sourcesContent":["export { CurrencyInput } from './CurrencyInput'\nexport type { CurrencyInputProps } from './CurrencyInput'\n"]}
@@ -69,8 +69,10 @@ export const NumberInput = forwardRef(function NumberInput({ id: idProp, type =
69
69
  onChange(roundNumber(currentValue));
70
70
  }
71
71
  };
72
- const frontIconToRender = frontIconComponent ? (_jsx(InputLeadingIconContainer, { $size: 20, $iconColor: theme.color.text.subtle, children: frontIconComponent })) : frontIcon ? (_jsx(StyledFrontIcon, { $disabled: disabled, render: frontIcon, color: "sesame" })) : null;
73
- const trailingIconToRender = trailingIconComponent ? (_jsx(InputTrailingIconContainer, { $size: 20, $iconColor: theme.color.text.subtle, children: trailingIconComponent })) : trailingIcon ? (_jsx(StyledTrailingIcon, { $disabled: disabled, render: trailingIcon, color: "sesame" })) : null;
72
+ const iconColor = disabled ? 'color.icon.subtle' : 'color.text.subtle';
73
+ const iconFill = disabled ? theme.color.icon.subtle : theme.color.text.subtle;
74
+ const frontIconToRender = frontIconComponent ? (_jsx(InputLeadingIconContainer, { $size: 20, $disabled: disabled, $iconColor: iconFill, children: frontIconComponent })) : frontIcon ? (_jsx(StyledFrontIcon, { $disabled: disabled, render: frontIcon, color: iconColor })) : null;
75
+ const trailingIconToRender = trailingIconComponent ? (_jsx(InputTrailingIconContainer, { $size: 20, $disabled: disabled, $iconColor: iconFill, children: trailingIconComponent })) : trailingIcon ? (_jsx(StyledTrailingIcon, { $disabled: disabled, render: trailingIcon, color: iconColor })) : null;
74
76
  return (_jsx(Field, { ...fieldProps, htmlFor: id, error: error, assistiveTextId: assistiveTextId, errorMsgId: errorMsgId, children: _jsxs(Box, { flex: true, alignItems: "center", justifyContent: "flex-start", children: [frontIconToRender, _jsx(Input, { ref: ref, $error: error, disabled: disabled, type: type, id: id, name: name, placeholder: placeholder, value: value, $frontIcon: Boolean(frontIconToRender), step: step, $fallbackStyle: fallbackStyle, onWheel: (e) => e.currentTarget.blur(), ...controlAria, onChange: (e) => {
75
77
  if (onChange)
76
78
  handleChange(e.currentTarget.value);
@@ -1 +1 @@
1
- {"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["../../src/NumberInput/NumberInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAKL,UAAU,GACX,MAAM,OAAO,CAAA;AACd,OAAO,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAGvC,OAAO,EACL,KAAK,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,eAAe,EACf,kBAAkB,GACnB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EACL,aAAa,EACb,WAAW,GACZ,MAAM,kDAAkD,CAAA;AACzD,OAAO,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ent,\n FormEvent,\n ForwardedRef,\n MouseEvent,\n forwardRef,\n} from 'react'\nimport styled, { useTheme } from 'styled-components'\n\nimport { Box } from '../Box'\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\n\nimport {\n Input,\n InputLeadingIconContainer,\n InputTrailingIconContainer,\n StyledFrontIcon,\n StyledTrailingIcon,\n} from '../fields/components/CommonInput'\nimport { useUniqueId } from '../utils/id'\nimport { getFieldAria } from '../fields/fieldAria'\nimport {\n faChevronDown,\n faChevronUp,\n} from '@awesome.me/kit-46ca99185c/icons/classic/regular'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { IconContainer } from '../sharedStyles/shared.styles'\n\nexport interface Props extends CommonFieldProps {\n type?: 'number'\n placeholder: string\n name?: string\n value: string\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n min?: number\n max?: number\n step?: number\n}\n\n/** on change or on input required */\ntype InputProps =\n | {\n /** on change is required and on input optional */\n onChange: (e: string | number) => void\n onInputChange?: (e: FormEvent<HTMLInputElement>) => void\n }\n | {\n /** on input is required and on change optional */\n onChange?: (e: string | number) => void\n onInputChange: (e: FormEvent<HTMLInputElement>) => void\n }\n\nexport type NumberInputProps = Props & InputProps\n\nexport const NumberInput = forwardRef(function NumberInput(\n {\n id: idProp,\n type = 'number',\n placeholder,\n name,\n value,\n onChange,\n onInputChange,\n onBlur,\n min = -999999,\n max = 999999,\n step = 0,\n disabled = false,\n error = false,\n frontIcon,\n frontIconComponent,\n trailingIconComponent,\n trailingIcon,\n fallbackStyle,\n ...fieldProps\n }: NumberInputProps,\n ref: ForwardedRef<HTMLInputElement>,\n) {\n const id = useUniqueId(idProp)\n const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {\n ...fieldProps,\n error,\n })\n const theme = useTheme()\n // Check whether the min/max value exists is within the specified range\n const isInRange = (value: number) => {\n if (min && value < min) {\n return false\n }\n\n if (max && value > max) {\n return false\n }\n\n return true\n }\n\n // Round the number to two decimal places\n const roundNumber = (event: number) => {\n return Math.round(event * 100) / 100\n }\n\n const applyMinMax = (value: number) => {\n if (min && value < min) return min\n if (max && value > max) return max\n return value\n }\n\n const handleChange = (event: string) => {\n if (onChange === undefined) return\n const EMPTY_INPUT = ''\n\n if (event === EMPTY_INPUT) {\n onChange(event)\n } else {\n const amount = Number(event)\n const normalisedValue = applyMinMax(amount)\n\n onChange(normalisedValue)\n }\n }\n // Increment or decrement the value when clicking the Spinner controls\n const incrementValue = (event: MouseEvent<HTMLButtonElement>) => {\n if (onChange === undefined) return\n event.preventDefault()\n const currentValue = Number(value) + step\n\n if (isInRange(currentValue)) {\n onChange(roundNumber(currentValue))\n }\n }\n\n const decrementValue = (event: MouseEvent<HTMLButtonElement>) => {\n if (onChange === undefined) return\n event.preventDefault()\n const currentValue = Number(value) - step\n\n if (isInRange(currentValue)) {\n onChange(roundNumber(currentValue))\n }\n }\n\n const frontIconToRender = frontIconComponent ? (\n <InputLeadingIconContainer $size={20} $iconColor={theme.color.text.subtle}>\n {frontIconComponent}\n </InputLeadingIconContainer>\n ) : frontIcon ? (\n <StyledFrontIcon $disabled={disabled} render={frontIcon} color=\"sesame\" />\n ) : null\n\n const trailingIconToRender = trailingIconComponent ? (\n <InputTrailingIconContainer $size={20} $iconColor={theme.color.text.subtle}>\n {trailingIconComponent}\n </InputTrailingIconContainer>\n ) : trailingIcon ? (\n <StyledTrailingIcon\n $disabled={disabled}\n render={trailingIcon}\n color=\"sesame\"\n />\n ) : null\n\n return (\n <Field\n {...fieldProps}\n htmlFor={id}\n error={error}\n assistiveTextId={assistiveTextId}\n errorMsgId={errorMsgId}\n >\n <Box flex alignItems=\"center\" justifyContent=\"flex-start\">\n {frontIconToRender}\n <Input\n ref={ref}\n $error={error}\n disabled={disabled}\n type={type}\n id={id}\n name={name}\n placeholder={placeholder}\n value={value}\n $frontIcon={Boolean(frontIconToRender)}\n step={step}\n $fallbackStyle={fallbackStyle}\n onWheel={(e) => e.currentTarget.blur()}\n {...controlAria}\n onChange={(e: FormEvent<HTMLInputElement>) => {\n if (onChange) handleChange(e.currentTarget.value)\n onInputChange?.(e)\n }}\n onBlur={onBlur}\n />\n\n {onChange && step > 0 && (\n <Spinner>\n <SpinnerButton\n aria-label=\"Increase\"\n onClick={incrementValue}\n disabled={disabled}\n >\n <IconContainer $size={20}>\n <FontAwesomeIcon\n icon={faChevronDown}\n color={theme.color.text.subtle}\n />\n </IconContainer>\n </SpinnerButton>\n\n <SpinnerButton\n aria-label=\"Decrease\"\n onClick={decrementValue}\n disabled={disabled}\n >\n <IconContainer $size={20}>\n <FontAwesomeIcon\n icon={faChevronUp}\n color={theme.color.text.subtle}\n />\n </IconContainer>\n </SpinnerButton>\n </Spinner>\n )}\n {trailingIconToRender && !step && trailingIconToRender}\n </Box>\n </Field>\n )\n})\n\nconst Spinner = styled.div`\n position: relative;\n display: flex;\n right: 58px;\n margin-right: -58px;\n`\n\ninterface IButton {\n disabled: boolean\n}\n\nconst SpinnerButton = styled.button<IButton>`\n width: 24px;\n height: 24px;\n background-color: transparent;\n border: 0;\n padding: 0;\n cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')};\n`\n"]}
1
+ {"version":3,"file":"NumberInput.js","sourceRoot":"","sources":["../../src/NumberInput/NumberInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAKL,UAAU,GACX,MAAM,OAAO,CAAA;AACd,OAAO,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAGvC,OAAO,EACL,KAAK,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,eAAe,EACf,kBAAkB,GACnB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAA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,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;CAKzB,CAAA;AAMD,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAS;;;;;;YAMhC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;CACnE,CAAA","sourcesContent":["import {\n FocusEvent,\n FormEvent,\n ForwardedRef,\n MouseEvent,\n forwardRef,\n} from 'react'\nimport styled, { useTheme } from 'styled-components'\n\nimport { Box } from '../Box'\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\n\nimport {\n Input,\n InputLeadingIconContainer,\n InputTrailingIconContainer,\n StyledFrontIcon,\n StyledTrailingIcon,\n} from '../fields/components/CommonInput'\nimport { useUniqueId } from '../utils/id'\nimport { getFieldAria } from '../fields/fieldAria'\nimport {\n faChevronDown,\n faChevronUp,\n} from '@awesome.me/kit-46ca99185c/icons/classic/regular'\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\nimport { IconContainer } from '../sharedStyles/shared.styles'\n\nexport interface Props extends CommonFieldProps {\n type?: 'number'\n placeholder: string\n name?: string\n value: string\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n min?: number\n max?: number\n step?: number\n}\n\n/** on change or on input required */\ntype InputProps =\n | {\n /** on change is required and on input optional */\n onChange: (e: string | number) => void\n onInputChange?: (e: FormEvent<HTMLInputElement>) => void\n }\n | {\n /** on input is required and on change optional */\n onChange?: (e: string | number) => void\n onInputChange: (e: FormEvent<HTMLInputElement>) => void\n }\n\nexport type NumberInputProps = Props & InputProps\n\nexport const NumberInput = forwardRef(function NumberInput(\n {\n id: idProp,\n type = 'number',\n placeholder,\n name,\n value,\n onChange,\n onInputChange,\n onBlur,\n min = -999999,\n max = 999999,\n step = 0,\n disabled = false,\n error = false,\n frontIcon,\n frontIconComponent,\n trailingIconComponent,\n trailingIcon,\n fallbackStyle,\n ...fieldProps\n }: NumberInputProps,\n ref: ForwardedRef<HTMLInputElement>,\n) {\n const id = useUniqueId(idProp)\n const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {\n ...fieldProps,\n error,\n })\n const theme = useTheme()\n // Check whether the min/max value exists is within the specified range\n const isInRange = (value: number) => {\n if (min && value < min) {\n return false\n }\n\n if (max && value > max) {\n return false\n }\n\n return true\n }\n\n // Round the number to two decimal places\n const roundNumber = (event: number) => {\n return Math.round(event * 100) / 100\n }\n\n const applyMinMax = (value: number) => {\n if (min && value < min) return min\n if (max && value > max) return max\n return value\n }\n\n const handleChange = (event: string) => {\n if (onChange === undefined) return\n const EMPTY_INPUT = ''\n\n if (event === EMPTY_INPUT) {\n onChange(event)\n } else {\n const amount = Number(event)\n const normalisedValue = applyMinMax(amount)\n\n onChange(normalisedValue)\n }\n }\n // Increment or decrement the value when clicking the Spinner controls\n const incrementValue = (event: MouseEvent<HTMLButtonElement>) => {\n if (onChange === undefined) return\n event.preventDefault()\n const currentValue = Number(value) + step\n\n if (isInRange(currentValue)) {\n onChange(roundNumber(currentValue))\n }\n }\n\n const decrementValue = (event: MouseEvent<HTMLButtonElement>) => {\n if (onChange === undefined) return\n event.preventDefault()\n const currentValue = Number(value) - step\n\n if (isInRange(currentValue)) {\n onChange(roundNumber(currentValue))\n }\n }\n\n const iconColor = disabled ? 'color.icon.subtle' : 'color.text.subtle'\n const iconFill = disabled ? theme.color.icon.subtle : theme.color.text.subtle\n\n const frontIconToRender = frontIconComponent ? (\n <InputLeadingIconContainer\n $size={20}\n $disabled={disabled}\n $iconColor={iconFill}\n >\n {frontIconComponent}\n </InputLeadingIconContainer>\n ) : frontIcon ? (\n <StyledFrontIcon\n $disabled={disabled}\n render={frontIcon}\n color={iconColor}\n />\n ) : null\n\n const trailingIconToRender = trailingIconComponent ? (\n <InputTrailingIconContainer\n $size={20}\n $disabled={disabled}\n $iconColor={iconFill}\n >\n {trailingIconComponent}\n </InputTrailingIconContainer>\n ) : trailingIcon ? (\n <StyledTrailingIcon\n $disabled={disabled}\n render={trailingIcon}\n color={iconColor}\n />\n ) : null\n\n return (\n <Field\n {...fieldProps}\n htmlFor={id}\n error={error}\n assistiveTextId={assistiveTextId}\n errorMsgId={errorMsgId}\n >\n <Box flex alignItems=\"center\" justifyContent=\"flex-start\">\n {frontIconToRender}\n <Input\n ref={ref}\n $error={error}\n disabled={disabled}\n type={type}\n id={id}\n name={name}\n placeholder={placeholder}\n value={value}\n $frontIcon={Boolean(frontIconToRender)}\n step={step}\n $fallbackStyle={fallbackStyle}\n onWheel={(e) => e.currentTarget.blur()}\n {...controlAria}\n onChange={(e: FormEvent<HTMLInputElement>) => {\n if (onChange) handleChange(e.currentTarget.value)\n onInputChange?.(e)\n }}\n onBlur={onBlur}\n />\n\n {onChange && step > 0 && (\n <Spinner>\n <SpinnerButton\n aria-label=\"Increase\"\n onClick={incrementValue}\n disabled={disabled}\n >\n <IconContainer $size={20}>\n <FontAwesomeIcon\n icon={faChevronDown}\n color={theme.color.text.subtle}\n />\n </IconContainer>\n </SpinnerButton>\n\n <SpinnerButton\n aria-label=\"Decrease\"\n onClick={decrementValue}\n disabled={disabled}\n >\n <IconContainer $size={20}>\n <FontAwesomeIcon\n icon={faChevronUp}\n color={theme.color.text.subtle}\n />\n </IconContainer>\n </SpinnerButton>\n </Spinner>\n )}\n {trailingIconToRender && !step && trailingIconToRender}\n </Box>\n </Field>\n )\n})\n\nconst Spinner = styled.div`\n position: relative;\n display: flex;\n right: 58px;\n margin-right: -58px;\n`\n\ninterface IButton {\n disabled: boolean\n}\n\nconst SpinnerButton = styled.button<IButton>`\n width: 24px;\n height: 24px;\n background-color: transparent;\n border: 0;\n padding: 0;\n cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')};\n`\n"]}
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, } from 'react';
3
3
  import { Box } from '../Box';
4
4
  import { Field } from '../fields/Field';
5
- import { Input, InputLeadingIconContainer, StyledFrontIcon, StyledTrailingIcon, } from '../fields/components/CommonInput';
5
+ import { Input, InputLeadingIconContainer, InputTrailingIconContainer, StyledFrontIcon, StyledTrailingIcon, } from '../fields/components/CommonInput';
6
6
  import { useUniqueId } from '../utils/id';
7
7
  import { getFieldAria } from '../fields/fieldAria';
8
8
  import { useTheme } from 'styled-components';
@@ -26,9 +26,11 @@ export const TextInput = forwardRef(function TextInput({ id: idProp, type = 'tex
26
26
  onAutoFill();
27
27
  }
28
28
  };
29
- const frontIconToRender = frontIconComponent ? (_jsx(InputLeadingIconContainer, { $size: 20, $iconColor: theme.color.text.subtle, children: frontIconComponent })) : frontIcon ? (_jsx(StyledFrontIcon, { $disabled: disabled, render: frontIcon, color: "color.icon.base" })) : null;
30
- const trailingIconToRender = trailingIconComponent ? (_jsx(InputLeadingIconContainer, { $size: 20, $iconColor: theme.color.text.subtle, children: trailingIconComponent })) : trailingIcon ? (_jsx(StyledTrailingIcon, { $disabled: disabled, render: trailingIcon, color: "color.icon.base" })) : null;
31
- return (_jsx(Field, { ...fieldProps, htmlFor: id, error: error, assistiveTextId: assistiveTextId, errorMsgId: errorMsgId, children: _jsxs(Box, { flex: true, alignItems: "center", justifyContent: "flex-start", children: [frontIconToRender, _jsx(Input, { disabled: disabled, type: type, id: id, name: name, ref: ref, onAnimationEnd: handleAnimationEnd, placeholder: placeholder, value: value, $error: error, $frontIcon: Boolean(frontIconToRender), $fallbackStyle: fallbackStyle, autoComplete: autoCompleteAttr, onChange: (e) => {
29
+ const iconColor = disabled ? 'color.icon.subtle' : 'color.icon.base';
30
+ const iconFill = disabled ? theme.color.icon.subtle : theme.color.text.subtle;
31
+ const frontIconToRender = frontIconComponent ? (_jsx(InputLeadingIconContainer, { $size: 20, $disabled: disabled, $iconColor: iconFill, children: frontIconComponent })) : frontIcon ? (_jsx(StyledFrontIcon, { $disabled: disabled, render: frontIcon, color: iconColor })) : null;
32
+ const trailingIconToRender = trailingIconComponent ? (_jsx(InputTrailingIconContainer, { $size: 20, $disabled: disabled, $iconColor: iconFill, children: trailingIconComponent })) : trailingIcon ? (_jsx(StyledTrailingIcon, { $disabled: disabled, render: trailingIcon, color: iconColor })) : null;
33
+ return (_jsx(Field, { ...fieldProps, htmlFor: id, error: error, assistiveTextId: assistiveTextId, errorMsgId: errorMsgId, children: _jsxs(Box, { flex: true, alignItems: "center", justifyContent: "flex-start", children: [frontIconToRender, _jsx(Input, { disabled: disabled, type: type, id: id, name: name, ref: ref, onAnimationEnd: handleAnimationEnd, placeholder: placeholder, value: value, $error: error, $frontIcon: Boolean(frontIconToRender), $trailingIcon: Boolean(trailingIconToRender), $fallbackStyle: fallbackStyle, autoComplete: autoCompleteAttr, onChange: (e) => {
32
34
  onChange?.(e.currentTarget.value);
33
35
  onInputChange?.(e);
34
36
  }, onBlur: onBlur, inputMode: inputModeAttr, ...controlAria }), trailingIconToRender] }) }));
@@ -1 +1 @@
1
- {"version":3,"file":"TextInput.js","sourceRoot":"","sources":["../../src/TextInput/TextInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAKL,UAAU,GAEX,MAAM,OAAO,CAAA;AAEd,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAEvC,OAAO,EACL,KAAK,EACL,yBAAyB,EACzB,eAAe,EACf,kBAAkB,GACnB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAoC5C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,SAAS,CACpD,EACE,EAAE,EAAE,MAAM,EACV,IAAI,GAAG,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,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CACjB,KAAC,kBAAkB,IACjB,SAAS,EAAE,QAAQ,EACnB,MAAM,EAAE,YAAY,EACpB,KAAK,EAAC,iBAAiB,GACvB,CACH,CAAC,CAAC,CAAC,IAAI,CAAA;IAER,OAAO,CACL,KAAC,KAAK,OACA,UAAU,EACd,OAAO,EAAE,EAAE,EACX,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,UAAU,YAEtB,MAAC,GAAG,IAAC,IAAI,QAAC,UAAU,EAAC,QAAQ,EAAC,cAAc,EAAC,YAAY,aACtD,iBAAiB,EAClB,KAAC,KAAK,IACJ,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,GAAG,EACR,cAAc,EAAE,kBAAkB,EAClC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,KAAK,EACb,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,EACtC,cAAc,EAAE,aAAa,EAC7B,YAAY,EAAE,gBAAgB,EAC9B,QAAQ,EAAE,CAAC,CAA8B,EAAE,EAAE;wBAC3C,QAAQ,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;wBACjC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAA;oBACpB,CAAC,EACD,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,aAAa,KACpB,WAAW,GACf,EACD,oBAAoB,IACjB,GACA,CACT,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import {\n FocusEvent,\n AnimationEvent,\n FormEvent,\n ForwardedRef,\n forwardRef,\n HTMLInputAutoCompleteAttribute,\n} from 'react'\n\nimport { Box } from '../Box'\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\nimport {\n Input,\n InputLeadingIconContainer,\n StyledFrontIcon,\n StyledTrailingIcon,\n} from '../fields/components/CommonInput'\nimport { useUniqueId } from '../utils/id'\nimport { getFieldAria } from '../fields/fieldAria'\nimport { useTheme } from 'styled-components'\n\ninterface Props extends CommonFieldProps {\n type?: 'text' | 'email' | 'password' | 'time' | 'date' | 'tel'\n placeholder: string\n name?: string\n value: string\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n /**\n * Triggers after animation end (animation duration is 2s),\n * the animation starts when a user selects or hovers over an autofill option\n */\n onAutoFill?: () => void\n}\n\ntype InputMode = 'text' | 'email' | 'numeric'\n\n/** on change or on input required */\ntype InputProps = (\n | {\n /** on change is required and on input optional */\n onChange: (e: string) => void\n onInputChange?: (e: FormEvent<HTMLInputElement>) => void\n }\n | {\n /** on input is required and on change optional */\n onChange?: (e: string) => void\n onInputChange: (e: FormEvent<HTMLInputElement>) => void\n }\n) & {\n autoCompleteAttr?: HTMLInputAutoCompleteAttribute\n inputModeAttr?: InputMode\n}\n\nexport type TextInputProps = Props & InputProps\n\n/**\n * A reusable TextInput component that supports various input types, custom styling, icons,\n * and autofill detection.\n *\n * ### Caveats:\n * - `onAutoFill` triggers after animation end (animation duration is 2s),\n * the animation starts when a user selects or hovers over an autofill option\n */\nexport const TextInput = forwardRef(function TextInput(\n {\n id: idProp,\n type = 'text',\n placeholder,\n name,\n value,\n error = false,\n onBlur,\n onChange,\n onInputChange,\n onAutoFill,\n disabled = false,\n frontIcon,\n frontIconComponent,\n trailingIconComponent,\n trailingIcon,\n fallbackStyle,\n autoCompleteAttr = 'off',\n inputModeAttr,\n ...fieldProps\n }: TextInputProps,\n ref: ForwardedRef<HTMLInputElement>,\n) {\n const id = useUniqueId(idProp)\n const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {\n ...fieldProps,\n error,\n })\n const theme = useTheme()\n\n const handleAnimationEnd = (e: AnimationEvent<HTMLInputElement>) => {\n if (e.animationName === 'onAutoFillStart' && onAutoFill && !!value) {\n onAutoFill()\n }\n }\n\n const frontIconToRender = frontIconComponent ? (\n <InputLeadingIconContainer $size={20} $iconColor={theme.color.text.subtle}>\n {frontIconComponent}\n </InputLeadingIconContainer>\n ) : frontIcon ? (\n <StyledFrontIcon\n $disabled={disabled}\n render={frontIcon}\n color=\"color.icon.base\"\n />\n ) : null\n\n const trailingIconToRender = trailingIconComponent ? (\n <InputLeadingIconContainer $size={20} $iconColor={theme.color.text.subtle}>\n {trailingIconComponent}\n </InputLeadingIconContainer>\n ) : trailingIcon ? (\n <StyledTrailingIcon\n $disabled={disabled}\n render={trailingIcon}\n color=\"color.icon.base\"\n />\n ) : null\n\n return (\n <Field\n {...fieldProps}\n htmlFor={id}\n error={error}\n assistiveTextId={assistiveTextId}\n errorMsgId={errorMsgId}\n >\n <Box flex alignItems=\"center\" justifyContent=\"flex-start\">\n {frontIconToRender}\n <Input\n disabled={disabled}\n type={type}\n id={id}\n name={name}\n ref={ref}\n onAnimationEnd={handleAnimationEnd}\n placeholder={placeholder}\n value={value}\n $error={error}\n $frontIcon={Boolean(frontIconToRender)}\n $fallbackStyle={fallbackStyle}\n autoComplete={autoCompleteAttr}\n onChange={(e: FormEvent<HTMLInputElement>) => {\n onChange?.(e.currentTarget.value)\n onInputChange?.(e)\n }}\n onBlur={onBlur}\n inputMode={inputModeAttr}\n {...controlAria}\n />\n {trailingIconToRender}\n </Box>\n </Field>\n )\n})\n"]}
1
+ {"version":3,"file":"TextInput.js","sourceRoot":"","sources":["../../src/TextInput/TextInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAKL,UAAU,GAEX,MAAM,OAAO,CAAA;AAEd,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAEvC,OAAO,EACL,KAAK,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,eAAe,EACf,kBAAkB,GACnB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aA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,EAAE,gBAAgB,EAC9B,QAAQ,EAAE,CAAC,CAA8B,EAAE,EAAE;wBAC3C,QAAQ,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;wBACjC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAA;oBACpB,CAAC,EACD,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,aAAa,KACpB,WAAW,GACf,EACD,oBAAoB,IACjB,GACA,CACT,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import {\n FocusEvent,\n AnimationEvent,\n FormEvent,\n ForwardedRef,\n forwardRef,\n HTMLInputAutoCompleteAttribute,\n} from 'react'\n\nimport { Box } from '../Box'\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\nimport {\n Input,\n InputLeadingIconContainer,\n InputTrailingIconContainer,\n StyledFrontIcon,\n StyledTrailingIcon,\n} from '../fields/components/CommonInput'\nimport { useUniqueId } from '../utils/id'\nimport { getFieldAria } from '../fields/fieldAria'\nimport { useTheme } from 'styled-components'\n\ninterface Props extends CommonFieldProps {\n type?: 'text' | 'email' | 'password' | 'time' | 'date' | 'tel'\n placeholder: string\n name?: string\n value: string\n onBlur?: (e: FocusEvent<HTMLInputElement>) => void\n /**\n * Triggers after animation end (animation duration is 2s),\n * the animation starts when a user selects or hovers over an autofill option\n */\n onAutoFill?: () => void\n}\n\ntype InputMode = 'text' | 'email' | 'numeric'\n\n/** on change or on input required */\ntype InputProps = (\n | {\n /** on change is required and on input optional */\n onChange: (e: string) => void\n onInputChange?: (e: FormEvent<HTMLInputElement>) => void\n }\n | {\n /** on input is required and on change optional */\n onChange?: (e: string) => void\n onInputChange: (e: FormEvent<HTMLInputElement>) => void\n }\n) & {\n autoCompleteAttr?: HTMLInputAutoCompleteAttribute\n inputModeAttr?: InputMode\n}\n\nexport type TextInputProps = Props & InputProps\n\n/**\n * A reusable TextInput component that supports various input types, custom styling, icons,\n * and autofill detection.\n *\n * ### Caveats:\n * - `onAutoFill` triggers after animation end (animation duration is 2s),\n * the animation starts when a user selects or hovers over an autofill option\n */\nexport const TextInput = forwardRef(function TextInput(\n {\n id: idProp,\n type = 'text',\n placeholder,\n name,\n value,\n error = false,\n onBlur,\n onChange,\n onInputChange,\n onAutoFill,\n disabled = false,\n frontIcon,\n frontIconComponent,\n trailingIconComponent,\n trailingIcon,\n fallbackStyle,\n autoCompleteAttr = 'off',\n inputModeAttr,\n ...fieldProps\n }: TextInputProps,\n ref: ForwardedRef<HTMLInputElement>,\n) {\n const id = useUniqueId(idProp)\n const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {\n ...fieldProps,\n error,\n })\n const theme = useTheme()\n\n const handleAnimationEnd = (e: AnimationEvent<HTMLInputElement>) => {\n if (e.animationName === 'onAutoFillStart' && onAutoFill && !!value) {\n onAutoFill()\n }\n }\n\n const iconColor = disabled ? 'color.icon.subtle' : 'color.icon.base'\n const iconFill = disabled ? theme.color.icon.subtle : theme.color.text.subtle\n\n const frontIconToRender = frontIconComponent ? (\n <InputLeadingIconContainer\n $size={20}\n $disabled={disabled}\n $iconColor={iconFill}\n >\n {frontIconComponent}\n </InputLeadingIconContainer>\n ) : frontIcon ? (\n <StyledFrontIcon\n $disabled={disabled}\n render={frontIcon}\n color={iconColor}\n />\n ) : null\n\n const trailingIconToRender = trailingIconComponent ? (\n <InputTrailingIconContainer\n $size={20}\n $disabled={disabled}\n $iconColor={iconFill}\n >\n {trailingIconComponent}\n </InputTrailingIconContainer>\n ) : trailingIcon ? (\n <StyledTrailingIcon\n $disabled={disabled}\n render={trailingIcon}\n color={iconColor}\n />\n ) : null\n\n return (\n <Field\n {...fieldProps}\n htmlFor={id}\n error={error}\n assistiveTextId={assistiveTextId}\n errorMsgId={errorMsgId}\n >\n <Box flex alignItems=\"center\" justifyContent=\"flex-start\">\n {frontIconToRender}\n <Input\n disabled={disabled}\n type={type}\n id={id}\n name={name}\n ref={ref}\n onAnimationEnd={handleAnimationEnd}\n placeholder={placeholder}\n value={value}\n $error={error}\n $frontIcon={Boolean(frontIconToRender)}\n $trailingIcon={Boolean(trailingIconToRender)}\n $fallbackStyle={fallbackStyle}\n autoComplete={autoCompleteAttr}\n onChange={(e: FormEvent<HTMLInputElement>) => {\n onChange?.(e.currentTarget.value)\n onInputChange?.(e)\n }}\n onBlur={onBlur}\n inputMode={inputModeAttr}\n {...controlAria}\n />\n {trailingIconToRender}\n </Box>\n </Field>\n )\n})\n"]}
@@ -4,6 +4,7 @@ import styled from 'styled-components';
4
4
  import { Field } from '../fields/Field';
5
5
  import { useUniqueId } from '../utils/id';
6
6
  import { getFieldAria } from '../fields/fieldAria';
7
+ import { fieldDisabledStyle, fieldFocusAttrs, fieldFocusRing, fieldHoverBorderColor, } from '../fields/components/fieldStyles';
7
8
  export const Textarea = forwardRef(function Textarea({ id: idProp, name, value, onChange, onInputChange, resize = 'none', error = false, placeholder, disabled = false, maxLength, onBlur, rows = 4, fallbackStyle, ...fieldProps }, ref) {
8
9
  const id = useUniqueId(idProp);
9
10
  const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {
@@ -15,7 +16,7 @@ export const Textarea = forwardRef(function Textarea({ id: idProp, name, value,
15
16
  onInputChange?.(e);
16
17
  }, maxLength: maxLength, onBlur: onBlur, rows: rows, ...controlAria }) }));
17
18
  });
18
- const StyledTextArea = styled.textarea `
19
+ const StyledTextArea = styled.textarea.attrs(fieldFocusAttrs) `
19
20
  font-size: 16px;
20
21
  font: inherit;
21
22
  line-height: 20px;
@@ -30,14 +31,24 @@ const StyledTextArea = styled.textarea `
30
31
  color: ${({ theme }) => theme.color.text.base};
31
32
  resize: ${({ $resize }) => $resize};
32
33
  cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'text')};
33
- opacity: ${({ disabled }) => (disabled ? '0.5' : '1')};
34
34
  border-color: ${({ $error, theme }) => $error ? theme.color.feedback.negative[200] : theme.color.border.subtle};
35
35
  outline: none;
36
36
 
37
- &:hover,
38
- &:focus,
39
- &:focus-visible {
40
- border-color: ${({ $error, theme }) => $error ? theme.color.feedback.negative[200] : theme.color.border.base};
37
+ &:hover:not(:disabled):not(:focus) {
38
+ border-color: ${({ $error, theme }) => fieldHoverBorderColor(theme, $error)};
39
+ }
40
+
41
+ &:focus {
42
+ border-color: ${({ $error, theme }) => $error
43
+ ? theme.color.feedback.negative[200]
44
+ : theme.color.border.contrast};
45
+ }
46
+
47
+ ${fieldFocusRing}
48
+ ${fieldDisabledStyle}
49
+
50
+ &::placeholder {
51
+ color: ${({ theme }) => theme.color.text.subtle};
41
52
  }
42
53
  `;
43
54
  //# sourceMappingURL=Textarea.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../../src/Textarea/Textarea.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAuC,UAAU,EAAE,MAAM,OAAO,CAAA;AACvE,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AA+BlD,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC,SAAS,QAAQ,CAClD,EACE,EAAE,EAAE,MAAM,EACV,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,aAAa,EACb,MAAM,GAAG,MAAM,EACf,KAAK,GAAG,KAAK,EACb,WAAW,EACX,QAAQ,GAAG,KAAK,EAChB,SAAS,EACT,MAAM,EACN,IAAI,GAAG,CAAC,EACR,aAAa,EACb,GAAG,UAAU,EACC,EAChB,GAAsC;IAEtC,MAAM,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IAC9B,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC,EAAE,EAAE;QACpE,GAAG,UAAU;QACb,KAAK;KACN,CAAC,CAAA;IACF,OAA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CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;aACpD,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;kBACrC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CACpC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM;;;;;;oBAMvD,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CACpC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI;;CAE1E,CAAA","sourcesContent":["import { FocusEvent, FormEvent, ForwardedRef, forwardRef } from 'react'\nimport styled from 'styled-components'\n\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\nimport { useUniqueId } from '../utils/id'\nimport { getFieldAria } from '../fields/fieldAria'\nimport { MarginProps } from '../utils/space'\n\ntype BaseProps = {\n id?: string\n placeholder?: string\n name?: string\n value: string\n error?: boolean\n errorMsg?: string\n resize?: 'none' | 'both'\n disabled?: boolean\n maxLength?: number\n onBlur?: (e: FocusEvent<HTMLTextAreaElement>) => void\n rows?: number\n fallbackStyle?: boolean\n} & CommonFieldProps &\n MarginProps\n\ntype TruncateProps =\n | {\n onChange: (e: string) => void\n onInputChange?: (e: FormEvent<HTMLTextAreaElement>) => void\n }\n | {\n onChange?: (e: string) => void\n onInputChange: (e: FormEvent<HTMLTextAreaElement>) => void\n }\n\nexport type TextareaProps = BaseProps & TruncateProps\n\nexport const Textarea = forwardRef(function Textarea(\n {\n id: idProp,\n name,\n value,\n onChange,\n onInputChange,\n resize = 'none',\n error = false,\n placeholder,\n disabled = false,\n maxLength,\n onBlur,\n rows = 4,\n fallbackStyle,\n ...fieldProps\n }: TextareaProps,\n ref: ForwardedRef<HTMLTextAreaElement>,\n) {\n const id = useUniqueId(idProp)\n const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {\n ...fieldProps,\n error,\n })\n return (\n <Field\n {...fieldProps}\n htmlFor={id}\n error={error}\n assistiveTextId={assistiveTextId}\n errorMsgId={errorMsgId}\n >\n <StyledTextArea\n ref={ref}\n $error={error}\n id={id}\n name={name}\n disabled={disabled}\n $resize={resize}\n $fallbackStyle={fallbackStyle}\n placeholder={placeholder}\n value={value}\n onChange={(e: FormEvent<HTMLTextAreaElement>) => {\n onChange?.(e.currentTarget.value)\n onInputChange?.(e)\n }}\n maxLength={maxLength}\n onBlur={onBlur}\n rows={rows}\n {...controlAria}\n />\n </Field>\n )\n})\n\ninterface TextArea {\n $resize: 'none' | 'both'\n disabled: boolean\n $error: boolean\n $fallbackStyle?: boolean\n}\n\nconst StyledTextArea = styled.textarea<TextArea>`\n font-size: 16px;\n font: inherit;\n line-height: 20px;\n background: ${({ $fallbackStyle, theme }) =>\n $fallbackStyle\n ? theme.color.surface.base[300]\n : theme.color.background['000']};\n border: 2px solid ${({ theme }) => theme.color.border.subtle};\n box-sizing: border-box;\n border-radius: 12px;\n width: 100%;\n padding: 12px;\n color: ${({ theme }) => theme.color.text.base};\n resize: ${({ $resize }) => $resize};\n cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'text')};\n opacity: ${({ disabled }) => (disabled ? '0.5' : '1')};\n border-color: ${({ $error, theme }) =>\n $error ? theme.color.feedback.negative[200] : theme.color.border.subtle};\n outline: none;\n\n &:hover,\n &:focus,\n &:focus-visible {\n border-color: ${({ $error, theme }) =>\n $error ? theme.color.feedback.negative[200] : theme.color.border.base};\n }\n`\n"]}
1
+ {"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../../src/Textarea/Textarea.tsx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AC;;;;oBAI3D,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CACpC,MAAM;IACJ,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;IACpC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ;;;IAGjC,cAAc;IACd,kBAAkB;;;aAGT,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;;CAElD,CAAA","sourcesContent":["import { FocusEvent, FormEvent, ForwardedRef, forwardRef } from 'react'\nimport styled from 'styled-components'\n\nimport { Field } from '../fields/Field'\nimport { CommonFieldProps } from '../fields/commonFieldTypes'\nimport { useUniqueId } from '../utils/id'\nimport { getFieldAria } from '../fields/fieldAria'\nimport {\n fieldDisabledStyle,\n fieldFocusAttrs,\n fieldFocusRing,\n fieldHoverBorderColor,\n} from '../fields/components/fieldStyles'\nimport { MarginProps } from '../utils/space'\n\ntype BaseProps = {\n id?: string\n placeholder?: string\n name?: string\n value: string\n error?: boolean\n errorMsg?: string\n resize?: 'none' | 'both'\n disabled?: boolean\n maxLength?: number\n onBlur?: (e: FocusEvent<HTMLTextAreaElement>) => void\n rows?: number\n fallbackStyle?: boolean\n} & CommonFieldProps &\n MarginProps\n\ntype TruncateProps =\n | {\n onChange: (e: string) => void\n onInputChange?: (e: FormEvent<HTMLTextAreaElement>) => void\n }\n | {\n onChange?: (e: string) => void\n onInputChange: (e: FormEvent<HTMLTextAreaElement>) => void\n }\n\nexport type TextareaProps = BaseProps & TruncateProps\n\nexport const Textarea = forwardRef(function Textarea(\n {\n id: idProp,\n name,\n value,\n onChange,\n onInputChange,\n resize = 'none',\n error = false,\n placeholder,\n disabled = false,\n maxLength,\n onBlur,\n rows = 4,\n fallbackStyle,\n ...fieldProps\n }: TextareaProps,\n ref: ForwardedRef<HTMLTextAreaElement>,\n) {\n const id = useUniqueId(idProp)\n const { assistiveTextId, errorMsgId, controlAria } = getFieldAria(id, {\n ...fieldProps,\n error,\n })\n return (\n <Field\n {...fieldProps}\n htmlFor={id}\n error={error}\n assistiveTextId={assistiveTextId}\n errorMsgId={errorMsgId}\n >\n <StyledTextArea\n ref={ref}\n $error={error}\n id={id}\n name={name}\n disabled={disabled}\n $resize={resize}\n $fallbackStyle={fallbackStyle}\n placeholder={placeholder}\n value={value}\n onChange={(e: FormEvent<HTMLTextAreaElement>) => {\n onChange?.(e.currentTarget.value)\n onInputChange?.(e)\n }}\n maxLength={maxLength}\n onBlur={onBlur}\n rows={rows}\n {...controlAria}\n />\n </Field>\n )\n})\n\ninterface TextArea {\n $resize: 'none' | 'both'\n disabled: boolean\n $error: boolean\n $fallbackStyle?: boolean\n}\n\nconst StyledTextArea = styled.textarea.attrs(fieldFocusAttrs)<TextArea>`\n font-size: 16px;\n font: inherit;\n line-height: 20px;\n background: ${({ $fallbackStyle, theme }) =>\n $fallbackStyle\n ? theme.color.surface.base[300]\n : theme.color.background['000']};\n border: 2px solid ${({ theme }) => theme.color.border.subtle};\n box-sizing: border-box;\n border-radius: 12px;\n width: 100%;\n padding: 12px;\n color: ${({ theme }) => theme.color.text.base};\n resize: ${({ $resize }) => $resize};\n cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'text')};\n border-color: ${({ $error, theme }) =>\n $error ? theme.color.feedback.negative[200] : theme.color.border.subtle};\n outline: none;\n\n &:hover:not(:disabled):not(:focus) {\n border-color: ${({ $error, theme }) => fieldHoverBorderColor(theme, $error)};\n }\n\n &:focus {\n border-color: ${({ $error, theme }) =>\n $error\n ? theme.color.feedback.negative[200]\n : theme.color.border.contrast};\n }\n\n ${fieldFocusRing}\n ${fieldDisabledStyle}\n\n &::placeholder {\n color: ${({ theme }) => theme.color.text.subtle};\n }\n`\n"]}
@@ -1,4 +1,3 @@
1
- import { Icons } from '../../Icon';
2
1
  interface IInput {
3
2
  $error?: boolean;
4
3
  disabled?: boolean;
@@ -6,7 +5,7 @@ interface IInput {
6
5
  step?: number;
7
6
  value?: string;
8
7
  $frontIcon?: boolean;
9
- $trailingIcon?: Icons;
8
+ $trailingIcon?: boolean;
10
9
  $fallbackStyle?: boolean;
11
10
  }
12
11
  interface SIcon {
@@ -32,14 +31,14 @@ export declare const InputLeadingIconContainer: import("styled-components/dist/t
32
31
  }, SIcon>> & string;
33
32
  export declare const StyledFrontIcon: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Merged<{
34
33
  className?: string;
35
- render: Icons;
34
+ render: import("../..").Icons;
36
35
  size?: number;
37
36
  color?: import("../..").ColorTypes;
38
37
  rotate?: number;
39
38
  } & import("../..").MarginProps, SIcon>> & string & Omit<import("react").FC<import("../../Icon/Icon").IconProps>, keyof import("react").Component<any, {}, any>>;
40
39
  export declare const StyledTrailingIcon: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Merged<{
41
40
  className?: string;
42
- render: Icons;
41
+ render: import("../..").Icons;
43
42
  size?: number;
44
43
  color?: import("../..").ColorTypes;
45
44
  rotate?: number;
@@ -1,7 +1,7 @@
1
1
  import styled from 'styled-components';
2
2
  import { Icon } from '../../Icon';
3
3
  import { IconContainer } from '../../sharedStyles/shared.styles';
4
- import { fieldDisabledStyle, fieldFocusAttrs, fieldFocusRing, fieldHoverBorderColor, } from './fieldStyles';
4
+ import { fieldDisabledStyle, fieldFocusAttrs, fieldFocusRing, fieldHoverBorderColor, fieldIconDisabledStyle, } from './fieldStyles';
5
5
  export const Input = styled.input.attrs(fieldFocusAttrs) `
6
6
  box-sizing: border-box;
7
7
  width: 100%;
@@ -75,29 +75,27 @@ export const InputLeadingIconContainer = styled(IconContainer) `
75
75
  left: 36px;
76
76
  margin-left: ${({ $size }) => -$size}px;
77
77
  z-index: 1;
78
- opacity: ${({ $disabled }) => ($disabled ? '0.5' : '1')};
79
- color: ${({ theme }) => theme.color.text.base};
78
+ color: ${({ $disabled, theme }) => $disabled ? theme.color.icon.subtle : theme.color.text.base};
79
+ ${fieldIconDisabledStyle}
80
80
  `;
81
81
  export const StyledFrontIcon = styled(Icon) `
82
82
  position: relative;
83
83
  left: 36px;
84
84
  margin-left: -24px;
85
85
  z-index: 1;
86
- opacity: ${({ $disabled }) => ($disabled ? '0.5' : '1')};
87
- color: ${({ theme }) => theme.color.text.base};
86
+ ${fieldIconDisabledStyle}
88
87
  `;
89
88
  export const StyledTrailingIcon = styled(Icon) `
90
89
  position: relative;
91
90
  right: 36px;
92
91
  margin-right: -36px;
93
- opacity: ${({ $disabled }) => ($disabled ? '0.5' : '1')};
94
- color: ${({ theme }) => theme.color.text.base};
92
+ ${fieldIconDisabledStyle}
95
93
  `;
96
94
  export const InputTrailingIconContainer = styled(IconContainer) `
97
95
  position: relative;
98
96
  right: 36px;
99
97
  margin-right: -36px;
100
- opacity: ${({ $disabled }) => ($disabled ? '0.5' : '1')};
101
- color: ${({ theme }) => theme.color.text.base};
98
+ color: ${({ $disabled, theme }) => $disabled ? theme.color.icon.subtle : theme.color.text.base};
99
+ ${fieldIconDisabledStyle}
102
100
  `;
103
101
  //# sourceMappingURL=CommonInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CommonInput.js","sourceRoot":"","sources":["../../../src/fields/components/CommonInput.tsx"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAA;AACtC,OAAO,EAAE,IAAI,EAAS,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAChE,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,qBAAqB,GACtB,MAAM,eAAe,CAAA;AAiBtB,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,eAAe,CAAC,CAAQ;;;;;;;MAO1D,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CACtB,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,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AC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK;;aAEzB,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;WAC9C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;CAC9C,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAO;;;;;aAKrC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;WAC9C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;CAC9C,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAO;;;;aAIxC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;WAC9C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;CAC9C,CAAA;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC,aAAa,CAAC,CAAO;;;;aAIzD,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;WAC9C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;CAC9C,CAAA","sourcesContent":["import styled from 'styled-components'\nimport { Icon, Icons } from '../../Icon'\nimport { IconContainer } from '../../sharedStyles/shared.styles'\nimport {\n fieldDisabledStyle,\n fieldFocusAttrs,\n fieldFocusRing,\n fieldHoverBorderColor,\n} from './fieldStyles'\n\ninterface IInput {\n $error?: boolean\n disabled?: boolean\n selected?: boolean\n step?: number\n value?: string\n $frontIcon?: boolean\n $trailingIcon?: Icons\n $fallbackStyle?: boolean\n}\n\ninterface SIcon {\n $disabled?: boolean\n}\n\nexport const Input = styled.input.attrs(fieldFocusAttrs)<IInput>`\n box-sizing: border-box;\n width: 100%;\n height: 48px;\n margin: 0;\n padding: 12px;\n border: 2px solid\n ${({ $error, theme }) =>\n $error ? theme.color.feedback.negative[200] : theme.color.border.subtle};\n border-radius: 12px;\n background-color: ${({ $fallbackStyle, theme }) =>\n $fallbackStyle\n ? theme.color.surface.base[300]\n : theme.color.background['000']};\n color: ${({ $error, theme }) =>\n $error ? theme.color.feedback.negative[200] : theme.color.text.base};\n font-family: inherit;\n font-size: 16px;\n line-height: 20px;\n outline: none;\n\n &:hover:not(:disabled):not(:focus) {\n border-color: ${({ $error, theme }) => fieldHoverBorderColor(theme, $error)};\n }\n\n &:focus {\n border-color: ${({ $error, theme }) =>\n $error\n ? theme.color.feedback.negative[200]\n : theme.color.border.contrast};\n }\n\n ${fieldFocusRing}\n ${fieldDisabledStyle}\n\n ${({ $frontIcon }) =>\n $frontIcon &&\n `\n padding-left: 42px;\n `}\n\n ${({ $trailingIcon }) =>\n $trailingIcon &&\n `\n padding-right: 42px;\n `}\n\n /* Remove the spinner on Firefox and Webkit browsers */\n -moz-appearance: textfield;\n\n &::-webkit-outer-spin-button,\n &::-webkit-inner-spin-button {\n -webkit-appearance: none;\n margin: 0;\n }\n\n &::placeholder {\n color: ${({ theme }) => theme.color.text.subtle};\n }\n\n &:-webkit-autofill {\n animation-name: onAutoFillStart;\n animation-duration: 2s;\n }\n\n @keyframes onAutoFillStart {\n from {\n background-color: inherit;\n }\n to {\n background-color: inherit;\n }\n }\n`\n\nexport const InputLeadingIconContainer = styled(IconContainer)<SIcon>`\n position: relative;\n left: 36px;\n margin-left: ${({ $size }) => -$size}px;\n z-index: 1;\n opacity: ${({ $disabled }) => ($disabled ? '0.5' : '1')};\n color: ${({ theme }) => theme.color.text.base};\n`\n\nexport const StyledFrontIcon = styled(Icon)<SIcon>`\n position: relative;\n left: 36px;\n margin-left: -24px;\n z-index: 1;\n opacity: ${({ $disabled }) => ($disabled ? '0.5' : '1')};\n color: ${({ theme }) => theme.color.text.base};\n`\n\nexport const StyledTrailingIcon = styled(Icon)<SIcon>`\n position: relative;\n right: 36px;\n margin-right: -36px;\n opacity: ${({ $disabled }) => ($disabled ? '0.5' : '1')};\n color: ${({ theme }) => theme.color.text.base};\n`\n\nexport const InputTrailingIconContainer = styled(IconContainer)<SIcon>`\n position: relative;\n right: 36px;\n margin-right: -36px;\n opacity: ${({ $disabled }) => ($disabled ? '0.5' : '1')};\n color: ${({ theme }) => theme.color.text.base};\n`\n"]}
1
+ {"version":3,"file":"CommonInput.js","sourceRoot":"","sources":["../../../src/fields/components/CommonInput.tsx"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAChE,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,eAAe,CAAA;AAiBtB,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,eAAe,CAAC,CAAQ;;;;;;;MAO1D,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CACtB,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM;;sBAEvD,CAAC,EAAE,cAAc,EAAE,KAAK,EAAE,EA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AK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;IAC3D,sBAAsB;CACzB,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAO;;;;;IAK9C,sBAAsB;CACzB,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAO;;;;IAIjD,sBAAsB;CACzB,CAAA;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC,aAAa,CAAC,CAAO;;;;WAI3D,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,CAChC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI;IAC3D,sBAAsB;CACzB,CAAA","sourcesContent":["import styled from 'styled-components'\nimport { Icon } from '../../Icon'\nimport { IconContainer } from '../../sharedStyles/shared.styles'\nimport {\n fieldDisabledStyle,\n fieldFocusAttrs,\n fieldFocusRing,\n fieldHoverBorderColor,\n fieldIconDisabledStyle,\n} from './fieldStyles'\n\ninterface IInput {\n $error?: boolean\n disabled?: boolean\n selected?: boolean\n step?: number\n value?: string\n $frontIcon?: boolean\n $trailingIcon?: boolean\n $fallbackStyle?: boolean\n}\n\ninterface SIcon {\n $disabled?: boolean\n}\n\nexport const Input = styled.input.attrs(fieldFocusAttrs)<IInput>`\n box-sizing: border-box;\n width: 100%;\n height: 48px;\n margin: 0;\n padding: 12px;\n border: 2px solid\n ${({ $error, theme }) =>\n $error ? theme.color.feedback.negative[200] : theme.color.border.subtle};\n border-radius: 12px;\n background-color: ${({ $fallbackStyle, theme }) =>\n $fallbackStyle\n ? theme.color.surface.base[300]\n : theme.color.background['000']};\n color: ${({ $error, theme }) =>\n $error ? theme.color.feedback.negative[200] : theme.color.text.base};\n font-family: inherit;\n font-size: 16px;\n line-height: 20px;\n outline: none;\n\n &:hover:not(:disabled):not(:focus) {\n border-color: ${({ $error, theme }) => fieldHoverBorderColor(theme, $error)};\n }\n\n &:focus {\n border-color: ${({ $error, theme }) =>\n $error\n ? theme.color.feedback.negative[200]\n : theme.color.border.contrast};\n }\n\n ${fieldFocusRing}\n ${fieldDisabledStyle}\n\n ${({ $frontIcon }) =>\n $frontIcon &&\n `\n padding-left: 42px;\n `}\n\n ${({ $trailingIcon }) =>\n $trailingIcon &&\n `\n padding-right: 42px;\n `}\n\n /* Remove the spinner on Firefox and Webkit browsers */\n -moz-appearance: textfield;\n\n &::-webkit-outer-spin-button,\n &::-webkit-inner-spin-button {\n -webkit-appearance: none;\n margin: 0;\n }\n\n &::placeholder {\n color: ${({ theme }) => theme.color.text.subtle};\n }\n\n &:-webkit-autofill {\n animation-name: onAutoFillStart;\n animation-duration: 2s;\n }\n\n @keyframes onAutoFillStart {\n from {\n background-color: inherit;\n }\n to {\n background-color: inherit;\n }\n }\n`\n\nexport const InputLeadingIconContainer = styled(IconContainer)<SIcon>`\n position: relative;\n left: 36px;\n margin-left: ${({ $size }) => -$size}px;\n z-index: 1;\n color: ${({ $disabled, theme }) =>\n $disabled ? theme.color.icon.subtle : theme.color.text.base};\n ${fieldIconDisabledStyle}\n`\n\nexport const StyledFrontIcon = styled(Icon)<SIcon>`\n position: relative;\n left: 36px;\n margin-left: -24px;\n z-index: 1;\n ${fieldIconDisabledStyle}\n`\n\nexport const StyledTrailingIcon = styled(Icon)<SIcon>`\n position: relative;\n right: 36px;\n margin-right: -36px;\n ${fieldIconDisabledStyle}\n`\n\nexport const InputTrailingIconContainer = styled(IconContainer)<SIcon>`\n position: relative;\n right: 36px;\n margin-right: -36px;\n color: ${({ $disabled, theme }) =>\n $disabled ? theme.color.icon.subtle : theme.color.text.base};\n ${fieldIconDisabledStyle}\n`\n"]}
@@ -16,4 +16,8 @@ export declare const fieldFocusAttrs: <T extends HTMLElement>({ onPointerDown, o
16
16
  };
17
17
  export declare const fieldFocusRing: import("styled-components").RuleSet<object>;
18
18
  export declare const fieldDisabledStyle: import("styled-components").RuleSet<object>;
19
+ /** Disabled icons sit over the input, so they show its disabled cursor themselves. */
20
+ export declare const fieldIconDisabledStyle: import("styled-components").RuleSet<NoInfer<{
21
+ $disabled?: boolean;
22
+ }>>;
19
23
  export declare const fieldHoverBorderColor: (theme: DefaultTheme, error?: boolean) => string;
@@ -36,5 +36,9 @@ export const fieldDisabledStyle = css `
36
36
  -webkit-text-fill-color: currentColor;
37
37
  }
38
38
  `;
39
+ /** Disabled icons sit over the input, so they show its disabled cursor themselves. */
40
+ export const fieldIconDisabledStyle = css `
41
+ ${({ $disabled }) => $disabled && 'cursor: not-allowed;'}
42
+ `;
39
43
  export const fieldHoverBorderColor = (theme, error) => error ? theme.color.feedback.negative[300] : theme.color.border.base;
40
44
  //# sourceMappingURL=fieldStyles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fieldStyles.js","sourceRoot":"","sources":["../../../src/fields/components/fieldStyles.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAgB,MAAM,mBAAmB,CAAA;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAA2B,EAAE,EAAE;IAC9D,IAAI,OAAO;QAAE,OAAO,CAAC,OAAO,CAAC,YAAY,GAAG,EAAE,CAAA;AAChD,CAAC,CAAA;AAED,2EAA2E;AAC3E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAwB,EACrD,aAAa,EACb,aAAa,GAId,EAAE,EAAE,CAAC,CAAC;IACL,aAAa,EAAE,CAAC,KAAsB,EAAE,EAAE;QACxC,gBAAgB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;QACrC,aAAa,EAAE,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;IACD,aAAa,EAAE,CAAC,KAAoB,EAAE,EAAE;QACtC,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,YAAY,CAAA;QAC/C,aAAa,EAAE,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAA;;yBAER,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO;;;CAGhE,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;;oBAEjB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;wBAC7C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;aAC3D,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;;;;;;CAMlD,CAAA;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAmB,EAAE,KAAe,EAAE,EAAE,CAC5E,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAA","sourcesContent":["import {\n FocusEvent,\n FocusEventHandler,\n PointerEvent,\n PointerEventHandler,\n} from 'react'\nimport { css, DefaultTheme } from 'styled-components'\n\n/**\n * Browsers treat text fields as `:focus-visible` even when they are clicked,\n * so fields flag focus that comes from a pointer and only show the focus ring\n * for keyboard focus.\n */\nexport const markPointerFocus = (element: HTMLElement | null) => {\n if (element) element.dataset.pointerFocus = ''\n}\n\n/** Pass to styled-components `.attrs`. Callers' own handlers still run. */\nexport const fieldFocusAttrs = <T extends HTMLElement>({\n onPointerDown,\n onBlurCapture,\n}: {\n onPointerDown?: PointerEventHandler<T>\n onBlurCapture?: FocusEventHandler<T>\n}) => ({\n onPointerDown: (event: PointerEvent<T>) => {\n markPointerFocus(event.currentTarget)\n onPointerDown?.(event)\n },\n onBlurCapture: (event: FocusEvent<T>) => {\n delete event.currentTarget.dataset.pointerFocus\n onBlurCapture?.(event)\n },\n})\n\nexport const fieldFocusRing = css`\n &:focus-visible:not([data-pointer-focus]) {\n outline: 2px solid ${({ theme }) => theme.color.focus.onLight};\n outline-offset: 2px;\n }\n`\n\nexport const fieldDisabledStyle = css`\n &:disabled {\n border-color: ${({ theme }) => theme.color.feedback.inactive[100]};\n background-color: ${({ theme }) => theme.color.feedback.inactive[50]};\n color: ${({ theme }) => theme.color.text.subtle};\n cursor: not-allowed;\n /* Safari fades disabled fields on top of these colours */\n opacity: 1;\n -webkit-text-fill-color: currentColor;\n }\n`\n\nexport const fieldHoverBorderColor = (theme: DefaultTheme, error?: boolean) =>\n error ? theme.color.feedback.negative[300] : theme.color.border.base\n"]}
1
+ {"version":3,"file":"fieldStyles.js","sourceRoot":"","sources":["../../../src/fields/components/fieldStyles.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAgB,MAAM,mBAAmB,CAAA;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAA2B,EAAE,EAAE;IAC9D,IAAI,OAAO;QAAE,OAAO,CAAC,OAAO,CAAC,YAAY,GAAG,EAAE,CAAA;AAChD,CAAC,CAAA;AAED,2EAA2E;AAC3E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAwB,EACrD,aAAa,EACb,aAAa,GAId,EAAE,EAAE,CAAC,CAAC;IACL,aAAa,EAAE,CAAC,KAAsB,EAAE,EAAE;QACxC,gBAAgB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;QACrC,aAAa,EAAE,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;IACD,aAAa,EAAE,CAAC,KAAoB,EAAE,EAAE;QACtC,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,YAAY,CAAA;QAC/C,aAAa,EAAE,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAA;;yBAER,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO;;;CAGhE,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;;oBAEjB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;wBAC7C,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;aAC3D,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;;;;;;CAMlD,CAAA;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAyB;IAC9D,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,IAAI,sBAAsB;CACzD,CAAA;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAmB,EAAE,KAAe,EAAE,EAAE,CAC5E,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAA","sourcesContent":["import {\n FocusEvent,\n FocusEventHandler,\n PointerEvent,\n PointerEventHandler,\n} from 'react'\nimport { css, DefaultTheme } from 'styled-components'\n\n/**\n * Browsers treat text fields as `:focus-visible` even when they are clicked,\n * so fields flag focus that comes from a pointer and only show the focus ring\n * for keyboard focus.\n */\nexport const markPointerFocus = (element: HTMLElement | null) => {\n if (element) element.dataset.pointerFocus = ''\n}\n\n/** Pass to styled-components `.attrs`. Callers' own handlers still run. */\nexport const fieldFocusAttrs = <T extends HTMLElement>({\n onPointerDown,\n onBlurCapture,\n}: {\n onPointerDown?: PointerEventHandler<T>\n onBlurCapture?: FocusEventHandler<T>\n}) => ({\n onPointerDown: (event: PointerEvent<T>) => {\n markPointerFocus(event.currentTarget)\n onPointerDown?.(event)\n },\n onBlurCapture: (event: FocusEvent<T>) => {\n delete event.currentTarget.dataset.pointerFocus\n onBlurCapture?.(event)\n },\n})\n\nexport const fieldFocusRing = css`\n &:focus-visible:not([data-pointer-focus]) {\n outline: 2px solid ${({ theme }) => theme.color.focus.onLight};\n outline-offset: 2px;\n }\n`\n\nexport const fieldDisabledStyle = css`\n &:disabled {\n border-color: ${({ theme }) => theme.color.feedback.inactive[100]};\n background-color: ${({ theme }) => theme.color.feedback.inactive[50]};\n color: ${({ theme }) => theme.color.text.subtle};\n cursor: not-allowed;\n /* Safari fades disabled fields on top of these colours */\n opacity: 1;\n -webkit-text-fill-color: currentColor;\n }\n`\n\n/** Disabled icons sit over the input, so they show its disabled cursor themselves. */\nexport const fieldIconDisabledStyle = css<{ $disabled?: boolean }>`\n ${({ $disabled }) => $disabled && 'cursor: not-allowed;'}\n`\n\nexport const fieldHoverBorderColor = (theme: DefaultTheme, error?: boolean) =>\n error ? theme.color.feedback.negative[300] : theme.color.border.base\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrshmllw/smores-react",
3
- "version": "16.10.7",
3
+ "version": "16.11.1",
4
4
  "description": "Collection of React components used by Marshmallow Technology",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",