@superdispatch/ui-lab 0.19.0 → 0.20.2

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-web/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import { CheckCircle, Info, Error, Image, Refresh, Delete, Menu, ExpandMore, MenuOpen, OpenInNew } from '@material-ui/icons';
1
+ import { CheckCircle, Info, Error as Error$1, Image, Refresh, Delete, Menu, ExpandMore, MenuOpen, ArrowBack, OpenInNew } from '@material-ui/icons';
2
2
  import { Alert as Alert$1 } from '@material-ui/lab';
3
- import { Color, parseResponsiveProp, isColorProp, parseSpaceProp, Stack, mergeRefs, useUID, isEmptyReactNode, Columns, Column, Inline, CardButton, useResponsiveValue } from '@superdispatch/ui';
3
+ import { Color, parseResponsiveProp, isColorProp, parseSpaceProp, Stack, mergeRefs, useUID, isEmptyReactNode, Columns, Column, Inline, CardButton, useResponsiveValue, useCollapseBreakpoint } from '@superdispatch/ui';
4
4
  import { forwardRef, useState, useEffect, useRef, useLayoutEffect, Suspense, memo, useContext, createContext, useMemo, createElement } from 'react';
5
5
  import styled, { css, keyframes } from 'styled-components';
6
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
7
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
8
8
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
9
9
  import { CSSTransition } from 'react-transition-group';
10
- import { ButtonBase, Typography, CircularProgress, SvgIcon, Link, Tooltip, IconButton, BottomNavigation, BottomNavigationAction, AccordionSummary, Accordion, useTheme, useMediaQuery, Drawer, Avatar, MenuItem, Menu as Menu$1, Divider as Divider$1, Checkbox } from '@material-ui/core';
10
+ import { ButtonBase, Typography, CircularProgress, SvgIcon, Link, Tooltip, IconButton, BottomNavigation, BottomNavigationAction, AccordionSummary, Accordion, useTheme, useMediaQuery, Drawer, Avatar, MenuItem, Menu as Menu$1, Toolbar, AppBar, Divider as Divider$1, Checkbox } from '@material-ui/core';
11
11
  import { mdiUpload, mdiFilePdfBox, mdiTextBox } from '@mdi/js';
12
12
  import Dropzone from 'react-dropzone';
13
13
  import { Anchorme } from 'react-anchorme';
