@doist/reactist 27.2.2 → 27.3.5

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.
@@ -8,7 +8,9 @@ import { Stack } from '../stack/stack.js';
8
8
  import { Spinner } from '../spinner/spinner.js';
9
9
  import { Columns, Column } from '../columns/columns.js';
10
10
 
11
- const MAX_LENGTH_THRESHOLD = 10;
11
+ // See: https://twist.com/a/1585/ch/765851/t/6664583/c/93631846 for latest spec
12
+
13
+ const MAX_LENGTH_THRESHOLD = 0;
12
14
 
13
15
  function fieldToneToTextTone(tone) {
14
16
  return tone === 'error' ? 'danger' : tone === 'success' ? 'positive' : 'secondary';
@@ -62,6 +64,10 @@ function validateInputLength({
62
64
  tone: isNearMaxLength ? 'error' : 'neutral'
63
65
  };
64
66
  }
67
+ /**
68
+ * BaseField is a base component that provides a consistent structure for form fields.
69
+ */
70
+
65
71
 
66
72
  function BaseField({
67
73
  variant = 'default',
@@ -76,7 +82,8 @@ function BaseField({
76
82
  maxLength,
77
83
  hidden,
78
84
  'aria-describedby': originalAriaDescribedBy,
79
- id: originalId
85
+ id: originalId,
86
+ characterCountPosition = 'below'
80
87
  }) {
81
88
  const id = useId(originalId);
82
89
  const messageId = useId();
@@ -87,6 +94,16 @@ function BaseField({
87
94
  const [characterCount, setCharacterCount] = React.useState(inputLength.count);
88
95
  const [characterCountTone, setCharacterCountTone] = React.useState(inputLength.tone);
89
96
  const ariaDescribedBy = originalAriaDescribedBy != null ? originalAriaDescribedBy : message ? messageId : null;
97
+ /**
98
+ * Renders the character count element.
99
+ * If the characterCountPosition value is 'hidden', it returns null.
100
+ */
101
+
102
+ function renderCharacterCount() {
103
+ return characterCountPosition !== 'hidden' ? /*#__PURE__*/React.createElement(FieldCharacterCount, {
104
+ tone: characterCountTone
105
+ }, characterCount) : null;
106
+ }
90
107
 
91
108
  const childrenProps = _objectSpread2(_objectSpread2({
92
109
  id,
@@ -107,8 +124,10 @@ function BaseField({
107
124
  });
108
125
  setCharacterCount(inputLength.count);
109
126
  setCharacterCountTone(inputLength.tone);
110
- }
127
+ },
111
128
 
129
+ // If the character count is inline, we pass it as a prop to the children element so it can be rendered inline
130
+ characterCountElement: characterCountPosition === 'inline' ? renderCharacterCount() : null
112
131
  });
113
132
 
114
133
  React.useEffect(function updateCharacterCountOnPropChange() {
@@ -152,11 +171,9 @@ function BaseField({
152
171
  }, /*#__PURE__*/React.createElement(FieldMessage, {
153
172
  id: messageId,
154
173
  tone: tone
155
- }, message)) : null, characterCount ? /*#__PURE__*/React.createElement(Column, {
174
+ }, message)) : null, characterCountPosition === 'below' ? /*#__PURE__*/React.createElement(Column, {
156
175
  width: "content"
157
- }, /*#__PURE__*/React.createElement(FieldCharacterCount, {
158
- tone: characterCountTone
159
- }, characterCount)) : null) : null);
176
+ }, renderCharacterCount()) : null) : null);
160
177
  }
161
178
 
162
179
  export { BaseField, FieldMessage };
