@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.
203 lines (168 loc) • 8.12 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
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 _orbitDesignTokens = require("@kiwicom/orbit-design-tokens");
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 _mediaQuery = _interopRequireDefault(require("../utils/mediaQuery"));
const _excluded = ["disabled", "theme", "type", "hasError"];
const getBorderColor = () => ({
theme,
hasError,
disabled,
checked
}) => {
if (disabled) return theme.orbit.paletteCloudDarker;
if (checked) return theme.orbit.paletteBlueNormal;
if (hasError && !disabled && !checked) return theme.orbit.borderColorCheckboxRadioError;
return theme.orbit.borderColorCheckboxRadio;
};
const getBackground = () => ({
theme,
disabled,
checked
}) => {
if (disabled && checked) return theme.orbit.paletteCloudDarker;
if (disabled && !checked) return theme.orbit.paletteCloudNormal;
return checked ? theme.orbit.paletteBlueNormal : theme.orbit.backgroundInput;
};
const Glyph = _styledComponents.default.span.withConfig({
displayName: "Radio__Glyph",
componentId: "sc-crlwn1-0"
})(["visibility:hidden;width:8px;height:8px;background-color:", ";border-radius:", ";flex-shrink:0;"], ({
theme,
disabled
}) => disabled ? theme.orbit.paletteCloudNormal : theme.orbit.paletteWhite, ({
theme
}) => theme.orbit.borderRadiusCircle); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
Glyph.defaultProps = {
theme: _defaultTheme.default
};
const IconContainer = _styledComponents.default.div.withConfig({
displayName: "Radio__IconContainer",
componentId: "sc-crlwn1-1"
})(["", ""], ({
theme
}) => (0, _styledComponents.css)(["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, theme.orbit.heightCheckbox, theme.orbit.widthCheckbox, theme.orbit.borderRadiusCircle, theme.orbit.durationFast)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
IconContainer.defaultProps = {
theme: _defaultTheme.default
};
const TextContainer = _styledComponents.default.div.withConfig({
displayName: "Radio__TextContainer",
componentId: "sc-crlwn1-2"
})(["display:flex;flex-direction:column;margin:", ";flex:1;"], ({
theme
}) => (0, _rtl.rtlSpacing)(`0 0 0 ${theme.orbit.spaceXSmall}`)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
TextContainer.defaultProps = {
theme: _defaultTheme.default
};
const Info = _styledComponents.default.span.withConfig({
displayName: "Radio__Info",
componentId: "sc-crlwn1-3"
})(["font-size:", ";color:", ";line-height:", ";"], ({
theme
}) => theme.orbit.fontSizeFormFeedback, ({
theme
}) => theme.orbit.colorInfoCheckBoxRadio, ({
theme
}) => theme.orbit.lineHeightTextSmall); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
Info.defaultProps = {
theme: _defaultTheme.default
};
const LabelText = _styledComponents.default.span.withConfig({
displayName: "Radio__LabelText",
componentId: "sc-crlwn1-4"
})(["", ""], ({
theme
}) => (0, _styledComponents.css)(["font-weight:", ";font-size:", ";color:", ";line-height:", ";", "{font-weight:", ";font-size:", ";color:", ";line-height:", ";}"], theme.orbit.fontWeightNormal, theme.orbit.fontSizeFormLabel, theme.orbit.colorFormLabel, theme.orbit.heightCheckbox, _Text.StyledText, theme.orbit.fontWeightNormal, theme.orbit.fontSizeFormLabel, theme.orbit.colorFormLabel, theme.orbit.heightCheckbox)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
LabelText.defaultProps = {
theme: _defaultTheme.default
};
const Input = _styledComponents.default.input.withConfig({
displayName: "Radio__Input",
componentId: "sc-crlwn1-5"
})(["position:absolute;opacity:0;&:checked ~ ", " > ", "{font-weight:", ";& > ", "{font-weight:", ";}}&:checked + ", " > ", "{visibility:visible;}&:focus + ", "{outline:0;border:", ";box-shadow:0 0 0 2px ", ";", "}"], TextContainer, LabelText, ({
theme
}) => theme.orbit.fontWeightMedium, _Text.StyledText, ({
theme
}) => theme.orbit.fontWeightMedium, IconContainer, Glyph, IconContainer, ({
theme,
hasError
}) => `2px ${theme.orbit.borderStyleInput} ${hasError ? theme.orbit.paletteRedNormal : theme.orbit.borderColorCheckboxRadioFocus}`, ({
theme,
hasError
}) => (0, _orbitDesignTokens.convertHexToRgba)(hasError ? theme.orbit.paletteRedNormal : theme.orbit.borderColorInputFocus, 15), _mediaQuery.default.largeMobile((0, _styledComponents.css)(["border-width:1px;"]))); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
Input.defaultProps = {
theme: _defaultTheme.default
};
const Label = (0, _styledComponents.default)((_ref) => {
let {
disabled,
theme,
type,
hasError
} = _ref,
props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
return /*#__PURE__*/React.createElement("label", props, props.children);
}).withConfig({
displayName: "Radio__Label",
componentId: "sc-crlwn1-6"
})(["", ""], ({
theme,
disabled
}) => (0, _styledComponents.css)(["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:", ";}", ""], theme.orbit.fontFamily, disabled ? theme.orbit.opacityCheckboxDisabled : "1", disabled ? "default" : "pointer", IconContainer, getBorderColor, IconContainer, !disabled && theme.orbit.paletteBlueLightActive, IconContainer, disabled ? getBorderColor : theme.orbit.paletteBlueNormal, !disabled && `scale(${theme.orbit.modifierScaleCheckboxRadioActive})`, _mediaQuery.default.largeMobile((0, _styledComponents.css)(["", "{border:1px solid ", ";}"], IconContainer, getBorderColor)))); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
Label.defaultProps = {
theme: _defaultTheme.default
};
const Radio = /*#__PURE__*/React.forwardRef((props, ref) => {
const {
label,
value,
hasError = false,
disabled = false,
checked = false,
onChange,
name,
info,
readOnly,
tabIndex,
dataTest,
tooltip
} = props;
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;