@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
291 lines (283 loc) • 9.9 kB
JavaScript
import React from 'react';
import { Header_defaultProps, Footer_defaultProps, Drawer_defaultProps } from "./props/defaultProps";
import { Header_propTypes, Content_propTypes, Footer_propTypes, Drawer_propTypes } from "./props/propTypes";
import FreezeLayer from "../FreezeLayer/FreezeLayer";
import { Container, Box } from '@zohodesk/components/lib/Layout';
import { Card, CardHeader, CardContent } from '@zohodesk/components/lib/Card';
import FormAction from "../FormAction/FormAction";
import VelocityAnimationGroup from '@zohodesk/components/lib/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup';
import { ResponsiveSender, ResponsiveReceiver } from '@zohodesk/components/lib/Responsive/CustomResponsive';
import Heading from '@zohodesk/components/lib/Heading/Heading';
import IconButton from "../IconButton/IconButton";
import { Icon } from '@zohodesk/icons';
import { getZIndex } from '@zohodesk/components/lib/Provider/ZindexProvider';
import style from "./Drawer.module.css";
import FocusScope from '@zohodesk/a11y/es/FocusScope/FocusScope';
export class Header extends React.Component {
render() {
let {
title,
onClose,
children,
className,
paddingSize,
closeTitle,
iconName,
iconSize,
onIconClick,
isIconBold,
dataId,
flexible,
getChildren,
iconTitle,
isBoxIcon,
getTitleChildren
} = this.props;
return /*#__PURE__*/React.createElement(CardHeader, {
customClass: `${style.header} ${style[`${paddingSize}HeaderPadding`]} ${className ? className : ''}`,
dataId: dataId
}, /*#__PURE__*/React.createElement(Container, {
alignBox: "row",
align: "vertical",
isCover: false,
className: style.subheader
}, /*#__PURE__*/React.createElement(Box, {
flexible: true,
shrink: true
}, /*#__PURE__*/React.createElement(Container, {
alignBox: "row",
isCover: false,
align: "vertical"
}, iconName ? /*#__PURE__*/React.createElement(Box, {
className: style.iconWrapper
}, isBoxIcon ? /*#__PURE__*/React.createElement(IconButton, {
iconName: iconName,
iconSize: iconSize,
onClick: onIconClick,
hoverType: "border",
isBold: isIconBold,
title: iconTitle
}) : /*#__PURE__*/React.createElement(Icon, {
name: iconName,
size: iconSize,
onClick: onIconClick,
title: iconTitle
})) : null, title || getTitleChildren ? /*#__PURE__*/React.createElement(Box, {
flexible: flexible,
shrink: true
}, /*#__PURE__*/React.createElement(Container, {
alignBox: "row",
align: "vertical"
}, title ? /*#__PURE__*/React.createElement(Box, {
"data-title": title,
shrink: true
}, /*#__PURE__*/React.createElement(Heading, {
title: title,
className: style.title
})) : null, getTitleChildren ? /*#__PURE__*/React.createElement(Box, null, getTitleChildren()) : null)) : null, children ? /*#__PURE__*/React.createElement(Box, null, children) : null)), onClose ? /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(IconButton, {
onClick: onClose,
dataId: "closeButton",
title: closeTitle,
iconName: "ZD-cross",
iconSize: "11",
a11y: {
ariaLabel: 'Close'
}
})) : null), getChildren ? /*#__PURE__*/React.createElement(Container, {
isCover: false
}, /*#__PURE__*/React.createElement(Box, {
flexible: true
}, getChildren())) : null);
}
}
Header.propTypes = Header_propTypes;
Header.defaultProps = Header_defaultProps;
export class Content extends React.Component {
render() {
let {
children,
className,
paddingSize,
eleRef
} = this.props;
return /*#__PURE__*/React.createElement(CardContent, {
scroll: "vertical",
isScrollAttribute: true,
customClass: `${className ? className : ''} ${paddingSize ? style[`${paddingSize}ContentPadding`] : ''}`,
eleRef: eleRef
}, children);
}
}
Content.propTypes = Content_propTypes;
export class Footer extends React.Component {
render() {
let {
paddingLeftSize,
paddingRightClass,
children,
size
} = this.props;
return /*#__PURE__*/React.createElement(FormAction, {
size: size,
paddingLeftSize: paddingLeftSize,
paddingRightClass: paddingRightClass
}, children);
}
}
Footer.propTypes = Footer_propTypes;
Footer.defaultProps = Footer_defaultProps;
export default class Drawer extends React.Component {
constructor(props) {
super(props);
this.drawers = this.drawers.bind(this);
this.responsiveFunc = this.responsiveFunc.bind(this);
this.getNextIndex = getZIndex(this);
this.createRef = /*#__PURE__*/React.createRef();
}
drawers(uptoTablet, styleByResolutions) {
let {
children,
size,
paddingSize,
subDrawerActive,
subDrawerChildren,
onBodyClick,
onClose,
needFocusScope,
customProps,
a11y,
customDrawerClass
} = this.props;
const {
focusScopeProps = {}
} = customProps;
const {
needAutoFocus = true,
needRestoreFocus = true,
needListNavigation = false,
needFocusLoop = true,
needEnterAction = true
} = focusScopeProps;
let childrenWithProps = React.Children.map(children, child => {
if (child.type === Header || child.type === Footer || child.type === Content) {
let {
paddingSize: childPaddingSize
} = child.props || {};
return paddingSize || childPaddingSize ? /*#__PURE__*/React.cloneElement(child, {
paddingSize: childPaddingSize ? childPaddingSize : paddingSize
}) : child;
}
return child;
});
let content = /*#__PURE__*/React.createElement(Box, {
className: `${style.container} ${style.columns} ${style.drawerModal} ${uptoTablet ? style.mbleSize : style[size]} ${customDrawerClass}`,
"data-a11y-need-focus-style": "false",
tabindex: -1,
eleRef: this.createRef,
...a11y
}, /*#__PURE__*/React.createElement(Card, {
onClick: e => {
e && e.stopPropagation && e.stopPropagation();
onBodyClick(e);
}
}, childrenWithProps));
return /*#__PURE__*/React.createElement(React.Fragment, null, subDrawerChildren ? /*#__PURE__*/React.createElement(Box, {
className: style.columns
}, /*#__PURE__*/React.createElement(VelocityAnimationGroup, {
name: "slideRight",
isActive: subDrawerActive
}, /*#__PURE__*/React.createElement(ResponsiveSender, null, /*#__PURE__*/React.createElement(Container, {
className: styleByResolutions,
onClick: e => {
e && e.stopPropagation && e.stopPropagation();
}
}, /*#__PURE__*/React.createElement(Box, {
flexible: true
}, subDrawerChildren))))) : null, needFocusScope ? /*#__PURE__*/React.createElement(FocusScope, {
elementRef: this.createRef,
needAutoFocus: needAutoFocus,
needFocusLoop: needFocusLoop,
needRestoreFocus: needRestoreFocus,
needListNavigation: needListNavigation,
onClose: onClose,
needEnterAction: needEnterAction
}, content) : content);
}
responsiveFunc(_ref) {
let {
mediaQueryOR
} = _ref;
return {
uptoTablet: mediaQueryOR([{
maxWidth: 768
}])
};
}
render() {
let {
needFreeze,
palette,
isActive,
onClose,
forwardRef,
responsiveId,
subDrawerSize,
subDrawerClass,
subDrawerActive,
customClass,
needAutoZindex,
innerPortalName,
onAnimateEnter,
postAnimateStyles,
onAnimateExit
} = this.props;
let zindexNumber = isActive ? this.getNextIndex() : '';
return /*#__PURE__*/React.createElement(ResponsiveReceiver, {
query: this.responsiveFunc,
responsiveId: responsiveId
}, _ref2 => {
let {
uptoTablet
} = _ref2;
let styleByResolutions = `${subDrawerClass} ${style.secondDrawer} ${uptoTablet ? `${style.secondMobDrawer} ${style.mbleSize}` : `${style[subDrawerSize]}`} `;
return needFreeze ? /*#__PURE__*/React.createElement(FreezeLayer, {
onClick: onClose,
isActive: isActive,
animationName: "fade",
childAnimationName: "slideRight",
palette: palette,
forwardRef: forwardRef,
customClass: customClass,
needAutoZindex: needAutoZindex,
onAnimateEnter: onAnimateEnter,
postAnimateStyles: postAnimateStyles,
onAnimateExit: onAnimateExit
}, /*#__PURE__*/React.createElement(Box, {
flexible: true
}, /*#__PURE__*/React.createElement(Container, {
alignBox: "row"
}, /*#__PURE__*/React.createElement(React.Fragment, null, uptoTablet ? /*#__PURE__*/React.createElement(Box, {
flexible: true
}) : null, /*#__PURE__*/React.createElement(ResponsiveSender, null, /*#__PURE__*/React.createElement(Box, {
flexible: true,
className: uptoTablet ? style.mobModal : style.drawerModal
}, !subDrawerActive && innerPortalName ? /*#__PURE__*/React.createElement("div", {
"data-portal": innerPortalName
}) : null)), this.drawers(uptoTablet, styleByResolutions))))) : /*#__PURE__*/React.createElement(VelocityAnimationGroup, {
isActive: isActive,
name: "slideRight"
}, /*#__PURE__*/React.createElement(Container, {
align: "right",
alignBox: "row",
scroll: "none",
eleRef: forwardRef,
className: `${style.isOverlay} ${customClass}`,
style: needAutoZindex ? {
zIndex: `${zindexNumber}`
} : {}
}, this.drawers(uptoTablet, styleByResolutions)));
});
}
}
Drawer.propTypes = Drawer_propTypes;
Drawer.defaultProps = Drawer_defaultProps;