UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

271 lines (218 loc) 12.3 kB
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } import _keys from "lodash/keys"; import _first from "lodash/first"; import _get from "lodash/get"; import _noop from "lodash/noop"; 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; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import React from 'react'; import PropTypes from 'react-peek/prop-types'; import { lucidClassNames } from '../../util/style-helpers'; import { filterTypes, findTypes, omitProps } from '../../util/component-types'; import { buildModernHybridComponent } from '../../util/state-management'; import * as reducers from './Submarine.reducers'; import SplitHorizontal from '../SplitHorizontal/SplitHorizontal'; import ChevronIcon from '../Icon/ChevronIcon/ChevronIcon'; import GripperHorizontalIcon from '../Icon/GripperHorizontalIcon/GripperHorizontalIcon'; import Button from '../Button/Button'; var cx = lucidClassNames.bind('&-Submarine'); var any = PropTypes.any, bool = PropTypes.bool, func = PropTypes.func, node = PropTypes.node, number = PropTypes.number, string = PropTypes.string, oneOf = PropTypes.oneOf, oneOfType = PropTypes.oneOfType; var Primary = function Primary(_props) { return null; }; Primary.peek = { description: "\n\t\tPrimary content rendered beside the Submarine.\n\t" }; Primary.displayName = 'SplitHorizontal.Primary'; Primary.propName = 'Primary'; var Title = function Title(_props) { return null; }; Title.peek = { description: "\n\t\tSubmarine title;\n\t" }; Title.displayName = 'Submarine.Title'; Title.propName = 'Title'; var Bar = function Bar(_props) { return null; }; Bar.peek = { description: "\n\t\tSubmarine bar;\n\t" }; Bar.displayName = 'Submarine.Bar'; Bar.propName = 'Bar'; Bar.propTypes = { Title: any }; var defaultProps = { isExpanded: true, isAnimated: true, height: 250, position: 'bottom', isResizeDisabled: false, isHidden: false, isTitleShownCollapsed: false, onResizing: _noop, onResize: _noop, onToggle: _noop }; var Submarine = /*#__PURE__*/function (_React$Component) { _inherits(Submarine, _React$Component); var _super = _createSuper(Submarine); function Submarine() { var _this; _classCallCheck(this, Submarine); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "handleExpanderClick", function (_ref) { var event = _ref.event; var onToggle = _this.props.onToggle; onToggle({ props: _this.props, event: event }); }); _defineProperty(_assertThisInitialized(_this), "handleResizing", function (height, _ref2) { var event = _ref2.event; var onResizing = _this.props.onResizing; onResizing(height, { props: _this.props, event: event }); }); _defineProperty(_assertThisInitialized(_this), "handleResize", function (height, _ref3) { var event = _ref3.event; var onResize = _this.props.onResize; onResize(height, { props: _this.props, event: event }); }); return _this; } _createClass(Submarine, [{ key: "render", value: function render() { var _this$props = this.props, children = _this$props.children, className = _this$props.className, isExpanded = _this$props.isExpanded, isAnimated = _this$props.isAnimated, position = _this$props.position, isResizeDisabled = _this$props.isResizeDisabled, height = _this$props.height, isHidden = _this$props.isHidden, isTitleShownCollapsed = _this$props.isTitleShownCollapsed, passThroughs = _objectWithoutProperties(_this$props, ["children", "className", "isExpanded", "isAnimated", "position", "isResizeDisabled", "height", "isHidden", "isTitleShownCollapsed"]); var primaryProps = _get(_first(filterTypes(children, Submarine.Primary)), 'props', {}); // props from first Primary var barProps = _get(_first(filterTypes(children, Submarine.Bar)), 'props', {}); // props from first Bar var titleProps = _get(findTypes(barProps, Submarine.Title).concat(findTypes(this.props, Submarine.Title)), // get titles from Bar and parent Submarine '[0].props', // select props from the first title element /*#__PURE__*/ React.createElement(Submarine.Title).props // default props ); var PrimaryPane, BarPane; // using Left/Right Pane as primary depends on position if (position !== 'bottom') { PrimaryPane = SplitHorizontal.BottomPane; BarPane = SplitHorizontal.TopPane; } else { PrimaryPane = SplitHorizontal.TopPane; BarPane = SplitHorizontal.BottomPane; } // leave 33px of sidebar to stick out when collapsed, or 0px if hidden var collapseShift = isHidden ? 0 : 33; return /*#__PURE__*/React.createElement(SplitHorizontal, _extends({}, omitProps(passThroughs, undefined, _keys(Submarine.propTypes), false), { className: cx('&', { '&-is-resize-disabled': isResizeDisabled, '&-is-position-bottom': position === 'bottom', '&-is-position-top': position !== 'bottom' }, className), isAnimated: isAnimated, isExpanded: isExpanded && !isHidden, collapseShift: collapseShift, onResizing: this.handleResizing, onResize: this.handleResize }), /*#__PURE__*/React.createElement(BarPane, _extends({}, omitProps(barProps, undefined, _keys(Submarine.Bar.propTypes), false), { className: cx('&-Bar', barProps.className), height: height }), /*#__PURE__*/React.createElement("div", { className: cx('&-Bar-overlay') }), /*#__PURE__*/React.createElement("div", { className: cx('&-Bar-header') }, /*#__PURE__*/React.createElement("div", _extends({}, titleProps, { className: cx('&-Bar-Title', { '&-Bar-Title-is-shown-collapsed': isTitleShownCollapsed }, titleProps.className) })), /*#__PURE__*/React.createElement(Button, { className: cx('&-expander'), kind: "invisible", onClick: this.handleExpanderClick, hasOnlyIcon: true }, /*#__PURE__*/React.createElement(ChevronIcon, { direction: isExpanded && position === 'bottom' || !isExpanded && position !== 'bottom' ? 'down' : 'up' }))), /*#__PURE__*/React.createElement("div", { className: cx('&-Bar-content') }, barProps.children)), /*#__PURE__*/React.createElement(SplitHorizontal.Divider, { className: cx('&-Divider') }, /*#__PURE__*/React.createElement(GripperHorizontalIcon, { className: cx('&-Divider-gripper') })), /*#__PURE__*/React.createElement(PrimaryPane, _extends({}, primaryProps, { className: cx('&-Primary', primaryProps.className), isPrimary: true }))); } }]); return Submarine; }(React.Component); _defineProperty(Submarine, "displayName", 'Submarine'); _defineProperty(Submarine, "Bar", Bar); _defineProperty(Submarine, "Title", Title); _defineProperty(Submarine, "Primary", Primary); _defineProperty(Submarine, "peek", { description: "\n\t\t\t\t`Submarine` renders a collapsible, resizeable side bar panel next to\n\t\t\t\tprimary content.\n\t\t\t", categories: ['layout'], madeFrom: ['SplitHorizontal', 'ChevronIcon', 'GripperHorizontalIcon'] }); _defineProperty(Submarine, "reducers", reducers); _defineProperty(Submarine, "propTypes", { className: string, children: node, height: oneOfType([number, string]), isExpanded: bool, isHidden: bool, isTitleShownCollapsed: bool, isAnimated: bool, position: oneOf(['top', 'bottom']), isResizeDisabled: bool, Title: any, Bar: any, Primary: any, onResizing: func, onResize: func, onToggle: func }); _defineProperty(Submarine, "defaultProps", defaultProps); export default buildModernHybridComponent(Submarine, { reducers: reducers }); export { Submarine as SubmarineDumb };