UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

155 lines 10.7 kB
"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.ExpanderDumb = 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 reducers = __importStar(require("./Expander.reducers")); var Button_1 = __importDefault(require("../Button/Button")); var cx = style_helpers_1.lucidClassNames.bind('&-Expander'); 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, oneOf = prop_types_1.default.oneOf, string = prop_types_1.default.string; var Label = function (_props) { return null; }; Label.displayName = 'Expander.Label'; Label.peek = { description: "\n\t\t\t\t\t\tRenders a `<span>` to be shown next to the expander icon.\n\t\t\t\t\t", }; Label.propName = 'Label'; Label.propTypes = { children: node(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\t\t\t\tUsed to identify the purpose of this switch to the user -- can be any\n\t\t\t\t\trenderable content.\n\t\t\t\t"], ["\n\t\t\t\t\tUsed to identify the purpose of this switch to the user -- can be any\n\t\t\t\t\trenderable content.\n\t\t\t\t"]))), }; var AdditionalLabelContent = function (_props) { return null; }; AdditionalLabelContent.displayName = 'Expander.AdditionalLabelContent'; AdditionalLabelContent.peek = { description: "\n\t\t\t\t\t\tRenders a `<span>` to be shown next to the expander label.\n\t\t\t\t\t", }; AdditionalLabelContent.propName = 'AdditionalLabelContent'; AdditionalLabelContent.propTypes = { children: node(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\t\t\t\tUsed to display additional information or/and actions next to expander label.\n\t\t\t\t"], ["\n\t\t\t\t\tUsed to display additional information or/and actions next to expander label.\n\t\t\t\t"]))), }; var defaultProps = { isExpanded: false, onToggle: lodash_1.default.noop, kind: 'simple', }; var Expander = /** @class */ (function (_super) { __extends(Expander, _super); function Expander() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.handleToggle = function (event) { _this.props.onToggle(!_this.props.isExpanded, { event: event, props: _this.props, }); }; return _this; } Expander.prototype.render = function () { var _a = this.props, children = _a.children, className = _a.className, isExpanded = _a.isExpanded, style = _a.style, kind = _a.kind, passThroughs = __rest(_a, ["children", "className", "isExpanded", "style", "kind"]); var labelChildProp = lodash_1.default.first(lodash_1.default.map(component_types_1.findTypes(this.props, Expander.Label), 'props')); var additionalLabelContentChildProp = lodash_1.default.first(lodash_1.default.map(component_types_1.findTypes(this.props, Expander.AdditionalLabelContent), 'props')); return (react_1.default.createElement("div", __assign({}, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(Expander.propTypes)), { className: cx('&', { '&-is-expanded': isExpanded, '&-kind-highlighted': kind === 'highlighted', }, className), style: style }), react_1.default.createElement("header", { className: cx('&-header') }, react_1.default.createElement("div", { className: cx('&-header-toggle'), 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' })), labelChildProp && (react_1.default.createElement("span", { className: cx('&-text') }, labelChildProp.children))), additionalLabelContentChildProp && (react_1.default.createElement("div", { className: cx('&-additional-content') }, additionalLabelContentChildProp.children))), react_1.default.createElement(Collapsible_1.default, { isExpanded: isExpanded, rootType: 'section', className: cx('&-content') }, children))); }; Expander.displayName = 'Expander'; Expander.propTypes = { children: node(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\t\tExpandable content.\n\t\t"], ["\n\t\t\tExpandable content.\n\t\t"]))), className: string(templateObject_4 || (templateObject_4 = __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_5 || (templateObject_5 = __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"]))), onToggle: func(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\t\tCalled when the user clicks on the component's header. Signature:\n\t\t\t`(isExpanded, { event, props }) => {}`\n\t\t"], ["\n\t\t\tCalled when the user clicks on the component's header. Signature:\n\t\t\t\\`(isExpanded, { event, props }) => {}\\`\n\t\t"]))), style: object(templateObject_7 || (templateObject_7 = __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"]))), Label: any(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n\t\t\tChild element whose children represents content to be shown next to the\n\t\t\texpander icon.\n\t\t"], ["\n\t\t\tChild element whose children represents content to be shown next to the\n\t\t\texpander icon.\n\t\t"]))), AdditionalLabelContent: node(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n\t\t\tChild element whose children respresent content to be shown inside\n\t\t\tExpander.Label and to the right of it\n\t\t"], ["\n\t\t\tChild element whose children respresent content to be shown inside\n\t\t\tExpander.Label and to the right of it\n\t\t"]))), kind: oneOf(['simple', 'highlighted'])(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n\t\t\tRenders different variants of Expander. 'simple' is default.\n\t\t\t'highlighted' is more prominant.\n\t\t"], ["\n\t\t\tRenders different variants of Expander. 'simple' is default.\n\t\t\t'highlighted' is more prominant.\n\t\t"]))), }; Expander.defaultProps = defaultProps; Expander.reducers = reducers; Expander.Label = Label; Expander.AdditionalLabelContent = AdditionalLabelContent; Expander.peek = { description: "\n\t\t\t\tThis is a container that provides a toggle that controls when the\n\t\t\t\tcontent is shown.\n\t\t\t", categories: ['layout'], madeFrom: ['ChevronIcon'], }; return Expander; }(react_1.default.Component)); exports.ExpanderDumb = Expander; exports.default = state_management_1.buildModernHybridComponent(Expander, { reducers: reducers }); var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10; //# sourceMappingURL=Expander.js.map