@primer/react 0.0.0-20260619204513 → 0.0.0-20260622123513

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 (62) hide show
  1. package/CHANGELOG.md +5 -5
  2. package/dist/TextInput/TextInput.d.ts.map +1 -1
  3. package/dist/TextInput/TextInput.js +30 -63
  4. package/dist/Textarea/Textarea.d.ts.map +1 -1
  5. package/dist/Textarea/Textarea.js +109 -150
  6. package/dist/UnderlineNav/UnderlineNav-4344d9b0.css +2 -0
  7. package/dist/UnderlineNav/UnderlineNav-4344d9b0.css.map +1 -0
  8. package/dist/UnderlineNav/UnderlineNav.d.ts +2 -1
  9. package/dist/UnderlineNav/UnderlineNav.d.ts.map +1 -1
  10. package/dist/UnderlineNav/UnderlineNav.js +331 -91
  11. package/dist/UnderlineNav/UnderlineNav.module.css.js +2 -2
  12. package/dist/UnderlineNav/UnderlineNavContext.d.ts +11 -1
  13. package/dist/UnderlineNav/UnderlineNavContext.d.ts.map +1 -1
  14. package/dist/UnderlineNav/UnderlineNavContext.js +4 -1
  15. package/dist/UnderlineNav/UnderlineNavItem-b65e8fd3.css +2 -0
  16. package/dist/UnderlineNav/UnderlineNavItem-b65e8fd3.css.map +1 -0
  17. package/dist/UnderlineNav/UnderlineNavItem.d.ts +32 -1
  18. package/dist/UnderlineNav/UnderlineNavItem.d.ts.map +1 -1
  19. package/dist/UnderlineNav/UnderlineNavItem.js +38 -33
  20. package/dist/UnderlineNav/UnderlineNavItem.module.css.js +1 -1
  21. package/dist/UnderlineNav/index.d.ts +1 -1
  22. package/dist/UnderlineNav/index.d.ts.map +1 -1
  23. package/dist/UnderlineNav/styles.d.ts +16 -0
  24. package/dist/UnderlineNav/styles.d.ts.map +1 -0
  25. package/dist/UnderlineNav/styles.js +19 -0
  26. package/dist/UnderlineNav/types.d.ts +10 -0
  27. package/dist/UnderlineNav/types.d.ts.map +1 -0
  28. package/dist/UnderlineNav/utils.d.ts +0 -2
  29. package/dist/UnderlineNav/utils.d.ts.map +1 -1
  30. package/dist/UnderlineNav/utils.js +1 -2
  31. package/dist/experimental/UnderlinePanels/UnderlinePanels-e4b325b9.css +2 -0
  32. package/dist/experimental/UnderlinePanels/UnderlinePanels-e4b325b9.css.map +1 -0
  33. package/dist/experimental/UnderlinePanels/UnderlinePanels.d.ts.map +1 -1
  34. package/dist/experimental/UnderlinePanels/UnderlinePanels.js +11 -8
  35. package/dist/experimental/UnderlinePanels/UnderlinePanels.module.css.js +1 -1
  36. package/dist/internal/components/UnderlineTabbedInterface-4197ee28.css +2 -0
  37. package/dist/internal/components/UnderlineTabbedInterface-4197ee28.css.map +1 -0
  38. package/dist/internal/components/UnderlineTabbedInterface.d.ts +1 -0
  39. package/dist/internal/components/UnderlineTabbedInterface.d.ts.map +1 -1
  40. package/dist/internal/components/UnderlineTabbedInterface.js +60 -66
  41. package/dist/internal/components/UnderlineTabbedInterface.module.css.js +1 -1
  42. package/dist/utils/__tests__/useCharacterCountAnnouncement.test.d.ts +2 -0
  43. package/dist/utils/__tests__/useCharacterCountAnnouncement.test.d.ts.map +1 -0
  44. package/dist/utils/character-counter.d.ts +16 -21
  45. package/dist/utils/character-counter.d.ts.map +1 -1
  46. package/dist/utils/character-counter.js +23 -59
  47. package/dist/utils/useCharacterCountAnnouncement.d.ts +14 -0
  48. package/dist/utils/useCharacterCountAnnouncement.d.ts.map +1 -0
  49. package/dist/utils/useCharacterCountAnnouncement.js +73 -0
  50. package/generated/components.json +2 -2
  51. package/package.json +1 -1
  52. package/dist/UnderlineNav/UnderlineNav-263b4e8f.css +0 -2
  53. package/dist/UnderlineNav/UnderlineNav-263b4e8f.css.map +0 -1
  54. package/dist/UnderlineNav/UnderlineNavItem-402cd41c.css +0 -2
  55. package/dist/UnderlineNav/UnderlineNavItem-402cd41c.css.map +0 -1
  56. package/dist/UnderlineNav/UnderlineNavItemsRegistry.d.ts +0 -40
  57. package/dist/UnderlineNav/UnderlineNavItemsRegistry.d.ts.map +0 -1
  58. package/dist/UnderlineNav/UnderlineNavItemsRegistry.js +0 -6
  59. package/dist/experimental/UnderlinePanels/UnderlinePanels-162f9aed.css +0 -2
  60. package/dist/experimental/UnderlinePanels/UnderlinePanels-162f9aed.css.map +0 -1
  61. package/dist/internal/components/UnderlineTabbedInterface-1745a3d6.css +0 -2
  62. package/dist/internal/components/UnderlineTabbedInterface-1745a3d6.css.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260619204513
