@primer/react 0.0.0-20260623140715 → 0.0.0-20260623155122

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 (32) hide show
  1. package/CHANGELOG.md +5 -5
  2. package/dist/Autocomplete/AutocompleteMenu.d.ts.map +1 -1
  3. package/dist/Autocomplete/AutocompleteMenu.js +12 -7
  4. package/dist/ConfirmationDialog/useConfirm.d.ts.map +1 -1
  5. package/dist/ConfirmationDialog/useConfirm.js +4 -8
  6. package/dist/Dialog/Dialog.d.ts.map +1 -1
  7. package/dist/Dialog/Dialog.js +1 -0
  8. package/dist/LabelGroup/LabelGroup.d.ts.map +1 -1
  9. package/dist/LabelGroup/LabelGroup.js +35 -30
  10. package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
  11. package/dist/SelectPanel/SelectPanel.js +12 -7
  12. package/dist/TextInput/TextInput.d.ts.map +1 -1
  13. package/dist/TextInput/TextInput.js +68 -27
  14. package/dist/Textarea/Textarea.d.ts.map +1 -1
  15. package/dist/Textarea/Textarea.js +186 -158
  16. package/dist/ToggleSwitch/ToggleSwitch.d.ts.map +1 -1
  17. package/dist/ToggleSwitch/ToggleSwitch.js +7 -8
  18. package/dist/TreeView/TreeView.d.ts.map +1 -1
  19. package/dist/_VisuallyHidden.js +2 -2
  20. package/dist/_VisuallyHidden.module.css.js +2 -2
  21. package/dist/experimental/SelectPanel2/SelectPanel.d.ts.map +1 -1
  22. package/dist/experimental/SelectPanel2/SelectPanel.js +2 -0
  23. package/dist/hooks/useMedia.d.ts.map +1 -1
  24. package/dist/hooks/useMedia.js +49 -46
  25. package/dist/internal/components/ValidationAnimationContainer.d.ts.map +1 -1
  26. package/dist/internal/components/ValidationAnimationContainer.js +18 -32
  27. package/dist/live-region/Announce.d.ts.map +1 -1
  28. package/dist/live-region/Announce.js +36 -51
  29. package/dist/utils/character-counter.d.ts +21 -16
  30. package/dist/utils/character-counter.d.ts.map +1 -1
  31. package/dist/utils/character-counter.js +59 -23
  32. package/package.json +1 -1
@@ -1,48 +1,34 @@
1
1
  import { c } from 'react-compiler-runtime';
2
- import { useState, useEffect } from 'react';
2
+ import { useState } from 'react';
3
3
  import classes from './ValidationAnimationContainer.module.css.js';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
 
