UNPKG

4.02 kBJavaScriptView Raw
1import { oneOf, bool, oneOfType, func, node, string } from 'prop-types';
2import { animatePropTypes, restrictHidePropTypes, animateDefaultProps, restrictDefaultProps } from './types/props.js';
3import { a as _objectSpread, c as _objectWithoutPropertiesLoose, g as _extends } from './chunk-1f79df9b.js';
4import Box from 'reakit/Box';
5import 'reakit/Block';
6import 'reakit/Inline';
7import 'reakit/InlineBlock';
8import 'reakit/Flex';
9import 'reakit/InlineFlex';
10import 'reakit/Grid';
11import { createElement, Fragment } from 'react';
12import Portal from './Portal/index.js';
13import Backdrop from './Backdrop/index.js';
14import { a as isFunction } from './chunk-5c9bbccf.js';
15import { a as TrapFocus } from './chunk-df6ef69d.js';
16import SidebarContainer from './Sidebar/SidebarContainer.js';
17import _Sidebar from './Sidebar/styled.js';
18import SidebarClose from './Sidebar/SidebarClose.js';
19import SidebarHide from './Sidebar/SidebarHide.js';
20import SidebarShow from './Sidebar/SidebarShow.js';
21
22var Sidebar = function Sidebar(_ref) {
23 var align = _ref.align,
24 backdropFade = _ref.backdropFade,
25 children = _ref.children,
26 delay = _ref.delay,
27 duration = _ref.duration,
28 fade = _ref.fade,
29 hide = _ref.hide,
30 hideCloseButton = _ref.hideCloseButton,
31 hideOnEsc = _ref.hideOnEsc,
32 hideOnClickOutside = _ref.hideOnClickOutside,
33 isVisible = _ref.isVisible,
34 onClickClose = _ref.onClickClose,
35 slide = _ref.slide,
36 width = _ref.width,
37 props = _objectWithoutPropertiesLoose(_ref, ["align", "backdropFade", "children", "delay", "duration", "fade", "hide", "hideCloseButton", "hideOnEsc", "hideOnClickOutside", "isVisible", "onClickClose", "slide", "width"]);
38
39 return createElement(Portal, null, createElement(TrapFocus, {
40 delayToActivate: fade || slide ? duration : undefined,
41 isActive: isVisible,
42 usesPortal: true
43 }, function (_ref2) {
44 var fallbackFocusRef = _ref2.fallbackFocusRef,
45 initialFocusRef = _ref2.initialFocusRef;
46 return createElement(Fragment, null, createElement(Backdrop, {
47 delay: delay,
48 duration: duration,
49 hide: hide,
50 fade: backdropFade,
51 hideOnEsc: hideOnEsc,
52 isVisible: isVisible,
53 use: hideOnClickOutside ? SidebarHide : undefined,
54 expand: undefined,
55 slide: undefined
56 }), createElement(Box, {
57 elementRef: fallbackFocusRef
58 }, createElement(_Sidebar, _extends({
59 "aria-modal": "true",
60 align: align,
61 delay: delay,
62 duration: duration,
63 fade: fade,
64 hideOnEsc: hideOnEsc,
65 hideOnClickOutside: hideOnClickOutside,
66 slide: slide,
67 width: width
68 }, props, {
69 // @ts-ignore
70 visible: isVisible || props.visible
71 }), !hideCloseButton && // @ts-ignore
72 createElement(SidebarClose, {
73 use: SidebarHide,
74 elementRef: initialFocusRef,
75 hide: hide,
76 onClick: onClickClose,
77 palette: "white",
78 sidebarAlign: align,
79 sidebarWidth: width
80 }), isFunction(children) ? children({
81 initialFocusRef: initialFocusRef
82 }) : children)));
83 }));
84};
85var sidebarPropTypes = _objectSpread({
86 align: oneOf(['left', 'right']),
87 backdropFade: bool,
88 children: oneOfType([func, node]),
89 className: string,
90 isVisible: bool,
91 hide: func,
92 hideCloseButton: bool,
93 onClickClose: func,
94 width: string
95}, animatePropTypes, restrictHidePropTypes);
96Sidebar.propTypes = sidebarPropTypes;
97var sidebarDefaultProps = _objectSpread({}, animateDefaultProps, restrictDefaultProps, {
98 align: 'left',
99 backdropFade: true,
100 className: undefined,
101 duration: '0.2s',
102 hideCloseButton: false,
103 hideOnClickOutside: true,
104 hideOnEsc: true,
105 isVisible: false,
106 onClickClose: undefined,
107 slide: true,
108 width: '250px'
109});
110Sidebar.defaultProps = sidebarDefaultProps;
111Sidebar.Container = SidebarContainer;
112Sidebar.Close = SidebarClose;
113Sidebar.Hide = SidebarHide;
114Sidebar.Show = SidebarShow;
115var C = Sidebar;
116
117export { C as a, sidebarPropTypes as b, sidebarDefaultProps as c };