@@ -1 +1 @@
1
- {"version":3,"file":"base-field.js","sources":["../../src/base-field/base-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Box, BoxProps } from '../box'\nimport { useId } from '../utils/common-helpers'\nimport { Text } from '../text'\nimport styles from './base-field.module.css'\nimport { Stack } from '../stack'\n\nimport type { WithEnhancedClassName } from '../utils/common-types'\nimport { Spinner } from '../spinner'\nimport { Column, Columns } from '../columns'\n\nconst MAX_LENGTH_THRESHOLD = 10\n\ntype FieldTone = 'neutral' | 'success' | 'error' | 'loading'\n\ntype FieldMessageProps = {\n id: string\n children: React.ReactNode\n tone: FieldTone\n}\n\nfunction fieldToneToTextTone(tone: FieldTone) {\n return tone === 'error' ? 'danger' : tone === 'success' ? 'positive' : 'secondary'\n}\n\nfunction FieldMessage({ id, children, tone }: FieldMessageProps) {\n return (\n <Text as=\"p\" tone={fieldToneToTextTone(tone)} size=\"copy\" id={id}>\n {tone === 'loading' ? (\n <Box\n as=\"span\"\n marginRight=\"xsmall\"\n display=\"inlineFlex\"\n className={styles.loadingIcon}\n >\n <Spinner size={16} />\n </Box>\n ) : null}\n {children}\n </Text>\n )\n}\n\ntype FieldCharacterCountProps = {\n children: React.ReactNode\n tone: FieldTone\n}\n\nfunction FieldCharacterCount({ children, tone }: FieldCharacterCountProps) {\n return (\n <Text tone={fieldToneToTextTone(tone)} size=\"copy\">\n {children}\n </Text>\n )\n}\n\ntype ValidateInputLengthProps = {\n value?: React.InputHTMLAttributes<unknown>['value']\n maxLength?: number\n}\n\ntype ValidateInputLengthResult = {\n count: string | null\n tone: FieldTone\n}\n\nfunction validateInputLength({\n value,\n maxLength,\n}: ValidateInputLengthProps): ValidateInputLengthResult {\n if (!maxLength) {\n return {\n count: null,\n tone: 'neutral',\n }\n }\n\n const currentLength = String(value || '').length\n const isNearMaxLength = maxLength - currentLength <= MAX_LENGTH_THRESHOLD\n\n return {\n count: `${currentLength}/${maxLength}`,\n tone: isNearMaxLength ? 'error' : 'neutral',\n }\n}\n\n//\n// BaseField\n//\n\ntype ChildrenRenderProps = {\n id: string\n value?: React.InputHTMLAttributes<unknown>['value']\n 'aria-describedby'?: string\n 'aria-invalid'?: true\n onChange?: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>\n}\n\ntype HtmlInputProps<T extends HTMLElement> = React.DetailedHTMLProps<\n React.InputHTMLAttributes<T>,\n T\n>\n\ntype BaseFieldVariant = 'default' | 'bordered'\ntype BaseFieldVariantProps = {\n /**\n * Provides alternative visual layouts or modes that the field can be rendered in.\n *\n * Namely, there are two variants supported:\n *\n * - the default one\n * - a \"bordered\" variant, where the border of the field surrounds also the labels, instead\n * of just surrounding the actual field element\n *\n * In both cases, the message and description texts for the field lie outside the bordered\n * area.\n */\n variant?: BaseFieldVariant\n}\n\ntype BaseFieldProps = WithEnhancedClassName &\n Pick<HtmlInputProps<HTMLInputElement>, 'id' | 'hidden' | 'maxLength' | 'aria-describedby'> & {\n /**\n * The main label for this field element.\n *\n * This prop is not optional. Consumers of field components must be explicit about not\n * wanting a label by passing `label=\"\"` or `label={null}`. In those situations, consumers\n * should make sure that fields are properly labelled semantically by other means (e.g using\n * `aria-labelledby`, or rendering a `<label />` element referencing the field by id).\n *\n * Avoid providing interactive elements in the label. Prefer `auxiliaryLabel` for that.\n *\n * @see BaseFieldProps['auxiliaryLabel']\n */\n label: React.ReactNode\n\n /**\n * The initial value for this field element.\n *\n * This prop is used to calculate the character count for the initial value, and is then\n * passed to the underlying child element.\n */\n value?: React.InputHTMLAttributes<unknown>['value']\n\n /**\n * An optional extra element to be placed to the right of the main label.\n *\n * This extra element is not included in the accessible name of the field element. Its only\n * purpose is either visual, or functional (if you include interactive elements in it).\n *\n * @see BaseFieldProps['label']\n *\n * @deprecated The usage of this element is discouraged given that it was removed from the\n * latest form field spec revision.\n */\n auxiliaryLabel?: React.ReactNode\n\n /**\n * A message associated with the field. It is rendered below the field, and with an\n * appearance that conveys the tone of the field (e.g. coloured red for errors, green for\n * success, etc).\n *\n * The message element is associated to the field via the `aria-describedby` attribute.\n *\n * In the future, when `aria-errormessage` gets better user agent support, we should use it\n * to associate the filed with a message when tone is `\"error\"`.\n *\n * @see BaseFieldProps['tone']\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-errormessage\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-invalid\n */\n message?: React.ReactNode\n\n /**\n * The tone with which the message, if any, is presented.\n *\n * If the tone is `\"error\"`, the field border turns red, and the message, if any, is also\n * red.\n *\n * When the tone is `\"loading\"`, it is recommended that you also disable the field. However,\n * this is not enforced by the component. It is only a recommendation.\n *\n * @see BaseFieldProps['message']\n * @see BaseFieldProps['hint']\n */\n tone?: FieldTone\n\n /**\n * The maximum width that the input field can expand to.\n */\n maxWidth?: BoxProps['maxWidth']\n\n /**\n * The maximum number of characters that the input field can accept.\n * When this limit is reached, the input field will not accept any more characters.\n * The counter element will turn red when the number of characters is within 10 of the maximum limit.\n */\n maxLength?: number\n\n /**\n * Used internally by components composed using `BaseField`. It is not exposed as part of\n * the public props of such components.\n */\n children: (props: ChildrenRenderProps) => React.ReactNode\n }\n\ntype FieldComponentProps<T extends HTMLElement> = Omit<\n BaseFieldProps,\n 'children' | 'className' | 'fieldRef' | 'variant'\n> &\n Omit<HtmlInputProps<T>, 'className' | 'style'>\n\nfunction BaseField({\n variant = 'default',\n label,\n value,\n auxiliaryLabel,\n message,\n tone = 'neutral',\n className,\n children,\n maxWidth,\n maxLength,\n hidden,\n 'aria-describedby': originalAriaDescribedBy,\n id: originalId,\n}: BaseFieldProps & BaseFieldVariantProps & WithEnhancedClassName) {\n const id = useId(originalId)\n const messageId = useId()\n\n const inputLength = validateInputLength({ value, maxLength })\n\n const [characterCount, setCharacterCount] = React.useState<string | null>(inputLength.count)\n const [characterCountTone, setCharacterCountTone] = React.useState<FieldTone>(inputLength.tone)\n\n const ariaDescribedBy = originalAriaDescribedBy ?? (message ? messageId : null)\n\n const childrenProps: ChildrenRenderProps = {\n id,\n value,\n ...(ariaDescribedBy ? { 'aria-describedby': ariaDescribedBy } : {}),\n 'aria-invalid': tone === 'error' ? true : undefined,\n onChange(event) {\n if (!maxLength) {\n return\n }\n\n const inputLength = validateInputLength({\n value: event.currentTarget.value,\n maxLength,\n })\n\n setCharacterCount(inputLength.count)\n setCharacterCountTone(inputLength.tone)\n },\n }\n\n React.useEffect(\n function updateCharacterCountOnPropChange() {\n if (!maxLength) {\n return\n }\n\n const inputLength = validateInputLength({\n value,\n maxLength,\n })\n\n setCharacterCount(inputLength.count)\n setCharacterCountTone(inputLength.tone)\n },\n [maxLength, value],\n )\n\n return (\n <Stack space=\"xsmall\" hidden={hidden}>\n <Box\n className={[\n className,\n styles.container,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n ]}\n maxWidth={maxWidth}\n >\n {label || auxiliaryLabel ? (\n <Box\n as=\"span\"\n display=\"flex\"\n justifyContent=\"spaceBetween\"\n alignItems=\"flexEnd\"\n >\n <Text\n size={variant === 'bordered' ? 'caption' : 'body'}\n as=\"label\"\n htmlFor={id}\n >\n {label ? <span className={styles.primaryLabel}>{label}</span> : null}\n </Text>\n {auxiliaryLabel ? (\n <Box className={styles.auxiliaryLabel} paddingLeft=\"small\">\n {auxiliaryLabel}\n </Box>\n ) : null}\n </Box>\n ) : null}\n {children(childrenProps)}\n </Box>\n {message || characterCount ? (\n <Columns align=\"right\" space=\"small\" maxWidth={maxWidth}>\n {message ? (\n <Column width=\"auto\">\n <FieldMessage id={messageId} tone={tone}>\n {message}\n </FieldMessage>\n </Column>\n ) : null}\n {characterCount ? (\n <Column width=\"content\">\n <FieldCharacterCount tone={characterCountTone}>\n {characterCount}\n </FieldCharacterCount>\n </Column>\n ) : null}\n </Columns>\n ) : null}\n </Stack>\n )\n}\n\nexport { BaseField, FieldMessage }\nexport type { BaseFieldVariant, BaseFieldVariantProps, FieldComponentProps }\n"],"names":["MAX_LENGTH_THRESHOLD","fieldToneToTextTone","tone","FieldMessage","id","children","React","Text","as","size","createElement","Box","marginRight","display","className","styles","loadingIcon","Spinner","FieldCharacterCount","validateInputLength","value","maxLength","count","currentLength","String","length","isNearMaxLength","BaseField","variant","label","auxiliaryLabel","message","maxWidth","hidden","originalAriaDescribedBy","originalId","useId","messageId","inputLength","characterCount","setCharacterCount","useState","characterCountTone","setCharacterCountTone","ariaDescribedBy","childrenProps","_objectSpread","undefined","onChange","event","currentTarget","useEffect","updateCharacterCountOnPropChange","Stack","space","container","error","bordered","justifyContent","alignItems","htmlFor","primaryLabel","paddingLeft","Columns","align","Column","width"],"mappings":";;;;;;;;;;AAWA,MAAMA,oBAAoB,GAAG,EAA7B,CAAA;;AAUA,SAASC,mBAAT,CAA6BC,IAA7B,EAA4C;AACxC,EAAA,OAAOA,IAAI,KAAK,OAAT,GAAmB,QAAnB,GAA8BA,IAAI,KAAK,SAAT,GAAqB,UAArB,GAAkC,WAAvE,CAAA;AACH,CAAA;;AAED,SAASC,YAAT,CAAsB;EAAEC,EAAF;EAAMC,QAA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,SAAJ;AAAenC,IAAAA,IAAI,EAAEA,IAAAA;AAArB,GAAd,EACK6B,OADL,CADJ,CADI,GAMJ,IAPR,EAQKQ,cAAc,gBACXjC,mBAAA,CAAC2D,MAAD,EAAO;AAACC,IAAAA,KAAK,EAAC,SAAA;AAAP,GAAP,eACI5D,KAAC,CAAAI,aAAD,CAACQ,mBAAD;AAAqBhB,IAAAA,IAAI,EAAEwC,kBAAAA;GAA3B,EACKH,cADL,CADJ,CADW,GAMX,IAdR,CADH,GAiBG,IAlDR,CADJ,CAAA;AAsDH;;;;"}
1
+ {"version":3,"file":"base-field.js","sources":["../../src/base-field/base-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Box, BoxProps } from '../box'\nimport { useId } from '../utils/common-helpers'\nimport { Text } from '../text'\nimport styles from './base-field.module.css'\nimport { Stack } from '../stack'\n\nimport type { WithEnhancedClassName } from '../utils/common-types'\nimport { Spinner } from '../spinner'\nimport { Column, Columns } from '../columns'\n\n// Define the remaining characters before the character count turns red\n// See: https://twist.com/a/1585/ch/765851/t/6664583/c/93631846 for latest spec\nconst MAX_LENGTH_THRESHOLD = 0\n\ntype FieldTone = 'neutral' | 'success' | 'error' | 'loading'\n\ntype FieldMessageProps = {\n id: string\n children: React.ReactNode\n tone: FieldTone\n}\n\nfunction fieldToneToTextTone(tone: FieldTone) {\n return tone === 'error' ? 'danger' : tone === 'success' ? 'positive' : 'secondary'\n}\n\nfunction FieldMessage({ id, children, tone }: FieldMessageProps) {\n return (\n <Text as=\"p\" tone={fieldToneToTextTone(tone)} size=\"copy\" id={id}>\n {tone === 'loading' ? (\n <Box\n as=\"span\"\n marginRight=\"xsmall\"\n display=\"inlineFlex\"\n className={styles.loadingIcon}\n >\n <Spinner size={16} />\n </Box>\n ) : null}\n {children}\n </Text>\n )\n}\n\ntype FieldCharacterCountProps = {\n children: React.ReactNode\n tone: FieldTone\n}\n\nfunction FieldCharacterCount({ children, tone }: FieldCharacterCountProps) {\n return (\n <Text tone={fieldToneToTextTone(tone)} size=\"copy\">\n {children}\n </Text>\n )\n}\n\ntype ValidateInputLengthProps = {\n value?: React.InputHTMLAttributes<unknown>['value']\n maxLength?: number\n}\n\ntype ValidateInputLengthResult = {\n count: string | null\n tone: FieldTone\n}\n\nfunction validateInputLength({\n value,\n maxLength,\n}: ValidateInputLengthProps): ValidateInputLengthResult {\n if (!maxLength) {\n return {\n count: null,\n tone: 'neutral',\n }\n }\n\n const currentLength = String(value || '').length\n const isNearMaxLength = maxLength - currentLength <= MAX_LENGTH_THRESHOLD\n\n return {\n count: `${currentLength}/${maxLength}`,\n tone: isNearMaxLength ? 'error' : 'neutral',\n }\n}\n\n//\n// BaseField\n//\n\ntype ChildrenRenderProps = {\n id: string\n value?: React.InputHTMLAttributes<unknown>['value']\n 'aria-describedby'?: string\n 'aria-invalid'?: true\n onChange?: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>\n characterCountElement?: React.ReactNode | null\n}\n\ntype HtmlInputProps<T extends HTMLElement> = React.DetailedHTMLProps<\n React.InputHTMLAttributes<T>,\n T\n>\n\ntype BaseFieldVariant = 'default' | 'bordered'\ntype BaseFieldVariantProps = {\n /**\n * Provides alternative visual layouts or modes that the field can be rendered in.\n *\n * Namely, there are two variants supported:\n *\n * - the default one\n * - a \"bordered\" variant, where the border of the field surrounds also the labels, instead\n * of just surrounding the actual field element\n *\n * In both cases, the message and description texts for the field lie outside the bordered\n * area.\n */\n variant?: BaseFieldVariant\n}\n\nexport type BaseFieldProps = WithEnhancedClassName &\n Pick<HtmlInputProps<HTMLInputElement>, 'id' | 'hidden' | 'maxLength' | 'aria-describedby'> & {\n /**\n * The main label for this field element.\n *\n * This prop is not optional. Consumers of field components must be explicit about not\n * wanting a label by passing `label=\"\"` or `label={null}`. In those situations, consumers\n * should make sure that fields are properly labelled semantically by other means (e.g using\n * `aria-labelledby`, or rendering a `<label />` element referencing the field by id).\n *\n * Avoid providing interactive elements in the label. Prefer `auxiliaryLabel` for that.\n *\n * @see BaseFieldProps['auxiliaryLabel']\n */\n label: React.ReactNode\n\n /**\n * The initial value for this field element.\n *\n * This prop is used to calculate the character count for the initial value, and is then\n * passed to the underlying child element.\n */\n value?: React.InputHTMLAttributes<unknown>['value']\n\n /**\n * An optional extra element to be placed to the right of the main label.\n *\n * This extra element is not included in the accessible name of the field element. Its only\n * purpose is either visual, or functional (if you include interactive elements in it).\n *\n * @see BaseFieldProps['label']\n *\n * @deprecated The usage of this element is discouraged given that it was removed from the\n * latest form field spec revision.\n */\n auxiliaryLabel?: React.ReactNode\n\n /**\n * A message associated with the field. It is rendered below the field, and with an\n * appearance that conveys the tone of the field (e.g. coloured red for errors, green for\n * success, etc).\n *\n * The message element is associated to the field via the `aria-describedby` attribute.\n *\n * In the future, when `aria-errormessage` gets better user agent support, we should use it\n * to associate the filed with a message when tone is `\"error\"`.\n *\n * @see BaseFieldProps['tone']\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-errormessage\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-invalid\n */\n message?: React.ReactNode\n\n /**\n * The tone with which the message, if any, is presented.\n *\n * If the tone is `\"error\"`, the field border turns red, and the message, if any, is also\n * red.\n *\n * When the tone is `\"loading\"`, it is recommended that you also disable the field. However,\n * this is not enforced by the component. It is only a recommendation.\n *\n * @see BaseFieldProps['message']\n * @see BaseFieldProps['hint']\n */\n tone?: FieldTone\n\n /**\n * The maximum width that the input field can expand to.\n */\n maxWidth?: BoxProps['maxWidth']\n\n /**\n * The maximum number of characters that the input field can accept.\n * When this limit is reached, the input field will not accept any more characters.\n * The counter element will turn red when the number of characters is within 10 of the maximum limit.\n */\n maxLength?: number\n\n /**\n * Used internally by components composed using `BaseField`. It is not exposed as part of\n * the public props of such components.\n */\n children: (props: ChildrenRenderProps) => React.ReactNode\n\n /**\n * The position of the character count element.\n * It can be shown below the field or inline with the field.\n *\n * @default 'below'\n */\n characterCountPosition?: 'below' | 'inline' | 'hidden'\n }\n\ntype FieldComponentProps<T extends HTMLElement> = Omit<\n BaseFieldProps,\n 'children' | 'className' | 'fieldRef' | 'variant'\n> &\n Omit<HtmlInputProps<T>, 'className' | 'style'>\n\n/**\n * BaseField is a base component that provides a consistent structure for form fields.\n */\nfunction BaseField({\n variant = 'default',\n label,\n value,\n auxiliaryLabel,\n message,\n tone = 'neutral',\n className,\n children,\n maxWidth,\n maxLength,\n hidden,\n 'aria-describedby': originalAriaDescribedBy,\n id: originalId,\n characterCountPosition = 'below',\n}: BaseFieldProps & BaseFieldVariantProps & WithEnhancedClassName) {\n const id = useId(originalId)\n const messageId = useId()\n\n const inputLength = validateInputLength({ value, maxLength })\n\n const [characterCount, setCharacterCount] = React.useState<string | null>(inputLength.count)\n const [characterCountTone, setCharacterCountTone] = React.useState<FieldTone>(inputLength.tone)\n\n const ariaDescribedBy = originalAriaDescribedBy ?? (message ? messageId : null)\n\n /**\n * Renders the character count element.\n * If the characterCountPosition value is 'hidden', it returns null.\n */\n function renderCharacterCount() {\n return characterCountPosition !== 'hidden' ? (\n <FieldCharacterCount tone={characterCountTone}>{characterCount}</FieldCharacterCount>\n ) : null\n }\n\n const childrenProps: ChildrenRenderProps = {\n id,\n value,\n ...(ariaDescribedBy ? { 'aria-describedby': ariaDescribedBy } : {}),\n 'aria-invalid': tone === 'error' ? true : undefined,\n onChange(event) {\n if (!maxLength) {\n return\n }\n\n const inputLength = validateInputLength({\n value: event.currentTarget.value,\n maxLength,\n })\n\n setCharacterCount(inputLength.count)\n setCharacterCountTone(inputLength.tone)\n },\n // If the character count is inline, we pass it as a prop to the children element so it can be rendered inline\n characterCountElement: characterCountPosition === 'inline' ? renderCharacterCount() : null,\n }\n\n React.useEffect(\n function updateCharacterCountOnPropChange() {\n if (!maxLength) {\n return\n }\n\n const inputLength = validateInputLength({\n value,\n maxLength,\n })\n\n setCharacterCount(inputLength.count)\n setCharacterCountTone(inputLength.tone)\n },\n [maxLength, value],\n )\n\n return (\n <Stack space=\"xsmall\" hidden={hidden}>\n <Box\n className={[\n className,\n styles.container,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n ]}\n maxWidth={maxWidth}\n >\n {label || auxiliaryLabel ? (\n <Box\n as=\"span\"\n display=\"flex\"\n justifyContent=\"spaceBetween\"\n alignItems=\"flexEnd\"\n >\n <Text\n size={variant === 'bordered' ? 'caption' : 'body'}\n as=\"label\"\n htmlFor={id}\n >\n {label ? <span className={styles.primaryLabel}>{label}</span> : null}\n </Text>\n {auxiliaryLabel ? (\n <Box className={styles.auxiliaryLabel} paddingLeft=\"small\">\n {auxiliaryLabel}\n </Box>\n ) : null}\n </Box>\n ) : null}\n {children(childrenProps)}\n </Box>\n\n {message || characterCount ? (\n <Columns align=\"right\" space=\"small\" maxWidth={maxWidth}>\n {message ? (\n <Column width=\"auto\">\n <FieldMessage id={messageId} tone={tone}>\n {message}\n </FieldMessage>\n </Column>\n ) : null}\n\n {/* If the character count is below the field, we render it, if it's inline,\n we pass it as a prop to the children element so it can be rendered inline */}\n {characterCountPosition === 'below' ? (\n <Column width=\"content\">{renderCharacterCount()}</Column>\n ) : null}\n </Columns>\n ) : null}\n </Stack>\n )\n}\n\nexport { BaseField, FieldMessage }\nexport type { BaseFieldVariant, BaseFieldVariantProps, FieldComponentProps }\n"],"names":["MAX_LENGTH_THRESHOLD","fieldToneToTextTone","tone","FieldMessage","id","children","React","Text","as","size","createElement","Box","marginRight","display","className","styles","loadingIcon","Spinner","FieldCharacterCount","validateInputLength","value","maxLength","count","currentLength","String","length","isNearMaxLength","BaseField","variant","label","auxiliaryLabel","message","maxWidth","hidden","originalAriaDescribedBy","originalId","characterCountPosition","useId","messageId","inputLength","characterCount","setCharacterCount","useState","characterCountTone","setCharacterCountTone","ariaDescribedBy","renderCharacterCount","childrenProps","_objectSpread","undefined","onChange","event","currentTarget","characterCountElement","useEffect","updateCharacterCountOnPropChange","Stack","space","container","error","bordered","justifyContent","alignItems","htmlFor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BAAA,OAAA;IAAMQ,SAAS,EAAEC,gBAAM,CAACiD,YAAAA;GAAxB,EAAuCnC,KAAvC,CAAH,GAA0D,IALpE,CANJ,EAaKC,cAAc,gBACXxB,KAAC,CAAAI,aAAD,CAACC,GAAD,EAAK;IAAAG,SAAS,EAAEC,gBAAM,CAACe,cAAlB;AAAkCmC,IAAAA,WAAW,EAAC,OAAA;GAAnD,EACKnC,cADL,CADW,GAIX,IAjBR,CADH,GAoBG,IA7BR,EA8BKzB,QAAQ,CAAC0C,aAAD,CA9Bb,CADJ,EAkCKhB,OAAO,IAAIS,cAAX,gBACGlC,mBAAA,CAAC4D,OAAD,EAAQ;AAACC,IAAAA,KAAK,EAAC,OAAP;AAAeV,IAAAA,KAAK,EAAC,OAArB;AAA6BzB,IAAAA,QAAQ,EAAEA,QAAAA;GAA/C,EACKD,OAAO,gBACJzB,mBAAA,CAAC8D,MAAD,EAAO;AAACC,IAAAA,KAAK,EAAC,MAAA;AAAP,GAAP,eACI/D,KAAA,CAAAI,aAAA,CAACP,YAAD,EAAc;AAAAC,IAAAA,EAAE,EAAEkC,SAAJ;AAAepC,IAAAA,IAAI,EAAEA,IAAAA;AAArB,GAAd,EACK6B,OADL,CADJ,CADI,GAMJ,IAPR,EAWKK,sBAAsB,KAAK,OAA3B,gBACG9B,KAAC,CAAAI,aAAD,CAAC0D,MAAD,EAAQ;AAAAC,IAAAA,KAAK,EAAC,SAAA;GAAd,EAAyBvB,oBAAoB,EAA7C,CADH,GAEG,IAbR,CADH,GAgBG,IAlDR,CADJ,CAAA;AAsDH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"select-field.js","sources":["../../src/select-field/select-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { BaseField, BaseFieldVariantProps, FieldComponentProps } from '../base-field'\nimport { Box } from '../box'\nimport styles from './select-field.module.css'\n\ninterface SelectFieldProps extends FieldComponentProps<HTMLSelectElement>, BaseFieldVariantProps {}\n\nconst SelectField = React.forwardRef<HTMLSelectElement, SelectFieldProps>(function SelectField(\n {\n variant = 'default',\n id,\n label,\n value,\n auxiliaryLabel,\n message,\n tone,\n maxWidth,\n children,\n hidden,\n 'aria-describedby': ariaDescribedBy,\n onChange: originalOnChange,\n ...props\n },\n ref,\n) {\n return (\n <BaseField\n variant={variant}\n id={id}\n label={label}\n value={value}\n auxiliaryLabel={auxiliaryLabel}\n message={message}\n tone={tone}\n maxWidth={maxWidth}\n hidden={hidden}\n aria-describedby={ariaDescribedBy}\n >\n {(extraProps) => (\n <Box\n data-testid=\"select-wrapper\"\n className={[\n styles.selectWrapper,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n ]}\n >\n <select\n {...props}\n {...extraProps}\n ref={ref}\n onChange={(event) => {\n originalOnChange?.(event)\n }}\n >\n {children}\n </select>\n <SelectChevron aria-hidden />\n </Box>\n )}\n </BaseField>\n )\n})\n\nfunction SelectChevron(props: JSX.IntrinsicElements['svg']) {\n return (\n <svg width=\"16\" height=\"16\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" {...props}>\n <path\n d=\"M11.646 5.646a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 1 1 .708-.708L8 9.293l3.646-3.647z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n}\n\nexport { SelectField }\nexport type { SelectFieldProps }\n"],"names":["SelectField","React","forwardRef","ref","variant","id","label","value","auxiliaryLabel","message","tone","maxWidth","children","hidden","ariaDescribedBy","onChange","originalOnChange","props","createElement","BaseField","extraProps","Box","className","styles","selectWrapper","error","bordered","_objectSpread","event","SelectChevron","width","height","fill","xmlns","d"],"mappings":";;;;;;;AAOMA,MAAAA,WAAW,gBAAGC,KAAK,CAACC,UAAN,CAAsD,SAASF,WAAT,CAgBtEG,IAAAA,EAAAA,GAhBsE,EAgBnE;EAAA,IAfH;AACIC,IAAAA,OAAO,GAAG,SADd;IAEIC,EAFJ;IAGIC,KAHJ;IAIIC,KAJJ;IA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;AACH,KAAA;GAEAhB,CAAAA,EAAAA,QARL,CARJ,eAkBIX,KAAA,CAAAiB,aAAA,CAACW,aAAD,EAA6B;IAAA,aAAA,EAAA,IAAA;GAA7B,CAlBJ,CAbR,CADJ,CAAA;AAqCH,CAvDmB,EAApB;;AAyDA,SAASA,aAAT,CAAuBZ,KAAvB,EAA0D;AACtD,EAAA,oBACIhB,KAAK,CAAAiB,aAAL,CAAK,KAAL,EAAAS,cAAA,CAAA;AAAKG,IAAAA,KAAK,EAAC,IAAX;AAAgBC,IAAAA,MAAM,EAAC,IAAvB;AAA4BC,IAAAA,IAAI,EAAC,MAAjC;AAAwCC,IAAAA,KAAK,EAAC,4BAAA;AAA9C,GAAA,EAA+EhB,KAA/E,CACIhB,eAAAA,KACI,CAAAiB,aADJ,CACI,MADJ,EACI;AAAAgB,IAAAA,CAAC,EAAC,yGAAF;AACAF,IAAAA,IAAI,EAAC,cAAA;AADL,GADJ,CADJ,CADJ,CAAA;AAQH;;;;"}
1
+ {"version":3,"file":"select-field.js","sources":["../../src/select-field/select-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { BaseField, BaseFieldVariantProps, FieldComponentProps } from '../base-field'\nimport { Box } from '../box'\nimport styles from './select-field.module.css'\n\ninterface SelectFieldProps\n extends Omit<FieldComponentProps<HTMLSelectElement>, 'maxLength' | 'characterCountPosition'>,\n BaseFieldVariantProps {}\n\nconst SelectField = React.forwardRef<HTMLSelectElement, SelectFieldProps>(function SelectField(\n {\n variant = 'default',\n id,\n label,\n value,\n auxiliaryLabel,\n message,\n tone,\n maxWidth,\n children,\n hidden,\n 'aria-describedby': ariaDescribedBy,\n onChange: originalOnChange,\n ...props\n },\n ref,\n) {\n return (\n <BaseField\n variant={variant}\n id={id}\n label={label}\n value={value}\n auxiliaryLabel={auxiliaryLabel}\n message={message}\n tone={tone}\n maxWidth={maxWidth}\n hidden={hidden}\n aria-describedby={ariaDescribedBy}\n >\n {(extraProps) => (\n <Box\n data-testid=\"select-wrapper\"\n className={[\n styles.selectWrapper,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n ]}\n >\n <select\n {...props}\n {...extraProps}\n ref={ref}\n onChange={(event) => {\n originalOnChange?.(event)\n }}\n >\n {children}\n </select>\n <SelectChevron aria-hidden />\n </Box>\n )}\n </BaseField>\n )\n})\n\nfunction SelectChevron(props: JSX.IntrinsicElements['svg']) {\n return (\n <svg width=\"16\" height=\"16\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" {...props}>\n <path\n d=\"M11.646 5.646a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 1 1 .708-.708L8 9.293l3.646-3.647z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n}\n\nexport { SelectField }\nexport type { SelectFieldProps }\n"],"names":["SelectField","React","forwardRef","ref","variant","id","label","value","auxiliaryLabel","message","tone","maxWidth","children","hidden","ariaDescribedBy","onChange","originalOnChange","props","createElement","BaseField","extraProps","Box","className","styles","selectWrapper","error","bordered","_objectSpread","event","SelectChevron","width","height","fill","xmlns","d"],"mappings":";;;;;;;AASMA,MAAAA,WAAW,gBAAGC,KAAK,CAACC,UAAN,CAAsD,SAASF,WAAT,CAgBtEG,IAAAA,EAAAA,GAhBsE,EAgBnE;EAAA,IAfH;AACIC,IAAAA,OAAO,GAAG,SADd;IAEIC,EAFJ;IAGIC,KAHJ;IAIIC,KAJJ;IAKIC,cALJ;IAMIC,OANJ;IAOIC,IAPJ;IAQIC,QARJ;IASIC,QATJ;IAUIC,MAVJ;AAWI,IAAA,kBAAA,EAAoBC,eAXxB;AAYIC,IAAAA,QAAQ,EAAEC,gBAAAA;GAGX,GAAA,IAAA;AAAA,MAFIC,KAEJ,GAAA,wBAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AAEH,EAAA,oBACIhB,KAAC,CAAAiB,aAAD,CAACC,SAAD,EACI;AAAAf,IAAAA,OAAO,EAAEA,OAAT;AACAC,IAAAA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,EAAC,IAAvB;AAA4BC,IAAAA,IAAI,EAAC,MAAjC;AAAwCC,IAAAA,KAAK,EAAC,4BAAA;AAA9C,GAAA,EAA+EhB,KAA/E,CACIhB,eAAAA,KACI,CAAAiB,aADJ,CACI,MADJ,EACI;AAAAgB,IAAAA,CAAC,EAAC,yGAAF;AACAF,IAAAA,IAAI,EAAC,cAAA;AADL,GADJ,CADJ,CADJ,CAAA;AAQH;;;;"}
@@ -5,8 +5,8 @@ import { Box } from '../box/box.js';
5
5
  import modules_aaf25250 from './text-field.module.css.js';
6
6
  import { useMergeRefs } from 'use-callback-ref';
7
7
 
8
- const _excluded = ["variant", "id", "label", "value", "auxiliaryLabel", "message", "tone", "type", "maxWidth", "maxLength", "hidden", "aria-describedby", "startSlot", "endSlot", "onChange"],
9
- _excluded2 = ["onChange"];
8
+ const _excluded = ["variant", "id", "label", "value", "auxiliaryLabel", "message", "tone", "type", "maxWidth", "maxLength", "hidden", "aria-describedby", "startSlot", "endSlot", "onChange", "characterCountPosition"],
9
+ _excluded2 = ["onChange", "characterCountElement"];
10
10
  const TextField = /*#__PURE__*/React.forwardRef(function TextField(_ref, ref) {
11
11
  let {
12
12
  variant = 'default',
@@ -23,7 +23,8 @@ const TextField = /*#__PURE__*/React.forwardRef(function TextField(_ref, ref) {
23
23
  'aria-describedby': ariaDescribedBy,
24
24
  startSlot,
25
25
  endSlot,
26
- onChange: originalOnChange
26
+ onChange: originalOnChange,
27
+ characterCountPosition = 'below'
27
28
  } = _ref,
28
29
  props = _objectWithoutProperties(_ref, _excluded);
29
30
 
@@ -48,10 +49,12 @@ const TextField = /*#__PURE__*/React.forwardRef(function TextField(_ref, ref) {
48
49
  maxWidth: maxWidth,
49
50
  maxLength: maxLength,
50
51
  hidden: hidden,
51
- "aria-describedby": ariaDescribedBy
52
+ "aria-describedby": ariaDescribedBy,
53
+ characterCountPosition: characterCountPosition
52
54
  }, _ref2 => {
53
55
  let {
54
- onChange
56
+ onChange,
57
+ characterCountElement
55
58
  } = _ref2,
56
59
  extraProps = _objectWithoutProperties(_ref2, _excluded2);
57
60
 
@@ -73,12 +76,12 @@ const TextField = /*#__PURE__*/React.forwardRef(function TextField(_ref, ref) {
73
76
  originalOnChange == null ? void 0 : originalOnChange(event);
74
77
  onChange == null ? void 0 : onChange(event);
75
78
  }
76
- })), endSlot ? /*#__PURE__*/React.createElement(Box, {
79
+ })), endSlot || characterCountElement ? /*#__PURE__*/React.createElement(Box, {
77
80
  className: modules_aaf25250.slot,
78
81
  display: "flex",
79
82
  marginRight: variant === 'bordered' ? '-xsmall' : 'xsmall',
80
83
  marginLeft: variant === 'bordered' ? 'xsmall' : '-xsmall'
81
- }, endSlot) : null);
84
+ }, characterCountElement, endSlot) : null);
82
85
  });
83
86
  });
