UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

192 lines 16.9 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.TabsDumb = 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 reducers = __importStar(require("./Tabs.reducers")); var Badge_1 = __importDefault(require("../Badge/Badge")); var cx = style_helpers_1.lucidClassNames.bind('&-Tabs'); var bool = prop_types_1.default.bool, func = prop_types_1.default.func, node = prop_types_1.default.node, number = prop_types_1.default.number, string = prop_types_1.default.string, any = prop_types_1.default.any; var Title = function (props) { return null; }; Title.peek = { description: "Titles can be provided as a child or prop to a Tab.", }; Title.displayName = 'Tabs.Title'; Title.propName = 'Title'; var Tab = function (props) { var isDisabled = props.isDisabled, isLastTab = props.isLastTab, isOpen = props.isOpen, isProgressive = props.isProgressive, isSelected = props.isSelected, Title = props.Title, className = props.className, count = props.count, isVariableCountWidth = props.isVariableCountWidth, _a = props.index, index = _a === void 0 ? 0 : _a, // this defaults should not be invoked unless someone is using `Tab` outside of `Tabs` _b = props.onSelect, // this defaults should not be invoked unless someone is using `Tab` outside of `Tabs` onSelect = _b === void 0 ? lodash_1.default.noop : _b, // this defaults should not be invoked unless someone is using `Tab` outside of `Tabs` passThroughs = __rest(props, ["isDisabled", "isLastTab", "isOpen", "isProgressive", "isSelected", "Title", "className", "count", "isVariableCountWidth", "index", "onSelect"]); var handleClick = function (event) { if (!isDisabled) { onSelect(index, props, event); } }; return (react_1.default.createElement("li", __assign({ className: cx('&-Tab', { '&-Tab-is-active': isSelected, '&-Tab-is-disabled': isDisabled, '&-Tab-is-active-and-open': isOpen && isSelected, '&-Tab-is-progressive': isProgressive && !isLastTab, }, className), onClick: handleClick }, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(Tab.propTypes))), react_1.default.createElement("span", { className: cx('&-Tab-content') }, Title, !lodash_1.default.isNil(count) && (react_1.default.createElement(Badge_1.default, { style: { marginLeft: '12px', width: isVariableCountWidth ? undefined : '20px', minWidth: '20px', }, type: 'stroke', kind: isSelected ? 'primary' : undefined }, count))), isProgressive && !isLastTab && (react_1.default.createElement("span", { className: cx('&-Tab-arrow') }, react_1.default.createElement("svg", { className: cx('&-Tab-arrow-svg'), viewBox: '0 0 8 37', preserveAspectRatio: 'none' }, react_1.default.createElement("polyline", { className: cx('&-Tab-arrow-tab-line'), fill: '#fff', points: '0,0 1,1 0,1' }), react_1.default.createElement("polyline", { className: cx('&-Tab-arrow-line'), fill: 'none', stroke: '#fff', strokeWidth: '1', points: '0,37 7.3,18.5 0,0' })))))); }; Tab.peek = { description: "\n\t\t\t\tContent that will be rendered in a tab. Be sure to nest a Title inside\n\t\t\t\teach Tab or provide it as a prop. Props other than `isDisabled`,\n\t\t\t\t`isSelected`, and `Title` can be inferred from the parent `Tabs`\n\t\t\t\tcomponent, but directly provided `props` will take precedence.\n\t\t\t", }; Tab.displayName = 'Tabs.Tab'; Tab.propName = 'Tab'; Tab.propTypes = { className: string(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\t\tClass names that are appended to the defaults.\n\t\t"], ["\n\t\t\tClass names that are appended to the defaults.\n\t\t"]))), index: number(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\t\tThe index of this `Tab` within the list of `Tabs`.\n\t\t"], ["\n\t\t\tThe index of this \\`Tab\\` within the list of \\`Tabs\\`.\n\t\t"]))), isDisabled: bool(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\t\tStyles a `Tab` as disabled. This is typically used with\n\t\t\t`isProgressive` to disable steps that have not been completed and\n\t\t\tshould not be selected until the current step has been completed.\n\t\t"], ["\n\t\t\tStyles a \\`Tab\\` as disabled. This is typically used with\n\t\t\t\\`isProgressive\\` to disable steps that have not been completed and\n\t\t\tshould not be selected until the current step has been completed.\n\t\t"]))), isLastTab: bool(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\t\tIf `true`, this `Tab` is the last `Tab` in the list of `Tabs`.\n\t\t"], ["\n\t\t\tIf \\`true\\`, this \\`Tab\\` is the last \\`Tab\\` in the list of \\`Tabs\\`.\n\t\t"]))), isOpen: bool(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\t\tIf `true` then the active `Tab` will appear open on the bottom.\n\t\t"], ["\n\t\t\tIf \\`true\\` then the active \\`Tab\\` will appear open on the bottom.\n\t\t"]))), isProgressive: bool(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\t\tIf `true`, the `Tab` will appear as a `Progressive` tab.\n\t\t"], ["\n\t\t\tIf \\`true\\`, the \\`Tab\\` will appear as a \\`Progressive\\` tab.\n\t\t"]))), isSelected: bool(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\t\tIf `true`, the `Tab` will appear selected.\n\t\t"], ["\n\t\t\tIf \\`true\\`, the \\`Tab\\` will appear selected.\n\t\t"]))), onSelect: func(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n\t\t\tCallback for when the user clicks a `Tab`. Called with the index of the\n\t\t\t`Tab` that was clicked.\n\t\t"], ["\n\t\t\tCallback for when the user clicks a \\`Tab\\`. Called with the index of the\n\t\t\t\\`Tab\\` that was clicked.\n\t\t"]))), Title: node(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n\t\t\tThe content to be rendered as the `Title` of the `Tab`.\n\t\t"], ["\n\t\t\tThe content to be rendered as the \\`Title\\` of the \\`Tab\\`.\n\t\t"]))), count: number(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n\t\t\tOptional prop that will show a count number next to the tab's title.\n\t\t"], ["\n\t\t\tOptional prop that will show a count number next to the tab's title.\n\t\t"]))), isVariableCountWidth: bool(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n\t\t\tDefaults to false.\n\t\t\tAllows the count bubble to grow large. Useful if working with huge numbers.\n\t\t"], ["\n\t\t\tDefaults to false.\n\t\t\tAllows the count bubble to grow large. Useful if working with huge numbers.\n\t\t"]))), }; var Tabs = /** @class */ (function (_super) { __extends(Tabs, _super); function Tabs() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.handleClicked = function (index, tabProps, event) { var onSelect = _this.props.onSelect; onSelect(index, { event: event, props: tabProps }); }; return _this; } Tabs.prototype.render = function () { var _this = this; var _a = this.props, className = _a.className, hasMultilineTitle = _a.hasMultilineTitle, isOpen = _a.isOpen, isProgressive = _a.isProgressive, selectedIndex = _a.selectedIndex, hasFullWidthTabs = _a.hasFullWidthTabs, isFloating = _a.isFloating, passThroughs = __rest(_a, ["className", "hasMultilineTitle", "isOpen", "isProgressive", "selectedIndex", "hasFullWidthTabs", "isFloating"]); // Grab props array from each Tab var tabChildProps = lodash_1.default.map(component_types_1.findTypes(this.props, Tab), 'props'); var selectedIndexFromChildren = lodash_1.default.findLastIndex(tabChildProps, { isSelected: true, }); var actualSelectedIndex = selectedIndexFromChildren !== -1 ? selectedIndexFromChildren : selectedIndex; return (react_1.default.createElement("div", __assign({}, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(Tabs.propTypes)), { className: cx('&', className) }), react_1.default.createElement("ul", { className: cx('&-bar', { '&-bar-is-multiline': hasMultilineTitle, '&-variable-width': !hasFullWidthTabs, '&-floating': isFloating, }) }, lodash_1.default.map(tabChildProps, function (tabProps, index) { return (react_1.default.createElement(Tab, __assign({ key: index, index: index, isLastTab: index === tabChildProps.length - 1, isOpen: isOpen, isProgressive: isProgressive, isSelected: index === actualSelectedIndex, onSelect: _this.handleClicked, Title: lodash_1.default.get(component_types_1.getFirst(tabProps, Tabs.Title), 'props.children', '') }, tabProps))); })), react_1.default.createElement("div", { className: cx('&-content') }, lodash_1.default.get(tabChildProps, [ lodash_1.default.isUndefined(actualSelectedIndex) ? '' : actualSelectedIndex, 'children', ])))); }; Tabs.displayName = 'Tabs'; Tabs.Title = Title; Tabs.Tab = Tab; Tabs.reducers = reducers; Tabs.peek = { description: "\n\t\t\t\t`Tabs` provides tabbed navigation. It has a flexible interface that\n\t\t\t\tallows tab content to be passed as regular React children or through\n\t\t\t\tprops.\n\t\t\t", categories: ['navigation'], }; Tabs.propTypes = { className: string(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n\t\t\tClass names that are appended to the defaults.\n\t\t"], ["\n\t\t\tClass names that are appended to the defaults.\n\t\t"]))), selectedIndex: number(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n\t\t\tIndicates which of the `Tabs.Tab` children is currently selected. The\n\t\t\tindex of the last `Tabs.Tab` child with `isSelected` equal to\n\t\t\t`true` takes precedence over this prop.\n\t\t"], ["\n\t\t\tIndicates which of the \\`Tabs.Tab\\` children is currently selected. The\n\t\t\tindex of the last \\`Tabs.Tab\\` child with \\`isSelected\\` equal to\n\t\t\t\\`true\\` takes precedence over this prop.\n\t\t"]))), onSelect: func(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n\t\t\tCallback for when the user clicks a tab. Called with the index of the tab\n\t\t\tthat was clicked.\n\t\t"], ["\n\t\t\tCallback for when the user clicks a tab. Called with the index of the tab\n\t\t\tthat was clicked.\n\t\t"]))), isOpen: bool(templateObject_15 || (templateObject_15 = __makeTemplateObject(["\n\t\t\tIf `true` then the active tab will appear open on the bottom.\n\t\t"], ["\n\t\t\tIf \\`true\\` then the active tab will appear open on the bottom.\n\t\t"]))), isProgressive: bool(templateObject_16 || (templateObject_16 = __makeTemplateObject(["\n\t\t\tStyle the tabs as a progression. This is typically used for a work flow\n\t\t\twhere the user needs to move forward and backward through a series of\n\t\t\tsteps.\n\t\t"], ["\n\t\t\tStyle the tabs as a progression. This is typically used for a work flow\n\t\t\twhere the user needs to move forward and backward through a series of\n\t\t\tsteps.\n\t\t"]))), isFloating: bool(templateObject_17 || (templateObject_17 = __makeTemplateObject(["\n\t\t\tProvides a small bottom border that offers a barrier between the tab\n\t\t\tgroup and the rest of the page.\n\t\t\tUseful if the tabs are not anchored to anything.\n\t\t"], ["\n\t\t\tProvides a small bottom border that offers a barrier between the tab\n\t\t\tgroup and the rest of the page.\n\t\t\tUseful if the tabs are not anchored to anything.\n\t\t"]))), hasMultilineTitle: bool(templateObject_18 || (templateObject_18 = __makeTemplateObject(["\n\t\t\tSet the multiline className. This is typically used for styling the\n\t\t\tTab.Title bar for improved readability when there are multiple React\n\t\t\telements in the tab headers.\n\t\t"], ["\n\t\t\tSet the multiline className. This is typically used for styling the\n\t\t\tTab.Title bar for improved readability when there are multiple React\n\t\t\telements in the tab headers.\n\t\t"]))), hasFullWidthTabs: bool(templateObject_19 || (templateObject_19 = __makeTemplateObject(["\n\t\t\tIf `true` the width will be evenly distributed to all tabs. `False`\n\t\t\ttypically used in conjunction with `Tab.width`\n\t\t"], ["\n\t\t\tIf \\`true\\` the width will be evenly distributed to all tabs. \\`False\\`\n\t\t\ttypically used in conjunction with \\`Tab.width\\`\n\t\t"]))), Tab: any(templateObject_20 || (templateObject_20 = __makeTemplateObject(["\n\t\t\t*Child Element* Can be used to define one or more individual `Tab`s in\n\t\t\tthe sequence of `Tabs`.\n\t\t"], ["\n\t\t\t*Child Element* Can be used to define one or more individual \\`Tab\\`s in\n\t\t\tthe sequence of \\`Tabs\\`.\n\t\t"]))), }; Tabs.defaultProps = { selectedIndex: 0, onSelect: lodash_1.default.noop, isOpen: true, isProgressive: false, isFloating: false, hasMultilineTitle: false, hasFullWidthTabs: false, }; return Tabs; }(react_1.default.Component)); exports.TabsDumb = Tabs; exports.default = state_management_1.buildModernHybridComponent(Tabs, { 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; //# sourceMappingURL=Tabs.js.map