UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

496 lines 38.1 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 __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.OptionGroup = exports.NullOption = exports.DropMenuDumb = void 0; var react_1 = __importDefault(require("react")); var prop_types_1 = __importDefault(require("react-peek/prop-types")); var lodash_1 = __importDefault(require("lodash")); var style_helpers_1 = require("../../util/style-helpers"); var component_types_1 = require("../../util/component-types"); var dom_helpers_1 = require("../../util/dom-helpers"); var state_management_1 = require("../../util/state-management"); var KEYCODE = __importStar(require("../../constants/key-code")); var reducers = __importStar(require("./DropMenu.reducers")); var ContextMenu_1 = __importDefault(require("../ContextMenu/ContextMenu")); function joinArray(array, getSeparator) { return lodash_1.default.reduce(array, function (newArray, element, index) { newArray.push(element); if (index < lodash_1.default.size(array) - 1) { newArray.push(getSeparator(element, index, array)); } return newArray; }, []); } function isOptionVisible(option) { return !option.optionProps.isHidden; } var cx = style_helpers_1.lucidClassNames.bind('&-DropMenu'); var any = prop_types_1.default.any, arrayOf = prop_types_1.default.arrayOf, bool = prop_types_1.default.bool, func = prop_types_1.default.func, node = prop_types_1.default.node, number = prop_types_1.default.number, object = prop_types_1.default.object, oneOf = prop_types_1.default.oneOf, string = prop_types_1.default.string; var Header = function (_props) { return null; }; Header.displayName = 'DropMenu.Header'; Header.peek = { description: "\n\t\tAn optional header to be displayed within the expanded Flyout,\n\t\tabove all `Option`s.\n\t", }; Header.propName = 'Header'; Header.propTypes = {}; var Control = function (_props) { return null; }; Control.displayName = 'DropMenu.Control'; Control.peek = { description: "\n\t\tRenders a `<div>` that acts as the control target which the\n\t\tflyout menu is anchored to. Only one `Control` is used.\n\t", }; Control.propName = 'Control'; Control.propTypes = {}; var OptionGroup = function (_props) { return null; }; exports.OptionGroup = OptionGroup; OptionGroup.displayName = 'DropMenu.OptionGroup'; OptionGroup.peek = { description: "\n\t\tA special kind of `Option` that is always rendered at the top of\n\t\tthe menu and has an `optionIndex` of `null`. Useful for\n\t\tunselect.\n\t", }; OptionGroup.propName = 'OptionGroup'; OptionGroup.propTypes = { isHidden: bool(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\thides the `OptionGroup` from the list.\n\t"], ["\n\t\thides the \\`OptionGroup\\` from the list.\n\t"]))), }; OptionGroup.defaultProps = { isHidden: false, }; var Option = function (_props) { return null; }; Option.displayName = 'DropMenu.Option'; Option.peek = { description: "\n\t\tRenders a `<div>` that acts as an option in the menu.\n\t", }; Option.propName = 'Option'; Option.propTypes = { isDisabled: bool(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\tdisables selection of the `Option`.\n\t"], ["\n\t\tdisables selection of the \\`Option\\`.\n\t"]))), isHidden: bool(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\thides the `Option` from the list.\n\t"], ["\n\t\thides the \\`Option\\` from the list.\n\t"]))), isWrapped: bool(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\tcontrols wrapping of the text.\n\t"], ["\n\t\tcontrols wrapping of the text.\n\t"]))), }; Option.defaultProps = { isDisabled: false, isHidden: false, isWrapped: true, }; var NullOption = function (_props) { return null; }; exports.NullOption = NullOption; NullOption.displayName = 'DropMenu.NullOption'; NullOption.peek = { description: "\n\t\tA special kind of `Option` that is always rendered at the top of\n\t\tthe menu and has an `optionIndex` of `null` used for\n\t\tdeselecting.\n\t", }; NullOption.propName = 'NullOption'; NullOption.propTypes = {}; var FixedOption = function (_props) { return null; }; FixedOption.displayName = 'DropMenu.FixedOption'; FixedOption.peek = { description: "\n\t\tA special kind of `Option` that is always rendered at the top of\n\t\tthe menu.\n\t", }; FixedOption.propName = 'FixedOption'; FixedOption.propTypes = { isDisabled: bool(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\tdisables selection of the `Option`.\n\t"], ["\n\t\tdisables selection of the \\`Option\\`.\n\t"]))), isHidden: bool(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\thides the `Option` from the list.\n\t"], ["\n\t\thides the \\`Option\\` from the list.\n\t"]))), isWrapped: bool(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\tcontrols wrapping of the text.\n\t"], ["\n\t\tcontrols wrapping of the text.\n\t"]))), }; FixedOption.defaultProps = { isDisabled: false, isHidden: false, isWrapped: true, }; var DropMenuContextMenu = function (_props) { return null; }; DropMenuContextMenu.displayName = 'DropMenu.ContextMenu'; DropMenuContextMenu.peek = { description: "\n\t\tProps that are passed through to the underlying ContextMenu.\n\t", }; DropMenuContextMenu.propName = 'ContextMenu'; DropMenuContextMenu.propTypes = { children: node(templateObject_8 || (templateObject_8 = __makeTemplateObject([""], [""]))), }; var DropMenu = /** @class */ (function (_super) { __extends(DropMenu, _super); function DropMenu(props) { var _this = _super.call(this, props) || this; _this.getPreprocessedOptionData = function (props) { return DropMenu.preprocessOptionData(props, DropMenu); }; _this.handleKeydown = function (event) { var _a = _this, props = _a.props, _b = _a.props, isExpanded = _b.isExpanded, focusedIndex = _b.focusedIndex, onExpand = _b.onExpand, onCollapse = _b.onCollapse, onSelect = _b.onSelect, onFocusOption = _b.onFocusOption; var _c = _this.state, flattenedOptionsData = _c.flattenedOptionsData, nullOptions = _c.nullOptions; _this.setState({ isMouseTriggered: false, }); if (isExpanded) { if (event.keyCode === KEYCODE.Enter) { event.preventDefault(); var focusedOptionData = lodash_1.default.get(flattenedOptionsData, lodash_1.default.isNil(focusedIndex) ? '' : focusedIndex, null); var focusedOptionProps = lodash_1.default.get(focusedOptionData, 'optionProps', Option.defaultProps); if (focusedOptionData && !focusedOptionProps.isDisabled) { onSelect && onSelect(focusedIndex, { props: focusedOptionProps, event: event }); } else if (lodash_1.default.isNull(focusedIndex)) { onSelect && onSelect(null, { props: lodash_1.default.first(nullOptions), event: event }); } } if (event.keyCode === KEYCODE.Escape) { event.preventDefault(); onCollapse && onCollapse({ props: props, event: event }); } if (event.keyCode === KEYCODE.ArrowUp) { if (lodash_1.default.isNumber(focusedIndex) || lodash_1.default.isNull(focusedIndex)) { if (focusedIndex === 0) { if (!lodash_1.default.isEmpty(nullOptions)) { event.preventDefault(); onFocusOption && onFocusOption(null, { props: props, event: event }); } } if (!lodash_1.default.isNil(focusedIndex) && focusedIndex > 0) { event.preventDefault(); onFocusOption && onFocusOption(lodash_1.default.findLastIndex(flattenedOptionsData, isOptionVisible, focusedIndex - 1), { props: props, event: event }); } } else { event.preventDefault(); focusedIndex && onFocusOption && onFocusOption(lodash_1.default.findLastIndex(flattenedOptionsData, isOptionVisible, focusedIndex - 1), { props: props, event: event }); } } if (event.keyCode === KEYCODE.ArrowDown) { if (lodash_1.default.isNumber(focusedIndex)) { if (focusedIndex < lodash_1.default.size(flattenedOptionsData) - 1) { event.preventDefault(); onFocusOption && onFocusOption(lodash_1.default.findIndex(flattenedOptionsData, isOptionVisible, focusedIndex + 1), { props: props, event: event }); } } else { event.preventDefault(); onFocusOption && onFocusOption(lodash_1.default.findIndex(flattenedOptionsData, isOptionVisible, !lodash_1.default.isNil(focusedIndex) ? focusedIndex : undefined), { props: props, event: event }); } } } else { if (event.keyCode === KEYCODE.ArrowDown) { event.preventDefault(); onExpand && onExpand({ props: props, event: event }); } } }; _this.handleClick = function (event) { var _a = _this, props = _a.props, _b = _a.props, isExpanded = _b.isExpanded, onExpand = _b.onExpand, onCollapse = _b.onCollapse; if (isExpanded) { onCollapse && onCollapse({ props: props, event: event }); } else { onExpand && onExpand({ props: props, event: event }); } }; _this.handleMouseFocusOption = function (optionIndex, optionProps, event) { var _a = _this.props, focusedIndex = _a.focusedIndex, onFocusOption = _a.onFocusOption; _this.setState({ isMouseTriggered: true, }); if (!optionProps.isDisabled && focusedIndex !== optionIndex) { onFocusOption && onFocusOption(optionIndex, { props: _this.props, event: event }); } }; _this.handleSelectOption = function (optionIndex, optionProps, event) { var onSelect = _this.props.onSelect; if (!optionProps.isDisabled) { onSelect && onSelect(optionIndex, { props: optionProps, event: event }); } }; _this.renderOption = function (optionProps, optionIndex, isGrouped) { if (isGrouped === void 0) { isGrouped = false; } var _a = _this.props, selectedIndices = _a.selectedIndices, focusedIndex = _a.focusedIndex; var isMouseTriggered = _this.state.isMouseTriggered; var isDisabled = optionProps.isDisabled, isHidden = optionProps.isHidden, isWrapped = optionProps.isWrapped; var isFocused = optionIndex === focusedIndex; var isSelected = lodash_1.default.includes(selectedIndices, optionIndex); return isHidden ? null : (react_1.default.createElement("div", __assign({ key: 'DropMenuOption' + optionIndex }, component_types_1.omitProps(optionProps, undefined, __spreadArrays(lodash_1.default.keys(DropMenu.Option.propTypes), [ 'Selection', ])), { onClick: function (event) { return _this.handleSelectOption(optionIndex, optionProps, event); }, onMouseMove: function (event) { return _this.handleMouseFocusOption(optionIndex, optionProps, event); }, className: cx('&-Option', { '&-Option-is-grouped': isGrouped, '&-Option-is-focused': isFocused, '&-Option-is-selected': isSelected, '&-Option-is-disabled': isDisabled, '&-Option-is-null': lodash_1.default.isNull(optionIndex), '&-Option-is-wrapped': isWrapped, }, optionProps.className), ref: function (optionHTMLElement) { if (isFocused && !isMouseTriggered) { dom_helpers_1.scrollParentTo(optionHTMLElement, _this._header && _this._header.current ? _this._header.current.offsetHeight : undefined); } } }))); }; _this.UNSAFE_componentWillReceiveProps = function (nextProps) { // only preprocess options data when it changes (via new props) - better performance than doing this each render _this.setState(_this.getPreprocessedOptionData(nextProps)); }; _this.state = __assign({ optionGroups: [], flattenedOptionsData: [], ungroupedOptionData: [], optionGroupDataLookup: {}, nullOptions: [], fixedOptionData: [], isMouseTriggered: false, portalId: _this.props.portalId || style_helpers_1.uniqueName('DropMenu-Portal-'), isExpanded: false, focusedIndex: null, optionGroupIndex: null, optionProps: [], selectedIndices: [] }, _this.getPreprocessedOptionData(props)); _this._header = react_1.default.createRef(); return _this; } DropMenu.prototype.render = function () { var _this = this; var _a = this.props, className = _a.className, style = _a.style, isDisabled = _a.isDisabled, isExpanded = _a.isExpanded, direction = _a.direction, alignment = _a.alignment, onCollapse = _a.onCollapse, flyOutStyle = _a.flyOutStyle, optionContainerStyle = _a.optionContainerStyle, passThroughs = __rest(_a, ["className", "style", "isDisabled", "isExpanded", "direction", "alignment", "onCollapse", "flyOutStyle", "optionContainerStyle"]); var _b = this.state, optionGroups = _b.optionGroups, fixedOptionData = _b.fixedOptionData, ungroupedOptionData = _b.ungroupedOptionData, optionGroupDataLookup = _b.optionGroupDataLookup, nullOptions = _b.nullOptions, portalId = _b.portalId; var contextMenuProps = lodash_1.default.get(component_types_1.getFirst(this.props, DropMenu.ContextMenu), 'props', {}); var controlProps = lodash_1.default.get(component_types_1.getFirst(this.props, DropMenu.Control), 'props', {}); var headerProps = lodash_1.default.get(component_types_1.getFirst(this.props, DropMenu.Header), 'props', {}); return (react_1.default.createElement("div", __assign({ className: cx('&', '&-base', { '&-is-expanded': isExpanded, '&-direction-down': isExpanded && direction === 'down', '&-direction-up': isExpanded && direction === 'up', }, className), style: style }, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(DropMenu.propTypes))), react_1.default.createElement(ContextMenu_1.default, __assign({}, contextMenuProps, { portalId: portalId, isExpanded: isExpanded, direction: direction, alignment: alignment, onClickOut: onCollapse }), react_1.default.createElement(ContextMenu_1.default.Target, null, react_1.default.createElement("div", __assign({}, (!isDisabled ? { tabIndex: 0, onClick: this.handleClick, onKeyDown: this.handleKeydown, } : null), controlProps, { className: cx('&-Control', lodash_1.default.get(controlProps, 'className')) }))), react_1.default.createElement(ContextMenu_1.default.FlyOut, { className: cx('&', className), style: flyOutStyle }, !lodash_1.default.isEmpty(headerProps) && (react_1.default.createElement("div", __assign({}, headerProps, { className: cx('&-Header', headerProps.className), onKeyDown: this.handleKeydown, ref: this._header }))), react_1.default.createElement("div", { className: cx('&-option-container'), style: lodash_1.default.assign({}, flyOutStyle, optionContainerStyle) }, lodash_1.default.map(nullOptions, function (optionProps) { return _this.renderOption(optionProps, null); }).concat(lodash_1.default.isEmpty(nullOptions) ? [] : [ react_1.default.createElement("div", { key: 'OptionGroup-divider-NullOption', className: cx('&-OptionGroup-divider') }), ]), // fixed options go first lodash_1.default.map(fixedOptionData, function (_a) { var optionProps = _a.optionProps, optionIndex = _a.optionIndex; return _this.renderOption(optionProps, optionIndex); }), joinArray( // for each option group, lodash_1.default.map(optionGroups, function (optionGroupProps, optionGroupIndex) { var groupedOptions = optionGroupDataLookup[optionGroupIndex]; if (optionGroupProps.isHidden || lodash_1.default.every(groupedOptions, { optionProps: { isHidden: true }, })) { return null; } var labelElements = component_types_1.rejectTypes(optionGroupProps.children, [ DropMenu.Control, DropMenu.OptionGroup, DropMenu.Option, DropMenu.NullOption, ]); // render label if there is one return (lodash_1.default.isEmpty(labelElements) ? [] : [ react_1.default.createElement("div", __assign({}, component_types_1.omitProps(optionGroupProps, undefined, lodash_1.default.keys(DropMenu.OptionGroup.propTypes)), { key: 'OptionGroup-label' + optionGroupIndex, className: cx('&-label', optionGroupProps.className) }), labelElements), ]).concat(lodash_1.default.map(optionGroupDataLookup[optionGroupIndex], function (_a) { var optionProps = _a.optionProps, optionIndex = _a.optionIndex; return _this.renderOption(optionProps, optionIndex, true); })); // append all ungrouped options as another unlabeled group }).concat(lodash_1.default.isEmpty(ungroupedOptionData) ? [] : [ lodash_1.default.map(ungroupedOptionData, function (_a) { var optionProps = _a.optionProps, optionIndex = _a.optionIndex; return _this.renderOption(optionProps, optionIndex); }), ]), function (element, index) { return element && (react_1.default.createElement("div", { key: "OptionGroup-divider-" + index, className: cx('&-OptionGroup-divider') })); } // separate each group with divider )))))); }; DropMenu.displayName = 'DropMenu'; DropMenu.ContextMenu = DropMenuContextMenu; DropMenu.FixedOption = FixedOption; DropMenu.NullOption = NullOption; DropMenu.Option = Option; DropMenu.OptionGroup = OptionGroup; DropMenu.Control = Control; DropMenu.Header = Header; DropMenu.peek = { ContextMenu: DropMenuContextMenu, description: "\n\t\t\t\t`DropMenu` is a helper component used to render a menu of options attached to\n\t\t\t\tany control. Supports option groups with and without labels as well as\n\t\t\t\tspecial options with a `null` index for unselect.\n\t\t\t", categories: ['helpers'], madeFrom: ['ContextMenu'], }; DropMenu.reducers = reducers; DropMenu.propTypes = { children: node(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n\t\t\tShould be instances of: `DropMenu.Control`, `DropMenu.Option`,\n\t\t\t`DropMenu.OptionGroup`, `DropMenu.Nulloption`. Other direct child\n\t\t\telements will not render.\n\t\t"], ["\n\t\t\tShould be instances of: \\`DropMenu.Control\\`, \\`DropMenu.Option\\`,\n\t\t\t\\`DropMenu.OptionGroup\\`, \\`DropMenu.Nulloption\\`. Other direct child\n\t\t\telements will not render.\n\t\t"]))), className: string(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n\t\t\tAppended to the component-specific class names set on the root elements.\n\t\t\tApplies to *both* the control and the flyout menu.\n\t\t"], ["\n\t\t\tAppended to the component-specific class names set on the root elements.\n\t\t\tApplies to *both* the control and the flyout menu.\n\t\t"]))), style: object(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n\t\t\tStyles that are passed through to root element.\n\t\t"], ["\n\t\t\tStyles that are passed through to root element.\n\t\t"]))), isDisabled: bool(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n\t\t\tDisables the DropMenu from being clicked or focused.\n\t\t"], ["\n\t\t\tDisables the DropMenu from being clicked or focused.\n\t\t"]))), isExpanded: bool(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n\t\t\tRenders the flyout menu adjacent to the control.\n\t\t"], ["\n\t\t\tRenders the flyout menu adjacent to the control.\n\t\t"]))), direction: oneOf(['down', 'up'])(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n\t\t\tSets the direction the flyout menu will render relative to the control.\n\t\t"], ["\n\t\t\tSets the direction the flyout menu will render relative to the control.\n\t\t"]))), alignment: oneOf(['start', 'center', 'end'])(templateObject_15 || (templateObject_15 = __makeTemplateObject(["\n\t\t\tSets the alignment the flyout menu will render relative to the control.\n\t\t"], ["\n\t\t\tSets the alignment the flyout menu will render relative to the control.\n\t\t"]))), selectedIndices: arrayOf(number)(templateObject_16 || (templateObject_16 = __makeTemplateObject(["\n\t\t\tAn array of currently selected `DropMenu.Option` indices.\n\t\t"], ["\n\t\t\tAn array of currently selected \\`DropMenu.Option\\` indices.\n\t\t"]))), focusedIndex: number(templateObject_17 || (templateObject_17 = __makeTemplateObject(["\n\t\t\tThe currently focused index of `DropMenu.Option`. Can also be `null`.\n\t\t"], ["\n\t\t\tThe currently focused index of \\`DropMenu.Option\\`. Can also be \\`null\\`.\n\t\t"]))), portalId: string(templateObject_18 || (templateObject_18 = __makeTemplateObject(["\n\t\t\tThe `id` of the flyout menu portal element that is appended to\n\t\t\t`document.body`. Defaults to a generated id.\n\t\t"], ["\n\t\t\tThe \\`id\\` of the flyout menu portal element that is appended to\n\t\t\t\\`document.body\\`. Defaults to a generated id.\n\t\t"]))), flyOutStyle: object(templateObject_19 || (templateObject_19 = __makeTemplateObject(["\n\t\t\tStyles that are passed through to the ContextMenu FlyOut element.\n\t\t"], ["\n\t\t\tStyles that are passed through to the ContextMenu FlyOut element.\n\t\t"]))), optionContainerStyle: object(templateObject_20 || (templateObject_20 = __makeTemplateObject(["\n\t\t\tStyles that are passed through to the option container element.\n\t\t"], ["\n\t\t\tStyles that are passed through to the option container element.\n\t\t"]))), onExpand: func(templateObject_21 || (templateObject_21 = __makeTemplateObject(["\n\t\t\tCalled when collapsed and the control is clicked, or when the control has\n\t\t\tfocus and the Down Arrow is pressed. Has the signature\n\t\t\t`({ props, event }) => {}`\n\t\t"], ["\n\t\t\tCalled when collapsed and the control is clicked, or when the control has\n\t\t\tfocus and the Down Arrow is pressed. Has the signature\n\t\t\t\\`({ props, event }) => {}\\`\n\t\t"]))), onCollapse: func(templateObject_22 || (templateObject_22 = __makeTemplateObject(["\n\t\t\tCalled when expanded and the user clicks the control or outside of the\n\t\t\tmenu, or when the control has focus and the Escape key is pressed Has the\n\t\t\tsignature `({ props, event }) => {}`\n\t\t"], ["\n\t\t\tCalled when expanded and the user clicks the control or outside of the\n\t\t\tmenu, or when the control has focus and the Escape key is pressed Has the\n\t\t\tsignature \\`({ props, event }) => {}\\`\n\t\t"]))), onSelect: func(templateObject_23 || (templateObject_23 = __makeTemplateObject(["\n\t\t\tCalled when an option is clicked, or when an option has focus and the\n\t\t\tEnter key is pressed. Has the signature\n\t\t\t`(optionIndex, {props, event}) => {}`\n\t\t\twhere optionIndex can be a number or `null`.\n\t\t"], ["\n\t\t\tCalled when an option is clicked, or when an option has focus and the\n\t\t\tEnter key is pressed. Has the signature\n\t\t\t\\`(optionIndex, {props, event}) => {}\\`\n\t\t\twhere optionIndex can be a number or \\`null\\`.\n\t\t"]))), onFocusNext: func(templateObject_24 || (templateObject_24 = __makeTemplateObject(["\n\t\t\tCalled when expanded and the the Down Arrow key is pressed. Not called\n\t\t\twhen focus is on the last option. Has the signature\n\t\t\t`({ props, event }) => {}`\n\t\t"], ["\n\t\t\tCalled when expanded and the the Down Arrow key is pressed. Not called\n\t\t\twhen focus is on the last option. Has the signature\n\t\t\t\\`({ props, event }) => {}\\`\n\t\t"]))), onFocusPrev: func(templateObject_25 || (templateObject_25 = __makeTemplateObject(["\n\t\t\tCalled when expanded and the the Up Arrow key is pressed. Not called when\n\t\t\tfocus is on the first option. Has the signature\n\t\t\t`({ props, event }) => {}`\n\t\t"], ["\n\t\t\tCalled when expanded and the the Up Arrow key is pressed. Not called when\n\t\t\tfocus is on the first option. Has the signature\n\t\t\t\\`({ props, event }) => {}\\`\n\t\t"]))), onFocusOption: func(templateObject_26 || (templateObject_26 = __makeTemplateObject(["\n\t\t\tCalled when the mouse moves over an option. Has the signature\n\t\t\t`(optionIndex) => {}` where optionIndex can be a number or `null`.\n\t\t"], ["\n\t\t\tCalled when the mouse moves over an option. Has the signature\n\t\t\t\\`(optionIndex) => {}\\` where optionIndex can be a number or \\`null\\`.\n\t\t"]))), Control: any(templateObject_27 || (templateObject_27 = __makeTemplateObject(["\n\t\t\t*Child Element* - The control target which the flyout menu is anchored\n\t\t\tto. Only one `Control` is used.\n\t\t"], ["\n\t\t\t*Child Element* - The control target which the flyout menu is anchored\n\t\t\tto. Only one \\`Control\\` is used.\n\t\t"]))), Option: any(templateObject_28 || (templateObject_28 = __makeTemplateObject(["\n\t\t\t*Child Element* - These are menu options. The `optionIndex` is in-order\n\t\t\tof rendering regardless of group nesting, starting with index `0`.\n\t\t\tEach `Option` may be passed a prop called `isDisabled` to disable\n\t\t\tselection of that `Option`. Any other props pass to Option will be\n\t\t\tavailable from the `onSelect` handler.\n\t\t"], ["\n\t\t\t*Child Element* - These are menu options. The \\`optionIndex\\` is in-order\n\t\t\tof rendering regardless of group nesting, starting with index \\`0\\`.\n\t\t\tEach \\`Option\\` may be passed a prop called \\`isDisabled\\` to disable\n\t\t\tselection of that \\`Option\\`. Any other props pass to Option will be\n\t\t\tavailable from the \\`onSelect\\` handler.\n\t\t"]))), OptionGroup: any(templateObject_29 || (templateObject_29 = __makeTemplateObject(["\n\t\t\t*Child Element* - Used to group `Option`s within the menu. Any\n\t\t\tnon-`Option`s passed in will be rendered as a label for the group.\n\t\t"], ["\n\t\t\t*Child Element* - Used to group \\`Option\\`s within the menu. Any\n\t\t\tnon-\\`Option\\`s passed in will be rendered as a label for the group.\n\t\t"]))), NullOption: any(templateObject_30 || (templateObject_30 = __makeTemplateObject(["\n\t\t\t*Child Element* - A special kind of `Option` that is always rendered at\n\t\t\tthe top of the menu and has an `optionIndex` of `null`. Useful for\n\t\t\tunselect.\n\t\t"], ["\n\t\t\t*Child Element* - A special kind of \\`Option\\` that is always rendered at\n\t\t\tthe top of the menu and has an \\`optionIndex\\` of \\`null\\`. Useful for\n\t\t\tunselect.\n\t\t"]))), Header: any(templateObject_31 || (templateObject_31 = __makeTemplateObject(["\n\t\t\t*Child Element* - An optional header to be displayed within the expanded\n\t\t\tFlyout, above all `Option`s.\n\t\t"], ["\n\t\t\t*Child Element* - An optional header to be displayed within the expanded\n\t\t\tFlyout, above all \\`Option\\`s.\n\t\t"]))), ContextMenu: any(templateObject_32 || (templateObject_32 = __makeTemplateObject(["\n\t\t\t*Child Element* - props pass through to the underlying ContextMenu\n\t\t\tcomponent\n\t\t"], ["\n\t\t\t*Child Element* - props pass through to the underlying ContextMenu\n\t\t\tcomponent\n\t\t"]))), FixedOption: any(templateObject_33 || (templateObject_33 = __makeTemplateObject(["\n\t\t\t*Child Element* - A special kind of `Option` that is always rendered at the top of\n\t\t\tthe menu.\n\t\t"], ["\n\t\t\t*Child Element* - A special kind of \\`Option\\` that is always rendered at the top of\n\t\t\tthe menu.\n\t\t"]))), }; DropMenu.defaultProps = { isDisabled: false, isExpanded: false, direction: 'down', alignment: 'start', selectedIndices: [], focusedIndex: null, flyOutStyle: { maxHeight: '18em' }, onExpand: lodash_1.default.noop, onCollapse: lodash_1.default.noop, onSelect: lodash_1.default.noop, onFocusNext: lodash_1.default.noop, onFocusPrev: lodash_1.default.noop, onFocusOption: lodash_1.default.noop, portalId: '', optionContainerStyle: {}, ContextMenu: ContextMenu_1.default.defaultProps, }; DropMenu.preprocessOptionData = function (props, ParentType) { var OptionGroup = ParentType.OptionGroup, Option = ParentType.Option, NullOption = ParentType.NullOption, FixedOption = ParentType.FixedOption; var optionGroups = lodash_1.default.map(component_types_1.findTypes(props, OptionGroup), 'props'); // find all OptionGroup props var fixedOptions = lodash_1.default.map(component_types_1.findTypes(props, FixedOption), 'props'); // find all FixedOption props var ungroupedOptions = lodash_1.default.map(component_types_1.findTypes(props, Option), 'props'); // find all ungrouped Option props var nullOptions = NullOption ? lodash_1.default.map(component_types_1.findTypes(props, NullOption), 'props') : []; // find all NullOption props var fixedOptionData = lodash_1.default.map(fixedOptions, function (optionProps, localOptionIndex) { return { localOptionIndex: localOptionIndex, optionIndex: localOptionIndex, optionGroupIndex: null, optionProps: optionProps, }; }); // flatten grouped options into array of objects to associate { index, group index, and props } for each option var groupedOptionData = lodash_1.default.reduce(optionGroups, function (memo, optionGroupProps, optionGroupIndex) { var groupedOptions = lodash_1.default.map(component_types_1.findTypes(optionGroupProps, Option), 'props'); // find all Option props for current group return memo.concat(lodash_1.default.map(groupedOptions, function (optionProps, localOptionIndex) { return { localOptionIndex: localOptionIndex, optionIndex: lodash_1.default.size(memo) + lodash_1.default.size(fixedOptionData) + localOptionIndex, optionGroupIndex: optionGroupIndex, optionProps: __assign({ isHidden: false }, optionProps), }; })); }, []); // create lookup object for options by their group index var optionGroupDataLookup = lodash_1.default.groupBy(groupedOptionData, 'optionGroupIndex'); // store ungrouped options into array of objects to associate { index, and props } for each option var ungroupedOptionData = lodash_1.default.map(ungroupedOptions, function (optionProps, localOptionIndex) { return { localOptionIndex: localOptionIndex, optionIndex: lodash_1.default.size(groupedOptionData) + lodash_1.default.size(fixedOptionData) + localOptionIndex, optionGroupIndex: null, optionProps: __assign({ isHidden: false }, optionProps), }; }); // concatenate grouped options array with ungrouped options array to get flat list of all options var flattenedOptionsData = lodash_1.default.concat(fixedOptionData, groupedOptionData, ungroupedOptionData); return { optionGroups: optionGroups, optionGroupDataLookup: optionGroupDataLookup, fixedOptionData: fixedOptionData, ungroupedOptionData: ungroupedOptionData, flattenedOptionsData: flattenedOptionsData, nullOptions: nullOptions, }; }; return DropMenu; }(react_1.default.Component)); exports.DropMenuDumb = DropMenu; exports.default = state_management_1.buildModernHybridComponent(DropMenu, { 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, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18, templateObject_19, templateObject_20, templateObject_21, templateObject_22, templateObject_23, templateObject_24, templateObject_25, templateObject_26, templateObject_27, templateObject_28, templateObject_29, templateObject_30, templateObject_31, templateObject_32, templateObject_33; //# sourceMappingURL=DropMenu.js.map