84
87
 
@@ -1 +1 @@
1
- {"version":3,"file":"text-field.js","sources":["../../src/text-field/text-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { BaseField, BaseFieldVariantProps } from '../base-field'\nimport { Box } from '../box'\nimport styles from './text-field.module.css'\nimport type { FieldComponentProps } from '../base-field'\nimport { useMergeRefs } from 'use-callback-ref'\n\ntype TextFieldType = 'email' | 'search' | 'tel' | 'text' | 'url'\n\ninterface TextFieldProps\n extends Omit<FieldComponentProps<HTMLInputElement>, 'type'>,\n BaseFieldVariantProps {\n type?: TextFieldType\n startSlot?: React.ReactElement | string | number\n endSlot?: React.ReactElement | string | number\n /**\n * The maximum number of characters that the input field can accept.\n * When this limit is reached, the input field will not accept any more characters.\n * The counter element will turn red when the number of characters is within 10 of the maximum limit.\n */\n maxLength?: number\n}\n\nconst TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(function TextField(\n {\n variant = 'default',\n id,\n label,\n value,\n auxiliaryLabel,\n message,\n tone,\n type = 'text',\n maxWidth,\n maxLength,\n hidden,\n 'aria-describedby': ariaDescribedBy,\n startSlot,\n endSlot,\n onChange: originalOnChange,\n ...props\n },\n ref,\n) {\n const internalRef = React.useRef<HTMLInputElement>(null)\n const combinedRef = useMergeRefs([ref, internalRef])\n\n function handleClick(event: React.MouseEvent) {\n if (event.currentTarget === combinedRef.current) return\n internalRef.current?.focus()\n }\n\n return (\n <BaseField\n variant={variant}\n id={id}\n label={label}\n value={value}\n auxiliaryLabel={auxiliaryLabel}\n message={message}\n tone={tone}\n maxWidth={maxWidth}\n maxLength={maxLength}\n hidden={hidden}\n aria-describedby={ariaDescribedBy}\n >\n {({ onChange, ...extraProps }) => (\n <Box\n display=\"flex\"\n alignItems=\"center\"\n className={[\n styles.inputWrapper,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n props.readOnly ? styles.readOnly : null,\n ]}\n onClick={handleClick}\n >\n {startSlot ? (\n <Box\n className={styles.slot}\n display=\"flex\"\n marginRight={variant === 'bordered' ? 'xsmall' : '-xsmall'}\n marginLeft={variant === 'bordered' ? '-xsmall' : 'xsmall'}\n >\n {startSlot}\n </Box>\n ) : null}\n <input\n {...props}\n {...extraProps}\n type={type}\n ref={combinedRef}\n maxLength={maxLength}\n onChange={(event) => {\n originalOnChange?.(event)\n onChange?.(event)\n }}\n />\n {endSlot ? (\n <Box\n className={styles.slot}\n display=\"flex\"\n marginRight={variant === 'bordered' ? '-xsmall' : 'xsmall'}\n marginLeft={variant === 'bordered' ? 'xsmall' : '-xsmall'}\n >\n {endSlot}\n </Box>\n ) : null}\n </Box>\n )}\n </BaseField>\n )\n})\n\nexport { TextField }\nexport type { TextFieldProps, TextFieldType }\n"],"names":["TextField","React","forwardRef","ref","variant","id","label","value","auxiliaryLabel","message","tone","type","maxWidth","maxLength","hidden","ariaDescribedBy","startSlot","endSlot","onChange","originalOnChange","props","internalRef","useRef","combinedRef","useMergeRefs","handleClick","event","currentTarget","current","focus","createElement","BaseField","extraProps","Box","display","alignItems","className","styles","inputWrapper","error","bordered","readOnly","onClick","slot","marginRight","marginLeft"],"mappings":";;;;;;;;;AAuBMA,MAAAA,SAAS,gBAAGC,KAAK,CAACC,UAAN,CAAmD,SAASF,SA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AAGQ,KAAD,IAAU;AAChBP,QAAAA,gBAAgB,IAAhB,IAAA,GAAA,KAAA,CAAA,GAAAA,gBAAgB,CAAGO,KAAH,CAAhB,CAAA;AACAR,QAAAA,QAAQ,IAAR,IAAA,GAAA,KAAA,CAAA,GAAAA,QAAQ,CAAGQ,KAAH,CAAR,CAAA;AACH,OAAA;KA9BT,CAAA,CAAA,EAgCKT,OAAO,gBACJhB,KAAA,CAAA6B,aAAA,CAACG,GAAD,EAAI;MACAG,SAAS,EAAEC,gBAAM,CAACM,IADlB;AAEAT,MAAAA,OAAO,EAAC,MAFR;AAGAU,MAAAA,WAAW,EAAExC,OAAO,KAAK,UAAZ,GAAyB,SAAzB,GAAqC,QAHlD;AAIAyC,MAAAA,UAAU,EAAEzC,OAAO,KAAK,UAAZ,GAAyB,QAAzB,GAAoC,SAAA;AAJhD,KAAJ,EAMKa,OANL,CADI,GASJ,IAzCR,CADH,CAAA;AAAA,GAbL,CADJ,CAAA;AA6DH,CA1FiB;;;;"}
1
+ {"version":3,"file":"text-field.js","sources":["../../src/text-field/text-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { BaseField, BaseFieldVariantProps } from '../base-field'\nimport { Box } from '../box'\nimport styles from './text-field.module.css'\nimport type { BaseFieldProps, FieldComponentProps } from '../base-field'\nimport { useMergeRefs } from 'use-callback-ref'\n\ntype TextFieldType = 'email' | 'search' | 'tel' | 'text' | 'url'\n\ninterface TextFieldProps\n extends Omit<FieldComponentProps<HTMLInputElement>, 'type'>,\n BaseFieldVariantProps,\n Pick<BaseFieldProps, 'characterCountPosition'> {\n type?: TextFieldType\n startSlot?: React.ReactElement | string | number\n endSlot?: React.ReactElement | string | number\n /**\n * The maximum number of characters that the input field can accept.\n * When this limit is reached, the input field will not accept any more characters.\n * The counter element will turn red when the number of characters is within 10 of the maximum limit.\n */\n maxLength?: number\n}\n\nconst TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(function TextField(\n {\n variant = 'default',\n id,\n label,\n value,\n auxiliaryLabel,\n message,\n tone,\n type = 'text',\n maxWidth,\n maxLength,\n hidden,\n 'aria-describedby': ariaDescribedBy,\n startSlot,\n endSlot,\n onChange: originalOnChange,\n characterCountPosition = 'below',\n ...props\n },\n ref,\n) {\n const internalRef = React.useRef<HTMLInputElement>(null)\n const combinedRef = useMergeRefs([ref, internalRef])\n\n function handleClick(event: React.MouseEvent) {\n if (event.currentTarget === combinedRef.current) return\n internalRef.current?.focus()\n }\n\n return (\n <BaseField\n variant={variant}\n id={id}\n label={label}\n value={value}\n auxiliaryLabel={auxiliaryLabel}\n message={message}\n tone={tone}\n maxWidth={maxWidth}\n maxLength={maxLength}\n hidden={hidden}\n aria-describedby={ariaDescribedBy}\n characterCountPosition={characterCountPosition}\n >\n {({ onChange, characterCountElement, ...extraProps }) => (\n <Box\n display=\"flex\"\n alignItems=\"center\"\n className={[\n styles.inputWrapper,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n props.readOnly ? styles.readOnly : null,\n ]}\n onClick={handleClick}\n >\n {startSlot ? (\n <Box\n className={styles.slot}\n display=\"flex\"\n marginRight={variant === 'bordered' ? 'xsmall' : '-xsmall'}\n marginLeft={variant === 'bordered' ? '-xsmall' : 'xsmall'}\n >\n {startSlot}\n </Box>\n ) : null}\n <input\n {...props}\n {...extraProps}\n type={type}\n ref={combinedRef}\n maxLength={maxLength}\n onChange={(event) => {\n originalOnChange?.(event)\n onChange?.(event)\n }}\n />\n {endSlot || characterCountElement ? (\n <Box\n className={styles.slot}\n display=\"flex\"\n marginRight={variant === 'bordered' ? '-xsmall' : 'xsmall'}\n marginLeft={variant === 'bordered' ? 'xsmall' : '-xsmall'}\n >\n {characterCountElement}\n {endSlot}\n </Box>\n ) : null}\n </Box>\n )}\n </BaseField>\n )\n})\n\nexport { TextField }\nexport type { TextFieldProps, TextFieldType }\n"],"names":["TextField","React","forwardRef","ref","variant","id","label","value","auxiliaryLabel","message","tone","type","maxWidth","maxLength","hidden","ariaDescribedBy","startSlot","endSlot","onChange","originalOnChange","characterCountPosition","props","internalRef","useRef","combinedRef","useMergeRefs","handleClick","event","currentTarget","current","focus","createElement","BaseField","characterCountElement","extraProps","Box","display","alignItems","className","styles","inputWrapper","error","bordered","readOnly","onClick","slot","marginRight","marginLeft"],"mappings":";;;;;;;;;AAwBMA,MAAAA,SAAS,gBAAGC,KAAK,CAACC,UAAN,CAAmD,SAASF,SAAT,CAoBjEG,IAAAA,EAAAA,GApBiE,EAoB9D;EAAA,IAnBH;AACIC,IAAAA,OAAO,GAAG,SADd;IAEIC,EAFJ;IAGIC,KAHJ;IAIIC,KAJJ;IAKIC,cALJ;IAMIC,OANJ;IAOIC,IAPJ;AAQIC,IAAAA,IAAI,GAAG,MARX;IASIC,QATJ;IAUIC,SAVJ;IAWIC,MAXJ;AAYI,IAAA,kBAAA,EAAoBC,eAZxB;IAaIC,SAbJ;IAcIC,OAdJ;AAeIC,IAAAA,QAAQ,EAAEC,gBAfd;AAgBIC,IAAAA,sBAAsB,GAAG,OAAA;GAG1B,GAAA,IAAA;AAAA,MAFIC,KAEJ,GAAA,wBAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AAEH,EAAA,MAAMC,WAAW,GAAGrB,KAAK,CAACsB,MAAN,CAA+B,IAA/B,CAApB,CAAA;EACA,MAAMC,WAAW,GAAGC,YAAY,CAAC,CAACtB,GAAD,EAAMmB,WAAN,CAAD,CAAhC,CAAA;;EAEA,SAASI,WAAT,CAAqBC,KAArB,EAA4C;AAAA,IAAA,IAAA,oBAAA,CAAA;;AACxC,IAAA,IAAIA,KAAK,CAACC,aAAN,KAAwBJ,WAAW,CAACK,OAAxC,EAAiD,OAAA;AACjD,IAAA,CAAA,oBAAA,GAAAP,WAAW,CAACO,OAAZ,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,oBAAA,CAAqBC,KAArB,EAAA,CAAA;AACH,GAAA;;AAED,EAAA,oBACI7B,KAAA,CAAA8B,aAAA,CAACC,SAAD,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C,OAAO,KAAK,UAAZ,GAAyB,SAAzB,GAAqC,QAAA;AAJjD,KAAJ,EAMKY,SANL,CADM,GASN,IApBR,eAqBIf,KACQ,CAAA8B,aADR,CACQ,OADR,EACQV,cAAAA,CAAAA,cAAAA,CAAAA,cAAAA,CAAAA,EAAAA,EAAAA,KADR,GAEQa,UAFR,CAAA,EAAA,EAAA,EAAA;AAGIvB,MAAAA,IAAI,EAAEA,IAHV;AAIIR,MAAAA,GAAG,EAAEqB,WAJT;AAKIX,MAAAA,SAAS,EAAEA,SALf;MAMIK,QAAQ,EAAGS,KAAD,IAAU;AAChBR,QAAAA,gBAAgB,IAAhB,IAAA,GAAA,KAAA,CAAA,GAAAA,gBAAgB,CAAGQ,KAAH,CAAhB,CAAA;AACAT,QAAAA,QAAQ,IAAR,IAAA,GAAA,KAAA,CAAA,GAAAA,QAAQ,CAAGS,KAAH,CAAR,CAAA;AACH,OAAA;KA9BT,CAAA,CAAA,EAgCKV,OAAO,IAAIgB,qBAAX,gBACGhC,KAAA,CAAA8B,aAAA,CAACI,GAAD,EACI;MAAAG,SAAS,EAAEC,gBAAM,CAACM,IAAlB;AACAT,MAAAA,OAAO,EAAC,MADR;AAEAU,MAAAA,WAAW,EAAE1C,OAAO,KAAK,UAAZ,GAAyB,SAAzB,GAAqC,QAFlD;AAGA2C,MAAAA,UAAU,EAAE3C,OAAO,KAAK,UAAZ,GAAyB,QAAzB,GAAoC,SAAA;AAHhD,KADJ,EAMK6B,qBANL,EAOKhB,OAPL,CADH,GAUG,IA1CR,CADH,CAAA;AAAA,GAdL,CADJ,CAAA;AA+DH,CA7FiB;;;;"}
@@ -1,4 +1,4 @@
1
- var modules_aaf25250 = {"inputWrapper":"f2de4e8d","readOnly":"ee26e40c","bordered":"_3afb1a56","error":"f3ff9f57","slot":"_3eb7b0ef"};
1
+ var modules_aaf25250 = {"inputWrapper":"c8f65b3b","readOnly":"_326f2644","bordered":"_5252fd3d","error":"_0141b7ac","slot":"b79b851f"};
2
2
 
