@dxos/react-ui 0.8.4-main.937b3ca → 0.8.4-main.9735255
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/dist/lib/browser/index.mjs +130 -34
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +130 -34
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Main/Main.d.ts +36 -11
- package/dist/types/src/components/Main/Main.d.ts.map +1 -1
- package/dist/types/src/components/Main/Main.stories.d.ts +2 -1
- package/dist/types/src/components/Main/Main.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -15
- package/src/components/Main/Main.stories.tsx +127 -20
- package/src/components/Main/Main.tsx +254 -47
|
@@ -1248,8 +1248,9 @@ import { Primitive as Primitive7 } from "@radix-ui/react-primitive";
|
|
|
1248
1248
|
import { Slot as Slot8 } from "@radix-ui/react-slot";
|
|
1249
1249
|
import { useControllableState as useControllableState3 } from "@radix-ui/react-use-controllable-state";
|
|
1250
1250
|
import React20, { forwardRef as forwardRef16, useCallback as useCallback7, useEffect as useEffect3, useRef, useState as useState5 } from "react";
|
|
1251
|
+
import { addEventListener } from "@dxos/async";
|
|
1251
1252
|
import { log } from "@dxos/log";
|
|
1252
|
-
import { useForwardedRef, useMediaQuery } from "@dxos/react-hooks";
|
|
1253
|
+
import { useDynamicRef, useForwardedRef, useMediaQuery, useViewportResize as useViewportResize2 } from "@dxos/react-hooks";
|
|
1253
1254
|
|
|
1254
1255
|
// src/components/Main/useSwipeToDismiss.ts
|
|
1255
1256
|
import { useCallback as useCallback6, useEffect as useEffect2, useState as useState4 } from "react";
|
|
@@ -1348,7 +1349,10 @@ var MAIN_NAME = "Main";
|
|
|
1348
1349
|
var MAIN_ROOT_NAME = "MainRoot";
|
|
1349
1350
|
var NAVIGATION_SIDEBAR_NAME = "NavigationSidebar";
|
|
1350
1351
|
var COMPLEMENTARY_SIDEBAR_NAME = "ComplementarySidebar";
|
|
1351
|
-
var
|
|
1352
|
+
var DRAWER_NAME = "Drawer";
|
|
1353
|
+
var handleOpenAutoFocus = (event) => {
|
|
1354
|
+
!document.body.hasAttribute("data-is-keyboard") && event.preventDefault();
|
|
1355
|
+
};
|
|
1352
1356
|
var landmarkAttr = "data-main-landmark";
|
|
1353
1357
|
var useLandmarkMover = (propsOnKeyDown, landmark) => {
|
|
1354
1358
|
const handleKeyDown = useCallback7((event) => {
|
|
@@ -1372,35 +1376,67 @@ var useLandmarkMover = (propsOnKeyDown, landmark) => {
|
|
|
1372
1376
|
}
|
|
1373
1377
|
});
|
|
1374
1378
|
return {
|
|
1375
|
-
onKeyDown: handleKeyDown,
|
|
1376
1379
|
[landmarkAttr]: landmark,
|
|
1377
1380
|
tabIndex: 0,
|
|
1381
|
+
onKeyDown: handleKeyDown,
|
|
1378
1382
|
...focusableGroupAttrs
|
|
1379
1383
|
};
|
|
1380
1384
|
};
|
|
1385
|
+
var isFullscreen = () => {
|
|
1386
|
+
const isMobile = window.innerHeight <= 1e3;
|
|
1387
|
+
return window.visualViewport && isMobile ? window.visualViewport.height < 700 : false;
|
|
1388
|
+
};
|
|
1389
|
+
var useDynamicDrawer = (consumerName) => {
|
|
1390
|
+
const { drawerState, setDrawerState } = useSidebars(consumerName);
|
|
1391
|
+
const drawersStateRef = useDynamicRef(drawerState);
|
|
1392
|
+
const checkViewport = useCallback7(() => {
|
|
1393
|
+
if (window.visualViewport) {
|
|
1394
|
+
document.documentElement.style.setProperty("--visual-viewport-height", `${window.visualViewport.height}px`);
|
|
1395
|
+
}
|
|
1396
|
+
if (drawersStateRef.current !== "closed") {
|
|
1397
|
+
setDrawerState(isFullscreen() ? "full" : "expanded");
|
|
1398
|
+
}
|
|
1399
|
+
}, [
|
|
1400
|
+
setDrawerState
|
|
1401
|
+
]);
|
|
1402
|
+
useViewportResize2(checkViewport, [], 100);
|
|
1403
|
+
useEffect3(() => addEventListener(window, "resize", checkViewport), [
|
|
1404
|
+
checkViewport
|
|
1405
|
+
]);
|
|
1406
|
+
return drawerState;
|
|
1407
|
+
};
|
|
1381
1408
|
var [MainProvider, useMainContext] = createContext6(MAIN_NAME, {
|
|
1382
1409
|
resizing: false,
|
|
1383
1410
|
navigationSidebarState: "closed",
|
|
1384
1411
|
setNavigationSidebarState: (_nextState) => {
|
|
1385
|
-
log.warn("
|
|
1412
|
+
log.warn("Not initialized", void 0, {
|
|
1386
1413
|
F: __dxlog_file,
|
|
1387
|
-
L:
|
|
1414
|
+
L: 150,
|
|
1388
1415
|
S: void 0,
|
|
1389
1416
|
C: (f, a) => f(...a)
|
|
1390
1417
|
});
|
|
1391
1418
|
},
|
|
1392
1419
|
complementarySidebarState: "closed",
|
|
1393
1420
|
setComplementarySidebarState: (_nextState) => {
|
|
1394
|
-
log.warn("
|
|
1421
|
+
log.warn("Not initialized", void 0, {
|
|
1395
1422
|
F: __dxlog_file,
|
|
1396
|
-
L:
|
|
1423
|
+
L: 155,
|
|
1424
|
+
S: void 0,
|
|
1425
|
+
C: (f, a) => f(...a)
|
|
1426
|
+
});
|
|
1427
|
+
},
|
|
1428
|
+
drawerState: "closed",
|
|
1429
|
+
setDrawerState: (_nextState) => {
|
|
1430
|
+
log.warn("Not initialized", void 0, {
|
|
1431
|
+
F: __dxlog_file,
|
|
1432
|
+
L: 160,
|
|
1397
1433
|
S: void 0,
|
|
1398
1434
|
C: (f, a) => f(...a)
|
|
1399
1435
|
});
|
|
1400
1436
|
}
|
|
1401
1437
|
});
|
|
1402
|
-
var useSidebars = (consumerName
|
|
1403
|
-
const { setNavigationSidebarState,
|
|
1438
|
+
var useSidebars = (consumerName) => {
|
|
1439
|
+
const { navigationSidebarState, setNavigationSidebarState, complementarySidebarState, setComplementarySidebarState, drawerState, setDrawerState } = useMainContext(consumerName);
|
|
1404
1440
|
return {
|
|
1405
1441
|
navigationSidebarState,
|
|
1406
1442
|
setNavigationSidebarState,
|
|
@@ -1419,11 +1455,18 @@ var useSidebars = (consumerName = GENERIC_CONSUMER_NAME) => {
|
|
|
1419
1455
|
]),
|
|
1420
1456
|
openComplementarySidebar: useCallback7(() => setComplementarySidebarState("expanded"), []),
|
|
1421
1457
|
collapseComplementarySidebar: useCallback7(() => setComplementarySidebarState("collapsed"), []),
|
|
1422
|
-
closeComplementarySidebar: useCallback7(() => setComplementarySidebarState("closed"), [])
|
|
1458
|
+
closeComplementarySidebar: useCallback7(() => setComplementarySidebarState("closed"), []),
|
|
1459
|
+
drawerState,
|
|
1460
|
+
setDrawerState,
|
|
1461
|
+
toggleDrawer: useCallback7(() => setDrawerState(drawerState === "closed" ? isFullscreen() ? "full" : "expanded" : "closed"), [
|
|
1462
|
+
drawerState,
|
|
1463
|
+
setDrawerState
|
|
1464
|
+
]),
|
|
1465
|
+
openDrawer: useCallback7(() => setDrawerState("expanded"), []),
|
|
1466
|
+
closeDrawer: useCallback7(() => setDrawerState("closed"), [])
|
|
1423
1467
|
};
|
|
1424
1468
|
};
|
|
1425
|
-
var
|
|
1426
|
-
var MainRoot = ({ navigationSidebarState: propsNavigationSidebarState, defaultNavigationSidebarState, onNavigationSidebarStateChange, complementarySidebarState: propsComplementarySidebarState, defaultComplementarySidebarState, onComplementarySidebarStateChange, children, ...props }) => {
|
|
1469
|
+
var MainRoot = ({ navigationSidebarState: propsNavigationSidebarState, defaultNavigationSidebarState = "closed", onNavigationSidebarStateChange, complementarySidebarState: propsComplementarySidebarState, defaultComplementarySidebarState = "closed", onComplementarySidebarStateChange, drawerState: propsDrawerState, defaultDrawerState = "closed", onDrawerStateChange, children, ...props }) => {
|
|
1427
1470
|
const [isLg] = useMediaQuery("lg");
|
|
1428
1471
|
const [navigationSidebarState = isLg ? "expanded" : "collapsed", setNavigationSidebarState] = useControllableState3({
|
|
1429
1472
|
prop: propsNavigationSidebarState,
|
|
@@ -1435,9 +1478,14 @@ var MainRoot = ({ navigationSidebarState: propsNavigationSidebarState, defaultNa
|
|
|
1435
1478
|
defaultProp: defaultComplementarySidebarState,
|
|
1436
1479
|
onChange: onComplementarySidebarStateChange
|
|
1437
1480
|
});
|
|
1481
|
+
const [drawerState = "closed", setDrawerState] = useControllableState3({
|
|
1482
|
+
prop: propsDrawerState,
|
|
1483
|
+
defaultProp: defaultDrawerState,
|
|
1484
|
+
onChange: onDrawerStateChange
|
|
1485
|
+
});
|
|
1438
1486
|
const [resizing, setResizing] = useState5(false);
|
|
1439
1487
|
const resizeInterval = useRef(null);
|
|
1440
|
-
|
|
1488
|
+
useEffect3(() => addEventListener(window, "resize", () => {
|
|
1441
1489
|
setResizing(true);
|
|
1442
1490
|
if (resizeInterval.current) {
|
|
1443
1491
|
clearTimeout(resizeInterval.current);
|
|
@@ -1445,27 +1493,20 @@ var MainRoot = ({ navigationSidebarState: propsNavigationSidebarState, defaultNa
|
|
|
1445
1493
|
resizeInterval.current = setTimeout(() => {
|
|
1446
1494
|
setResizing(false);
|
|
1447
1495
|
resizeInterval.current = null;
|
|
1448
|
-
},
|
|
1449
|
-
}, []);
|
|
1450
|
-
useEffect3(() => {
|
|
1451
|
-
window.addEventListener("resize", handleResize);
|
|
1452
|
-
return () => window.removeEventListener("resize", handleResize);
|
|
1453
|
-
}, [
|
|
1454
|
-
handleResize
|
|
1455
|
-
]);
|
|
1496
|
+
}, 3e3);
|
|
1497
|
+
}), []);
|
|
1456
1498
|
return /* @__PURE__ */ React20.createElement(MainProvider, {
|
|
1457
1499
|
...props,
|
|
1458
1500
|
navigationSidebarState,
|
|
1459
1501
|
setNavigationSidebarState,
|
|
1460
1502
|
complementarySidebarState,
|
|
1461
1503
|
setComplementarySidebarState,
|
|
1504
|
+
drawerState,
|
|
1505
|
+
setDrawerState,
|
|
1462
1506
|
resizing
|
|
1463
1507
|
}, children);
|
|
1464
1508
|
};
|
|
1465
1509
|
MainRoot.displayName = MAIN_ROOT_NAME;
|
|
1466
|
-
var handleOpenAutoFocus = (event) => {
|
|
1467
|
-
!document.body.hasAttribute("data-is-keyboard") && event.preventDefault();
|
|
1468
|
-
};
|
|
1469
1510
|
var MainSidebar = /* @__PURE__ */ forwardRef16(({ classNames, children, swipeToDismiss, onOpenAutoFocus, state, resizing, onStateChange, side, label, ...props }, forwardedRef) => {
|
|
1470
1511
|
const [isLg] = useMediaQuery("lg");
|
|
1471
1512
|
const { tx } = useThemeContext();
|
|
@@ -1499,15 +1540,15 @@ var MainSidebar = /* @__PURE__ */ forwardRef16(({ classNames, children, swipeToD
|
|
|
1499
1540
|
tabIndex: -1,
|
|
1500
1541
|
onOpenAutoFocus: onOpenAutoFocus ?? handleOpenAutoFocus
|
|
1501
1542
|
},
|
|
1543
|
+
...state === "closed" && {
|
|
1544
|
+
inert: true
|
|
1545
|
+
},
|
|
1502
1546
|
...props,
|
|
1503
1547
|
"data-side": side === "inline-end" ? "ie" : "is",
|
|
1504
1548
|
"data-state": state,
|
|
1505
1549
|
"data-resizing": resizing ? "true" : "false",
|
|
1506
1550
|
className: tx("main.sidebar", "main__sidebar", {}, classNames),
|
|
1507
1551
|
onKeyDownCapture: handleKeyDown,
|
|
1508
|
-
...state === "closed" && {
|
|
1509
|
-
inert: true
|
|
1510
|
-
},
|
|
1511
1552
|
ref
|
|
1512
1553
|
}, children));
|
|
1513
1554
|
});
|
|
@@ -1538,9 +1579,61 @@ var MainComplementarySidebar = /* @__PURE__ */ forwardRef16((props, forwardedRef
|
|
|
1538
1579
|
ref: forwardedRef
|
|
1539
1580
|
});
|
|
1540
1581
|
});
|
|
1541
|
-
|
|
1582
|
+
MainComplementarySidebar.displayName = COMPLEMENTARY_SIDEBAR_NAME;
|
|
1583
|
+
var MainDrawer = /* @__PURE__ */ forwardRef16(({ classNames, children, swipeToDismiss, onOpenAutoFocus, state, resizing, onStateChange, label, ...props }, forwardedRef) => {
|
|
1584
|
+
const [isLg] = useMediaQuery("lg");
|
|
1585
|
+
const { tx } = useThemeContext();
|
|
1586
|
+
const { t } = useTranslation();
|
|
1587
|
+
const ref = useForwardedRef(forwardedRef);
|
|
1588
|
+
const noopRef = useRef(null);
|
|
1589
|
+
useSwipeToDismiss(swipeToDismiss ? ref : noopRef, {
|
|
1590
|
+
onDismiss: () => onStateChange?.("closed")
|
|
1591
|
+
});
|
|
1592
|
+
const handleKeyDown = useCallback7((event) => {
|
|
1593
|
+
const focusGroupParent = event.target.closest("[data-tabster]");
|
|
1594
|
+
if (event.key === "Escape" && focusGroupParent) {
|
|
1595
|
+
event.preventDefault();
|
|
1596
|
+
event.stopPropagation();
|
|
1597
|
+
focusGroupParent.focus();
|
|
1598
|
+
}
|
|
1599
|
+
props.onKeyDown?.(event);
|
|
1600
|
+
}, [
|
|
1601
|
+
props.onKeyDown
|
|
1602
|
+
]);
|
|
1603
|
+
return /* @__PURE__ */ React20.createElement(Primitive7.div, {
|
|
1604
|
+
...state === "closed" && {
|
|
1605
|
+
inert: true
|
|
1606
|
+
},
|
|
1607
|
+
...!isLg && {
|
|
1608
|
+
forceMount: true,
|
|
1609
|
+
tabIndex: -1,
|
|
1610
|
+
onOpenAutoFocus: onOpenAutoFocus ?? handleOpenAutoFocus
|
|
1611
|
+
},
|
|
1612
|
+
...props,
|
|
1613
|
+
role: "region",
|
|
1614
|
+
"aria-label": toLocalizedString(label, t),
|
|
1615
|
+
"data-state": state,
|
|
1616
|
+
"data-resizing": resizing ? "true" : "false",
|
|
1617
|
+
className: tx("main.drawer", "main__drawer", {}, classNames),
|
|
1618
|
+
onKeyDownCapture: handleKeyDown,
|
|
1619
|
+
ref
|
|
1620
|
+
}, children);
|
|
1621
|
+
});
|
|
1622
|
+
var MainDrawerRoot = /* @__PURE__ */ forwardRef16((props, forwardedRef) => {
|
|
1623
|
+
const { drawerState, setDrawerState, resizing } = useMainContext(DRAWER_NAME);
|
|
1624
|
+
const mover = useLandmarkMover(props.onKeyDown, "3");
|
|
1625
|
+
return /* @__PURE__ */ React20.createElement(MainDrawer, {
|
|
1626
|
+
...mover,
|
|
1627
|
+
...props,
|
|
1628
|
+
resizing,
|
|
1629
|
+
state: drawerState,
|
|
1630
|
+
onStateChange: setDrawerState,
|
|
1631
|
+
ref: forwardedRef
|
|
1632
|
+
});
|
|
1633
|
+
});
|
|
1634
|
+
MainDrawerRoot.displayName = DRAWER_NAME;
|
|
1542
1635
|
var MainContent = /* @__PURE__ */ forwardRef16(({ asChild, classNames, bounce, handlesFocus, children, role, ...props }, forwardedRef) => {
|
|
1543
|
-
const { navigationSidebarState, complementarySidebarState } = useMainContext(MAIN_NAME);
|
|
1636
|
+
const { navigationSidebarState, complementarySidebarState, drawerState } = useMainContext(MAIN_NAME);
|
|
1544
1637
|
const { tx } = useThemeContext();
|
|
1545
1638
|
const Root6 = asChild ? Slot8 : role ? "div" : "main";
|
|
1546
1639
|
const mover = useLandmarkMover(props.onKeyDown, "1");
|
|
@@ -1552,6 +1645,7 @@ var MainContent = /* @__PURE__ */ forwardRef16(({ asChild, classNames, bounce, h
|
|
|
1552
1645
|
...props,
|
|
1553
1646
|
"data-sidebar-inline-start-state": navigationSidebarState,
|
|
1554
1647
|
"data-sidebar-inline-end-state": complementarySidebarState,
|
|
1648
|
+
"data-drawer-state": drawerState,
|
|
1555
1649
|
"data-handles-focus": handlesFocus,
|
|
1556
1650
|
className: tx("main.content", "main", {
|
|
1557
1651
|
bounce,
|
|
@@ -1566,11 +1660,11 @@ var MainOverlay = /* @__PURE__ */ forwardRef16(({ classNames, ...props }, forwar
|
|
|
1566
1660
|
const { navigationSidebarState, setNavigationSidebarState, complementarySidebarState, setComplementarySidebarState } = useMainContext(MAIN_NAME);
|
|
1567
1661
|
const { tx } = useThemeContext();
|
|
1568
1662
|
return /* @__PURE__ */ React20.createElement("div", {
|
|
1663
|
+
...props,
|
|
1569
1664
|
onClick: () => {
|
|
1570
1665
|
setNavigationSidebarState("collapsed");
|
|
1571
1666
|
setComplementarySidebarState("collapsed");
|
|
1572
1667
|
},
|
|
1573
|
-
...props,
|
|
1574
1668
|
className: tx("main.overlay", "main__overlay", {
|
|
1575
1669
|
isLg,
|
|
1576
1670
|
inlineStartSidebarOpen: navigationSidebarState,
|
|
@@ -1586,7 +1680,8 @@ var Main = {
|
|
|
1586
1680
|
Content: MainContent,
|
|
1587
1681
|
Overlay: MainOverlay,
|
|
1588
1682
|
NavigationSidebar: MainNavigationSidebar,
|
|
1589
|
-
ComplementarySidebar: MainComplementarySidebar
|
|
1683
|
+
ComplementarySidebar: MainComplementarySidebar,
|
|
1684
|
+
Drawer: MainDrawerRoot
|
|
1590
1685
|
};
|
|
1591
1686
|
|
|
1592
1687
|
// src/components/Menu/ContextMenu.tsx
|
|
@@ -2583,7 +2678,7 @@ var ScrollArea = {
|
|
|
2583
2678
|
// src/components/ScrollContainer/ScrollContainer.tsx
|
|
2584
2679
|
import { createContext as createContext8 } from "@radix-ui/react-context";
|
|
2585
2680
|
import React27, { forwardRef as forwardRef23, useCallback as useCallback10, useEffect as useEffect6, useImperativeHandle, useMemo as useMemo5, useRef as useRef4, useState as useState7 } from "react";
|
|
2586
|
-
import { addEventListener, combine } from "@dxos/async";
|
|
2681
|
+
import { addEventListener as addEventListener2, combine } from "@dxos/async";
|
|
2587
2682
|
import { invariant } from "@dxos/invariant";
|
|
2588
2683
|
import { useForwardedRef as useForwardedRef2 } from "@dxos/react-hooks";
|
|
2589
2684
|
import { mx as mx5 } from "@dxos/ui-theme";
|
|
@@ -2650,11 +2745,11 @@ var Root3 = /* @__PURE__ */ forwardRef23(({ children, classNames, pin, fade, beh
|
|
|
2650
2745
|
}
|
|
2651
2746
|
return combine(
|
|
2652
2747
|
// Check if user scrolls.
|
|
2653
|
-
|
|
2748
|
+
addEventListener2(scrollerRef.current, "wheel", () => {
|
|
2654
2749
|
setPinned(isBottom(scrollerRef.current));
|
|
2655
2750
|
}),
|
|
2656
2751
|
// Check if scrolls.
|
|
2657
|
-
|
|
2752
|
+
addEventListener2(scrollerRef.current, "scroll", () => {
|
|
2658
2753
|
setOverflow((scrollerRef.current?.scrollTop ?? 0) > 0);
|
|
2659
2754
|
})
|
|
2660
2755
|
);
|
|
@@ -3142,6 +3237,7 @@ export {
|
|
|
3142
3237
|
useDensityContext,
|
|
3143
3238
|
useDropdownMenuContext,
|
|
3144
3239
|
useDropdownMenuMenuScope,
|
|
3240
|
+
useDynamicDrawer,
|
|
3145
3241
|
useElevationContext,
|
|
3146
3242
|
useIconHref,
|
|
3147
3243
|
useLandmarkMover,
|