UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

98 lines (88 loc) 4.71 kB
import _keys from "lodash/keys"; import _get from "lodash/get"; function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } 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; } import React from 'react'; import PropTypes from 'react-peek/prop-types'; import { getFirst, omitProps } from '../../util/component-types'; import { lucidClassNames } from '../../util/style-helpers'; import LoadingIndicator from '../LoadingIndicator/LoadingIndicator'; import OverlayWrapper, { OverlayWrapperMessage } from '../OverlayWrapper/OverlayWrapper'; var cx = lucidClassNames.bind('&-EmptyStateWrapper'); var any = PropTypes.any, bool = PropTypes.bool, node = PropTypes.node, string = PropTypes.string; var EmptyStateWrapperBody = function EmptyStateWrapperBody(_props) { return null; }; var EmptyStateWrapperTitle = function EmptyStateWrapperTitle(_props) { return null; }; var defaultProps = { isEmpty: false, isLoading: false, anchorMessage: false }; export var EmptyStateWrapper = function EmptyStateWrapper(props) { var children = props.children, className = props.className, isEmpty = props.isEmpty, isLoading = props.isLoading, anchorMessage = props.anchorMessage, passThroughs = _objectWithoutProperties(props, ["children", "className", "isEmpty", "isLoading", "anchorMessage"]); var emptyMessageBodyProp = _get(getFirst(props, EmptyStateWrapperBody), 'props'); var emptyMessageTitleProp = _get(getFirst(props, EmptyStateWrapperTitle), 'props', { children: 'You have no data.' }); return isLoading ? /*#__PURE__*/React.createElement(LoadingIndicator, _extends({ className: cx('&', className), isLoading: true }, omitProps(passThroughs, undefined, _keys(EmptyStateWrapper.propTypes)), { anchorMessage: anchorMessage }), children) : /*#__PURE__*/React.createElement(OverlayWrapper, _extends({ className: cx('&', className), hasOverlay: false, isVisible: isEmpty, anchorMessage: anchorMessage }, omitProps(passThroughs, undefined, _keys(EmptyStateWrapper.propTypes))), /*#__PURE__*/React.createElement(OverlayWrapperMessage, { className: cx('&-message-container') }, /*#__PURE__*/React.createElement("div", { className: cx('&-message-header') }), /*#__PURE__*/React.createElement("div", { className: cx('&-message-contents') }, /*#__PURE__*/React.createElement("header", _extends({}, emptyMessageTitleProp, { className: cx('&-message-title', emptyMessageTitleProp.className) })), emptyMessageBodyProp && /*#__PURE__*/React.createElement("div", emptyMessageBodyProp))), children); }; EmptyStateWrapper._isPrivate = true; EmptyStateWrapper.peek = { description: "\n\t\tA wrapper which can display either a `LoadingIndicator` or\n\t\t`OverlayWrapper`.\n\t", categories: ['utility'], madeFrom: ['LoadingIndicator', 'OverlayWrapper'] }; EmptyStateWrapper.displayName = 'EmptyStateWrapper'; EmptyStateWrapper.defaultProps = defaultProps; EmptyStateWrapper.propTypes = { className: string, children: node, isEmpty: bool, isLoading: bool, anchorMessage: bool, Body: any, Title: any }; EmptyStateWrapperBody.displayName = 'EmptyStateWrapper.Body'; EmptyStateWrapper.Body = EmptyStateWrapperBody; EmptyStateWrapperBody.peek = { description: "\n\t\tBody content for the message to display when there is no data.\n\t" }; EmptyStateWrapperBody.propName = 'Body'; EmptyStateWrapperTitle.displayName = 'EmptyStateWrapper.Title'; EmptyStateWrapper.Title = EmptyStateWrapperTitle; EmptyStateWrapperTitle.peek = { description: "\n\t\tTitle text for the message to display when there is no data.\n\t" }; EmptyStateWrapperTitle.propName = 'Title'; export default EmptyStateWrapper;