@mrshmllw/smores-react 16.10.7 → 16.11.0

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: 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,GAAG,UAAU,EACM,EACrB,G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AA;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,EAAE,KAAK,EAAE,MA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,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={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"]}
@@ -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 { 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;
@@ -34,10 +35,16 @@ const StyledTextArea = styled.textarea `
34
35
  border-color: ${({ $error, theme }) => $error ? theme.color.feedback.negative[200] : theme.color.border.subtle};
35
36
  outline: none;
36
37
 
37
- &:hover,
38
- &:focus,
39
- &:focus-visible {
40
- border-color: ${({ $error, theme }) => $error ? theme.color.feedback.negative[200] : theme.color.border.base};
38
+ &:hover:not(:disabled):not(:focus) {
39
+ border-color: ${({ $error, theme }) => fieldHoverBorderColor(theme, $error)};
41
40
  }
41
+
42
+ &:focus {
43
+ border-color: ${({ $error, theme }) => $error
44
+ ? theme.color.feedback.negative[200]
45
+ : theme.color.border.contrast};
46
+ }
47
+
48
+ ${fieldFocusRing}
42
49
  `;
43
50
  //# 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,EA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,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,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
+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AC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM;;;;oBAIvD,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC;;;;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;CACjB,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 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 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: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`\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.0",
4
4
  "description": "Collection of React components used by Marshmallow Technology",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",