UNPKG

lucid-ui

Version:

A UI component library from Xandr.

195 lines 8.84 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExpanderPanelDumb = void 0; var lodash_1 = __importStar(require("lodash")); var react_1 = __importDefault(require("react")); var prop_types_1 = __importDefault(require("prop-types")); var style_helpers_1 = require("../../util/style-helpers"); var component_types_1 = require("../../util/component-types"); var state_management_1 = require("../../util/state-management"); var ChevronIcon_1 = __importDefault(require("../Icon/ChevronIcon/ChevronIcon")); var Collapsible_1 = __importDefault(require("../Collapsible/Collapsible")); var Button_1 = __importDefault(require("../Button/Button")); var Panel_1 = __importDefault(require("../Panel/Panel")); var reducers = __importStar(require("../Expander/Expander.reducers")); var cx = style_helpers_1.lucidClassNames.bind('&-ExpanderPanel'); var any = prop_types_1.default.any, bool = prop_types_1.default.bool, func = prop_types_1.default.func, node = prop_types_1.default.node, object = prop_types_1.default.object, string = prop_types_1.default.string; var Header = function (_props) { return null; }; Header.displayName = 'ExpanderPanel.Header'; Header.peek = { description: "Renders a `<span>` of content next to the `ChevronIcon` in the `Panel.Header`.", }; Header.propName = 'Header'; Header.propTypes = { /** Used to identify the purpose of this switch to the user -- can be any renderable content. */ children: node, }; /** TODO: Remove the nonPassThroughs when the component is converted to a functional component */ var nonPassThroughs = [ 'className', 'isExpanded', 'onToggle', 'onRest', 'onRestAppliedOnCollapse', 'Header', 'isDisabled', 'hasPadding', 'initialState', ]; var ExpanderPanel = /** @class */ (function (_super) { __extends(ExpanderPanel, _super); function ExpanderPanel() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.handleToggle = function (event) { if (!_this.props.isDisabled) { _this.props.onToggle(!_this.props.isExpanded, { event: event, props: _this.props, }); } }; return _this; } ExpanderPanel.prototype.render = function () { var _a = this.props, children = _a.children, className = _a.className, isExpanded = _a.isExpanded, isDisabled = _a.isDisabled, hasPadding = _a.hasPadding, onRest = _a.onRest, onRestAppliedOnCollapse = _a.onRestAppliedOnCollapse, style = _a.style, passThroughs = __rest(_a, ["children", "className", "isExpanded", "isDisabled", "hasPadding", "onRest", "onRestAppliedOnCollapse", "style"]); var headerChildProps = lodash_1.default.get((0, component_types_1.getFirst)(this.props, ExpanderPanel.Header), 'props'); var cleanedOnRest = onRestAppliedOnCollapse || isExpanded ? onRest : undefined; return (react_1.default.createElement(Panel_1.default, __assign({}, (0, lodash_1.omit)(passThroughs, nonPassThroughs), { className: cx('&', { '&-is-collapsed': !isExpanded, '&-is-disabled': isDisabled, }, className), style: style, isGutterless: !hasPadding }), react_1.default.createElement(Panel_1.default.Header, { className: cx('&-header'), onClick: this.handleToggle }, react_1.default.createElement(Button_1.default, { className: cx('&-icon'), kind: 'invisible', hasOnlyIcon: true }, react_1.default.createElement(ChevronIcon_1.default, { direction: isExpanded ? 'up' : 'down' })), react_1.default.createElement("span", __assign({}, headerChildProps))), react_1.default.createElement(Collapsible_1.default, { isExpanded: isExpanded, className: cx('&-content', { '&-content-is-expanded': isExpanded, }), onRest: cleanedOnRest }, react_1.default.createElement("div", { className: cx('&-content-inner') }, children)))); }; ExpanderPanel.displayName = 'ExpanderPanel'; ExpanderPanel.Header = Header; ExpanderPanel.propTypes = { /** Expandable content. */ children: node, /** Appended to the component-specific class names set on the root element. */ className: string, /** Indicates that the component is in the "expanded" state when true and in the "unexpanded" state when false. */ isExpanded: bool, /** Indicates that the component is in the "disabled" state when true and in the "enabled" state when false. */ isDisabled: bool, /** Controls the presence of padding on the inner content. */ hasPadding: bool, /** Called when the user clicks on the component's header. Signature: \`(isExpanded, { event, props }) => {}\` */ onToggle: func, /** Passed through to the root element. */ style: object, /** Optional. The callback that fires when the animation comes to a rest. */ onRest: func, /* Applies on onRest callback when rest state is closed. */ onRestAppliedOnCollapse: bool, /** prop alternative to Header child component passed through to the underlying ExpanderPanel */ Header: any, }; ExpanderPanel.peek = { description: "An expandable container that provides a toggle that controls when the `Panel` content is shown.", categories: ['layout'], madeFrom: ['ChevronIcon', 'Expander', 'Panel'], }; ExpanderPanel.defaultProps = { isExpanded: false, onToggle: lodash_1.default.noop, hasPadding: true, isDisabled: false, }; return ExpanderPanel; }(react_1.default.Component)); exports.ExpanderPanelDumb = ExpanderPanel; exports.default = (0, state_management_1.buildModernHybridComponent)(ExpanderPanel, { reducers: reducers }); //# sourceMappingURL=ExpanderPanel.js.map