pouncejs
Version:
A collection of UI components from Panther labs
65 lines (60 loc) • 2.23 kB
JavaScript
/* eslint-disable @typescript-eslint/no-explicit-any */
import css from '@styled-system/css';
import { addOpacity } from '../utils/helpers';
import colors from '../theme/colors';
export var truncateProp = function truncateProp(_ref) {
var truncated = _ref.truncated;
if (truncated) {
return {
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
};
}
};
export var visuallyHiddenProp = function visuallyHiddenProp(_ref2) {
var visuallyHidden = _ref2.visuallyHidden;
if (visuallyHidden) {
return {
border: '0px',
height: '1px',
width: '1px',
margin: '-1px',
padding: '0px',
overflow: 'hidden',
whiteSpace: 'nowrap',
position: 'absolute'
};
}
};
export var backgroundOpacityProp = function backgroundOpacityProp(_ref3) {
var backgroundOpacity = _ref3.backgroundOpacity,
backgroundColor = _ref3.backgroundColor;
if (backgroundOpacity) {
var _colors;
// As the value of `backgroundOpacity` we want to be able to parse a lot of alternatives such as: 0.5, "0.5", 50, "50"
// Obviously the user can still add values such as "110" or "200", but we can't do much there
var bgOpacity = typeof backgroundOpacity === 'string' ? Number(backgroundOpacity) : backgroundOpacity;
bgOpacity = bgOpacity > 1 ? bgOpacity / 100 : bgOpacity;
var bgColor = (_colors = colors[backgroundColor]) != null ? _colors : colors.inherit;
return {
backgroundColor: addOpacity(bgColor, bgOpacity)
};
}
};
export var borderOpacityProp = function borderOpacityProp(_ref4) {
var borderOpacity = _ref4.borderOpacity,
borderColor = _ref4.borderColor;
if (borderOpacity) {
// As the value of `borderOpacity` we want to be able to parse a lot of alternatives such as: 0.5, "0.5", 50, "50"
// Obviously the user can still add values such as "110" or "200", but we can't do much there
var opacity = typeof borderOpacity === 'string' ? Number(borderOpacity) : borderOpacity;
opacity = opacity > 1 ? opacity / 100 : opacity;
return {
borderColor: addOpacity(colors[borderColor], opacity)
};
}
};
export var sxProp = function sxProp(props) {
return css(props.sx)(props);
};