UNPKG

grommet

Version:

focus on the essential experience

51 lines (50 loc) 2.95 kB
import styled, { keyframes } from 'styled-components'; import { Box } from '../Box'; import { baseStyle, edgeStyle, roundStyle } from '../../utils/styles'; import { backgroundStyle } from '../../utils/background'; function getTransformOriginStyle(align) { var vertical = 'top'; if (align.bottom) { vertical = 'bottom'; } var horizontal = 'left'; if (align.right) { horizontal = 'right'; } return vertical + " " + horizontal; } var dropKeyFrames = keyframes(["0%{opacity:0.5;transform:scale(0.8);}100%{opacity:1;transform:scale(1);}"]); // The desired margin may be adjusted depending on drops alignment var marginStyle = function marginStyle(theme, align, data, responsive, marginProp) { // NOTE: If marginProp is passed, it overrides the alignment-aware // margin logic and uses the provided value instead. var margin = theme.global.edgeSize[data] || data; var adjustedMargin = {}; // if user provides CSS string such as '50px 12px', apply that always var customCSS = typeof margin === 'string' && margin.split(' ').length > 1; if (theme.global.drop.intelligentMargin === true && !customCSS && typeof margin === 'string') { if (align.top === 'bottom') adjustedMargin.top = margin;else if (align.bottom === 'top') adjustedMargin.bottom = margin; if (align.right === 'left') adjustedMargin.left = "-" + margin;else if (align.left === 'right') adjustedMargin.left = margin; if (!Object.keys(adjustedMargin)) adjustedMargin = 'none'; } else { return edgeStyle('margin', marginProp || theme.global.drop.margin, responsive, theme.global.edgeSize.responsiveBreakpoint, theme); } return edgeStyle('margin', marginProp || adjustedMargin, responsive, theme.global.edgeSize.responsiveBreakpoint, theme); }; var StyledDrop = styled(Box).withConfig({ displayName: "StyledDrop", componentId: "sc-16s5rx8-0" })(["", " ", " position:fixed;z-index:", ";outline:none;", " ", " opacity:0;transform-origin:", ";animation:", " 0.1s forwards;animation-delay:0.01s;@media screen and (-ms-high-contrast:active),(-ms-high-contrast:none){display:flex;align-items:stretch;}", ""], baseStyle, function (props) { return !props.plain && (props.round && roundStyle(props.round, props.responsive || true, props.theme) || "border-radius: " + props.theme.global.drop.border.radius + ";"); }, function (props) { return props.theme.global.drop.zIndex; }, function (props) { return !props.plain && backgroundStyle(props.background || props.theme.global.drop.background, props.theme); }, function (props) { return !props.plain && (props.margin || props.theme.global.drop.margin) && props.theme.global && marginStyle(props.theme, props.alignProp, props.theme.global.drop.margin, props.responsive, props.margin); }, function (props) { return getTransformOriginStyle(props.alignProp); }, dropKeyFrames, function (props) { return props.theme.global.drop && props.theme.global.drop.extend; }); export { StyledDrop };