4
-
5
- ### Minor Changes
6
-
7
- - [#7622](https://github.com/primer/react/pull/7622) [`4d8d5e6`](https://github.com/primer/react/commit/4d8d5e6b9b0b1d394d19154369f9c37eabe7cb87) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Refactors `UnderlineNav` overflow handling to use CSS-based overflow detection instead of JavaScript width measurements, eliminating layout shift (CLS) issues and improving performance. The overflow menu is now implemented with `ActionMenu`, and item registration uses a descendant registry instead of the `React.Children` API. Consumer-facing changes: items can now be wrapped in fragments or wrapper components; the current item may appear in the overflow menu when the viewport is narrow; and the overflow menu button is right-aligned.
3
+ ## 0.0.0-20260622123513
8
4
 
9
5
  ### Patch Changes
10
6
 
11
7
  - Fake entry to force publishing
12
8
 
9
+ - [#8021](https://github.com/primer/react/pull/8021) [`09223e9`](https://github.com/primer/react/commit/09223e9dbc00edc8bd900c083c025381730cb258) Thanks [@mattcosta7](https://github.com/mattcosta7)! - Textarea: Improve typing performance by deriving the character counter in render instead of in effects, removing extra re-renders on each keystroke.
10
+
11
+ - [#8021](https://github.com/primer/react/pull/8021) [`09223e9`](https://github.com/primer/react/commit/09223e9dbc00edc8bd900c083c025381730cb258) Thanks [@mattcosta7](https://github.com/mattcosta7)! - TextInput: Improve typing performance by deriving the character counter in render instead of in effects, removing extra re-renders on each keystroke.
12
+
13
13
  ## 38.29.0
14
14
 
15
15
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":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,OAAO,CAAC,EAAE,4BAA4B,CAAC,CAAA;;;;;;;;;;;AAyNzG,wBAGE"}
@@ -1,4 +1,4 @@
1
- import React, { useState, useRef, useId, useCallback, useEffect } from 'react';
1
+ import React, { useState, useId, useCallback } from 'react';
2
2
  import { isValidElementType } from 'react-is';
3
3
  import { clsx } from 'clsx';
4
4
  import { AlertFillIcon } from '@primer/octicons-react';
@@ -8,7 +8,8 @@ import { TextInputWrapper } from '../internal/components/TextInputWrapper.js';
8
8
  import TextInputAction from '../internal/components/TextInputInnerAction.js';
9
9
  import UnstyledTextInput from '../internal/components/UnstyledTextInput.js';
10
10
  import VisuallyHidden from '../_VisuallyHidden.js';
11
- import { CharacterCounter } from '../utils/character-counter.js';
11
+ import { getCharacterCountState } from '../utils/character-counter.js';
12
+ import { useCharacterCountAnnouncement } from '../utils/useCharacterCountAnnouncement.js';
12
13
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
13
14
  import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate.js';
14
15
  import Text from '../Text/Text.js';
@@ -46,16 +47,29 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
46
47
  'data-component': dataComponent,
47
48
  ...inputProps
48
49
  }, ref) => {
50
+ var _counter$isOverLimit;
49
51
  const [isInputFocused, setIsInputFocused] = useState(false);
50
52
  const inputRef = useProvidedRefOrCreate(ref);
51
- const [characterCount, setCharacterCount] = useState('');
52
- const [isOverLimit, setIsOverLimit] = useState(false);
53
- const [screenReaderMessage, setScreenReaderMessage] = useState('');
54
- const characterCounterRef = useRef(null);
55
- const lastCountedLengthRef = useRef(null);
56
- const lastCharacterCountRef = useRef('');
57
- const lastIsOverLimitRef = useRef(false);
58
- const lastScreenReaderMessageRef = useRef('');
53
+
54
+ // For uncontrolled usage we track the length of the input's content so the
55
+ // character counter can be derived during render rather than synced from an
56
+ // effect (which would trigger an extra render on every keystroke). For
57
+ // controlled usage the `value` prop is the source of truth.
58
+ const isControlled = value !== undefined;
59
+ const [uncontrolledLength, setUncontrolledLength] = useState(() => defaultValue !== undefined ? String(defaultValue).length : 0);
60
+ const currentLength = isControlled ? String(value).length : uncontrolledLength;
61
+
62
+ // The counter and validation state are derived directly from the current
63
+ // length, so they stay in sync with the input without an extra render.
64
+ const counter = characterLimit ? getCharacterCountState(currentLength, characterLimit) : undefined;
65
+ const isOverLimit = (_counter$isOverLimit = counter === null || counter === void 0 ? void 0 : counter.isOverLimit) !== null && _counter$isOverLimit !== void 0 ? _counter$isOverLimit : false;
66
+
67
+ // The debounced screen reader announcement is encapsulated in a shared hook so
68
+ // it never blocks typing and stays consistent with Textarea.
69
+ const {
70
+ screenReaderMessage,
71
+ announce
72
+ } = useCharacterCountAnnouncement(characterLimit);
59
73
 
60
74
  // this class is necessary to style FilterSearch, plz no touchy!
61
75
  const wrapperClasses = clsx(className, 'TextInput-wrapper');
@@ -84,63 +98,16 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
84
98
  onBlur && onBlur(e_1);
85
99
  }, [onBlur]);
