@superdispatch/ui-lab 0.50.6 → 0.50.8
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-node/index.js +31 -23
- package/dist-node/index.js.map +1 -1
- package/dist-src/navbar/Navbar.js +18 -3
- package/dist-src/navbar/NavbarAccordion.js +9 -19
- package/dist-src/navbar/NavbarContext.js +3 -1
- package/dist-src/navbar/NavbarList.js +2 -1
- package/dist-types/index.d.ts +8 -6
- package/dist-web/index.js +31 -23
- package/dist-web/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -24,8 +24,10 @@ export function Navbar(_ref) {
|
|
|
24
24
|
children,
|
|
25
25
|
containerStyle,
|
|
26
26
|
hasExtraBadge,
|
|
27
|
+
groupExpanded: controlledGroupExpanded,
|
|
27
28
|
isMenuExpanded: controlledIsMenuExpanded,
|
|
28
|
-
onMenuExpandedChange
|
|
29
|
+
onMenuExpandedChange,
|
|
30
|
+
onGroupExpandedChange
|
|
29
31
|
} = _ref;
|
|
30
32
|
var theme = useTheme();
|
|
31
33
|
var [isDrawerOpen, setDrawerOpen] = useState(false);
|
|
@@ -35,6 +37,8 @@ export function Navbar(_ref) {
|
|
|
35
37
|
noSsr: true
|
|
36
38
|
});
|
|
37
39
|
var [internalIsMenuExpanded, setInternalMenuExpanded] = useState(matches);
|
|
40
|
+
var [groupExpandedState, setGroupExpandedState] = useState(controlledGroupExpanded || {});
|
|
41
|
+
var groupExpanded = controlledGroupExpanded ? controlledGroupExpanded : groupExpandedState;
|
|
38
42
|
var isMenuExpanded = controlledIsMenuExpanded !== undefined ? controlledIsMenuExpanded : internalIsMenuExpanded;
|
|
39
43
|
var setMenuExpanded = useCallback(value => {
|
|
40
44
|
if (controlledIsMenuExpanded === undefined) {
|
|
@@ -42,14 +46,25 @@ export function Navbar(_ref) {
|
|
|
42
46
|
}
|
|
43
47
|
onMenuExpandedChange === null || onMenuExpandedChange === void 0 || onMenuExpandedChange(value);
|
|
44
48
|
}, [controlledIsMenuExpanded, onMenuExpandedChange]);
|
|
49
|
+
var setGroupExpanded = useCallback((groupKey, isExpanded) => {
|
|
50
|
+
var updatedGroupExpanded = _objectSpread(_objectSpread({}, groupExpanded), {}, {
|
|
51
|
+
[groupKey]: isExpanded
|
|
52
|
+
});
|
|
53
|
+
if (!controlledGroupExpanded) {
|
|
54
|
+
setGroupExpandedState(updatedGroupExpanded);
|
|
55
|
+
}
|
|
56
|
+
onGroupExpandedChange === null || onGroupExpandedChange === void 0 || onGroupExpandedChange(updatedGroupExpanded);
|
|
57
|
+
}, [controlledGroupExpanded, groupExpanded, onGroupExpandedChange]);
|
|
45
58
|
var hasBadge = hasExtraBadge || items.some(item => item.badge);
|
|
46
59
|
var ctx = useMemo(() => ({
|
|
47
60
|
isDrawerOpen,
|
|
48
61
|
isMenuExpanded,
|
|
49
62
|
setDrawerOpen,
|
|
50
63
|
setMenuExpanded,
|
|
51
|
-
isNavbarExpanded: isMenuExpanded || isDrawerOpen
|
|
52
|
-
|
|
64
|
+
isNavbarExpanded: isMenuExpanded || isDrawerOpen,
|
|
65
|
+
setGroupExpanded,
|
|
66
|
+
groupExpanded
|
|
67
|
+
}), [isDrawerOpen, isMenuExpanded, setMenuExpanded, setGroupExpanded, groupExpanded]);
|
|
53
68
|
return /*#__PURE__*/_jsx(NavbarContext.Provider, {
|
|
54
69
|
value: ctx,
|
|
55
70
|
children: /*#__PURE__*/_jsxs("div", {
|
|
@@ -2,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
|
2
2
|
import { Accordion, AccordionSummary } from '@material-ui/core';
|
|
3
3
|
import { ExpandMore } from '@material-ui/icons';
|
|
4
4
|
import { Color, ColorDark, ColorDynamic, useUID } from '@superdispatch/ui';
|
|
5
|
-
import {
|
|
5
|
+
import { useMemo, createElement as _createElement } from 'react';
|
|
6
6
|
import styled from 'styled-components';
|
|
7
7
|
import { useNavbarContext } from "./NavbarContext.js";
|
|
8
8
|
import { NavbarItem } from "./NavbarItem.js";
|
|
@@ -29,33 +29,23 @@ var IconWrapper = /*#__PURE__*/styled.div.withConfig({
|
|
|
29
29
|
componentId: "SD__sc-1s7g3kw-3"
|
|
30
30
|
})(["width:24px;margin-right:8px;& svg{font-size:24px;}"]);
|
|
31
31
|
export function NavbarAccordion(_ref2) {
|
|
32
|
+
var _groupExpanded$groupK;
|
|
32
33
|
var {
|
|
33
34
|
label,
|
|
34
35
|
icon,
|
|
35
36
|
gutter,
|
|
36
37
|
items,
|
|
37
38
|
onClick: _onClick,
|
|
38
|
-
|
|
39
|
-
onExpandedChange
|
|
39
|
+
groupKey
|
|
40
40
|
} = _ref2;
|
|
41
41
|
var uid = useUID();
|
|
42
42
|
var {
|
|
43
43
|
setDrawerOpen,
|
|
44
|
-
isNavbarExpanded
|
|
44
|
+
isNavbarExpanded,
|
|
45
|
+
groupExpanded,
|
|
46
|
+
setGroupExpanded
|
|
45
47
|
} = useNavbarContext();
|
|
46
|
-
var
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (controlledIsExpanded === undefined) {
|
|
49
|
-
setInternalExpanded(isNavbarExpanded);
|
|
50
|
-
}
|
|
51
|
-
}, [isNavbarExpanded, controlledIsExpanded]);
|
|
52
|
-
var isExpanded = controlledIsExpanded !== undefined ? controlledIsExpanded : internalIsExpanded;
|
|
53
|
-
function setExpanded(value) {
|
|
54
|
-
if (controlledIsExpanded === undefined) {
|
|
55
|
-
setInternalExpanded(value);
|
|
56
|
-
}
|
|
57
|
-
onExpandedChange === null || onExpandedChange === void 0 || onExpandedChange(value);
|
|
58
|
-
}
|
|
48
|
+
var isExpanded = isNavbarExpanded ? (_groupExpanded$groupK = groupExpanded[groupKey]) !== null && _groupExpanded$groupK !== void 0 ? _groupExpanded$groupK : true : false;
|
|
59
49
|
var filteredItems = useMemo(() => items.filter(item => !item.hide), [items]);
|
|
60
50
|
return /*#__PURE__*/_jsxs(NavbarAccordionRoot, {
|
|
61
51
|
square: true,
|
|
@@ -64,8 +54,8 @@ export function NavbarAccordion(_ref2) {
|
|
|
64
54
|
expanded: isExpanded,
|
|
65
55
|
onClick: event => {
|
|
66
56
|
_onClick === null || _onClick === void 0 || _onClick(event);
|
|
67
|
-
if (
|
|
68
|
-
|
|
57
|
+
if (isNavbarExpanded) {
|
|
58
|
+
setGroupExpanded(groupKey, !isExpanded);
|
|
69
59
|
}
|
|
70
60
|
},
|
|
71
61
|
children: [/*#__PURE__*/_jsxs(NavbarAccordionSummary, {
|
|
@@ -3,8 +3,10 @@ export var NavbarContext = /*#__PURE__*/createContext({
|
|
|
3
3
|
isDrawerOpen: false,
|
|
4
4
|
isMenuExpanded: false,
|
|
5
5
|
isNavbarExpanded: false,
|
|
6
|
+
groupExpanded: {},
|
|
6
7
|
setMenuExpanded: () => void 0,
|
|
7
|
-
setDrawerOpen: () => void 0
|
|
8
|
+
setDrawerOpen: () => void 0,
|
|
9
|
+
setGroupExpanded: () => void 0
|
|
8
10
|
});
|
|
9
11
|
export function useNavbarContext() {
|
|
10
12
|
return useContext(NavbarContext);
|
|
@@ -114,7 +114,8 @@ export function NavbarList(_ref6) {
|
|
|
114
114
|
return /*#__PURE__*/_createElement(NavbarAccordion, _objectSpread(_objectSpread({}, item), {}, {
|
|
115
115
|
key: item.key,
|
|
116
116
|
gutter: prev && prev.groupKey !== item.groupKey,
|
|
117
|
-
onClick: item.onClick
|
|
117
|
+
onClick: item.onClick,
|
|
118
|
+
groupKey: item.groupKey || item.key
|
|
118
119
|
}));
|
|
119
120
|
}
|
|
120
121
|
return /*#__PURE__*/_createElement(NavbarItem, _objectSpread(_objectSpread({}, item), {}, {
|
package/dist-types/index.d.ts
CHANGED
|
@@ -259,10 +259,9 @@ interface NavbarAccordionProps {
|
|
|
259
259
|
gutter?: boolean;
|
|
260
260
|
items: Array<Omit<NavbarItemOptions, 'icon'>>;
|
|
261
261
|
onClick?: (event: MouseEvent<HTMLDivElement>) => void;
|
|
262
|
-
|
|
263
|
-
onExpandedChange?: (isExpanded: boolean) => void;
|
|
262
|
+
groupKey: Key;
|
|
264
263
|
}
|
|
265
|
-
declare function NavbarAccordion({ label, icon, gutter, items, onClick,
|
|
264
|
+
declare function NavbarAccordion({ label, icon, gutter, items, onClick, groupKey, }: NavbarAccordionProps): ReactElement;
|
|
266
265
|
|
|
267
266
|
declare const NavbarBadge: StyledComponent<"span", DefaultTheme, {}, never>;
|
|
268
267
|
declare const NavbarLabel: StyledComponent<"span", DefaultTheme, {}, never>;
|
|
@@ -286,7 +285,7 @@ interface NavbarMenuItemProps {
|
|
|
286
285
|
component?: ComponentType<HTMLAttributes<HTMLElement>>;
|
|
287
286
|
}
|
|
288
287
|
declare function NavbarMenuItem({ label, icon, onClick, component, }: NavbarMenuItemProps): ReactElement;
|
|
289
|
-
interface NavbarAccordionOptions extends NavbarAccordionProps {
|
|
288
|
+
interface NavbarAccordionOptions extends Omit<NavbarAccordionProps, 'groupKey'> {
|
|
290
289
|
key: Key;
|
|
291
290
|
groupKey?: Key;
|
|
292
291
|
hide?: boolean;
|
|
@@ -312,9 +311,11 @@ interface NavbarProps {
|
|
|
312
311
|
footer?: ReactNode;
|
|
313
312
|
hasExtraBadge?: boolean;
|
|
314
313
|
isMenuExpanded?: boolean;
|
|
314
|
+
groupExpanded?: Record<Key, boolean>;
|
|
315
315
|
onMenuExpandedChange?: (isExpanded: boolean) => void;
|
|
316
|
+
onGroupExpandedChange?: (groupExpanded: Record<Key, boolean>) => void;
|
|
316
317
|
}
|
|
317
|
-
declare function Navbar({ footer, items, header, bottomItems, children, containerStyle, hasExtraBadge, isMenuExpanded: controlledIsMenuExpanded, onMenuExpandedChange, }: NavbarProps): ReactElement;
|
|
318
|
+
declare function Navbar({ footer, items, header, bottomItems, children, containerStyle, hasExtraBadge, groupExpanded: controlledGroupExpanded, isMenuExpanded: controlledIsMenuExpanded, onMenuExpandedChange, onGroupExpandedChange, }: NavbarProps): ReactElement;
|
|
318
319
|
|
|
319
320
|
interface NavbarAvatarProps extends Omit<AvatarProps, 'title'> {
|
|
320
321
|
title: ReactNode;
|
|
@@ -323,13 +324,14 @@ interface NavbarAvatarProps extends Omit<AvatarProps, 'title'> {
|
|
|
323
324
|
}
|
|
324
325
|
declare function NavbarAvatar({ title, subtitle, children, ...props }: NavbarAvatarProps): ReactElement;
|
|
325
326
|
|
|
326
|
-
|
|
327
327
|
interface NavbarContextType {
|
|
328
328
|
isDrawerOpen: boolean;
|
|
329
329
|
isMenuExpanded: boolean;
|
|
330
330
|
isNavbarExpanded: boolean;
|
|
331
|
+
groupExpanded: Record<Key, boolean>;
|
|
331
332
|
setDrawerOpen: (value: boolean) => void;
|
|
332
333
|
setMenuExpanded: (value: boolean) => void;
|
|
334
|
+
setGroupExpanded: (expandedKey: Key, isExpanded: boolean) => void;
|
|
333
335
|
}
|
|
334
336
|
declare function useNavbarContext(): NavbarContextType;
|
|
335
337
|
|
package/dist-web/index.js
CHANGED
|
@@ -1334,8 +1334,10 @@ var NavbarContext = /*#__PURE__*/createContext({
|
|
|
1334
1334
|
isDrawerOpen: false,
|
|
1335
1335
|
isMenuExpanded: false,
|
|
1336
1336
|
isNavbarExpanded: false,
|
|
1337
|
+
groupExpanded: {},
|
|
1337
1338
|
setMenuExpanded: () => void 0,
|
|
1338
|
-
setDrawerOpen: () => void 0
|
|
1339
|
+
setDrawerOpen: () => void 0,
|
|
1340
|
+
setGroupExpanded: () => void 0
|
|
1339
1341
|
});
|
|
1340
1342
|
function useNavbarContext() {
|
|
1341
1343
|
return useContext(NavbarContext);
|
|
@@ -1478,33 +1480,23 @@ var IconWrapper$2 = /*#__PURE__*/styled.div.withConfig({
|
|
|
1478
1480
|
componentId: "SD__sc-1s7g3kw-3"
|
|
1479
1481
|
})(["width:24px;margin-right:8px;& svg{font-size:24px;}"]);
|
|
1480
1482
|
function NavbarAccordion(_ref2) {
|
|
1483
|
+
var _groupExpanded$groupK;
|
|
1481
1484
|
var {
|
|
1482
1485
|
label,
|
|
1483
1486
|
icon,
|
|
1484
1487
|
gutter,
|
|
1485
1488
|
items,
|
|
1486
1489
|
onClick: _onClick,
|
|
1487
|
-
|
|
1488
|
-
onExpandedChange
|
|
1490
|
+
groupKey
|
|
1489
1491
|
} = _ref2;
|
|
1490
1492
|
var uid = useUID();
|
|
1491
1493
|
var {
|
|
1492
1494
|
setDrawerOpen,
|
|
1493
|
-
isNavbarExpanded
|
|
1495
|
+
isNavbarExpanded,
|
|
1496
|
+
groupExpanded,
|
|
1497
|
+
setGroupExpanded
|
|
1494
1498
|
} = useNavbarContext();
|
|
1495
|
-
var
|
|
1496
|
-
useEffect(() => {
|
|
1497
|
-
if (controlledIsExpanded === undefined) {
|
|
1498
|
-
setInternalExpanded(isNavbarExpanded);
|
|
1499
|
-
}
|
|
1500
|
-
}, [isNavbarExpanded, controlledIsExpanded]);
|
|
1501
|
-
var isExpanded = controlledIsExpanded !== undefined ? controlledIsExpanded : internalIsExpanded;
|
|
1502
|
-
function setExpanded(value) {
|
|
1503
|
-
if (controlledIsExpanded === undefined) {
|
|
1504
|
-
setInternalExpanded(value);
|
|
1505
|
-
}
|
|
1506
|
-
onExpandedChange === null || onExpandedChange === void 0 || onExpandedChange(value);
|
|
1507
|
-
}
|
|
1499
|
+
var isExpanded = isNavbarExpanded ? (_groupExpanded$groupK = groupExpanded[groupKey]) !== null && _groupExpanded$groupK !== void 0 ? _groupExpanded$groupK : true : false;
|
|
1508
1500
|
var filteredItems = useMemo(() => items.filter(item => !item.hide), [items]);
|
|
1509
1501
|
return /*#__PURE__*/jsxs(NavbarAccordionRoot, {
|
|
1510
1502
|
square: true,
|
|
@@ -1513,8 +1505,8 @@ function NavbarAccordion(_ref2) {
|
|
|
1513
1505
|
expanded: isExpanded,
|
|
1514
1506
|
onClick: event => {
|
|
1515
1507
|
_onClick === null || _onClick === void 0 || _onClick(event);
|
|
1516
|
-
if (
|
|
1517
|
-
|
|
1508
|
+
if (isNavbarExpanded) {
|
|
1509
|
+
setGroupExpanded(groupKey, !isExpanded);
|
|
1518
1510
|
}
|
|
1519
1511
|
},
|
|
1520
1512
|
children: [/*#__PURE__*/jsxs(NavbarAccordionSummary, {
|
|
@@ -1658,7 +1650,8 @@ function NavbarList(_ref6) {
|
|
|
1658
1650
|
return /*#__PURE__*/createElement(NavbarAccordion, _objectSpread(_objectSpread({}, item), {}, {
|
|
1659
1651
|
key: item.key,
|
|
1660
1652
|
gutter: prev && prev.groupKey !== item.groupKey,
|
|
1661
|
-
onClick: item.onClick
|
|
1653
|
+
onClick: item.onClick,
|
|
1654
|
+
groupKey: item.groupKey || item.key
|
|
1662
1655
|
}));
|
|
1663
1656
|
}
|
|
1664
1657
|
return /*#__PURE__*/createElement(NavbarItem, _objectSpread(_objectSpread({}, item), {}, {
|
|
@@ -1696,8 +1689,10 @@ function Navbar(_ref) {
|
|
|
1696
1689
|
children,
|
|
1697
1690
|
containerStyle,
|
|
1698
1691
|
hasExtraBadge,
|
|
1692
|
+
groupExpanded: controlledGroupExpanded,
|
|
1699
1693
|
isMenuExpanded: controlledIsMenuExpanded,
|
|
1700
|
-
onMenuExpandedChange
|
|
1694
|
+
onMenuExpandedChange,
|
|
1695
|
+
onGroupExpandedChange
|
|
1701
1696
|
} = _ref;
|
|
1702
1697
|
var theme = useTheme();
|
|
1703
1698
|
var [isDrawerOpen, setDrawerOpen] = useState(false);
|
|
@@ -1707,6 +1702,8 @@ function Navbar(_ref) {
|
|
|
1707
1702
|
noSsr: true
|
|
1708
1703
|
});
|
|
1709
1704
|
var [internalIsMenuExpanded, setInternalMenuExpanded] = useState(matches);
|
|
1705
|
+
var [groupExpandedState, setGroupExpandedState] = useState(controlledGroupExpanded || {});
|
|
1706
|
+
var groupExpanded = controlledGroupExpanded ? controlledGroupExpanded : groupExpandedState;
|
|
1710
1707
|
var isMenuExpanded = controlledIsMenuExpanded !== undefined ? controlledIsMenuExpanded : internalIsMenuExpanded;
|
|
1711
1708
|
var setMenuExpanded = useCallback(value => {
|
|
1712
1709
|
if (controlledIsMenuExpanded === undefined) {
|
|
@@ -1714,14 +1711,25 @@ function Navbar(_ref) {
|
|
|
1714
1711
|
}
|
|
1715
1712
|
onMenuExpandedChange === null || onMenuExpandedChange === void 0 || onMenuExpandedChange(value);
|
|
1716
1713
|
}, [controlledIsMenuExpanded, onMenuExpandedChange]);
|
|
1714
|
+
var setGroupExpanded = useCallback((groupKey, isExpanded) => {
|
|
1715
|
+
var updatedGroupExpanded = _objectSpread(_objectSpread({}, groupExpanded), {}, {
|
|
1716
|
+
[groupKey]: isExpanded
|
|
1717
|
+
});
|
|
1718
|
+
if (!controlledGroupExpanded) {
|
|
1719
|
+
setGroupExpandedState(updatedGroupExpanded);
|
|
1720
|
+
}
|
|
1721
|
+
onGroupExpandedChange === null || onGroupExpandedChange === void 0 || onGroupExpandedChange(updatedGroupExpanded);
|
|
1722
|
+
}, [controlledGroupExpanded, groupExpanded, onGroupExpandedChange]);
|
|
1717
1723
|
var hasBadge = hasExtraBadge || items.some(item => item.badge);
|
|
1718
1724
|
var ctx = useMemo(() => ({
|
|
1719
1725
|
isDrawerOpen,
|
|
1720
1726
|
isMenuExpanded,
|
|
1721
1727
|
setDrawerOpen,
|
|
1722
1728
|
setMenuExpanded,
|
|
1723
|
-
isNavbarExpanded: isMenuExpanded || isDrawerOpen
|
|
1724
|
-
|
|
1729
|
+
isNavbarExpanded: isMenuExpanded || isDrawerOpen,
|
|
1730
|
+
setGroupExpanded,
|
|
1731
|
+
groupExpanded
|
|
1732
|
+
}), [isDrawerOpen, isMenuExpanded, setMenuExpanded, setGroupExpanded, groupExpanded]);
|
|
1725
1733
|
return /*#__PURE__*/jsx(NavbarContext.Provider, {
|
|
1726
1734
|
value: ctx,
|
|
1727
1735
|
children: /*#__PURE__*/jsxs("div", {
|