@@ -29,7 +29,7 @@ function toMaterialSeverity(severity) {
29
29
  var iconMapping = {
30
30
  success: /*#__PURE__*/jsx(CheckCircle, {}),
31
31
  info: /*#__PURE__*/jsx(Info, {}),
32
- error: /*#__PURE__*/jsx(Error, {})
32
+ error: /*#__PURE__*/jsx(Error$1, {})
33
33
  };
34
34
  var Alert = /*#__PURE__*/forwardRef((_ref, ref) => {
35
35
  var {
@@ -807,7 +807,7 @@ function UploadRejection(_ref2) {
807
807
  align: "center",
808
808
  children: [/*#__PURE__*/jsx(Column, {
809
809
  width: "content",
810
- children: /*#__PURE__*/jsx(Error, {})
810
+ children: /*#__PURE__*/jsx(Error$1, {})
811
811
  }), /*#__PURE__*/jsx(Column, {
812
812
  children: error.code === 'file-too-large' ? maxSize == null ? 'Attachment size is too large' : "Attachment size should be less than ".concat(formatBytes(maxSize)) : error.message
813
813
  })]
@@ -942,7 +942,7 @@ var FileListItem = /*#__PURE__*/forwardRef((_ref2, ref) => {
942
942
  space: "xsmall",
943
943
  children: [/*#__PURE__*/jsx(Column, {
944
944
  width: "content",
945
- children: status === 'error' ? /*#__PURE__*/jsx(Error, {
945
+ children: status === 'error' ? /*#__PURE__*/jsx(Error$1, {
946
946
  color: "error",
947
947
  fontSize: "small"
948
948
  }) : fileType === 'pdf' ? /*#__PURE__*/jsx(PdfIcon, {
@@ -1130,7 +1130,7 @@ var NavbarLabel = /*#__PURE__*/styled.span.withConfig({
1130
1130
  var NavbarItemRoot = /*#__PURE__*/styled.div.withConfig({
1131
1131
  displayName: "NavbarItem__NavbarItemRoot",
1132
1132
  componentId: "SD__sc-1pvzq3w-2"
1133
- })(["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);
1133
+ })(["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']{background-color:#2f394a;border-left-color:", ";}"], Color.White, Color.Blue300, Color.Blue300);
1134
1134
  var IconWrapper$1 = /*#__PURE__*/styled.div.withConfig({
1135
1135
  displayName: "NavbarItem__IconWrapper",
1136
1136
  componentId: "SD__sc-1pvzq3w-3"
@@ -1180,12 +1180,12 @@ var NavbarAccordionRoot = /*#__PURE__*/styled(Accordion).withConfig({
1180
1180
  var {
1181
1181
  gutter
1182
1182
  } = _ref;
1183
- 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');
1183
+ 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:", ";&[aria-current]{background-color:#2f394a;color:", ";}&.MuiAccordion-root:before{background-color:#1b2638;}&.MuiPaper-elevation0{border:0px;}&.MuiAccordion-root.Mui-expanded{margin-top:", ";}"], gutter ? '16px' : '0', Color.White, gutter ? '16px' : '0');
1184
1184
  });
1185
1185
  var NavbarAccordionSummary = /*#__PURE__*/styled(AccordionSummary).withConfig({
1186
1186
  displayName: "NavbarAccordion__NavbarAccordionSummary",
1187
1187
  componentId: "SD__sc-1s7g3kw-2"
1188
- })(["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);
1188
+ })(["border-left:4px solid transparent;padding-left:20px;&.MuiAccordionSummary-root{max-height:40px;min-height:40px;}&:hover,&[data-active='true']{background-color:#2f394a;border-left-color:", ";}&[data-expanded='false']{.MuiAccordionSummary-expandIcon{display:none;}}"], Color.Blue300);
1189
1189
  var IconWrapper$2 = /*#__PURE__*/styled.div.withConfig({
1190
1190
  displayName: "NavbarAccordion__IconWrapper",
1191
1191
  componentId: "SD__sc-1s7g3kw-3"
@@ -1579,7 +1579,7 @@ function NavbarMenu(_ref2) {
1579
1579
  var SidebarRoot = /*#__PURE__*/styled.aside.withConfig({
1580
1580
  displayName: "Sidebar__SidebarRoot",
1581
1581
  componentId: "SD__sc-b77o22-0"
1582
- })(["top:0;position:sticky;overflow-y:auto;overflow-x:hidden;width:240px;height:100vh;background-color:", ";border-right:1px solid ", ";"], Color.White, Color.Silver400);
1582
+ })(["top:0;position:sticky;overflow-y:auto;overflow-x:hidden;height:100vh;background-color:", ";border-right:1px solid ", ";"], Color.White, Color.Silver400);
1583
1583
  var SidebarHeader = /*#__PURE__*/styled.div.withConfig({
1584
1584
  displayName: "Sidebar__SidebarHeader",
1585
1585
  componentId: "SD__sc-b77o22-1"
@@ -1631,28 +1631,187 @@ var Sidebar = /*#__PURE__*/forwardRef((_ref, ref) => {
1631
1631
  });
1632
1632
  if (process.env.NODE_ENV !== "production") Sidebar.displayName = "Sidebar";
1633
1633
 
1634
- var SidebarContainerRoot = /*#__PURE__*/styled.div.withConfig({
1635
- displayName: "SidebarContainer__SidebarContainerRoot",
1634
+ var Context = /*#__PURE__*/createContext(null);
1635
+ function useSidebarContext() {
1636
+ var context = useContext(Context);
1637
+
1638
+ if (!context) {
1639
+ throw new Error('SidebarContext is used outside Provider');
1640
+ }
1641
+
1642
+ return context;
1643
+ }
1644
+ var SidebarContainerSidebar = /*#__PURE__*/styled.div.withConfig({
1645
+ displayName: "SidebarContainer__SidebarContainerSidebar",
1636
1646
  componentId: "SD__sc-uibj1m-0"
1637
- })(["display:flex;height:inherit;max-height:inherit;min-height:inherit;"]);
1647
+ })(["height:inherit;max-height:inherit;min-height:inherit;width:240px;"]);
1638
1648
  var SidebarContainerContent = /*#__PURE__*/styled.div.withConfig({
1639
1649
  displayName: "SidebarContainer__SidebarContainerContent",
1640
1650
  componentId: "SD__sc-uibj1m-1"
1641
- })(["height:inherit;max-height:inherit;min-height:inherit;width:calc(100% - 240px);min-width:calc(100% - 240px);max-width:calc(100% - 240px);"]);
1651
+ })(["height:inherit;max-height:inherit;min-height:inherit;"]);
1652
+ var SidebarContainerRoot = /*#__PURE__*/styled.div.withConfig({
1653
+ displayName: "SidebarContainer__SidebarContainerRoot",
1654
+ componentId: "SD__sc-uibj1m-2"
1655
+ })(["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);
1642
1656
  var SidebarContainer = /*#__PURE__*/forwardRef((_ref, ref) => {
1643
1657
  var {
1644
1658
  sidebar,
1645
1659
  children
1646
1660
  } = _ref;
1647
- return /*#__PURE__*/jsxs(SidebarContainerRoot, {
1648
- ref: ref,
1649
- children: [sidebar, /*#__PURE__*/jsx(SidebarContainerContent, {
1650
- children: children
1651
- })]
1661
+ var isCollapsed = useCollapseBreakpoint('sm');
1662
+ var [visibilityState, setVisibilityState] = useState('sidebar');
1663
+ var visibility = isCollapsed ? visibilityState : 'both';
1664
+ var context = useMemo(() => {
1665
+ return {
1666
+ openSidebar: () => {
1667
+ setVisibilityState('sidebar');
1668
+ },
1669
+ openSidebarContent: () => {
1670
+ setVisibilityState('content');
1671
+ }
1672
+ };
1673
+ }, []);
1674
+ return /*#__PURE__*/jsx(Context.Provider, {
1675
+ value: context,
1676
+ children: /*#__PURE__*/jsxs(SidebarContainerRoot, {
1677
+ ref: ref,
1678
+ "data-visibility": visibility,
1679
+ children: [/*#__PURE__*/jsx(SidebarContainerSidebar, {
1680
+ children: sidebar
1681
+ }), /*#__PURE__*/jsx(SidebarContainerContent, {
1682
+ children: children
1683
+ })]
1684
+ })
1652
1685
  });
1653
1686
  });
1654
1687
  if (process.env.NODE_ENV !== "production") SidebarContainer.displayName = "SidebarContainer";
1655
1688
 
1689
+ var _excluded$8 = ["onClick", "children"];
1690
+ function SidebarBackButton(_ref) {
1691
+ var {
1692
+ onClick: _onClick,
1693
+ children = /*#__PURE__*/jsx(ArrowBack, {
1694
+ fontSize: "small"
1695
+ })
1696
+ } = _ref,
1697
+ props = _objectWithoutProperties(_ref, _excluded$8);
1698
+
1699
+ var isCollapsed = useCollapseBreakpoint('sm');
1700
+ var {
1701
+ openSidebar
1702
+ } = useSidebarContext();
1703
+
1704
+ if (!isCollapsed) {
1705
+ return null;
1706
+ }
1707
+
1708
+ return /*#__PURE__*/jsx(IconButton, _objectSpread(_objectSpread({}, props), {}, {
1709
+ size: "small",
1710
+ onClick: event => {
1711
+ _onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
1712
+
1713
+ if (!event.isDefaultPrevented()) {
1714
+ openSidebar();
1715
+ }
1716
+ },
1717
+ children: children
1718
+ }));
1719
+ }
1720
+
1721
+ var SidebarAppBar = /*#__PURE__*/styled(AppBar).withConfig({
1722
+ displayName: "SidebarContent__SidebarAppBar",
1723
+ componentId: "SD__sc-zpgf61-0"
1724
+ })(_ref => {
1725
+ var {
1726
+ theme
1727
+ } = _ref;
1728
+ return css(["", "{&&{border-left:transparent;}}"], theme.breakpoints.up('sm'));
1729
+ });
1730
+ var ToolbarContent = /*#__PURE__*/styled.div.withConfig({
1731
+ displayName: "SidebarContent__ToolbarContent",
1732
+ componentId: "SD__sc-zpgf61-1"
1733
+ })(["flex:1;padding:16px;"]);
1734
+ function SidebarContent(_ref2) {
1735
+ var {
1736
+ dense,
1737
+ action,
1738
+ title,
1739
+ children,
1740
+ onBack,
1741
+ openOnMount,
1742
+ closeOnUnmount
1743
+ } = _ref2;
1744
+ var isOpenedOnMount = useRef(false);
1745
+ var isClosedOnMount = useRef(false);
1746
+ var {
1747
+ openSidebarContent,
1748
+ openSidebar
1749
+ } = useSidebarContext();
1750
+ useLayoutEffect(() => {
1751
+ if (openOnMount) {
1752
+ if (isOpenedOnMount.current) {
1753
+ // eslint-disable-next-line no-console
1754
+ console.warn('[SidebarContent]: "openOnMount" should not change during lifecycle of the component.');
1755
+ } else {
1756
+ isOpenedOnMount.current = true;
1757
+ openSidebarContent();
1758
+ }
1759
+ }
1760
+ }, [openOnMount, openSidebarContent]);
1761
+ useLayoutEffect(() => {
1762
+ return () => {
1763
+ if (closeOnUnmount) {
1764
+ if (isClosedOnMount.current) {
1765
+ // eslint-disable-next-line no-console
1766
+ console.warn('[SidebarContent]: "closeOnUnmount" should not change during lifecycle of the component.');
1767
+ } else {
1768
+ isClosedOnMount.current = true;
1769
+ openSidebar();
1770
+ }
1771
+ }
1772
+ };
1773
+ }, [openSidebar, closeOnUnmount]);
1774
+ return /*#__PURE__*/jsxs(Stack, {
1775
+ space: "none",
1776
+ children: [/*#__PURE__*/jsx(SidebarAppBar, {
1777
+ children: /*#__PURE__*/jsx(Toolbar, {
1778
+ disableGutters: true,
1779
+ children: /*#__PURE__*/jsx(ToolbarContent, {
1780
+ children: /*#__PURE__*/jsxs(Columns, {
1781
+ align: ['top', 'center'],
1782
+ space: "small",
1783
+ children: [/*#__PURE__*/jsx(Column, {
1784
+ width: "content",
1785
+ children: /*#__PURE__*/jsx(SidebarBackButton, {
1786
+ onClick: onBack
1787
+ })
1788
+ }), /*#__PURE__*/jsx(Column, {
1789
+ children: /*#__PURE__*/jsxs(Columns, {
1790
+ space: "small",
1791
+ collapseBelow: "tablet",
1792
+ reverse: [true, false],
1793
+ align: ['bottom', 'center'],
1794
+ children: [/*#__PURE__*/jsx(Column, {
1795
+ children: /*#__PURE__*/jsx(TextBox, {
1796
+ variant: "heading-2",
1797
+ children: title
1798
+ })
1799
+ }), action && /*#__PURE__*/jsx(Column, {
1800
+ width: "content",
1801
+ children: action
1802
+ })]
1803
+ })
1804
+ })]
1805
+ })
1806
+ })
1807
+ })
1808
+ }), /*#__PURE__*/jsx(Box, {
1809
+ padding: dense ? 'none' : ['small', 'medium'],
1810
+ children: children
1811
+ })]
1812
+ });
1813
+ }
1814
+
1656
1815
  var SidebarDividerRoot = /*#__PURE__*/styled.div.withConfig({
1657
1816
  displayName: "SidebarDivider__SidebarDividerRoot",
1658
1817
  componentId: "SD__sc-5lwi2i-0"
@@ -1707,36 +1866,60 @@ var SidebarMenuItem = /*#__PURE__*/forwardRef((_ref2, ref) => {
1707
1866
  var {
1708
1867
  action,
1709
1868
  avatar,
1710
- onClick,
1869
+ onClick: _onClick,
1711
1870
  external,
1712
1871
  children,
1713
1872
  disabled,
1714
1873
  selected,
1715
1874
  secondaryActions,
1716
- badge: badgeProp
1875
+ badge: badgeProp,
1876
+ openContentOnClick
1717
1877
  } = _ref2;
1718
1878
  var [hovered, setHovered] = useState(false);
1879
+ var rootRef = useRef(null);
1719
1880
  var actionsRef = useRef(null);
1720
1881
  var actionsPlaceholderRef = useRef(null);
1882
+ var {
1883
+ openSidebarContent
1884
+ } = useSidebarContext();
1885
+ var {
1886
+ matches: isHoverSupported
1887
+ } = matchMedia('(hover: hover)');
1721
1888
  useLayoutEffect(() => {
1722
1889
  if (actionsRef.current && actionsPlaceholderRef.current) {
1723
1890
  actionsPlaceholderRef.current.style.width = "".concat(Math.max(0, actionsRef.current.offsetWidth - 8), "px");
1724
1891
  }
1725
1892
  });
1893
+ useLayoutEffect(() => {
1894
+ var rootNode = rootRef.current;
1895
+
1896
+ if (rootNode) {
1897
+ if (isHoverSupported) {
1898
+ rootNode.addEventListener('mouseenter', () => {
1899
+ setHovered(true);
1900
+ });
1901
+ rootNode.addEventListener('mouseleave', () => {
1902
+ setHovered(false);
1903
+ });
1904
+ } else {
1905
+ setHovered(true);
1906
+ }
1907
+ }
1908
+ }, [isHoverSupported]);
1726
1909
  var badge = !badgeProp || !Number.isFinite(badgeProp) ? null : badgeProp > 999 ? '999+' : badgeProp;
1727
1910
  return /*#__PURE__*/jsxs(SidebarMenuItemRoot, {
1728
- ref: ref,
1911
+ ref: mergeRefs(ref, rootRef),
1729
1912
  hasAvatar: !!avatar,
1730
- onMouseEnter: () => {
1731
- setHovered(true);
1732
- },
1733
- onMouseLeave: () => {
1734
- setHovered(false);
1735
- },
1736
1913
  children: [/*#__PURE__*/jsx(ButtonBase, {
1737
- onClick: onClick,
1738
1914
  disabled: disabled,
1739
1915
  "aria-current": selected,
1916
+ onClick: event => {
1917
+ _onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
1918
+
1919
+ if (!event.isDefaultPrevented() && openContentOnClick) {
1920
+ openSidebarContent();
1921
+ }
1922
+ },
1740
1923
  children: /*#__PURE__*/jsxs(Columns, {
1741
1924
  align: "center",
1742
1925
  space: "xsmall",
@@ -1849,6 +2032,7 @@ var SidebarMenuItemAvatar = /*#__PURE__*/forwardRef((_ref, ref) => {
1849
2032
  color: "primary",
1850
2033
  checked: value,
1851
2034
  disabled: disabled,
2035
+ onClick: stopPropagation,
1852
2036
  onMouseDown: stopPropagation,
1853
2037
  onTouchStart: stopPropagation,
1854
2038
  onChange: (_, checked) => {
@@ -1898,5 +2082,5 @@ var SidebarSubheader = /*#__PURE__*/forwardRef((_ref, ref) => {
1898
2082
  });
1899
2083
  if (process.env.NODE_ENV !== "production") SidebarSubheader.displayName = "SidebarSubheader";
1900
2084
 
1901
- export { Alert, AnchorButton, Banner, Box, Button, ButtonArea, Container, DescriptionItem, FileDropZone, FileListItem, LinkedText, MultilineText, Navbar, NavbarAvatar, NavbarBadge, NavbarBottomBar, NavbarItem, NavbarLabel, NavbarList, NavbarMenu, NavbarMenuItem, Sidebar, SidebarContainer, SidebarDivider, SidebarMenuItem, SidebarMenuItemAction, SidebarMenuItemAvatar, SidebarSubheader, TextBox, formatBytes, toBytes, useNavbarContext };
2085
+ export { Alert, AnchorButton, Banner, Box, Button, ButtonArea, Container, DescriptionItem, FileDropZone, FileListItem, LinkedText, MultilineText, Navbar, NavbarAvatar, NavbarBadge, NavbarBottomBar, NavbarItem, NavbarLabel, NavbarList, NavbarMenu, NavbarMenuItem, Sidebar, SidebarBackButton, SidebarContainer, SidebarContent, SidebarDivider, SidebarMenuItem, SidebarMenuItemAction, SidebarMenuItemAvatar, SidebarSubheader, TextBox, formatBytes, toBytes, useNavbarContext, useSidebarContext };
1902
2086
  //# sourceMappingURL=index.js.map