UNPKG

@onesy/ui-react

Version:
73 lines 3.13 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["tonal", "color", "version", "elevation", "alt", "image", "shape", "marginHorizontal", "Component", "className", "children"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React from 'react'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import { staticClassName } from '../utils'; const useStyle = styleMethod(theme => ({ root: { display: 'block', backgroundSize: 'cover', backgroundRepeat: 'no-repeat', backgroundPosition: 'center', objectFit: 'cover', width: '100%', height: '100%' }, shape_top: { borderRadius: `${theme.shape.radius.unit * 3}px ${theme.shape.radius.unit * 3}px 0 0` }, shape_left: { borderRadius: `${theme.shape.radius.unit * 3}px 0 0 ${theme.shape.radius.unit * 3}px` }, shape_right: { borderRadius: `0 ${theme.shape.radius.unit * 3}px ${theme.shape.radius.unit * 3}px 0` }, shape_bottom: { borderRadius: `0 0 ${theme.shape.radius.unit * 3}px ${theme.shape.radius.unit * 3}px` }, shape_all: { borderRadius: `${theme.shape.radius.unit * 3}px` }, shape_none: { borderRadius: `0` }, marginHorizontal: { width: 'calc(100% - 48px)', margin: '0 24px' } }), { name: 'onesy-CardImage' }); const CardImage = /*#__PURE__*/React.forwardRef((props_, ref) => { const theme = useOnesyTheme(); const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyCardImage?.props?.default), props_), [props_]); const { tonal = true, color, version, elevation, alt, image, shape = 'bottom', marginHorizontal, Component = 'img', className, children } = props, other = _objectWithoutProperties(props, _excluded); const { classes } = useStyle(); return /*#__PURE__*/React.createElement(Component, _extends({ ref: ref, alt: alt || '', src: image, className: classNames([staticClassName('CardImage', theme) && [`onesy-CardImage-root`], className, classes.root, classes[`shape_${shape}`], marginHorizontal && classes.marginHorizontal]) }, other)); }); CardImage.displayName = 'onesy-CardImage'; export default CardImage;