@primer/react 0.0.0-20260427204101 → 0.0.0-20260427204434
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 -12
- package/dist/AnchoredOverlay/AnchoredOverlay.d.ts.map +1 -1
- package/dist/AnchoredOverlay/AnchoredOverlay.js +80 -62
- package/dist/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/Checkbox/Checkbox.js +0 -4
- package/dist/hooks/useAnchoredPosition.d.ts +6 -0
- package/dist/hooks/useAnchoredPosition.d.ts.map +1 -1
- package/dist/hooks/useAnchoredPosition.js +7 -21
- package/generated/components.json +10 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- [#7770](https://github.com/primer/react/pull/7770) [`619175c`](https://github.com/primer/react/commit/619175c00dece144573fe5afbe4cd51e524a6c3d) Thanks [@LisaKr](https://github.com/LisaKr)! - Defer `useAnchoredPosition` initial mount setState from useLayoutEffect to useEffect when overlay is closed, eliminating unnecessary cascading re-renders that block paint.
|
|
8
|
-
|
|
9
|
-
- Fake entry to force publishing
|
|
10
|
-
|
|
11
|
-
- [#7780](https://github.com/primer/react/pull/7780) [`b401fb6`](https://github.com/primer/react/commit/b401fb6c20fdd6ca951b32662fd2c45d427d2fcf) Thanks [@francinelucca](https://github.com/francinelucca)! - fix: Checkbox indeterminate state now persists on click if the state didn't change
|
|
12
|
-
|
|
13
|
-
## 38.21.0
|
|
3
|
+
## 0.0.0-20260427204434
|
|
14
4
|
|
|
15
5
|
### Minor Changes
|
|
16
6
|
|
|
@@ -33,7 +23,7 @@
|
|
|
33
23
|
|
|
34
24
|
This enables consumers to query and test components using stable selectors like `[data-component="Table.Row"]`.
|
|
35
25
|
|
|
36
|
-
- [#7766](https://github.com/primer/react/pull/7766) [`
|
|
26
|
+
- [#7766](https://github.com/primer/react/pull/7766) [`6770095`](https://github.com/primer/react/commit/67700952bec8373c01843b88e39ccb6dfe5b108c) Thanks [@TylerJDev](https://github.com/TylerJDev)! - AnchoredOverlay: (Behind feature flag) Make popover API usage opt-in
|
|
37
27
|
|
|
38
28
|
- [#7763](https://github.com/primer/react/pull/7763) [`b288d6e`](https://github.com/primer/react/commit/b288d6e2dc9d1eef345ef4d16f6b0fba4f165955) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Add borderRadius prop to Card component.
|
|
39
29
|
|
|
@@ -43,8 +33,12 @@
|
|
|
43
33
|
|
|
44
34
|
- [#7754](https://github.com/primer/react/pull/7754) [`9e3fe4b`](https://github.com/primer/react/commit/9e3fe4b501ce5affb558bf92697e5c79341903ca) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Breadcrumbs: On narrow viewports, only show the current page breadcrumb and the overflow menu when `overflow="menu"` is set.
|
|
45
35
|
|
|
36
|
+
- Fake entry to force publishing
|
|
37
|
+
|
|
46
38
|
- [#7757](https://github.com/primer/react/pull/7757) [`ed82a1e`](https://github.com/primer/react/commit/ed82a1e0399b98428d4b794239bb37649806b5cc) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - SelectPanel: Lock body scroll when modal variant is on.
|
|
47
39
|
|
|
40
|
+
- [#7775](https://github.com/primer/react/pull/7775) [`2199b7f`](https://github.com/primer/react/commit/2199b7f18f1a47e79e9b21cf04f1599d5af8836a) Thanks [@TylerJDev](https://github.com/TylerJDev)! - AnchoredOverlay: Ensure styles persist on anchors even when re-mounted (behind feature flag)
|
|
41
|
+
|
|
48
42
|
- [#7734](https://github.com/primer/react/pull/7734) [`421ebf0`](https://github.com/primer/react/commit/421ebf0a54558a29f1efbe1850036f80b1bbe126) Thanks [@llastflowers](https://github.com/llastflowers)! - add data-component attributes for Avatar, AvatarStack, Banner, & BaseStyles
|
|
49
43
|
|
|
50
44
|
## 38.20.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnchoredOverlay.d.ts","sourceRoot":"","sources":["../../src/AnchoredOverlay/AnchoredOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,
|
|
1
|
+
{"version":3,"file":"AnchoredOverlay.d.ts","sourceRoot":"","sources":["../../src/AnchoredOverlay/AnchoredOverlay.tsx"],"names":[],"mappings":"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"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
3
2
|
import { useFocusTrap } from '../hooks/useFocusTrap.js';
|
|
4
3
|
import { useFocusZone } from '../hooks/useFocusZone.js';
|
|
5
4
|
import { useId } from '../hooks/useId.js';
|
|
@@ -52,13 +51,29 @@ const AnchoredOverlay = ({
|
|
|
52
51
|
renderAs = 'portal'
|
|
53
52
|
}) => {
|
|
54
53
|
const cssAnchorPositioningFlag = useFeatureFlag('primer_react_css_anchor_positioning');
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
const
|
|
54
|
+
// Lazy initial state so feature detection runs once per mount on the client.
|
|
55
|
+
// Guarded for SSR where `document` is undefined.
|
|
56
|
+
const [supportsNativeCSSAnchorPositioning] = useState(() => typeof document !== 'undefined' && 'anchorName' in document.documentElement.style);
|
|
57
|
+
const cssAnchorPositioning = cssAnchorPositioningFlag && supportsNativeCSSAnchorPositioning;
|
|
58
58
|
// Only use Popover API when both CSS anchor positioning is enabled AND renderAs is true
|
|
59
59
|
const shouldRenderAsPopover = cssAnchorPositioning && renderAs === 'popover';
|
|
60
60
|
const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
|
|
61
|
+
// Track the current anchor DOM element in state so that effects depending on
|
|
62
|
+
// its identity (e.g. applying `anchor-name` for CSS anchor positioning) re-run
|
|
63
|
+
// when a consumer remounts/replaces the anchor element while keeping the same
|
|
64
|
+
// `anchorRef` object. Refs alone don't notify React when `.current` changes.
|
|
65
|
+
const [anchorElement, setAnchorElement] = useState(null);
|
|
66
|
+
// Detect when `anchorRef.current` has been mutated by a consumer (e.g. via
|
|
67
|
+
// their own `ref={anchorRef}`) without React's ref system notifying us.
|
|
68
|
+
// Reading the ref during render and conditionally calling setState is the
|
|
69
|
+
// documented React pattern for syncing external mutable state, but the
|
|
70
|
+
// react-hooks/refs lint rule is conservative and disallows it.
|
|
71
|
+
// eslint-disable-next-line react-hooks/refs
|
|
72
|
+
if (anchorRef.current !== anchorElement) {
|
|
73
|
+
setAnchorElement(anchorRef.current);
|
|
74
|
+
}
|
|
61
75
|
const [overlayRef, updateOverlayRef] = useRenderForcingRef();
|
|
76
|
+
const [overlayElement, setOverlayElement] = useState(null);
|
|
62
77
|
const anchorId = useId(externalAnchorId);
|
|
63
78
|
const onClickOutside = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('click-outside'), [onClose]);
|
|
64
79
|
const onEscape = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('escape'), [onClose]);
|
|
@@ -70,14 +85,14 @@ const AnchoredOverlay = ({
|
|
|
70
85
|
}
|
|
71
86
|
}
|
|
72
87
|
}, [open, onOpen]);
|
|
73
|
-
const onAnchorClick = useCallback(
|
|
74
|
-
if (
|
|
88
|
+
const onAnchorClick = useCallback(event => {
|
|
89
|
+
if (event.defaultPrevented || event.button !== 0) {
|
|
75
90
|
return;
|
|
76
91
|
}
|
|
77
92
|
// Prevent the browser's native popovertarget toggle so React
|
|
78
93
|
// stays the single source of truth for popover visibility.
|
|
79
94
|
if (cssAnchorPositioning) {
|
|
80
|
-
|
|
95
|
+
event.preventDefault();
|
|
81
96
|
}
|
|
82
97
|
if (!open) {
|
|
83
98
|
onOpen === null || onOpen === void 0 ? void 0 : onOpen('anchor-click');
|
|
@@ -93,7 +108,7 @@ const AnchoredOverlay = ({
|
|
|
93
108
|
}
|
|
94
109
|
};
|
|
95
110
|
const {
|
|
96
|
-
position
|
|
111
|
+
position
|
|
97
112
|
} = useAnchoredPosition({
|
|
98
113
|
anchorElementRef: anchorRef,
|
|
99
114
|
floatingElementRef: overlayRef,
|
|
@@ -103,13 +118,13 @@ const AnchoredOverlay = ({
|
|
|
103
118
|
alignmentOffset,
|
|
104
119
|
anchorOffset,
|
|
105
120
|
displayInViewport,
|
|
106
|
-
onPositionChange: positionChange
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
121
|
+
onPositionChange: positionChange,
|
|
122
|
+
// When native CSS anchor positioning is active, skip JS-based position
|
|
123
|
+
// computation, scroll listeners, and resize observers since the browser
|
|
124
|
+
// handles repositioning natively.
|
|
125
|
+
enabled: !cssAnchorPositioning
|
|
126
|
+
}, [overlayElement]);
|
|
110
127
|
useEffect(() => {
|
|
111
|
-
supportsNativeCSSAnchorPositioning.current = 'anchorName' in document.documentElement.style;
|
|
112
|
-
|
|
113
128
|
// ensure overlay ref gets cleared when closed, so position can reset between closing/re-opening
|
|
114
129
|
if (!open && overlayRef.current) {
|
|
115
130
|
updateOverlayRef(null);
|
|
@@ -117,64 +132,64 @@ const AnchoredOverlay = ({
|
|
|
117
132
|
}, [open, overlayRef, updateOverlayRef]);
|
|
118
133
|
useFocusZone({
|
|
119
134
|
containerRef: overlayRef,
|
|
120
|
-
disabled: !open || !
|
|
135
|
+
disabled: !open || !position && !cssAnchorPositioning,
|
|
121
136
|
...focusZoneSettings
|
|
122
137
|
});
|
|
123
138
|
useFocusTrap({
|
|
124
139
|
containerRef: overlayRef,
|
|
125
|
-
disabled: !open || !
|
|
140
|
+
disabled: !open || !position && !cssAnchorPositioning,
|
|
126
141
|
...focusTrapSettings
|
|
127
142
|
});
|
|
128
143
|
const popoverId = useId();
|
|
129
144
|
const id = popoverId.replaceAll(':', '_'); // popoverId can contain colons which are invalid in CSS custom property names, so we replace them with underscores
|
|
130
145
|
|
|
131
146
|
useEffect(() => {
|
|
132
|
-
if (!cssAnchorPositioning || !
|
|
133
|
-
const anchor = anchorRef.current;
|
|
134
|
-
const overlay = overlayRef.current;
|
|
135
|
-
anchor.style.setProperty('anchor-name', `--anchored-overlay-anchor-${id}`);
|
|
136
|
-
return () => {
|
|
137
|
-
anchor.style.removeProperty('anchor-name');
|
|
138
|
-
if (overlay) {
|
|
139
|
-
overlay.style.removeProperty('position-anchor');
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
// eslint-disable-next-line react-hooks/refs
|
|
143
|
-
}, [cssAnchorPositioning, anchorRef, overlayRef, id, open]);
|
|
144
|
-
|
|
145
|
-
// Track the overlay element so we can re-run the effect when it changes.
|
|
146
|
-
// The overlay unmounts when closed, so each open creates a new DOM node -
|
|
147
|
-
// that needs showPopover() called.
|
|
148
|
-
// eslint-disable-next-line react-hooks/refs
|
|
149
|
-
const overlayElement = overlayRef.current;
|
|
150
|
-
useIsomorphicLayoutEffect(() => {
|
|
151
|
-
// Read ref inside effect to get the value after child refs are attached
|
|
147
|
+
if (!cssAnchorPositioning || !anchorElement) return;
|
|
152
148
|
const currentOverlay = overlayRef.current;
|
|
153
|
-
if (!cssAnchorPositioning || !open || !currentOverlay) return;
|
|
154
|
-
currentOverlay.style.setProperty('position-anchor', `--anchored-overlay-anchor-${id}`);
|
|
155
|
-
const anchorElement = anchorRef.current;
|
|
156
|
-
if (anchorElement) {
|
|
157
|
-
const overlayWidth = width ? parseInt(widthMap[width]) : null;
|
|
158
|
-
const result = getDefaultPosition(anchorElement, overlayWidth);
|
|
159
|
-
currentOverlay.setAttribute('data-align', result.horizontal);
|
|
160
149
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
150
|
+
// Link the anchor and the overlay (when present) via CSS anchor positioning.
|
|
151
|
+
anchorElement.style.setProperty('anchor-name', `--anchored-overlay-anchor-${id}`);
|
|
152
|
+
let rafId = null;
|
|
153
|
+
if (open && currentOverlay) {
|
|
154
|
+
currentOverlay.style.setProperty('position-anchor', `--anchored-overlay-anchor-${id}`);
|
|
155
|
+
|
|
156
|
+
// Defer the getBoundingClientRect read into a rAF so the style write above
|
|
157
|
+
// does not force a synchronous layout. This matters when many overlays open
|
|
158
|
+
// simultaneously: each effect would otherwise trigger a full-document layout
|
|
159
|
+
// immediately after writing `anchor-name`/`position-anchor`.
|
|
160
|
+
rafId = requestAnimationFrame(() => {
|
|
161
|
+
rafId = null;
|
|
162
|
+
const overlayWidth = width ? parseInt(widthMap[width]) : null;
|
|
163
|
+
const result = getDefaultPosition(anchorElement, overlayWidth);
|
|
164
|
+
currentOverlay.setAttribute('data-align', result.horizontal);
|
|
165
|
+
|
|
166
|
+
// Apply offset only when viewport is too narrow
|
|
167
|
+
const offset = result.horizontal === 'left' ? result.leftOffset : result.rightOffset;
|
|
168
|
+
currentOverlay.style.setProperty(`--anchored-overlay-anchor-offset-${result.horizontal}`, `${offset || 0}px`);
|
|
169
|
+
});
|
|
165
170
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
+
// Only call showPopover when shouldRenderAsPopover is enabled
|
|
172
|
+
if (shouldRenderAsPopover) {
|
|
173
|
+
try {
|
|
174
|
+
if (!currentOverlay.matches(':popover-open')) {
|
|
175
|
+
currentOverlay.showPopover();
|
|
176
|
+
}
|
|
177
|
+
} catch {
|
|
178
|
+
// Ignore if popover is already showing or not supported
|
|
171
179
|
}
|
|
172
|
-
} catch {
|
|
173
|
-
// Ignore if popover is already showing or not supported
|
|
174
180
|
}
|
|
175
181
|
}
|
|
176
|
-
|
|
177
|
-
|
|
182
|
+
return () => {
|
|
183
|
+
if (rafId !== null) cancelAnimationFrame(rafId);
|
|
184
|
+
anchorElement.style.removeProperty('anchor-name');
|
|
185
|
+
// The overlay may no longer be in the DOM at this point, so we need to check for its presence before trying to update it.
|
|
186
|
+
if (currentOverlay) {
|
|
187
|
+
currentOverlay.style.removeProperty('position-anchor');
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
// overlayRef is a stable ref object; including it in deps is unnecessary.
|
|
191
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
192
|
+
}, [cssAnchorPositioning, shouldRenderAsPopover, open, anchorElement, overlayElement, id, width]);
|
|
178
193
|
const showXIcon = onClose && variant.narrow === 'fullscreen' && displayCloseButton;
|
|
179
194
|
const XButtonAriaLabelledBy = closeButtonProps['aria-labelledby'];
|
|
180
195
|
const XButtonAriaLabel = closeButtonProps['aria-label'];
|
|
@@ -185,6 +200,8 @@ const AnchoredOverlay = ({
|
|
|
185
200
|
} = overlayProps || {};
|
|
186
201
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
187
202
|
children: [renderAnchor &&
|
|
203
|
+
// anchorRef is a ref object passed as a JSX `ref` prop on the rendered
|
|
204
|
+
// anchor; React writes to it at commit time, it is not read during render.
|
|
188
205
|
// eslint-disable-next-line react-hooks/refs
|
|
189
206
|
renderAnchor({
|
|
190
207
|
ref: anchorRef,
|
|
@@ -203,13 +220,13 @@ const AnchoredOverlay = ({
|
|
|
203
220
|
ignoreClickRefs: [anchorRef],
|
|
204
221
|
onEscape: onEscape,
|
|
205
222
|
role: "none",
|
|
206
|
-
visibility: cssAnchorPositioning ||
|
|
223
|
+
visibility: cssAnchorPositioning || position ? 'visible' : 'hidden',
|
|
207
224
|
height: height,
|
|
208
225
|
width: width,
|
|
209
|
-
top: cssAnchorPositioning ? undefined : (
|
|
210
|
-
left: cssAnchorPositioning ? undefined : (
|
|
226
|
+
top: cssAnchorPositioning ? undefined : (position === null || position === void 0 ? void 0 : position.top) || 0,
|
|
227
|
+
left: cssAnchorPositioning ? undefined : (position === null || position === void 0 ? void 0 : position.left) || 0,
|
|
211
228
|
responsiveVariant: variant.narrow === 'fullscreen' ? 'fullscreen' : undefined,
|
|
212
|
-
anchorSide: cssAnchorPositioning ? undefined :
|
|
229
|
+
anchorSide: cssAnchorPositioning ? undefined : position === null || position === void 0 ? void 0 : position.anchorSide,
|
|
213
230
|
className: clsx(className, overlayClassName, cssAnchorPositioning ? classes.AnchoredOverlay : undefined),
|
|
214
231
|
preventOverflow: preventOverflow,
|
|
215
232
|
"data-component": "AnchoredOverlay",
|
|
@@ -226,9 +243,10 @@ const AnchoredOverlay = ({
|
|
|
226
243
|
assignRef(overlayProps.ref, node);
|
|
227
244
|
}
|
|
228
245
|
updateOverlayRef(node);
|
|
246
|
+
setOverlayElement(node);
|
|
229
247
|
},
|
|
230
248
|
"data-anchor-position": cssAnchorPositioning,
|
|
231
|
-
"data-side": cssAnchorPositioning ? side :
|
|
249
|
+
"data-side": cssAnchorPositioning ? side : position === null || position === void 0 ? void 0 : position.anchorSide,
|
|
232
250
|
children: [showXIcon ? /*#__PURE__*/jsx("div", {
|
|
233
251
|
className: classes.ResponsiveCloseButtonContainer,
|
|
234
252
|
children: /*#__PURE__*/jsx(IconButton, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.d.ts","sourceRoot":"","sources":["../../src/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAiD,KAAK,mBAAmB,EAAoB,MAAM,OAAO,CAAA;AAExH,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,qCAAqC,CAAA;AAI7E,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAA;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAA;IACvC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,gBAAgB,CAAC,EAAE,oBAAoB,CAAA;IACvC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,GAAG,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAAA;AAE3D;;GAEG;AACH,QAAA,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"Checkbox.d.ts","sourceRoot":"","sources":["../../src/Checkbox/Checkbox.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAiD,KAAK,mBAAmB,EAAoB,MAAM,OAAO,CAAA;AAExH,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,qCAAqC,CAAA;AAI7E,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAA;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAA;IACvC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,gBAAgB,CAAC,EAAE,oBAAoB,CAAA;IACvC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,GAAG,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAAA;AAE3D;;GAEG;AACH,QAAA,MAAM,QAAQ,qGAgDb,CAAA;wBAK0B,cAAc,CAAC,OAAO,QAAQ,CAAC;AAA1D,wBAA0D"}
|
|
@@ -29,10 +29,6 @@ const Checkbox = /*#__PURE__*/React.forwardRef(({
|
|
|
29
29
|
const handleOnChange = e => {
|
|
30
30
|
checkboxGroupContext.onChange && checkboxGroupContext.onChange(e);
|
|
31
31
|
onChange && onChange(e);
|
|
32
|
-
if (indeterminate && checkboxRef.current) {
|
|
33
|
-
checkboxRef.current.indeterminate = true;
|
|
34
|
-
checkboxRef.current.setAttribute('aria-checked', 'mixed');
|
|
35
|
-
}
|
|
36
32
|
};
|
|
37
33
|
const inputProps = {
|
|
38
34
|
type: 'checkbox',
|
|
@@ -5,6 +5,12 @@ export interface AnchoredPositionHookSettings extends Partial<PositionSettings>
|
|
|
5
5
|
anchorElementRef?: React.RefObject<Element | null>;
|
|
6
6
|
pinPosition?: boolean;
|
|
7
7
|
onPositionChange?: (position: AnchorPosition | undefined) => void;
|
|
8
|
+
/**
|
|
9
|
+
* When false, skips position computation, scroll listeners, and resize
|
|
10
|
+
* observers. Useful when an external mechanism (e.g. native CSS anchor
|
|
11
|
+
* positioning) is handling positioning instead. Defaults to true.
|
|
12
|
+
*/
|
|
13
|
+
enabled?: boolean;
|
|
8
14
|
}
|
|
9
15
|
/**
|
|
10
16
|
* Calculates the top and left values for an absolutely-positioned floating element
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAnchoredPosition.d.ts","sourceRoot":"","sources":["../../src/hooks/useAnchoredPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AA0BvE,MAAM,WAAW,4BAA6B,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IAC7E,kBAAkB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACpD,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAClD,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"useAnchoredPosition.d.ts","sourceRoot":"","sources":["../../src/hooks/useAnchoredPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AA0BvE,MAAM,WAAW,4BAA6B,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IAC7E,kBAAkB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACpD,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAClD,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAA;IACjE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,CAAC,EAAE,4BAA4B,EACvC,YAAY,GAAE,KAAK,CAAC,cAAmB,GACtC;IACD,kBAAkB,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACnD,gBAAgB,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACjD,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAA;CACrC,CA+GA"}
|
|
@@ -34,8 +34,10 @@ function getScrollableAncestors(element) {
|
|
|
34
34
|
* floating element.
|
|
35
35
|
*/
|
|
36
36
|
function useAnchoredPosition(settings, dependencies = []) {
|
|
37
|
+
var _settings$enabled;
|
|
37
38
|
const floatingElementRef = useProvidedRefOrCreate(settings === null || settings === void 0 ? void 0 : settings.floatingElementRef);
|
|
38
39
|
const anchorElementRef = useProvidedRefOrCreate(settings === null || settings === void 0 ? void 0 : settings.anchorElementRef);
|
|
40
|
+
const enabled = (_settings$enabled = settings === null || settings === void 0 ? void 0 : settings.enabled) !== null && _settings$enabled !== void 0 ? _settings$enabled : true;
|
|
39
41
|
const savedOnPositionChange = React.useRef(settings === null || settings === void 0 ? void 0 : settings.onPositionChange);
|
|
40
42
|
const [position, setPosition] = React.useState(undefined);
|
|
41
43
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -62,6 +64,7 @@ function useAnchoredPosition(settings, dependencies = []) {
|
|
|
62
64
|
};
|
|
63
65
|
const updatePosition = React.useCallback(() => {
|
|
64
66
|
var _floatingElementRef$c5;
|
|
67
|
+
if (!enabled) return;
|
|
65
68
|
if (floatingElementRef.current instanceof Element && anchorElementRef.current instanceof Element) {
|
|
66
69
|
const newPosition = getAnchoredPosition(floatingElementRef.current, anchorElementRef.current, settings);
|
|
67
70
|
setPosition(prev => {
|
|
@@ -88,35 +91,18 @@ function useAnchoredPosition(settings, dependencies = []) {
|
|
|
88
91
|
setPrevHeight((_floatingElementRef$c5 = floatingElementRef.current) === null || _floatingElementRef$c5 === void 0 ? void 0 : _floatingElementRef$c5.clientHeight);
|
|
89
92
|
},
|
|
90
93
|
// eslint-disable-next-line react-hooks/exhaustive-deps, react-hooks/use-memo
|
|
91
|
-
[floatingElementRef, anchorElementRef, ...dependencies]);
|
|
94
|
+
[floatingElementRef, anchorElementRef, enabled, ...dependencies]);
|
|
92
95
|
useIsomorphicLayoutEffect(() => {
|
|
93
96
|
savedOnPositionChange.current = settings === null || settings === void 0 ? void 0 : settings.onPositionChange;
|
|
94
97
|
}, [settings === null || settings === void 0 ? void 0 : settings.onPositionChange]);
|
|
95
|
-
|
|
96
|
-
// Defer the first updatePosition to useEffect when the overlay is closed on
|
|
97
|
-
// mount, avoiding paint-blocking cascading setState. If the overlay is already
|
|
98
|
-
// open on mount, run synchronously in useLayoutEffect to prevent a flash.
|
|
99
|
-
// After mount (including Suspense reappear), only call updatePosition when
|
|
100
|
-
// both refs are attached — skipping closed overlays avoids unnecessary setState.
|
|
101
|
-
const hasMountedRef = React.useRef(false);
|
|
102
|
-
useIsomorphicLayoutEffect(() => {
|
|
103
|
-
if (floatingElementRef.current instanceof Element && anchorElementRef.current instanceof Element) {
|
|
104
|
-
hasMountedRef.current = true;
|
|
105
|
-
updatePosition();
|
|
106
|
-
}
|
|
107
|
-
}, [updatePosition, floatingElementRef, anchorElementRef]);
|
|
108
|
-
React.useEffect(() => {
|
|
109
|
-
if (!hasMountedRef.current) {
|
|
110
|
-
hasMountedRef.current = true;
|
|
111
|
-
updatePosition();
|
|
112
|
-
}
|
|
113
|
-
}, [updatePosition]);
|
|
98
|
+
useIsomorphicLayoutEffect(updatePosition, [updatePosition]);
|
|
114
99
|
useResizeObserver(updatePosition); // watches for changes in window size
|
|
115
100
|
useResizeObserver(updatePosition, floatingElementRef); // watches for changes in floating element size
|
|
116
101
|
|
|
117
102
|
// Recalculate position when any scrollable ancestor of the anchor scrolls.
|
|
118
103
|
// Uses requestAnimationFrame to avoid layout thrashing during scroll.
|
|
119
104
|
React.useEffect(() => {
|
|
105
|
+
if (!enabled) return;
|
|
120
106
|
const anchorEl = anchorElementRef.current;
|
|
121
107
|
if (!anchorEl) return;
|
|
122
108
|
let rafId = null;
|
|
@@ -140,7 +126,7 @@ function useAnchoredPosition(settings, dependencies = []) {
|
|
|
140
126
|
cancelAnimationFrame(rafId);
|
|
141
127
|
}
|
|
142
128
|
};
|
|
143
|
-
}, [anchorElementRef, updatePosition]);
|
|
129
|
+
}, [anchorElementRef, updatePosition, enabled]);
|
|
144
130
|
return {
|
|
145
131
|
floatingElementRef,
|
|
146
132
|
anchorElementRef,
|
|
@@ -1174,7 +1174,7 @@
|
|
|
1174
1174
|
},
|
|
1175
1175
|
{
|
|
1176
1176
|
"id": "components-avatar-features--square",
|
|
1177
|
-
"code": "() => (\n <Avatar\n square\n alt=\"primer\"\n src=\"https://avatars.githubusercontent.com/
|
|
1177
|
+
"code": "() => (\n <Avatar\n square\n alt=\"primer\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n)"
|
|
1178
1178
|
},
|
|
1179
1179
|
{
|
|
1180
1180
|
"id": "components-avatar-features--size",
|
|
@@ -1224,35 +1224,35 @@
|
|
|
1224
1224
|
"stories": [
|
|
1225
1225
|
{
|
|
1226
1226
|
"id": "components-avatarstack-features--align-left",
|
|
1227
|
-
"code": "() => (\n <AvatarStack>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/
|
|
1227
|
+
"code": "() => (\n <AvatarStack>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
|
|
1228
1228
|
},
|
|
1229
1229
|
{
|
|
1230
1230
|
"id": "components-avatarstack-features--align-right",
|
|
1231
|
-
"code": "() => (\n <AvatarStack alignRight>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/
|
|
1231
|
+
"code": "() => (\n <AvatarStack alignRight>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
|
|
1232
1232
|
},
|
|
1233
1233
|
{
|
|
1234
1234
|
"id": "components-avatarstack-features--disable-expand-on-hover",
|
|
1235
|
-
"code": "() => (\n <AvatarStack disableExpand>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/
|
|
1235
|
+
"code": "() => (\n <AvatarStack disableExpand>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
|
|
1236
1236
|
},
|
|
1237
1237
|
{
|
|
1238
1238
|
"id": "components-avatarstack-features--custom-size-on-parent",
|
|
1239
|
-
"code": "() => (\n <AvatarStack size={32}>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/
|
|
1239
|
+
"code": "() => (\n <AvatarStack size={32}>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
|
|
1240
1240
|
},
|
|
1241
1241
|
{
|
|
1242
1242
|
"id": "components-avatarstack-features--custom-size-on-parent-responsive",
|
|
1243
|
-
"code": "() => (\n <AvatarStack\n size={{\n narrow: 32,\n regular: 48,\n wide: 64,\n }}\n >\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/
|
|
1243
|
+
"code": "() => (\n <AvatarStack\n size={{\n narrow: 32,\n regular: 48,\n wide: 64,\n }}\n >\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar alt=\"Atom logo\" src=\"https://avatars.githubusercontent.com/atom\" />\n <Avatar\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
|
|
1244
1244
|
},
|
|
1245
1245
|
{
|
|
1246
1246
|
"id": "components-avatarstack-features--custom-size-on-children",
|
|
1247
|
-
"code": "() => (\n <AvatarStack>\n <Avatar\n size={20}\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/
|
|
1247
|
+
"code": "() => (\n <AvatarStack>\n <Avatar\n size={20}\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n size={32}\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar\n size={48}\n alt=\"Atom logo\"\n src=\"https://avatars.githubusercontent.com/atom\"\n />\n <Avatar\n size={64}\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
|
|
1248
1248
|
},
|
|
1249
1249
|
{
|
|
1250
1250
|
"id": "components-avatarstack-features--custom-size-on-children-responsive",
|
|
1251
|
-
"code": "() => (\n <AvatarStack>\n <Avatar\n size={{\n narrow: 16,\n regular: 32,\n wide: 48,\n }}\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/
|
|
1251
|
+
"code": "() => (\n <AvatarStack>\n <Avatar\n size={{\n narrow: 16,\n regular: 32,\n wide: 48,\n }}\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n <Avatar\n size={{\n narrow: 32,\n regular: 48,\n wide: 64,\n }}\n alt=\"GitHub logo\"\n src=\"https://avatars.githubusercontent.com/github\"\n />\n <Avatar\n size={{\n narrow: 48,\n regular: 64,\n wide: 96,\n }}\n alt=\"Atom logo\"\n src=\"https://avatars.githubusercontent.com/atom\"\n />\n <Avatar\n size={{\n narrow: 64,\n regular: 96,\n wide: 120,\n }}\n alt=\"GitHub Desktop logo\"\n src=\"https://avatars.githubusercontent.com/desktop\"\n />\n </AvatarStack>\n)"
|
|
1252
1252
|
},
|
|
1253
1253
|
{
|
|
1254
1254
|
"id": "components-avatarstack-features--with-single-avatar",
|
|
1255
|
-
"code": "() => (\n <AvatarStack>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/
|
|
1255
|
+
"code": "() => (\n <AvatarStack>\n <Avatar\n alt=\"Primer logo\"\n src=\"https://avatars.githubusercontent.com/primer\"\n />\n </AvatarStack>\n)"
|
|
1256
1256
|
}
|
|
1257
1257
|
],
|
|
1258
1258
|
"importPath": "@primer/react",
|
|
@@ -2234,7 +2234,7 @@
|
|
|
2234
2234
|
},
|
|
2235
2235
|
{
|
|
2236
2236
|
"id": "components-checkbox-features--indeterminate",
|
|
2237
|
-
"code": "() =>
|
|
2237
|
+
"code": "() => (\n <form>\n <FormControl>\n <Checkbox value=\"default\" indeterminate />\n <FormControl.Label>Default label</FormControl.Label>\n </FormControl>\n </form>\n)"
|
|
2238
2238
|
}
|
|
2239
2239
|
],
|
|
2240
2240
|
"importPath": "@primer/react",
|
package/package.json
CHANGED