@lote-design-system/marketing-blocks
Version:
569 lines (497 loc) • 21.2 kB
JavaScript
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.NavBar2 = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _polished = require("polished");
var _svg = require("../svg");
var _icons = require("@lote-design-system/icons");
var _core = require("@lote-design-system/core");
// => Dependent styled-components
// Our main component depends upon the following styled-components
var NavBar = _styledComponents["default"].nav.withConfig({
displayName: "NavBar2__NavBar",
componentId: "fv1p0z-0"
})(["padding:", " 0;", ";", ";", ";"], (0, _polished.rem)(16), function (_ref) {
var fixed = _ref.fixed;
if (fixed === 'top') {
return (0, _styledComponents.css)(["position:fixed;top:0;right:0;left:0;z-index:1030;"]);
} else if (fixed === 'bottom') {
return (0, _styledComponents.css)(["position:fixed;right:0;bottom:0;left:0;z-index:1030;"]);
} else {
return (0, _styledComponents.css)([""]);
}
}, function (_ref2) {
var sticky = _ref2.sticky;
if (sticky) {
return (0, _styledComponents.css)(["@supports ((position:-webkit-sticky) or (position:sticky)){position:sticky;top:0;z-index:1020;}"]);
} else {
return (0, _styledComponents.css)([""]);
}
}, function (_ref3) {
var styled = _ref3.styled;
if (styled) {
return (0, _styledComponents.css)(["&{", ";}"], styled);
}
}); // This container is very important component for the Nav aligning
var ContainerModify = (0, _styledComponents["default"])(_core.Container).withConfig({
displayName: "NavBar2__ContainerModify",
componentId: "fv1p0z-1"
})(["position:relative;display:flex;flex-wrap:wrap;align-items:center;", " justify-content:space-between;max-width:", ";"], ''
/* Remember this is a very important property if you remove it your NavBarStart, NavBarEnd and BurgerButton
will not display left of even right side of the bar. */
, function (_ref4) {
var theme = _ref4.theme;
return theme.maxContainerWidth;
});
var NavBarBrand = _styledComponents["default"].a.withConfig({
displayName: "NavBar2__NavBarBrand",
componentId: "fv1p0z-2"
})(["display:inline-flex;align-items:center;padding:", " 0;white-space:nowrap;margin-right:", ";> svg,> img{width:56px;height:56px;}}}"], (0, _polished.rem)(4), (0, _polished.rem)(64));
var NavBarButtonToggler = (0, _styledComponents["default"])(_core.Button).withConfig({
displayName: "NavBar2__NavBarButtonToggler",
componentId: "fv1p0z-3"
})(["width:48px;height:48px;padding:", " ", ";display:inline-flex;justify-content:center;align-items:center;", "{display:none;}"], (0, _polished.rem)(4), (0, _polished.rem)(12), function (_ref5) {
var theme = _ref5.theme;
return theme.mediaQueries.lg;
});
var navbarOverlayOpacity = (0, _styledComponents.keyframes)(["0%{opacity:0;}100%{opacity:1;}"]);
var NavBarPlate = _styledComponents["default"].div.withConfig({
displayName: "NavBar2__NavBarPlate",
componentId: "fv1p0z-4"
})(["", " display:none;", " ", "{display:flex;align-items:center;flex-grow:1;}@media (max-width:991px){display:block;position:fixed;z-index:", ";width:0;height:100%;transition:transform 0.4s linear,height 0s ease 0.4s,width 0s ease 0.4s;top:0;", " ", "}"], ''
/* Default NavBarPlate will be disabled on Mobile devices. */
, ''
/* NavBarPlate will be enabled on Desktop devices. */
, function (_ref6) {
var theme = _ref6.theme;
return theme.mediaQueries.lg;
}, function (_ref7) {
var zIndex = _ref7.zIndex;
return zIndex;
}, function (props) {
if (props.placement === 'left') {
return {
left: 0
};
} else if (props.placement === 'right') {
return {
right: 0
};
}
}, function (props) {
return props.visible && (0, _styledComponents.css)(["width:100%;transition:transform 0.4s linear;", "{height:100%;opacity:1;transition:none;animation:", " 0.4s linear;}", "{visibility:visible;", "}"], NavBarOverlay, navbarOverlayOpacity, NavBarMenu, function (props) {
if (props.placement === 'left') {
return {
transform: 'translateX(100%)'
};
} else if (props.placement === 'right') {
return {
transform: 'translateX(-100%)'
};
}
});
});
var NavBarOverlay = _styledComponents["default"].div.withConfig({
displayName: "NavBar2__NavBarOverlay",
componentId: "fv1p0z-5"
})(["@media (max-width:991px){position:fixed;top:0;left:0;width:100%;height:0;opacity:0;transition:opacity 0.4s linear,height 0s ease 0.4s;background-color:rgba(0,0,0,0.7);}"]); // NavBarMenu is important component because all placement of links depend upon this.
var NavBarMenu = _styledComponents["default"].div.withConfig({
displayName: "NavBar2__NavBarMenu",
componentId: "fv1p0z-6"
})(["", " ", "{display:flex;align-items:center;flex-grow:1;}@media (max-width:991px){", ";position:fixed;", ";height:100%;background-color:#ffffff;overflow-y:auto;visibility:hidden;transition:transform 0.2s linear,visibility 0.2s linear;}"], ''
/* Styling for the NavBarMenu will be disabled on Desktop devices. */
, function (_ref8) {
var theme = _ref8.theme;
return theme.mediaQueries.lg;
}, function (_ref9) {
var theme = _ref9.theme,
placement = _ref9.placement;
if (placement === 'left') {
return {
boxShadow: theme.shadowSide.right,
right: '100%'
};
} else if (placement === 'right') {
return {
boxShadow: theme.shadowSide.left,
left: '100%'
};
}
}, function (_ref10) {
var w = _ref10.w;
if (typeof w === 'number') {
return (0, _styledComponents.css)(["width:", "px;"], w);
} else if (typeof w === 'string') {
return (0, _styledComponents.css)(["width:", ";"], w);
} else {
return (0, _styledComponents.css)(["width:", "px;"], w);
}
});
var NavBarHeader = _styledComponents["default"].div.withConfig({
displayName: "NavBar2__NavBarHeader",
componentId: "fv1p0z-7"
})(["display:none;@media (max-width:991px){display:flex;flex-wrap:wrap;align-items:center;border-bottom:1px solid #f8f8f8;", ""], function (_ref11) {
var hasTitle = _ref11.hasTitle,
hasClosable = _ref11.hasClosable;
if (hasTitle && hasClosable) {
return (0, _styledComponents.css)(["justify-content:space-between;padding:", " ", ";"], (0, _polished.rem)(8), (0, _polished.rem)(18));
} else if (hasTitle && !hasClosable) {
return (0, _styledComponents.css)(["padding:", ";"], (0, _polished.rem)(18));
} else if (!hasTitle && hasClosable) {
return (0, _styledComponents.css)(["justify-content:flex-end;padding:", " ", ";"], (0, _polished.rem)(8), (0, _polished.rem)(18));
}
});
var NavBarText = _styledComponents["default"].span.withConfig({
displayName: "NavBar2__NavBarText",
componentId: "fv1p0z-8"
})(["font-size:", ";font-weight:500;color:", ";"], (0, _polished.rem)(16), function (_ref12) {
var colors = _ref12.theme.colors;
return colors.text.title;
});
var NavBarCloseButton = (0, _styledComponents["default"])(_core.Button).withConfig({
displayName: "NavBar2__NavBarCloseButton",
componentId: "fv1p0z-9"
})(["width:46px;height:46px;padding:", ";font-size:", ";"], (0, _polished.rem)(4), (0, _polished.rem)(18)); // NavBarStart Section i.e. unordered list display on the left side
// =================================================================
// Anchor
var NavBarStartLink = _styledComponents["default"].a.withConfig({
displayName: "NavBar2__NavBarStartLink",
componentId: "fv1p0z-10"
})(["font-size:", ";color:", ";display:block;font-weight:500;padding:", " ", ";transition:color 0.4s linear;&:hover{color:", ";}"], (0, _polished.rem)(14), function (_ref13) {
var colors = _ref13.theme.colors;
return colors.text.primary;
}, (0, _polished.rem)(8), (0, _polished.rem)(16), function (_ref14) {
var colors = _ref14.theme.colors;
return colors.primary;
}); // ListItem
var NavBarStartItem = _styledComponents["default"].li.withConfig({
displayName: "NavBar2__NavBarStartItem",
componentId: "fv1p0z-11"
})(["", ";"], function (props) {
return props.active && (0, _styledComponents.css)(["> ", "{color:", ";}"], NavBarStartLink, function (_ref15) {
var colors = _ref15.theme.colors;
return colors.primary;
});
}); // Unordered List
var NavBarStart = _styledComponents["default"].ul.withConfig({
displayName: "NavBar2__NavBarStart",
componentId: "fv1p0z-12"
})(["", " ", " padding:", ";margin-bottom:0;list-style:none;", "{display:flex;align-items:center;padding:0;margin-right:auto;}"], ''
/* These styles will appear on both Desktop & Mobile devices. */
, ''
/* But the bottom padding property will be only applied on Mobile Devices.
Basically, It will add the padding on the list container. */
, (0, _polished.rem)(14), function (_ref16) {
var theme = _ref16.theme;
return theme.mediaQueries.lg;
}); // End =================================
// NavBarEnd Section i.e. unordered list display on the right side
// =================================================================
// Unordered List
var NavBarEnd = _styledComponents["default"].div.withConfig({
displayName: "NavBar2__NavBarEnd",
componentId: "fv1p0z-13"
})(["", " ", " padding:", ";", "{display:flex;align-items:center;padding:0;margin-left:auto;}"], ''
/* These styles will appear on both Desktop & Mobile devices. */
, ''
/* But the bottom padding property will only apply on the Mobile Devices.
Basically, It will add the padding on the list container. */
, (0, _polished.rem)(14), function (_ref17) {
var theme = _ref17.theme;
return theme.mediaQueries.lg;
}); // Button
var NavBarEndLinkButton = (0, _styledComponents["default"])(_core.Button).withConfig({
displayName: "NavBar2__NavBarEndLinkButton",
componentId: "fv1p0z-14"
})(["font-weight:500;margin:", ";@media (max-width:991px){display:block;}"], (0, _polished.rem)(8)); // End =================================
// <= End Dependent styled-components
var leftLinkShape = {
id: _propTypes["default"].number.isRequired,
href: _propTypes["default"].string.isRequired,
text: _propTypes["default"].string.isRequired,
active: _propTypes["default"].bool
};
var variationShape = {
drawerVariation: _propTypes["default"].string.isRequired,
normal: _propTypes["default"].string.isRequired
};
var rightLinkShape = {
id: _propTypes["default"].number.isRequired,
href: _propTypes["default"].string.isRequired,
text: _propTypes["default"].string.isRequired,
variation: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].shape(variationShape)]).isRequired,
color: _propTypes["default"].string
};
var leftLinkSchema = [{
id: 1,
href: '/',
text: 'Home',
active: true
}, {
id: 2,
href: '/',
text: 'Features'
}, {
id: 3,
href: '/',
text: 'Pricing'
}, {
id: 4,
href: '/',
text: 'Services'
}, {
id: 5,
href: '/',
text: 'About Us'
}];
var rightLinkSchema = [{
id: 1,
href: '/',
text: 'Login',
variation: {
drawerVariation: 'light',
normal: 'transparent'
},
color: 'primary'
}, {
id: 2,
href: '/',
text: 'Get Started',
variation: 'fill',
color: 'primary'
}];
var propTypes = {
/** Render new styles on the NavBar Container. */
styledCSS: _propTypes["default"].string,
/** Position an element at the top/bottom of the viewport, from edge to edge. Fixed NavBars use
position: fixed, meaning they’re pulled from the normal flow of the DOM and may require
custom CSS (e.g., padding-top on the <body>) to prevent overlap with other elements. */
fixed: _propTypes["default"].oneOf(['top', 'bottom']),
/** Position an element at the top of the viewport, from edge to edge, but only after you scroll past it. */
sticky: _propTypes["default"].bool,
/** Whether a close (X) button is visible on top right of the Drawer dialog or not. */
closable: _propTypes["default"].bool,
/** Whether to show mask or not. */
mask: _propTypes["default"].bool,
/** Clicking on the mask (area outside the Drawer) to close the Drawer or not. */
maskClosable: _propTypes["default"].bool,
/** The title of the Drawer. */
title: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].node]),
/** Width of the Drawer dialog. */
width: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
/** The z-index of the Drawer. */
zIndex: _propTypes["default"].number,
/** The placement of the Drawer. */
placement: _propTypes["default"].oneOf(['right', 'left']),
/** The logo appear on the NavBar, default it will be ui-kit logo. */
logo: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].node]),
/** Links appear on the left side of the NavBar, same links also render on the Drawer. */
leftLinks: _propTypes["default"].arrayOf(_propTypes["default"].shape(leftLinkShape)).isRequired,
/** Links appear on the right side of the NavBar, same links also render on the Drawer. */
rightLinks: _propTypes["default"].arrayOf(_propTypes["default"].shape(rightLinkShape)).isRequired
};
var defaultProps = {
closable: true,
mask: true,
maskClosable: true,
width: 256,
zIndex: 1000,
placement: 'right',
logo: /*#__PURE__*/_react["default"].createElement(_svg.LogoDefault, {
fill: "#01a1ff"
}),
leftLinks: leftLinkSchema,
rightLinks: rightLinkSchema
};
/**
* Returns the JSX or null for the logo.
* @param logo {*} - The logo will React.element or a path
* @return {null|*} - Returns the JSX or null
*/
var renderLogo = function renderLogo(logo) {
if (_react["default"].isValidElement(logo)) {
return logo;
} else if (typeof logo === 'string' && logo.length > 0) {
return /*#__PURE__*/_react["default"].createElement("img", {
src: logo,
alt: "Brand Logo"
});
} else {
return null;
}
};
/**
* Render overlay mask on the back of the Drawer.
* @param state {boolean} - Updated value of the state
* @param mask {boolean} - Whether to show mask or not
* @param maskClosable {boolean} - Clicking on the mask to close the Drawer or not
* @param onClose {function} - A function that will be called when a user clicks mask
* @return {null|*} - Returns the JSX or null
*/
var renderMask = function renderMask(state, mask, maskClosable, onClose) {
if (mask) {
if (state) {
document.body.style.position = 'relative';
document.body.style.overflow = 'hidden';
document.body.style.width = "calc(".concat(100, "% - ", 17, "px)");
} else {
document.body.style.position = '';
document.body.style.overflow = '';
document.body.style.width = '';
}
if (maskClosable) {
return /*#__PURE__*/_react["default"].createElement(NavBarOverlay, {
onClick: onClose
});
} else {
return /*#__PURE__*/_react["default"].createElement(NavBarOverlay, null);
}
} else {
return null;
}
};
/**
* Render header on the Drawer
* @param title {*|string} - The title of the Drawer
* @param closable {boolean} - Whether a close (X) button is visible on top right of the Drawer dialog or not
* @param onClose {function} - A function that will be called when a user clicks the close button
* @return {null|*} - Returns the JSX or null
*/
var renderHeader = function renderHeader(title, closable, onClose) {
// If title is undefined & closeable is undefined then render nothing, else render deterministic elements
if (!title && !closable) {
return null;
} else {
return /*#__PURE__*/_react["default"].createElement(NavBarHeader, {
hasTitle: !!title,
hasClosable: !!closable
}, title && /*#__PURE__*/_react["default"].createElement(NavBarText, null, title), closable && /*#__PURE__*/_react["default"].createElement(NavBarCloseButton, {
type: "button",
basic: true,
variation: "lightTransparent",
onClick: onClose
}, /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
name: "x"
})));
}
};
/**
* Render schema for the NavBar
* @param leftData {Array} - Left side schema for the NavBar
* @param rightData {Array} - Right side schema for the NavBar
* @param windowSize {Number} - Size of the browser window
* @return {null|*}
*/
var renderBody = function renderBody(leftData, rightData, windowSize) {
if (Array.isArray(leftData) && leftData.length > 0 && Array.isArray(rightData) && rightData.length > 0) {
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(NavBarStart, null, leftData.map(function (_ref18) {
var id = _ref18.id,
href = _ref18.href,
text = _ref18.text,
active = _ref18.active;
return /*#__PURE__*/_react["default"].createElement(NavBarStartItem, {
key: id,
active: active
}, /*#__PURE__*/_react["default"].createElement(NavBarStartLink, {
href: href
}, text));
})), /*#__PURE__*/_react["default"].createElement(NavBarEnd, null, rightData.map(function (_ref19) {
var id = _ref19.id,
href = _ref19.href,
text = _ref19.text,
variation = _ref19.variation,
color = _ref19.color;
// Check if variation is an object type then it means user want to use the breakpoints
if (variation != null && ((0, _typeof2["default"])(variation) === 'object' || typeof variation === 'function')) {
return /*#__PURE__*/_react["default"].createElement(NavBarEndLinkButton, {
key: id,
href: href,
variation: windowSize < 992 ? variation.drawerVariation : variation.normal,
color: color
}, text);
} else {
return /*#__PURE__*/_react["default"].createElement(NavBarEndLinkButton, {
key: id,
href: href,
variation: variation,
color: color
}, text);
}
})));
} else {
return null;
}
};
var NavBar2 = function NavBar2(props) {
var _useWindowSize = (0, _core.useWindowSize)(),
innerWidth = _useWindowSize.innerWidth;
var styledCSS = props.styledCSS,
fixed = props.fixed,
sticky = props.sticky,
closable = props.closable,
mask = props.mask,
maskClosable = props.maskClosable,
title = props.title,
width = props.width,
zIndex = props.zIndex,
Logo = props.logo,
leftLinks = props.leftLinks,
rightLinks = props.rightLinks,
placement = props.placement,
attributes = (0, _objectWithoutProperties2["default"])(props, ["styledCSS", "fixed", "sticky", "closable", "mask", "maskClosable", "title", "width", "zIndex", "logo", "leftLinks", "rightLinks", "placement"]);
var _useState = (0, _react.useState)(false),
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
visibleDrawer = _useState2[0],
setVisibleDrawer = _useState2[1];
var showDrawer = function showDrawer() {
setVisibleDrawer(!visibleDrawer);
}; // This will be used inside the Drawer header, close button & MaskOverlay
var onClose = function onClose() {
setVisibleDrawer(false);
}; // Always make sure the Drawer don't show up on the big screen size,
// so the state will always be false.
(0, _react.useEffect)(function () {
if (innerWidth > 991) {
setVisibleDrawer(false);
}
}, [innerWidth]);
return /*#__PURE__*/_react["default"].createElement(NavBar, (0, _extends2["default"])({
styled: styledCSS,
fixed: fixed,
sticky: sticky
}, attributes), /*#__PURE__*/_react["default"].createElement(ContainerModify, {
fluid: true
}, /*#__PURE__*/_react["default"].createElement(NavBarBrand, {
href: "/"
}, renderLogo(Logo)), /*#__PURE__*/_react["default"].createElement(NavBarButtonToggler, {
basic: true,
variation: "fill",
color: "primary",
active: visibleDrawer,
onClick: showDrawer
}, visibleDrawer ? /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
name: "x"
}) : /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
name: "menu"
})), /*#__PURE__*/_react["default"].createElement(NavBarPlate, {
visible: visibleDrawer,
placement: placement,
zIndex: zIndex
}, renderMask(visibleDrawer, mask, maskClosable, onClose), /*#__PURE__*/_react["default"].createElement(NavBarMenu, {
w: width,
placement: placement
}, renderHeader(title, closable, onClose), renderBody(leftLinks, rightLinks, innerWidth)))));
};
exports.NavBar2 = NavBar2;
NavBar2.propTypes = propTypes;
NavBar2.defaultProps = defaultProps;