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