oneslash-design-system 2.27.0 → 2.27.1
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.
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import React, { useState, useEffect, useRef, isValidElement } from 'react';
|
|
2
|
+
import React, { useState, useEffect, useLayoutEffect, useRef, isValidElement } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import { usePopper } from 'react-popper';
|
|
5
|
-
import {
|
|
5
|
+
import { anchoredHidden, anchoredTransition, overlayVisible } from './sharedStyles';
|
|
6
6
|
import { useOverlayTransition } from './useOverlayTransition';
|
|
7
7
|
import Menu from './menu';
|
|
8
8
|
import { PICKABLE, isInTopOverlay } from '../internal/overlayStack';
|
|
9
|
+
// useLayoutEffect warns during server rendering on React 18
|
|
10
|
+
var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
9
11
|
// PICKABLE plus the other things a browser stops on with Tab
|
|
10
12
|
var TAB_STOPS = "".concat(PICKABLE, ", details > summary:first-of-type, [contenteditable]:not([contenteditable=\"false\"]), iframe");
|
|
11
13
|
var isRadio = function (el) { return el instanceof HTMLInputElement && el.type === 'radio'; };
|
|
@@ -118,6 +120,17 @@ export default function Popover(_a) {
|
|
|
118
120
|
}, 0);
|
|
119
121
|
return function () { return clearTimeout(timer); };
|
|
120
122
|
}, [open]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
123
|
+
// Grow from the anchor: the scale's origin is the anchor's center, measured from the panel's
|
|
124
|
+
// unscaled box, so the Popover comes out of the button whichever side Popper put it on
|
|
125
|
+
var panelRef = useRef(null);
|
|
126
|
+
useIsomorphicLayoutEffect(function () {
|
|
127
|
+
var panel = panelRef.current;
|
|
128
|
+
if (!panel || !popoverElement || !anchorEl)
|
|
129
|
+
return;
|
|
130
|
+
var from = anchorEl.getBoundingClientRect();
|
|
131
|
+
var box = popoverElement.getBoundingClientRect();
|
|
132
|
+
panel.style.transformOrigin = "".concat(from.left + from.width / 2 - box.left, "px ").concat(from.top + from.height / 2 - box.top, "px");
|
|
133
|
+
}, [styles.popper, anchorEl, popoverElement, visible]);
|
|
121
134
|
// Ensure popover is only rendered after the component mounts
|
|
122
135
|
useEffect(function () {
|
|
123
136
|
setHasMounted(true);
|
|
@@ -135,7 +148,7 @@ export default function Popover(_a) {
|
|
|
135
148
|
// dark-only edge: a ring only in dark mode, so it keeps a dark: variant (it follows whatever dark variant the app's preset/@theme defines, class-only or OS-aware)
|
|
136
149
|
return createPortal(<div id={id} ref={setPopoverElement} style={styles.popper} {...attributes.popper} className="z-[var(--os-z-overlay)]" role="dialog" aria-label={dialogLabel} aria-labelledby={ariaLabelledby}>
|
|
137
150
|
{/* Popper owns the outer transform, so the fade and scale go on this inner panel */}
|
|
138
|
-
<div className={"".concat(panelClass, " origin-top-left\n ").concat(
|
|
151
|
+
<div ref={panelRef} className={"".concat(panelClass, " origin-top-left\n ").concat(anchoredTransition, " ").concat(visible ? overlayVisible : anchoredHidden)}>
|
|
139
152
|
{children}
|
|
140
153
|
</div>
|
|
141
154
|
</div>, document.body // Mounting the popover in the document body for isolation
|
|
@@ -6,4 +6,6 @@ export declare const pressFeedbackAny = "active:scale-[0.97]";
|
|
|
6
6
|
export declare const overlayTransition = "transition-[opacity,transform] duration-[var(--os-duration-fast)] ease-emphasized motion-reduce:transition-none";
|
|
7
7
|
export declare const overlayHidden = "opacity-0 scale-[0.96]";
|
|
8
8
|
export declare const overlayVisible = "opacity-100 scale-100";
|
|
9
|
+
export declare const anchoredTransition = "transition-[opacity,transform] duration-100 ease-emphasized motion-reduce:transition-none";
|
|
10
|
+
export declare const anchoredHidden = "opacity-0 scale-[0.85]";
|
|
9
11
|
export declare const popTransition = "transition-transform duration-[var(--os-duration-fast)] ease-spring motion-reduce:transition-none";
|
|
@@ -16,5 +16,9 @@ export var pressFeedbackAny = 'active:scale-[0.97]';
|
|
|
16
16
|
export var overlayTransition = 'transition-[opacity,transform] duration-[var(--os-duration-fast)] ease-emphasized motion-reduce:transition-none';
|
|
17
17
|
export var overlayHidden = 'opacity-0 scale-[0.96]';
|
|
18
18
|
export var overlayVisible = 'opacity-100 scale-100';
|
|
19
|
+
// A Popover starts smaller and grows out of its trigger, so the scale reads as movement.
|
|
20
|
+
// It runs quicker than the other overlays, since it opens on every click of its trigger.
|
|
21
|
+
export var anchoredTransition = 'transition-[opacity,transform] duration-100 ease-emphasized motion-reduce:transition-none';
|
|
22
|
+
export var anchoredHidden = 'opacity-0 scale-[0.85]';
|
|
19
23
|
// Small marks (checkbox tick, radio dot) pop in with a slight overshoot
|
|
20
24
|
export var popTransition = 'transition-transform duration-[var(--os-duration-fast)] ease-spring motion-reduce:transition-none';
|