3
3
  export { modules_aaf25250 as default };
4
4
  //# sourceMappingURL=text-field.module.css.js.map
@@ -14,6 +14,7 @@ type ChildrenRenderProps = {
14
14
  'aria-describedby'?: string;
15
15
  'aria-invalid'?: true;
16
16
  onChange?: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>;
17
+ characterCountElement?: React.ReactNode | null;
17
18
  };
18
19
  type HtmlInputProps<T extends HTMLElement> = React.DetailedHTMLProps<React.InputHTMLAttributes<T>, T>;
19
20
  type BaseFieldVariant = 'default' | 'bordered';
@@ -32,7 +33,7 @@ type BaseFieldVariantProps = {
32
33
  */
33
34
  variant?: BaseFieldVariant;
34
35
  };
35
- type BaseFieldProps = WithEnhancedClassName & Pick<HtmlInputProps<HTMLInputElement>, 'id' | 'hidden' | 'maxLength' | 'aria-describedby'> & {
36
+ export type BaseFieldProps = WithEnhancedClassName & Pick<HtmlInputProps<HTMLInputElement>, 'id' | 'hidden' | 'maxLength' | 'aria-describedby'> & {
36
37
  /**
37
38
  * The main label for this field element.
38
39
  *
@@ -108,8 +109,18 @@ type BaseFieldProps = WithEnhancedClassName & Pick<HtmlInputProps<HTMLInputEleme
108
109
  * the public props of such components.
109
110
  */
110
111
  children: (props: ChildrenRenderProps) => React.ReactNode;
112
+ /**
113
+ * The position of the character count element.
114
+ * It can be shown below the field or inline with the field.
115
+ *
116
+ * @default 'below'
117
+ */
118
+ characterCountPosition?: 'below' | 'inline' | 'hidden';
111
119
  };
112
120
  type FieldComponentProps<T extends HTMLElement> = Omit<BaseFieldProps, 'children' | 'className' | 'fieldRef' | 'variant'> & Omit<HtmlInputProps<T>, 'className' | 'style'>;
113
- declare function BaseField({ variant, label, value, auxiliaryLabel, message, tone, className, children, maxWidth, maxLength, hidden, 'aria-describedby': originalAriaDescribedBy, id: originalId, }: BaseFieldProps & BaseFieldVariantProps & WithEnhancedClassName): React.JSX.Element;
121
+ /**
122
+ * BaseField is a base component that provides a consistent structure for form fields.
123
+ */
124
+ declare function BaseField({ variant, label, value, auxiliaryLabel, message, tone, className, children, maxWidth, maxLength, hidden, 'aria-describedby': originalAriaDescribedBy, id: originalId, characterCountPosition, }: BaseFieldProps & BaseFieldVariantProps & WithEnhancedClassName): React.JSX.Element;
114
125
  export { BaseField, FieldMessage };
115
126
  export type { BaseFieldVariant, BaseFieldVariantProps, FieldComponentProps };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_rollupPluginBabelHelpers.js"),t=require("react"),n=require("../box/box.js"),r=require("../utils/common-helpers.js"),a=require("../text/text.js"),l=require("./base-field.module.css.js"),u=require("../stack/stack.js"),i=require("../spinner/spinner.js"),s=require("../columns/columns.js");function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,t}var c=o(t);function d(e){return"error"===e?"danger":"success"===e?"positive":"secondary"}function m({id:e,children:t,tone:r}){return c.createElement(a.Text,{as:"p",tone:d(r),size:"copy",id:e},"loading"===r?c.createElement(n.Box,{as:"span",marginRight:"xsmall",display:"inlineFlex",className:l.default.loadingIcon},c.createElement(i.Spinner,{size:16})):null,t)}function f({children:e,tone:t}){return c.createElement(a.Text,{tone:d(t),size:"copy"},e)}function p({value:e,maxLength:t}){if(!t)return{count:null,tone:"neutral"};const n=String(e||"").length;return{count:n+"/"+t,tone:t-n<=10?"error":"neutral"}}exports.BaseField=function({variant:t="default",label:i,value:o,auxiliaryLabel:d,message:x,tone:b="neutral",className:g,children:h,maxWidth:E,maxLength:v,hidden:j,"aria-describedby":y,id:q}){const L=r.useId(q),B=r.useId(),S=p({value:o,maxLength:v}),[O,_]=c.useState(S.count),[C,N]=c.useState(S.tone),k=null!=y?y:x?B:null,w=e.objectSpread2(e.objectSpread2({id:L,value:o},k?{"aria-describedby":k}:{}),{},{"aria-invalid":"error"===b||void 0,onChange(e){if(!v)return;const t=p({value:e.currentTarget.value,maxLength:v});_(t.count),N(t.tone)}});return c.useEffect((function(){if(!v)return;const e=p({value:o,maxLength:v});_(e.count),N(e.tone)}),[v,o]),c.createElement(u.Stack,{space:"xsmall",hidden:j},c.createElement(n.Box,{className:[g,l.default.container,"error"===b?l.default.error:null,"bordered"===t?l.default.bordered:null],maxWidth:E},i||d?c.createElement(n.Box,{as:"span",display:"flex",justifyContent:"spaceBetween",alignItems:"flexEnd"},c.createElement(a.Text,{size:"bordered"===t?"caption":"body",as:"label",htmlFor:L},i?c.createElement("span",{className:l.default.primaryLabel},i):null),d?c.createElement(n.Box,{className:l.default.auxiliaryLabel,paddingLeft:"small"},d):null):null,h(w)),x||O?c.createElement(s.Columns,{align:"right",space:"small",maxWidth:E},x?c.createElement(s.Column,{width:"auto"},c.createElement(m,{id:B,tone:b},x)):null,O?c.createElement(s.Column,{width:"content"},c.createElement(f,{tone:C},O)):null):null)},exports.FieldMessage=m;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_rollupPluginBabelHelpers.js"),t=require("react"),n=require("../box/box.js"),r=require("../utils/common-helpers.js"),l=require("../text/text.js"),a=require("./base-field.module.css.js"),u=require("../stack/stack.js"),i=require("../spinner/spinner.js"),o=require("../columns/columns.js");function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,t}var c=s(t);function d(e){return"error"===e?"danger":"success"===e?"positive":"secondary"}function m({id:e,children:t,tone:r}){return c.createElement(l.Text,{as:"p",tone:d(r),size:"copy",id:e},"loading"===r?c.createElement(n.Box,{as:"span",marginRight:"xsmall",display:"inlineFlex",className:a.default.loadingIcon},c.createElement(i.Spinner,{size:16})):null,t)}function f({children:e,tone:t}){return c.createElement(l.Text,{tone:d(t),size:"copy"},e)}function p({value:e,maxLength:t}){if(!t)return{count:null,tone:"neutral"};const n=String(e||"").length;return{count:n+"/"+t,tone:t-n<=0?"error":"neutral"}}exports.BaseField=function({variant:t="default",label:i,value:s,auxiliaryLabel:d,message:x,tone:b="neutral",className:h,children:g,maxWidth:E,maxLength:v,hidden:j,"aria-describedby":y,id:q,characterCountPosition:L="below"}){const B=r.useId(q),C=r.useId(),S=p({value:s,maxLength:v}),[w,O]=c.useState(S.count),[_,N]=c.useState(S.tone),P=null!=y?y:x?C:null;function k(){return"hidden"!==L?c.createElement(f,{tone:_},w):null}const z=e.objectSpread2(e.objectSpread2({id:B,value:s},P?{"aria-describedby":P}:{}),{},{"aria-invalid":"error"===b||void 0,onChange(e){if(!v)return;const t=p({value:e.currentTarget.value,maxLength:v});O(t.count),N(t.tone)},characterCountElement:"inline"===L?k():null});return c.useEffect((function(){if(!v)return;const e=p({value:s,maxLength:v});O(e.count),N(e.tone)}),[v,s]),c.createElement(u.Stack,{space:"xsmall",hidden:j},c.createElement(n.Box,{className:[h,a.default.container,"error"===b?a.default.error:null,"bordered"===t?a.default.bordered:null],maxWidth:E},i||d?c.createElement(n.Box,{as:"span",display:"flex",justifyContent:"spaceBetween",alignItems:"flexEnd"},c.createElement(l.Text,{size:"bordered"===t?"caption":"body",as:"label",htmlFor:B},i?c.createElement("span",{className:a.default.primaryLabel},i):null),d?c.createElement(n.Box,{className:a.default.auxiliaryLabel,paddingLeft:"small"},d):null):null,g(z)),x||w?c.createElement(o.Columns,{align:"right",space:"small",maxWidth:E},x?c.createElement(o.Column,{width:"auto"},c.createElement(m,{id:C,tone:b},x)):null,"below"===L?c.createElement(o.Column,{width:"content"},k()):null):null)},exports.FieldMessage=m;
