UNPKG

@dotconnor/grommet

Version:

focus on the essential experience

139 lines (115 loc) 5.39 kB
import styled, { css } from 'styled-components'; import { activeStyle, disabledStyle, focusStyle, genericStyles, kindPartStyles } from '../../utils'; import { defaultProps } from '../../default-props'; var radiusStyle = function radiusStyle(props) { var size = props.sizeProp; if (size && props.theme.button.size && props.theme.button.size[size]) return css(["border-radius:", ";"], props.theme.button.size[size].border.radius); if (props.theme.button.border && props.theme.button.border.radius) return css(["border-radius:", ";"], props.theme.button.border.radius); return ''; }; var fontStyle = function fontStyle(props) { var size = props.sizeProp || 'medium'; var data = props.theme.text[size]; return css(["font-size:", ";line-height:", ";"], data.size, data.height); }; var padStyle = function padStyle(_ref) { var size = _ref.sizeProp, theme = _ref.theme; if (size && theme.button.size && theme.button.size[size] && theme.button.size[size].pad) { return css(["padding:", " ", ";"], theme.button.size[size].pad.vertical, theme.button.size[size].pad.horizontal); } if (theme.button.padding) { return css(["padding:", " ", ";"], theme.global.edgeSize[theme.button.padding.vertical] || theme.button.padding.vertical, theme.global.edgeSize[theme.button.padding.horizontal] || theme.button.padding.horizontal); } return ''; }; // The > svg rule is to ensure Buttons with just an icon don't add additional // vertical height internally. var basicStyle = function basicStyle(props) { return css(["border:none;", ";", " ", " > svg{vertical-align:bottom;}"], radiusStyle(props), padStyle(props), fontStyle(props)); }; // build up CSS from basic to specific based on the supplied sub-object paths var kindStyle = function kindStyle(_ref2) { var colorValue = _ref2.colorValue, themePaths = _ref2.themePaths, theme = _ref2.theme; var styles = []; themePaths.base.forEach(function (themePath) { var obj = theme.button; if (themePath) { var parts = themePath.split('.'); while (obj && parts.length) { obj = obj[parts.shift()]; } } if (obj) { styles.push(kindPartStyles(obj, theme, colorValue)); } }); themePaths.hover.forEach(function (themePath) { var obj = theme.button; if (themePath) { var parts = themePath.split('.'); while (obj && parts.length) { obj = obj[parts.shift()]; } if (obj) { var partStyles = kindPartStyles(obj, theme); if (partStyles.length > 0) styles.push(css(["&:hover{", "}"], partStyles)); } } }); return styles; }; var hoverIndicatorStyle = function hoverIndicatorStyle(_ref3) { var hoverIndicator = _ref3.hoverIndicator, theme = _ref3.theme; var themishObj = {}; if (hoverIndicator === true || hoverIndicator === 'background') themishObj.background = theme.global.hover.background;else themishObj.background = hoverIndicator; var styles = kindPartStyles(themishObj, theme); if (styles.length > 0) return css(["&:hover{", "}"], styles); return ''; }; var fillStyle = function fillStyle(fillContainer) { if (fillContainer === 'horizontal') { return 'width: 100%;'; } if (fillContainer === 'vertical') { return 'height: 100%;'; } if (fillContainer) { return "\n width: 100%;\n height: 100%;\n max-width: none;\n flex: 1 0 auto;\n "; } return undefined; }; // The > svg rule is to ensure Buttons with just an icon don't add additional // vertical height internally. var plainStyle = function plainStyle() { return css(["outline:none;border:none;padding:0;text-align:inherit;color:inherit;> svg{vertical-align:bottom;}"]); }; var StyledButtonKind = styled.button.withConfig({ displayName: "StyledButtonKind", componentId: "sc-1vhfpnt-0" })(["display:inline-block;box-sizing:border-box;cursor:pointer;font:inherit;text-decoration:none;margin:0;background:transparent;overflow:visible;text-transform:none;", " ", " ", " ", " ", " ", " ", " ", " &:focus{", "}", " ", " ", ""], genericStyles, function (props) { return props.plain && plainStyle(props); }, function (props) { return !props.disabled && props.active && activeStyle; }, function (props) { return !props.plain && basicStyle(props); }, function (props) { return !props.plain && kindStyle(props); }, function (props) { return !props.plain && props.align && "\n text-align: " + props.align + ";\n "; }, function (props) { return !props.disabled && props.hoverIndicator && hoverIndicatorStyle(props); }, function (props) { return props.disabled && disabledStyle(props.theme.button.disabled.opacity); }, function (props) { return (!props.plain || props.focusIndicator) && focusStyle(); }, function (props) { return !props.plain && props.theme.button.transition && "\n transition-property: " + props.theme.button.transition.properties.join(',') + ";\n transition-duration: " + props.theme.button.transition.duration + "s;\n transition-timing-function: " + props.theme.button.transition.timing + ";\n "; }, function (props) { return props.fillContainer && fillStyle(props.fillContainer); }, function (props) { return props.theme.button && props.theme.button.extend; }); StyledButtonKind.defaultProps = {}; Object.setPrototypeOf(StyledButtonKind.defaultProps, defaultProps); export { StyledButtonKind };