86
100
 
87
- // Initialize character counter
88
- useEffect(() => {
89
- if (characterLimit) {
90
- characterCounterRef.current = new CharacterCounter({
91
- onCountUpdate: (count, overLimit, message) => {
92
- if (message !== lastCharacterCountRef.current) {
93
- lastCharacterCountRef.current = message;
94
- setCharacterCount(message);
95
- }
96
- if (overLimit !== lastIsOverLimitRef.current) {
97
- lastIsOverLimitRef.current = overLimit;
98
- setIsOverLimit(overLimit);
99
- }
100
- },
101
- onScreenReaderAnnounce: message_0 => {
102
- if (message_0 !== lastScreenReaderMessageRef.current) {
103
- lastScreenReaderMessageRef.current = message_0;
104
- setScreenReaderMessage(message_0);
105
- }
106
- }
107
- });
108
- lastCountedLengthRef.current = null;
109
- return () => {
110
- var _characterCounterRef$;
111
- (_characterCounterRef$ = characterCounterRef.current) === null || _characterCounterRef$ === void 0 ? void 0 : _characterCounterRef$.cleanup();
112
- characterCounterRef.current = null;
113
- lastCountedLengthRef.current = null;
114
- lastCharacterCountRef.current = '';
115
- lastIsOverLimitRef.current = false;
116
- lastScreenReaderMessageRef.current = '';
117
- };
118
- }
119
- }, [characterLimit]);
120
-
121
- // Update character count when value changes or on mount
122
- useEffect(() => {
123
- if (characterLimit && characterCounterRef.current) {
124
- const currentValue = value !== undefined ? String(value) : defaultValue !== undefined ? String(defaultValue) : '';
125
- const currentLength = currentValue.length;
126
- if (currentLength !== lastCountedLengthRef.current) {
127
- lastCountedLengthRef.current = currentLength;
128
- characterCounterRef.current.updateCharacterCount(currentLength, characterLimit);
129
- }
130
- }
131
- }, [value, defaultValue, characterLimit]);
132
-
133
101
  // Handle input change with character counter
