@enact/ui
Version:
A collection of simplified unstyled cross-platform UI components for Enact
250 lines (249 loc) • 10.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.GridListImageItem = void 0;
var _deprecate = _interopRequireDefault(require("@enact/core/internal/deprecate"));
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _react = require("react");
var _Layout = require("../Layout");
var _Icon = _interopRequireDefault(require("../Icon"));
var _Image = _interopRequireDefault(require("../Image"));
var _GridListImageItemModule = _interopRequireDefault(require("./GridListImageItem.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["css", "imageComponent", "placeholder", "source", "selectionOverlay", "subComponents"];
/**
* Unstyled grid list image item components and behaviors to be customized by a theme or application.
*
* @module ui/GridListImageItem
* @exports GridListImageItem
* @deprecated Will be removed in 5.0.0. Use {@link ui/ImageItem} instead.
*/
/**
* A basic grid list image item without any behavior.
*
* @class GridListImageItem
* @memberof ui/GridListImageItem
* @ui
* @public
*/
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(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(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; }
var GridListImageItem = exports.GridListImageItem = (0, _kind["default"])({
name: 'ui:GridListImageItem',
propTypes: /** @lends ui/GridListImageItem.GridListImageItem.prototype */{
/**
* The primary caption to be displayed with the image.
*
* @type {String}
* @public
*/
caption: _propTypes2["default"].string,
/**
* The component used to render the captions
*
* @type {String|Component}
* @public
*/
captionComponent: _propTypes["default"].renderable,
/**
* 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:
*
* * `icon` - The icon component class for default selection overlay
* * `image` - The image component class
* * `selected` - Applied when `selected` prop is `true`
* * `caption` - The caption component class
* * `subCaption` - The subCaption component class
*
* @type {Object}
* @public
*/
css: _propTypes2["default"].object,
/**
* The component used to render the default check icon when selected.
* If there is custom selectionOverlay component, this icon will not be shown.
*
* @type {Component}
* @default ui/Icon.Icon
* @public
*/
iconComponent: _propTypes["default"].component,
/**
* The component used to render the image component
*
* @type {Component}
* @default ui/Image.Image
* @public
*/
imageComponent: _propTypes["default"].component,
/**
* Placeholder image used while {@link ui/GridListImageItem.GridListImageItem.source|source}
* is loaded.
*
* @type {String}
* @public
*/
placeholder: _propTypes2["default"].string,
/**
* Applies a selected visual effect to the image, but only if `selectionOverlayShowing`
* is also `true`.
*
* @type {Boolean}
* @default false
* @public
*/
selected: _propTypes2["default"].bool,
/**
* The custom selection overlay component to render.
*
* A component can be a stateless functional component, `kind()` or React component.
* The following is an example with custom selection overlay kind.
*
* Example:
* ```
* const SelectionOverlay = kind({
* render: () => <div>custom overlay</div>
* });
*
* <GridListImageItem selectionOverlay={SelectionOverlay} />
* ```
*
* @type {Function}
* @public
*/
selectionOverlay: _propTypes2["default"].func,
/**
* Shows a selection overlay with a centered icon. When `selected` is true, a check mark is shown.
*
* @type {Boolean}
* @default false
* @public
*/
selectionOverlayShowing: _propTypes2["default"].bool,
/**
* The absolute URL path to the image.
*
* @type {String}
* @public
*/
source: _propTypes2["default"].string,
/**
* The second caption line to be displayed with the image.
*
* @type {String}
* @public
*/
subCaption: _propTypes2["default"].string,
/**
* The components that will be shown below the image.
*
* @type {Array|Element}
* @private
*/
subComponents: _propTypes2["default"].oneOfType([_propTypes2["default"].array, _propTypes2["default"].element])
},
defaultProps: {
captionComponent: 'div',
iconComponent: _Icon["default"],
imageComponent: _Image["default"],
selected: false,
selectionOverlayShowing: false
},
styles: {
css: _GridListImageItemModule["default"],
className: 'gridListImageItem',
publicClassNames: true
},
computed: {
className: function className(_ref) {
var caption = _ref.caption,
selected = _ref.selected,
styler = _ref.styler,
subCaption = _ref.subCaption;
return styler.append({
selected: selected,
caption: caption,
subCaption: subCaption
});
},
selectionOverlay: function selectionOverlay(_ref2) {
var css = _ref2.css,
IconComponent = _ref2.iconComponent,
SelectionOverlay = _ref2.selectionOverlay,
selectionOverlayShowing = _ref2.selectionOverlayShowing;
if (selectionOverlayShowing) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: css.overlayContainer,
children: SelectionOverlay ? /*#__PURE__*/(0, _jsxRuntime.jsx)(SelectionOverlay, {}) : /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: css.overlayComponent,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(IconComponent, {
className: css.icon,
children: "check"
})
})
});
}
},
subComponents: function subComponents(_ref3) {
var caption = _ref3.caption,
Caption = _ref3.captionComponent,
css = _ref3.css,
subCaption = _ref3.subCaption,
_subComponents = _ref3.subComponents;
return _subComponents ? _subComponents : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
children: [caption ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
className: css.caption,
component: Caption,
shrink: true,
children: caption
}) : null, subCaption ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
className: css.subCaption,
component: Caption,
shrink: true,
children: subCaption
}) : null]
});
}
},
render: (0, _deprecate["default"])(function (_ref4) {
var css = _ref4.css,
ImageComponent = _ref4.imageComponent,
placeholder = _ref4.placeholder,
source = _ref4.source,
selectionOverlay = _ref4.selectionOverlay,
subComponents = _ref4.subComponents,
rest = _objectWithoutProperties(_ref4, _excluded);
delete rest.caption;
delete rest.captionComponent;
delete rest.iconComponent;
delete rest.selected;
delete rest.selectionOverlayShowing;
delete rest.subCaption;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Layout.Column, _objectSpread(_objectSpread({}, rest), {}, {
inline: true,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
className: css.image,
component: ImageComponent,
placeholder: placeholder,
src: source,
children: selectionOverlay
}), subComponents]
}));
}, {
name: 'ui/GridListImageItem',
replacedBy: 'ui/ImageItem',
until: '5.0.0'
})
});
var _default = exports["default"] = GridListImageItem;