@primer/react 38.32.0-rc.7fd08e0cc → 38.32.0-rc.94f147e58
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.
- package/CHANGELOG.md +6 -0
- package/dist/ActionBar/ActionBar.js +130 -424
- package/dist/FilteredActionList/FilteredActionList.js +66 -155
- package/dist/FilteredActionList/useAnnouncements.js +66 -138
- package/dist/LabelGroup/LabelGroup.js +76 -110
- package/dist/Overlay/Overlay.js +45 -169
- package/dist/TextInput/TextInput.js +7 -7
- package/dist/ToggleSwitch/ToggleSwitch.js +167 -186
- package/dist/TreeView/TreeView.js +309 -814
- package/dist/experimental/UnderlinePanels/UnderlinePanels.js +38 -95
- package/dist/hooks/useControllableState.js +3 -3
- package/dist/hooks/useMedia.js +44 -43
- package/dist/internal/components/ValidationAnimationContainer.js +40 -34
- package/package.json +3 -1
|
@@ -6,7 +6,6 @@ import { isSlot } from "../../utils/is-slot.js";
|
|
|
6
6
|
import { createComponent } from "../../utils/create-component.js";
|
|
7
7
|
import { UnderlineItem, UnderlineItemList, UnderlineWrapper } from "../../internal/components/UnderlineTabbedInterface.js";
|
|
8
8
|
import UnderlinePanels_module_css_default from "./UnderlinePanels.module.css.js";
|
|
9
|
-
import { c } from "react-compiler-runtime";
|
|
10
9
|
import { clsx } from "clsx";
|
|
11
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
11
|
import React, { Children, cloneElement, createContext, isValidElement, useContext, useMemo, useRef, useState } from "react";
|
|
@@ -22,7 +21,7 @@ const UnderlinePanels = ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabel
|
|
|
22
21
|
const wrapperRef = useRef(null);
|
|
23
22
|
const listRef = useRef(null);
|
|
24
23
|
const parentId = useId$1(props.id);
|
|
25
|
-
const [
|
|
24
|
+
const [tabs, tabPanels, tabsHaveIcons] = useMemo(() => {
|
|
26
25
|
let tabIndex = 0;
|
|
27
26
|
let panelIndex = 0;
|
|
28
27
|
const childrenWithProps = Children.map(children, (child) => {
|
|
@@ -32,10 +31,10 @@ const UnderlinePanels = ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabel
|
|
|
32
31
|
});
|
|
33
32
|
const tabs = [];
|
|
34
33
|
const tabPanels = [];
|
|
35
|
-
for (const
|
|
36
|
-
if (!/*#__PURE__*/ isValidElement(
|
|
37
|
-
if (
|
|
38
|
-
else if (
|
|
34
|
+
for (const child of Children.toArray(childrenWithProps)) {
|
|
35
|
+
if (!/*#__PURE__*/ isValidElement(child)) continue;
|
|
36
|
+
if (child.type === Tab || isSlot(child, Tab)) tabs.push(child);
|
|
37
|
+
else if (child.type === Panel || isSlot(child, Panel)) tabPanels.push(child);
|
|
39
38
|
}
|
|
40
39
|
return [
|
|
41
40
|
tabs,
|
|
@@ -53,20 +52,20 @@ const UnderlinePanels = ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabel
|
|
|
53
52
|
}, [iconsVisible]);
|
|
54
53
|
const listWidthRef = useRef(0);
|
|
55
54
|
useResizeObserver((entries) => {
|
|
56
|
-
if (!
|
|
55
|
+
if (!tabsHaveIcons) return;
|
|
57
56
|
if (!iconsVisibleRef.current) return;
|
|
58
57
|
listWidthRef.current = entries[0].contentRect.width;
|
|
59
58
|
}, listRef, []);
|
|
60
59
|
useResizeObserver((resizeObserverEntries) => {
|
|
61
|
-
if (!
|
|
60
|
+
if (!tabsHaveIcons) return;
|
|
62
61
|
const wrapperWidth = resizeObserverEntries[0].contentRect.width;
|
|
63
62
|
setIconsVisible(wrapperWidth > listWidthRef.current);
|
|
64
63
|
}, wrapperRef, []);
|
|
65
|
-
!(
|
|
66
|
-
const ariaSelected = /*#__PURE__*/ React.isValidElement(
|
|
64
|
+
!(tabs.filter((tab) => {
|
|
65
|
+
const ariaSelected = /*#__PURE__*/ React.isValidElement(tab) && tab.props["aria-selected"];
|
|
67
66
|
return ariaSelected === true || ariaSelected === "true";
|
|
68
67
|
}).length <= 1) && invariant(false, "Only one tab can be selected at a time.");
|
|
69
|
-
!(
|
|
68
|
+
!(tabs.length === tabPanels.length) && invariant(false, `The number of tabs and panels must be equal. Counted ${tabs.length} tabs and ${tabPanels.length} panels.`);
|
|
70
69
|
return /*#__PURE__*/ jsx(UnderlinePanelsContext.Provider, {
|
|
71
70
|
value: contextValue,
|
|
72
71
|
children: /*#__PURE__*/ jsxs(TabContainerComponent, { children: [/*#__PURE__*/ jsx(UnderlineWrapper, {
|
|
@@ -80,100 +79,44 @@ const UnderlinePanels = ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabel
|
|
|
80
79
|
"aria-label": ariaLabel,
|
|
81
80
|
"aria-labelledby": ariaLabelledBy,
|
|
82
81
|
role: "tablist",
|
|
83
|
-
children:
|
|
82
|
+
children: tabs
|
|
84
83
|
})
|
|
85
|
-
}),
|
|
84
|
+
}), tabPanels] })
|
|
86
85
|
});
|
|
87
86
|
};
|
|
88
87
|
UnderlinePanels.displayName = "UnderlinePanels";
|
|
89
|
-
const TabImpl = (
|
|
90
|
-
const $ = c(15);
|
|
91
|
-
let ariaSelected;
|
|
92
|
-
let onSelect;
|
|
93
|
-
let props;
|
|
94
|
-
if ($[0] !== t0) {
|
|
95
|
-
({"aria-selected": ariaSelected, onSelect, ...props} = t0);
|
|
96
|
-
$[0] = t0;
|
|
97
|
-
$[1] = ariaSelected;
|
|
98
|
-
$[2] = onSelect;
|
|
99
|
-
$[3] = props;
|
|
100
|
-
} else {
|
|
101
|
-
ariaSelected = $[1];
|
|
102
|
-
onSelect = $[2];
|
|
103
|
-
props = $[3];
|
|
104
|
-
}
|
|
88
|
+
const TabImpl = ({ "aria-selected": ariaSelected, onSelect, ...props }) => {
|
|
105
89
|
const { loadingCounters } = useContext(UnderlinePanelsContext);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
const keyDownHandler = t2;
|
|
124
|
-
const t3 = ariaSelected ? 0 : -1;
|
|
125
|
-
let t4;
|
|
126
|
-
if ($[8] !== ariaSelected || $[9] !== clickHandler || $[10] !== keyDownHandler || $[11] !== loadingCounters || $[12] !== props || $[13] !== t3) {
|
|
127
|
-
t4 = /*#__PURE__*/ jsx(UnderlineItem, {
|
|
128
|
-
as: "button",
|
|
129
|
-
role: "tab",
|
|
130
|
-
tabIndex: t3,
|
|
131
|
-
"aria-selected": ariaSelected,
|
|
132
|
-
type: "button",
|
|
133
|
-
onClick: clickHandler,
|
|
134
|
-
onKeyDown: keyDownHandler,
|
|
135
|
-
loadingCounters,
|
|
136
|
-
...props
|
|
137
|
-
});
|
|
138
|
-
$[8] = ariaSelected;
|
|
139
|
-
$[9] = clickHandler;
|
|
140
|
-
$[10] = keyDownHandler;
|
|
141
|
-
$[11] = loadingCounters;
|
|
142
|
-
$[12] = props;
|
|
143
|
-
$[13] = t3;
|
|
144
|
-
$[14] = t4;
|
|
145
|
-
} else t4 = $[14];
|
|
146
|
-
return t4;
|
|
90
|
+
const clickHandler = React.useCallback((event) => {
|
|
91
|
+
if (!event.defaultPrevented && typeof onSelect === "function") onSelect(event);
|
|
92
|
+
}, [onSelect]);
|
|
93
|
+
const keyDownHandler = React.useCallback((event) => {
|
|
94
|
+
if ((event.key === " " || event.key === "Enter") && !event.defaultPrevented && typeof onSelect === "function") onSelect(event);
|
|
95
|
+
}, [onSelect]);
|
|
96
|
+
return /*#__PURE__*/ jsx(UnderlineItem, {
|
|
97
|
+
as: "button",
|
|
98
|
+
role: "tab",
|
|
99
|
+
tabIndex: ariaSelected ? 0 : -1,
|
|
100
|
+
"aria-selected": ariaSelected,
|
|
101
|
+
type: "button",
|
|
102
|
+
onClick: clickHandler,
|
|
103
|
+
onKeyDown: keyDownHandler,
|
|
104
|
+
loadingCounters,
|
|
105
|
+
...props
|
|
106
|
+
});
|
|
147
107
|
};
|
|
108
|
+
TabImpl.displayName = "TabImpl";
|
|
148
109
|
TabImpl.displayName = "UnderlinePanels.Tab";
|
|
149
110
|
const Tab = /*#__PURE__*/ React.memo(TabImpl);
|
|
150
111
|
Tab.displayName = "UnderlinePanels.Tab";
|
|
151
|
-
const Panel = (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
$[0] = t0;
|
|
158
|
-
$[1] = children;
|
|
159
|
-
$[2] = rest;
|
|
160
|
-
} else {
|
|
161
|
-
children = $[1];
|
|
162
|
-
rest = $[2];
|
|
163
|
-
}
|
|
164
|
-
let t1;
|
|
165
|
-
if ($[3] !== children || $[4] !== rest) {
|
|
166
|
-
t1 = /*#__PURE__*/ jsx("div", {
|
|
167
|
-
role: "tabpanel",
|
|
168
|
-
...rest,
|
|
169
|
-
children
|
|
170
|
-
});
|
|
171
|
-
$[3] = children;
|
|
172
|
-
$[4] = rest;
|
|
173
|
-
$[5] = t1;
|
|
174
|
-
} else t1 = $[5];
|
|
175
|
-
return t1;
|
|
112
|
+
const Panel = ({ children, ...rest }) => {
|
|
113
|
+
return /*#__PURE__*/ jsx("div", {
|
|
114
|
+
role: "tabpanel",
|
|
115
|
+
...rest,
|
|
116
|
+
children
|
|
117
|
+
});
|
|
176
118
|
};
|
|
119
|
+
Panel.displayName = "Panel";
|
|
177
120
|
Panel.displayName = "UnderlinePanels.Panel";
|
|
178
121
|
var UnderlinePanels_default = Object.assign(UnderlinePanels, {
|
|
179
122
|
Panel,
|
|
@@ -21,9 +21,9 @@ function useControllableState({ name = "custom", defaultValue, value, onChange }
|
|
|
21
21
|
if (controlled.current === null) controlled.current = value !== void 0;
|
|
22
22
|
const setState = React.useCallback((stateOrUpdater) => {
|
|
23
23
|
var _stableOnChange$curre;
|
|
24
|
-
const
|
|
25
|
-
if (controlled.current === false) internalSetState(
|
|
26
|
-
(_stableOnChange$curre = stableOnChange.current) === null || _stableOnChange$curre === void 0 || _stableOnChange$curre.call(stableOnChange,
|
|
24
|
+
const value = typeof stateOrUpdater === "function" ? stateOrUpdater(state) : stateOrUpdater;
|
|
25
|
+
if (controlled.current === false) internalSetState(value);
|
|
26
|
+
(_stableOnChange$curre = stableOnChange.current) === null || _stableOnChange$curre === void 0 || _stableOnChange$curre.call(stableOnChange, value);
|
|
27
27
|
}, [state]);
|
|
28
28
|
React.useEffect(() => {
|
|
29
29
|
const controlledValue = value !== void 0;
|
package/dist/hooks/useMedia.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { canUseDOM } from "../utils/environment.js";
|
|
2
1
|
import { warning } from "../utils/warning.js";
|
|
3
2
|
import { MatchMediaContext } from "./MatchMediaContext.js";
|
|
4
3
|
import { c } from "react-compiler-runtime";
|
|
5
|
-
import
|
|
4
|
+
import { useContext, useSyncExternalStore } from "react";
|
|
6
5
|
//#region src/hooks/useMedia.ts
|
|
7
6
|
/**
|
|
8
7
|
* `useMedia` will use the given `mediaQueryString` with `matchMedia` to
|
|
@@ -18,52 +17,54 @@ import React, { useContext, useEffect } from "react";
|
|
|
18
17
|
* }
|
|
19
18
|
*/
|
|
20
19
|
function useMedia(mediaQueryString, defaultState) {
|
|
21
|
-
const $ = c(
|
|
22
|
-
const
|
|
20
|
+
const $ = c(9);
|
|
21
|
+
const contextValue = useContext(MatchMediaContext)[mediaQueryString];
|
|
23
22
|
let t0;
|
|
24
|
-
if ($[0] !==
|
|
25
|
-
t0 = () => {
|
|
26
|
-
if (
|
|
27
|
-
if (defaultState !== void 0) return defaultState;
|
|
28
|
-
if (canUseDOM) return window.matchMedia(mediaQueryString).matches;
|
|
29
|
-
warning(true, "`useMedia` When server side rendering, defaultState should be defined to prevent a hydration mismatches.");
|
|
30
|
-
return false;
|
|
31
|
-
};
|
|
32
|
-
$[0] = defaultState;
|
|
33
|
-
$[1] = features;
|
|
34
|
-
$[2] = mediaQueryString;
|
|
35
|
-
$[3] = t0;
|
|
36
|
-
} else t0 = $[3];
|
|
37
|
-
const [matches, setMatches] = React.useState(t0);
|
|
38
|
-
if (features[mediaQueryString] !== void 0 && matches !== features[mediaQueryString]) setMatches(features[mediaQueryString]);
|
|
39
|
-
let t1;
|
|
40
|
-
let t2;
|
|
41
|
-
if ($[4] !== features || $[5] !== mediaQueryString) {
|
|
42
|
-
t1 = () => {
|
|
43
|
-
if (features[mediaQueryString] !== void 0) return;
|
|
44
|
-
const listener = function listener(event) {
|
|
45
|
-
setMatches(event.matches);
|
|
46
|
-
};
|
|
23
|
+
if ($[0] !== contextValue || $[1] !== mediaQueryString) {
|
|
24
|
+
t0 = (onStoreChange) => {
|
|
25
|
+
if (contextValue !== void 0) return _temp;
|
|
47
26
|
const mediaQueryList = window.matchMedia(mediaQueryString);
|
|
48
|
-
if (mediaQueryList.addEventListener)
|
|
49
|
-
|
|
50
|
-
|
|
27
|
+
if (mediaQueryList.addEventListener) {
|
|
28
|
+
mediaQueryList.addEventListener("change", onStoreChange);
|
|
29
|
+
return () => {
|
|
30
|
+
mediaQueryList.removeEventListener("change", onStoreChange);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
mediaQueryList.addListener(onStoreChange);
|
|
51
34
|
return () => {
|
|
52
|
-
|
|
53
|
-
else mediaQueryList.removeListener(listener);
|
|
35
|
+
mediaQueryList.removeListener(onStoreChange);
|
|
54
36
|
};
|
|
55
37
|
};
|
|
56
|
-
|
|
57
|
-
$[
|
|
58
|
-
$[
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
38
|
+
$[0] = contextValue;
|
|
39
|
+
$[1] = mediaQueryString;
|
|
40
|
+
$[2] = t0;
|
|
41
|
+
} else t0 = $[2];
|
|
42
|
+
const subscribe = t0;
|
|
43
|
+
let t1;
|
|
44
|
+
if ($[3] !== contextValue || $[4] !== mediaQueryString) {
|
|
45
|
+
t1 = () => {
|
|
46
|
+
if (contextValue !== void 0) return contextValue;
|
|
47
|
+
return window.matchMedia(mediaQueryString).matches;
|
|
48
|
+
};
|
|
49
|
+
$[3] = contextValue;
|
|
50
|
+
$[4] = mediaQueryString;
|
|
51
|
+
$[5] = t1;
|
|
52
|
+
} else t1 = $[5];
|
|
53
|
+
const getSnapshot = t1;
|
|
54
|
+
let t2;
|
|
55
|
+
if ($[6] !== contextValue || $[7] !== defaultState) {
|
|
56
|
+
t2 = () => {
|
|
57
|
+
if (contextValue !== void 0) return contextValue;
|
|
58
|
+
if (defaultState !== void 0) return defaultState;
|
|
59
|
+
warning(typeof window === "undefined", "`useMedia` When server side rendering, defaultState should be defined to prevent a hydration mismatches.");
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
$[6] = contextValue;
|
|
63
|
+
$[7] = defaultState;
|
|
64
|
+
$[8] = t2;
|
|
65
|
+
} else t2 = $[8];
|
|
66
|
+
return useSyncExternalStore(subscribe, getSnapshot, t2);
|
|
67
67
|
}
|
|
68
|
+
function _temp() {}
|
|
68
69
|
//#endregion
|
|
69
70
|
export { useMedia };
|
|
@@ -1,40 +1,44 @@
|
|
|
1
1
|
import ValidationAnimationContainer_module_css_default from "./ValidationAnimationContainer.module.css.js";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
import {
|
|
4
|
+
import { useState } from "react";
|
|
5
5
|
//#region src/internal/components/ValidationAnimationContainer.tsx
|
|
6
6
|
const ValidationAnimationContainer = (t0) => {
|
|
7
|
-
const $ = c(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
let
|
|
12
|
-
if ($[0] !==
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
$[
|
|
18
|
-
$[
|
|
19
|
-
$[2] = t2;
|
|
7
|
+
const $ = c(14);
|
|
8
|
+
let children;
|
|
9
|
+
let rest;
|
|
10
|
+
let show;
|
|
11
|
+
let style;
|
|
12
|
+
if ($[0] !== t0) {
|
|
13
|
+
({show, children, style, ...rest} = t0);
|
|
14
|
+
$[0] = t0;
|
|
15
|
+
$[1] = children;
|
|
16
|
+
$[2] = rest;
|
|
17
|
+
$[3] = show;
|
|
18
|
+
$[4] = style;
|
|
20
19
|
} else {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
children = $[1];
|
|
21
|
+
rest = $[2];
|
|
22
|
+
show = $[3];
|
|
23
|
+
style = $[4];
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const [shouldRender, setRender] = useState(Boolean(show));
|
|
26
|
+
if (show && !shouldRender) setRender(true);
|
|
27
|
+
let t1;
|
|
28
|
+
if ($[5] !== show) {
|
|
29
|
+
t1 = () => {
|
|
28
30
|
if (!show) setRender(false);
|
|
29
31
|
};
|
|
30
|
-
$[
|
|
31
|
-
$[
|
|
32
|
-
} else
|
|
33
|
-
const onAnimationEnd =
|
|
34
|
-
let
|
|
35
|
-
if ($[
|
|
36
|
-
|
|
32
|
+
$[5] = show;
|
|
33
|
+
$[6] = t1;
|
|
34
|
+
} else t1 = $[6];
|
|
35
|
+
const onAnimationEnd = t1;
|
|
36
|
+
let t2;
|
|
37
|
+
if ($[7] !== children || $[8] !== onAnimationEnd || $[9] !== rest || $[10] !== shouldRender || $[11] !== show || $[12] !== style) {
|
|
38
|
+
t2 = shouldRender ? /*#__PURE__*/ jsx("div", {
|
|
39
|
+
...rest,
|
|
37
40
|
style: {
|
|
41
|
+
...style,
|
|
38
42
|
height: show ? "auto" : 0,
|
|
39
43
|
overflow: "hidden"
|
|
40
44
|
},
|
|
@@ -45,13 +49,15 @@ const ValidationAnimationContainer = (t0) => {
|
|
|
45
49
|
children
|
|
46
50
|
})
|
|
47
51
|
}) : null;
|
|
48
|
-
$[
|
|
49
|
-
$[
|
|
50
|
-
$[
|
|
51
|
-
$[
|
|
52
|
-
$[
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
$[7] = children;
|
|
53
|
+
$[8] = onAnimationEnd;
|
|
54
|
+
$[9] = rest;
|
|
55
|
+
$[10] = shouldRender;
|
|
56
|
+
$[11] = show;
|
|
57
|
+
$[12] = style;
|
|
58
|
+
$[13] = t2;
|
|
59
|
+
} else t2 = $[13];
|
|
60
|
+
return t2;
|
|
55
61
|
};
|
|
56
62
|
//#endregion
|
|
57
63
|
export { ValidationAnimationContainer as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "38.32.0-rc.
|
|
4
|
+
"version": "38.32.0-rc.94f147e58",
|
|
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",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"build:hooks.json": "tsx script/hooks-json/build.ts",
|
|
48
48
|
"build:precompile-color-schemes": "tsx script/precompile-color-schemes.ts",
|
|
49
49
|
"lint:npm": "publint --types",
|
|
50
|
+
"lint:react-compiler": "node script/lint-react-compiler.ts",
|
|
50
51
|
"storybook": "storybook",
|
|
51
52
|
"type-check": "tsc --noEmit",
|
|
52
53
|
"type-css-modules": "tcm -p src/**/*.module.css"
|
|
@@ -108,6 +109,7 @@
|
|
|
108
109
|
"@figma/code-connect": "1.3.2",
|
|
109
110
|
"@primer/css": "^21.5.1",
|
|
110
111
|
"@primer/doc-gen": "^0.0.1",
|
|
112
|
+
"@primer/react-compiler-check": "^0.0.0",
|
|
111
113
|
"@rolldown/plugin-babel": "^0.2.3",
|
|
112
114
|
"@storybook/addon-a11y": "^10.4.6",
|
|
113
115
|
"@storybook/addon-docs": "^10.4.6",
|