UNPKG

@kiwicom/orbit-components

Version:

<div align="center"> <a href="https://orbit.kiwi" target="_blank"> <img alt="orbit-components" src="https://orbit.kiwi/wp-content/uploads/2018/08/orbit-components.png" srcset="https://orbit.kiwi/wp-content/uploads/2018/08/orbit-components@2x.png 2x"

221 lines (187 loc) 7.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _react = require("react"); var React = _interopRequireWildcard(_react); var _styledComponents = require("styled-components"); var _styledComponents2 = _interopRequireDefault(_styledComponents); var _defaultTokens = require("../defaultTokens"); var _defaultTokens2 = _interopRequireDefault(_defaultTokens); var _consts = require("./consts"); var _consts2 = _interopRequireDefault(_consts); var _Check = require("../icons/Check"); var _Check2 = _interopRequireDefault(_Check); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var getToken = function getToken(name) { return function (_ref) { var _tokens; var theme = _ref.theme, hasError = _ref.hasError, disabled = _ref.disabled, checked = _ref.checked; var tokens = (_tokens = {}, _defineProperty(_tokens, _consts2.default.borderColor, hasError && !disabled && !checked ? theme.orbit.borderColorCheckboxRadioError : theme.orbit.borderColorCheckboxRadio), _defineProperty(_tokens, _consts2.default.iconColor, disabled ? theme.orbit.colorIconCheckboxRadioDisabled : theme.orbit.colorIconCheckboxRadio), _tokens); return tokens[name]; }; }; var IconContainer = _styledComponents2.default.div.withConfig({ displayName: "Checkbox__IconContainer" })(["position:relative;box-sizing:border-box;flex:0 0 auto;display:flex;align-items:center;justify-content:center;background-color:", ";height:", ";width:", ";border-radius:", ";transform:scale(1);transition:all ", " ease-in-out;& > svg{visibility:hidden;display:flex;align-items:center;justify-content:center;width:16px;height:16px;}"], function (_ref2) { var theme = _ref2.theme; return theme.orbit.backgroundInput; }, function (_ref3) { var theme = _ref3.theme; return theme.orbit.heightCheckbox; }, function (_ref4) { var theme = _ref4.theme; return theme.orbit.widthCheckbox; }, function (_ref5) { var theme = _ref5.theme; return theme.orbit.borderRadiusNormal; }, function (_ref6) { var theme = _ref6.theme; return theme.orbit.durationFast; }); IconContainer.defaultProps = { theme: _defaultTokens2.default }; var TextContainer = _styledComponents2.default.div.withConfig({ displayName: "Checkbox__TextContainer" })(["display:flex;flex-direction:column;margin-left:", ";"], function (_ref7) { var theme = _ref7.theme; return theme.orbit.spaceXSmall; }); TextContainer.defaultProps = { theme: _defaultTokens2.default }; var Info = _styledComponents2.default.span.withConfig({ displayName: "Checkbox__Info" })(["font-size:", ";color:", ";line-height:", ";"], function (_ref8) { var theme = _ref8.theme; return theme.orbit.fontSizeFormFeedback; }, function (_ref9) { var theme = _ref9.theme; return theme.orbit.colorInfoCheckBoxRadio; }, function (_ref10) { var theme = _ref10.theme; return theme.orbit.lineHeightText; }); Info.defaultProps = { theme: _defaultTokens2.default }; var LabelText = _styledComponents2.default.span.withConfig({ displayName: "Checkbox__LabelText" })(["font-weight:", ";font-size:", ";color:", ";height:", ";line-height:", ";"], function (_ref11) { var theme = _ref11.theme; return theme.orbit.fontWeightNormal; }, function (_ref12) { var theme = _ref12.theme; return theme.orbit.fontSizeFormLabel; }, function (_ref13) { var theme = _ref13.theme; return theme.orbit.colorFormLabel; }, function (_ref14) { var theme = _ref14.theme; return theme.orbit.heightCheckbox; }, function (_ref15) { var theme = _ref15.theme; return theme.orbit.heightCheckbox; }); LabelText.defaultProps = { theme: _defaultTokens2.default }; var Input = _styledComponents2.default.input.withConfig({ displayName: "Checkbox__Input" })(["visibility:hidden;display:none;&:checked ~ ", " > ", "{font-weight:", ";}&:checked + ", " > svg{visibility:visible;}"], TextContainer, LabelText, function (_ref16) { var theme = _ref16.theme; return theme.orbit.fontWeightMedium; }, IconContainer); Input.defaultProps = { theme: _defaultTokens2.default }; var Label = (0, _styledComponents2.default)(function (_ref17) { var className = _ref17.className, children = _ref17.children, dataTest = _ref17.dataTest; return React.createElement( "label", { className: className, "data-test": dataTest }, children ); }).withConfig({ displayName: "Checkbox__Label" })(["font-family:", ";display:flex;flex-direction:row;align-items:self-start;opacity:", ";cursor:", ";position:relative;", "{color:", ";border:1px solid ", ";}&:hover ", "{border-color:", ";}&:active ", "{border-color:", ";transform:", ";}&:focus{outline:0;& ", "{border:", ";}}"], function (_ref18) { var theme = _ref18.theme; return theme.orbit.fontFamily; }, function (_ref19) { var disabled = _ref19.disabled, theme = _ref19.theme; return disabled ? theme.orbit.opacityCheckboxDisabled : "1"; }, function (_ref20) { var disabled = _ref20.disabled; return disabled ? "default" : "pointer"; }, IconContainer, getToken(_consts2.default.iconColor), getToken(_consts2.default.borderColor), IconContainer, function (_ref21) { var disabled = _ref21.disabled, theme = _ref21.theme; return !disabled && theme.orbit.borderColorCheckboxRadioHover; }, IconContainer, function (_ref22) { var disabled = _ref22.disabled, theme = _ref22.theme; return disabled ? getToken(_consts2.default.borderColor) : theme.orbit.borderColorCheckboxRadioActive; }, function (_ref23) { var disabled = _ref23.disabled, theme = _ref23.theme; return !disabled && "scale(" + theme.orbit.modifierScaleCheckboxRadioActive + ")"; }, IconContainer, function (_ref24) { var theme = _ref24.theme; return "2px " + theme.orbit.borderStyleInput + " " + theme.orbit.borderColorCheckboxRadioFocus; }); Label.defaultProps = { theme: _defaultTokens2.default }; var Checkbox = function Checkbox(props) { var label = props.label, value = props.value, _props$hasError = props.hasError, hasError = _props$hasError === undefined ? false : _props$hasError, _props$disabled = props.disabled, disabled = _props$disabled === undefined ? false : _props$disabled, _props$checked = props.checked, checked = _props$checked === undefined ? false : _props$checked, onChange = props.onChange, dataTest = props.dataTest, info = props.info; return React.createElement( Label, { disabled: disabled, hasError: hasError, checked: checked, dataTest: dataTest }, React.createElement(Input, { value: value, type: "checkbox", disabled: disabled, checked: checked, onChange: onChange }), React.createElement( IconContainer, null, React.createElement(_Check2.default, null) ), React.createElement( TextContainer, null, label && React.createElement( LabelText, null, label ), info && React.createElement( Info, null, info ) ) ); }; exports.default = Checkbox;