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.

273 lines (239 loc) 9.8 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireWildcard(require("styled-components")); var _convertHexToRgba = _interopRequireDefault(require("@kiwicom/orbit-design-tokens/lib/convertHexToRgba")); var _defaultTheme = _interopRequireDefault(require("../defaultTheme")); var _Text = require("../Text"); var _rtl = require("../utils/rtl"); var _getFieldDataState = _interopRequireDefault(require("../common/getFieldDataState")); var _cloneWithTooltip = _interopRequireDefault(require("../utils/cloneWithTooltip")); var _index = _interopRequireDefault(require("../utils/mediaQuery/index")); var getBorderColor = function getBorderColor() { return function (_ref) { var theme = _ref.theme, hasError = _ref.hasError, disabled = _ref.disabled, checked = _ref.checked; if (disabled) { return theme.orbit.paletteInkLighter; } if (checked) { return theme.orbit.paletteBlueNormal; } if (hasError && !disabled && !checked) { return theme.orbit.borderColorCheckboxRadioError; } return theme.orbit.borderColorCheckboxRadio; }; }; var getBackground = function getBackground() { return function (_ref2) { var theme = _ref2.theme, disabled = _ref2.disabled, checked = _ref2.checked; if (disabled && checked) { return theme.orbit.paletteInkLighter; } if (disabled && !checked) { return theme.orbit.paletteCloudNormal; } return checked ? theme.orbit.paletteBlueNormal : theme.orbit.backgroundInput; }; }; var Glyph = _styledComponents.default.span.withConfig({ displayName: "Radio__Glyph", componentId: "sc-5lanou-0" })(["visibility:hidden;width:8px;height:8px;background-color:", ";border-radius:", ";flex-shrink:0;"], function (_ref3) { var theme = _ref3.theme, disabled = _ref3.disabled; return disabled ? theme.orbit.paletteCloudNormal : theme.orbit.paletteWhite; }, function (_ref4) { var theme = _ref4.theme; return theme.orbit.borderRadiusCircle; }); Glyph.defaultProps = { theme: _defaultTheme.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;}"], getBackground(), 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: _defaultTheme.default }; var TextContainer = _styledComponents.default.div.withConfig({ displayName: "Radio__TextContainer", componentId: "sc-5lanou-2" })(["display:flex;flex-direction:column;margin:", ";flex:1;"], function (_ref9) { var theme = _ref9.theme; return (0, _rtl.rtlSpacing)("0 0 0 ".concat(theme.orbit.spaceXSmall)); }); TextContainer.defaultProps = { theme: _defaultTheme.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.lineHeightTextSmall; }); Info.defaultProps = { theme: _defaultTheme.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: _defaultTheme.default }; var Input = _styledComponents.default.input.withConfig({ displayName: "Radio__Input", componentId: "sc-5lanou-5" })(["position:absolute;opacity:0;&:checked ~ ", " > ", "{font-weight:", ";& > ", "{font-weight:", ";}}&:checked + ", " > ", "{visibility:visible;}&:focus + ", "{outline:0;border:", ";box-shadow:0 0 0 3px ", ";", "}"], 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, IconContainer, function (_ref23) { var theme = _ref23.theme, hasError = _ref23.hasError; return "2px ".concat(theme.orbit.borderStyleInput, " ").concat(hasError ? theme.orbit.paletteRedNormal : theme.orbit.borderColorCheckboxRadioFocus); }, function (_ref24) { var theme = _ref24.theme, hasError = _ref24.hasError; return (0, _convertHexToRgba.default)(hasError ? theme.orbit.paletteRedNormal : theme.orbit.borderColorInputFocus, 15); }, _index.default.largeMobile((0, _styledComponents.css)(["border-width:1px;"]))); Input.defaultProps = { theme: _defaultTheme.default }; var Label = (0, _styledComponents.default)(function (_ref25) { var disabled = _ref25.disabled, theme = _ref25.theme, type = _ref25.type, hasError = _ref25.hasError, props = (0, _objectWithoutProperties2.default)(_ref25, ["disabled", "theme", "type", "hasError"]); return /*#__PURE__*/React.createElement("label", props, props.children); }).withConfig({ displayName: "Radio__Label", componentId: "sc-5lanou-6" })(["font-family:", ";display:flex;width:100%;flex-direction:row;align-items:self-start;opacity:", ";cursor:", ";position:relative;", "{border:2px solid ", ";}&:hover ", "{border-color:", ";}&:active ", "{border-color:", ";transform:", ";}", ""], function (_ref26) { var theme = _ref26.theme; return theme.orbit.fontFamily; }, function (_ref27) { var disabled = _ref27.disabled, theme = _ref27.theme; return disabled ? theme.orbit.opacityCheckboxDisabled : "1"; }, function (_ref28) { var disabled = _ref28.disabled; return disabled ? "default" : "pointer"; }, IconContainer, getBorderColor(), IconContainer, function (_ref29) { var disabled = _ref29.disabled, theme = _ref29.theme; return !disabled && theme.orbit.paletteBlueLightActive; }, IconContainer, function (_ref30) { var disabled = _ref30.disabled, theme = _ref30.theme; return disabled ? getBorderColor() : theme.orbit.paletteBlueNormal; }, function (_ref31) { var disabled = _ref31.disabled, theme = _ref31.theme; return !disabled && "scale(".concat(theme.orbit.modifierScaleCheckboxRadioActive, ")"); }, _index.default.largeMobile((0, _styledComponents.css)(["", "{border:1px solid ", ";}"], IconContainer, getBorderColor()))); Label.defaultProps = { theme: _defaultTheme.default }; var Radio = /*#__PURE__*/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, readOnly = props.readOnly, tabIndex = props.tabIndex, dataTest = props.dataTest, tooltip = props.tooltip; return /*#__PURE__*/React.createElement(Label, { disabled: disabled, hasError: hasError, checked: checked }, /*#__PURE__*/React.createElement(Input, { "data-test": dataTest, "data-state": (0, _getFieldDataState.default)(hasError), value: value, type: "radio", disabled: disabled, checked: checked, onChange: onChange, name: name, tabIndex: tabIndex, ref: ref, readOnly: readOnly, hasError: hasError }), (0, _cloneWithTooltip.default)(tooltip, /*#__PURE__*/React.createElement(IconContainer, { disabled: disabled, checked: checked }, /*#__PURE__*/React.createElement(Glyph, { disabled: disabled }))), (label || info) && /*#__PURE__*/React.createElement(TextContainer, null, label && /*#__PURE__*/React.createElement(LabelText, null, label), info && /*#__PURE__*/React.createElement(Info, null, info))); }); Radio.displayName = "Radio"; var _default = Radio; exports.default = _default;