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.
83 lines (76 loc) • 3.13 kB
JavaScript
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 PropTypes from 'prop-types';
import { useFela } from 'react-fela';
import { Flex } from '../flex';
import { getThemeStyle } from '../../get-theme-style';
var transition = '300ms cubic-bezier(0.23, 1, 0.32, 1) 0s';
var style = function style(_ref) {
var theme = _ref.theme,
href = _ref.href,
selected = _ref.selected;
return {
boxSizing: 'border-box',
boxShadow: theme.tokens.card.shadow,
overflow: 'hidden',
background: theme.tokens.card.background,
borderRadius: 4,
extend: [{
condition: selected,
style: {
position: 'relative',
':after': {
content: '" "',
pointerEvents: 'none',
display: 'block',
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
borderRadius: 4,
border: '1px solid ' + theme.color.ornament.highlight
}
}
}, {
condition: href,
style: {
textDecoration: 'none',
color: 'inherit',
transition: "transform ".concat(transition, ", box-shadow ").concat(transition),
':hover': {
transform: 'translateY(-5px)',
boxShadow: 'rgba(0, 0, 0, 0.2) 0px 12px 24px'
}
}
}]
};
};
export var Card = React.forwardRef(function (_ref2, ref) {
var selected = _ref2.selected,
href = _ref2.href,
children = _ref2.children,
props = _objectWithoutProperties(_ref2, ["selected", "href", "children"]);
var _useFela = useFela(),
theme = _useFela.theme;
var styleProps = {
theme: theme,
selected: selected,
href: href
};
return React.createElement(Flex, _extends({
as: href ? 'a' : 'div',
ref: ref,
href: href
}, props, {
extend: [style(styleProps), getThemeStyle('card', theme, styleProps)]
}), children);
});
Card.displayName = 'Card';
Card.propTypes = {
selected: PropTypes.bool,
href: PropTypes.string,
children: PropTypes.node
};