@vitessce/styles 3.9.0 → 3.9.2

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/src/Popper.js DELETED
@@ -1,221 +0,0 @@
1
- /*
2
- * This is the Popper component from MUI v4 which uses Popper.js v1.
3
- * The Popper in MUI v7 uses Popper.js v2 and does not seem to respect the anchorEl's positioning,
4
- * which is the reason we copy the v4 version here.
5
- * Reference: https://github.com/mui/material-ui/blob/v4.x/packages/material-ui/src/Popper/Popper.js
6
- */
7
- import * as React from 'react';
8
- import PopperJs from 'popper.js';
9
- import { useStyles as useTheme } from 'tss-react/mui';
10
- import { Portal } from '@mui/material';
11
- import { createChainedFunction, setRef, useForkRef } from './utils.js';
12
-
13
- function flipPlacement(placement, theme) {
14
- const direction = (theme && theme.direction) || 'ltr';
15
-
16
- if (direction === 'ltr') {
17
- return placement;
18
- }
19
-
20
- switch (placement) {
21
- case 'bottom-end':
22
- return 'bottom-start';
23
- case 'bottom-start':
24
- return 'bottom-end';
25
- case 'top-end':
26
- return 'top-start';
27
- case 'top-start':
28
- return 'top-end';
29
- default:
30
- return placement;
31
- }
32
- }
33
-
34
- function getAnchorEl(anchorEl) {
35
- return typeof anchorEl === 'function' ? anchorEl() : anchorEl;
36
- }
37
-
38
- const useEnhancedEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
39
-
40
- const defaultPopperOptions = {};
41
-
42
- /**
43
- * Poppers rely on the 3rd party library [Popper.js](https://popper.js.org/docs/v1/) for positioning.
44
- */
45
- export const Popper = React.forwardRef((props, ref) => {
46
- const {
47
- anchorEl,
48
- children,
49
- container,
50
- disablePortal = false,
51
- keepMounted = false,
52
- modifiers,
53
- open,
54
- placement: initialPlacement = 'bottom',
55
- popperOptions = defaultPopperOptions,
56
- popperRef: popperRefProp,
57
- style,
58
- transition = false,
59
- ...other
60
- } = props;
61
- const tooltipRef = React.useRef(null);
62
- const ownRef = useForkRef(tooltipRef, ref);
63
-
64
- const popperRef = React.useRef(null);
65
- const handlePopperRef = useForkRef(popperRef, popperRefProp);
66
- const handlePopperRefRef = React.useRef(handlePopperRef);
67
- useEnhancedEffect(() => {
68
- handlePopperRefRef.current = handlePopperRef;
69
- }, [handlePopperRef]);
70
- React.useImperativeHandle(popperRefProp, () => popperRef.current, []);
71
-
72
- const [exited, setExited] = React.useState(true);
73
-
74
- const { theme } = useTheme();
75
- const rtlPlacement = flipPlacement(initialPlacement, theme);
76
- /**
77
- * placement initialized from prop but can change during lifetime if modifiers.flip.
78
- * modifiers.flip is essentially a flip for controlled/uncontrolled behavior
79
- */
80
- const [placement, setPlacement] = React.useState(rtlPlacement);
81
-
82
- React.useEffect(() => {
83
- if (popperRef.current) {
84
- popperRef.current.update();
85
- }
86
- });
87
-
88
- const handleOpen = React.useCallback(() => {
89
- if (!tooltipRef.current || !anchorEl || !open) {
90
- return;
91
- }
92
-
93
- if (popperRef.current) {
94
- popperRef.current.destroy();
95
- handlePopperRefRef.current(null);
96
- }
97
-
98
- const handlePopperUpdate = (data) => {
99
- setPlacement(data.placement);
100
- };
101
-
102
- const resolvedAnchorEl = getAnchorEl(anchorEl);
103
-
104
- if (process.env.NODE_ENV !== 'production') {
105
- if (resolvedAnchorEl && resolvedAnchorEl.nodeType === 1) {
106
- const box = resolvedAnchorEl.getBoundingClientRect();
107
-
108
- if (
109
- process.env.NODE_ENV !== 'test'
110
- && box.top === 0
111
- && box.left === 0
112
- && box.right === 0
113
- && box.bottom === 0
114
- ) {
115
- console.warn(
116
- [
117
- 'Material-UI: The `anchorEl` prop provided to the component is invalid.',
118
- 'The anchor element should be part of the document layout.',
119
- "Make sure the element is present in the document or that it's not display none.",
120
- ].join('\n'),
121
- );
122
- }
123
- }
124
- }
125
-
126
- const popper = new PopperJs(getAnchorEl(anchorEl), tooltipRef.current, {
127
- placement: rtlPlacement,
128
- ...popperOptions,
129
- modifiers: {
130
- ...(disablePortal
131
- ? {}
132
- : {
133
- // It's using scrollParent by default, we can use the viewport when using a portal.
134
- preventOverflow: {
135
- boundariesElement: 'window',
136
- },
137
- }),
138
- ...modifiers,
139
- ...popperOptions.modifiers,
140
- },
141
- // We could have been using a custom modifier like react-popper is doing.
142
- // But it seems this is the best public API for this use case.
143
- onCreate: createChainedFunction(handlePopperUpdate, popperOptions.onCreate),
144
- onUpdate: createChainedFunction(handlePopperUpdate, popperOptions.onUpdate),
145
- });
146
-
147
- handlePopperRefRef.current(popper);
148
- }, [anchorEl, disablePortal, modifiers, open, rtlPlacement, popperOptions]);
149
-
150
- const handleRef = React.useCallback(
151
- (node) => {
152
- setRef(ownRef, node);
153
- handleOpen();
154
- },
155
- [ownRef, handleOpen],
156
- );
157
-
158
- const handleEnter = () => {
159
- setExited(false);
160
- };
161
-
162
- const handleClose = () => {
163
- if (!popperRef.current) {
164
- return;
165
- }
166
-
167
- popperRef.current.destroy();
168
- handlePopperRefRef.current(null);
169
- };
170
-
171
- const handleExited = () => {
172
- setExited(true);
173
- handleClose();
174
- };
175
-
176
- React.useEffect(() => () => {
177
- handleClose();
178
- }, []);
179
-
180
- React.useEffect(() => {
181
- if (!open && !transition) {
182
- // Otherwise handleExited will call this.
183
- handleClose();
184
- }
185
- }, [open, transition]);
186
-
187
- if (!keepMounted && !open && (!transition || exited)) {
188
- return null;
189
- }
190
-
191
- const childProps = { placement };
192
-
193
- if (transition) {
194
- childProps.TransitionProps = {
195
- in: open,
196
- onEnter: handleEnter,
197
- onExited: handleExited,
198
- };
199
- }
200
-
201
- return (
202
- <Portal disablePortal={disablePortal} container={container}>
203
- <div
204
- ref={handleRef}
205
- role="tooltip"
206
- {...other}
207
- style={{
208
- // Prevents scroll issue, waiting for Popper.js to add this style once initiated.
209
- position: 'fixed',
210
- // Fix Popper.js display issue
211
- top: 0,
212
- left: 0,
213
- display: !open && keepMounted && !transition ? 'none' : null,
214
- ...style,
215
- }}
216
- >
217
- {typeof children === 'function' ? children(childProps) : children}
218
- </div>
219
- </Portal>
220
- );
221
- });
@@ -1,24 +0,0 @@
1
- import React, { useMemo } from 'react';
2
- import { GlobalStyles } from 'tss-react';
3
-
4
- function prependParentClassName(jssObject, parentClassName) {
5
- return Object.entries(jssObject).reduce((accumulator, [key, value]) => {
6
- accumulator[`.${parentClassName} ${key}`] = value;
7
- return accumulator;
8
- }, {});
9
- }
10
-
11
- export function ScopedGlobalStyles(props) {
12
- const { styles, parentClassName } = props;
13
-
14
- const component = useMemo(() => {
15
- const computedStyles = prependParentClassName(
16
- styles,
17
- parentClassName,
18
- );
19
- return (
20
- <GlobalStyles styles={computedStyles} />
21
- );
22
- }, [parentClassName]);
23
- return component;
24
- }
File without changes