6
6
  const ValidationAnimationContainer = t0 => {
7
- const $ = c(10);
7
+ const $ = c(7);
8
8
  const {
9
9
  show,
10
10
  children
11
11
  } = t0;
12
12
  const [shouldRender, setRender] = useState(show);
13
+ if (show && !shouldRender) {
14
+ setRender(true);
15
+ }
13
16
  let t1;
14
- let t2;
15
17
  if ($[0] !== show) {
16
18
  t1 = () => {
17
- if (show) {
18
- setRender(true);
19
+ if (!show) {
20
+ setRender(false);
19
21
  }
20
22
  };
21
- t2 = [show];
22
23
  $[0] = show;
23
24
  $[1] = t1;
24
- $[2] = t2;
25
25
  } else {
26
26
  t1 = $[1];
27
- t2 = $[2];
28
27
  }
29
- useEffect(t1, t2);
30
- let t3;
31
- if ($[3] !== show) {
32
- t3 = () => {
33
- if (!show) {
34
- setRender(false);
35
- }
36
- };
37
- $[3] = show;
38
- $[4] = t3;
39
- } else {
40
- t3 = $[4];
41
- }
42
- const onAnimationEnd = t3;
43
- let t4;
44
- if ($[5] !== children || $[6] !== onAnimationEnd || $[7] !== shouldRender || $[8] !== show) {
45
- t4 = shouldRender ? /*#__PURE__*/jsx("div", {
28
+ const onAnimationEnd = t1;
29
+ let t2;
30
+ if ($[2] !== children || $[3] !== onAnimationEnd || $[4] !== shouldRender || $[5] !== show) {
31
+ t2 = shouldRender ? /*#__PURE__*/jsx("div", {
46
32
  style: {
47
33
  height: show ? "auto" : 0,
48
34
  overflow: "hidden"
@@ -54,15 +40,15 @@ const ValidationAnimationContainer = t0 => {
54
40
  children: children
55
41
  })
56
42
  }) : null;
57
- $[5] = children;
58
- $[6] = onAnimationEnd;
59
- $[7] = shouldRender;
60
- $[8] = show;
61
- $[9] = t4;
43
+ $[2] = children;
44
+ $[3] = onAnimationEnd;
45
+ $[4] = shouldRender;
46
+ $[5] = show;
47
+ $[6] = t2;
62
48
  } else {
63
- t4 = $[9];
49
+ t2 = $[6];
64
50
  }
65
- return t4;
51
+ return t2;
66
52
  };
67
53
 
68
54
  export { ValidationAnimationContainer as default };
@@ -1 +1 @@
1
- {"version":3,"file":"Announce.d.ts","sourceRoot":"","sources":["../../src/live-region/Announce.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAA;AAEjE,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,IAAI,gBAAgB,CACxE,EAAE,EACF,KAAK,EACL;IACE;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CACpC,CACF,CAAA;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,qBAsGtF"}
1
+ {"version":3,"file":"Announce.d.ts","sourceRoot":"","sources":["../../src/live-region/Announce.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAA;AAEjE,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,IAAI,gBAAgB,CACxE,EAAE,EACF,KAAK,EACL;IACE;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CACpC,CACF,CAAA;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,qBAwGtF"}
@@ -1,6 +1,6 @@
1
1
  import { c } from 'react-compiler-runtime';
2
2
  import { announceFromElement } from '@primer/live-region-element';
3
- import { useRef, useEffect } from 'react';
3
+ import { useRef, useState, useEffect } from 'react';
4
4
  import { useEffectOnce } from '../internal/hooks/useEffectOnce.js';
5
5
  import { useEffectCallback } from '../internal/hooks/useEffectCallback.js';
6
6
  import { jsx } from 'react/jsx-runtime';
@@ -11,7 +11,7 @@ import { jsx } from 'react/jsx-runtime';
11
11
  * will also announce any changes to the text content of `children`
12
12
  */
13
13
  function Announce(props) {
14
- const $ = c(24);
14
+ const $ = c(25);
15
15
  let children;
16
16
  let delayMs;
17
17
  let rest;
@@ -51,10 +51,10 @@ function Announce(props) {
51
51
  const hidden = t2 === undefined ? false : t2;
52
52
  const politeness = t3 === undefined ? "polite" : t3;
53
53
  const ref = useRef(null);
54
- const previousAnnouncementText = useRef(null);
54
+ const [previousAnnouncementText, setPreviousAnnouncementText] = useState(null);
55
55
  const savedAnnouncement = useRef(null);
56
56
  let t4;
57
- if ($[8] !== delayMs || $[9] !== hidden || $[10] !== politeness) {
57
+ if ($[8] !== delayMs || $[9] !== hidden || $[10] !== politeness || $[11] !== previousAnnouncementText) {
58
58
  t4 = () => {
59
59
  var _savedAnnouncement$cu;
60
60
  const {
@@ -70,10 +70,14 @@ function Announce(props) {
70
70
  if (!textContent) {
71
71
  return;
72
72
  }
73
- if (textContent === previousAnnouncementText.current) {
73
+ if (textContent === previousAnnouncementText) {
74
74
  return;
75
75
  }
76
- if (!isVisible(element)) {
76
+ const style = window.getComputedStyle(element);
77
+ if (style.display === "none") {
78
+ return;
79
+ }
80
+ if (style.visibility === "hidden") {
77
81
  return;
78
82
  }
79
83
  (_savedAnnouncement$cu = savedAnnouncement.current) === null || _savedAnnouncement$cu === void 0 ? void 0 : _savedAnnouncement$cu.cancel();
@@ -83,33 +87,34 @@ function Announce(props) {
83
87
  politeness,
84
88
  delayMs
85
89
  });
86
- previousAnnouncementText.current = textContent;
90
+ setPreviousAnnouncementText(textContent);
87
91
  };
88
92
  $[8] = delayMs;
89
93
  $[9] = hidden;
90
94
  $[10] = politeness;
91
- $[11] = t4;
95
+ $[11] = previousAnnouncementText;
96
+ $[12] = t4;
92
97
  } else {
93
- t4 = $[11];
98
+ t4 = $[12];
94
99
  }
95
100
  const announce = useEffectCallback(t4);
96
101
  let t5;
97
- if ($[12] !== announce || $[13] !== announceOnShow) {
102
+ if ($[13] !== announce || $[14] !== announceOnShow) {
98
103
  t5 = () => {
99
104
  if (announceOnShow) {
100
105
  announce();
101
106
  }
102
107
  };
103
- $[12] = announce;
104
- $[13] = announceOnShow;
105
- $[14] = t5;
108
+ $[13] = announce;
109
+ $[14] = announceOnShow;
110
+ $[15] = t5;
106
111
  } else {
107
- t5 = $[14];
112
+ t5 = $[15];
108
113
  }
109
114
  useEffectOnce(t5);
110
115
  let t6;
111
116
  let t7;
112
- if ($[15] !== announce) {
117
+ if ($[16] !== announce) {
113
118
  t6 = () => {
114
119
  const {
115
120
  current: container
@@ -130,17 +135,17 @@ function Announce(props) {
130
135
  };
131
136
  };
132
137
  t7 = [announce];
133
- $[15] = announce;
134
- $[16] = t6;
135
- $[17] = t7;
138
+ $[16] = announce;
139
+ $[17] = t6;
140
+ $[18] = t7;
136
141
  } else {
137
- t6 = $[16];
138
- t7 = $[17];
142
+ t6 = $[17];
143
+ t7 = $[18];
139
144
  }
140
145
  useEffect(t6, t7);
141
146
  let t8;
142
147
  let t9;
143
- if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
148
+ if ($[19] === Symbol.for("react.memo_cache_sentinel")) {
144
149
  t8 = () => () => {
145
150
  if (savedAnnouncement.current !== null) {
146
151
  savedAnnouncement.current.cancel();
@@ -148,26 +153,26 @@ function Announce(props) {
148
153
  }
149
154
  };
150
155
  t9 = [];
151
- $[18] = t8;
152
- $[19] = t9;
156
+ $[19] = t8;
157
+ $[20] = t9;
153
158
  } else {
154
- t8 = $[18];
155
- t9 = $[19];
159
+ t8 = $[19];
160
+ t9 = $[20];
156
161
  }
157
162
  useEffect(t8, t9);
158
163
  let t10;
159
- if ($[20] !== BaseComponent || $[21] !== children || $[22] !== rest) {
164
+ if ($[21] !== BaseComponent || $[22] !== children || $[23] !== rest) {
160
165
  t10 = /*#__PURE__*/jsx(BaseComponent, {
161
166
  ...rest,
162
167
  ref: ref,
163
168
  children: children
164
169
  });
165
- $[20] = BaseComponent;
166
- $[21] = children;
167
- $[22] = rest;
168
- $[23] = t10;
170
+ $[21] = BaseComponent;
171
+ $[22] = children;
172
+ $[23] = rest;
173
+ $[24] = t10;
169
174
  } else {
170
- t10 = $[23];
175
+ t10 = $[24];
171
176
  }
172
177
  return t10;
173
178
  }
@@ -181,24 +186,4 @@ function getTextContent(element) {
181
186
  return value ? value.trim() : '';
182
187
  }
183
188
 
184
- /**
185
- * Determine if an element is visible (not hidden via `display: none` or
186
- * `visibility: hidden`). Prefers the native `checkVisibility()` API when
187
- * available and falls back to `getComputedStyle` for older browsers.
188
- */
189
- function isVisible(element) {
190
- if (typeof element.checkVisibility === 'function') {
191
- return element.checkVisibility({
192
- // `visibilityProperty` is the standard option name (Chrome 116+, Firefox
193
- // 125+, Safari 17.4+); `checkVisibilityCSS` is the legacy Chromium name
194
- // (Chrome 105+). Unknown options are ignored, so passing both ensures
195
- // `visibility: hidden` is treated as not visible across all engines.
196
- visibilityProperty: true,
197
- checkVisibilityCSS: true
198
- });
199
- }
200
- const style = window.getComputedStyle(element);
201
- return style.display !== 'none' && style.visibility !== 'hidden';
202
- }
203
-
204
189
  export { Announce };
@@ -1,22 +1,27 @@
1
1
  /**
2
- * Shared character counting helpers for text inputs with character limits.
3
- * Provides the pure derivation used to render the counter and validation state.
2
+ * Shared character counting functionality for text inputs with character limits.
3
+ * Handles real-time character count updates, validation, and aria-live announcements.
4
4
  */
5
- export declare const SCREEN_READER_DELAY = 500;
6
- export interface CharacterCountState {
5
+ export interface CharacterCounterCallbacks {
6
+ onCountUpdate: (count: number, isOverLimit: boolean, message: string) => void;
7
+ onScreenReaderAnnounce: (message: string) => void;
8
+ }
9
+ export declare class CharacterCounter {
10
+ private announceTimeout;
11
+ private callbacks;
12
+ private isInitialLoad;
13
+ constructor(callbacks: CharacterCounterCallbacks);
14
+ /**
15
+ * Update the character count based on current input value
16
+ */
17
+ updateCharacterCount(currentLength: number, maxLength: number): void;
7
18
  /**
8
- * Number of characters remaining before the limit is reached, or the number of
9
- * characters over the limit when it has been exceeded.
19
+ * Announce character count to screen readers with debouncing
10
20
  */
11
- count: number;
12
- /** Whether the current length exceeds the limit. */
13
- isOverLimit: boolean;
14
- /** Human readable description of the remaining or over count. */
15
- message: string;
21
+ private announceToScreenReader;
22
+ /**
23
+ * Clean up any pending timeouts
24
+ */
25
+ cleanup(): void;
16
26
  }
17
- /**
18
- * Compute the character count state for a given length and limit. This is a pure
19
- * function so the counter can be derived during render without component state.
20
- */
21
- export declare function getCharacterCountState(currentLength: number, maxLength: number): CharacterCountState;
22
27
  //# sourceMappingURL=character-counter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"character-counter.d.ts","sourceRoot":"","sources":["../../src/utils/character-counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,mBAAmB,MAAM,CAAA;AAEtC,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;IACb,oDAAoD;IACpD,WAAW,EAAE,OAAO,CAAA;IACpB,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,mBAAmB,CAmBpG"}
1
+ {"version":3,"file":"character-counter.d.ts","sourceRoot":"","sources":["../../src/utils/character-counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7E,sBAAsB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAClD;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,aAAa,CAAgB;gBAEzB,SAAS,EAAE,yBAAyB;IAIhD;;OAEG;IACH,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IA0BpE;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAc9B;;OAEG;IACH,OAAO,IAAI,IAAI;CAKhB"}
@@ -1,30 +1,66 @@
1
1
  /**
2
- * Shared character counting helpers for text inputs with character limits.
3
- * Provides the pure derivation used to render the counter and validation state.
2
+ * Shared character counting functionality for text inputs with character limits.
3
+ * Handles real-time character count updates, validation, and aria-live announcements.
4
4
  */
5
5
 
6
6
  const SCREEN_READER_DELAY = 500;
7
- /**
8
- * Compute the character count state for a given length and limit. This is a pure
9
- * function so the counter can be derived during render without component state.
10
- */
11
- function getCharacterCountState(currentLength, maxLength) {
12
- const charactersRemaining = maxLength - currentLength;
13
- if (charactersRemaining >= 0) {
14
- const characterText = charactersRemaining === 1 ? 'character' : 'characters';
15
- return {
16
- count: charactersRemaining,
17
- isOverLimit: false,
18
- message: `${charactersRemaining} ${characterText} remaining`
19
- };
7
+ class CharacterCounter {
8
+ announceTimeout = null;
9
+ isInitialLoad = true;
10
+ constructor(callbacks) {
11
+ this.callbacks = callbacks;
12
+ }
13
+
14
+ /**
15
+ * Update the character count based on current input value
16
+ */
17
+ updateCharacterCount(currentLength, maxLength) {
18
+ const charactersRemaining = maxLength - currentLength;
19
+ // eslint-disable-next-line no-useless-assignment
20
+ let message = '';
21
+ if (charactersRemaining >= 0) {
22
+ const characterText = charactersRemaining === 1 ? 'character' : 'characters';
23
+ message = `${charactersRemaining} ${characterText} remaining`;
24
+ this.callbacks.onCountUpdate(charactersRemaining, false, message);
25
+ } else {
26
+ const charactersOver = -charactersRemaining;
27
+ const characterText = charactersOver === 1 ? 'character' : 'characters';
28
+ message = `${charactersOver} ${characterText} over`;
29
+ this.callbacks.onCountUpdate(charactersOver, true, message);
30
+ }
31
+ if (!this.isInitialLoad) {
32
+ this.announceToScreenReader(message);
33
+ }
34
+
35
+ // After first update, set isInitialLoad to false
36
+ if (this.isInitialLoad) {
37
+ this.isInitialLoad = false;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Announce character count to screen readers with debouncing
43
+ */
44
+ announceToScreenReader(message) {
45
+ if (this.announceTimeout) {
46
+ clearTimeout(this.announceTimeout);
47
+ }
48
+ if (typeof window === 'undefined' || typeof window.setTimeout !== 'function') {
49
+ return;
50
+ }
51
+ this.announceTimeout = window.setTimeout(() => {
52
+ this.callbacks.onScreenReaderAnnounce(message);
53
+ }, SCREEN_READER_DELAY);
54
+ }
55
+
56
+ /**
57
+ * Clean up any pending timeouts
58
+ */
59
+ cleanup() {
60
+ if (this.announceTimeout) {
61
+ clearTimeout(this.announceTimeout);
62
+ }
20
63
  }
21
- const charactersOver = -charactersRemaining;
22
- const characterText = charactersOver === 1 ? 'character' : 'characters';
23
- return {
24
- count: charactersOver,
25
- isOverLimit: true,
26
- message: `${charactersOver} ${characterText} over`
27
- };
28
64
  }
29
65
 
30
- export { SCREEN_READER_DELAY, getCharacterCountState };
66
+ export { CharacterCounter };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260623140715",
4
+ "version": "0.0.0-20260623155122",
5
5
  "description": "An implementation of GitHub's Primer Design System using React",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",