@superdispatch/ui-lab 0.19.0 → 0.20.0

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.
@@ -1586,7 +1586,7 @@ function NavbarMenu(_ref2) {
1586
1586
  var SidebarRoot = /*#__PURE__*/styled__default.aside.withConfig({
1587
1587
  displayName: "Sidebar__SidebarRoot",
1588
1588
  componentId: "SD__sc-b77o22-0"
1589
- })(["top:0;position:sticky;overflow-y:auto;overflow-x:hidden;width:240px;height:100vh;background-color:", ";border-right:1px solid ", ";"], ui.Color.White, ui.Color.Silver400);
1589
+ })(["top:0;position:sticky;overflow-y:auto;overflow-x:hidden;height:100vh;background-color:", ";border-right:1px solid ", ";"], ui.Color.White, ui.Color.Silver400);
1590
1590
  var SidebarHeader = /*#__PURE__*/styled__default.div.withConfig({
1591
1591
  displayName: "Sidebar__SidebarHeader",
1592
1592
  componentId: "SD__sc-b77o22-1"
@@ -1638,28 +1638,172 @@ var Sidebar = /*#__PURE__*/react.forwardRef((_ref, ref) => {
1638
1638
  });
1639
1639
  if (process.env.NODE_ENV !== "production") Sidebar.displayName = "Sidebar";
1640
1640
 
1641
- var SidebarContainerRoot = /*#__PURE__*/styled__default.div.withConfig({
1642
- displayName: "SidebarContainer__SidebarContainerRoot",
1641
+ var Context = /*#__PURE__*/react.createContext(null);
1642
+ function useSidebarContext() {
1643
+ var context = react.useContext(Context);
1644
+
1645
+ if (!context) {
1646
+ throw new Error('SidebarContext is used outside Provider');
1647
+ }
1648
+
1649
+ return context;
1650
+ }
1651
+ var SidebarContainerSidebar = /*#__PURE__*/styled__default.div.withConfig({
1652
+ displayName: "SidebarContainer__SidebarContainerSidebar",
1643
1653
  componentId: "SD__sc-uibj1m-0"
1644
- })(["display:flex;height:inherit;max-height:inherit;min-height:inherit;"]);
1654
+ })(["height:inherit;max-height:inherit;min-height:inherit;width:240px;"]);
1645
1655
  var SidebarContainerContent = /*#__PURE__*/styled__default.div.withConfig({
1646
1656
  displayName: "SidebarContainer__SidebarContainerContent",
1647
1657
  componentId: "SD__sc-uibj1m-1"
1648
- })(["height:inherit;max-height:inherit;min-height:inherit;width:calc(100% - 240px);min-width:calc(100% - 240px);max-width:calc(100% - 240px);"]);
1658
+ })(["height:inherit;max-height:inherit;min-height:inherit;"]);
1659
+ var SidebarContainerRoot = /*#__PURE__*/styled__default.div.withConfig({
1660
+ displayName: "SidebarContainer__SidebarContainerRoot",
1661
+ componentId: "SD__sc-uibj1m-2"
1662
+ })(["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);
1649
1663
  var SidebarContainer = /*#__PURE__*/react.forwardRef((_ref, ref) => {
1650
1664
  var {
1651
1665
  sidebar,
1652
1666
  children
1653
1667
  } = _ref;
1654
- return /*#__PURE__*/jsxRuntime.jsxs(SidebarContainerRoot, {
1655
- ref: ref,
1656
- children: [sidebar, /*#__PURE__*/jsxRuntime.jsx(SidebarContainerContent, {
1657
- children: children
1658
- })]
1668
+ var isCollapsed = ui.useCollapseBreakpoint('sm');
1669
+ var [visibilityState, setVisibilityState] = react.useState('sidebar');
1670
+ var visibility = isCollapsed ? visibilityState : 'both';
1671
+ var context = react.useMemo(() => {
1672
+ return {
1673
+ openSidebar: () => {
1674
+ setVisibilityState('sidebar');
1675
+ },
1676
+ openSidebarContent: () => {
1677
+ setVisibilityState('content');
1678
+ }
1679
+ };
1680
+ }, []);
1681
+ return /*#__PURE__*/jsxRuntime.jsx(Context.Provider, {
1682
+ value: context,
1683
+ children: /*#__PURE__*/jsxRuntime.jsxs(SidebarContainerRoot, {
1684
+ ref: ref,
1685
+ "data-visibility": visibility,
1686
+ children: [/*#__PURE__*/jsxRuntime.jsx(SidebarContainerSidebar, {
1687
+ children: sidebar
1688
+ }), /*#__PURE__*/jsxRuntime.jsx(SidebarContainerContent, {
1689
+ children: children
1690
+ })]
1691
+ })
1659
1692
  });
1660
1693
  });
1661
1694
  if (process.env.NODE_ENV !== "production") SidebarContainer.displayName = "SidebarContainer";
1662
1695
 
1696
+ var _excluded$8 = ["onClick", "children"];
1697
+ function SidebarBackButton(_ref) {
1698
+ var {
1699
+ onClick: _onClick,
1700
+ children = /*#__PURE__*/jsxRuntime.jsx(icons.ArrowBack, {
1701
+ fontSize: "small"
1702
+ })
1703
+ } = _ref,
1704
+ props = _objectWithoutProperties(_ref, _excluded$8);
1705
+
1706
+ var isCollapsed = ui.useCollapseBreakpoint('sm');
1707
+ var {
1708
+ openSidebar
1709
+ } = useSidebarContext();
1710
+
1711
+ if (!isCollapsed) {
1712
+ return null;
1713
+ }
1714
+
1715
+ return /*#__PURE__*/jsxRuntime.jsx(core.IconButton, _objectSpread(_objectSpread({}, props), {}, {
1716
+ size: "small",
1717
+ onClick: event => {
1718
+ _onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
1719
+
1720
+ if (!event.isDefaultPrevented()) {
1721
+ openSidebar();
1722
+ }
1723
+ },
1724
+ children: children
1725
+ }));
1726
+ }
1727
+
1728
+ var SidebarAppBar = /*#__PURE__*/styled__default(core.AppBar).withConfig({
1729
+ displayName: "SidebarContent__SidebarAppBar",
1730
+ componentId: "SD__sc-zpgf61-0"
1731
+ })(_ref => {
1732
+ var {
1733
+ theme
1734
+ } = _ref;
1735
+ return styled.css(["", "{&&{border-left:transparent;}}"], theme.breakpoints.up('sm'));
1736
+ });
1737
+ function SidebarContent(_ref2) {
1738
+ var {
1739
+ dense,
1740
+ action,
1741
+ title,
1742
+ children,
1743
+ onBack,
1744
+ openOnMount,
1745
+ closeOnUnmount
1746
+ } = _ref2;
1747
+ var isOpenedOnMount = react.useRef(false);
1748
+ var isClosedOnMount = react.useRef(false);
1749
+ var {
1750
+ openSidebarContent,
1751
+ openSidebar
1752
+ } = useSidebarContext();
1753
+ react.useLayoutEffect(() => {
1754
+ if (openOnMount) {
1755
+ if (isOpenedOnMount.current) {
1756
+ // eslint-disable-next-line no-console
1757
+ console.warn('[SidebarContent]: "openOnMount" should not change during lifecycle of the component.');
1758
+ } else {
1759
+ isOpenedOnMount.current = true;
1760
+ openSidebarContent();
1761
+ }
1762
+ }
1763
+ }, [openOnMount, openSidebarContent]);
1764
+ react.useLayoutEffect(() => {
1765
+ return () => {
1766
+ if (closeOnUnmount) {
1767
+ if (isClosedOnMount.current) {
1768
+ // eslint-disable-next-line no-console
1769
+ console.warn('[SidebarContent]: "closeOnUnmount" should not change during lifecycle of the component.');
1770
+ } else {
1771
+ isClosedOnMount.current = true;
1772
+ openSidebar();
1773
+ }
1774
+ }
1775
+ };
1776
+ }, [openSidebar, closeOnUnmount]);
1777
+ return /*#__PURE__*/jsxRuntime.jsxs(ui.Stack, {
1778
+ space: "none",
1779
+ children: [/*#__PURE__*/jsxRuntime.jsx(SidebarAppBar, {
1780
+ children: /*#__PURE__*/jsxRuntime.jsx(core.Toolbar, {
1781
+ children: /*#__PURE__*/jsxRuntime.jsxs(ui.Columns, {
1782
+ align: "center",
1783
+ space: "small",
1784
+ children: [/*#__PURE__*/jsxRuntime.jsx(ui.Column, {
1785
+ width: "content",
1786
+ children: /*#__PURE__*/jsxRuntime.jsx(SidebarBackButton, {
1787
+ onClick: onBack
1788
+ })
1789
+ }), /*#__PURE__*/jsxRuntime.jsx(ui.Column, {
1790
+ children: /*#__PURE__*/jsxRuntime.jsx(TextBox, {
1791
+ variant: "heading-2",
1792
+ children: title
1793
+ })
1794
+ }), /*#__PURE__*/jsxRuntime.jsx(ui.Column, {
1795
+ width: "content",
1796
+ children: action
1797
+ })]
1798
+ })
1799
+ })
1800
+ }), /*#__PURE__*/jsxRuntime.jsx(Box, {
1801
+ padding: dense ? 'none' : 'medium',
1802
+ children: children
1803
+ })]
1804
+ });
1805
+ }
1806
+
1663
1807
  var SidebarDividerRoot = /*#__PURE__*/styled__default.div.withConfig({
1664
1808
  displayName: "SidebarDivider__SidebarDividerRoot",
1665
1809
  componentId: "SD__sc-5lwi2i-0"
@@ -1714,17 +1858,21 @@ var SidebarMenuItem = /*#__PURE__*/react.forwardRef((_ref2, ref) => {
1714
1858
  var {
1715
1859
  action,
1716
1860
  avatar,
1717
- onClick,
1861
+ onClick: _onClick,
1718
1862
  external,
1719
1863
  children,
1720
1864
  disabled,
1721
1865
  selected,
1722
1866
  secondaryActions,
1723
- badge: badgeProp
1867
+ badge: badgeProp,
1868
+ openContentOnClick
1724
1869
  } = _ref2;
1725
1870
  var [hovered, setHovered] = react.useState(false);
1726
1871
  var actionsRef = react.useRef(null);
1727
1872
  var actionsPlaceholderRef = react.useRef(null);
1873
+ var {
1874
+ openSidebarContent
1875
+ } = useSidebarContext();
1728
1876
  react.useLayoutEffect(() => {
1729
1877
  if (actionsRef.current && actionsPlaceholderRef.current) {
1730
1878
  actionsPlaceholderRef.current.style.width = "".concat(Math.max(0, actionsRef.current.offsetWidth - 8), "px");
@@ -1741,9 +1889,15 @@ var SidebarMenuItem = /*#__PURE__*/react.forwardRef((_ref2, ref) => {
1741
1889
  setHovered(false);
1742
1890
  },
1743
1891
  children: [/*#__PURE__*/jsxRuntime.jsx(core.ButtonBase, {
1744
- onClick: onClick,
1745
1892
  disabled: disabled,
1746
1893
  "aria-current": selected,
1894
+ onClick: event => {
1895
+ _onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
1896
+
1897
+ if (!event.isDefaultPrevented() && openContentOnClick) {
1898
+ openSidebarContent();
1899
+ }
1900
+ },
1747
1901
  children: /*#__PURE__*/jsxRuntime.jsxs(ui.Columns, {
1748
1902
  align: "center",
1749
1903
  space: "xsmall",
@@ -1856,6 +2010,7 @@ var SidebarMenuItemAvatar = /*#__PURE__*/react.forwardRef((_ref, ref) => {
1856
2010
  color: "primary",
1857
2011
  checked: value,
1858
2012
  disabled: disabled,
2013
+ onClick: stopPropagation,
1859
2014
  onMouseDown: stopPropagation,
1860
2015
  onTouchStart: stopPropagation,
1861
2016
  onChange: (_, checked) => {
@@ -1927,7 +2082,9 @@ exports.NavbarList = NavbarList;
1927
2082
  exports.NavbarMenu = NavbarMenu;
1928
2083
  exports.NavbarMenuItem = NavbarMenuItem;
1929
2084
  exports.Sidebar = Sidebar;
2085
+ exports.SidebarBackButton = SidebarBackButton;
1930
2086
  exports.SidebarContainer = SidebarContainer;
2087
+ exports.SidebarContent = SidebarContent;
1931
2088
  exports.SidebarDivider = SidebarDivider;
1932
2089
  exports.SidebarMenuItem = SidebarMenuItem;
1933
2090
  exports.SidebarMenuItemAction = SidebarMenuItemAction;
@@ -1937,4 +2094,5 @@ exports.TextBox = TextBox;
1937
2094
  exports.formatBytes = formatBytes;
1938
2095
  exports.toBytes = toBytes;
1939
2096
  exports.useNavbarContext = useNavbarContext;
2097
+ exports.useSidebarContext = useSidebarContext;
1940
2098
  //# sourceMappingURL=index.js.map