2
2
  //# sourceMappingURL=base-field.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base-field.js","sources":["../../src/base-field/base-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Box, BoxProps } from '../box'\nimport { useId } from '../utils/common-helpers'\nimport { Text } from '../text'\nimport styles from './base-field.module.css'\nimport { Stack } from '../stack'\n\nimport type { WithEnhancedClassName } from '../utils/common-types'\nimport { Spinner } from '../spinner'\nimport { Column, Columns } from '../columns'\n\nconst MAX_LENGTH_THRESHOLD = 10\n\ntype FieldTone = 'neutral' | 'success' | 'error' | 'loading'\n\ntype FieldMessageProps = {\n id: string\n children: React.ReactNode\n tone: FieldTone\n}\n\nfunction fieldToneToTextTone(tone: FieldTone) {\n return tone === 'error' ? 'danger' : tone === 'success' ? 'positive' : 'secondary'\n}\n\nfunction FieldMessage({ id, children, tone }: FieldMessageProps) {\n return (\n <Text as=\"p\" tone={fieldToneToTextTone(tone)} size=\"copy\" id={id}>\n {tone === 'loading' ? (\n <Box\n as=\"span\"\n marginRight=\"xsmall\"\n display=\"inlineFlex\"\n className={styles.loadingIcon}\n >\n <Spinner size={16} />\n </Box>\n ) : null}\n {children}\n </Text>\n )\n}\n\ntype FieldCharacterCountProps = {\n children: React.ReactNode\n tone: FieldTone\n}\n\nfunction FieldCharacterCount({ children, tone }: FieldCharacterCountProps) {\n return (\n <Text tone={fieldToneToTextTone(tone)} size=\"copy\">\n {children}\n </Text>\n )\n}\n\ntype ValidateInputLengthProps = {\n value?: React.InputHTMLAttributes<unknown>['value']\n maxLength?: number\n}\n\ntype ValidateInputLengthResult = {\n count: string | null\n tone: FieldTone\n}\n\nfunction validateInputLength({\n value,\n maxLength,\n}: ValidateInputLengthProps): ValidateInputLengthResult {\n if (!maxLength) {\n return {\n count: null,\n tone: 'neutral',\n }\n }\n\n const currentLength = String(value || '').length\n const isNearMaxLength = maxLength - currentLength <= MAX_LENGTH_THRESHOLD\n\n return {\n count: `${currentLength}/${maxLength}`,\n tone: isNearMaxLength ? 'error' : 'neutral',\n }\n}\n\n//\n// BaseField\n//\n\ntype ChildrenRenderProps = {\n id: string\n value?: React.InputHTMLAttributes<unknown>['value']\n 'aria-describedby'?: string\n 'aria-invalid'?: true\n onChange?: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>\n}\n\ntype HtmlInputProps<T extends HTMLElement> = React.DetailedHTMLProps<\n React.InputHTMLAttributes<T>,\n T\n>\n\ntype BaseFieldVariant = 'default' | 'bordered'\ntype BaseFieldVariantProps = {\n /**\n * Provides alternative visual layouts or modes that the field can be rendered in.\n *\n * Namely, there are two variants supported:\n *\n * - the default one\n * - a \"bordered\" variant, where the border of the field surrounds also the labels, instead\n * of just surrounding the actual field element\n *\n * In both cases, the message and description texts for the field lie outside the bordered\n * area.\n */\n variant?: BaseFieldVariant\n}\n\ntype BaseFieldProps = WithEnhancedClassName &\n Pick<HtmlInputProps<HTMLInputElement>, 'id' | 'hidden' | 'maxLength' | 'aria-describedby'> & {\n /**\n * The main label for this field element.\n *\n * This prop is not optional. Consumers of field components must be explicit about not\n * wanting a label by passing `label=\"\"` or `label={null}`. In those situations, consumers\n * should make sure that fields are properly labelled semantically by other means (e.g using\n * `aria-labelledby`, or rendering a `<label />` element referencing the field by id).\n *\n * Avoid providing interactive elements in the label. Prefer `auxiliaryLabel` for that.\n *\n * @see BaseFieldProps['auxiliaryLabel']\n */\n label: React.ReactNode\n\n /**\n * The initial value for this field element.\n *\n * This prop is used to calculate the character count for the initial value, and is then\n * passed to the underlying child element.\n */\n value?: React.InputHTMLAttributes<unknown>['value']\n\n /**\n * An optional extra element to be placed to the right of the main label.\n *\n * This extra element is not included in the accessible name of the field element. Its only\n * purpose is either visual, or functional (if you include interactive elements in it).\n *\n * @see BaseFieldProps['label']\n *\n * @deprecated The usage of this element is discouraged given that it was removed from the\n * latest form field spec revision.\n */\n auxiliaryLabel?: React.ReactNode\n\n /**\n * A message associated with the field. It is rendered below the field, and with an\n * appearance that conveys the tone of the field (e.g. coloured red for errors, green for\n * success, etc).\n *\n * The message element is associated to the field via the `aria-describedby` attribute.\n *\n * In the future, when `aria-errormessage` gets better user agent support, we should use it\n * to associate the filed with a message when tone is `\"error\"`.\n *\n * @see BaseFieldProps['tone']\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-errormessage\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-invalid\n */\n message?: React.ReactNode\n\n /**\n * The tone with which the message, if any, is presented.\n *\n * If the tone is `\"error\"`, the field border turns red, and the message, if any, is also\n * red.\n *\n * When the tone is `\"loading\"`, it is recommended that you also disable the field. However,\n * this is not enforced by the component. It is only a recommendation.\n *\n * @see BaseFieldProps['message']\n * @see BaseFieldProps['hint']\n */\n tone?: FieldTone\n\n /**\n * The maximum width that the input field can expand to.\n */\n maxWidth?: BoxProps['maxWidth']\n\n /**\n * The maximum number of characters that the input field can accept.\n * When this limit is reached, the input field will not accept any more characters.\n * The counter element will turn red when the number of characters is within 10 of the maximum limit.\n */\n maxLength?: number\n\n /**\n * Used internally by components composed using `BaseField`. It is not exposed as part of\n * the public props of such components.\n */\n children: (props: ChildrenRenderProps) => React.ReactNode\n }\n\ntype FieldComponentProps<T extends HTMLElement> = Omit<\n BaseFieldProps,\n 'children' | 'className' | 'fieldRef' | 'variant'\n> &\n Omit<HtmlInputProps<T>, 'className' | 'style'>\n\nfunction BaseField({\n variant = 'default',\n label,\n value,\n auxiliaryLabel,\n message,\n tone = 'neutral',\n className,\n children,\n maxWidth,\n maxLength,\n hidden,\n 'aria-describedby': originalAriaDescribedBy,\n id: originalId,\n}: BaseFieldProps & BaseFieldVariantProps & WithEnhancedClassName) {\n const id = useId(originalId)\n const messageId = useId()\n\n const inputLength = validateInputLength({ value, maxLength })\n\n const [characterCount, setCharacterCount] = React.useState<string | null>(inputLength.count)\n const [characterCountTone, setCharacterCountTone] = React.useState<FieldTone>(inputLength.tone)\n\n const ariaDescribedBy = originalAriaDescribedBy ?? (message ? messageId : null)\n\n const childrenProps: ChildrenRenderProps = {\n id,\n value,\n ...(ariaDescribedBy ? { 'aria-describedby': ariaDescribedBy } : {}),\n 'aria-invalid': tone === 'error' ? true : undefined,\n onChange(event) {\n if (!maxLength) {\n return\n }\n\n const inputLength = validateInputLength({\n value: event.currentTarget.value,\n maxLength,\n })\n\n setCharacterCount(inputLength.count)\n setCharacterCountTone(inputLength.tone)\n },\n }\n\n React.useEffect(\n function updateCharacterCountOnPropChange() {\n if (!maxLength) {\n return\n }\n\n const inputLength = validateInputLength({\n value,\n maxLength,\n })\n\n setCharacterCount(inputLength.count)\n setCharacterCountTone(inputLength.tone)\n },\n [maxLength, value],\n )\n\n return (\n <Stack space=\"xsmall\" hidden={hidden}>\n <Box\n className={[\n className,\n styles.container,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n ]}\n maxWidth={maxWidth}\n >\n {label || auxiliaryLabel ? (\n <Box\n as=\"span\"\n display=\"flex\"\n justifyContent=\"spaceBetween\"\n alignItems=\"flexEnd\"\n >\n <Text\n size={variant === 'bordered' ? 'caption' : 'body'}\n as=\"label\"\n htmlFor={id}\n >\n {label ? <span className={styles.primaryLabel}>{label}</span> : null}\n </Text>\n {auxiliaryLabel ? (\n <Box className={styles.auxiliaryLabel} paddingLeft=\"small\">\n {auxiliaryLabel}\n </Box>\n ) : null}\n </Box>\n ) : null}\n {children(childrenProps)}\n </Box>\n {message || characterCount ? (\n <Columns align=\"right\" space=\"small\" maxWidth={maxWidth}>\n {message ? (\n <Column width=\"auto\">\n <FieldMessage id={messageId} tone={tone}>\n {message}\n </FieldMessage>\n </Column>\n ) : null}\n {characterCount ? (\n <Column width=\"content\">\n <FieldCharacterCount tone={characterCountTone}>\n {characterCount}\n </FieldCharacterCount>\n </Column>\n ) : null}\n </Columns>\n ) : null}\n </Stack>\n )\n}\n\nexport { BaseField, FieldMessage }\nexport type { BaseFieldVariant, BaseFieldVariantProps, FieldComponentProps }\n"],"names":["fieldToneToTextTone","tone","FieldMessage","id","children","React","Text","as","size","createElement","Box","marginRight","display","className","styles","loadingIcon","Spinner","FieldCharacterCount","validateInputLength","value","maxLength","count","currentLength","String","length","variant","label","auxiliaryLabel","message","maxWidth","hidden","aria-describedby","originalAriaDescribedBy","originalId","useId","messageId","inputLength","characterCount","setCharacterCount","useState","characterCountTone","setCharacterCountTone","ariaDescribedBy","childrenProps","_objectSpread","objectSpread2","aria-invalid","undefined","onChange","event","currentTarget","useEffect","Stack","space","container","error","bordered","justifyContent","alignItems","htmlFor","primaryLabel","paddingLeft","Columns","align","Column","width"],"mappings":"ypBAqBA,SAASA,EAAoBC,GACzB,MAAgB,UAATA,EAAmB,SAAoB,YAATA,EAAqB,WAAa,YAG3E,SAASC,GAAaC,GAAEA,EAAFC,SAAMA,EAANH,KAAgBA,IAClC,OACII,gBAACC,OAAI,CAACC,GAAG,IAAIN,KAAMD,EAAoBC,GAAOO,KAAK,OAAOL,GAAIA,GAChD,YAATF,EACGI,EAACI,cAAAC,EAAAA,IACG,CAAAH,GAAG,OACHI,YAAY,SACZC,QAAQ,aACRC,UAAWC,EAAM,QAACC,aAElBV,EAACI,cAAAO,UAAQ,CAAAR,KAAM,MAEnB,KACHJ,GAUb,SAASa,GAAoBb,SAAEA,EAAFH,KAAYA,IACrC,OACII,EAACI,cAAAH,QAAKL,KAAMD,EAAoBC,GAAOO,KAAK,QACvCJ,GAeb,SAASc,GAAoBC,MACzBA,EADyBC,UAEzBA,IAEA,IAAKA,EACD,MAAO,CACHC,MAAO,KACPpB,KAAM,WAId,MAAMqB,EAAgBC,OAAOJ,GAAS,IAAIK,OAG1C,MAAO,CACHH,MAAUC,EAAL,IAAsBF,EAC3BnB,KAJoBmB,EAAYE,GAnEX,GAuEG,QAAU,6BAkI1C,UAAmBG,QACfA,EAAU,UADKC,MAEfA,EAFeP,MAGfA,EAHeQ,eAIfA,EAJeC,QAKfA,EALe3B,KAMfA,EAAO,UANQY,UAOfA,EAPeT,SAQfA,EAReyB,SASfA,EATeT,UAUfA,EAVeU,OAWfA,EACAC,mBAAoBC,EACpB7B,GAAI8B,IAEJ,MAAM9B,EAAK+B,QAAMD,GACXE,EAAYD,EAAAA,QAEZE,EAAclB,EAAo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YAAY,SAC9ClC,GAEL,MAER,KACHvB,EAASuC,IAEbf,GAAWS,EACRhC,gBAACyD,EAAAA,QAAO,CAACC,MAAM,QAAQV,MAAM,QAAQxB,SAAUA,GAC1CD,EACGvB,gBAAC2D,SAAM,CAACC,MAAM,QACV5D,EAAAI,cAACP,EAAa,CAAAC,GAAIgC,EAAWlC,KAAMA,GAC9B2B,IAGT,KACHS,EACGhC,gBAAC2D,SAAM,CAACC,MAAM,WACV5D,EAACI,cAAAQ,GAAoBhB,KAAMuC,GACtBH,IAGT,MAER"}
