@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.
174 lines (169 loc) • 6.36 kB
JavaScript
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; }
import * as React from "react";
import styled from "styled-components";
import defaultTheme from "../defaultTheme";
import { StyledText } from "../Text";
import { rtlSpacing } from "../utils/rtl";
import getFieldDataState from "../common/getFieldDataState";
const getBorderColor = () => ({
theme,
hasError,
disabled,
checked
}) => hasError && !disabled && !checked ? theme.orbit.borderColorCheckboxRadioError : theme.orbit.borderColorCheckboxRadio;
const Glyph = styled.span.withConfig({
displayName: "Radio__Glyph",
componentId: "sc-5lanou-0"
})(["visibility:hidden;width:12px;height:12px;background-color:", ";border-radius:", ";flex-shrink:0;"], ({
theme,
disabled
}) => disabled ? theme.orbit.colorIconCheckboxRadioDisabled : theme.orbit.colorIconCheckboxRadio, ({
theme
}) => theme.orbit.borderRadiusCircle);
Glyph.defaultProps = {
theme: defaultTheme
};
const IconContainer = styled.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;}"], ({
theme
}) => theme.orbit.backgroundInput, ({
theme
}) => theme.orbit.heightCheckbox, ({
theme
}) => theme.orbit.widthCheckbox, ({
theme
}) => theme.orbit.borderRadiusCircle, ({
theme
}) => theme.orbit.durationFast);
IconContainer.defaultProps = {
theme: defaultTheme
};
const TextContainer = styled.div.withConfig({
displayName: "Radio__TextContainer",
componentId: "sc-5lanou-2"
})(["display:flex;flex-direction:column;margin:", ";flex:1;"], ({
theme
}) => rtlSpacing(`0 0 0 ${theme.orbit.spaceXSmall}`));
TextContainer.defaultProps = {
theme: defaultTheme
};
const Info = styled.span.withConfig({
displayName: "Radio__Info",
componentId: "sc-5lanou-3"
})(["font-size:", ";color:", ";line-height:", ";"], ({
theme
}) => theme.orbit.fontSizeFormFeedback, ({
theme
}) => theme.orbit.colorInfoCheckBoxRadio, ({
theme
}) => theme.orbit.lineHeightTextSmall);
Info.defaultProps = {
theme: defaultTheme
};
const LabelText = styled.span.withConfig({
displayName: "Radio__LabelText",
componentId: "sc-5lanou-4"
})(["font-weight:", ";font-size:", ";color:", ";line-height:", ";", "{font-weight:", ";font-size:", ";color:", ";line-height:", ";}"], ({
theme
}) => theme.orbit.fontWeightNormal, ({
theme
}) => theme.orbit.fontSizeFormLabel, ({
theme
}) => theme.orbit.colorFormLabel, ({
theme
}) => theme.orbit.heightCheckbox, StyledText, ({
theme
}) => theme.orbit.fontWeightNormal, ({
theme
}) => theme.orbit.fontSizeFormLabel, ({
theme
}) => theme.orbit.colorFormLabel, ({
theme
}) => theme.orbit.heightCheckbox);
LabelText.defaultProps = {
theme: defaultTheme
};
const Input = styled.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:", ";}"], TextContainer, LabelText, ({
theme
}) => theme.orbit.fontWeightMedium, StyledText, ({
theme
}) => theme.orbit.fontWeightMedium, IconContainer, Glyph, IconContainer, ({
theme
}) => `2px ${theme.orbit.borderStyleInput} ${theme.orbit.borderColorCheckboxRadioFocus}`);
Input.defaultProps = {
theme: defaultTheme
};
const Label = styled((_ref) => {
let {
disabled,
theme,
type,
hasError
} = _ref,
props = _objectWithoutProperties(_ref, ["disabled", "theme", "type", "hasError"]);
return 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:1px solid ", ";}&:hover ", "{border-color:", ";}&:active ", "{border-color:", ";transform:", ";}"], ({
theme
}) => theme.orbit.fontFamily, ({
disabled,
theme
}) => disabled ? theme.orbit.opacityCheckboxDisabled : "1", ({
disabled
}) => disabled ? "default" : "pointer", IconContainer, getBorderColor(), IconContainer, ({
disabled,
theme
}) => !disabled && theme.orbit.borderColorCheckboxRadioHover, IconContainer, ({
disabled,
theme
}) => disabled ? getBorderColor() : theme.orbit.borderColorCheckboxRadioActive, ({
disabled,
theme
}) => !disabled && `scale(${theme.orbit.modifierScaleCheckboxRadioActive})`);
Label.defaultProps = {
theme: defaultTheme
};
const Radio = React.forwardRef((props, ref) => {
const {
label,
value,
hasError = false,
disabled = false,
checked = false,
onChange,
name,
info,
readOnly,
tabIndex,
dataTest
} = props;
return React.createElement(Label, {
disabled: disabled,
hasError: hasError,
checked: checked
}, React.createElement(Input, {
"data-test": dataTest,
"data-state": getFieldDataState(hasError),
value: value,
type: "radio",
disabled: disabled,
checked: checked,
onChange: onChange,
name: name,
tabIndex: tabIndex,
ref: ref,
readOnly: readOnly
}), React.createElement(IconContainer, null, React.createElement(Glyph, {
disabled: disabled
})), (label || info) && React.createElement(TextContainer, null, label && React.createElement(LabelText, null, label), info && React.createElement(Info, null, info)));
});
Radio.displayName = "Radio";
export default Radio;