UNPKG

@confi/conflux-react-ui-test-package

Version:

Modern and minimalist React UI library.

62 lines (55 loc) 3.41 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import _JSXStyle from "styled-jsx/style"; import React, { useMemo } from 'react'; import useTheme from '../styles/use-theme'; import { getStyles } from './styles'; import CardFooter from './card-footer'; import CardContent from './card-content'; import Image from '../image'; import { hasChild, pickChild } from '../utils/collections'; var defaultProps = { type: 'default', hoverable: false, shadow: false, width: '100%', className: '' }; var Card = function Card(_ref) { var children = _ref.children, hoverable = _ref.hoverable, className = _ref.className, shadow = _ref.shadow, type = _ref.type, width = _ref.width, props = _objectWithoutProperties(_ref, ["children", "hoverable", "className", "shadow", "type", "width"]); var theme = useTheme(); var hoverShadow = useMemo(function () { if (shadow) return theme.expressiveness.shadowMedium; return hoverable ? theme.expressiveness.shadowSmall : 'none'; }, [hoverable, shadow, theme.expressiveness]); var _useMemo = useMemo(function () { return getStyles(type, theme.palette, shadow); }, [type, theme.palette, shadow]), color = _useMemo.color, bgColor = _useMemo.bgColor, borderColor = _useMemo.borderColor; var _pickChild = pickChild(children, CardFooter), _pickChild2 = _slicedToArray(_pickChild, 2), withoutFooterChildren = _pickChild2[0], footerChildren = _pickChild2[1]; var _pickChild3 = pickChild(withoutFooterChildren, Image), _pickChild4 = _slicedToArray(_pickChild3, 2), withoutImageChildren = _pickChild4[0], imageChildren = _pickChild4[1]; var hasContent = hasChild(withoutImageChildren, CardContent); return /*#__PURE__*/React.createElement("div", _extends({}, props, { className: _JSXStyle.dynamic([["3053086214", [theme.palette.background, width, theme.layout.radius, shadow ? theme.expressiveness.shadowSmall : 'none', color, bgColor, borderColor, hoverShadow]]]) + " " + (props && props.className != null && props.className || "card ".concat(className)) }), imageChildren, hasContent ? withoutImageChildren : /*#__PURE__*/React.createElement(CardContent, null, withoutImageChildren), footerChildren, /*#__PURE__*/React.createElement(_JSXStyle, { id: "3053086214", dynamic: [theme.palette.background, width, theme.layout.radius, shadow ? theme.expressiveness.shadowSmall : 'none', color, bgColor, borderColor, hoverShadow] }, ".card.__jsx-style-dynamic-selector{background:".concat(theme.palette.background, ";margin:0;padding:0;width:").concat(width, ";-webkit-transition:all 0.2s ease;transition:all 0.2s ease;border-radius:").concat(theme.layout.radius, ";box-shadow:").concat(shadow ? theme.expressiveness.shadowSmall : 'none', ";box-sizing:border-box;color:").concat(color, ";background-color:").concat(bgColor, ";border:1px solid ").concat(borderColor, ";}.card.__jsx-style-dynamic-selector:hover{box-shadow:").concat(hoverShadow, ";}.card.__jsx-style-dynamic-selector img{width:100%;}.card.__jsx-style-dynamic-selector .image{border-bottom-left-radius:0;border-bottom-right-radius:0;}"))); }; Card.defaultProps = defaultProps; export default React.memo(Card);