UNPKG

@enact/ui

Version:

A collection of simplified unstyled cross-platform UI components for Enact

225 lines (221 loc) 8.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.CardDecorator = exports.CardBase = exports.Card = void 0; var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types")); var _kind = _interopRequireDefault(require("@enact/core/kind")); var _propTypes2 = _interopRequireDefault(require("prop-types")); var _compose = _interopRequireDefault(require("ramda/src/compose")); var _ComponentOverride = _interopRequireDefault(require("../ComponentOverride")); var _ForwardRef = _interopRequireDefault(require("../ForwardRef")); var _Image = _interopRequireDefault(require("../Image")); var _Layout = require("../Layout"); var _CardModule = _interopRequireDefault(require("./Card.module.css")); var _jsxRuntime = require("react/jsx-runtime"); var _excluded = ["imageComponent"], _excluded2 = ["captionOverlay", "children", "componentRef", "css", "imageComponent", "orientation", "placeholder", "src"]; /** * Unstyled card components and behaviors to be customized by a theme or application. * * @module ui/Card * @exports Card * @exports CardBase * @exports CardDecorator */ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } 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; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } function ImageOverride(_ref) { var imageComponent = _ref.imageComponent, rest = _objectWithoutProperties(_ref, _excluded); return (0, _ComponentOverride["default"])(_objectSpread({ component: imageComponent }, rest)); } /** * A basic card without any behavior. * * @class CardBase * @memberof ui/Card * @ui * @public */ var CardBase = exports.CardBase = (0, _kind["default"])({ name: 'ui:Card', propTypes: /** @lends ui/Card.CardBase.prototype */{ /** * Determines whether the caption will be placed over the image or not. * * @type {Boolean} * @default false * @public */ captionOverlay: _propTypes2["default"].bool, /** * The caption node to be displayed with the image. * @type {Node} * @public */ children: _propTypes2["default"].node, /** * Called with a reference to the root component. * * When using {@link ui/Card.Card}, the `ref` prop is forwarded to this component * as `componentRef`. * * @type {Object|Function} * @public */ componentRef: _propTypes["default"].ref, /** * Customizes the component by mapping the supplied collection of CSS class names to the * corresponding internal elements and states of this component. * * The following classes are supported. * * @type {Object} * @public */ css: _propTypes2["default"].object, /** * Fits the image to its height and width and positions it on the center of the Card * * @type {Boolean} * @public */ fitImage: _propTypes2["default"].bool, /** * The component used to render the image component. * * @type {Component|Element} * @default {@link ui/Image.Image} * @public */ imageComponent: _propTypes["default"].componentOverride, /** * The layout orientation of the component. * * @type {('horizontal'|'vertical')} * @default 'vertical' * @public */ orientation: _propTypes2["default"].oneOf(['horizontal', 'vertical']), /** * A placeholder image to be displayed before the image is loaded. * * @type {String} * @public */ placeholder: _propTypes2["default"].string, /** * Applies a selected visual effect to the image. * * @type {Boolean} * @default false * @public */ selected: _propTypes2["default"].bool, /** * String value or object of values used to determine which image will appear on a specific * screenSize. * * @type {String|Object} * @public */ src: _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].object]) }, defaultProps: { imageComponent: _Image["default"], orientation: 'vertical' }, styles: { css: _CardModule["default"], className: 'card', publicClassNames: true }, computed: { className: function className(_ref2) { var captionOverlay = _ref2.captionOverlay, fitImage = _ref2.fitImage, orientation = _ref2.orientation, selected = _ref2.selected, styler = _ref2.styler; return styler.append({ captionOverlay: captionOverlay && orientation === 'vertical', selected: selected, fitImage: fitImage, horizontal: orientation === 'horizontal', vertical: orientation === 'vertical' }); } }, render: function render(_ref3) { var captionOverlay = _ref3.captionOverlay, children = _ref3.children, componentRef = _ref3.componentRef, css = _ref3.css, imageComponent = _ref3.imageComponent, orientation = _ref3.orientation, placeholder = _ref3.placeholder, src = _ref3.src, rest = _objectWithoutProperties(_ref3, _excluded2); delete rest.fitImage; var isHorizontal = orientation === 'horizontal'; var isCaptionOverlay = captionOverlay && !isHorizontal; var Component = isHorizontal ? _Layout.Row : _Layout.Column; var Wrapped = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, { children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, { className: css.image, component: ImageOverride, imageComponent: imageComponent, placeholder: placeholder, shrink: true, src: src }), children ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, { className: css.children, shrink: !isHorizontal // eslint-disable-next-line no-undefined , align: isHorizontal ? 'center' : undefined, children: children }) : null] }); return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread(_objectSpread({}, rest), {}, { ref: componentRef, children: isCaptionOverlay ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { className: css.imageContainer, children: Wrapped }) : Wrapped })); } }); /** * A higher-order component that adds behaviors to an {@link ui/Card.CardBase|Card}. * * @hoc * @memberof ui/Card * @mixes ui/ForwardRef.ForwardRef * @public */ var CardDecorator = exports.CardDecorator = (0, _compose["default"])((0, _ForwardRef["default"])({ prop: 'componentRef' })); /** * A minimally styled Card ready for customization by a theme. * * @class Card * @memberof ui/Card * @extends ui/Card.CardBase * @mixes ui/Card.CardDecorator * @omit componentRef * @ui * @public */ var Card = exports.Card = CardDecorator(CardBase); var _default = exports["default"] = Card;