@vrobots/storybook 0.1.18 → 0.1.20

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vrobots/storybook",
3
3
  "private": false,
4
- "version": "0.1.18",
4
+ "version": "0.1.20",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -4,7 +4,7 @@ import { Box, IconButton } from "@chakra-ui/react";
4
4
  import { useColorMode } from "./ui/color-mode";
5
5
  import { LuMenu } from "react-icons/lu";
6
6
  import { motion } from "motion/react";
7
- import { useBreakpoint } from "../hooks";
7
+ import { useBreakpoint, useIsMobile } from "../hooks";
8
8
  import { COLOR_GRAY_200, COLOR_GRAY_800 } from "../constants";
9
9
  export const SidebarContext = React.createContext({});
10
10
  export const SidebarProvider = (props) => {
@@ -25,15 +25,11 @@ export const SidebarToggleButton = (props) => {
25
25
  return (_jsx(IconButton, { onClick: toggleSidebar, position: 'absolute', bottom: 2, right: 2, zIndex: 3, variant: 'ghost', ...props, children: _jsx(LuMenu, {}) }));
26
26
  };
27
27
  export const Sidebar = forwardRef((props, ref) => {
28
- const [shouldAnimate, setShouldAnimate] = React.useState(false);
28
+ const [isFirstTimeOpen, setIsFirstTimeOpen] = React.useState(true);
29
29
  const sidebar = useSidebar();
30
30
  const { colorMode } = useColorMode();
31
31
  const breakpoint = useBreakpoint();
32
- React.useEffect(() => {
33
- if (!shouldAnimate && sidebar.isOpen) {
34
- setShouldAnimate(true);
35
- }
36
- }, [sidebar.isOpen, shouldAnimate]);
32
+ const isMobile = useIsMobile();
37
33
  const width = {
38
34
  base: '100vw',
39
35
  sm: '100vw',
@@ -52,9 +48,11 @@ export const Sidebar = forwardRef((props, ref) => {
52
48
  animate: { width: '0' },
53
49
  transition: { duration: 0.2 }
54
50
  };
55
- const action = shouldAnimate ? sidebar.isOpen ? open : close : {};
51
+ const action = isMobile ? sidebar.isOpen ? open : close : {};
56
52
  const borderColor = colorMode === 'light' ? COLOR_GRAY_200 : COLOR_GRAY_800;
57
- return (_jsx(SidebarContext.Provider, { value: sidebar, children: _jsx(motion.div, { style: {
53
+ if (!sidebar.menu)
54
+ return null;
55
+ return (_jsx(React.Fragment, { children: _jsx(motion.div, { style: {
58
56
  position: 'relative',
59
57
  display: 'flex',
60
58
  flexDirection: 'column',
@@ -62,7 +60,7 @@ export const Sidebar = forwardRef((props, ref) => {
62
60
  zIndex: 1,
63
61
  overflow: 'hidden',
64
62
  height: 'inherit',
65
- width: 0,
63
+ width: sidebar.isOpen ? width[breakpoint || 'base'] : '0',
66
64
  borderRight: `1px solid ${borderColor}`,
67
65
  }, ...action, ref: ref, children: _jsx(Box, { width: width[breakpoint || 'base'], children: sidebar.menu }) }) }));
68
66
  });
@@ -1,9 +1,9 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import packageJson from '../../package.json';
3
3
  import { Frame } from '../components/Frame';
4
4
  import { Heading } from '@chakra-ui/react';
5
5
  import { Menu } from '../components/Menu';
6
- import { SidebarProvider, SidebarToggleButton } from '../components/Sidebar';
6
+ import { SidebarProvider } from '../components/Sidebar';
7
7
  import { SIDEBAR_MENU } from './Sidebar.stories';
8
8
  import { Page } from '../components/Page';
9
9
  import { EXAMPLE_BREADCRUMBS } from './Breadcrumbs.stories';
@@ -39,7 +39,7 @@ export const Component = {
39
39
  (Story) => {
40
40
  const isMobile = useIsMobile();
41
41
  const isSidebarOpen = !isMobile;
42
- return (_jsx(HeaderProvider, { appName: 'My Application', logo: logo, menu: menu, version: packageJson.version, children: _jsxs(SidebarProvider, { isOpen: isSidebarOpen, menu: _jsx(Menu, { label: 'Sidebar Menu', menuItems: SIDEBAR_MENU }), children: [_jsx(Story, {}), isMobile && _jsx(SidebarToggleButton, { name: 'sidebar-toggle', "aria-label": 'Toggle sidebar' })] }) }));
42
+ return (_jsx(HeaderProvider, { appName: 'My Application', logo: logo, menu: menu, version: packageJson.version, children: _jsx(SidebarProvider, { isOpen: isSidebarOpen, menu: _jsx(Menu, { label: 'Sidebar Menu', menuItems: SIDEBAR_MENU }), children: _jsx(Story, {}) }) }));
43
43
  },
44
44
  ],
45
45
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vrobots/storybook",
3
3
  "private": false,
4
- "version": "0.1.18",
4
+ "version": "0.1.20",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",