lucid-ui
Version:
A UI component library from AppNexus.
175 lines (139 loc) • 9.02 kB
JavaScript
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 _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 { getFirst, omitProps } from '../../util/component-types';
import { buildModernHybridComponent } from '../../util/state-management';
import ChevronIcon from '../Icon/ChevronIcon/ChevronIcon';
import Collapsible from '../Collapsible/Collapsible';
import Button from '../Button/Button';
import Panel from '../Panel/Panel';
import * as reducers from '../Expander/Expander.reducers';
var cx = lucidClassNames.bind('&-ExpanderPanel');
var any = PropTypes.any,
bool = PropTypes.bool,
func = PropTypes.func,
node = PropTypes.node,
object = PropTypes.object,
string = PropTypes.string;
var Header = function Header(_props) {
return null;
};
Header.displayName = 'ExpanderPanel.Header';
Header.peek = {
description: "\n\t\tRenders a `<span>` of content next to the `ChevronIcon` in the\n\t\t`Panel.Header`\n\t"
};
Header.propName = 'Header';
Header.propTypes = {
children: node
};
var ExpanderPanel = /*#__PURE__*/function (_React$Component) {
_inherits(ExpanderPanel, _React$Component);
var _super = _createSuper(ExpanderPanel);
function ExpanderPanel() {
var _this;
_classCallCheck(this, ExpanderPanel);
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), "handleToggle", function (event) {
if (!_this.props.isDisabled) {
_this.props.onToggle(!_this.props.isExpanded, {
event: event,
props: _this.props
});
}
});
return _this;
}
_createClass(ExpanderPanel, [{
key: "render",
value: function render() {
var _this$props = this.props,
children = _this$props.children,
className = _this$props.className,
isExpanded = _this$props.isExpanded,
isDisabled = _this$props.isDisabled,
hasPadding = _this$props.hasPadding,
onRest = _this$props.onRest,
onRestAppliedOnCollapse = _this$props.onRestAppliedOnCollapse,
style = _this$props.style,
passThroughs = _objectWithoutProperties(_this$props, ["children", "className", "isExpanded", "isDisabled", "hasPadding", "onRest", "onRestAppliedOnCollapse", "style"]);
var headerChildProps = _get(getFirst(this.props, ExpanderPanel.Header), 'props');
var cleanedOnRest = onRestAppliedOnCollapse || isExpanded ? onRest : undefined;
return /*#__PURE__*/React.createElement(Panel, _extends({}, omitProps(passThroughs, undefined, _keys(ExpanderPanel.propTypes), false), {
className: cx('&', {
'&-is-collapsed': !isExpanded,
'&-is-disabled': isDisabled
}, className),
style: style,
isGutterless: !hasPadding
}), /*#__PURE__*/React.createElement(Panel.Header, {
className: cx('&-header'),
onClick: this.handleToggle
}, /*#__PURE__*/React.createElement(Button, {
className: cx('&-icon'),
kind: "invisible",
hasOnlyIcon: true
}, /*#__PURE__*/React.createElement(ChevronIcon, {
direction: isExpanded ? 'up' : 'down'
})), /*#__PURE__*/React.createElement("span", headerChildProps)), /*#__PURE__*/React.createElement(Collapsible, {
isExpanded: isExpanded,
className: cx('&-content', {
'&-content-is-expanded': isExpanded
}),
onRest: cleanedOnRest
}, /*#__PURE__*/React.createElement("div", {
className: cx('&-content-inner')
}, children)));
}
}]);
return ExpanderPanel;
}(React.Component);
_defineProperty(ExpanderPanel, "displayName", 'ExpanderPanel');
_defineProperty(ExpanderPanel, "Header", Header);
_defineProperty(ExpanderPanel, "propTypes", {
children: node,
className: string,
isExpanded: bool,
isDisabled: bool,
hasPadding: bool,
onToggle: func,
style: object,
onRest: func,
onRestAppliedOnCollapse: bool,
Header: any
});
_defineProperty(ExpanderPanel, "peek", {
description: "\n\t\t\t\t\tThis is a container that provides a toggle that controls when the\n\t\t\t\t\tcontent is shown.\n\t\t\t\t",
categories: ['layout'],
madeFrom: ['ChevronIcon', 'Expander', 'Panel']
});
_defineProperty(ExpanderPanel, "defaultProps", {
isExpanded: false,
onToggle: _noop,
hasPadding: true,
isDisabled: false
});
export default buildModernHybridComponent(ExpanderPanel, {
reducers: reducers
});
export { ExpanderPanel as ExpanderPanelDumb };