134
102
  const handleInputChange = useCallback(e_2 => {
135
- if (characterLimit && characterCounterRef.current) {
136
- const currentLength_0 = e_2.target.value.length;
137
- if (currentLength_0 !== lastCountedLengthRef.current) {
138
- lastCountedLengthRef.current = currentLength_0;
139
- characterCounterRef.current.updateCharacterCount(currentLength_0, characterLimit);
103
+ if (characterLimit) {
104
+ if (!isControlled) {
105
+ setUncontrolledLength(e_2.target.value.length);
140
106
  }
107
+ announce(e_2.target.value.length);
141
108
  }
142
109
  onChange === null || onChange === void 0 ? void 0 : onChange(e_2);
143
- }, [onChange, characterLimit]);
110
+ }, [onChange, characterLimit, isControlled, announce]);
144
111
  const characterCountId = useId();
145
112
  const characterCountStaticMessageId = useId();
146
113
  const isValid = isOverLimit ? 'error' : validationStatus;
@@ -217,7 +184,7 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
217
184
  "data-component": "TextInput.CharacterCounter",
218
185
  children: [isOverLimit && /*#__PURE__*/jsx(AlertFillIcon, {
219
186
  size: 16
220
- }), characterCount]
187
+ }), counter === null || counter === void 0 ? void 0 : counter.message]
221
188
  })]
222
189
  })]
223
190
  });
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../src/Textarea/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,sBAAsB,EAAe,MAAM,OAAO,CAAA;AAC/D,OAA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M,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU;IACpD;;OAEG;eACQ,OAAO;IAClB;;OAEG;gBACS,MAAM;IAClB;;OAEG;gBACS,MAAM;IAClB;;OAEG;gBACS,MAAM;IAClB;;OAEG;YACK,KAAK,CAAC,aAAa;IAC3B;;;OAGG;qBACc,MAAM;2FA6HxB,CAAA;wBAK0B,cAAc,CAAC,OAAO,QAAQ,CAAC;AAA1D,wBAA0D"}
@@ -1,9 +1,10 @@
1
1
  import { c } from 'react-compiler-runtime';
2
- import React, { useRef, useId, useEffect } from 'react';
2
+ import React, { useId, useState } from 'react';
3
3
  import { TextInputBaseWrapper } from '../internal/components/TextInputWrapper.js';
4
4
  import classes from './TextArea.module.css.js';
5
5
  import { AlertFillIcon } from '@primer/octicons-react';
6
- import { CharacterCounter } from '../utils/character-counter.js';
6
+ import { getCharacterCountState } from '../utils/character-counter.js';
7
+ import { useCharacterCountAnnouncement } from '../utils/useCharacterCountAnnouncement.js';
7
8
  import VisuallyHidden from '../_VisuallyHidden.js';
8
9
  import { clsx } from 'clsx';
9
10
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -17,7 +18,8 @@ const DEFAULT_TEXTAREA_RESIZE = 'both';
17
18
  * This component accepts all native HTML <textarea> attributes as props.
18
19
  */
