@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.
150 lines (149 loc) • 6.92 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = exports.StyledLabel = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
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"));
var _common = require("../utils/common");
const getBorderColor = () => ({
theme,
hasError,
disabled,
checked
}) => {
if (disabled) return theme.orbit.paletteCloudNormal;
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) return theme.orbit.paletteCloudNormal;
return checked ? theme.orbit.paletteBlueNormal : theme.orbit.backgroundInput;
};
const Glyph = _styledComponents.default.span.withConfig({
displayName: "Radio__Glyph",
componentId: "sc-1e6hy4x-0"
})(["", ""], ({
theme,
disabled
}) => (0, _styledComponents.css)(["visibility:hidden;width:8px;height:8px;background-color:", ";border-radius:", ";flex-shrink:0;"], disabled ? theme.orbit.paletteCloudNormal : theme.orbit.paletteWhite, theme.orbit.borderRadiusCircle));
Glyph.defaultProps = {
theme: _defaultTheme.default
};
const StyledIconContainer = _styledComponents.default.div.withConfig({
displayName: "Radio__StyledIconContainer",
componentId: "sc-1e6hy4x-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));
StyledIconContainer.defaultProps = {
theme: _defaultTheme.default
};
const StyledTextContainer = _styledComponents.default.div.withConfig({
displayName: "Radio__StyledTextContainer",
componentId: "sc-1e6hy4x-2"
})(["", ""], ({
theme,
disabled
}) => (0, _styledComponents.css)(["display:flex;flex-direction:column;font-weight:", ";margin:", ";flex:1;opacity:", ";"], theme.orbit.fontWeightMedium, (0, _rtl.rtlSpacing)(`0 0 0 ${theme.orbit.spaceXSmall}`), disabled ? theme.orbit.opacityRadioButtonDisabled : "1"));
StyledTextContainer.defaultProps = {
theme: _defaultTheme.default
};
const StyledInfo = _styledComponents.default.span.withConfig({
displayName: "Radio__StyledInfo",
componentId: "sc-1e6hy4x-3"
})(["", ""], ({
theme
}) => (0, _styledComponents.css)(["font-size:", ";color:", ";line-height:", ";"], theme.orbit.fontSizeFormFeedback, theme.orbit.colorInfoCheckBoxRadio, theme.orbit.lineHeightTextSmall));
StyledInfo.defaultProps = {
theme: _defaultTheme.default
};
const StyledLabelText = _styledComponents.default.span.withConfig({
displayName: "Radio__StyledLabelText",
componentId: "sc-1e6hy4x-4"
})(["", ""], ({
theme
}) => (0, _styledComponents.css)(["font-weight:", ";font-size:", ";color:", ";line-height:", ";", "{font-weight:", ";font-size:", ";color:", ";line-height:", ";}"], theme.orbit.fontWeightMedium, theme.orbit.fontSizeFormLabel, theme.orbit.colorFormLabel, theme.orbit.heightCheckbox, _Text.StyledText, theme.orbit.fontWeightMedium, theme.orbit.fontSizeFormLabel, theme.orbit.colorFormLabel, theme.orbit.heightCheckbox));
StyledLabelText.defaultProps = {
theme: _defaultTheme.default
};
const StyledInput = _styledComponents.default.input.withConfig({
displayName: "Radio__StyledInput",
componentId: "sc-1e6hy4x-5"
})(["position:absolute;opacity:0;&:checked + ", " > ", "{visibility:visible;}&:focus + ", "{", ";", "}"], StyledIconContainer, Glyph, StyledIconContainer, _common.defaultFocus, _mediaQuery.default.largeMobile((0, _styledComponents.css)(["border-width:1px;"])));
StyledInput.defaultProps = {
theme: _defaultTheme.default
};
const StyledLabel = (0, _styledComponents.default)(({
disabled,
theme,
type,
hasError,
...props
}) => /*#__PURE__*/React.createElement("label", props, props.children)).withConfig({
displayName: "Radio__StyledLabel",
componentId: "sc-1e6hy4x-6"
})(["", ""], ({
theme,
disabled
}) => (0, _styledComponents.css)(["font-family:", ";display:flex;width:100%;flex-direction:row;align-items:self-start;cursor:", ";position:relative;", "{border:2px solid ", ";}&:hover ", "{border-color:", ";}&:active ", "{border-color:", ";transform:", ";}", ""], theme.orbit.fontFamily, disabled ? "not-allowed" : "pointer", StyledIconContainer, getBorderColor, StyledIconContainer, !disabled && theme.orbit.paletteBlueLightActive, StyledIconContainer, disabled ? getBorderColor : theme.orbit.paletteBlueNormal, !disabled && `scale(${theme.orbit.modifierScaleCheckboxRadioActive})`, _mediaQuery.default.largeMobile((0, _styledComponents.css)(["", "{border:1px solid ", ";}"], StyledIconContainer, getBorderColor))));
exports.StyledLabel = StyledLabel;
StyledLabel.defaultProps = {
theme: _defaultTheme.default
};
const Radio = /*#__PURE__*/React.forwardRef((props, ref) => {
const {
label,
value,
hasError = false,
disabled = false,
checked = false,
onChange,
name,
info,
readOnly,
id,
tabIndex,
dataTest,
tooltip
} = props;
return /*#__PURE__*/React.createElement(StyledLabel, {
disabled: disabled,
hasError: hasError,
checked: checked
}, /*#__PURE__*/React.createElement(StyledInput, {
"data-test": dataTest,
"data-state": (0, _getFieldDataState.default)(hasError),
value: value,
type: "radio",
disabled: disabled,
checked: checked,
id: id,
onChange: onChange,
name: name,
tabIndex: tabIndex ? Number(tabIndex) : undefined,
ref: ref,
readOnly: readOnly
}), (0, _cloneWithTooltip.default)(tooltip, /*#__PURE__*/React.createElement(StyledIconContainer, {
disabled: disabled,
checked: checked
}, /*#__PURE__*/React.createElement(Glyph, {
disabled: disabled
}))), (label || info) && /*#__PURE__*/React.createElement(StyledTextContainer, {
disabled: disabled
}, label && /*#__PURE__*/React.createElement(StyledLabelText, null, label), info && /*#__PURE__*/React.createElement(StyledInfo, null, info)));
});
Radio.displayName = "Radio";
var _default = Radio;
exports.default = _default;