UNPKG

grommet

Version:

focus on the essential experience

121 lines (120 loc) 6.95 kB
import styled, { css } from 'styled-components'; import { edgeStyle, focusStyle, normalizeColor, styledComponentsConfig } from '../../utils'; import { Box } from '../Box'; // Note: since `fillStyle` is only used in one place, `justify-content` was // added to it to simplify its logic. If this is ever reused somewhere else, // consider the need of separating those once again. var fillStyle = function fillStyle() { return "\n width: auto;\n height: 100%;\n max-width: none;\n flex: 1 0 auto;\n justify-content: space-between;\n "; }; var disabledStyle = "\n opacity: 0.5;\n cursor: default;\n"; var hoverStyle = css(["&:hover input:not([disabled]) + div,&:hover input:not([disabled]) + span{border-color:", ";", "}&:hover{background-color:", ";}"], function (props) { var _props$theme$checkBox; return normalizeColor((_props$theme$checkBox = props.theme.checkBox.hover) == null || (_props$theme$checkBox = _props$theme$checkBox.border) == null ? void 0 : _props$theme$checkBox.color, props.theme); }, function (props) { var _props$theme$checkBox2; return (_props$theme$checkBox2 = props.theme.checkBox.hover) == null ? void 0 : _props$theme$checkBox2.extend; }, function (props) { var _props$theme$checkBox3; return normalizeColor(!props.disabled && ((_props$theme$checkBox3 = props.theme.checkBox.hover) == null || (_props$theme$checkBox3 = _props$theme$checkBox3.background) == null ? void 0 : _props$theme$checkBox3.color), props.theme); }); var StyledCheckBoxIcon = styled.svg.withConfig(styledComponentsConfig).withConfig({ displayName: "StyledCheckBox__StyledCheckBoxIcon", componentId: "sc-1dbk5ju-0" })(["box-sizing:border-box;stroke-width:", ";stroke:", ";width:", ";height:", ";", ";"], function (props) { return props.theme.checkBox.check.thickness; }, function (props) { return normalizeColor(props.theme.checkBox.color || 'control', props.theme); }, function (props) { return props.theme.checkBox.icon.size || props.theme.checkBox.size; }, function (props) { return props.theme.checkBox.icon.size || props.theme.checkBox.size; }, function (props) { return props.theme.checkBox.icon.extend; }); var StyledCheckBoxContainer = styled.label.withConfig(styledComponentsConfig).withConfig({ displayName: "StyledCheckBox__StyledCheckBoxContainer", componentId: "sc-1dbk5ju-1" })(["display:flex;flex-direction:row;align-items:", ";user-select:none;-webkit-user-select:none;", " ", " ", " ", " ", " ", " ", ""], function (props) { return typeof props.labelProp === 'string' ? props.theme.checkBox.label.align : undefined; }, function (props) { return props.fillProp ? fillStyle() : 'width: fit-content;'; }, function (props) { return (props.pad || props.theme.checkBox.pad) && edgeStyle('padding', props.pad || props.theme.checkBox.pad, props.responsive, props.theme.box.responsiveBreakpoint, props.theme); }, function (props) { return props.disabled && disabledStyle; }, function (props) { return !props.disabled && 'cursor: pointer;'; }, hoverStyle, function (props) { var _props$theme$checkBox4, _props$theme$checkBox5; return props.focus && !props.focusIndicator && "\n input:not([disabled]) + div,\n input:not([disabled]) + span {\n border-color: " + normalizeColor((_props$theme$checkBox4 = props.theme.checkBox.hover) == null || (_props$theme$checkBox4 = _props$theme$checkBox4.border) == null ? void 0 : _props$theme$checkBox4.color, props.theme) + ";\n }\n\n background-color: " + normalizeColor(!props.disabled && ((_props$theme$checkBox5 = props.theme.checkBox.hover) == null || (_props$theme$checkBox5 = _props$theme$checkBox5.background) == null ? void 0 : _props$theme$checkBox5.color), props.theme) + ";"; }, function (props) { return props.theme.checkBox.extend; }); var StyledCheckBoxInput = styled.input.withConfig(styledComponentsConfig).withConfig({ displayName: "StyledCheckBox__StyledCheckBoxInput", componentId: "sc-1dbk5ju-2" })(["opacity:0;-moz-appearance:none;width:0;height:0;margin:0;", " &:checked + span > span{", ":calc( ", " - ", " );background:", ";}"], function (props) { return !props.disabled && 'cursor: pointer;'; }, function (props) { return !props.theme.dir ? 'left' : 'right'; }, function (props) { return props.theme.checkBox.toggle.size; }, function (props) { return props.theme.checkBox.size; }, function (props) { return normalizeColor(props.theme.checkBox.color || 'control', props.theme); }); var StyledCheckBoxBox = styled(Box).withConfig({ displayName: "StyledCheckBox__StyledCheckBoxBox", componentId: "sc-1dbk5ju-3" })(["", ";", ";"], function (props) { return props.focus && props.focusIndicator && focusStyle(); }, function (props) { return props.theme.checkBox.check.extend; }); var StyledCheckBoxToggle = styled.span.withConfig(styledComponentsConfig).withConfig({ displayName: "StyledCheckBox__StyledCheckBoxToggle", componentId: "sc-1dbk5ju-4" })(["box-sizing:border-box;vertical-align:middle;display:inline-block;width:", ";height:", ";border:", " solid;border-color:", ";border-radius:", ";background-color:", ";", ";", ";"], function (props) { return props.theme.checkBox.toggle.size; }, function (props) { return props.theme.checkBox.size; }, function (props) { return props.theme.checkBox.border.width; }, function (props) { return normalizeColor(props.theme.checkBox.border.color, props.theme); }, function (props) { return props.theme.checkBox.toggle.radius; }, function (props) { return props.theme.checkBox.toggle.background ? normalizeColor(props.theme.checkBox.toggle.background, props.theme) : 'transparent'; }, function (props) { return props.focus && props.focusIndicator && focusStyle(); }, function (props) { return props.theme.checkBox.toggle.extend; }); var StyledCheckBoxKnob = styled.span.withConfig(styledComponentsConfig).withConfig({ displayName: "StyledCheckBox__StyledCheckBoxKnob", componentId: "sc-1dbk5ju-5" })(["box-sizing:border-box;position:relative;display:inherit;top:-", ";", ":-", ";transition:all 0.3s;width:", ";height:", ";background:", ";border-radius:", ";", ";"], function (props) { return props.theme.checkBox.border.width; }, function (props) { return !props.theme.dir ? 'left' : 'right'; }, function (props) { return props.theme.checkBox.border.width; }, function (props) { return props.theme.checkBox.size; }, function (props) { return props.theme.checkBox.size; }, function (props) { return normalizeColor(props.theme.checkBox.toggle.color, props.theme); }, function (props) { return props.theme.checkBox.toggle.radius; }, function (props) { return props.theme.checkBox.toggle.knob.extend; }); var StyledCheckBox = styled(Box).withConfig({ displayName: "StyledCheckBox", componentId: "sc-1dbk5ju-6" })(["flex-shrink:0;"]); export { StyledCheckBoxIcon, StyledCheckBoxContainer, StyledCheckBoxInput, StyledCheckBoxBox, StyledCheckBoxToggle, StyledCheckBoxKnob, StyledCheckBox };