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.

120 lines (105 loc) 4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Checkbox = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = require("prop-types"); var _reactFela = require("react-fela"); var _block = require("../block"); var _getThemeStyle = require("../../get-theme-style"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } var checkboxStyle = function checkboxStyle(_ref) { var theme = _ref.theme, isValid = _ref.isValid; return { boxSizing: 'border-box', borderWidth: 1, borderStyle: 'solid', appearance: 'none', width: 20, height: 20, margin: 0, padding: 0, flexShrink: 0, flexGrow: 0, outline: 0, display: 'flex', justifyContent: 'center', alignItems: 'center', position: 'relative', cursor: 'pointer', borderColor: theme.tokens.inputBorder, background: theme.tokens.inputBackground, extend: [{ condition: !isValid, style: { borderColor: theme.color.foreground.alert } }, { condition: isValid, style: { ':focus': { borderColor: theme.tokens.inputBorderFocus } } }, { condition: isValid, style: { ':active': { color: 'pink' } } }], ':disabled': { cursor: 'not-allowed', borderColor: theme.tokens.inputDisabledBorder, ':checked': { ':before': { borderRight: "2px solid ".concat(theme.tokens.inputDisabledControl), borderBottom: "2px solid ".concat(theme.tokens.inputDisabledControl) } } }, ':checked': { ':before': { boxSizing: 'border-box', transform: 'translateY(-1px) rotate(45deg)', display: 'block', content: "''", width: 5, height: 10, position: 'absolute', borderRight: "2px solid ".concat(theme.tokens.inputControl), borderBottom: "2px solid ".concat(theme.tokens.inputControl) } } }; }; var Checkbox = _react.default.forwardRef(function (_ref2, ref) { var _ref2$isValid = _ref2.isValid, isValid = _ref2$isValid === void 0 ? true : _ref2$isValid, props = _objectWithoutProperties(_ref2, ["isValid"]); var _useFela = (0, _reactFela.useFela)(), theme = _useFela.theme; var styleProps = { isValid: isValid, theme: theme }; return _react.default.createElement(_block.Block, _extends({}, props, { ref: ref, as: "input", type: "checkbox", extend: [checkboxStyle(styleProps), (0, _getThemeStyle.getThemeStyle)('checkbox', theme, styleProps)] })); }); exports.Checkbox = Checkbox; Checkbox.displayName = 'Checkbox'; Checkbox.propTypes = { onChange: _propTypes.func.isRequired, checked: _propTypes.bool, isValid: _propTypes.bool };