@superdispatch/ui-lab 0.18.3 → 0.20.1
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 +323 -18
- package/dist-node/index.js.map +1 -1
- package/dist-src/index.js +4 -0
- package/dist-src/multiline-text/MultilineText.js +11 -0
- package/dist-src/navbar/NavbarAccordion.js +97 -0
- package/dist-src/navbar/NavbarItem.js +4 -2
- package/dist-src/navbar/NavbarList.js +11 -1
- package/dist-src/sidebar/Sidebar.js +1 -1
- package/dist-src/sidebar/SidebarBackButton.js +38 -0
- package/dist-src/sidebar/SidebarContainer.js +44 -10
- package/dist-src/sidebar/SidebarContent.js +88 -0
- package/dist-src/sidebar/SidebarMenuItem.js +14 -3
- package/dist-src/sidebar/SidebarMenuItemAvatar.js +1 -0
- package/dist-types/index.d.ts +53 -5
- package/dist-web/index.js +325 -25
- package/dist-web/index.js.map +1 -1
- package/package.json +3 -3
package/dist-src/index.js
CHANGED
|
@@ -7,6 +7,8 @@ export * from "./container/Container.js";
|
|
|
7
7
|
export * from "./description-item/DescriptionItem.js";
|
|
8
8
|
export * from "./file-drop-zone/FileDropZone.js";
|
|
9
9
|
export * from "./file-list-item/FileListItem.js";
|
|
10
|
+
export * from "./linked-text/LinkedText.js";
|
|
11
|
+
export * from "./multiline-text/MultilineText.js";
|
|
10
12
|
export * from "./navbar/Navbar.js";
|
|
11
13
|
export * from "./navbar/NavbarAvatar.js";
|
|
12
14
|
export * from "./navbar/NavbarBottomBar.js";
|
|
@@ -15,7 +17,9 @@ export * from "./navbar/NavbarItem.js";
|
|
|
15
17
|
export * from "./navbar/NavbarList.js";
|
|
16
18
|
export * from "./navbar/NavbarMenu.js";
|
|
17
19
|
export * from "./sidebar/Sidebar.js";
|
|
20
|
+
export * from "./sidebar/SidebarBackButton.js";
|
|
18
21
|
export * from "./sidebar/SidebarContainer.js";
|
|
22
|
+
export * from "./sidebar/SidebarContent.js";
|
|
19
23
|
export * from "./sidebar/SidebarDivider.js";
|
|
20
24
|
export * from "./sidebar/SidebarMenuItem.js";
|
|
21
25
|
export * from "./sidebar/SidebarMenuItemAction.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
export var MultilineText = /*#__PURE__*/styled.span.withConfig({
|
|
3
|
+
displayName: "MultilineText",
|
|
4
|
+
componentId: "SD__sc-34heyp-0"
|
|
5
|
+
})(["white-space:pre-wrap;overflow-wrap:", ";"], _ref => {
|
|
6
|
+
var {
|
|
7
|
+
overflowWrap = 'normal'
|
|
8
|
+
} = _ref;
|
|
9
|
+
return overflowWrap;
|
|
10
|
+
});
|
|
11
|
+
MultilineText.displayName = 'MultilineText';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
+
import { Accordion, AccordionSummary } from '@material-ui/core';
|
|
3
|
+
import { ExpandMore } from '@material-ui/icons';
|
|
4
|
+
import { Color, useUID } from '@superdispatch/ui';
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import styled, { css } from 'styled-components';
|
|
7
|
+
import { useNavbarContext } from "./NavbarContext.js";
|
|
8
|
+
import { NavbarItem } from "./NavbarItem.js";
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { createElement as _createElement } from "react";
|
|
12
|
+
export var NavbarAccordionLabel = /*#__PURE__*/styled.span.withConfig({
|
|
13
|
+
displayName: "NavbarAccordion__NavbarAccordionLabel",
|
|
14
|
+
componentId: "SD__sc-1s7g3kw-0"
|
|
15
|
+
})(["flex-grow:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;&[data-expanded='false']{display:none;}"]);
|
|
16
|
+
var NavbarAccordionRoot = /*#__PURE__*/styled(Accordion).withConfig({
|
|
17
|
+
displayName: "NavbarAccordion__NavbarAccordionRoot",
|
|
18
|
+
componentId: "SD__sc-1s7g3kw-1"
|
|
19
|
+
})(_ref => {
|
|
20
|
+
var {
|
|
21
|
+
gutter
|
|
22
|
+
} = _ref;
|
|
23
|
+
return css(["width:100%;color:#c2c4c9;font-size:14px;font-weight:400;line-height:20px;text-decoration:none;outline:none;cursor:pointer;background-color:#1b2638;margin-top:", ";&:hover,&[aria-current]{background-color:#2f394a;color:", ";}&.MuiAccordion-root:before{background-color:#1b2638;}&.MuiPaper-elevation0{border:0px;}&&.MuiAccordionSummary-root.Mui-expanded{margin-top:", ";max-height:40px;min-height:40px;}"], gutter ? '16px' : '0', Color.White, gutter ? '16px' : '0');
|
|
24
|
+
});
|
|
25
|
+
var NavbarAccordionSummary = /*#__PURE__*/styled(AccordionSummary).withConfig({
|
|
26
|
+
displayName: "NavbarAccordion__NavbarAccordionSummary",
|
|
27
|
+
componentId: "SD__sc-1s7g3kw-2"
|
|
28
|
+
})(["border-left:4px solid transparent;padding-left:20px;&.MuiAccordionSummary-root{max-height:40px;min-height:40px;}&:hover,&[data-active='true']{border-left-color:", ";}&[data-expanded='false']{.MuiAccordionSummary-expandIcon{display:none;}}"], Color.Blue300);
|
|
29
|
+
var IconWrapper = /*#__PURE__*/styled.div.withConfig({
|
|
30
|
+
displayName: "NavbarAccordion__IconWrapper",
|
|
31
|
+
componentId: "SD__sc-1s7g3kw-3"
|
|
32
|
+
})(["width:24px;margin-right:8px;& svg{font-size:24px;}"]);
|
|
33
|
+
export function NavbarAccordion(_ref2) {
|
|
34
|
+
var {
|
|
35
|
+
label,
|
|
36
|
+
icon,
|
|
37
|
+
gutter,
|
|
38
|
+
items,
|
|
39
|
+
onClick: _onClick
|
|
40
|
+
} = _ref2;
|
|
41
|
+
var uid = useUID();
|
|
42
|
+
var {
|
|
43
|
+
isExpanded: isMenuExpanded,
|
|
44
|
+
isDrawerOpen,
|
|
45
|
+
setDrawerOpen
|
|
46
|
+
} = useNavbarContext();
|
|
47
|
+
var [isExpanded, setExpanded] = useState(false);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!isMenuExpanded) {
|
|
50
|
+
setExpanded(false);
|
|
51
|
+
}
|
|
52
|
+
}, [isMenuExpanded]);
|
|
53
|
+
return /*#__PURE__*/_jsxs(NavbarAccordionRoot, {
|
|
54
|
+
"aria-labelledby": uid,
|
|
55
|
+
gutter: !!gutter,
|
|
56
|
+
expanded: isExpanded,
|
|
57
|
+
onClick: event => {
|
|
58
|
+
if (isMenuExpanded || isDrawerOpen) {
|
|
59
|
+
setExpanded(!isExpanded);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
_onClick(event);
|
|
63
|
+
},
|
|
64
|
+
square: true,
|
|
65
|
+
children: [/*#__PURE__*/_jsxs(NavbarAccordionSummary, {
|
|
66
|
+
"data-active": !isExpanded && items.some(item => item.active),
|
|
67
|
+
"data-expanded": isMenuExpanded || isDrawerOpen,
|
|
68
|
+
expandIcon: /*#__PURE__*/_jsx(ExpandMore, {}),
|
|
69
|
+
children: [/*#__PURE__*/_jsx(IconWrapper, {
|
|
70
|
+
children: icon
|
|
71
|
+
}), /*#__PURE__*/_jsx(NavbarAccordionLabel, {
|
|
72
|
+
id: uid,
|
|
73
|
+
"data-expanded": isMenuExpanded || isDrawerOpen,
|
|
74
|
+
children: label
|
|
75
|
+
})]
|
|
76
|
+
}), items.map(item => {
|
|
77
|
+
var index = items.indexOf(item);
|
|
78
|
+
var prev = items[index - 1];
|
|
79
|
+
return /*#__PURE__*/_createElement(NavbarItem, _objectSpread(_objectSpread({}, item), {}, {
|
|
80
|
+
key: item.key,
|
|
81
|
+
ident: 1,
|
|
82
|
+
active: item.active,
|
|
83
|
+
gutter: prev && prev.groupKey !== item.groupKey,
|
|
84
|
+
onClick: event => {
|
|
85
|
+
var _item$onClick;
|
|
86
|
+
|
|
87
|
+
event.stopPropagation();
|
|
88
|
+
(_item$onClick = item.onClick) === null || _item$onClick === void 0 ? void 0 : _item$onClick.call(item, event);
|
|
89
|
+
|
|
90
|
+
if (!event.isDefaultPrevented()) {
|
|
91
|
+
setDrawerOpen(false);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}));
|
|
95
|
+
})]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -13,7 +13,7 @@ export var NavbarLabel = /*#__PURE__*/styled.span.withConfig({
|
|
|
13
13
|
var NavbarItemRoot = /*#__PURE__*/styled.div.withConfig({
|
|
14
14
|
displayName: "NavbarItem__NavbarItemRoot",
|
|
15
15
|
componentId: "SD__sc-1pvzq3w-2"
|
|
16
|
-
})(["width:100%;display:flex;align-items:center;color:#c2c4c9;font-size:14px;font-weight:400;line-height:20px;text-decoration:none;outline:none;cursor:pointer;padding:8px 16px;border-left:4px solid transparent;&:hover,&[aria-current]{background-color:#2f394a;color:", ";border-left-color:", ";}"], Color.White, Color.Blue300);
|
|
16
|
+
})(["width:100%;display:flex;align-items:center;color:#c2c4c9;font-size:14px;font-weight:400;line-height:20px;text-decoration:none;outline:none;cursor:pointer;padding:8px 16px;border-left:4px solid transparent;&:hover,&[aria-current]{background-color:#2f394a;color:", ";border-left-color:", ";}&[data-active='true']{border-left-color:", ";}"], Color.White, Color.Blue300, Color.Blue300);
|
|
17
17
|
var IconWrapper = /*#__PURE__*/styled.div.withConfig({
|
|
18
18
|
displayName: "NavbarItem__IconWrapper",
|
|
19
19
|
componentId: "SD__sc-1pvzq3w-3"
|
|
@@ -27,13 +27,15 @@ export function NavbarItem(_ref) {
|
|
|
27
27
|
component,
|
|
28
28
|
onClick,
|
|
29
29
|
variant,
|
|
30
|
-
ident = 0
|
|
30
|
+
ident = 0,
|
|
31
|
+
active
|
|
31
32
|
} = _ref;
|
|
32
33
|
var uid = useUID();
|
|
33
34
|
return /*#__PURE__*/_jsxs(NavbarItemRoot, {
|
|
34
35
|
as: component,
|
|
35
36
|
onClick: onClick,
|
|
36
37
|
"aria-labelledby": uid,
|
|
38
|
+
"data-active": active,
|
|
37
39
|
style: {
|
|
38
40
|
marginTop: gutter ? '16px' : '0',
|
|
39
41
|
paddingLeft: (ident + 1) * 20
|
|
@@ -4,6 +4,7 @@ import { Menu as MenuIcon, MenuOpen } from '@material-ui/icons';
|
|
|
4
4
|
import { Color, Inline, useResponsiveValue } from '@superdispatch/ui';
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
import styled from 'styled-components';
|
|
7
|
+
import { NavbarAccordion } from "./NavbarAccordion.js";
|
|
7
8
|
import { useNavbarContext } from "./NavbarContext.js";
|
|
8
9
|
import { NavbarBadge, NavbarItem, NavbarLabel } from "./NavbarItem.js";
|
|
9
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -66,7 +67,7 @@ export function NavbarMenuItem(_ref4) {
|
|
|
66
67
|
var Content = /*#__PURE__*/styled.div.withConfig({
|
|
67
68
|
displayName: "NavbarList__Content",
|
|
68
69
|
componentId: "SD__sc-19zrmxc-5"
|
|
69
|
-
})(["height:100%;min-height:50px;overflow:
|
|
70
|
+
})(["height:100%;min-height:50px;overflow-y:auto;overflow-x:hidden;&[aria-expanded='false']{", ",", "{display:none;}}"], NavbarBadge, NavbarLabel);
|
|
70
71
|
export function NavbarList(_ref5) {
|
|
71
72
|
var {
|
|
72
73
|
header,
|
|
@@ -106,6 +107,15 @@ export function NavbarList(_ref5) {
|
|
|
106
107
|
children: filteredItems.map(item => {
|
|
107
108
|
var index = filteredItems.indexOf(item);
|
|
108
109
|
var prev = filteredItems[index - 1];
|
|
110
|
+
|
|
111
|
+
if ('items' in item) {
|
|
112
|
+
return /*#__PURE__*/_createElement(NavbarAccordion, _objectSpread(_objectSpread({}, item), {}, {
|
|
113
|
+
key: item.key,
|
|
114
|
+
gutter: prev && prev.groupKey !== item.groupKey,
|
|
115
|
+
onClick: item.onClick
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
|
|
109
119
|
return /*#__PURE__*/_createElement(NavbarItem, _objectSpread(_objectSpread({}, item), {}, {
|
|
110
120
|
key: item.key,
|
|
111
121
|
gutter: prev && prev.groupKey !== item.groupKey,
|
|
@@ -7,7 +7,7 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
var SidebarRoot = /*#__PURE__*/styled.aside.withConfig({
|
|
8
8
|
displayName: "Sidebar__SidebarRoot",
|
|
9
9
|
componentId: "SD__sc-b77o22-0"
|
|
10
|
-
})(["top:0;position:sticky;overflow-y:auto;overflow-x:hidden;
|
|
10
|
+
})(["top:0;position:sticky;overflow-y:auto;overflow-x:hidden;height:100vh;background-color:", ";border-right:1px solid ", ";"], Color.White, Color.Silver400);
|
|
11
11
|
var SidebarHeader = /*#__PURE__*/styled.div.withConfig({
|
|
12
12
|
displayName: "Sidebar__SidebarHeader",
|
|
13
13
|
componentId: "SD__sc-b77o22-1"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["onClick", "children"];
|
|
4
|
+
import { IconButton } from '@material-ui/core';
|
|
5
|
+
import { ArrowBack } from '@material-ui/icons';
|
|
6
|
+
import { useCollapseBreakpoint } from '@superdispatch/ui';
|
|
7
|
+
import { useSidebarContext } from "./SidebarContainer.js";
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
export function SidebarBackButton(_ref) {
|
|
10
|
+
var {
|
|
11
|
+
onClick: _onClick,
|
|
12
|
+
children = /*#__PURE__*/_jsx(ArrowBack, {
|
|
13
|
+
fontSize: "small"
|
|
14
|
+
})
|
|
15
|
+
} = _ref,
|
|
16
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
17
|
+
|
|
18
|
+
var isCollapsed = useCollapseBreakpoint('sm');
|
|
19
|
+
var {
|
|
20
|
+
openSidebar
|
|
21
|
+
} = useSidebarContext();
|
|
22
|
+
|
|
23
|
+
if (!isCollapsed) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return /*#__PURE__*/_jsx(IconButton, _objectSpread(_objectSpread({}, props), {}, {
|
|
28
|
+
size: "small",
|
|
29
|
+
onClick: event => {
|
|
30
|
+
_onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
|
|
31
|
+
|
|
32
|
+
if (!event.isDefaultPrevented()) {
|
|
33
|
+
openSidebar();
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
children: children
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
@@ -1,25 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCollapseBreakpoint } from '@superdispatch/ui';
|
|
2
|
+
import { createContext, forwardRef, useContext, useMemo, useState } from 'react';
|
|
2
3
|
import styled from 'styled-components';
|
|
3
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
5
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
-
var
|
|
6
|
-
|
|
6
|
+
var Context = /*#__PURE__*/createContext(null);
|
|
7
|
+
export function useSidebarContext() {
|
|
8
|
+
var context = useContext(Context);
|
|
9
|
+
|
|
10
|
+
if (!context) {
|
|
11
|
+
throw new Error('SidebarContext is used outside Provider');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
16
|
+
var SidebarContainerSidebar = /*#__PURE__*/styled.div.withConfig({
|
|
17
|
+
displayName: "SidebarContainer__SidebarContainerSidebar",
|
|
7
18
|
componentId: "SD__sc-uibj1m-0"
|
|
8
|
-
})(["
|
|
19
|
+
})(["height:inherit;max-height:inherit;min-height:inherit;width:240px;"]);
|
|
9
20
|
var SidebarContainerContent = /*#__PURE__*/styled.div.withConfig({
|
|
10
21
|
displayName: "SidebarContainer__SidebarContainerContent",
|
|
11
22
|
componentId: "SD__sc-uibj1m-1"
|
|
12
|
-
})(["height:inherit;max-height:inherit;min-height:inherit;
|
|
23
|
+
})(["height:inherit;max-height:inherit;min-height:inherit;"]);
|
|
24
|
+
var SidebarContainerRoot = /*#__PURE__*/styled.div.withConfig({
|
|
25
|
+
displayName: "SidebarContainer__SidebarContainerRoot",
|
|
26
|
+
componentId: "SD__sc-uibj1m-2"
|
|
27
|
+
})(["display:flex;height:inherit;max-height:inherit;min-height:inherit;& ", "{width:calc(100% - 240px);min-width:calc(100% - 240px);max-width:calc(100% - 240px);}&[data-visibility='sidebar'] ", "{width:100%;}&[data-visibility='sidebar'] ", "{display:none;}&[data-visibility='content'] ", "{display:none;}&[data-visibility='content'] ", "{width:100%;max-width:unset;}"], SidebarContainerContent, SidebarContainerSidebar, SidebarContainerContent, SidebarContainerSidebar, SidebarContainerContent);
|
|
13
28
|
export var SidebarContainer = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
14
29
|
var {
|
|
15
30
|
sidebar,
|
|
16
31
|
children
|
|
17
32
|
} = _ref;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
var isCollapsed = useCollapseBreakpoint('sm');
|
|
34
|
+
var [visibilityState, setVisibilityState] = useState('sidebar');
|
|
35
|
+
var visibility = isCollapsed ? visibilityState : 'both';
|
|
36
|
+
var context = useMemo(() => {
|
|
37
|
+
return {
|
|
38
|
+
openSidebar: () => {
|
|
39
|
+
setVisibilityState('sidebar');
|
|
40
|
+
},
|
|
41
|
+
openSidebarContent: () => {
|
|
42
|
+
setVisibilityState('content');
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
return /*#__PURE__*/_jsx(Context.Provider, {
|
|
47
|
+
value: context,
|
|
48
|
+
children: /*#__PURE__*/_jsxs(SidebarContainerRoot, {
|
|
49
|
+
ref: ref,
|
|
50
|
+
"data-visibility": visibility,
|
|
51
|
+
children: [/*#__PURE__*/_jsx(SidebarContainerSidebar, {
|
|
52
|
+
children: sidebar
|
|
53
|
+
}), /*#__PURE__*/_jsx(SidebarContainerContent, {
|
|
54
|
+
children: children
|
|
55
|
+
})]
|
|
56
|
+
})
|
|
23
57
|
});
|
|
24
58
|
});
|
|
25
59
|
if (process.env.NODE_ENV !== "production") SidebarContainer.displayName = "SidebarContainer";
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AppBar, Toolbar } from '@material-ui/core';
|
|
2
|
+
import { Column, Columns, Stack } from '@superdispatch/ui';
|
|
3
|
+
import { useLayoutEffect, useRef } from 'react';
|
|
4
|
+
import styled, { css } from 'styled-components';
|
|
5
|
+
import { Box } from "../box/Box.js";
|
|
6
|
+
import { TextBox } from "../text-box/TextBox.js";
|
|
7
|
+
import { SidebarBackButton } from "./SidebarBackButton.js";
|
|
8
|
+
import { useSidebarContext } from "./SidebarContainer.js";
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
var SidebarAppBar = /*#__PURE__*/styled(AppBar).withConfig({
|
|
12
|
+
displayName: "SidebarContent__SidebarAppBar",
|
|
13
|
+
componentId: "SD__sc-zpgf61-0"
|
|
14
|
+
})(_ref => {
|
|
15
|
+
var {
|
|
16
|
+
theme
|
|
17
|
+
} = _ref;
|
|
18
|
+
return css(["", "{&&{border-left:transparent;}}"], theme.breakpoints.up('sm'));
|
|
19
|
+
});
|
|
20
|
+
export function SidebarContent(_ref2) {
|
|
21
|
+
var {
|
|
22
|
+
dense,
|
|
23
|
+
action,
|
|
24
|
+
title,
|
|
25
|
+
children,
|
|
26
|
+
onBack,
|
|
27
|
+
openOnMount,
|
|
28
|
+
closeOnUnmount
|
|
29
|
+
} = _ref2;
|
|
30
|
+
var isOpenedOnMount = useRef(false);
|
|
31
|
+
var isClosedOnMount = useRef(false);
|
|
32
|
+
var {
|
|
33
|
+
openSidebarContent,
|
|
34
|
+
openSidebar
|
|
35
|
+
} = useSidebarContext();
|
|
36
|
+
useLayoutEffect(() => {
|
|
37
|
+
if (openOnMount) {
|
|
38
|
+
if (isOpenedOnMount.current) {
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.warn('[SidebarContent]: "openOnMount" should not change during lifecycle of the component.');
|
|
41
|
+
} else {
|
|
42
|
+
isOpenedOnMount.current = true;
|
|
43
|
+
openSidebarContent();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}, [openOnMount, openSidebarContent]);
|
|
47
|
+
useLayoutEffect(() => {
|
|
48
|
+
return () => {
|
|
49
|
+
if (closeOnUnmount) {
|
|
50
|
+
if (isClosedOnMount.current) {
|
|
51
|
+
// eslint-disable-next-line no-console
|
|
52
|
+
console.warn('[SidebarContent]: "closeOnUnmount" should not change during lifecycle of the component.');
|
|
53
|
+
} else {
|
|
54
|
+
isClosedOnMount.current = true;
|
|
55
|
+
openSidebar();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}, [openSidebar, closeOnUnmount]);
|
|
60
|
+
return /*#__PURE__*/_jsxs(Stack, {
|
|
61
|
+
space: "none",
|
|
62
|
+
children: [/*#__PURE__*/_jsx(SidebarAppBar, {
|
|
63
|
+
children: /*#__PURE__*/_jsx(Toolbar, {
|
|
64
|
+
children: /*#__PURE__*/_jsxs(Columns, {
|
|
65
|
+
align: "center",
|
|
66
|
+
space: "small",
|
|
67
|
+
children: [/*#__PURE__*/_jsx(Column, {
|
|
68
|
+
width: "content",
|
|
69
|
+
children: /*#__PURE__*/_jsx(SidebarBackButton, {
|
|
70
|
+
onClick: onBack
|
|
71
|
+
})
|
|
72
|
+
}), /*#__PURE__*/_jsx(Column, {
|
|
73
|
+
children: /*#__PURE__*/_jsx(TextBox, {
|
|
74
|
+
variant: "heading-2",
|
|
75
|
+
children: title
|
|
76
|
+
})
|
|
77
|
+
}), /*#__PURE__*/_jsx(Column, {
|
|
78
|
+
width: "content",
|
|
79
|
+
children: action
|
|
80
|
+
})]
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
}), /*#__PURE__*/_jsx(Box, {
|
|
84
|
+
padding: dense ? 'none' : ['small', 'medium'],
|
|
85
|
+
children: children
|
|
86
|
+
})]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -4,6 +4,7 @@ import { Color, Column, Columns, Inline } from '@superdispatch/ui';
|
|
|
4
4
|
import { forwardRef, useLayoutEffect, useRef, useState } from 'react';
|
|
5
5
|
import styled, { css } from 'styled-components';
|
|
6
6
|
import { TextBox } from "../text-box/TextBox.js";
|
|
7
|
+
import { useSidebarContext } from "./SidebarContainer.js";
|
|
7
8
|
import { SidebarMenuItemContextProvider } from "./SidebarMenuItemContext.js";
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
10
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -29,17 +30,21 @@ export var SidebarMenuItem = /*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
|
29
30
|
var {
|
|
30
31
|
action,
|
|
31
32
|
avatar,
|
|
32
|
-
onClick,
|
|
33
|
+
onClick: _onClick,
|
|
33
34
|
external,
|
|
34
35
|
children,
|
|
35
36
|
disabled,
|
|
36
37
|
selected,
|
|
37
38
|
secondaryActions,
|
|
38
|
-
badge: badgeProp
|
|
39
|
+
badge: badgeProp,
|
|
40
|
+
openContentOnClick
|
|
39
41
|
} = _ref2;
|
|
40
42
|
var [hovered, setHovered] = useState(false);
|
|
41
43
|
var actionsRef = useRef(null);
|
|
42
44
|
var actionsPlaceholderRef = useRef(null);
|
|
45
|
+
var {
|
|
46
|
+
openSidebarContent
|
|
47
|
+
} = useSidebarContext();
|
|
43
48
|
useLayoutEffect(() => {
|
|
44
49
|
if (actionsRef.current && actionsPlaceholderRef.current) {
|
|
45
50
|
actionsPlaceholderRef.current.style.width = "".concat(Math.max(0, actionsRef.current.offsetWidth - 8), "px");
|
|
@@ -56,9 +61,15 @@ export var SidebarMenuItem = /*#__PURE__*/forwardRef((_ref2, ref) => {
|
|
|
56
61
|
setHovered(false);
|
|
57
62
|
},
|
|
58
63
|
children: [/*#__PURE__*/_jsx(ButtonBase, {
|
|
59
|
-
onClick: onClick,
|
|
60
64
|
disabled: disabled,
|
|
61
65
|
"aria-current": selected,
|
|
66
|
+
onClick: event => {
|
|
67
|
+
_onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
|
|
68
|
+
|
|
69
|
+
if (!event.isDefaultPrevented() && openContentOnClick) {
|
|
70
|
+
openSidebarContent();
|
|
71
|
+
}
|
|
72
|
+
},
|
|
62
73
|
children: /*#__PURE__*/_jsxs(Columns, {
|
|
63
74
|
align: "center",
|
|
64
75
|
space: "xsmall",
|
|
@@ -35,6 +35,7 @@ export var SidebarMenuItemAvatar = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
35
35
|
color: "primary",
|
|
36
36
|
checked: value,
|
|
37
37
|
disabled: disabled,
|
|
38
|
+
onClick: stopPropagation,
|
|
38
39
|
onMouseDown: stopPropagation,
|
|
39
40
|
onTouchStart: stopPropagation,
|
|
40
41
|
onChange: (_, checked) => {
|
package/dist-types/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { ReactNode, ForwardRefExoticComponent, RefAttributes, Ref, AriaAttributes, MouseEventHandler, FocusEventHandler, HTMLAttributes,
|
|
2
|
+
import { ReactNode, ForwardRefExoticComponent, RefAttributes, Ref, AriaAttributes, MouseEventHandler, FocusEventHandler, HTMLAttributes, AnchorHTMLAttributes, FunctionComponent, ReactElement, ComponentType, MouseEvent, Key, CSSProperties, ReactChild } from 'react';
|
|
3
3
|
import { CSSTransition } from 'react-transition-group';
|
|
4
4
|
import { CSSTransitionProps } from 'react-transition-group/CSSTransition';
|
|
5
5
|
import { SpaceProp, NegativeSpaceProp, ResponsiveProp, ColorProp } from '@superdispatch/ui';
|
|
6
6
|
import { Property } from 'csstype';
|
|
7
|
-
import { ButtonBaseProps, AvatarProps, TooltipProps } from '@material-ui/core';
|
|
7
|
+
import { ButtonBaseProps, AvatarProps, IconButtonProps, TooltipProps } from '@material-ui/core';
|
|
8
8
|
import { FileRejection } from 'react-dropzone';
|
|
9
9
|
import { StyledComponent, DefaultTheme } from 'styled-components';
|
|
10
10
|
|
|
@@ -163,6 +163,21 @@ interface FileListItemProps {
|
|
|
163
163
|
}
|
|
164
164
|
declare const FileListItem: ForwardRefExoticComponent<FileListItemProps & RefAttributes<HTMLDivElement>>;
|
|
165
165
|
|
|
166
|
+
declare type LinkComponentProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & {
|
|
167
|
+
href: string;
|
|
168
|
+
truncate?: number;
|
|
169
|
+
};
|
|
170
|
+
interface LinkedTextProps extends Omit<LinkComponentProps, 'ref' | 'href'> {
|
|
171
|
+
children?: null | string;
|
|
172
|
+
linkComponent?: FunctionComponent<LinkComponentProps>;
|
|
173
|
+
}
|
|
174
|
+
declare function LinkedText({ children, linkComponent, ...props }: LinkedTextProps): ReactElement | null;
|
|
175
|
+
|
|
176
|
+
interface MultilineTextProps {
|
|
177
|
+
overflowWrap?: Extract<Property.OverflowWrap, 'anywhere' | 'break-word' | 'normal'>;
|
|
178
|
+
}
|
|
179
|
+
declare const MultilineText: StyledComponent<"span", DefaultTheme, MultilineTextProps, never>;
|
|
180
|
+
|
|
166
181
|
interface NavbarBottomBarItem {
|
|
167
182
|
active?: boolean;
|
|
168
183
|
value: string;
|
|
@@ -178,6 +193,14 @@ interface NavbarBottomBarProps {
|
|
|
178
193
|
}
|
|
179
194
|
declare function NavbarBottomBar({ items, hasMenuBadge, }: NavbarBottomBarProps): ReactElement;
|
|
180
195
|
|
|
196
|
+
interface NavbarAccordionProps {
|
|
197
|
+
label: ReactNode;
|
|
198
|
+
icon?: ReactNode;
|
|
199
|
+
gutter?: boolean;
|
|
200
|
+
items: NavbarItemOptions[];
|
|
201
|
+
onClick: (event: MouseEvent<HTMLDivElement>) => void;
|
|
202
|
+
}
|
|
203
|
+
|
|
181
204
|
declare const NavbarBadge: StyledComponent<"span", DefaultTheme, {}, never>;
|
|
182
205
|
declare const NavbarLabel: StyledComponent<"span", DefaultTheme, {}, never>;
|
|
183
206
|
interface NavbarItemProps {
|
|
@@ -189,8 +212,9 @@ interface NavbarItemProps {
|
|
|
189
212
|
ident?: number;
|
|
190
213
|
gutter?: boolean;
|
|
191
214
|
variant?: 'danger' | 'primary';
|
|
215
|
+
active?: boolean;
|
|
192
216
|
}
|
|
193
|
-
declare function NavbarItem({ label, gutter, badge, icon, component, onClick, variant, ident, }: NavbarItemProps): ReactElement;
|
|
217
|
+
declare function NavbarItem({ label, gutter, badge, icon, component, onClick, variant, ident, active, }: NavbarItemProps): ReactElement;
|
|
194
218
|
|
|
195
219
|
interface NavbarMenuItemProps {
|
|
196
220
|
icon?: ReactNode;
|
|
@@ -199,6 +223,11 @@ interface NavbarMenuItemProps {
|
|
|
199
223
|
component?: ComponentType<HTMLAttributes<HTMLElement>>;
|
|
200
224
|
}
|
|
201
225
|
declare function NavbarMenuItem({ label, icon, onClick, component, }: NavbarMenuItemProps): ReactElement;
|
|
226
|
+
interface NavbarAccordionOptions extends NavbarAccordionProps {
|
|
227
|
+
key: Key;
|
|
228
|
+
groupKey?: Key;
|
|
229
|
+
hide?: boolean;
|
|
230
|
+
}
|
|
202
231
|
interface NavbarItemOptions extends NavbarItemProps {
|
|
203
232
|
key: Key;
|
|
204
233
|
groupKey?: Key;
|
|
@@ -206,7 +235,7 @@ interface NavbarItemOptions extends NavbarItemProps {
|
|
|
206
235
|
}
|
|
207
236
|
interface NavbarListProps {
|
|
208
237
|
header: ReactNode;
|
|
209
|
-
items: NavbarItemOptions
|
|
238
|
+
items: Array<NavbarItemOptions | NavbarAccordionOptions>;
|
|
210
239
|
footer?: ReactNode;
|
|
211
240
|
}
|
|
212
241
|
declare function NavbarList({ header, items, footer, }: NavbarListProps): ReactElement;
|
|
@@ -260,12 +289,30 @@ interface SidebarProps {
|
|
|
260
289
|
}
|
|
261
290
|
declare const Sidebar: ForwardRefExoticComponent<SidebarProps & RefAttributes<HTMLDivElement>>;
|
|
262
291
|
|
|
292
|
+
declare function SidebarBackButton({ onClick, children, ...props }: IconButtonProps): ReactElement | null;
|
|
293
|
+
|
|
294
|
+
interface SidebarContext {
|
|
295
|
+
openSidebar: () => void;
|
|
296
|
+
openSidebarContent: () => void;
|
|
297
|
+
}
|
|
298
|
+
declare function useSidebarContext(): SidebarContext;
|
|
263
299
|
interface SidebarContainerProps {
|
|
264
300
|
sidebar: ReactChild;
|
|
265
301
|
children?: ReactNode;
|
|
266
302
|
}
|
|
267
303
|
declare const SidebarContainer: ForwardRefExoticComponent<SidebarContainerProps & RefAttributes<HTMLDivElement>>;
|
|
268
304
|
|
|
305
|
+
interface SidebarContentProps {
|
|
306
|
+
dense?: boolean;
|
|
307
|
+
title: ReactNode;
|
|
308
|
+
children: ReactNode;
|
|
309
|
+
action?: ReactNode;
|
|
310
|
+
openOnMount?: boolean;
|
|
311
|
+
closeOnUnmount?: boolean;
|
|
312
|
+
onBack?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
313
|
+
}
|
|
314
|
+
declare function SidebarContent({ dense, action, title, children, onBack, openOnMount, closeOnUnmount, }: SidebarContentProps): ReactElement;
|
|
315
|
+
|
|
269
316
|
|
|
270
317
|
declare const SidebarDivider: ForwardRefExoticComponent<RefAttributes<HTMLDivElement>>;
|
|
271
318
|
|
|
@@ -278,6 +325,7 @@ interface SidebarMenuItemProps {
|
|
|
278
325
|
action?: ReactNode;
|
|
279
326
|
avatar?: ReactNode;
|
|
280
327
|
children?: ReactNode;
|
|
328
|
+
openContentOnClick?: boolean;
|
|
281
329
|
secondaryActions?: ReactNode;
|
|
282
330
|
}
|
|
283
331
|
declare const SidebarMenuItem: ForwardRefExoticComponent<SidebarMenuItemProps & RefAttributes<HTMLDivElement>>;
|
|
@@ -322,4 +370,4 @@ interface TextBoxProps {
|
|
|
322
370
|
}
|
|
323
371
|
declare const TextBox: ForwardRefExoticComponent<TextBoxProps & RefAttributes<HTMLElement>>;
|
|
324
372
|
|
|
325
|
-
export { Alert, AlertProps, AlertSeverityProp, AnchorButton, AnchorButtonProps, Banner, BorderRadiusProp, BorderWidthProp, Box, BoxProps, Button, ButtonArea, ButtonAreaProps, ButtonProps, ButtonSizeProp, ButtonVariantProp, Container, ContainerProps, DescriptionItem, DescriptionItemProps, FileDropZone, FileDropZoneProps, FileListItem, FileListItemProps, MarginProp, Navbar, NavbarAvatar, NavbarBadge, NavbarBottomBar, NavbarBottomBarItem, NavbarItem, NavbarItemOptions, NavbarItemProps, NavbarLabel, NavbarList, NavbarMenu, NavbarMenuItem, NavbarMenuItemOption, Sidebar, SidebarContainer, SidebarContainerProps, SidebarDivider, SidebarMenuItem, SidebarMenuItemAction, SidebarMenuItemActionProps, SidebarMenuItemAvatar, SidebarMenuItemAvatarProps, SidebarMenuItemProps, SidebarProps, SidebarSubheader, SidebarSubheaderProps, TextAlignProp, TextBox, TextBoxProps, TextColorProp, TextDisplayProp, TextVariantProp, formatBytes, toBytes, useNavbarContext };
|
|
373
|
+
export { Alert, AlertProps, AlertSeverityProp, AnchorButton, AnchorButtonProps, Banner, BorderRadiusProp, BorderWidthProp, Box, BoxProps, Button, ButtonArea, ButtonAreaProps, ButtonProps, ButtonSizeProp, ButtonVariantProp, Container, ContainerProps, DescriptionItem, DescriptionItemProps, FileDropZone, FileDropZoneProps, FileListItem, FileListItemProps, LinkComponentProps, LinkedText, LinkedTextProps, MarginProp, MultilineText, MultilineTextProps, Navbar, NavbarAccordionOptions, NavbarAvatar, NavbarBadge, NavbarBottomBar, NavbarBottomBarItem, NavbarItem, NavbarItemOptions, NavbarItemProps, NavbarLabel, NavbarList, NavbarMenu, NavbarMenuItem, NavbarMenuItemOption, Sidebar, SidebarBackButton, SidebarContainer, SidebarContainerProps, SidebarContent, SidebarContentProps, SidebarDivider, SidebarMenuItem, SidebarMenuItemAction, SidebarMenuItemActionProps, SidebarMenuItemAvatar, SidebarMenuItemAvatarProps, SidebarMenuItemProps, SidebarProps, SidebarSubheader, SidebarSubheaderProps, TextAlignProp, TextBox, TextBoxProps, TextColorProp, TextDisplayProp, TextVariantProp, formatBytes, toBytes, useNavbarContext, useSidebarContext };
|