@transferwise/components 0.0.0-experimental-a7b7094 → 0.0.0-experimental-580125e

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.
Files changed (54) hide show
  1. package/build/field/Field.js +32 -63
  2. package/build/field/Field.js.map +1 -1
  3. package/build/field/Field.mjs +34 -65
  4. package/build/field/Field.mjs.map +1 -1
  5. package/build/i18n/en.json +0 -1
  6. package/build/i18n/en.json.js +0 -1
  7. package/build/i18n/en.json.js.map +1 -1
  8. package/build/i18n/en.json.mjs +0 -1
  9. package/build/i18n/en.json.mjs.map +1 -1
  10. package/build/inputs/TextArea.js +0 -25
  11. package/build/inputs/TextArea.js.map +1 -1
  12. package/build/inputs/TextArea.mjs +2 -27
  13. package/build/inputs/TextArea.mjs.map +1 -1
  14. package/build/inputs/contexts.js +0 -16
  15. package/build/inputs/contexts.js.map +1 -1
  16. package/build/inputs/contexts.mjs +2 -16
  17. package/build/inputs/contexts.mjs.map +1 -1
  18. package/build/main.css +3 -21
  19. package/build/popover/Popover.js +9 -12
  20. package/build/popover/Popover.js.map +1 -1
  21. package/build/popover/Popover.mjs +9 -12
  22. package/build/popover/Popover.mjs.map +1 -1
  23. package/build/styles/field/Field.css +3 -19
  24. package/build/styles/main.css +3 -21
  25. package/build/types/field/Field.d.ts.map +1 -1
  26. package/build/types/inputs/TextArea.d.ts.map +1 -1
  27. package/build/types/inputs/contexts.d.ts +0 -6
  28. package/build/types/inputs/contexts.d.ts.map +1 -1
  29. package/build/types/popover/Popover.d.ts.map +1 -1
  30. package/build/types/test-utils/index.d.ts +0 -2
  31. package/build/types/test-utils/index.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/src/field/Field.css +3 -19
  34. package/src/field/Field.less +3 -17
  35. package/src/field/Field.story.tsx +1 -5
  36. package/src/field/Field.test.tsx +0 -90
  37. package/src/field/Field.tsx +37 -84
  38. package/src/i18n/en.json +0 -1
  39. package/src/inputs/TextArea.tsx +3 -34
  40. package/src/inputs/contexts.tsx +1 -18
  41. package/src/main.css +3 -21
  42. package/src/popover/Popover.story.tsx +45 -0
  43. package/src/popover/Popover.test.story.tsx +63 -0
  44. package/src/popover/Popover.test.tsx +56 -0
  45. package/src/popover/Popover.tsx +10 -12
  46. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +0 -1
  47. package/build/field/Field.messages.js +0 -14
  48. package/build/field/Field.messages.js.map +0 -1
  49. package/build/field/Field.messages.mjs +0 -10
  50. package/build/field/Field.messages.mjs.map +0 -1
  51. package/build/types/field/Field.messages.d.ts +0 -8
  52. package/build/types/field/Field.messages.d.ts.map +0 -1
  53. package/src/field/Field.messages.ts +0 -8
  54. package/src/inputs/TextArea.story.tsx +0 -56
@@ -2,8 +2,6 @@
2
2
 
3
3
  var clsx = require('clsx');
4
4
  var React = require('react');
5
- var reactIntl = require('react-intl');
6
- var Body = require('../body/Body.js');
7
5
  require('../common/theme.js');
8
6
  require('../common/direction.js');
9
7
  require('../common/propsValues/control.js');
@@ -25,10 +23,11 @@ require('../common/propsValues/markdownNodeType.js');
25
23
  require('../common/fileType.js');
26
24
  require('@transferwise/formatting');
27
25
  require('@transferwise/icons');
26
+ require('react-intl');
28
27
  require('../common/closeButton/CloseButton.messages.js');
29
28
  var jsxRuntime = require('react/jsx-runtime');
30
- var Field_messages = require('./Field.messages.js');
31
29
  var InlinePrompt = require('../prompt/InlinePrompt/InlinePrompt.js');
30
+ require('../body/Body.js');
32
31
  require('../button/Button.resolver.js');
33
32
  require('../prompt/PrimitivePrompt/PrimitivePrompt.js');
34
33
  require('../badge/Badge.js');