19
20
  const Textarea = /*#__PURE__*/React.forwardRef((t0, ref) => {
20
- const $ = c(68);
21
+ var _counter$isOverLimit;
22
+ const $ = c(57);
21
23
  let block;
22
24
  let characterLimit;
23
25
  let className;
@@ -95,200 +97,157 @@ const Textarea = /*#__PURE__*/React.forwardRef((t0, ref) => {
95
97
  const rows = t1 === undefined ? DEFAULT_TEXTAREA_ROWS : t1;
96
98
  const cols = t2 === undefined ? DEFAULT_TEXTAREA_COLS : t2;
97
99
  const resize = t3 === undefined ? DEFAULT_TEXTAREA_RESIZE : t3;
98
- const [characterCount, setCharacterCount] = React.useState("");
99
- const [isOverLimit, setIsOverLimit] = React.useState(false);
100
- const [screenReaderMessage, setScreenReaderMessage] = React.useState("");
101
- const characterCounterRef = useRef(null);
102
100
  const characterCountId = useId();
103
101
  const characterCountStaticMessageId = useId();
102
+ const isControlled = value !== undefined;
104
103
  let t4;
105
- let t5;
106
- if ($[18] !== characterLimit) {
107
- t4 = () => {
108
- if (characterLimit) {
109
- characterCounterRef.current = new CharacterCounter({
110
- onCountUpdate: (count, overLimit, message) => {
111
- setCharacterCount(message);
112
- setIsOverLimit(overLimit);
113
- },
114
- onScreenReaderAnnounce: message_0 => {
115
- setScreenReaderMessage(message_0);
116
- }
117
- });
118
- return () => {
119
- var _characterCounterRef$;
120
- (_characterCounterRef$ = characterCounterRef.current) === null || _characterCounterRef$ === void 0 ? void 0 : _characterCounterRef$.cleanup();
121
- };
122
- }
123
- };
124
- t5 = [characterLimit];
125
- $[18] = characterLimit;
104
+ if ($[18] !== defaultValue) {
105
+ t4 = () => defaultValue !== undefined ? String(defaultValue).length : 0;
106
+ $[18] = defaultValue;
126
107
  $[19] = t4;
127
- $[20] = t5;
128
108
  } else {
129
109
  t4 = $[19];
130
- t5 = $[20];
131
110
  }
132
- useEffect(t4, t5);
133
- let t6;
134
- let t7;
135
- if ($[21] !== characterLimit || $[22] !== defaultValue || $[23] !== value) {
136
- t6 = () => {
137
- if (characterLimit && characterCounterRef.current) {
138
- const currentValue = value !== undefined ? String(value) : defaultValue !== undefined ? String(defaultValue) : "";
139
- characterCounterRef.current.updateCharacterCount(currentValue.length, characterLimit);
140
- }
141
- };
142
- t7 = [value, defaultValue, characterLimit];
143
- $[21] = characterLimit;
144
- $[22] = defaultValue;
145
- $[23] = value;
146
- $[24] = t6;
147
- $[25] = t7;
148
- } else {
149
- t6 = $[24];
150
- t7 = $[25];
151
- }
152
- useEffect(t6, t7);
153
- let t8;
154
- if ($[26] !== characterLimit || $[27] !== onChange) {
155
- t8 = e => {
111
+ const [uncontrolledLength, setUncontrolledLength] = useState(t4);
112
+ const currentLength = isControlled ? String(value).length : uncontrolledLength;
113
+ const counter = characterLimit ? getCharacterCountState(currentLength, characterLimit) : undefined;
114
+ const isOverLimit = (_counter$isOverLimit = counter === null || counter === void 0 ? void 0 : counter.isOverLimit) !== null && _counter$isOverLimit !== void 0 ? _counter$isOverLimit : false;
115
+ const {
116
+ screenReaderMessage,
117
+ announce
118
+ } = useCharacterCountAnnouncement(characterLimit);
119
+ let t5;
120
+ if ($[20] !== announce || $[21] !== characterLimit || $[22] !== isControlled || $[23] !== onChange) {
121
+ t5 = e => {
156
122
  var _onChange;
157
- if (characterLimit && characterCounterRef.current) {
158
- characterCounterRef.current.updateCharacterCount(e.target.value.length, characterLimit);
123
+ if (characterLimit) {
124
+ if (!isControlled) {
125
+ setUncontrolledLength(e.target.value.length);
126
+ }
127
+ announce(e.target.value.length);
159
128
  }
160
129
  (_onChange = onChange) === null || _onChange === void 0 ? void 0 : _onChange(e);
161
130
  };
162
- $[26] = characterLimit;
163
- $[27] = onChange;
164
- $[28] = t8;
131
+ $[20] = announce;
132
+ $[21] = characterLimit;
133
+ $[22] = isControlled;
134
+ $[23] = onChange;
135
+ $[24] = t5;
165
136
  } else {
166
- t8 = $[28];
137
+ t5 = $[24];
167
138
  }
168
- const handleTextareaChange = t8;
139
+ const handleTextareaChange = t5;
169
140
  const isValid = isOverLimit ? "error" : validationStatus;
170
- const t9 = isValid === "error" ? "true" : "false";
171
- let t10;
172
- if ($[29] !== maxHeight || $[30] !== minHeight || $[31] !== style) {
173
- t10 = {
141
+ const t6 = isValid === "error" ? "true" : "false";
142
+ let t7;
143
+ if ($[25] !== maxHeight || $[26] !== minHeight || $[27] !== style) {
144
+ t7 = {
174
145
  minHeight,
175
146
  maxHeight,
176
147
  ...style
177
148
  };
178
- $[29] = maxHeight;
179
- $[30] = minHeight;
180
- $[31] = style;
181
- $[32] = t10;
149
+ $[25] = maxHeight;
150
+ $[26] = minHeight;
151
+ $[27] = style;
152
+ $[28] = t7;
182
153
  } else {
183
- t10 = $[32];
154
+ t7 = $[28];
184
155
  }
185
- let t11;
186
- if ($[33] !== characterCountStaticMessageId || $[34] !== characterLimit || $[35] !== rest) {
187
- t11 = characterLimit ? [characterCountStaticMessageId, rest["aria-describedby"]].filter(Boolean).join(" ") || undefined : rest["aria-describedby"];
188
- $[33] = characterCountStaticMessageId;
189
- $[34] = characterLimit;
190
- $[35] = rest;
191
- $[36] = t11;
156
+ let t8;
157
+ if ($[29] !== characterCountStaticMessageId || $[30] !== characterLimit || $[31] !== rest) {
158
+ t8 = characterLimit ? [characterCountStaticMessageId, rest["aria-describedby"]].filter(Boolean).join(" ") || undefined : rest["aria-describedby"];
159
+ $[29] = characterCountStaticMessageId;
160
+ $[30] = characterLimit;
161
+ $[31] = rest;
162
+ $[32] = t8;
192
163
  } else {
193
- t11 = $[36];
164
+ t8 = $[32];
194
165
  }
195
- let t12;
196
- if ($[37] !== cols || $[38] !== defaultValue || $[39] !== disabled || $[40] !== handleTextareaChange || $[41] !== ref || $[42] !== required || $[43] !== resize || $[44] !== rest || $[45] !== rows || $[46] !== t10 || $[47] !== t11 || $[48] !== t9 || $[49] !== value) {
197
- t12 = /*#__PURE__*/jsx("textarea", {
166
+ let t9;
167
+ if ($[33] !== cols || $[34] !== defaultValue || $[35] !== disabled || $[36] !== handleTextareaChange || $[37] !== ref || $[38] !== required || $[39] !== resize || $[40] !== rest || $[41] !== rows || $[42] !== t6 || $[43] !== t7 || $[44] !== t8 || $[45] !== value) {
168
+ t9 = /*#__PURE__*/jsx("textarea", {
198
169
  value: value,
199
170
  defaultValue: defaultValue,
200
171
  "data-resize": resize,
201
172
  "aria-required": required,
202
- "aria-invalid": t9,
173
+ "aria-invalid": t6,
203
174
  ref: ref,
204
175
  disabled: disabled,
205
176
  rows: rows,
206
177
  cols: cols,
207
178
  className: classes.TextArea,
208
179
  onChange: handleTextareaChange,
209
- style: t10,
180
+ style: t7,
210
181
  ...rest,
211
- "aria-describedby": t11
182
+ "aria-describedby": t8
212
183
  });
213
- $[37] = cols;
214
- $[38] = defaultValue;
215
- $[39] = disabled;
216
- $[40] = handleTextareaChange;
217
- $[41] = ref;
218
- $[42] = required;
219
- $[43] = resize;
220
- $[44] = rest;
221
- $[45] = rows;
222
- $[46] = t10;
223
- $[47] = t11;
224
- $[48] = t9;
225
- $[49] = value;
226
- $[50] = t12;
184
+ $[33] = cols;
185
+ $[34] = defaultValue;
186
+ $[35] = disabled;
187
+ $[36] = handleTextareaChange;
188
+ $[37] = ref;
189
+ $[38] = required;
190
+ $[39] = resize;
191
+ $[40] = rest;
192
+ $[41] = rows;
193
+ $[42] = t6;
194
+ $[43] = t7;
195
+ $[44] = t8;
196
+ $[45] = value;
197
+ $[46] = t9;
227
198
  } else {
228
- t12 = $[50];
199
+ t9 = $[46];
229
200
  }
230
- let t13;
231
- if ($[51] !== block || $[52] !== className || $[53] !== contrast || $[54] !== disabled || $[55] !== isValid || $[56] !== t12) {
232
- t13 = /*#__PURE__*/jsx(TextInputBaseWrapper, {
201
+ let t10;
202
+ if ($[47] !== block || $[48] !== className || $[49] !== contrast || $[50] !== disabled || $[51] !== isValid || $[52] !== t9) {
203
+ t10 = /*#__PURE__*/jsx(TextInputBaseWrapper, {
233
204
  validationStatus: isValid,
234
205
  disabled: disabled,
235
206
  block: block,
236
207
  contrast: contrast,
237
208
  className: className,
238
- children: t12
209
+ children: t9
239
210
  });
240
- $[51] = block;
241
- $[52] = className;
242
- $[53] = contrast;
243
- $[54] = disabled;
244
- $[55] = isValid;
245
- $[56] = t12;
246
- $[57] = t13;
247
- } else {
248
- t13 = $[57];
249
- }
250
- let t14;
251
- if ($[58] !== characterCount || $[59] !== characterCountId || $[60] !== characterCountStaticMessageId || $[61] !== characterLimit || $[62] !== isOverLimit || $[63] !== screenReaderMessage) {
252
- t14 = characterLimit && /*#__PURE__*/jsxs(Fragment, {
253
- children: [/*#__PURE__*/jsx(VisuallyHidden, {
254
- "aria-live": "polite",
255
- role: "status",
256
- children: screenReaderMessage
257
- }), /*#__PURE__*/jsxs(VisuallyHidden, {
258
- id: characterCountStaticMessageId,
259
- children: ["You can enter up to ", characterLimit, " ", characterLimit === 1 ? "character" : "characters"]
260
- }), /*#__PURE__*/jsxs(Text, {
261
- "aria-hidden": "true",
262
- id: characterCountId,
263
- size: "small",
264
- className: clsx(classes.CharacterCounter, isOverLimit && classes["CharacterCounter--error"]),
265
- children: [isOverLimit && /*#__PURE__*/jsx(AlertFillIcon, {
266
- size: 16
267
- }), characterCount]
268
- })]
269
- });
270
- $[58] = characterCount;
271
- $[59] = characterCountId;
272
- $[60] = characterCountStaticMessageId;
273
- $[61] = characterLimit;
274
- $[62] = isOverLimit;
275
- $[63] = screenReaderMessage;
276
- $[64] = t14;
211
+ $[47] = block;
212
+ $[48] = className;
213
+ $[49] = contrast;
214
+ $[50] = disabled;
215
+ $[51] = isValid;
216
+ $[52] = t9;
217
+ $[53] = t10;
277
218
  } else {
278
- t14 = $[64];
219
+ t10 = $[53];
279
220
  }
280
- let t15;
281
- if ($[65] !== t13 || $[66] !== t14) {
282
- t15 = /*#__PURE__*/jsxs(Fragment, {
283
- children: [t13, t14]
221
+ const t11 = characterLimit && /*#__PURE__*/jsxs(Fragment, {
222
+ children: [/*#__PURE__*/jsx(VisuallyHidden, {
223
+ "aria-live": "polite",
224
+ role: "status",
225
+ children: screenReaderMessage
226
+ }), /*#__PURE__*/jsxs(VisuallyHidden, {
227
+ id: characterCountStaticMessageId,
228
+ children: ["You can enter up to ", characterLimit, " ", characterLimit === 1 ? "character" : "characters"]
229
+ }), /*#__PURE__*/jsxs(Text, {
230
+ "aria-hidden": "true",
231
+ id: characterCountId,
232
+ size: "small",
233
+ className: clsx(classes.CharacterCounter, isOverLimit && classes["CharacterCounter--error"]),
234
+ children: [isOverLimit && /*#__PURE__*/jsx(AlertFillIcon, {
235
+ size: 16
236
+ }), counter === null || counter === void 0 ? void 0 : counter.message]
237
+ })]
238
+ });
239
+ let t12;
240
+ if ($[54] !== t10 || $[55] !== t11) {
241
+ t12 = /*#__PURE__*/jsxs(Fragment, {
242
+ children: [t10, t11]
284
243
  });
285
- $[65] = t13;
286
- $[66] = t14;
287
- $[67] = t15;
244
+ $[54] = t10;
245
+ $[55] = t11;
246
+ $[56] = t12;
288
247
  } else {
289
- t15 = $[67];
248
+ t12 = $[56];
290
249
  }
291
- return t15;
250
+ return t12;
292
251
  });
293
252
  Textarea.displayName = 'Textarea';
294
253
  Textarea.__SLOT__ = Symbol('Textarea');
@@ -0,0 +1,2 @@
1
+ .prc-UnderlineNav-MenuItemContent-3J7gB{align-items:center;display:flex;justify-content:space-between}.prc-UnderlineNav-MoreButton-Y8soj{background:transparent;border:0;box-shadow:none;font-weight:var(--base-text-weight-normal,400);margin:0;padding:var(--base-size-4,.25rem) var(--base-size-8,.5rem)}.prc-UnderlineNav-MoreButton-Y8soj>[data-component=trailingVisual]{margin-left:0}
2
+ /*# sourceMappingURL=UnderlineNav-4344d9b0.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/UnderlineNav/UnderlineNav.module.css.js"],"names":[],"mappings":"AAAA,wCAEE,kBAAmB,CADnB,YAAa,CAEb,6BACF,CAGA,mCAGE,sBAAuB,CADvB,QAAS,CAGT,eAAgB,CADhB,8CAA2C,CAH3C,QAAS,CAQT,0DAKF,CAHE,mEACE,aACF","file":"UnderlineNav-4344d9b0.css","sourcesContent":[".MenuItemContent {\n display: flex;\n align-items: center;\n justify-content: space-between;\n}\n\n/* More button styles migrated from styles.ts (was moreBtnStyles) */\n.MoreButton {\n margin: 0; /* reset Safari extra margin */\n border: 0;\n background: transparent;\n font-weight: var(--base-text-weight-normal);\n box-shadow: none;\n padding-top: var(--base-size-4);\n padding-bottom: var(--base-size-4);\n padding-left: var(--base-size-8);\n padding-right: var(--base-size-8);\n\n & > [data-component='trailingVisual'] {\n margin-left: 0;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type React from 'react';
1
+ import React from 'react';
2
2
  export type UnderlineNavProps = {
3
3
  children: React.ReactNode;
4
4
  'aria-label'?: React.AriaAttributes['aria-label'];
@@ -15,5 +15,6 @@ export type UnderlineNavProps = {
15
15
  */
16
16
  variant?: 'inset' | 'flush';
17
17
  };
18
+ export declare const MORE_BTN_WIDTH = 86;
18
19
  export declare const UnderlineNav: React.ForwardRefExoticComponent<UnderlineNavProps & React.RefAttributes<unknown>>;
19
20
  //# sourceMappingURL=UnderlineNav.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UnderlineNav.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNav.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAgB9B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IACjD,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;CAC5B,CAAA;AAED,eAAO,MAAM,YAAY,mFAsIxB,CAAA"}
1
+ {"version":3,"file":"UnderlineNav.d.ts","sourceRoot":"","sources":["../../src/UnderlineNav/UnderlineNav.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkD,MAAM,OAAO,CAAA;AAqBtE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IACjD,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;CAC5B,CAAA;AAGD,eAAO,MAAM,cAAc,KAAK,CAAA;AAsGhC,eAAO,MAAM,YAAY,mFA0SxB,CAAA"}