UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

224 lines (200 loc) 8.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _defaultTokens = _interopRequireDefault(require("../defaultTokens")); var _Text = require("../Text"); 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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var getBorderColor = function getBorderColor() { return function (_ref) { var theme = _ref.theme, hasError = _ref.hasError, disabled = _ref.disabled, checked = _ref.checked; return hasError && !disabled && !checked ? theme.orbit.borderColorCheckboxRadioError : theme.orbit.borderColorCheckboxRadio; }; }; var Glyph = _styledComponents.default.span.withConfig({ displayName: "Radio__Glyph", componentId: "sc-5lanou-0" })(["visibility:hidden;width:12px;height:12px;background-color:", ";border-radius:", ";flex-shrink:0;"], function (_ref2) { var theme = _ref2.theme, disabled = _ref2.disabled; return disabled ? theme.orbit.colorIconCheckboxRadioDisabled : theme.orbit.colorIconCheckboxRadio; }, function (_ref3) { var theme = _ref3.theme; return theme.orbit.borderRadiusCircle; }); Glyph.defaultProps = { theme: _defaultTokens.default }; var IconContainer = _styledComponents.default.div.withConfig({ displayName: "Radio__IconContainer", componentId: "sc-5lanou-1" })(["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;}"], function (_ref4) { var theme = _ref4.theme; return theme.orbit.backgroundInput; }, function (_ref5) { var theme = _ref5.theme; return theme.orbit.heightCheckbox; }, function (_ref6) { var theme = _ref6.theme; return theme.orbit.widthCheckbox; }, function (_ref7) { var theme = _ref7.theme; return theme.orbit.borderRadiusCircle; }, function (_ref8) { var theme = _ref8.theme; return theme.orbit.durationFast; }); IconContainer.defaultProps = { theme: _defaultTokens.default }; var TextContainer = _styledComponents.default.div.withConfig({ displayName: "Radio__TextContainer", componentId: "sc-5lanou-2" })(["display:flex;flex-direction:column;margin-left:", ";"], function (_ref9) { var theme = _ref9.theme; return theme.orbit.spaceXSmall; }); TextContainer.defaultProps = { theme: _defaultTokens.default }; var Info = _styledComponents.default.span.withConfig({ displayName: "Radio__Info", componentId: "sc-5lanou-3" })(["font-size:", ";color:", ";line-height:", ";"], function (_ref10) { var theme = _ref10.theme; return theme.orbit.fontSizeFormFeedback; }, function (_ref11) { var theme = _ref11.theme; return theme.orbit.colorInfoCheckBoxRadio; }, function (_ref12) { var theme = _ref12.theme; return theme.orbit.lineHeightText; }); Info.defaultProps = { theme: _defaultTokens.default }; var LabelText = _styledComponents.default.span.withConfig({ displayName: "Radio__LabelText", componentId: "sc-5lanou-4" })(["font-weight:", ";font-size:", ";color:", ";line-height:", ";", "{font-weight:", ";font-size:", ";color:", ";line-height:", ";}"], function (_ref13) { var theme = _ref13.theme; return theme.orbit.fontWeightNormal; }, function (_ref14) { var theme = _ref14.theme; return theme.orbit.fontSizeFormLabel; }, function (_ref15) { var theme = _ref15.theme; return theme.orbit.colorFormLabel; }, function (_ref16) { var theme = _ref16.theme; return theme.orbit.heightCheckbox; }, _Text.StyledText, function (_ref17) { var theme = _ref17.theme; return theme.orbit.fontWeightNormal; }, function (_ref18) { var theme = _ref18.theme; return theme.orbit.fontSizeFormLabel; }, function (_ref19) { var theme = _ref19.theme; return theme.orbit.colorFormLabel; }, function (_ref20) { var theme = _ref20.theme; return theme.orbit.heightCheckbox; }); LabelText.defaultProps = { theme: _defaultTokens.default }; var Input = _styledComponents.default.input.withConfig({ displayName: "Radio__Input", componentId: "sc-5lanou-5" })(["visibility:hidden;display:none;&:checked ~ ", " > ", "{font-weight:", ";& > ", "{font-weight:", ";}}&:checked + ", " > ", "{visibility:visible;}"], TextContainer, LabelText, function (_ref21) { var theme = _ref21.theme; return theme.orbit.fontWeightMedium; }, _Text.StyledText, function (_ref22) { var theme = _ref22.theme; return theme.orbit.fontWeightMedium; }, IconContainer, Glyph); Input.defaultProps = { theme: _defaultTokens.default }; var Label = (0, _styledComponents.default)(function (_ref23) { var disabled = _ref23.disabled, theme = _ref23.theme, type = _ref23.type, hasError = _ref23.hasError, props = _objectWithoutProperties(_ref23, ["disabled", "theme", "type", "hasError"]); return React.createElement("label", props, props.children); }).withConfig({ displayName: "Radio__Label", componentId: "sc-5lanou-6" })(["font-family:", ";display:flex;flex-direction:row;align-items:self-start;opacity:", ";cursor:", ";position:relative;", "{border:1px solid ", ";}&:hover ", "{border-color:", ";}&:active ", "{border-color:", ";transform:", ";}&:focus{outline:0;& ", "{border:", ";}}"], function (_ref24) { var theme = _ref24.theme; return theme.orbit.fontFamily; }, function (_ref25) { var disabled = _ref25.disabled, theme = _ref25.theme; return disabled ? theme.orbit.opacityCheckboxDisabled : "1"; }, function (_ref26) { var disabled = _ref26.disabled; return disabled ? "default" : "pointer"; }, IconContainer, getBorderColor(), IconContainer, function (_ref27) { var disabled = _ref27.disabled, theme = _ref27.theme; return !disabled && theme.orbit.borderColorCheckboxRadioHover; }, IconContainer, function (_ref28) { var disabled = _ref28.disabled, theme = _ref28.theme; return disabled ? getBorderColor() : theme.orbit.borderColorCheckboxRadioActive; }, function (_ref29) { var disabled = _ref29.disabled, theme = _ref29.theme; return !disabled && "scale(".concat(theme.orbit.modifierScaleCheckboxRadioActive, ")"); }, IconContainer, function (_ref30) { var theme = _ref30.theme; return "2px ".concat(theme.orbit.borderStyleInput, " ").concat(theme.orbit.borderColorCheckboxRadioFocus); }); Label.defaultProps = { theme: _defaultTokens.default }; // $FlowExpected var Radio = React.forwardRef(function (props, ref) { var label = props.label, value = props.value, _props$hasError = props.hasError, hasError = _props$hasError === void 0 ? false : _props$hasError, _props$disabled = props.disabled, disabled = _props$disabled === void 0 ? false : _props$disabled, _props$checked = props.checked, checked = _props$checked === void 0 ? false : _props$checked, onChange = props.onChange, name = props.name, info = props.info, dataTest = props.dataTest; return React.createElement(Label, { disabled: disabled, hasError: hasError, checked: checked, "data-test": dataTest }, React.createElement(Input, { value: value, type: "radio", disabled: disabled, checked: checked, onChange: onChange, name: name, ref: ref }), React.createElement(IconContainer, null, React.createElement(Glyph, { disabled: disabled })), React.createElement(TextContainer, null, label && React.createElement(LabelText, null, label), info && React.createElement(Info, null, info))); }); Radio.displayName = "Radio"; var _default = Radio; exports.default = _default;