@@ -57,9 +56,6 @@ const Field = ({
57
56
  children,
58
57
  ...props
59
58
  }) => {
60
- const {
61
- formatMessage
62
- } = reactIntl.useIntl();
63
59
  const labelRef = React.useRef(null);
64
60
  const sentiment$1 = props.error ? sentiment.Sentiment.NEGATIVE : propType;
65
61
  const message = propMessage || props.error;
@@ -69,10 +65,6 @@ const Field = ({
69
65
  const inputId = id !== null ? id ?? fallbackInputId : undefined;
70
66
  const messageId = React.useId();
71
67
  const descriptionId = React.useId();
72
- const textareaCharCounterId = React.useId();
73
- const [textareaCharacterCount, setTextareaCharacterCount] = React.useState(null);
74
- const handleTextareaCharacterCount = React.useCallback(state => setTextareaCharacterCount(state), []);
75
- const isNearCharLimit = textareaCharacterCount != null && textareaCharacterCount.current >= textareaCharacterCount.max * 0.8;
76
68
  /**
77
69
  * form control can have multiple messages to describe it,
78
70
  * e.g the description underneath the label and inline alert
@@ -85,9 +77,6 @@ const Field = ({
85
77
  if (message) {
86
78
  messageIds.push(messageId);
87
79
  }
88
- if (textareaCharacterCount) {
89
- messageIds.push(textareaCharCounterId);
90
- }
91
80
  return messageIds.length > 0 ? messageIds.join(' ') : undefined;
92
81
  }
93
82
  return /*#__PURE__*/jsxRuntime.jsx(contexts.FieldLabelContextProvider, {
@@ -101,57 +90,37 @@ const Field = ({
101
90
  value: ariaDescribedbyByIds(),
102
91
  children: /*#__PURE__*/jsxRuntime.jsx(contexts.InputInvalidProvider, {
103
92
  value: hasError,
104
- children: /*#__PURE__*/jsxRuntime.jsx(contexts.TextareaCharacterCountProvider, {
105
- value: handleTextareaCharacterCount,
106
- children: /*#__PURE__*/jsxRuntime.jsxs("div", {
107
- className: clsx.clsx('np-field form-group d-block', {
108
- 'has-success': sentiment$1 === sentiment.Sentiment.POSITIVE,
109
- 'has-warning': sentiment$1 === sentiment.Sentiment.WARNING,
110
- 'has-error': hasError,
111
- 'has-info': sentiment$1 === sentiment.Sentiment.NEUTRAL
112
- }, className),
113
- children: [label != null ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
114
- children: [/*#__PURE__*/jsxRuntime.jsx(Label.Label, {
115
- ref: labelRef,
116
- id: labelId,
117
- htmlFor: inputId,
118
- children: required ? label : /*#__PURE__*/jsxRuntime.jsx(Label.Label.Optional, {
119
- children: label
120
- })
121
- }), /*#__PURE__*/jsxRuntime.jsx(Label.Label.Description, {
122
- id: descriptionId,
123
- children: description
124
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
125
- className: "np-field-control",
126
- children: children
127
- })]
128
- }) : children, (message || textareaCharacterCount) && /*#__PURE__*/jsxRuntime.jsxs("div", {
129
- className: "np-field-validation",
130
- children: [message && /*#__PURE__*/jsxRuntime.jsx(InlinePrompt.InlinePrompt, {
131
- sentiment: sentiment$1,
132
- id: messageId,
133
- mediaLabel: messageIconLabel,
134
- className: "np-field__prompt",
135
- loading: messageLoading,
136
- width: "full",
137
- children: message
138
- }), textareaCharacterCount && /*#__PURE__*/jsxRuntime.jsxs(Body.default, {
139
- as: "span",
140
- id: textareaCharCounterId,
141
- ...(isNearCharLimit ? {
142
- role: 'status',
143
- 'aria-live': 'polite',
144
- 'aria-atomic': 'true'
145
- } : {}),
146
- "aria-label": formatMessage(Field_messages.default.characterCount, {
147
- current: textareaCharacterCount.current,
148
- max: textareaCharacterCount.max
149
- }),
150
- className: "np-field-textarea-char-counter",
151
- children: [textareaCharacterCount.current, "/", textareaCharacterCount.max]
152
- })]
93
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
94
+ className: clsx.clsx('np-field form-group d-block', {
95
+ 'has-success': sentiment$1 === sentiment.Sentiment.POSITIVE,
96
+ 'has-warning': sentiment$1 === sentiment.Sentiment.WARNING,
97
+ 'has-error': hasError,
98
+ 'has-info': sentiment$1 === sentiment.Sentiment.NEUTRAL
99
+ }, className),
100
+ children: [label != null ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
101
+ children: [/*#__PURE__*/jsxRuntime.jsx(Label.Label, {
102
+ ref: labelRef,
103
+ id: labelId,
104
+ htmlFor: inputId,
105
+ children: required ? label : /*#__PURE__*/jsxRuntime.jsx(Label.Label.Optional, {
106
+ children: label
107
+ })
108
+ }), /*#__PURE__*/jsxRuntime.jsx(Label.Label.Description, {
109
+ id: descriptionId,
110
+ children: description
111
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
112
+ className: "np-field-control",
113
+ children: children
153
114
  })]
154
- })
115
+ }) : children, message && /*#__PURE__*/jsxRuntime.jsx(InlinePrompt.InlinePrompt, {
116
+ sentiment: sentiment$1,
117
+ id: messageId,
118
+ mediaLabel: messageIconLabel,
119
+ className: "np-field__prompt",
120
+ loading: messageLoading,
121
+ width: "full",
122
+ children: message
123
+ })]
155
124
  })
156
125
  })
157
126
  })
@@ -1 +1 @@
1
- {"version":3,"file":"Field.js","sources":["../../src/field/Field.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useCallback, useId, useRef, useState } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport Body from '../body';\nimport { Sentiment } from '../common';\nimport messages from './Field.messages';\nimport { InlinePrompt, type InlinePromptProps } from '../prompt';\nimport {\n TextareaCharacterCountProvider,\n type TextareaCharacterCountState,\n FieldLabelContextProvider,\n InputDescribedByProvider,\n InputIdContextProvider,\n InputInvalidProvider,\n} from '../inputs/contexts';\nimport { Label } from '../label';\n\nexport type FieldProps = {\n /** `null` disables auto-generating the `id` attribute, falling back to nesting-based label association over setting `htmlFor` explicitly. */\n id?: string | null;\n /** Should be specified unless the wrapped control has its own labeling mechanism, e.g. `Checkbox`. */\n label?: React.ReactNode;\n /** @default true */\n required?: boolean;\n /** @deprecated Use `description` prop instead. */\n hint?: React.ReactNode;\n message?: React.ReactNode;\n /**\n * Override for the [InlinePrompt icon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)\n * announced by the screen readers\n * */\n messageIconLabel?: string;\n /**\n * If true, shows a loading spinner in place of the message icon of the InlinePrompt\n * @default false\n */\n messageLoading?: boolean;\n description?: React.ReactNode;\n /** @deprecated Use `message` and `type={Sentiment.NEGATIVE}` prop instead. */\n error?: React.ReactNode;\n /** @default Sentiment.NEUTRAL */\n sentiment?: InlinePromptProps['sentiment'];\n className?: string;\n children?: React.ReactNode;\n};\n\nexport const Field = ({\n id,\n label,\n required = true,\n message: propMessage,\n messageIconLabel,\n messageLoading,\n hint,\n description = hint,\n sentiment: propType = Sentiment.NEUTRAL,\n className,\n children,\n ...props\n}: FieldProps) => {\n const { formatMessage } = useIntl();\n const labelRef = useRef<HTMLLabelElement>(null);\n const sentiment = props.error ? Sentiment.NEGATIVE : propType;\n const message = propMessage || props.error;\n const hasError = sentiment === Sentiment.NEGATIVE;\n\n const labelId = useId();\n\n const fallbackInputId = useId();\n const inputId = id !== null ? (id ?? fallbackInputId) : undefined;\n\n const messageId = useId();\n const descriptionId = useId();\n const textareaCharCounterId = useId();\n\n const [textareaCharacterCount, setTextareaCharacterCount] =\n useState<TextareaCharacterCountState>(null);\n const handleTextareaCharacterCount = useCallback(\n (state: TextareaCharacterCountState) => setTextareaCharacterCount(state),\n [],\n );\n\n const isNearCharLimit =\n textareaCharacterCount != null &&\n textareaCharacterCount.current >= textareaCharacterCount.max * 0.8;\n\n /**\n * form control can have multiple messages to describe it,\n * e.g the description underneath the label and inline alert\n */\n function ariaDescribedbyByIds() {\n const messageIds = [];\n if (description) {\n messageIds.push(descriptionId);\n }\n if (message) {\n messageIds.push(messageId);\n }\n if (textareaCharacterCount) {\n messageIds.push(textareaCharCounterId);\n }\n return messageIds.length > 0 ? messageIds.join(' ') : undefined;\n }\n\n return (\n <FieldLabelContextProvider value={{ id: labelId, ref: labelRef }}>\n <InputIdContextProvider value={inputId}>\n <InputDescribedByProvider value={ariaDescribedbyByIds()}>\n <InputInvalidProvider value={hasError}>\n <TextareaCharacterCountProvider value={handleTextareaCharacterCount}>\n <div\n className={clsx(\n 'np-field form-group d-block',\n {\n 'has-success': sentiment === Sentiment.POSITIVE,\n 'has-warning': sentiment === Sentiment.WARNING,\n 'has-error': hasError,\n 'has-info': sentiment === Sentiment.NEUTRAL,\n },\n className,\n )}\n >\n {label != null ? (\n <>\n <Label ref={labelRef} id={labelId} htmlFor={inputId}>\n {required ? label : <Label.Optional>{label}</Label.Optional>}\n </Label>\n <Label.Description id={descriptionId}>{description}</Label.Description>\n <div className=\"np-field-control\">{children}</div>\n </>\n ) : (\n children\n )}\n\n {(message || textareaCharacterCount) && (\n <div className=\"np-field-validation\">\n {message && (\n <InlinePrompt\n sentiment={sentiment}\n id={messageId}\n mediaLabel={messageIconLabel}\n className=\"np-field__prompt\"\n loading={messageLoading}\n width=\"full\"\n >\n {message}\n </InlinePrompt>\n )}\n {textareaCharacterCount && (\n <Body\n as=\"span\"\n id={textareaCharCounterId}\n {...(isNearCharLimit\n ? {\n role: 'status' as const,\n 'aria-live': 'polite' as const,\n 'aria-atomic': 'true' as const,\n }\n : {})}\n aria-label={formatMessage(messages.characterCount, {\n current: textareaCharacterCount.current,\n max: textareaCharacterCount.max,\n })}\n className=\"np-field-textarea-char-counter\"\n >\n {textareaCharacterCount.current}/{textareaCharacterCount.max}\n </Body>\n )}\n </div>\n )}\n </div>\n </TextareaCharacterCountProvider>\n </InputInvalidProvider>\n </InputDescribedByProvider>\n </InputIdContextProvider>\n </FieldLabelContextProvider>\n );\n};\n"],"names":["Field","id","label","required","message","propMessage","messageIconLabel","messageLoading","hint","description","sentiment","propType","Sentiment","NEUTRAL","className","children","props","formatMessage","useIntl","labelRef","useRef","error","NEGATIVE","hasError","labelId","useId","fallbackInputId","inputId","undefined","messageId","descriptionId","textareaCharCounterId","textareaCharacterCount","setTextareaCharacterCount","useState","handleTextareaCharacterCount","useCallback","state","isNearCharLimit","current","max","ariaDescribedbyByIds","messageIds","push","length","join","_jsx","FieldLabelContextProvider","value","ref","InputIdContextProvider","InputDescribedByProvider","InputInvalidProvider","TextareaCharacterCountProvider","_jsxs","clsx","POSITIVE","WARNING","_Fragment","Label","htmlFor","Optional","Description","InlinePrompt","mediaLabel","loading","width","Body","as","role","messages","characterCount"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CO,MAAMA,KAAK,GAAGA,CAAC;EACpBC,EAAE;EACFC,KAAK;AACLC,EAAAA,QAAQ,GAAG,IAAI;AACfC,EAAAA,OAAO,EAAEC,WAAW;EACpBC,gBAAgB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B;AACE+B,oBAAAA,IAAI,EAAE,QAAiB;AACvB,oBAAA,WAAW,EAAE,QAAiB;AAC9B,oBAAA,aAAa,EAAE;mBAChB,GACD,EAAE,CAAA;AACN,kBAAA,YAAA,EAAYpD,aAAa,CAACqD,sBAAQ,CAACC,cAAc,EAAE;oBACjDhC,OAAO,EAAEP,sBAAsB,CAACO,OAAO;oBACvCC,GAAG,EAAER,sBAAsB,CAACQ;AAC7B,mBAAA,CAAE;AACH1B,kBAAAA,SAAS,EAAC,gCAAgC;kBAAAC,QAAA,EAAA,CAEzCiB,sBAAsB,CAACO,OAAO,EAAC,GAAC,EAACP,sBAAsB,CAACQ,GAAG;AAAA,iBACxD,CACP;AAAA,eACE,CACN;aACE;WACyB;SACZ;OACE;KACJ;AAC1B,GAA2B,CAAC;AAEhC;;;;"}
1
+ {"version":3,"file":"Field.js","sources":["../../src/field/Field.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useId, useRef } from 'react';\n\nimport { Sentiment } from '../common';\nimport { InlinePrompt, type InlinePromptProps } from '../prompt';\nimport {\n FieldLabelContextProvider,\n InputDescribedByProvider,\n InputIdContextProvider,\n InputInvalidProvider,\n} from '../inputs/contexts';\nimport { Label } from '../label';\n\nexport type FieldProps = {\n /** `null` disables auto-generating the `id` attribute, falling back to nesting-based label association over setting `htmlFor` explicitly. */\n id?: string | null;\n /** Should be specified unless the wrapped control has its own labeling mechanism, e.g. `Checkbox`. */\n label?: React.ReactNode;\n /** @default true */\n required?: boolean;\n /** @deprecated Use `description` prop instead. */\n hint?: React.ReactNode;\n message?: React.ReactNode;\n /**\n * Override for the [InlinePrompt icon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)\n * announced by the screen readers\n * */\n messageIconLabel?: string;\n /**\n * If true, shows a loading spinner in place of the message icon of the InlinePrompt\n * @default false\n */\n messageLoading?: boolean;\n description?: React.ReactNode;\n /** @deprecated Use `message` and `type={Sentiment.NEGATIVE}` prop instead. */\n error?: React.ReactNode;\n /** @default Sentiment.NEUTRAL */\n sentiment?: InlinePromptProps['sentiment'];\n className?: string;\n children?: React.ReactNode;\n};\n\nexport const Field = ({\n id,\n label,\n required = true,\n message: propMessage,\n messageIconLabel,\n messageLoading,\n hint,\n description = hint,\n sentiment: propType = Sentiment.NEUTRAL,\n className,\n children,\n ...props\n}: FieldProps) => {\n const labelRef = useRef<HTMLLabelElement>(null);\n const sentiment = props.error ? Sentiment.NEGATIVE : propType;\n const message = propMessage || props.error;\n const hasError = sentiment === Sentiment.NEGATIVE;\n\n const labelId = useId();\n\n const fallbackInputId = useId();\n const inputId = id !== null ? (id ?? fallbackInputId) : undefined;\n\n const messageId = useId();\n const descriptionId = useId();\n\n /**\n * form control can have multiple messages to describe it,\n * e.g the description underneath the label and inline alert\n */\n function ariaDescribedbyByIds() {\n const messageIds = [];\n if (description) {\n messageIds.push(descriptionId);\n }\n if (message) {\n messageIds.push(messageId);\n }\n return messageIds.length > 0 ? messageIds.join(' ') : undefined;\n }\n\n return (\n <FieldLabelContextProvider value={{ id: labelId, ref: labelRef }}>\n <InputIdContextProvider value={inputId}>\n <InputDescribedByProvider value={ariaDescribedbyByIds()}>\n <InputInvalidProvider value={hasError}>\n <div\n className={clsx(\n 'np-field form-group d-block',\n {\n 'has-success': sentiment === Sentiment.POSITIVE,\n 'has-warning': sentiment === Sentiment.WARNING,\n 'has-error': hasError,\n 'has-info': sentiment === Sentiment.NEUTRAL,\n },\n className,\n )}\n >\n {label != null ? (\n <>\n <Label ref={labelRef} id={labelId} htmlFor={inputId}>\n {required ? label : <Label.Optional>{label}</Label.Optional>}\n </Label>\n <Label.Description id={descriptionId}>{description}</Label.Description>\n <div className=\"np-field-control\">{children}</div>\n </>\n ) : (\n children\n )}\n\n {message && (\n <InlinePrompt\n sentiment={sentiment}\n id={messageId}\n mediaLabel={messageIconLabel}\n className=\"np-field__prompt\"\n loading={messageLoading}\n width=\"full\"\n >\n {message}\n </InlinePrompt>\n )}\n </div>\n </InputInvalidProvider>\n </InputDescribedByProvider>\n </InputIdContextProvider>\n </FieldLabelContextProvider>\n );\n};\n"],"names":["Field","id","label","required","message","propMessage","messageIconLabel","messageLoading","hint","description","sentiment","propType","Sentiment","NEUTRAL","className","children","props","labelRef","useRef","error","NEGATIVE","hasError","labelId","useId","fallbackInputId","inputId","undefined","messageId","descriptionId","ariaDescribedbyByIds","messageIds","push","length","join","_jsx","FieldLabelContextProvider","value","ref","InputIdContextProvider","InputDescribedByProvider","InputInvalidProvider","_jsxs","clsx","POSITIVE","WARNING","_Fragment","Label","htmlFor","Optional","Description","InlinePrompt","mediaLabel","loading","width"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CO,MAAMA,KAAK,GAAGA,CAAC;EACpBC,EAAE;EACFC,KAAK;AACLC,EAAAA,QAAQ,GAAG,IAAI;AACfC,EAAAA,OAAO,EAAEC,WAAW;EACpBC,gBAAgB;EAChBC,cAAc;EACdC,IAAI;AACJC,EAAAA,WAAW,GAAGD,IAAI;AAClBE,EAAAA,SAAS,EAAEC,QAAQ,GAAGC,mBAAS,CAACC,OAAO;EACvCC,SAAS;EACTC,QAAQ;EACR,GAAGC;AAAK,CACG,KAAI;AACf,EAAA,MAAMC,QAAQ,GAAGC,YAAM,CAAmB,IAAI,CAAC;EAC/C,MAAMR,WAAS,GAAGM,KAAK,CAACG,KAAK,GAAGP,mBAAS,CAACQ,QAAQ,GAAGT,QAAQ;AAC7D,EAAA,MAAMP,OAAO,GAAGC,WAAW,IAAIW,KAAK,CAACG,KAAK;AAC1C,EAAA,MAAME,QAAQ,GAAGX,WAAS,KAAKE,mBAAS,CAACQ,QAAQ;AAEjD,EAAA,MAAME,OAAO,GAAGC,WAAK,EAAE;AAEvB,EAAA,MAAMC,eAAe,GAAGD,WAAK,EAAE;EAC/B,MAAME,OAAO,GAAGxB,EAAE,KAAK,IAAI,GAAIA,EAAE,IAAIuB,eAAe,GAAIE,SAAS;AAEjE,EAAA,MAAMC,SAA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A,CAAAI,mBAAA,EAAA;cAAA9B,QAAA,EAAA,cACEmB,cAAA,CAACY,WAAK,EAAA;AAACT,gBAAAA,GAAG,EAAEpB,QAAS;AAAChB,gBAAAA,EAAE,EAAEqB,OAAQ;AAACyB,gBAAAA,OAAO,EAAEtB,OAAQ;gBAAAV,QAAA,EACjDZ,QAAQ,GAAGD,KAAK,gBAAGgC,cAAA,CAACY,WAAK,CAACE,QAAQ,EAAA;AAAAjC,kBAAAA,QAAA,EAAEb;iBAAsB;AAAC,eACvD,CACP,eAAAgC,cAAA,CAACY,WAAK,CAACG,WAAW,EAAA;AAAChD,gBAAAA,EAAE,EAAE2B,aAAc;AAAAb,gBAAAA,QAAA,EAAEN;eAA+B,CACtE,eAAAyB,cAAA,CAAA,KAAA,EAAA;AAAKpB,gBAAAA,SAAS,EAAC,kBAAkB;AAAAC,gBAAAA,QAAA,EAAEA;AAAQ,eAAM,CACnD;aAAA,CAAG,GAEHA,QACD,EAEAX,OAAO,iBACN8B,cAAA,CAACgB,yBAAY,EAAA;AACXxC,cAAAA,SAAS,EAAEA,WAAU;AACrBT,cAAAA,EAAE,EAAE0B,SAAU;AACdwB,cAAAA,UAAU,EAAE7C,gBAAiB;AAC7BQ,cAAAA,SAAS,EAAC,kBAAkB;AAC5BsC,cAAAA,OAAO,EAAE7C,cAAe;AACxB8C,cAAAA,KAAK,EAAC,MAAM;AAAAtC,cAAAA,QAAA,EAEXX;AAAO,aACI,CACf;WACE;SACe;OACE;KACJ;AAC1B,GAA2B,CAAC;AAEhC;;;;"}
@@ -1,7 +1,5 @@
1
1
  import { clsx } from 'clsx';
2
- import { useRef, useId, useState, useCallback } from 'react';
3
- import { useIntl } from 'react-intl';
4
- import Body from '../body/Body.mjs';
2
+ import { useRef, useId } from 'react';
5
3
  import '../common/theme.mjs';
6
4
  import '../common/direction.mjs';
7
5
  import '../common/propsValues/control.mjs';
@@ -23,10 +21,11 @@ import '../common/propsValues/markdownNodeType.mjs';
23
21
  import '../common/fileType.mjs';
24
22
  import '@transferwise/formatting';
25
23
  import '@transferwise/icons';
24
+ import 'react-intl';
26
25
  import '../common/closeButton/CloseButton.messages.mjs';
27
26
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
28
- import messages from './Field.messages.mjs';
29
27
  import { InlinePrompt } from '../prompt/InlinePrompt/InlinePrompt.mjs';
28
+ import '../body/Body.mjs';
30
29
  import '../button/Button.resolver.mjs';
31
30
  import '../prompt/PrimitivePrompt/PrimitivePrompt.mjs';
32
31
  import '../badge/Badge.mjs';
@@ -38,7 +37,7 @@ import '../primitives/PrimitiveButton/PrimitiveButton.mjs';
38
37
  import '../primitives/PrimitiveAnchor/PrimitiveAnchor.mjs';
39
38
  import '../link/Link.messages.mjs';
40
39
  import '../prompt/common/Expander/Expander.messages.mjs';
41
- import { FieldLabelContextProvider, InputIdContextProvider, InputDescribedByProvider, InputInvalidProvider, TextareaCharacterCountProvider } from '../inputs/contexts.mjs';
40
+ import { FieldLabelContextProvider, InputIdContextProvider, InputDescribedByProvider, InputInvalidProvider } from '../inputs/contexts.mjs';
42
41
  import { Label as LabelNamespace } from '../label/Label.mjs';
43
42
 
44
43
  const Field = ({
@@ -55,9 +54,6 @@ const Field = ({
55
54
  children,
56
55
  ...props
57
56
  }) => {
58
- const {
59
- formatMessage
60
- } = useIntl();
61
57
  const labelRef = useRef(null);
62
58
  const sentiment = props.error ? Sentiment.NEGATIVE : propType;
63
59
  const message = propMessage || props.error;
@@ -67,10 +63,6 @@ const Field = ({
67
63
  const inputId = id !== null ? id ?? fallbackInputId : undefined;
68
64
  const messageId = useId();
69
65
  const descriptionId = useId();
70
- const textareaCharCounterId = useId();
71
- const [textareaCharacterCount, setTextareaCharacterCount] = useState(null);
72
- const handleTextareaCharacterCount = useCallback(state => setTextareaCharacterCount(state), []);
73
- const isNearCharLimit = textareaCharacterCount != null && textareaCharacterCount.current >= textareaCharacterCount.max * 0.8;
74
66
  /**
75
67
  * form control can have multiple messages to describe it,
76
68
  * e.g the description underneath the label and inline alert
@@ -83,9 +75,6 @@ const Field = ({
83
75
  if (message) {
84
76
  messageIds.push(messageId);
85
77
  }
86
- if (textareaCharacterCount) {
87
- messageIds.push(textareaCharCounterId);
88
- }
89
78
  return messageIds.length > 0 ? messageIds.join(' ') : undefined;
90
79
  }
91
80
  return /*#__PURE__*/jsx(FieldLabelContextProvider, {
@@ -99,57 +88,37 @@ const Field = ({
99
88
  value: ariaDescribedbyByIds(),
100
89
  children: /*#__PURE__*/jsx(InputInvalidProvider, {
101
90
  value: hasError,
102
- children: /*#__PURE__*/jsx(TextareaCharacterCountProvider, {
103
- value: handleTextareaCharacterCount,
104
- children: /*#__PURE__*/jsxs("div", {
105
- className: clsx('np-field form-group d-block', {
106
- 'has-success': sentiment === Sentiment.POSITIVE,
107
- 'has-warning': sentiment === Sentiment.WARNING,
108
- 'has-error': hasError,
109
- 'has-info': sentiment === Sentiment.NEUTRAL
110
- }, className),
111
- children: [label != null ? /*#__PURE__*/jsxs(Fragment, {
112
- children: [/*#__PURE__*/jsx(LabelNamespace, {
113
- ref: labelRef,
114
- id: labelId,
115
- htmlFor: inputId,
116
- children: required ? label : /*#__PURE__*/jsx(LabelNamespace.Optional, {
117
- children: label
118
- })
119
- }), /*#__PURE__*/jsx(LabelNamespace.Description, {
120
- id: descriptionId,
121
- children: description
122
- }), /*#__PURE__*/jsx("div", {
123
- className: "np-field-control",
124
- children: children
125
- })]
126
- }) : children, (message || textareaCharacterCount) && /*#__PURE__*/jsxs("div", {
127
- className: "np-field-validation",
128
- children: [message && /*#__PURE__*/jsx(InlinePrompt, {
129
- sentiment: sentiment,
130
- id: messageId,
131
- mediaLabel: messageIconLabel,
132
- className: "np-field__prompt",
133
- loading: messageLoading,
134
- width: "full",
135
- children: message
136
- }), textareaCharacterCount && /*#__PURE__*/jsxs(Body, {
137
- as: "span",
138
- id: textareaCharCounterId,
139
- ...(isNearCharLimit ? {
140
- role: 'status',
141
- 'aria-live': 'polite',
142
- 'aria-atomic': 'true'
143
- } : {}),
144
- "aria-label": formatMessage(messages.characterCount, {
145
- current: textareaCharacterCount.current,
146
- max: textareaCharacterCount.max
147
- }),
148
- className: "np-field-textarea-char-counter",
149
- children: [textareaCharacterCount.current, "/", textareaCharacterCount.max]
150
- })]
91
+ children: /*#__PURE__*/jsxs("div", {
92
+ className: clsx('np-field form-group d-block', {
93
+ 'has-success': sentiment === Sentiment.POSITIVE,
94
+ 'has-warning': sentiment === Sentiment.WARNING,
95
+ 'has-error': hasError,
96
+ 'has-info': sentiment === Sentiment.NEUTRAL
97
+ }, className),
98
+ children: [label != null ? /*#__PURE__*/jsxs(Fragment, {
99
+ children: [/*#__PURE__*/jsx(LabelNamespace, {
100
+ ref: labelRef,
101
+ id: labelId,
102
+ htmlFor: inputId,
103
+ children: required ? label : /*#__PURE__*/jsx(LabelNamespace.Optional, {
104
+ children: label
105
+ })
106
+ }), /*#__PURE__*/jsx(LabelNamespace.Description, {
107
+ id: descriptionId,
108
+ children: description
109
+ }), /*#__PURE__*/jsx("div", {
110
+ className: "np-field-control",
111
+ children: children
151
112
  })]
152
- })
113
+ }) : children, message && /*#__PURE__*/jsx(InlinePrompt, {
114
+ sentiment: sentiment,
115
+ id: messageId,
116
+ mediaLabel: messageIconLabel,
117
+ className: "np-field__prompt",
118
+ loading: messageLoading,
119
+ width: "full",
120
+ children: message
121
+ })]
153
122
  })
154
123
  })
155
124
  })
@@ -1 +1 @@
1
- {"version":3,"file":"Field.mjs","sources":["../../src/field/Field.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useCallback, useId, useRef, useState } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport Body from '../body';\nimport { Sentiment } from '../common';\nimport messages from './Field.messages';\nimport { InlinePrompt, type InlinePromptProps } from '../prompt';\nimport {\n TextareaCharacterCountProvider,\n type TextareaCharacterCountState,\n FieldLabelContextProvider,\n InputDescribedByProvider,\n InputIdContextProvider,\n InputInvalidProvider,\n} from '../inputs/contexts';\nimport { Label } from '../label';\n\nexport type FieldProps = {\n /** `null` disables auto-generating the `id` attribute, falling back to nesting-based label association over setting `htmlFor` explicitly. */\n id?: string | null;\n /** Should be specified unless the wrapped control has its own labeling mechanism, e.g. `Checkbox`. */\n label?: React.ReactNode;\n /** @default true */\n required?: boolean;\n /** @deprecated Use `description` prop instead. */\n hint?: React.ReactNode;\n message?: React.ReactNode;\n /**\n * Override for the [InlinePrompt icon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)\n * announced by the screen readers\n * */\n messageIconLabel?: string;\n /**\n * If true, shows a loading spinner in place of the message icon of the InlinePrompt\n * @default false\n */\n messageLoading?: boolean;\n description?: React.ReactNode;\n /** @deprecated Use `message` and `type={Sentiment.NEGATIVE}` prop instead. */\n error?: React.ReactNode;\n /** @default Sentiment.NEUTRAL */\n sentiment?: InlinePromptProps['sentiment'];\n className?: string;\n children?: React.ReactNode;\n};\n\nexport const Field = ({\n id,\n label,\n required = true,\n message: propMessage,\n messageIconLabel,\n messageLoading,\n hint,\n description = hint,\n sentiment: propType = Sentiment.NEUTRAL,\n className,\n children,\n ...props\n}: FieldProps) => {\n const { formatMessage } = useIntl();\n const labelRef = useRef<HTMLLabelElement>(null);\n const sentiment = props.error ? Sentiment.NEGATIVE : propType;\n const message = propMessage || props.error;\n const hasError = sentiment === Sentiment.NEGATIVE;\n\n const labelId = useId();\n\n const fallbackInputId = useId();\n const inputId = id !== null ? (id ?? fallbackInputId) : undefined;\n\n const messageId = useId();\n const descriptionId = useId();\n const textareaCharCounterId = useId();\n\n const [textareaCharacterCount, setTextareaCharacterCount] =\n useState<TextareaCharacterCountState>(null);\n const handleTextareaCharacterCount = useCallback(\n (state: TextareaCharacterCountState) => setTextareaCharacterCount(state),\n [],\n );\n\n const isNearCharLimit =\n textareaCharacterCount != null &&\n textareaCharacterCount.current >= textareaCharacterCount.max * 0.8;\n\n /**\n * form control can have multiple messages to describe it,\n * e.g the description underneath the label and inline alert\n */\n function ariaDescribedbyByIds() {\n const messageIds = [];\n if (description) {\n messageIds.push(descriptionId);\n }\n if (message) {\n messageIds.push(messageId);\n }\n if (textareaCharacterCount) {\n messageIds.push(textareaCharCounterId);\n }\n return messageIds.length > 0 ? messageIds.join(' ') : undefined;\n }\n\n return (\n <FieldLabelContextProvider value={{ id: labelId, ref: labelRef }}>\n <InputIdContextProvider value={inputId}>\n <InputDescribedByProvider value={ariaDescribedbyByIds()}>\n <InputInvalidProvider value={hasError}>\n <TextareaCharacterCountProvider value={handleTextareaCharacterCount}>\n <div\n className={clsx(\n 'np-field form-group d-block',\n {\n 'has-success': sentiment === Sentiment.POSITIVE,\n 'has-warning': sentiment === Sentiment.WARNING,\n 'has-error': hasError,\n 'has-info': sentiment === Sentiment.NEUTRAL,\n },\n className,\n )}\n >\n {label != null ? (\n <>\n <Label ref={labelRef} id={labelId} htmlFor={inputId}>\n {required ? label : <Label.Optional>{label}</Label.Optional>}\n </Label>\n <Label.Description id={descriptionId}>{description}</Label.Description>\n <div className=\"np-field-control\">{children}</div>\n </>\n ) : (\n children\n )}\n\n {(message || textareaCharacterCount) && (\n <div className=\"np-field-validation\">\n {message && (\n <InlinePrompt\n sentiment={sentiment}\n id={messageId}\n mediaLabel={messageIconLabel}\n className=\"np-field__prompt\"\n loading={messageLoading}\n width=\"full\"\n >\n {message}\n </InlinePrompt>\n )}\n {textareaCharacterCount && (\n <Body\n as=\"span\"\n id={textareaCharCounterId}\n {...(isNearCharLimit\n ? {\n role: 'status' as const,\n 'aria-live': 'polite' as const,\n 'aria-atomic': 'true' as const,\n }\n : {})}\n aria-label={formatMessage(messages.characterCount, {\n current: textareaCharacterCount.current,\n max: textareaCharacterCount.max,\n })}\n className=\"np-field-textarea-char-counter\"\n >\n {textareaCharacterCount.current}/{textareaCharacterCount.max}\n </Body>\n )}\n </div>\n )}\n </div>\n </TextareaCharacterCountProvider>\n </InputInvalidProvider>\n </InputDescribedByProvider>\n </InputIdContextProvider>\n </FieldLabelContextProvider>\n );\n};\n"],"names":["Field","id","label","required","message","propMessage","messageIconLabel","messageLoading","hint","description","sentiment","propType","Sentiment","NEUTRAL","className","children","props","formatMessage","useIntl","labelRef","useRef","error","NEGATIVE","hasError","labelId","useId","fallbackInputId","inputId","undefined","messageId","descriptionId","textareaCharCounterId","textareaCharacterCount","setTextareaCharacterCount","useState","handleTextareaCharacterCount","useCallback","state","isNearCharLimit","current","max","ariaDescribedbyByIds","messageIds","push","length","join","_jsx","FieldLabelContextProvider","value","ref","InputIdContextProvider","InputDescribedByProvider","InputInvalidProvider","TextareaCharacterCountProvider","_jsxs","clsx","POSITIVE","WARNING","_Fragment","Label","htmlFor","Optional","Description","InlinePrompt","mediaLabel","loading","width","Body","as","role","messages","characterCount"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CO,MAAMA,KAAK,GAAGA,CAAC;EACpBC,EAAE;EACFC,KAAK;AACLC,EAAAA,QAAQ,GAAG,IAAI;AACfC,EAAAA,OAAO,EAAEC,WAAW;EACpBC,gBAAgB;EAChBC,cAAc;EACdC,IAAI;AACJC,EAAAA,WAAW,GAAGD,IAAI;AAClBE,EAAAA,SAAS,EAAEC,QAAQ,GAAGC,SAAS,CAACC,OAAO;EACvCC,SAAS;EACTC,QAAQ;EACR,GAAGC;AAAK,CACG,KAAI;EACf,MAAM;AAAEC,IAAAA;GAAe,GAAGC,OAAO,EAAE;AACnC,EAAA,MAAMC,QAAQ,GAAGC,MAAM,CAAmB,IAAI,CAAC;EAC/C,MAAMV,SAAS,GAAGM,KAAK,CAACK,KAAK,GAAGT,SAAS,CAACU,QAAQ,GAAGX,QAAQ;AAC7D,EAAA,MAAMP,OAAO,GAAGC,WAAW,IAAIW,KAAK,CAACK,KAAK;AAC1C,EAAA,MAAME,QAAQ,GAAGb,SAAS,KAAKE,SAAS,CAACU,QAAQ;AAEjD,EAAA,MAAME,OAAO,GAAGC,KAAK,EAAE;AAEvB,EAAA,MAAMC,eAAe,GAAGD,KAAK,EAAE;EAC/B,MAAME,OA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,GAEHA,QACD,EAEA,CAACX,OAAO,IAAI4B,sBAAsB,kBACjCsB,IAAA,CAAA,KAAA,EAAA;AAAKxC,gBAAAA,SAAS,EAAC,qBAAqB;AAAAC,gBAAAA,QAAA,EAAA,CACjCX,OAAO,iBACN0C,GAAA,CAACiB,YAAY,EAAA;AACXrD,kBAAAA,SAAS,EAAEA,SAAU;AACrBT,kBAAAA,EAAE,EAAE4B,SAAU;AACdmC,kBAAAA,UAAU,EAAE1D,gBAAiB;AAC7BQ,kBAAAA,SAAS,EAAC,kBAAkB;AAC5BmD,kBAAAA,OAAO,EAAE1D,cAAe;AACxB2D,kBAAAA,KAAK,EAAC,MAAM;AAAAnD,kBAAAA,QAAA,EAEXX;AAAO,iBACI,CACf,EACA4B,sBAAsB,iBACrBsB,IAAA,CAACa,IAAI,EAAA;AACHC,kBAAAA,EAAE,EAAC,MAAM;AACTnE,kBAAAA,EAAE,EAAE8B,qBAAsB;AAAA,kBAAA,IACrBO,eAAe,GAChB;AACE+B,oBAAAA,IAAI,EAAE,QAAiB;AACvB,oBAAA,WAAW,EAAE,QAAiB;AAC9B,oBAAA,aAAa,EAAE;mBAChB,GACD,EAAE,CAAA;AACN,kBAAA,YAAA,EAAYpD,aAAa,CAACqD,QAAQ,CAACC,cAAc,EAAE;oBACjDhC,OAAO,EAAEP,sBAAsB,CAACO,OAAO;oBACvCC,GAAG,EAAER,sBAAsB,CAACQ;AAC7B,mBAAA,CAAE;AACH1B,kBAAAA,SAAS,EAAC,gCAAgC;kBAAAC,QAAA,EAAA,CAEzCiB,sBAAsB,CAACO,OAAO,EAAC,GAAC,EAACP,sBAAsB,CAACQ,GAAG;AAAA,iBACxD,CACP;AAAA,eACE,CACN;aACE;WACyB;SACZ;OACE;KACJ;AAC1B,GAA2B,CAAC;AAEhC;;;;"}
1
+ {"version":3,"file":"Field.mjs","sources":["../../src/field/Field.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useId, useRef } from 'react';\n\nimport { Sentiment } from '../common';\nimport { InlinePrompt, type InlinePromptProps } from '../prompt';\nimport {\n FieldLabelContextProvider,\n InputDescribedByProvider,\n InputIdContextProvider,\n InputInvalidProvider,\n} from '../inputs/contexts';\nimport { Label } from '../label';\n\nexport type FieldProps = {\n /** `null` disables auto-generating the `id` attribute, falling back to nesting-based label association over setting `htmlFor` explicitly. */\n id?: string | null;\n /** Should be specified unless the wrapped control has its own labeling mechanism, e.g. `Checkbox`. */\n label?: React.ReactNode;\n /** @default true */\n required?: boolean;\n /** @deprecated Use `description` prop instead. */\n hint?: React.ReactNode;\n message?: React.ReactNode;\n /**\n * Override for the [InlinePrompt icon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)\n * announced by the screen readers\n * */\n messageIconLabel?: string;\n /**\n * If true, shows a loading spinner in place of the message icon of the InlinePrompt\n * @default false\n */\n messageLoading?: boolean;\n description?: React.ReactNode;\n /** @deprecated Use `message` and `type={Sentiment.NEGATIVE}` prop instead. */\n error?: React.ReactNode;\n /** @default Sentiment.NEUTRAL */\n sentiment?: InlinePromptProps['sentiment'];\n className?: string;\n children?: React.ReactNode;\n};\n\nexport const Field = ({\n id,\n label,\n required = true,\n message: propMessage,\n messageIconLabel,\n messageLoading,\n hint,\n description = hint,\n sentiment: propType = Sentiment.NEUTRAL,\n className,\n children,\n ...props\n}: FieldProps) => {\n const labelRef = useRef<HTMLLabelElement>(null);\n const sentiment = props.error ? Sentiment.NEGATIVE : propType;\n const message = propMessage || props.error;\n const hasError = sentiment === Sentiment.NEGATIVE;\n\n const labelId = useId();\n\n const fallbackInputId = useId();\n const inputId = id !== null ? (id ?? fallbackInputId) : undefined;\n\n const messageId = useId();\n const descriptionId = useId();\n\n /**\n * form control can have multiple messages to describe it,\n * e.g the description underneath the label and inline alert\n */\n function ariaDescribedbyByIds() {\n const messageIds = [];\n if (description) {\n messageIds.push(descriptionId);\n }\n if (message) {\n messageIds.push(messageId);\n }\n return messageIds.length > 0 ? messageIds.join(' ') : undefined;\n }\n\n return (\n <FieldLabelContextProvider value={{ id: labelId, ref: labelRef }}>\n <InputIdContextProvider value={inputId}>\n <InputDescribedByProvider value={ariaDescribedbyByIds()}>\n <InputInvalidProvider value={hasError}>\n <div\n className={clsx(\n 'np-field form-group d-block',\n {\n 'has-success': sentiment === Sentiment.POSITIVE,\n 'has-warning': sentiment === Sentiment.WARNING,\n 'has-error': hasError,\n 'has-info': sentiment === Sentiment.NEUTRAL,\n },\n className,\n )}\n >\n {label != null ? (\n <>\n <Label ref={labelRef} id={labelId} htmlFor={inputId}>\n {required ? label : <Label.Optional>{label}</Label.Optional>}\n </Label>\n <Label.Description id={descriptionId}>{description}</Label.Description>\n <div className=\"np-field-control\">{children}</div>\n </>\n ) : (\n children\n )}\n\n {message && (\n <InlinePrompt\n sentiment={sentiment}\n id={messageId}\n mediaLabel={messageIconLabel}\n className=\"np-field__prompt\"\n loading={messageLoading}\n width=\"full\"\n >\n {message}\n </InlinePrompt>\n )}\n </div>\n </InputInvalidProvider>\n </InputDescribedByProvider>\n </InputIdContextProvider>\n </FieldLabelContextProvider>\n );\n};\n"],"names":["Field","id","label","required","message","propMessage","messageIconLabel","messageLoading","hint","description","sentiment","propType","Sentiment","NEUTRAL","className","children","props","labelRef","useRef","error","NEGATIVE","hasError","labelId","useId","fallbackInputId","inputId","undefined","messageId","descriptionId","ariaDescribedbyByIds","messageIds","push","length","join","_jsx","FieldLabelContextProvider","value","ref","InputIdContextProvider","InputDescribedByProvider","InputInvalidProvider","_jsxs","clsx","POSITIVE","WARNING","_Fragment","Label","htmlFor","Optional","Description","InlinePrompt","mediaLabel","loading","width"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CO,MAAMA,KAAK,GAAGA,CAAC;EACpBC,EAAE;EACFC,KAAK;AACLC,EAAAA,QAAQ,GAAG,IAAI;AACfC,EAAAA,OAAO,EAAEC,WAAW;EACpBC,gBAAgB;EAChBC,cAAc;EACdC,IAAI;AACJC,EAAAA,WAAW,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YAAY,EAAA;AACXxC,cAAAA,SAAS,EAAEA,SAAU;AACrBT,cAAAA,EAAE,EAAE0B,SAAU;AACdwB,cAAAA,UAAU,EAAE7C,gBAAiB;AAC7BQ,cAAAA,SAAS,EAAC,kBAAkB;AAC5BsC,cAAAA,OAAO,EAAE7C,cAAe;AACxB8C,cAAAA,KAAK,EAAC,MAAM;AAAAtC,cAAAA,QAAA,EAEXX;AAAO,aACI,CACf;WACE;SACe;OACE;KACJ;AAC1B,GAA2B,CAAC;AAEhC;;;;"}
@@ -20,7 +20,6 @@
20
20
  "neptune.Expander.expandAriaLabel": "Expand",
21
21
  "neptune.ExpressiveMoneyInput.currency.search.placeholder": "Type a currency / country",
22
22
  "neptune.ExpressiveMoneyInput.currency.select.currency": "Select currency",
23
- "neptune.Field.characterCount": "{current} of {max} characters used",
24
23
  "neptune.FlowNavigation.back": "back to previous step",
25
24
  "neptune.Info.ariaLabel": "More information",
26
25
  "neptune.Label.optional": "(Optional)",
@@ -24,7 +24,6 @@ var en = {
24
24
  "neptune.Expander.expandAriaLabel": "Expand",
25
25
  "neptune.ExpressiveMoneyInput.currency.search.placeholder": "Type a currency / country",
26
26
  "neptune.ExpressiveMoneyInput.currency.select.currency": "Select currency",
27
- "neptune.Field.characterCount": "{current} of {max} characters used",
28
27
  "neptune.FlowNavigation.back": "back to previous step",
29
28
  "neptune.Info.ariaLabel": "More information",
30
29
  "neptune.Label.optional": "(Optional)",
@@ -1 +1 @@
1
- {"version":3,"file":"en.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"en.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -20,7 +20,6 @@ var en = {
20
20
  "neptune.Expander.expandAriaLabel": "Expand",
21
21
  "neptune.ExpressiveMoneyInput.currency.search.placeholder": "Type a currency / country",
22
22
  "neptune.ExpressiveMoneyInput.currency.select.currency": "Select currency",
23
- "neptune.Field.characterCount": "{current} of {max} characters used",
24
23
  "neptune.FlowNavigation.back": "back to previous step",
25
24
  "neptune.Info.ariaLabel": "More information",
26
25
  "neptune.Label.optional": "(Optional)",
@@ -1 +1 @@
1
- {"version":3,"file":"en.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"en.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -8,41 +8,16 @@ var jsxRuntime = require('react/jsx-runtime');
8
8
 
9
9
  const TextArea = /*#__PURE__*/React.forwardRef(function TextArea({
10
10
  className,
11
- maxLength,
12
- onChange,
13
11
  ...restProps
14
12
  }, reference) {
15
13
  const inputAttributes = contexts.useInputAttributes();
16
- const value = restProps.value ?? restProps.defaultValue ?? '';
17
- const currentLength = getGraphemeLength(typeof value === 'string' ? value : String(value));
18
- contexts.useTextareaCharacterCount(currentLength, maxLength);
19
- const handleChange = React.useCallback(e => {
20
- if (maxLength != null && getGraphemeLength(e.target.value) > maxLength) {
21
- return;
22
- }
23
- onChange?.(e);
24
- }, [maxLength, onChange]);
25
14
  return /*#__PURE__*/jsxRuntime.jsx("textarea", {
26
15
  ref: reference,
27
16
  className: clsx.clsx(className, _common.inputClassNameBase(), 'np-text-area'),
28
- onChange: handleChange,
29
17
  ...inputAttributes,
30
18
  ...restProps
31
19
  });
32
20
  });
33
- const segmenter = typeof Intl.Segmenter === 'function' ? new Intl.Segmenter(undefined, {
34
- granularity: 'grapheme'
35
- }) : undefined;
36
- function getGraphemeLength(str) {
37
- if (segmenter) {
38
- let count = 0;
39
- for (const _ of segmenter.segment(str)) {
40
- count += 1;
41
- }
42
- return count;
43
- }
44
- return Array.from(str).length;
45
- }
46
21
 
47
22
  exports.TextArea = TextArea;
48
23
  //# sourceMappingURL=TextArea.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.js","sources":["../../src/inputs/TextArea.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { forwardRef, useCallback } from 'react';\n\nimport { Merge } from '../utils';\nimport { inputClassNameBase } from './_common';\nimport { useTextareaCharacterCount, useInputAttributes } from './contexts';\n\nexport interface TextAreaProps extends Merge<\n React.ComponentPropsWithRef<'textarea'>,\n {\n 'aria-invalid'?: boolean;\n }\n> {}\n\nexport const TextArea = forwardRef(function TextArea(\n { className, maxLength, onChange, ...restProps }: TextAreaProps,\n reference: React.ForwardedRef<HTMLTextAreaElement | null>,\n) {\n const inputAttributes = useInputAttributes();\n const value = restProps.value ?? restProps.defaultValue ?? '';\n const currentLength = getGraphemeLength(typeof value === 'string' ? value : String(value));\n\n useTextareaCharacterCount(currentLength, maxLength);\n\n const handleChange = useCallback(\n (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n if (maxLength != null && getGraphemeLength(e.target.value) > maxLength) {\n return;\n }\n onChange?.(e);\n },\n [maxLength, onChange],\n );\n\n return (\n <textarea\n ref={reference}\n className={clsx(className, inputClassNameBase(), 'np-text-area')}\n onChange={handleChange}\n {...inputAttributes}\n {...restProps}\n />\n );\n});\n\nconst segmenter =\n typeof Intl.Segmenter === 'function'\n ? new Intl.Segmenter(undefined, { granularity: 'grapheme' })\n : undefined;\n\nfunction getGraphemeLength(str: string): number {\n if (segmenter) {\n let count = 0;\n for (const _ of segmenter.segment(str)) {\n count += 1;\n }\n return count;\n }\n return Array.from(str).length;\n}\n"],"names":["TextArea","forwardRef","className","maxLength","onChange","restProps","reference","inputAttributes","useInputAttributes","value","defaultValue","currentLength","getGraphemeLength","String","useTextareaCharacterCount","handleChange","useCallback","e","target","_jsx","ref","clsx","inputClassNameBase","segmenter","Intl","Segmenter","undefined","granularity","str","count","_","segment","Array","from","length"],"mappings":";;;;;;;;MAcaA,QAAQ,gBAAGC,gBAAU,CAAC,SAASD,QAAQA,CAClD;EAAEE,SAAS;EAAEC,SAAS;EAAEC,QAAQ;EAAE,GAAGC;AAAS,CAAiB,EAC/DC,SAAyD,EAAA;AAEzD,EAAA,MAAMC,eAAe,GAAGC,2BAAkB,EAAE;EAC5C,MAAMC,KAAK,GAAGJ,SAAS,CAACI,KAAK,IAAIJ,SAAS,CAACK,YAAY,IAAI,EAAE;AAC7D,EAAA,MAAMC,aAAa,GAAGC,iBAAiB,CAAC,OAAOH,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGI,MAAM,CAACJ,KAAK,CAAC,CAAC;AAE1FK,EAAAA,kCAAyB,CAACH,aAAa,EAAER,SAAS,CAAC;AAEnD,EAAA,MAAMY,YAAY,GAAGC,iBAAW,CAC7BC,CAAyC,IAAI;AAC5C,IAAA,IAAId,SAAS,IAAI,IAAI,IAAIS,iBAAiB,CAACK,CAAC,CAACC,MAAM,CAACT,KAAK,CAAC,GAAGN,SAAS,EAAE;AACtE,MAAA;AACF,IAAA;IACAC,QAAQ,GAAGa,CAAC,CAAC;AACf,EAAA,CAAC,EACD,CAACd,SAAS,EAAEC,QAAQ,CAAC,CACtB;AAED,EAAA,oBACEe,cAAA,CAAA,UAAA,EAAA;AACEC,IAAAA,GAAG,EAAEd,SAAU;IACfJ,SAAS,EAAEmB,SAAI,CAACnB,SAAS,EAAEoB,0BAAkB,EAAE,EAAE,cAAc,CAAE;AACjElB,IAAAA,QAAQ,EAAEW,YAAa;AAAA,IAAA,GACnBR,eAAe;IAAA,GACfF;AAAS,GAAC,CACd;AAEN,CAAC;AAED,MAAMkB,SAAS,GACb,OAAOC,IAAI,CAACC,SAAS,KAAK,UAAU,GAChC,IAAID,IAAI,CAACC,SAAS,CAACC,SAAS,EAAE;AAAEC,EAAAA,WAAW,EAAE;CAAY,CAAC,GAC1DD,SAAS;AAEf,SAASd,iBAAiBA,CAACgB,GAAW,EAAA;AACpC,EAAA,IAAIL,SAAS,EAAE;IACb,IAAIM,KAAK,GAAG,CAAC;IACb,KAAK,MAAMC,CAAC,IAAIP,SAAS,CAACQ,OAAO,CAACH,GAAG,CAAC,EAAE;AACtCC,MAAAA,KAAK,IAAI,CAAC;AACZ,IAAA;AACA,IAAA,OAAOA,KAAK;AACd,EAAA;AACA,EAAA,OAAOG,KAAK,CAACC,IAAI,CAACL,GAAG,CAAC,CAACM,MAAM;AAC/B;;;;"}
1
+ {"version":3,"file":"TextArea.js","sources":["../../src/inputs/TextArea.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { forwardRef } from 'react';\n\nimport { Merge } from '../utils';\nimport { inputClassNameBase } from './_common';\nimport { useInputAttributes } from './contexts';\n\nexport interface TextAreaProps extends Merge<\n React.ComponentPropsWithRef<'textarea'>,\n {\n 'aria-invalid'?: boolean;\n }\n> {}\n\nexport const TextArea = forwardRef(function TextArea(\n { className, ...restProps }: TextAreaProps,\n reference: React.ForwardedRef<HTMLTextAreaElement | null>,\n) {\n const inputAttributes = useInputAttributes();\n\n return (\n <textarea\n ref={reference}\n className={clsx(className, inputClassNameBase(), 'np-text-area')}\n {...inputAttributes}\n {...restProps}\n />\n );\n});\n"],"names":["TextArea","forwardRef","className","restProps","reference","inputAttributes","useInputAttributes","_jsx","ref","clsx","inputClassNameBase"],"mappings":";;;;;;;;MAcaA,QAAQ,gBAAGC,gBAAU,CAAC,SAASD,QAAQA,CAClD;EAAEE,SAAS;EAAE,GAAGC;AAAS,CAAiB,EAC1CC,SAAyD,EAAA;AAEzD,EAAA,MAAMC,eAAe,GAAGC,2BAAkB,EAAE;AAE5C,EAAA,oBACEC,cAAA,CAAA,UAAA,EAAA;AACEC,IAAAA,GAAG,EAAEJ,SAAU;IACfF,SAAS,EAAEO,SAAI,CAACP,SAAS,EAAEQ,0BAAkB,EAAE,EAAE,cAAc,CAAE;AAAA,IAAA,GAC7DL,eAAe;IAAA,GACfF;AAAS,GAAC,CACd;AAEN,CAAC;;;;"}
@@ -1,46 +1,21 @@
1
1
  import { clsx } from 'clsx';
2
- import { forwardRef, useCallback } from 'react';
2
+ import { forwardRef } from 'react';
3
3
  import { inputClassNameBase } from './_common.mjs';
4
- import { useInputAttributes, useTextareaCharacterCount } from './contexts.mjs';
4
+ import { useInputAttributes } from './contexts.mjs';
5
5
  import { jsx } from 'react/jsx-runtime';
6
6
 
7
7
  const TextArea = /*#__PURE__*/forwardRef(function TextArea({
8
8
  className,
9
- maxLength,
10
- onChange,
11
9
  ...restProps
12
10
  }, reference) {
13
11
  const inputAttributes = useInputAttributes();
14
- const value = restProps.value ?? restProps.defaultValue ?? '';
15
- const currentLength = getGraphemeLength(typeof value === 'string' ? value : String(value));
16
- useTextareaCharacterCount(currentLength, maxLength);
17
- const handleChange = useCallback(e => {
18
- if (maxLength != null && getGraphemeLength(e.target.value) > maxLength) {
19
- return;
20
- }
21
- onChange?.(e);
22
- }, [maxLength, onChange]);
23
12
  return /*#__PURE__*/jsx("textarea", {
24
13
  ref: reference,
25
14
  className: clsx(className, inputClassNameBase(), 'np-text-area'),
26
- onChange: handleChange,
27
15
  ...inputAttributes,
28
16
  ...restProps
29
17
  });
30
18
  });
31
- const segmenter = typeof Intl.Segmenter === 'function' ? new Intl.Segmenter(undefined, {
32
- granularity: 'grapheme'
33
- }) : undefined;
34
- function getGraphemeLength(str) {
35
- if (segmenter) {
36
- let count = 0;
37
- for (const _ of segmenter.segment(str)) {
38
- count += 1;
39
- }
40
- return count;
41
- }
42
- return Array.from(str).length;
43
- }
44
19
 
45
20
  export { TextArea };
46
21
  //# sourceMappingURL=TextArea.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.mjs","sources":["../../src/inputs/TextArea.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { forwardRef, useCallback } from 'react';\n\nimport { Merge } from '../utils';\nimport { inputClassNameBase } from './_common';\nimport { useTextareaCharacterCount, useInputAttributes } from './contexts';\n\nexport interface TextAreaProps extends Merge<\n React.ComponentPropsWithRef<'textarea'>,\n {\n 'aria-invalid'?: boolean;\n }\n> {}\n\nexport const TextArea = forwardRef(function TextArea(\n { className, maxLength, onChange, ...restProps }: TextAreaProps,\n reference: React.ForwardedRef<HTMLTextAreaElement | null>,\n) {\n const inputAttributes = useInputAttributes();\n const value = restProps.value ?? restProps.defaultValue ?? '';\n const currentLength = getGraphemeLength(typeof value === 'string' ? value : String(value));\n\n useTextareaCharacterCount(currentLength, maxLength);\n\n const handleChange = useCallback(\n (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n if (maxLength != null && getGraphemeLength(e.target.value) > maxLength) {\n return;\n }\n onChange?.(e);\n },\n [maxLength, onChange],\n );\n\n return (\n <textarea\n ref={reference}\n className={clsx(className, inputClassNameBase(), 'np-text-area')}\n onChange={handleChange}\n {...inputAttributes}\n {...restProps}\n />\n );\n});\n\nconst segmenter =\n typeof Intl.Segmenter === 'function'\n ? new Intl.Segmenter(undefined, { granularity: 'grapheme' })\n : undefined;\n\nfunction getGraphemeLength(str: string): number {\n if (segmenter) {\n let count = 0;\n for (const _ of segmenter.segment(str)) {\n count += 1;\n }\n return count;\n }\n return Array.from(str).length;\n}\n"],"names":["TextArea","forwardRef","className","maxLength","onChange","restProps","reference","inputAttributes","useInputAttributes","value","defaultValue","currentLength","getGraphemeLength","String","useTextareaCharacterCount","handleChange","useCallback","e","target","_jsx","ref","clsx","inputClassNameBase","segmenter","Intl","Segmenter","undefined","granularity","str","count","_","segment","Array","from","length"],"mappings":";;;;;;MAcaA,QAAQ,gBAAGC,UAAU,CAAC,SAASD,QAAQA,CAClD;EAAEE,SAAS;EAAEC,SAAS;EAAEC,QAAQ;EAAE,GAAGC;AAAS,CAAiB,EAC/DC,SAAyD,EAAA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AC;AACZ,IAAA;AACA,IAAA,OAAOA,KAAK;AACd,EAAA;AACA,EAAA,OAAOG,KAAK,CAACC,IAAI,CAACL,GAAG,CAAC,CAACM,MAAM;AAC/B;;;;"}
1
+ {"version":3,"file":"TextArea.mjs","sources":["../../src/inputs/TextArea.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { forwardRef } from 'react';\n\nimport { Merge } from '../utils';\nimport { inputClassNameBase } from './_common';\nimport { useInputAttributes } from './contexts';\n\nexport interface TextAreaProps extends Merge<\n React.ComponentPropsWithRef<'textarea'>,\n {\n 'aria-invalid'?: boolean;\n }\n> {}\n\nexport const TextArea = forwardRef(function TextArea(\n { className, ...restProps }: TextAreaProps,\n reference: React.ForwardedRef<HTMLTextAreaElement | null>,\n) {\n const inputAttributes = useInputAttributes();\n\n return (\n <textarea\n ref={reference}\n className={clsx(className, inputClassNameBase(), 'np-text-area')}\n {...inputAttributes}\n {...restProps}\n />\n );\n});\n"],"names":["TextArea","forwardRef","className","restProps","reference","inputAttributes","useInputAttributes","_jsx","ref","clsx","inputClassNameBase"],"mappings":";;;;;;MAcaA,QAAQ,gBAAGC,UAAU,CAAC,SAASD,QAAQA,CAClD;EAAEE,SAAS;EAAE,GAAGC;AAAS,CAAiB,EAC1CC,SAAyD,EAAA;AAEzD,EAAA,MAAMC,eAAe,GAAGC,kBAAkB,EAAE;AAE5C,EAAA,oBACEC,GAAA,CAAA,UAAA,EAAA;AACEC,IAAAA,GAAG,EAAEJ,SAAU;IACfF,SAAS,EAAEO,IAAI,CAACP,SAAS,EAAEQ,kBAAkB,EAAE,EAAE,cAAc,CAAE;AAAA,IAAA,GAC7DL,eAAe;IAAA,GACfF;AAAS,GAAC,CACd;AAEN,CAAC;;;;"}
@@ -25,20 +25,6 @@ function useInputAttributes({
25
25
  function useFieldLabelRef() {
26
26
  return React.useContext(FieldLabelContext)?.ref;
27
27
  }
28
- const TextareaCharacterCountContext = /*#__PURE__*/React.createContext(undefined);
29
- const TextareaCharacterCountProvider = TextareaCharacterCountContext.Provider;
30
- function useTextareaCharacterCount(current, max) {
31
- const setCharacterCount = React.useContext(TextareaCharacterCountContext);
32
- React.useEffect(() => {
33
- if (setCharacterCount && max != null) {
34
- setCharacterCount({
35
- current,
36
- max
37
- });
38
- return () => setCharacterCount(null);
39
- }
40
- }, [setCharacterCount, current, max]);
41
- }
42
28
  function withInputAttributes(Component, args) {
43
29
  function ComponentWithInputAttributes(props) {
44
30
  return /*#__PURE__*/jsxRuntime.jsx(Component, {
@@ -54,9 +40,7 @@ exports.FieldLabelContextProvider = FieldLabelContextProvider;
54
40
  exports.InputDescribedByProvider = InputDescribedByProvider;
55
41
  exports.InputIdContextProvider = InputIdContextProvider;
56
42
  exports.InputInvalidProvider = InputInvalidProvider;
57
- exports.TextareaCharacterCountProvider = TextareaCharacterCountProvider;
58
43
  exports.useFieldLabelRef = useFieldLabelRef;
59
44
  exports.useInputAttributes = useInputAttributes;
60
- exports.useTextareaCharacterCount = useTextareaCharacterCount;
61
45
  exports.withInputAttributes = withInputAttributes;
62
46
  //# sourceMappingURL=contexts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contexts.js","sources":["../../src/inputs/contexts.tsx"],"sourcesContent":["import { createContext, useContext, useEffect } from 'react';\n\ntype FieldLabelContextType = {\n id?: string;\n ref?: React.RefObject<HTMLLabelElement>;\n};\n\nconst FieldLabelContext = createContext<FieldLabelContextType | undefined>(undefined);\nexport const FieldLabelContextProvider = FieldLabelContext.Provider;\n\nconst InputIdContext = createContext<string | undefined>(undefined);\nexport const InputIdContextProvider = InputIdContext.Provider;\n\nconst InputDescribedByContext = createContext<string | undefined>(undefined);\nexport const InputDescribedByProvider = InputDescribedByContext.Provider;\n\nconst InputInvalidContext = createContext<boolean | undefined>(undefined);\nexport const InputInvalidProvider = InputInvalidContext.Provider;\n\ninterface UseInputAttributesArgs {\n /** Set this to `true` if the underlying element is not directly [labelable as per the HTML specification](https://html.spec.whatwg.org/multipage/forms.html#category-label). */\n nonLabelable?: boolean;\n}\n\nexport function useInputAttributes({ nonLabelable }: UseInputAttributesArgs = {}) {\n const labelId = useContext(FieldLabelContext)?.id;\n return {\n id: useContext(InputIdContext),\n 'aria-labelledby': nonLabelable ? labelId : undefined,\n 'aria-describedby': useContext(InputDescribedByContext),\n 'aria-invalid': useContext(InputInvalidContext),\n } satisfies React.HTMLAttributes<HTMLElement>;\n}\n\nexport function useFieldLabelRef() {\n return useContext(FieldLabelContext)?.ref;\n}\n\nexport type TextareaCharacterCountState = { current: number; max: number } | null;\n\nconst TextareaCharacterCountContext = createContext<\n ((state: TextareaCharacterCountState) => void) | undefined\n>(undefined);\nexport const TextareaCharacterCountProvider = TextareaCharacterCountContext.Provider;\n\nexport function useTextareaCharacterCount(current: number, max: number | undefined) {\n const setCharacterCount = useContext(TextareaCharacterCountContext);\n useEffect(() => {\n if (setCharacterCount && max != null) {\n setCharacterCount({ current, max });\n return () => setCharacterCount(null);\n }\n }, [setCharacterCount, current, max]);\n}\n\nexport interface WithInputAttributesProps {\n inputAttributes: ReturnType<typeof useInputAttributes>;\n}\n\nexport function withInputAttributes<T extends Partial<WithInputAttributesProps>>(\n Component: React.ComponentType<T>,\n args?: UseInputAttributesArgs,\n) {\n function ComponentWithInputAttributes(props: Omit<T, keyof WithInputAttributesProps>) {\n return <Component inputAttributes={useInputAttributes(args)} {...(props as T)} />;\n }\n\n ComponentWithInputAttributes.displayName = `withInputAttributes(${Component.displayName || Component.name || 'Component'})`;\n\n return ComponentWithInputAttributes;\n}\n"],"names":["FieldLabelContext","createContext","undefined","FieldLabelContextProvider","Provider","InputIdContext","InputIdContextProvider","InputDescribedByContext","InputDescribedByProvider","InputInvalidContext","InputInvalidProvider","useInputAttributes","nonLabelable","labelId","useContext","id","useFieldLabelRef","ref","TextareaCharacterCountContext","TextareaCharacterCountProvider","useTextareaCharacterCount","current","max","setCharacterCount","useEffect","withInputAttributes","Component","args","ComponentWithInputAttributes","props","_jsx","inputAttributes","displayName","name"],"mappings":";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AAA;AAAG,OAAE,CAAC;AACnC,MAAA,OAAO,MAAMC,iBAAiB,CAAC,IAAI,CAAC;AACtC,IAAA;EACF,CAAC,EAAE,CAACA,iBAAiB,EAAEF,OAAO,EAAEC,GAAG,CAAC,CAAC;AACvC;AAMM,SAAUG,mBAAmBA,CACjCC,SAAiC,EACjCC,IAA6B,EAAA;EAE7B,SAASC,4BAA4BA,CAACC,KAA8C,EAAA;IAClF,oBAAOC,cAAA,CAACJ,SAAS,EAAA;AAACK,MAAAA,eAAe,EAAEpB,kBAAkB,CAACgB,IAAI,CAAE;MAAA,GAAME;AAAW,MAAI;AACnF,EAAA;AAEAD,EAAAA,4BAA4B,CAACI,WAAW,GAAG,CAAA,oBAAA,EAAuBN,SAAS,CAACM,WAAW,IAAIN,SAAS,CAACO,IAAI,IAAI,WAAW,CAAA,CAAA,CAAG;AAE3H,EAAA,OAAOL,4BAA4B;AACrC;;;;;;;;;;;;"}
1
+ {"version":3,"file":"contexts.js","sources":["../../src/inputs/contexts.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\ntype FieldLabelContextType = {\n id?: string;\n ref?: React.RefObject<HTMLLabelElement>;\n};\n\nconst FieldLabelContext = createContext<FieldLabelContextType | undefined>(undefined);\nexport const FieldLabelContextProvider = FieldLabelContext.Provider;\n\nconst InputIdContext = createContext<string | undefined>(undefined);\nexport const InputIdContextProvider = InputIdContext.Provider;\n\nconst InputDescribedByContext = createContext<string | undefined>(undefined);\nexport const InputDescribedByProvider = InputDescribedByContext.Provider;\n\nconst InputInvalidContext = createContext<boolean | undefined>(undefined);\nexport const InputInvalidProvider = InputInvalidContext.Provider;\n\ninterface UseInputAttributesArgs {\n /** Set this to `true` if the underlying element is not directly [labelable as per the HTML specification](https://html.spec.whatwg.org/multipage/forms.html#category-label). */\n nonLabelable?: boolean;\n}\n\nexport function useInputAttributes({ nonLabelable }: UseInputAttributesArgs = {}) {\n const labelId = useContext(FieldLabelContext)?.id;\n return {\n id: useContext(InputIdContext),\n 'aria-labelledby': nonLabelable ? labelId : undefined,\n 'aria-describedby': useContext(InputDescribedByContext),\n 'aria-invalid': useContext(InputInvalidContext),\n } satisfies React.HTMLAttributes<HTMLElement>;\n}\n\nexport function useFieldLabelRef() {\n return useContext(FieldLabelContext)?.ref;\n}\n\nexport interface WithInputAttributesProps {\n inputAttributes: ReturnType<typeof useInputAttributes>;\n}\n\nexport function withInputAttributes<T extends Partial<WithInputAttributesProps>>(\n Component: React.ComponentType<T>,\n args?: UseInputAttributesArgs,\n) {\n function ComponentWithInputAttributes(props: Omit<T, keyof WithInputAttributesProps>) {\n return <Component inputAttributes={useInputAttributes(args)} {...(props as T)} />;\n }\n\n ComponentWithInputAttributes.displayName = `withInputAttributes(${Component.displayName || Component.name || 'Component'})`;\n\n return ComponentWithInputAttributes;\n}\n"],"names":["FieldLabelContext","createContext","undefined","FieldLabelContextProvider","Provider","InputIdContext","InputIdContextProvider","InputDescribedByContext","InputDescribedByProvider","InputInvalidContext","InputInvalidProvider","useInputAttributes","nonLabelable","labelId","useContext","id","useFieldLabelRef","ref","withInputAttributes","Component","args","ComponentWithInputAttributes","props","_jsx","inputAttributes","displayName","name"],"mappings":";;;;;AAOA,MAAMA,iBAAiB,gBAAGC,mBAAa,CAAoCC,SAAS,CAAC;AAC9E,MAAMC,yBAAyB,GAAGH,iBAAiB,CAACI;AAE3D,MAAMC,cAAc,gBAAGJ,mBAAa,CAAqBC,SAAS,CAAC;AAC5D,MAAMI,sBAAsB,GAAGD,cAAc,CAACD;AAErD,MAAMG,uBAAuB,gBAAGN,mBAAa,CAAqBC,SAAS,CAAC;AACrE,MAAMM,wBAAwB,GAAGD,uBAAuB,CAACH;AAEhE,MAAMK,mBAAmB,gBAAGR,mBAAa,CAAsBC,SAAS,CAAC;AAClE,MAAMQ,oBAAoB,GAAGD,mBAAmB,CAACL;SAOxCO,kBAAkBA,CAAC;AAAEC,EAAAA;IAAyC,EAAE,EAAA;AAC9E,EAAA,MAAMC,OAAO,GAAGC,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