@vuu-ui/vuu-layout 0.5.4 → 0.5.5
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/README.md +1 -0
- package/cjs/index.js +4 -7379
- package/cjs/index.js.map +7 -0
- package/esm/index.js +20 -0
- package/esm/index.js.map +7 -0
- package/index.css +1 -951
- package/index.css.map +3 -3
- package/package.json +6 -9
- package/src/Component.css +0 -2
- package/src/Component.tsx +0 -20
- package/src/DraggableLayout.css +0 -18
- package/src/DraggableLayout.tsx +0 -29
- package/src/__tests__/flexbox-utils.spec.js +0 -90
- package/src/action-buttons/index.ts +0 -1
- package/src/chest-of-drawers/Chest.css +0 -36
- package/src/chest-of-drawers/Chest.tsx +0 -42
- package/src/chest-of-drawers/Drawer.css +0 -159
- package/src/chest-of-drawers/Drawer.tsx +0 -118
- package/src/chest-of-drawers/index.ts +0 -2
- package/src/common-types.ts +0 -9
- package/src/debug.ts +0 -16
- package/src/dialog/Dialog.css +0 -16
- package/src/dialog/Dialog.tsx +0 -59
- package/src/dialog/index.ts +0 -1
- package/src/drag-drop/BoxModel.ts +0 -546
- package/src/drag-drop/DragState.ts +0 -222
- package/src/drag-drop/Draggable.ts +0 -282
- package/src/drag-drop/DropMenu.css +0 -71
- package/src/drag-drop/DropMenu.tsx +0 -61
- package/src/drag-drop/DropTarget.ts +0 -392
- package/src/drag-drop/DropTargetRenderer.css +0 -40
- package/src/drag-drop/DropTargetRenderer.tsx +0 -279
- package/src/drag-drop/dragDropTypes.ts +0 -49
- package/src/drag-drop/index.ts +0 -4
- package/src/editable-label/EditableLabel.css +0 -28
- package/src/editable-label/EditableLabel.tsx +0 -99
- package/src/editable-label/index.ts +0 -1
- package/src/flexbox/Flexbox.css +0 -45
- package/src/flexbox/Flexbox.tsx +0 -70
- package/src/flexbox/FlexboxLayout.jsx +0 -26
- package/src/flexbox/FluidGrid.css +0 -134
- package/src/flexbox/FluidGrid.tsx +0 -84
- package/src/flexbox/FluidGridLayout.tsx +0 -10
- package/src/flexbox/Splitter.css +0 -140
- package/src/flexbox/Splitter.tsx +0 -135
- package/src/flexbox/flexbox-utils.ts +0 -128
- package/src/flexbox/flexboxTypes.ts +0 -63
- package/src/flexbox/index.ts +0 -4
- package/src/flexbox/useResponsiveSizing.ts +0 -85
- package/src/flexbox/useSplitterResizing.ts +0 -272
- package/src/index.ts +0 -21
- package/src/layout-action.ts +0 -21
- package/src/layout-header/ActionButton.tsx +0 -23
- package/src/layout-header/Header.css +0 -8
- package/src/layout-header/Header.tsx +0 -222
- package/src/layout-header/index.ts +0 -1
- package/src/layout-provider/LayoutProvider.tsx +0 -160
- package/src/layout-provider/LayoutProviderContext.ts +0 -17
- package/src/layout-provider/index.ts +0 -2
- package/src/layout-provider/useLayoutDragDrop.ts +0 -241
- package/src/layout-reducer/flexUtils.ts +0 -281
- package/src/layout-reducer/index.ts +0 -4
- package/src/layout-reducer/insert-layout-element.ts +0 -365
- package/src/layout-reducer/layout-reducer.ts +0 -255
- package/src/layout-reducer/layoutTypes.ts +0 -151
- package/src/layout-reducer/layoutUtils.ts +0 -302
- package/src/layout-reducer/remove-layout-element.ts +0 -240
- package/src/layout-reducer/replace-layout-element.ts +0 -118
- package/src/layout-reducer/resize-flex-children.ts +0 -56
- package/src/layout-reducer/wrap-layout-element.ts +0 -317
- package/src/layout-view/View.css +0 -61
- package/src/layout-view/View.tsx +0 -149
- package/src/layout-view/ViewContext.ts +0 -31
- package/src/layout-view/index.ts +0 -4
- package/src/layout-view/useView.tsx +0 -104
- package/src/layout-view/useViewActionDispatcher.ts +0 -133
- package/src/layout-view/useViewResize.ts +0 -53
- package/src/layout-view/viewTypes.ts +0 -37
- package/src/menu/ContextMenu.css +0 -22
- package/src/menu/ContextMenu.jsx +0 -121
- package/src/menu/MenuList.css +0 -150
- package/src/menu/MenuList.jsx +0 -179
- package/src/menu/aim/aim.js +0 -92
- package/src/menu/aim/corners.js +0 -114
- package/src/menu/aim/point-in-polygon.js +0 -25
- package/src/menu/aim/utils.js +0 -19
- package/src/menu/context-menu-provider.jsx +0 -135
- package/src/menu/index.js +0 -4
- package/src/menu/key-code.js +0 -61
- package/src/menu/list-dom-utils.js +0 -22
- package/src/menu/use-cascade.js +0 -292
- package/src/menu/use-click-away.js +0 -22
- package/src/menu/use-items-with-ids.js +0 -75
- package/src/menu/use-keyboard-navigation.js +0 -162
- package/src/menu/utils.js +0 -5
- package/src/palette/Palette.css +0 -37
- package/src/palette/Palette.tsx +0 -140
- package/src/palette/PaletteSalt.css +0 -9
- package/src/palette/PaletteSalt.tsx +0 -79
- package/src/palette/index.ts +0 -2
- package/src/placeholder/Placeholder.css +0 -10
- package/src/placeholder/Placeholder.tsx +0 -39
- package/src/placeholder/index.ts +0 -1
- package/src/popup/index.js +0 -2
- package/src/popup/popup-provider.js +0 -0
- package/src/popup/popup-service.css +0 -15
- package/src/popup/popup-service.js +0 -281
- package/src/portal/Portal.jsx +0 -50
- package/src/portal/index.ts +0 -3
- package/src/portal/render-portal.jsx +0 -68
- package/src/portal/utils.js +0 -16
- package/src/registry/ComponentRegistry.ts +0 -35
- package/src/registry/index.ts +0 -1
- package/src/responsive/OverflowMenu.css +0 -31
- package/src/responsive/OverflowMenu.jsx +0 -56
- package/src/responsive/breakpoints.ts +0 -62
- package/src/responsive/index.ts +0 -4
- package/src/responsive/measureMinimumNodeSize.ts +0 -23
- package/src/responsive/overflowUtils.js +0 -14
- package/src/responsive/use-breakpoints.ts +0 -100
- package/src/responsive/useOverflowObserver.ts +0 -606
- package/src/responsive/useResizeObserver.ts +0 -154
- package/src/responsive/utils.ts +0 -37
- package/src/stack/Stack.css +0 -39
- package/src/stack/Stack.tsx +0 -161
- package/src/stack/StackLayout.tsx +0 -137
- package/src/stack/index.ts +0 -3
- package/src/stack/stackTypes.ts +0 -19
- package/src/tabs/TabPanel.css +0 -12
- package/src/tabs/TabPanel.tsx +0 -17
- package/src/tabs/index.ts +0 -1
- package/src/tools/config-wrapper/ConfigWrapper.jsx +0 -53
- package/src/tools/config-wrapper/index.js +0 -1
- package/src/tools/devtools-box/layout-configurator.css +0 -112
- package/src/tools/devtools-box/layout-configurator.jsx +0 -369
- package/src/tools/devtools-tree/layout-tree-viewer.css +0 -15
- package/src/tools/devtools-tree/layout-tree-viewer.jsx +0 -36
- package/src/tools/index.js +0 -3
- package/src/use-persistent-state.ts +0 -115
- package/src/utils/apply-handlers.js +0 -15
- package/src/utils/componentFromLayout.tsx +0 -30
- package/src/utils/index.ts +0 -6
- package/src/utils/pathUtils.ts +0 -294
- package/src/utils/propUtils.ts +0 -24
- package/src/utils/refUtils.ts +0 -16
- package/src/utils/styleUtils.ts +0 -14
- package/src/utils/typeOf.ts +0 -22
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import * as ReactDOM from "react-dom";
|
|
2
|
-
import { SaltProvider } from "@salt-ds/core";
|
|
3
|
-
|
|
4
|
-
import { getPortalContainer } from "./utils";
|
|
5
|
-
|
|
6
|
-
const electronAPI = window?.require?.("electron");
|
|
7
|
-
let currentPosition = null;
|
|
8
|
-
let windowId = 1;
|
|
9
|
-
|
|
10
|
-
if (electronAPI) {
|
|
11
|
-
electronAPI.ipcRenderer.on("set-position", (evt, position) => {
|
|
12
|
-
currentPosition = position;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const createDOMContainer = (x, y) => {
|
|
17
|
-
return getPortalContainer(x, y);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const renderDOMPortal = (component, container, x, y, onRender) => {
|
|
21
|
-
// check this first to see if position has changed
|
|
22
|
-
container.style.cssText = `left:${x}px; top:${y}px;position: absolute;`;
|
|
23
|
-
|
|
24
|
-
ReactDOM.render(
|
|
25
|
-
<SaltProvider applyClassesTo="scope">{component}</SaltProvider>,
|
|
26
|
-
container,
|
|
27
|
-
onRender
|
|
28
|
-
);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const renderElectronPortal = (component, x, y, el, onRender) => {
|
|
32
|
-
let portalContainer = null;
|
|
33
|
-
console.log("render electron");
|
|
34
|
-
electronAPI.ipcRenderer.send("portal-request", "open-popup", "");
|
|
35
|
-
console.log(
|
|
36
|
-
`currentPosition: x ${currentPosition.x} y ${currentPosition.y}, x,y ${x} ${y}`
|
|
37
|
-
);
|
|
38
|
-
const top = y + currentPosition.y + 30,
|
|
39
|
-
left = x + currentPosition.x;
|
|
40
|
-
const windowName = `popup_${windowId++}`;
|
|
41
|
-
// console.log(`we're in electron, open window ${windowName} at ${x} ${y}`);
|
|
42
|
-
const win = window.open(
|
|
43
|
-
"",
|
|
44
|
-
windowName,
|
|
45
|
-
`top=${top},left=${left},width=140,height=200,frame=false,resizeable,nodeIntegration=no,roundedCorners=false`
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
portalContainer = getPortalContainer(0, 0, win);
|
|
49
|
-
const handleRender = () => {
|
|
50
|
-
const targetEl = portalContainer.querySelector("hw-theme > *");
|
|
51
|
-
const { height } = targetEl.getBoundingClientRect();
|
|
52
|
-
win.resizeTo(100, height);
|
|
53
|
-
onRender && onRender();
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
ReactDOM.render(
|
|
57
|
-
<SaltProvider applyClassesTo="scope">{component}</SaltProvider>,
|
|
58
|
-
portalContainer,
|
|
59
|
-
handleRender
|
|
60
|
-
);
|
|
61
|
-
return portalContainer;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const renderPortal = electronAPI
|
|
65
|
-
? renderElectronPortal
|
|
66
|
-
: renderDOMPortal;
|
|
67
|
-
|
|
68
|
-
export const createContainer = createDOMContainer;
|
package/src/portal/utils.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export const installTheme = (themeId) => {
|
|
2
|
-
const installedThemes = getComputedStyle(document.body).getPropertyValue('--installed-themes');
|
|
3
|
-
document.body.style.setProperty('--installed-themes', `${installedThemes} ${themeId}`);
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
let containerId = 1;
|
|
7
|
-
|
|
8
|
-
export const getPortalContainer = (x = 0, y = 0, win = window) => {
|
|
9
|
-
// let el = document.body.querySelector('.hwReactPopup.' + group);
|
|
10
|
-
// if (el === null) {
|
|
11
|
-
let el = win.document.createElement('div');
|
|
12
|
-
el.className = 'hwReactPopup ' + containerId++;
|
|
13
|
-
el.style.cssText = `left:${x}px; top:${y}px;position: absolute;`;
|
|
14
|
-
win.document.body.appendChild(el);
|
|
15
|
-
return el;
|
|
16
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React, { FunctionComponent } from 'react';
|
|
2
|
-
|
|
3
|
-
const _containers: { [key: string]: boolean } = {};
|
|
4
|
-
const _views: { [key: string]: boolean } = {};
|
|
5
|
-
|
|
6
|
-
export type layoutComponentType = 'component' | 'container' | 'view';
|
|
7
|
-
|
|
8
|
-
export const ComponentRegistry: { [key: string]: FunctionComponent } = {};
|
|
9
|
-
|
|
10
|
-
export function isContainer(componentType: string) {
|
|
11
|
-
return _containers[componentType] === true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function isView(componentType: string) {
|
|
15
|
-
return _views[componentType] === true;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const isLayoutComponent = (type: string) => isContainer(type) || isView(type);
|
|
19
|
-
|
|
20
|
-
export const isRegistered = (className: string) => !!ComponentRegistry[className];
|
|
21
|
-
|
|
22
|
-
// We could check and set displayName in here
|
|
23
|
-
export function registerComponent(
|
|
24
|
-
componentName: string,
|
|
25
|
-
component: FunctionComponent<any>,
|
|
26
|
-
type: layoutComponentType = 'component'
|
|
27
|
-
) {
|
|
28
|
-
ComponentRegistry[componentName] = component;
|
|
29
|
-
|
|
30
|
-
if (type === 'container') {
|
|
31
|
-
_containers[componentName] = true;
|
|
32
|
-
} else if (type === 'view') {
|
|
33
|
-
_views[componentName] = true;
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/registry/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ComponentRegistry';
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
.OverflowMenu {
|
|
2
|
-
/* width: 20px;
|
|
3
|
-
height: 20px;
|
|
4
|
-
display: flex;
|
|
5
|
-
align-items: center;
|
|
6
|
-
justify-content: center;
|
|
7
|
-
cursor: pointer;
|
|
8
|
-
margin: 6px 0px 6px 0;
|
|
9
|
-
align-self: flex-end;
|
|
10
|
-
border: none;
|
|
11
|
-
border-radius: 0;
|
|
12
|
-
background-color: inherit;
|
|
13
|
-
padding: 0; */
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/* .OverflowMenu-open {
|
|
17
|
-
backgroundcolor: active.overflow.background;
|
|
18
|
-
} */
|
|
19
|
-
|
|
20
|
-
/* .OverflowMenu-open .OverflowMenu-icon {
|
|
21
|
-
color: active.overflow.color;
|
|
22
|
-
} */
|
|
23
|
-
|
|
24
|
-
/* .Toolbar .Toolbar-overflow:hover {
|
|
25
|
-
background-color: lightgrey;
|
|
26
|
-
} */
|
|
27
|
-
|
|
28
|
-
[data-overflowed] {
|
|
29
|
-
order: 99;
|
|
30
|
-
/* visibility: hidden; */
|
|
31
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react';
|
|
2
|
-
import { MoreSmallListVertButton } from '../action-buttons';
|
|
3
|
-
|
|
4
|
-
import './OverflowMenu.css';
|
|
5
|
-
|
|
6
|
-
const OverflowMenu = forwardRef(function OverflowMenu(
|
|
7
|
-
// eslint-disable-next-line no-unused-vars
|
|
8
|
-
{ iconName = 'more', overflowOffsetLeft: left, source = [], ...rest },
|
|
9
|
-
// eslint-disable-next-line no-unused-vars
|
|
10
|
-
ref
|
|
11
|
-
) {
|
|
12
|
-
return source.length > 0 ? (
|
|
13
|
-
<MoreSmallListVertButton />
|
|
14
|
-
) : // <Dropdown
|
|
15
|
-
// ListProps={{
|
|
16
|
-
// width: 200,
|
|
17
|
-
// }}
|
|
18
|
-
// ref={ref}
|
|
19
|
-
// source={source}
|
|
20
|
-
// {...rest}
|
|
21
|
-
// >
|
|
22
|
-
// {({ DropdownButtonProps, isOpen }) => {
|
|
23
|
-
// const { style, ...restButtonProps } = DropdownButtonProps;
|
|
24
|
-
|
|
25
|
-
// const {
|
|
26
|
-
// onClick,
|
|
27
|
-
// onKeyDown,
|
|
28
|
-
// onFocus,
|
|
29
|
-
// onBlur,
|
|
30
|
-
// 'aria-expanded': menuOpen, // do we use this or isOpen ?
|
|
31
|
-
// } = DropdownButtonProps;
|
|
32
|
-
// const defaultProps = {
|
|
33
|
-
// 'data-jpmui-test': 'dropdown-button',
|
|
34
|
-
// 'aria-label': 'toggle overflow',
|
|
35
|
-
// 'aria-haspopup': true,
|
|
36
|
-
// className: cx('OverflowMenu-dropdown', {
|
|
37
|
-
// 'OverflowMenu-open': isOpen,
|
|
38
|
-
// }),
|
|
39
|
-
// onBlur,
|
|
40
|
-
// onPress: onClick,
|
|
41
|
-
// onFocus,
|
|
42
|
-
// onKeyDown,
|
|
43
|
-
// title: 'Overflow Menu',
|
|
44
|
-
// type: 'button',
|
|
45
|
-
// variant: 'secondary',
|
|
46
|
-
// };
|
|
47
|
-
|
|
48
|
-
// return (
|
|
49
|
-
// <MoreSmallListVertButton {...defaultProps}/>
|
|
50
|
-
// );
|
|
51
|
-
// }}
|
|
52
|
-
// </Dropdown>
|
|
53
|
-
null;
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
export default OverflowMenu;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// should we have some global; defaults ?
|
|
2
|
-
|
|
3
|
-
import { BreakPointsProp } from "../flexbox/flexboxTypes";
|
|
4
|
-
|
|
5
|
-
export type BreakPointRamp = [string, number, number];
|
|
6
|
-
|
|
7
|
-
function breakpointReader(
|
|
8
|
-
themeName: string,
|
|
9
|
-
defaultBreakpoints?: BreakPointsProp
|
|
10
|
-
) {
|
|
11
|
-
//TODO ownerDocument
|
|
12
|
-
const themeRoot = document.body.querySelector(`.${themeName}`);
|
|
13
|
-
const handler = {
|
|
14
|
-
get: function (style: CSSStyleDeclaration, stopName: string) {
|
|
15
|
-
const val = style.getPropertyValue(
|
|
16
|
-
// lets assume we have the following naming convention
|
|
17
|
-
`--${themeName}-breakpoint-${stopName}`
|
|
18
|
-
);
|
|
19
|
-
return val ? parseInt(val) : undefined;
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return themeRoot
|
|
24
|
-
? new Proxy(getComputedStyle(themeRoot), handler)
|
|
25
|
-
: defaultBreakpoints ?? {};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const byDescendingStopSize = (
|
|
29
|
-
[, s1]: [string, number],
|
|
30
|
-
[, s2]: [string, number]
|
|
31
|
-
) => s2 - s1;
|
|
32
|
-
|
|
33
|
-
// These are assumed to be min-width (aka mobile-first) stops, we could take a
|
|
34
|
-
// paramneter to support max-width as well ?
|
|
35
|
-
// return [stopName, minWidth, maxWidth]
|
|
36
|
-
export const breakpointRamp = (
|
|
37
|
-
breakpoints: BreakPointsProp
|
|
38
|
-
): BreakPointRamp[] =>
|
|
39
|
-
Object.entries(breakpoints)
|
|
40
|
-
.sort(byDescendingStopSize)
|
|
41
|
-
.map(([name, value], i, all) => [
|
|
42
|
-
name,
|
|
43
|
-
value,
|
|
44
|
-
i < all.length - 1 ? all[i + 1][1] : 9999,
|
|
45
|
-
]);
|
|
46
|
-
|
|
47
|
-
let documentBreakpoints: BreakPointRamp[] | null = null;
|
|
48
|
-
|
|
49
|
-
const loadBreakpoints = (themeName = "salt") => {
|
|
50
|
-
// TODO would be nice to read these breakpoint labels from a css variable to
|
|
51
|
-
// avoid hard-coding them here ?
|
|
52
|
-
const { xs, sm, md, lg, xl } = breakpointReader(themeName) as BreakPointsProp;
|
|
53
|
-
return breakpointRamp({ xs, sm, md, lg, xl });
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
//TODO support multiple themes loaded
|
|
57
|
-
export const getBreakPoints = (themeName?: string) => {
|
|
58
|
-
if (documentBreakpoints === null) {
|
|
59
|
-
documentBreakpoints = loadBreakpoints(themeName);
|
|
60
|
-
}
|
|
61
|
-
return documentBreakpoints;
|
|
62
|
-
};
|
package/src/responsive/index.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const LEFT_RIGHT = ['left', 'right'];
|
|
2
|
-
const TOP_BOTTOM = ['top', 'bottom'];
|
|
3
|
-
|
|
4
|
-
export function measureMinimumNodeSize(node: HTMLElement, dimension: 'width' | 'height' = 'width') {
|
|
5
|
-
const { [dimension]: size } = node.getBoundingClientRect();
|
|
6
|
-
const { padRight = false, padLeft = false } = node.dataset;
|
|
7
|
-
const style = getComputedStyle(node);
|
|
8
|
-
const [start, end] = dimension === 'width' ? LEFT_RIGHT : TOP_BOTTOM;
|
|
9
|
-
const marginStart = padLeft ? 0 : parseInt(style.getPropertyValue(`margin-${start}`), 10);
|
|
10
|
-
const marginEnd = padRight ? 0 : parseInt(style.getPropertyValue(`margin-${end}`), 10);
|
|
11
|
-
|
|
12
|
-
let minWidth = size;
|
|
13
|
-
const flexShrink = parseInt(style.getPropertyValue('flex-shrink'), 10);
|
|
14
|
-
if (flexShrink > 0) {
|
|
15
|
-
const flexBasis = parseInt(style.getPropertyValue('flex-basis'), 10);
|
|
16
|
-
// TODO what about percentage values ?
|
|
17
|
-
if (!isNaN(flexBasis)) {
|
|
18
|
-
minWidth = flexBasis;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return marginStart + minWidth + marginEnd;
|
|
23
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const getOverflowedItems = (containerRef, height = 64) => {
|
|
2
|
-
const elements = Array.from(containerRef.current.childNodes);
|
|
3
|
-
const firstOverflowIdx = findFirstOverflow(elements, height);
|
|
4
|
-
return [elements.slice(0, firstOverflowIdx), elements.slice(firstOverflowIdx)];
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const findFirstOverflow = (elements, height) => {
|
|
8
|
-
for (let i = 0; i < elements.length; i++) {
|
|
9
|
-
if (elements[i].offsetTop >= height) {
|
|
10
|
-
return i;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return -1;
|
|
14
|
-
};
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { RefObject, useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { useResizeObserver } from './useResizeObserver';
|
|
3
|
-
import {
|
|
4
|
-
BreakPointRamp,
|
|
5
|
-
breakpointRamp,
|
|
6
|
-
getBreakPoints as getDocumentBreakpoints
|
|
7
|
-
} from './breakpoints';
|
|
8
|
-
import { BreakPoint, BreakPointsProp } from '../flexbox/flexboxTypes';
|
|
9
|
-
import { ExecFileOptionsWithStringEncoding } from 'child_process';
|
|
10
|
-
|
|
11
|
-
const EMPTY_ARRAY: BreakPoint[] = [];
|
|
12
|
-
|
|
13
|
-
export interface BreakpointsHookProps {
|
|
14
|
-
breakPoints?: BreakPointsProp;
|
|
15
|
-
smallerThan?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// TODO how do we cater for smallerThan/greaterThan breakpoints
|
|
19
|
-
export const useBreakpoints = (
|
|
20
|
-
{ breakPoints: breakPointsProp, smallerThan }: BreakpointsHookProps,
|
|
21
|
-
ref: RefObject<any>
|
|
22
|
-
) => {
|
|
23
|
-
const [breakpointMatch, setBreakpointmatch] = useState(smallerThan ? false : 'lg');
|
|
24
|
-
const bodyRef = useRef(document.body);
|
|
25
|
-
const breakPointsRef = useRef(
|
|
26
|
-
breakPointsProp ? breakpointRamp(breakPointsProp) : getDocumentBreakpoints()
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
// TODO how do we identify the default
|
|
30
|
-
const sizeRef = useRef('lg');
|
|
31
|
-
|
|
32
|
-
const stopFromMinWidth = useCallback(
|
|
33
|
-
(w) => {
|
|
34
|
-
if (breakPointsRef.current) {
|
|
35
|
-
for (let [name, size] of breakPointsRef.current) {
|
|
36
|
-
if (w >= size) {
|
|
37
|
-
return name;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
[breakPointsRef]
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const matchSizeAgainstBreakpoints = useCallback(
|
|
46
|
-
(width) => {
|
|
47
|
-
if (smallerThan) {
|
|
48
|
-
const breakPointRamp = breakPointsRef.current.find(
|
|
49
|
-
([name]: BreakPointRamp) => name === smallerThan
|
|
50
|
-
);
|
|
51
|
-
if (breakPointRamp) {
|
|
52
|
-
const [, , maxValue] = breakPointRamp;
|
|
53
|
-
return width < maxValue;
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
return stopFromMinWidth(width);
|
|
57
|
-
}
|
|
58
|
-
// is this right ?
|
|
59
|
-
return width;
|
|
60
|
-
},
|
|
61
|
-
[smallerThan, stopFromMinWidth]
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// TODO need to make the dimension a config
|
|
65
|
-
useResizeObserver(
|
|
66
|
-
ref || bodyRef,
|
|
67
|
-
breakPointsRef.current ? ['width'] : EMPTY_ARRAY,
|
|
68
|
-
({ width: measuredWidth }: { width: number }) => {
|
|
69
|
-
const result = matchSizeAgainstBreakpoints(measuredWidth);
|
|
70
|
-
if (result !== sizeRef.current) {
|
|
71
|
-
sizeRef.current = result;
|
|
72
|
-
setBreakpointmatch(result);
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
true
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
const target = ref || bodyRef;
|
|
80
|
-
if (target.current) {
|
|
81
|
-
const prevSize = sizeRef.current;
|
|
82
|
-
if (breakPointsRef.current) {
|
|
83
|
-
// We're measuring here when the resizeObserver has also measured
|
|
84
|
-
// There isn't a convenient way to get the Resizeobserver to
|
|
85
|
-
// notify initial size - that's not really its job, unless we
|
|
86
|
-
// set a flag ?
|
|
87
|
-
const { clientWidth } = target.current;
|
|
88
|
-
const result = matchSizeAgainstBreakpoints(clientWidth);
|
|
89
|
-
sizeRef.current = result;
|
|
90
|
-
// If initial size of ref does not match the default, notify client after render
|
|
91
|
-
if (result !== prevSize) {
|
|
92
|
-
setBreakpointmatch(result);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}, [setBreakpointmatch, matchSizeAgainstBreakpoints, ref]);
|
|
97
|
-
|
|
98
|
-
// No, just ass the class directly to the ref, no need to render
|
|
99
|
-
return breakpointMatch;
|
|
100
|
-
};
|