baseui
Version:
A React Component library implementing the Base design language
134 lines (128 loc) • 4.28 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Padding = exports.Inner = exports.Hidden = exports.Body = exports.Arrow = void 0;
exports.getArrowStyles = getArrowStyles;
exports.getBodyStyles = getBodyStyles;
exports.getInnerStyles = getInnerStyles;
var _styles = require("../styles");
var _constants = require("./constants");
var _utils = require("./utils");
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
/**
* Main popover container element that gets positioned next to the anchor
*/
function getBodyStyles(props) {
const {
$animationDuration,
$isOpen,
$isAnimating,
$placement,
$popoverOffset,
$showArrow,
$theme,
$popoverMargin,
$isHoverTrigger
} = props;
return {
position: 'absolute',
top: 0,
left: 0,
backgroundColor: $theme.colors.backgroundTertiary,
borderTopLeftRadius: $theme.borders.popoverBorderRadius,
borderTopRightRadius: $theme.borders.popoverBorderRadius,
borderBottomRightRadius: $theme.borders.popoverBorderRadius,
borderBottomLeftRadius: $theme.borders.popoverBorderRadius,
boxShadow: $theme.lighting.shadow600,
transitionProperty: 'opacity,transform',
transitionDuration: $isAnimating ? $isOpen ? '0.1s' : `${$animationDuration}ms` : '0s',
transitionTimingFunction: $isOpen ? $theme.animation.easeOutCurve : $theme.animation.easeInCurve,
opacity: $isAnimating && $isOpen ? 1 : 0,
transform: $isAnimating && $isOpen ? (0, _utils.getEndPosition)($popoverOffset) : (0, _utils.getStartPosition)($popoverOffset, $placement, $showArrow ? _constants.ARROW_SIZE : 0, $popoverMargin),
...(0, _utils.getPopoverMarginStyles)($showArrow ? _constants.ARROW_SIZE : 0, $placement, $popoverMargin),
...($isHoverTrigger ? {
animationDuration: '.1s',
animationName: {
'0%': {
pointerEvents: 'none'
},
'99%': {
pointerEvents: 'none'
},
'100%': {
pointerEvents: 'auto'
}
}
} : {})
};
}
const Body = exports.Body = (0, _styles.styled)('div', getBodyStyles);
Body.displayName = "Body";
Body.displayName = 'Body';
/**
* Arrow shown between the popover and the anchor element
*/
function getArrowStyles(props) {
const {
$arrowOffset,
$placement,
$theme
} = props;
return {
backgroundColor: $theme.colors.backgroundTertiary,
boxShadow: $theme.lighting.shadow600,
width: `${_constants.ARROW_WIDTH}px`,
height: `${_constants.ARROW_WIDTH}px`,
transform: 'rotate(45deg)',
position: 'absolute',
...(0, _utils.getArrowPositionStyles)($arrowOffset, $placement)
};
}
const Arrow = exports.Arrow = (0, _styles.styled)('div', getArrowStyles);
Arrow.displayName = "Arrow";
Arrow.displayName = 'Arrow';
/**
* Extra div that holds the popover content. This extra element
* is needed for the arrow–the arrow is just a 45deg rotated div,
* and rendering this extra element on top with a solid background
* clips the part of the arrow that extends into the popover.
*/
function getInnerStyles({
$theme
}) {
return {
backgroundColor: $theme.colors.backgroundTertiary,
borderTopLeftRadius: $theme.borders.popoverBorderRadius,
borderTopRightRadius: $theme.borders.popoverBorderRadius,
borderBottomRightRadius: $theme.borders.popoverBorderRadius,
borderBottomLeftRadius: $theme.borders.popoverBorderRadius,
color: $theme.colors.contentPrimary,
position: 'relative'
};
}
const Inner = exports.Inner = (0, _styles.styled)('div', getInnerStyles);
Inner.displayName = "Inner";
Inner.displayName = 'Inner';
/**
* A drop-in component that provides the recommended padding
* for popovers. Mostly a convenience for users so they don't
* have to define this themselves.
*/
const Padding = exports.Padding = (0, _styles.styled)('div', {
paddingLeft: '12px',
paddingTop: '12px',
paddingRight: '12px',
paddingBottom: '12px'
});
Padding.displayName = "Padding";
Padding.displayName = 'Padding';
const Hidden = exports.Hidden = (0, _styles.styled)('div', {
display: 'none'
});
Hidden.displayName = "Hidden";
Hidden.displayName = 'Hidden';