lucid-ui
Version:
A UI component library from AppNexus.
148 lines • 10.4 kB
JavaScript
"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
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) {
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 = __importDefault(require("lodash"));
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("react-peek/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: "\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(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\tUsed to identify the purpose of this switch to the user -- can be any\n\t\trenderable content.\n\t"], ["\n\t\tUsed to identify the purpose of this switch to the user -- can be any\n\t\trenderable content.\n\t"]))),
};
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(component_types_1.getFirst(this.props, ExpanderPanel.Header), 'props');
var cleanedOnRest = onRestAppliedOnCollapse || isExpanded ? onRest : undefined;
return (react_1.default.createElement(Panel_1.default, __assign({}, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(ExpanderPanel.propTypes), false), { 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 = {
children: node(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\t\tExpandable content.\n\t\t"], ["\n\t\t\tExpandable content.\n\t\t"]))),
className: string(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t"], ["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t"]))),
isExpanded: bool(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\t\tIndicates that the component is in the \"expanded\" state when true and in\n\t\t\tthe \"unexpanded\" state when false.\n\t\t"], ["\n\t\t\tIndicates that the component is in the \"expanded\" state when true and in\n\t\t\tthe \"unexpanded\" state when false.\n\t\t"]))),
isDisabled: bool(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\t\tIndicates that the component is in the \"disabled\" state when true and in\n\t\t\tthe \"enabled\" state when false.\n\t\t"], ["\n\t\t\tIndicates that the component is in the \"disabled\" state when true and in\n\t\t\tthe \"enabled\" state when false.\n\t\t"]))),
hasPadding: bool(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\t\tControls the presence of padding on the inner content.\n\t\t"], ["\n\t\t\tControls the presence of padding on the inner content.\n\t\t"]))),
onToggle: func(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\t\tCalled when the user clicks on the component's header.\n\t\t\tSignature: `(isExpanded, { event, props }) => {}`\n\t\t"], ["\n\t\t\tCalled when the user clicks on the component's header.\n\t\t\tSignature: \\`(isExpanded, { event, props }) => {}\\`\n\t\t"]))),
style: object(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n\t\t\tPassed through to the root element.\n\t\t"], ["\n\t\t\tPassed through to the root element.\n\t\t"]))),
onRest: func(templateObject_9 || (templateObject_9 = __makeTemplateObject(["Optional. The callback that fires when the animation comes to a rest."], ["Optional. The callback that fires when the animation comes to a rest."]))),
onRestAppliedOnCollapse: bool(templateObject_10 || (templateObject_10 = __makeTemplateObject(["Applies on onRest callback when rest state is closed."], ["Applies on onRest callback when rest state is closed."]))),
Header: any(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n\t\t\tprop alternative to Header child component passed through to the\n\t\t\tunderlying ExpanderPanel\n\t\t"], ["\n\t\t\tprop alternative to Header child component passed through to the\n\t\t\tunderlying ExpanderPanel\n\t\t"]))),
};
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'],
};
ExpanderPanel.defaultProps = {
isExpanded: false,
onToggle: lodash_1.default.noop,
hasPadding: true,
isDisabled: false,
};
return ExpanderPanel;
}(react_1.default.Component));
exports.ExpanderPanelDumb = ExpanderPanel;
exports.default = state_management_1.buildModernHybridComponent(ExpanderPanel, { reducers: reducers });
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11;
//# sourceMappingURL=ExpanderPanel.js.map