UNPKG

@dotconnor/grommet

Version:

focus on the essential experience

457 lines (425 loc) 24.7 kB
"use strict"; exports.__esModule = true; exports.StyledContainer = exports.StyledOverlay = exports.StyledLayer = exports.animationDuration = void 0; var _styledComponents = _interopRequireWildcard(require("styled-components")); var _utils = require("../../utils"); var _defaultProps = require("../../default-props"); function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var hiddenPositionStyle = (0, _styledComponents.css)(["left:-100%;right:100%;z-index:-1;position:fixed;"]); var desktopLayerStyle = "\n position: fixed;\n top: 0px;\n left: 0px;\n right: 0px;\n bottom: 0px;\n"; var responsiveLayerStyle = "\n position: absolute;\n width: 100%;\n height: 100%;\n min-height: 100vh;\n"; var StyledLayer = _styledComponents["default"].div.withConfig({ displayName: "StyledLayer", componentId: "rmtehz-0" })(["", " background:transparent;position:relative;z-index:", ";pointer-events:none;outline:none;", " ", ";"], _utils.baseStyle, function (props) { return props.theme.layer.zIndex; }, function (props) { if (props.position === 'hidden') { return hiddenPositionStyle; } var styles = []; if (props.targetBounds) { var _props$targetBounds = props.targetBounds, left = _props$targetBounds.left, right = _props$targetBounds.right, top = _props$targetBounds.top, bottom = _props$targetBounds.bottom; styles.push("\n position: fixed;\n top: " + top + "px;\n left: " + left + "px;\n right: " + right + "px;\n bottom: " + bottom + "px;\n "); } else { styles.push(desktopLayerStyle); } if (props.responsive && props.theme.layer.responsiveBreakpoint) { var breakpoint = props.theme.global.breakpoints[props.theme.layer.responsiveBreakpoint]; styles.push((0, _utils.breakpointStyle)(breakpoint, responsiveLayerStyle)); } return styles; }, function (props) { return props.theme.layer && props.theme.layer.extend; }); exports.StyledLayer = StyledLayer; StyledLayer.defaultProps = {}; Object.setPrototypeOf(StyledLayer.defaultProps, _defaultProps.defaultProps); var StyledOverlay = _styledComponents["default"].div.withConfig({ displayName: "StyledLayer__StyledOverlay", componentId: "rmtehz-1" })(["position:absolute;", " top:0px;left:0px;right:0px;bottom:0px;", " pointer-events:all;"], function (props) { if (props.responsive && props.theme.layer.responsiveBreakpoint) { var breakpoint = props.theme.global.breakpoints[props.theme.layer.responsiveBreakpoint]; return (0, _utils.breakpointStyle)(breakpoint, 'position: relative;'); } return ''; }, function (props) { return !props.plain && props.theme.layer.overlay.background && (0, _utils.backgroundStyle)(props.theme.layer.overlay.background, props.theme); }); exports.StyledOverlay = StyledOverlay; var getMargin = function getMargin(margin, theme, position) { var axis = position.indexOf('top') !== -1 || position.indexOf('bottom') !== -1 ? 'vertical' : 'horizontal'; var marginValue = margin[position] || margin[axis] || margin; var marginApplied = theme.global.edgeSize[marginValue] || marginValue; var marginInTheme = !!theme.global.edgeSize[marginValue]; return !marginInTheme && typeof marginValue !== 'string' ? 0 : (0, _utils.parseMetricToNum)(marginApplied); }; var getBounds = function getBounds(bounds, margin, theme, position) { if (position === void 0) { position = undefined; } if (position) { return bounds[position] + getMargin(margin, theme, position); } return { bottom: bounds.bottom + getMargin(margin, theme, 'bottom'), // 'bottom-left': getMargin(margin, theme, 'bottom-left'), // 'bottom-right': getMargin(margin, theme, 'bottom-right'), end: bounds.right + getMargin(margin, theme, 'end'), left: bounds.left + getMargin(margin, theme, 'left'), right: bounds.right + getMargin(margin, theme, 'right'), start: bounds.left + getMargin(margin, theme, 'start'), top: bounds.top + getMargin(margin, theme, 'top') // 'top-right': getMargin(margin, theme, 'top-right'), // 'top-left': getMargin(margin, theme, 'top-left'), }; }; var KEYFRAMES = { center: { vertical: (0, _styledComponents.keyframes)(["0%{transform:translateX(-50%) scale(0.8);}100%{transform:translateX(-50%) scale(1);}"]), horizontal: (0, _styledComponents.keyframes)(["0%{transform:translateY(-50%) scale(0.8);}100%{transform:translateY(-50) scale(1);}"]), "true": (0, _styledComponents.keyframes)(["0%{transform:scale(0.8);}100%{transform:scale(1);}"]), "false": (0, _styledComponents.keyframes)(["0%{transform:translate(-50%,-50%) scale(0.8);}100%{transform:translate(-50%,-50%) scale(1);}"]) }, top: { vertical: (0, _styledComponents.keyframes)(["0%{transform:translate(-50%,-100%);}100%{transform:translate(-50%,0);}"]), horizontal: (0, _styledComponents.keyframes)(["0%{transform:translateY(-100%);}100%{transform:translateY(0);}"]), "true": (0, _styledComponents.keyframes)(["0%{transform:translateY(-100%);}100%{transform:translateY(0);}"]), "false": (0, _styledComponents.keyframes)(["0%{transform:translate(-50%,-100%);}100%{transform:translate(-50%,0);}"]) }, bottom: { vertical: (0, _styledComponents.keyframes)(["0%{transform:translate(-50%,100%);}100%{transform:translate(-50%,0);}"]), horizontal: (0, _styledComponents.keyframes)(["0%{transform:translateY(100%);}100%{transform:translateY(0);}"]), "true": (0, _styledComponents.keyframes)(["0%{transform:translateY(100%);}100%{transform:translateY(0);}"]), "false": (0, _styledComponents.keyframes)(["0%{transform:translate(-50%,100%);}100%{transform:translate(-50%,0);}"]) }, left: { vertical: (0, _styledComponents.keyframes)(["0%{transform:translateX(-100%);}100%{transform:translateX(0);}"]), horizontal: (0, _styledComponents.keyframes)(["0%{transform:translate(-100%,-50%);}100%{transform:translate(0,-50%);}"]), "true": (0, _styledComponents.keyframes)(["0%{transform:translateX(-100%);}100%{transform:translateX(0);}"]), "false": (0, _styledComponents.keyframes)(["0%{transform:translate(-100%,-50%);}100%{transform:translate(0,-50%);}"]) }, right: { vertical: (0, _styledComponents.keyframes)(["0%{transform:translateX(100%);}100%{transform:translateX(0);}"]), horizontal: (0, _styledComponents.keyframes)(["0%{transform:translate(100%,-50%);}100%{transform:translate(0,-50%);}"]), "true": (0, _styledComponents.keyframes)(["0%{transform:translateX(100%);}100%{transform:translateX(0);}"]), "false": (0, _styledComponents.keyframes)(["0%{transform:translate(100%,-50%);}100%{transform:translate(0,-50%);}"]) }, start: { vertical: (0, _styledComponents.keyframes)(["0%{transform:translateX(-100%);}100%{transform:translateX(0);}"]), horizontal: (0, _styledComponents.keyframes)(["0%{transform:translate(-100%,-50%);}100%{transform:translate(0,-50%);}"]), "true": (0, _styledComponents.keyframes)(["0%{transform:translateX(-100%);}100%{transform:translateX(0);}"]), "false": (0, _styledComponents.keyframes)(["0%{transform:translate(-100%,-50%);}100%{transform:translate(0,-50%);}"]) }, end: { vertical: (0, _styledComponents.keyframes)(["0%{transform:translateX(100%);}100%{transform:translateX(0);}"]), horizontal: (0, _styledComponents.keyframes)(["0%{transform:translate(100%,-50%);}100%{transform:translate(0,-50%);}"]), "true": (0, _styledComponents.keyframes)(["0%{transform:translateX(100%);}100%{transform:translateX(0);}"]), "false": (0, _styledComponents.keyframes)(["0%{transform:translate(100%,-50%);}100%{transform:translate(0,-50%);}"]) } }; var animationDuration = 200; exports.animationDuration = animationDuration; var getAnimationStyle = function getAnimationStyle(props, position, full) { var animation = props.animation !== undefined ? props.animation : props.animate; if (animation === undefined) animation = 'slide'; var keys; if (animation === 'slide' || animation === true) { keys = KEYFRAMES[position][full]; } else if (animation === 'fadeIn') { keys = (0, _styledComponents.keyframes)(["0%{opacity:0}100%{opacity:1}"]); } return keys ? (0, _styledComponents.css)(["animation:", " ", "s ease-in-out forwards;"], keys, animationDuration / 1000.0) : ''; }; // POSITIONS combines 'position', 'full', and 'margin' properties, since // they are all interdependent. // Basically, non-full axes combine 50% position with -50% translation. // full axes pin to the window edges offset by any margin. // The keyframe animations are included as they are done via translations // as well so they must take into account the non-animated positioning. var POSITIONS = { center: { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:50%;transform:translateX(-50%);", ""], bounds.top, bounds.bottom, function (props) { return getAnimationStyle(props, 'center', 'vertical'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["left:", "px;right:", "px;top:50%;transform:translateY(-50%);", ""], bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'center', 'horizontal'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;right:", "px;", ""], bounds.top, bounds.bottom, bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'center', 'true'); }); }, "false": function _false() { return (0, _styledComponents.css)(["top:50%;left:50%;transform:translate(-50%,-50%);", ""], function (props) { return getAnimationStyle(props, 'center', 'false'); }); } }, top: { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:50%;transform:translate(-50%,0%);", ""], bounds.top, bounds.bottom, function (props) { return getAnimationStyle(props, 'top', 'vertical'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["left:", "px;right:", "px;top:", "px;transform:translateY(0);", ""], bounds.left, bounds.right, bounds.top, function (props) { return getAnimationStyle(props, 'top', 'horizontal'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;right:", "px;transform:translateY(0);", ""], bounds.top, bounds.bottom, bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'top', 'true'); }); }, "false": function _false(bounds) { return (0, _styledComponents.css)(["top:", "px;left:50%;transform:translate(-50%,0);", ""], bounds.top, function (props) { return getAnimationStyle(props, 'top', 'false'); }); } }, bottom: { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:50%;transform:translate(-50%,0);", ""], bounds.top, bounds.bottom, function (props) { return getAnimationStyle(props, 'bottom', 'vertical'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["left:", "px;right:", "px;bottom:", "px;transform:translateY(0);", ""], bounds.left, bounds.top, bounds.bottom, function (props) { return getAnimationStyle(props, 'bottom', 'horizontal'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;right:", "px;transform:translateY(0);", ""], bounds.top, bounds.bottom, bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'bottom', 'true'); }); }, "false": function _false(bounds) { return (0, _styledComponents.css)(["bottom:", "px;left:50%;transform:translate(-50%,0);", ""], bounds.bottom, function (props) { return getAnimationStyle(props, 'bottom', 'false'); }); } }, left: { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.left, function (props) { return getAnimationStyle(props, 'left', 'vertical'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["left:", "px;right:", "px;top:50%;transform:translate(0,-50%);", ""], bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'left', 'horizontal'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;right:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'left', 'true'); }); }, "false": function _false(bounds) { return (0, _styledComponents.css)(["left:", "px;top:50%;transform:translate(0,-50%);", ""], bounds.left, function (props) { return getAnimationStyle(props, 'left', 'false'); }); } }, right: { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;right:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.right, function (props) { return getAnimationStyle(props, 'right', 'vertical'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["left:", "px;right:", "px;top:50%;transform:translate(0,-50%);", ""], bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'right', 'horizontal'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;right:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'right', 'true'); }); }, "false": function _false(bounds) { return (0, _styledComponents.css)(["right:", "px;top:50%;transform:translate(0,-50%);", ""], bounds.right, function (props) { return getAnimationStyle(props, 'right', 'false'); }); } }, start: { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;inset-inline-start:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.start, function (props) { return getAnimationStyle(props, 'start', 'vertical'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["inset-inline-start:", "px;inset-inline-end:", "px;top:50%;transform:translate(0,-50%);", ""], bounds.start, bounds.end, function (props) { return getAnimationStyle(props, 'start', 'horizontal'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;inset-inline-start:", "px;inset-inline-end:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.start, bounds.end, function (props) { return getAnimationStyle(props, 'start', 'true'); }); }, "false": function _false(bounds) { return (0, _styledComponents.css)(["inset-inline-start:", "px;top:50%;transform:translate(0,-50%);", ""], bounds.start, function (props) { return getAnimationStyle(props, 'start', 'false'); }); } }, end: { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;inset-inline-end:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.end, function (props) { return getAnimationStyle(props, 'end', 'vertical'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["inset-inline-start:", "px;inset-inline-end:", "px;top:50%;transform:translate(0,-50%);", ""], bounds.start, bounds.end, function (props) { return getAnimationStyle(props, 'end', 'horizontal'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;inset-inline-start:", "px;inset-inline-end:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.start, bounds.end, function (props) { return getAnimationStyle(props, 'end', 'true'); }); }, "false": function _false(bounds) { return (0, _styledComponents.css)(["inset-inline-end:", "px;top:50%;transform:translate(0,-50%);", ""], bounds.end, function (props) { return getAnimationStyle(props, 'end', 'false'); }); } }, 'top-right': { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;right:", "px;transform:translateX(0);", ";"], bounds.top, bounds.bottom, bounds.right, function (props) { return getAnimationStyle(props, 'top', 'true'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["left:", "px;right:", "px;top:0;transform:translateX(0);", ";"], bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'top', 'true'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;right:", "px;transform:translateX(0);", ";"], bounds.top, bounds.bottom, bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'top', 'true'); }); }, "false": function _false(bounds) { return (0, _styledComponents.css)(["top:", "px;right:", "px;transform:translateY(0);", ";"], bounds.top, bounds.right, function (props) { return getAnimationStyle(props, 'top', 'true'); }); } }, 'top-left': { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.left, function (props) { return getAnimationStyle(props, 'top', 'true'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["left:", "px;right:", "px;top:0;transform:translateX(0);", ""], bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'top', 'true'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;right:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'top', 'true'); }); }, "false": function _false(bounds) { return (0, _styledComponents.css)(["top:", "px;left:", "px;transform:translateY(0);", ""], bounds.top, bounds.left, function (props) { return getAnimationStyle(props, 'top', 'true'); }); } }, 'bottom-right': { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;right:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.right, function (props) { return getAnimationStyle(props, 'bottom', 'true'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["left:", "px;right:", "px;bottom:", "px;transform:translateY(0);", ""], bounds.left, bounds.right, bounds.bottom, function (props) { return getAnimationStyle(props, 'bottom', 'true'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;right:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'bottom', 'true'); }); }, "false": function _false(bounds) { return (0, _styledComponents.css)(["bottom:", "px;right:", "px;transform:translateY(0);", ""], bounds.bottom, bounds.right, function (props) { return getAnimationStyle(props, 'bottom', 'true'); }); } }, 'bottom-left': { vertical: function vertical(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.left, function (props) { return getAnimationStyle(props, 'bottom', 'true'); }); }, horizontal: function horizontal(bounds) { return (0, _styledComponents.css)(["left:", "px;right:", "px;bottom:", "px;transform:translateY(0);", ""], bounds.left, bounds.right, bounds.bottom, function (props) { return getAnimationStyle(props, 'bottom', 'true'); }); }, "true": function _true(bounds) { return (0, _styledComponents.css)(["top:", "px;bottom:", "px;left:", "px;right:", "px;transform:translateX(0);", ""], bounds.top, bounds.bottom, bounds.left, bounds.right, function (props) { return getAnimationStyle(props, 'bottom', 'true'); }); }, "false": function _false(bounds) { return (0, _styledComponents.css)(["bottom:", "px;left:", "px;transform:translateY(0);", ""], bounds.bottom, bounds.left, function (props) { return getAnimationStyle(props, 'bottom', 'true'); }); } } }; var desktopContainerStyle = (0, _styledComponents.css)(["", " max-height:", ";max-width:", ";border-radius:", ";", ";"], function (props) { if (!props.modal && props.position === 'hidden') { return hiddenPositionStyle; } return (0, _styledComponents.css)(["position:", ";"], props.modal ? 'absolute' : 'fixed'); }, function (props) { return "calc(100% - " + getBounds(props.targetBounds, props.margin, props.theme, 'top') + "px - " + getBounds(props.targetBounds, props.margin, props.theme, 'bottom') + "px)"; }, function (props) { return "calc(100% - " + getBounds(props.targetBounds, props.margin, props.theme, 'left') + "px - " + getBounds(props.targetBounds, props.margin, props.theme, 'right') + "px)"; }, function (props) { return props.plain ? 0 : props.theme.layer.border.radius; }, function (props) { return props.position !== 'hidden' && POSITIONS[props.position][props.full](getBounds(props.targetBounds, props.margin, props.theme), props.targetBounds) || ''; }); var responsiveContainerStyle = (0, _styledComponents.css)(["position:relative;max-height:none;max-width:none;border-radius:0;top:0;bottom:0;left:0;right:0;transform:none;animation:none;height:100vh;width:100vw;"]); var StyledContainer = _styledComponents["default"].div.withConfig({ displayName: "StyledLayer__StyledContainer", componentId: "rmtehz-2" })(["", " display:flex;flex-direction:column;min-height:", ";", " outline:none;pointer-events:all;z-index:", ";", " ", ";"], function (props) { return !props.modal ? _utils.baseStyle : ''; }, function (props) { return props.theme.global.size.xxsmall; }, function (props) { return !props.plain && props.theme.layer.background && (0, _utils.backgroundStyle)(props.theme.layer.background, props.theme); }, function (props) { return props.theme.layer.container.zIndex; }, desktopContainerStyle, function (props) { if (props.responsive && props.theme.layer.responsiveBreakpoint) { var breakpoint = props.theme.global.breakpoints[props.theme.layer.responsiveBreakpoint]; if (breakpoint) { return (0, _utils.breakpointStyle)(breakpoint, responsiveContainerStyle); } } return ''; }); exports.StyledContainer = StyledContainer; StyledContainer.defaultProps = {}; Object.setPrototypeOf(StyledContainer.defaultProps, _defaultProps.defaultProps);