1
+ {"version":3,"file":"base-field.js","sources":["../../src/base-field/base-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Box, BoxProps } from '../box'\nimport { useId } from '../utils/common-helpers'\nimport { Text } from '../text'\nimport styles from './base-field.module.css'\nimport { Stack } from '../stack'\n\nimport type { WithEnhancedClassName } from '../utils/common-types'\nimport { Spinner } from '../spinner'\nimport { Column, Columns } from '../columns'\n\n// Define the remaining characters before the character count turns red\n// See: https://twist.com/a/1585/ch/765851/t/6664583/c/93631846 for latest spec\nconst MAX_LENGTH_THRESHOLD = 0\n\ntype FieldTone = 'neutral' | 'success' | 'error' | 'loading'\n\ntype FieldMessageProps = {\n id: string\n children: React.ReactNode\n tone: FieldTone\n}\n\nfunction fieldToneToTextTone(tone: FieldTone) {\n return tone === 'error' ? 'danger' : tone === 'success' ? 'positive' : 'secondary'\n}\n\nfunction FieldMessage({ id, children, tone }: FieldMessageProps) {\n return (\n <Text as=\"p\" tone={fieldToneToTextTone(tone)} size=\"copy\" id={id}>\n {tone === 'loading' ? (\n <Box\n as=\"span\"\n marginRight=\"xsmall\"\n display=\"inlineFlex\"\n className={styles.loadingIcon}\n >\n <Spinner size={16} />\n </Box>\n ) : null}\n {children}\n </Text>\n )\n}\n\ntype FieldCharacterCountProps = {\n children: React.ReactNode\n tone: FieldTone\n}\n\nfunction FieldCharacterCount({ children, tone }: FieldCharacterCountProps) {\n return (\n <Text tone={fieldToneToTextTone(tone)} size=\"copy\">\n {children}\n </Text>\n )\n}\n\ntype ValidateInputLengthProps = {\n value?: React.InputHTMLAttributes<unknown>['value']\n maxLength?: number\n}\n\ntype ValidateInputLengthResult = {\n count: string | null\n tone: FieldTone\n}\n\nfunction validateInputLength({\n value,\n maxLength,\n}: ValidateInputLengthProps): ValidateInputLengthResult {\n if (!maxLength) {\n return {\n count: null,\n tone: 'neutral',\n }\n }\n\n const currentLength = String(value || '').length\n const isNearMaxLength = maxLength - currentLength <= MAX_LENGTH_THRESHOLD\n\n return {\n count: `${currentLength}/${maxLength}`,\n tone: isNearMaxLength ? 'error' : 'neutral',\n }\n}\n\n//\n// BaseField\n//\n\ntype ChildrenRenderProps = {\n id: string\n value?: React.InputHTMLAttributes<unknown>['value']\n 'aria-describedby'?: string\n 'aria-invalid'?: true\n onChange?: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>\n characterCountElement?: React.ReactNode | null\n}\n\ntype HtmlInputProps<T extends HTMLElement> = React.DetailedHTMLProps<\n React.InputHTMLAttributes<T>,\n T\n>\n\ntype BaseFieldVariant = 'default' | 'bordered'\ntype BaseFieldVariantProps = {\n /**\n * Provides alternative visual layouts or modes that the field can be rendered in.\n *\n * Namely, there are two variants supported:\n *\n * - the default one\n * - a \"bordered\" variant, where the border of the field surrounds also the labels, instead\n * of just surrounding the actual field element\n *\n * In both cases, the message and description texts for the field lie outside the bordered\n * area.\n */\n variant?: BaseFieldVariant\n}\n\nexport type BaseFieldProps = WithEnhancedClassName &\n Pick<HtmlInputProps<HTMLInputElement>, 'id' | 'hidden' | 'maxLength' | 'aria-describedby'> & {\n /**\n * The main label for this field element.\n *\n * This prop is not optional. Consumers of field components must be explicit about not\n * wanting a label by passing `label=\"\"` or `label={null}`. In those situations, consumers\n * should make sure that fields are properly labelled semantically by other means (e.g using\n * `aria-labelledby`, or rendering a `<label />` element referencing the field by id).\n *\n * Avoid providing interactive elements in the label. Prefer `auxiliaryLabel` for that.\n *\n * @see BaseFieldProps['auxiliaryLabel']\n */\n label: React.ReactNode\n\n /**\n * The initial value for this field element.\n *\n * This prop is used to calculate the character count for the initial value, and is then\n * passed to the underlying child element.\n */\n value?: React.InputHTMLAttributes<unknown>['value']\n\n /**\n * An optional extra element to be placed to the right of the main label.\n *\n * This extra element is not included in the accessible name of the field element. Its only\n * purpose is either visual, or functional (if you include interactive elements in it).\n *\n * @see BaseFieldProps['label']\n *\n * @deprecated The usage of this element is discouraged given that it was removed from the\n * latest form field spec revision.\n */\n auxiliaryLabel?: React.ReactNode\n\n /**\n * A message associated with the field. It is rendered below the field, and with an\n * appearance that conveys the tone of the field (e.g. coloured red for errors, green for\n * success, etc).\n *\n * The message element is associated to the field via the `aria-describedby` attribute.\n *\n * In the future, when `aria-errormessage` gets better user agent support, we should use it\n * to associate the filed with a message when tone is `\"error\"`.\n *\n * @see BaseFieldProps['tone']\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-errormessage\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-invalid\n */\n message?: React.ReactNode\n\n /**\n * The tone with which the message, if any, is presented.\n *\n * If the tone is `\"error\"`, the field border turns red, and the message, if any, is also\n * red.\n *\n * When the tone is `\"loading\"`, it is recommended that you also disable the field. However,\n * this is not enforced by the component. It is only a recommendation.\n *\n * @see BaseFieldProps['message']\n * @see BaseFieldProps['hint']\n */\n tone?: FieldTone\n\n /**\n * The maximum width that the input field can expand to.\n */\n maxWidth?: BoxProps['maxWidth']\n\n /**\n * The maximum number of characters that the input field can accept.\n * When this limit is reached, the input field will not accept any more characters.\n * The counter element will turn red when the number of characters is within 10 of the maximum limit.\n */\n maxLength?: number\n\n /**\n * Used internally by components composed using `BaseField`. It is not exposed as part of\n * the public props of such components.\n */\n children: (props: ChildrenRenderProps) => React.ReactNode\n\n /**\n * The position of the character count element.\n * It can be shown below the field or inline with the field.\n *\n * @default 'below'\n */\n characterCountPosition?: 'below' | 'inline' | 'hidden'\n }\n\ntype FieldComponentProps<T extends HTMLElement> = Omit<\n BaseFieldProps,\n 'children' | 'className' | 'fieldRef' | 'variant'\n> &\n Omit<HtmlInputProps<T>, 'className' | 'style'>\n\n/**\n * BaseField is a base component that provides a consistent structure for form fields.\n */\nfunction BaseField({\n variant = 'default',\n label,\n value,\n auxiliaryLabel,\n message,\n tone = 'neutral',\n className,\n children,\n maxWidth,\n maxLength,\n hidden,\n 'aria-describedby': originalAriaDescribedBy,\n id: originalId,\n characterCountPosition = 'below',\n}: BaseFieldProps & BaseFieldVariantProps & WithEnhancedClassName) {\n const id = useId(originalId)\n const messageId = useId()\n\n const inputLength = validateInputLength({ value, maxLength })\n\n const [characterCount, setCharacterCount] = React.useState<string | null>(inputLength.count)\n const [characterCountTone, setCharacterCountTone] = React.useState<FieldTone>(inputLength.tone)\n\n const ariaDescribedBy = originalAriaDescribedBy ?? (message ? messageId : null)\n\n /**\n * Renders the character count element.\n * If the characterCountPosition value is 'hidden', it returns null.\n */\n function renderCharacterCount() {\n return characterCountPosition !== 'hidden' ? (\n <FieldCharacterCount tone={characterCountTone}>{characterCount}</FieldCharacterCount>\n ) : null\n }\n\n const childrenProps: ChildrenRenderProps = {\n id,\n value,\n ...(ariaDescribedBy ? { 'aria-describedby': ariaDescribedBy } : {}),\n 'aria-invalid': tone === 'error' ? true : undefined,\n onChange(event) {\n if (!maxLength) {\n return\n }\n\n const inputLength = validateInputLength({\n value: event.currentTarget.value,\n maxLength,\n })\n\n setCharacterCount(inputLength.count)\n setCharacterCountTone(inputLength.tone)\n },\n // If the character count is inline, we pass it as a prop to the children element so it can be rendered inline\n characterCountElement: characterCountPosition === 'inline' ? renderCharacterCount() : null,\n }\n\n React.useEffect(\n function updateCharacterCountOnPropChange() {\n if (!maxLength) {\n return\n }\n\n const inputLength = validateInputLength({\n value,\n maxLength,\n })\n\n setCharacterCount(inputLength.count)\n setCharacterCountTone(inputLength.tone)\n },\n [maxLength, value],\n )\n\n return (\n <Stack space=\"xsmall\" hidden={hidden}>\n <Box\n className={[\n className,\n styles.container,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n ]}\n maxWidth={maxWidth}\n >\n {label || auxiliaryLabel ? (\n <Box\n as=\"span\"\n display=\"flex\"\n justifyContent=\"spaceBetween\"\n alignItems=\"flexEnd\"\n >\n <Text\n size={variant === 'bordered' ? 'caption' : 'body'}\n as=\"label\"\n htmlFor={id}\n >\n {label ? <span className={styles.primaryLabel}>{label}</span> : null}\n </Text>\n {auxiliaryLabel ? (\n <Box className={styles.auxiliaryLabel} paddingLeft=\"small\">\n {auxiliaryLabel}\n </Box>\n ) : null}\n </Box>\n ) : null}\n {children(childrenProps)}\n </Box>\n\n {message || characterCount ? (\n <Columns align=\"right\" space=\"small\" maxWidth={maxWidth}>\n {message ? (\n <Column width=\"auto\">\n <FieldMessage id={messageId} tone={tone}>\n {message}\n </FieldMessage>\n </Column>\n ) : null}\n\n {/* If the character count is below the field, we render it, if it's inline,\n we pass it as a prop to the children element so it can be rendered inline */}\n {characterCountPosition === 'below' ? (\n <Column width=\"content\">{renderCharacterCount()}</Column>\n ) : null}\n </Columns>\n ) : null}\n </Stack>\n )\n}\n\nexport { BaseField, FieldMessage }\nexport type { BaseFieldVariant, BaseFieldVariantProps, FieldComponentProps }\n"],"names":["fieldToneToTextTone","tone","FieldMessage","id","children","React","Text","as","size","createElement","Box","marginRight","display","className","styles","loadingIcon","Spinner","FieldCharacterCount","validateInputLength","value","maxLength","count","currentLength","String","length","variant","label","auxiliaryLabel","message","maxWidth","hidden","aria-describedby","originalAriaDescribedBy","originalId","characterCountPosition","useId","messageId","inputLength","characterCount","setCharacterCount","useState","characterCountTone","setCharacterCountTone","ariaDescribedBy","renderCharacterCount","childrenProps","_objectSpread","objectSpread2","aria-invalid","undefined","onChange","event","currentTarget","characterCountElement","useEffect","Stack","space","container","error","bordered","justifyContent","alignItems","htmlFor","primaryLabel","paddingLeft","Columns","align","Column","width"],"mappings":"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C4D,EAAAA,QAAO,CAACC,MAAM,QAAQV,MAAM,QAAQ3B,SAAUA,GAC1CD,EACGvB,gBAAC8D,SAAM,CAACC,MAAM,QACV/D,EAAAI,cAACP,EAAa,CAAAC,GAAIiC,EAAWnC,KAAMA,GAC9B2B,IAGT,KAIwB,UAA3BM,EACG7B,EAACI,cAAA0D,SAAO,CAAAC,MAAM,WAAWxB,KACzB,MAER"}
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { BaseFieldVariantProps, FieldComponentProps } from '../base-field';
3
- interface SelectFieldProps extends FieldComponentProps<HTMLSelectElement>, BaseFieldVariantProps {
3
+ interface SelectFieldProps extends Omit<FieldComponentProps<HTMLSelectElement>, 'maxLength' | 'characterCountPosition'>, BaseFieldVariantProps {
4
4
  }
5
5
  declare const SelectField: React.ForwardRefExoticComponent<Omit<SelectFieldProps, "ref"> & React.RefAttributes<HTMLSelectElement>>;
6
6
  export { SelectField };
@@ -1 +1 @@
1
- {"version":3,"file":"select-field.js","sources":["../../src/select-field/select-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { BaseField, BaseFieldVariantProps, FieldComponentProps } from '../base-field'\nimport { Box } from '../box'\nimport styles from './select-field.module.css'\n\ninterface SelectFieldProps extends FieldComponentProps<HTMLSelectElement>, BaseFieldVariantProps {}\n\nconst SelectField = React.forwardRef<HTMLSelectElement, SelectFieldProps>(function SelectField(\n {\n variant = 'default',\n id,\n label,\n value,\n auxiliaryLabel,\n message,\n tone,\n maxWidth,\n children,\n hidden,\n 'aria-describedby': ariaDescribedBy,\n onChange: originalOnChange,\n ...props\n },\n ref,\n) {\n return (\n <BaseField\n variant={variant}\n id={id}\n label={label}\n value={value}\n auxiliaryLabel={auxiliaryLabel}\n message={message}\n tone={tone}\n maxWidth={maxWidth}\n hidden={hidden}\n aria-describedby={ariaDescribedBy}\n >\n {(extraProps) => (\n <Box\n data-testid=\"select-wrapper\"\n className={[\n styles.selectWrapper,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n ]}\n >\n <select\n {...props}\n {...extraProps}\n ref={ref}\n onChange={(event) => {\n originalOnChange?.(event)\n }}\n >\n {children}\n </select>\n <SelectChevron aria-hidden />\n </Box>\n )}\n </BaseField>\n )\n})\n\nfunction SelectChevron(props: JSX.IntrinsicElements['svg']) {\n return (\n <svg width=\"16\" height=\"16\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" {...props}>\n <path\n d=\"M11.646 5.646a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 1 1 .708-.708L8 9.293l3.646-3.647z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n}\n\nexport { SelectField }\nexport type { SelectFieldProps }\n"],"names":["SelectChevron","props","React","createElement","_objectSpread","width","height","fill","xmlns","d","forwardRef","ref","variant","id","label","value","auxiliaryLabel","message","tone","maxWidth","children","hidden","aria-describedby","ariaDescribedBy","onChange","originalOnChange","_ref","_objectWithoutProperties","objectWithoutProperties","_excluded","BaseField","extraProps","Box","data-testid","className","styles","selectWrapper","error","bordered","objectSpread2","event","aria-hidden"],"mappings":"kqBAgEA,SAASA,EAAcC,GACnB,OACIC,EAAKC,cAAA,MAALC,gBAAA,CAAKC,MAAM,KAAKC,OAAO,KAAKC,KAAK,OAAOC,MAAM,8BAAiCP,GAC3EC,EACIC,cAAA,OAAA,CAAAM,EAAE,0GACFF,KAAK,sCA9DDL,EAAMQ,YAAgD,SAgBtEC,EAAAA,GAAG,IAfHC,QACIA,EAAU,UADdC,GAEIA,EAFJC,MAGIA,EAHJC,MAIIA,EAJJC,eAKIA,EALJC,QAMIA,EANJC,KAOIA,EAPJC,SAQIA,EARJC,SASIA,EATJC,OAUIA,EACAC,mBAAoBC,EACpBC,SAAUC,GAGXC,EAFIzB,EAEJ0B,EAAAC,wBAAAF,EAAAG,GAEH,OACI3B,EAACC,cAAA2B,YACG,CAAAlB,QAASA,EACTC,GAAIA,EACJC,MAAOA,EACPC,MAAOA,EACPC,eAAgBA,EAChBC,QAASA,EACTC,KAAMA,EACNC,SAAUA,EACVE,OAAQA,EACUC,mBAAAC,GAEhBQ,GACE7B,EAACC,cAAA6B,MACe,CAAAC,cAAA,iBACZC,UAAW,CACPC,EAAM,QAACC,cACE,UAATlB,EAAmBiB,EAAM,QAACE,MAAQ,KACtB,aAAZzB,EAAyBuB,EAAAA,QAAOG,SAAW,OAG/CpC,EAAAC,cAAA,SAAAC,EAAAmC,cAAAnC,EAAAmC,cAAAnC,gBAAA,GACQH,GACA8B,GAFR,GAAA,CAGIpB,IAAKA,EACLa,SAAWgB,IACP,MAAAf,GAAAA,EAAmBe,MAGtBpB,GAELlB,EAAAC,cAACH,EAA4B,CAAAyC,eAAA"}
1
+ {"version":3,"file":"select-field.js","sources":["../../src/select-field/select-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { BaseField, BaseFieldVariantProps, FieldComponentProps } from '../base-field'\nimport { Box } from '../box'\nimport styles from './select-field.module.css'\n\ninterface SelectFieldProps\n extends Omit<FieldComponentProps<HTMLSelectElement>, 'maxLength' | 'characterCountPosition'>,\n BaseFieldVariantProps {}\n\nconst SelectField = React.forwardRef<HTMLSelectElement, SelectFieldProps>(function SelectField(\n {\n variant = 'default',\n id,\n label,\n value,\n auxiliaryLabel,\n message,\n tone,\n maxWidth,\n children,\n hidden,\n 'aria-describedby': ariaDescribedBy,\n onChange: originalOnChange,\n ...props\n },\n ref,\n) {\n return (\n <BaseField\n variant={variant}\n id={id}\n label={label}\n value={value}\n auxiliaryLabel={auxiliaryLabel}\n message={message}\n tone={tone}\n maxWidth={maxWidth}\n hidden={hidden}\n aria-describedby={ariaDescribedBy}\n >\n {(extraProps) => (\n <Box\n data-testid=\"select-wrapper\"\n className={[\n styles.selectWrapper,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n ]}\n >\n <select\n {...props}\n {...extraProps}\n ref={ref}\n onChange={(event) => {\n originalOnChange?.(event)\n }}\n >\n {children}\n </select>\n <SelectChevron aria-hidden />\n </Box>\n )}\n </BaseField>\n )\n})\n\nfunction SelectChevron(props: JSX.IntrinsicElements['svg']) {\n return (\n <svg width=\"16\" height=\"16\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" {...props}>\n <path\n d=\"M11.646 5.646a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 1 1 .708-.708L8 9.293l3.646-3.647z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n}\n\nexport { SelectField }\nexport type { SelectFieldProps }\n"],"names":["SelectChevron","props","React","createElement","_objectSpread","width","height","fill","xmlns","d","forwardRef","ref","variant","id","label","value","auxiliaryLabel","message","tone","maxWidth","children","hidden","aria-describedby","ariaDescribedBy","onChange","originalOnChange","_ref","_objectWithoutProperties","objectWithoutProperties","_excluded","BaseField","extraProps","Box","data-testid","className","styles","selectWrapper","error","bordered","objectSpread2","event","aria-hidden"],"mappings":"kqBAkEA,SAASA,EAAcC,GACnB,OACIC,EAAKC,cAAA,MAALC,gBAAA,CAAKC,MAAM,KAAKC,OAAO,KAAKC,KAAK,OAAOC,MAAM,8BAAiCP,GAC3EC,EACIC,cAAA,OAAA,CAAAM,EAAE,0GACFF,KAAK,sCA9DDL,EAAMQ,YAAgD,SAgBtEC,EAAAA,GAAG,IAfHC,QACIA,EAAU,UADdC,GAEIA,EAFJC,MAGIA,EAHJC,MAIIA,EAJJC,eAKIA,EALJC,QAMIA,EANJC,KAOIA,EAPJC,SAQIA,EARJC,SASIA,EATJC,OAUIA,EACAC,mBAAoBC,EACpBC,SAAUC,GAGXC,EAFIzB,EAEJ0B,EAAAC,wBAAAF,EAAAG,GAEH,OACI3B,EAACC,cAAA2B,YACG,CAAAlB,QAASA,EACTC,GAAIA,EACJC,MAAOA,EACPC,MAAOA,EACPC,eAAgBA,EAChBC,QAASA,EACTC,KAAMA,EACNC,SAAUA,EACVE,OAAQA,EACUC,mBAAAC,GAEhBQ,GACE7B,EAACC,cAAA6B,MACe,CAAAC,cAAA,iBACZC,UAAW,CACPC,EAAM,QAACC,cACE,UAATlB,EAAmBiB,EAAM,QAACE,MAAQ,KACtB,aAAZzB,EAAyBuB,EAAAA,QAAOG,SAAW,OAG/CpC,EAAAC,cAAA,SAAAC,EAAAmC,cAAAnC,EAAAmC,cAAAnC,gBAAA,GACQH,GACA8B,GAFR,GAAA,CAGIpB,IAAKA,EACLa,SAAWgB,IACP,MAAAf,GAAAA,EAAmBe,MAGtBpB,GAELlB,EAAAC,cAACH,EAA4B,CAAAyC,eAAA"}
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { BaseFieldVariantProps } from '../base-field';
3
- import type { FieldComponentProps } from '../base-field';
3
+ import type { BaseFieldProps, FieldComponentProps } from '../base-field';
4
4
  type TextFieldType = 'email' | 'search' | 'tel' | 'text' | 'url';
5
- interface TextFieldProps extends Omit<FieldComponentProps<HTMLInputElement>, 'type'>, BaseFieldVariantProps {
5
+ interface TextFieldProps extends Omit<FieldComponentProps<HTMLInputElement>, 'type'>, BaseFieldVariantProps, Pick<BaseFieldProps, 'characterCountPosition'> {
6
6
  type?: TextFieldType;
7
7
  startSlot?: React.ReactElement | string | number;
8
8
  endSlot?: React.ReactElement | string | number;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../base-field/base-field.js"),a=require("../box/box.js"),l=require("./text-field.module.css.js"),n=require("use-callback-ref");function i(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,r}var u=i(r);const d=["variant","id","label","value","auxiliaryLabel","message","tone","type","maxWidth","maxLength","hidden","aria-describedby","startSlot","endSlot","onChange"],s=["onChange"];exports.TextField=u.forwardRef((function(r,i){let{variant:o="default",id:c,label:b,value:f,auxiliaryLabel:m,message:x,tone:g,type:p="text",maxWidth:h,maxLength:y,hidden:j,"aria-describedby":v,startSlot:L,endSlot:O,onChange:S}=r,q=e.objectWithoutProperties(r,d);const C=u.useRef(null),E=n.useMergeRefs([i,C]);function P(e){var r;e.currentTarget!==E.current&&(null==(r=C.current)||r.focus())}return u.createElement(t.BaseField,{variant:o,id:c,label:b,value:f,auxiliaryLabel:m,message:x,tone:g,maxWidth:h,maxLength:y,hidden:j,"aria-describedby":v},r=>{let{onChange:t}=r,n=e.objectWithoutProperties(r,s);return u.createElement(a.Box,{display:"flex",alignItems:"center",className:[l.default.inputWrapper,"error"===g?l.default.error:null,"bordered"===o?l.default.bordered:null,q.readOnly?l.default.readOnly:null],onClick:P},L?u.createElement(a.Box,{className:l.default.slot,display:"flex",marginRight:"bordered"===o?"xsmall":"-xsmall",marginLeft:"bordered"===o?"-xsmall":"xsmall"},L):null,u.createElement("input",e.objectSpread2(e.objectSpread2(e.objectSpread2({},q),n),{},{type:p,ref:E,maxLength:y,onChange:e=>{null==S||S(e),null==t||t(e)}})),O?u.createElement(a.Box,{className:l.default.slot,display:"flex",marginRight:"bordered"===o?"-xsmall":"xsmall",marginLeft:"bordered"===o?"xsmall":"-xsmall"},O):null)})}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_rollupPluginBabelHelpers.js"),t=require("react"),r=require("../base-field/base-field.js"),a=require("../box/box.js"),l=require("./text-field.module.css.js"),n=require("use-callback-ref");function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,t}var o=i(t);const u=["variant","id","label","value","auxiliaryLabel","message","tone","type","maxWidth","maxLength","hidden","aria-describedby","startSlot","endSlot","onChange","characterCountPosition"],s=["onChange","characterCountElement"];exports.TextField=o.forwardRef((function(t,i){let{variant:d="default",id:c,label:b,value:m,auxiliaryLabel:f,message:x,tone:g,type:h="text",maxWidth:p,maxLength:y,hidden:j,"aria-describedby":v,startSlot:C,endSlot:L,onChange:P,characterCountPosition:E="below"}=t,O=e.objectWithoutProperties(t,u);const S=o.useRef(null),q=n.useMergeRefs([i,S]);function W(e){var t;e.currentTarget!==q.current&&(null==(t=S.current)||t.focus())}return o.createElement(r.BaseField,{variant:d,id:c,label:b,value:m,auxiliaryLabel:f,message:x,tone:g,maxWidth:p,maxLength:y,hidden:j,"aria-describedby":v,characterCountPosition:E},t=>{let{onChange:r,characterCountElement:n}=t,i=e.objectWithoutProperties(t,s);return o.createElement(a.Box,{display:"flex",alignItems:"center",className:[l.default.inputWrapper,"error"===g?l.default.error:null,"bordered"===d?l.default.bordered:null,O.readOnly?l.default.readOnly:null],onClick:W},C?o.createElement(a.Box,{className:l.default.slot,display:"flex",marginRight:"bordered"===d?"xsmall":"-xsmall",marginLeft:"bordered"===d?"-xsmall":"xsmall"},C):null,o.createElement("input",e.objectSpread2(e.objectSpread2(e.objectSpread2({},O),i),{},{type:h,ref:q,maxLength:y,onChange:e=>{null==P||P(e),null==r||r(e)}})),L||n?o.createElement(a.Box,{className:l.default.slot,display:"flex",marginRight:"bordered"===d?"-xsmall":"xsmall",marginLeft:"bordered"===d?"xsmall":"-xsmall"},n,L):null)})}));
2
2
  //# sourceMappingURL=text-field.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"text-field.js","sources":["../../src/text-field/text-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { BaseField, BaseFieldVariantProps } from '../base-field'\nimport { Box } from '../box'\nimport styles from './text-field.module.css'\nimport type { FieldComponentProps } from '../base-field'\nimport { useMergeRefs } from 'use-callback-ref'\n\ntype TextFieldType = 'email' | 'search' | 'tel' | 'text' | 'url'\n\ninterface TextFieldProps\n extends Omit<FieldComponentProps<HTMLInputElement>, 'type'>,\n BaseFieldVariantProps {\n type?: TextFieldType\n startSlot?: React.ReactElement | string | number\n endSlot?: React.ReactElement | string | number\n /**\n * The maximum number of characters that the input field can accept.\n * When this limit is reached, the input field will not accept any more characters.\n * The counter element will turn red when the number of characters is within 10 of the maximum limit.\n */\n maxLength?: number\n}\n\nconst TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(function TextField(\n {\n variant = 'default',\n id,\n label,\n value,\n auxiliaryLabel,\n message,\n tone,\n type = 'text',\n maxWidth,\n maxLength,\n hidden,\n 'aria-describedby': ariaDescribedBy,\n startSlot,\n endSlot,\n onChange: originalOnChange,\n ...props\n },\n ref,\n) {\n const internalRef = React.useRef<HTMLInputElement>(null)\n const combinedRef = useMergeRefs([ref, internalRef])\n\n function handleClick(event: React.MouseEvent) {\n if (event.currentTarget === combinedRef.current) return\n internalRef.current?.focus()\n }\n\n return (\n <BaseField\n variant={variant}\n id={id}\n label={label}\n value={value}\n auxiliaryLabel={auxiliaryLabel}\n message={message}\n tone={tone}\n maxWidth={maxWidth}\n maxLength={maxLength}\n hidden={hidden}\n aria-describedby={ariaDescribedBy}\n >\n {({ onChange, ...extraProps }) => (\n <Box\n display=\"flex\"\n alignItems=\"center\"\n className={[\n styles.inputWrapper,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n props.readOnly ? styles.readOnly : null,\n ]}\n onClick={handleClick}\n >\n {startSlot ? (\n <Box\n className={styles.slot}\n display=\"flex\"\n marginRight={variant === 'bordered' ? 'xsmall' : '-xsmall'}\n marginLeft={variant === 'bordered' ? '-xsmall' : 'xsmall'}\n >\n {startSlot}\n </Box>\n ) : null}\n <input\n {...props}\n {...extraProps}\n type={type}\n ref={combinedRef}\n maxLength={maxLength}\n onChange={(event) => {\n originalOnChange?.(event)\n onChange?.(event)\n }}\n />\n {endSlot ? (\n <Box\n className={styles.slot}\n display=\"flex\"\n marginRight={variant === 'bordered' ? '-xsmall' : 'xsmall'}\n marginLeft={variant === 'bordered' ? 'xsmall' : '-xsmall'}\n >\n {endSlot}\n </Box>\n ) : null}\n </Box>\n )}\n </BaseField>\n )\n})\n\nexport { TextField }\nexport type { TextFieldProps, TextFieldType }\n"],"names":["React","forwardRef","ref","variant","id","label","value","auxiliaryLabel","message","tone","type","maxWidth","maxLength","hidden","aria-describedby","ariaDescribedBy","startSlot","endSlot","onChange","originalOnChange","_ref","props","_objectWithoutProperties","objectWithoutProperties","_excluded","internalRef","useRef","combinedRef","useMergeRefs","handleClick","event","_internalRef$current","currentTarget","current","focus","createElement","BaseField","_ref2","extraProps","_excluded2","Box","display","alignItems","className","styles","inputWrapper","error","bordered","readOnly","onClick","slot","marginRight","marginLeft"],"mappings":"6vBAuBkBA,EAAMC,YAA6C,SAmBjEC,EAAAA,GAAG,IAlBHC,QACIA,EAAU,UADdC,GAEIA,EAFJC,MAGIA,EAHJC,MAIIA,EAJJC,eAKIA,EALJC,QAMIA,EANJC,KAOIA,EAPJC,KAQIA,EAAO,OARXC,SASIA,EATJC,UAUIA,EAVJC,OAWIA,EACAC,mBAAoBC,EAZxBC,UAaIA,EAbJC,QAcIA,EACAC,SAAUC,GAGXC,EAFIC,EAEJC,EAAAC,wBAAAH,EAAAI,GAEH,MAAMC,EAAczB,EAAM0B,OAAyB,MAC7CC,EAAcC,EAAYA,aAAC,CAAC1B,EAAKuB,IAEvC,SAASI,EAAYC,GAAuB,IAAAC,EACpCD,EAAME,gBAAkBL,EAAYM,UACxC,OAAAF,EAAAN,EAAYQ,UAAZF,EAAqBG,SAGzB,OACIlC,EAAAmC,cAACC,YAAS,CACNjC,QAASA,EACTC,GAAIA,EACJC,MAAOA,EACPC,MAAOA,EACPC,eAAgBA,EAChBC,QAASA,EACTC,KAAMA,EACNE,SAAUA,EACVC,UAAWA,EACXC,OAAQA,EACUC,mBAAAC,GAEjBsB,IAAA,IAACnB,SAAEA,GAAHmB,EAAgBC,EAAhBhB,EAAAC,wBAAAc,EAAAE,GAAA,OACGvC,EAAAmC,cAACK,MACG,CAAAC,QAAQ,OACRC,WAAW,SACXC,UAAW,CACPC,EAAM,QAACC,aACE,UAATpC,EAAmBmC,EAAM,QAACE,MAAQ,KACtB,aAAZ3C,EAAyByC,EAAM,QAACG,SAAW,KAC3C1B,EAAM2B,SAAWJ,EAAM,QAACI,SAAW,MAEvCC,QAASpB,GAERb,EACGhB,gBAACwC,MAAG,CACAG,UAAWC,EAAM,QAACM,KAClBT,QAAQ,OACRU,YAAyB,aAAZhD,EAAyB,SAAW,UACjDiD,WAAwB,aAAZjD,EAAyB,UAAY,UAEhDa,GAEL,KACJhB,EACQmC,cAAA,QAAAd,EAAAA,cAAAA,EAAAA,cAAAA,EAAAA,cAAAA,GAAAA,GACAiB,GAFR,GAAA,CAGI5B,KAAMA,EACNR,IAAKyB,EACLf,UAAWA,EACXM,SAAWY,IACP,MAAAX,GAAAA,EAAmBW,GACnB,MAAAZ,GAAAA,EAAWY,OAGlBb,EACGjB,EAAAmC,cAACK,EAAAA,IAAG,CACAG,UAAWC,EAAM,QAACM,KAClBT,QAAQ,OACRU,YAAyB,aAAZhD,EAAyB,UAAY,SAClDiD,WAAwB,aAAZjD,EAAyB,SAAW,WAE/Cc,GAEL"}
1
+ {"version":3,"file":"text-field.js","sources":["../../src/text-field/text-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { BaseField, BaseFieldVariantProps } from '../base-field'\nimport { Box } from '../box'\nimport styles from './text-field.module.css'\nimport type { BaseFieldProps, FieldComponentProps } from '../base-field'\nimport { useMergeRefs } from 'use-callback-ref'\n\ntype TextFieldType = 'email' | 'search' | 'tel' | 'text' | 'url'\n\ninterface TextFieldProps\n extends Omit<FieldComponentProps<HTMLInputElement>, 'type'>,\n BaseFieldVariantProps,\n Pick<BaseFieldProps, 'characterCountPosition'> {\n type?: TextFieldType\n startSlot?: React.ReactElement | string | number\n endSlot?: React.ReactElement | string | number\n /**\n * The maximum number of characters that the input field can accept.\n * When this limit is reached, the input field will not accept any more characters.\n * The counter element will turn red when the number of characters is within 10 of the maximum limit.\n */\n maxLength?: number\n}\n\nconst TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(function TextField(\n {\n variant = 'default',\n id,\n label,\n value,\n auxiliaryLabel,\n message,\n tone,\n type = 'text',\n maxWidth,\n maxLength,\n hidden,\n 'aria-describedby': ariaDescribedBy,\n startSlot,\n endSlot,\n onChange: originalOnChange,\n characterCountPosition = 'below',\n ...props\n },\n ref,\n) {\n const internalRef = React.useRef<HTMLInputElement>(null)\n const combinedRef = useMergeRefs([ref, internalRef])\n\n function handleClick(event: React.MouseEvent) {\n if (event.currentTarget === combinedRef.current) return\n internalRef.current?.focus()\n }\n\n return (\n <BaseField\n variant={variant}\n id={id}\n label={label}\n value={value}\n auxiliaryLabel={auxiliaryLabel}\n message={message}\n tone={tone}\n maxWidth={maxWidth}\n maxLength={maxLength}\n hidden={hidden}\n aria-describedby={ariaDescribedBy}\n characterCountPosition={characterCountPosition}\n >\n {({ onChange, characterCountElement, ...extraProps }) => (\n <Box\n display=\"flex\"\n alignItems=\"center\"\n className={[\n styles.inputWrapper,\n tone === 'error' ? styles.error : null,\n variant === 'bordered' ? styles.bordered : null,\n props.readOnly ? styles.readOnly : null,\n ]}\n onClick={handleClick}\n >\n {startSlot ? (\n <Box\n className={styles.slot}\n display=\"flex\"\n marginRight={variant === 'bordered' ? 'xsmall' : '-xsmall'}\n marginLeft={variant === 'bordered' ? '-xsmall' : 'xsmall'}\n >\n {startSlot}\n </Box>\n ) : null}\n <input\n {...props}\n {...extraProps}\n type={type}\n ref={combinedRef}\n maxLength={maxLength}\n onChange={(event) => {\n originalOnChange?.(event)\n onChange?.(event)\n }}\n />\n {endSlot || characterCountElement ? (\n <Box\n className={styles.slot}\n display=\"flex\"\n marginRight={variant === 'bordered' ? '-xsmall' : 'xsmall'}\n marginLeft={variant === 'bordered' ? 'xsmall' : '-xsmall'}\n >\n {characterCountElement}\n {endSlot}\n </Box>\n ) : null}\n </Box>\n )}\n </BaseField>\n )\n})\n\nexport { TextField }\nexport type { TextFieldProps, TextFieldType }\n"],"names":["React","forwardRef","ref","variant","id","label","value","auxiliaryLabel","message","tone","type","maxWidth","maxLength","hidden","aria-describedby","ariaDescribedBy","startSlot","endSlot","onChange","originalOnChange","characterCountPosition","_ref","props","_objectWithoutProperties","objectWithoutProperties","_excluded","internalRef","useRef","combinedRef","useMergeRefs","handleClick","event","_internalRef$current","currentTarget","current","focus","createElement","BaseField","_ref2","characterCountElement","extraProps","_excluded2","Box","display","alignItems","className","styles","inputWrapper","error","bordered","readOnly","onClick","slot","marginRight","marginLeft"],"mappings":"8yBAwBkBA,EAAMC,YAA6C,SAoBjEC,EAAAA,GAAG,IAnBHC,QACIA,EAAU,UADdC,GAEIA,EAFJC,MAGIA,EAHJC,MAIIA,EAJJC,eAKIA,EALJC,QAMIA,EANJC,KAOIA,EAPJC,KAQIA,EAAO,OARXC,SASIA,EATJC,UAUIA,EAVJC,OAWIA,EACAC,mBAAoBC,EAZxBC,UAaIA,EAbJC,QAcIA,EACAC,SAAUC,EAfdC,uBAgBIA,EAAyB,SAG1BC,EAFIC,EAEJC,EAAAC,wBAAAH,EAAAI,GAEH,MAAMC,EAAc1B,EAAM2B,OAAyB,MAC7CC,EAAcC,EAAYA,aAAC,CAAC3B,EAAKwB,IAEvC,SAASI,EAAYC,GAAuB,IAAAC,EACpCD,EAAME,gBAAkBL,EAAYM,UACxC,OAAAF,EAAAN,EAAYQ,UAAZF,EAAqBG,SAGzB,OACInC,EAAAoC,cAACC,YAAS,CACNlC,QAASA,EACTC,GAAIA,EACJC,MAAOA,EACPC,MAAOA,EACPC,eAAgBA,EAChBC,QAASA,EACTC,KAAMA,EACNE,SAAUA,EACVC,UAAWA,EACXC,OAAQA,EAAMC,mBACIC,EAClBK,uBAAwBA,GAEvBkB,IAAA,IAACpB,SAAEA,EAAFqB,sBAAYA,GAAbD,EAAuCE,EAAvCjB,EAAAC,wBAAAc,EAAAG,GAAA,OACGzC,EAAAoC,cAACM,MACG,CAAAC,QAAQ,OACRC,WAAW,SACXC,UAAW,CACPC,EAAM,QAACC,aACE,UAATtC,EAAmBqC,EAAM,QAACE,MAAQ,KACtB,aAAZ7C,EAAyB2C,EAAM,QAACG,SAAW,KAC3C3B,EAAM4B,SAAWJ,EAAM,QAACI,SAAW,MAEvCC,QAASrB,GAERd,EACGhB,gBAAC0C,MAAG,CACAG,UAAWC,EAAM,QAACM,KAClBT,QAAQ,OACRU,YAAyB,aAAZlD,EAAyB,SAAW,UACjDmD,WAAwB,aAAZnD,EAAyB,UAAY,UAEhDa,GAEL,KACJhB,EACQoC,cAAA,QAAAd,EAAAA,cAAAA,EAAAA,cAAAA,EAAAA,cAAAA,GAAAA,GACAkB,GAFR,GAAA,CAGI9B,KAAMA,EACNR,IAAK0B,EACLhB,UAAWA,EACXM,SAAWa,IACP,MAAAZ,GAAAA,EAAmBY,GACnB,MAAAb,GAAAA,EAAWa,OAGlBd,GAAWsB,EACRvC,EAAAoC,cAACM,EAAAA,IACG,CAAAG,UAAWC,EAAM,QAACM,KAClBT,QAAQ,OACRU,YAAyB,aAAZlD,EAAyB,UAAY,SAClDmD,WAAwB,aAAZnD,EAAyB,SAAW,WAE/CoC,EACAtB,GAEL"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default={inputWrapper:"f2de4e8d",readOnly:"ee26e40c",bordered:"_3afb1a56",error:"f3ff9f57",slot:"_3eb7b0ef"};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default={inputWrapper:"c8f65b3b",readOnly:"_326f2644",bordered:"_5252fd3d",error:"_0141b7ac",slot:"b79b851f"};
2
2
  //# sourceMappingURL=text-field.module.css.js.map
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "email": "henning@doist.com",
7
7
  "url": "http://doist.com"
8
8
  },
9
- "version": "27.2.2",
9
+ "version": "27.3.5",
10
10
  "license": "MIT",
11
11
  "homepage": "https://github.com/Doist/reactist#readme",
12
12
  "repository": {