UNPKG

vcc-ui

Version:

VCC UI is a collection of React UI Components that can be used for developing front-end applications at Volvo Car Corporation.

98 lines (90 loc) 3.38 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } 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 React from 'react'; import { useFela } from 'react-fela'; import { string, bool, func } from 'prop-types'; import { Inline } from '../inline'; import { getThemeStyle } from '../../get-theme-style'; var radioStyle = function radioStyle(_ref) { var theme = _ref.theme, isValid = _ref.isValid; return { boxSizing: 'border-box', borderWidth: 1, borderStyle: 'solid', appearance: 'none', borderRadius: '50%', width: 20, height: 20, margin: 0, padding: 0, display: 'flex', justifyContent: 'center', alignItems: 'center', position: 'relative', cursor: 'pointer', borderColor: theme.tokens.inputBorder, background: theme.tokens.inputBackground, outline: 0, extend: [{ condition: !isValid, style: { borderColor: theme.color.foreground.alert } }, { condition: isValid, style: { ':focus': { borderColor: theme.tokens.inputBorderFocus } } }], ':checked': { ':before': { borderRadius: '50%', display: 'block', content: "''", width: 8, height: 8, backgroundColor: theme.tokens.inputControl, position: 'absolute' } }, ':disabled': { cursor: 'not-allowed', borderColor: theme.tokens.inputDisabledBorder, ':checked': { ':before': { backgroundColor: theme.tokens.inputDisabledControl } } } }; }; export var Radio = React.forwardRef(function (_ref2, ref) { var _ref2$isValid = _ref2.isValid, isValid = _ref2$isValid === void 0 ? true : _ref2$isValid, props = _objectWithoutProperties(_ref2, ["isValid"]); var _useFela = useFela(), theme = _useFela.theme; var styleProps = { isValid: isValid, theme: theme }; return React.createElement(Inline, _extends({ ref: ref }, props, { as: "input", type: "radio", extend: [radioStyle(styleProps), getThemeStyle('radio', theme, styleProps)] })); }); Radio.displayName = 'Radio'; Radio.propTypes = { onChange: func.isRequired, checked: bool.isRequired, /** Should be the same for all radio buttons belonging to same group */ name: string.isRequired, isValid: bool };