UNPKG

@braineet/ui

Version:

Braineet design system

140 lines 4.74 kB
var _excluded = ["boxShadow", "active", "hover", "focus"]; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } import styled, { css } from 'styled-components'; import { variant } from 'styled-system'; import { fluid } from '../../utils'; import Box from '../box'; import Icon from '../icon'; import Spinner from '../spinner'; import Text from '../text'; export var StyledButton = styled(Box).withConfig({ displayName: "styles__StyledButton", componentId: "sc-1pvy5pr-0" })(["padding:0;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;transition:background-color 0.3s ease,box-shadow 0.3s ease;text-decoration:none;white-space:nowrap;", " ", " ", " ", " ", ""], function (p) { return getButtonStyles(p); }, variant({ prop: 'size', variants: { large: { height: fluid(48) } } }), variant({ prop: '$shouldFitContainer', variants: { true: { width: '100%' } } }), function (props) { return props.disabled && !props.$isLoading && Disabled; }, function (props) { return props.$isLoading && Loading; }); var getButtonStyles = function getButtonStyles(props) { var _props$theme$helpers$ = props.theme.helpers.getFills({ appearance: props.$styleType, color: props.$textColor, reverse: props.$reverseColor }), shadow = _props$theme$helpers$.boxShadow, active = _props$theme$helpers$.active, hover = _props$theme$helpers$.hover, focus = _props$theme$helpers$.focus, defaultStyles = _objectWithoutPropertiesLoose(_props$theme$helpers$, _excluded); var borderSize = { medium: 4, large: 8 }; var flexs = { right: 'row', left: 'row-reverse' }; var flex = flexs[props.$direction]; var borderRadius = borderSize[props.size]; var boxShadow = !props.$hasShadow ? null : shadow; return _extends({}, defaultStyles, { boxShadow: boxShadow, borderRadius: borderRadius, flexDirection: flex, active: active, hover: hover, focus: focus, '&[data-active-item]': hover, '&:active,&[data-active]': hover, '&:not([disabled]):hover': hover, '&:not([disabled]):focus:focus-visible': focus, '&:not([disabled]):active': active, '&:not([disabled]):active:focus:focus-visible': active }); }; export var TextButton = styled(Text).withConfig({ displayName: "styles__TextButton", componentId: "sc-1pvy5pr-1" })(["margin:", ";text-overflow:ellipsis;overflow:hidden;"], function (p) { return getMargin(p); }); var margins = { medium: { text: { default: fluid(8) + " " + fluid(16) + " " + fluid(8) + " " + fluid(16), right: fluid(8) + " " + fluid(8) + " " + fluid(8) + " " + fluid(12), left: fluid(8) + " " + fluid(12) + " " + fluid(8) + " " + fluid(8) }, icon: { default: "" + fluid(4), right: "0 " + fluid(4) + " 0 0", left: "0 0 0 " + fluid(4) } }, large: { text: { default: "0 " + fluid(24), right: "0 " + fluid(12) + " 0 " + fluid(16), left: "0 " + fluid(16) + " 0 " + fluid(12) }, icon: { default: "" + fluid(12), right: "0 " + fluid(12) + " 0 0", left: "0 0 0 " + fluid(12) } } }; export var LoadingIcon = styled(Spinner).withConfig({ displayName: "styles__LoadingIcon", componentId: "sc-1pvy5pr-2" })(["margin:", ";flex-shrink:0;"], function (p) { return getMarginIcon(p); }); export var IconButton = styled(Icon).withConfig({ displayName: "styles__IconButton", componentId: "sc-1pvy5pr-3" })(["margin:", ";flex-shrink:0;"], function (p) { return getMarginIcon(p); }); var Disabled = function Disabled() { return css(["opacity:0.24;cursor:not-allowed;box-shadow:none;"]); }; var Loading = function Loading() { return css(["pointer-events:none;> *{pointer-events:none;}"]); }; var getMargin = function getMargin(p) { var sizeVariant = p.size === 'xs' ? 'medium' : 'large'; var directionVariant = p.icon === '' || !p.icon ? 'default' : p.$direction; return margins[sizeVariant].text[directionVariant]; }; var getMarginIcon = function getMarginIcon(p) { var directionVariant = p.$hasText ? p.$direction : 'default'; return margins[p.$size].icon[directionVariant]; }; export var sizes = { medium: { text: 'xs', icon: 24 }, large: { text: 'md', icon: 24 } };