UNPKG

@amaui/ui-react

Version:
72 lines 3.26 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(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } import React from 'react'; import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/style-react'; import { staticClassName } from '../utils'; const useStyle = styleMethod(theme => ({ root: { display: 'block', backgroundSize: 'cover', backgroundRepeat: 'no-repeat', backgroundPosition: 'center', objectFit: 'cover', width: '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: 'amaui-CardImage' }); const CardImage = /*#__PURE__*/React.forwardRef((props_, ref) => { const theme = useAmauiTheme(); const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.amauiCardImage?.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) && [`amaui-CardImage-root`], className, classes.root, classes[`shape_${shape}`], marginHorizontal && classes.marginHorizontal]) }, other)); }); CardImage.displayName = 'amaui-CardImage'; export default CardImage;