UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

203 lines 15.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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SubmarineDumb = 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("./Submarine.reducers")); var SplitHorizontal_1 = __importDefault(require("../SplitHorizontal/SplitHorizontal")); var ChevronIcon_1 = __importDefault(require("../Icon/ChevronIcon/ChevronIcon")); var GripperHorizontalIcon_1 = __importDefault(require("../Icon/GripperHorizontalIcon/GripperHorizontalIcon")); var Button_1 = __importDefault(require("../Button/Button")); var cx = style_helpers_1.lucidClassNames.bind('&-Submarine'); 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, number = prop_types_1.default.number, string = prop_types_1.default.string, oneOf = prop_types_1.default.oneOf, oneOfType = prop_types_1.default.oneOfType; var Primary = function (_props) { return null; }; Primary.peek = { description: "\n\t\tPrimary content rendered beside the Submarine.\n\t", }; Primary.displayName = 'SplitHorizontal.Primary'; Primary.propName = 'Primary'; var Title = function (_props) { return null; }; Title.peek = { description: "\n\t\tSubmarine title;\n\t", }; Title.displayName = 'Submarine.Title'; Title.propName = 'Title'; var Bar = function (_props) { return null; }; Bar.peek = { description: "\n\t\tSubmarine bar;\n\t", }; Bar.displayName = 'Submarine.Bar'; Bar.propName = 'Bar'; Bar.propTypes = { Title: any(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\tSet the title of the Submarine. (alias for `Submarine.Title`)\n\t"], ["\n\t\tSet the title of the Submarine. (alias for \\`Submarine.Title\\`)\n\t"]))), }; var defaultProps = { isExpanded: true, isAnimated: true, height: 250, position: 'bottom', isResizeDisabled: false, isHidden: false, isTitleShownCollapsed: false, onResizing: lodash_1.default.noop, onResize: lodash_1.default.noop, onToggle: lodash_1.default.noop, }; var Submarine = /** @class */ (function (_super) { __extends(Submarine, _super); function Submarine() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.handleExpanderClick = function (_a) { var event = _a.event; var onToggle = _this.props.onToggle; onToggle({ props: _this.props, event: event }); }; _this.handleResizing = function (height, _a) { var event = _a.event; var onResizing = _this.props.onResizing; onResizing(height, { props: _this.props, event: event }); }; _this.handleResize = function (height, _a) { var event = _a.event; var onResize = _this.props.onResize; onResize(height, { props: _this.props, event: event }); }; return _this; } Submarine.prototype.render = function () { var _a = this.props, children = _a.children, className = _a.className, isExpanded = _a.isExpanded, isAnimated = _a.isAnimated, position = _a.position, isResizeDisabled = _a.isResizeDisabled, height = _a.height, isHidden = _a.isHidden, isTitleShownCollapsed = _a.isTitleShownCollapsed, passThroughs = __rest(_a, ["children", "className", "isExpanded", "isAnimated", "position", "isResizeDisabled", "height", "isHidden", "isTitleShownCollapsed"]); var primaryProps = lodash_1.default.get(lodash_1.default.first(component_types_1.filterTypes(children, Submarine.Primary)), 'props', {}); // props from first Primary var barProps = lodash_1.default.get(lodash_1.default.first(component_types_1.filterTypes(children, Submarine.Bar)), 'props', {}); // props from first Bar var titleProps = lodash_1.default.get(component_types_1.findTypes(barProps, Submarine.Title).concat(component_types_1.findTypes(this.props, Submarine.Title)), // get titles from Bar and parent Submarine '[0].props', // select props from the first title element react_1.default.createElement(Submarine.Title).props // default props ); var PrimaryPane, BarPane; // using Left/Right Pane as primary depends on position if (position !== 'bottom') { PrimaryPane = SplitHorizontal_1.default.BottomPane; BarPane = SplitHorizontal_1.default.TopPane; } else { PrimaryPane = SplitHorizontal_1.default.TopPane; BarPane = SplitHorizontal_1.default.BottomPane; } // leave 33px of sidebar to stick out when collapsed, or 0px if hidden var collapseShift = isHidden ? 0 : 33; return (react_1.default.createElement(SplitHorizontal_1.default, __assign({}, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(Submarine.propTypes), false), { className: cx('&', { '&-is-resize-disabled': isResizeDisabled, '&-is-position-bottom': position === 'bottom', '&-is-position-top': position !== 'bottom', }, className), isAnimated: isAnimated, isExpanded: isExpanded && !isHidden, collapseShift: collapseShift, onResizing: this.handleResizing, onResize: this.handleResize }), react_1.default.createElement(BarPane, __assign({}, component_types_1.omitProps(barProps, undefined, lodash_1.default.keys(Submarine.Bar.propTypes), false), { className: cx('&-Bar', barProps.className), height: height }), react_1.default.createElement("div", { className: cx('&-Bar-overlay') }), react_1.default.createElement("div", { className: cx('&-Bar-header') }, react_1.default.createElement("div", __assign({}, titleProps, { className: cx('&-Bar-Title', { '&-Bar-Title-is-shown-collapsed': isTitleShownCollapsed }, titleProps.className) })), react_1.default.createElement(Button_1.default, { className: cx('&-expander'), kind: 'invisible', onClick: this.handleExpanderClick, hasOnlyIcon: true }, react_1.default.createElement(ChevronIcon_1.default, { direction: (isExpanded && position === 'bottom') || (!isExpanded && position !== 'bottom') ? 'down' : 'up' }))), react_1.default.createElement("div", { className: cx('&-Bar-content') }, barProps.children)), react_1.default.createElement(SplitHorizontal_1.default.Divider, { className: cx('&-Divider') }, react_1.default.createElement(GripperHorizontalIcon_1.default, { className: cx('&-Divider-gripper') })), react_1.default.createElement(PrimaryPane, __assign({}, primaryProps, { className: cx('&-Primary', primaryProps.className), isPrimary: true })))); }; Submarine.displayName = 'Submarine'; Submarine.Bar = Bar; Submarine.Title = Title; Submarine.Primary = Primary; Submarine.peek = { description: "\n\t\t\t\t`Submarine` renders a collapsible, resizeable side bar panel next to\n\t\t\t\tprimary content.\n\t\t\t", categories: ['layout'], madeFrom: ['SplitHorizontal', 'ChevronIcon', 'GripperHorizontalIcon'], }; Submarine.reducers = reducers; Submarine.propTypes = { className: string(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t\tValue is run through the `classnames` library.\n\t\t"], ["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t\tValue is run through the \\`classnames\\` library.\n\t\t"]))), children: node(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\t\tDirect children must be types {Submarine.Primary, Submarine.Bar,\n\t\t\tSubmarine.Title}. All content is composed as children of these\n\t\t\trespective elements.\n\t\t"], ["\n\t\t\tDirect children must be types {Submarine.Primary, Submarine.Bar,\n\t\t\tSubmarine.Title}. All content is composed as children of these\n\t\t\trespective elements.\n\t\t"]))), height: oneOfType([number, string])(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\t\tSets the starting height of the Bar.\n\t\t"], ["\n\t\t\tSets the starting height of the Bar.\n\t\t"]))), isExpanded: bool(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\t\tForce the Submarine to be expanded or collapsed.\n\t\t"], ["\n\t\t\tForce the Submarine to be expanded or collapsed.\n\t\t"]))), isHidden: bool(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\t\tIndicates if the Submarine should be shown or not. This will override\n\t\t\tthe value of isExpanded.\n\t\t"], ["\n\t\t\tIndicates if the Submarine should be shown or not. This will override\n\t\t\tthe value of isExpanded.\n\t\t"]))), isTitleShownCollapsed: bool(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\t\tIndicates if the Title should be shown when the Submarine is collapsed\n\t\t"], ["\n\t\t\tIndicates if the Title should be shown when the Submarine is collapsed\n\t\t"]))), isAnimated: bool(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n\t\t\tAllows animated expand and collapse behavior.\n\t\t"], ["\n\t\t\tAllows animated expand and collapse behavior.\n\t\t"]))), position: oneOf(['top', 'bottom'])(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n\t\t\tRender the Submarine to the top or bottom of primary content.\n\t\t"], ["\n\t\t\tRender the Submarine to the top or bottom of primary content.\n\t\t"]))), isResizeDisabled: bool(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n\t\t\tDisable user resizing of the Submarine.\n\t\t"], ["\n\t\t\tDisable user resizing of the Submarine.\n\t\t"]))), Title: any(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n\t\t\tSet the title of the Submarine.\n\t\t"], ["\n\t\t\tSet the title of the Submarine.\n\t\t"]))), Bar: any(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n\t\t\tSet the submarine bar content.\n\t\t"], ["\n\t\t\tSet the submarine bar content.\n\t\t"]))), Primary: any(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n\t\t\tSet the primary content of the Submarine.\n\t\t"], ["\n\t\t\tSet the primary content of the Submarine.\n\t\t"]))), onResizing: func(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n\t\t\tCalled when the user is currently resizing the Submarine. Signature:\n\t\t\t`(height, { event, props }) => {}`\n\t\t"], ["\n\t\t\tCalled when the user is currently resizing the Submarine. Signature:\n\t\t\t\\`(height, { event, props }) => {}\\`\n\t\t"]))), onResize: func(templateObject_15 || (templateObject_15 = __makeTemplateObject(["\n\t\t\tCalled when the user resizes the Submarine. Signature:\n\t\t\t`(height, { event, props }) => {}`\n\t\t"], ["\n\t\t\tCalled when the user resizes the Submarine. Signature:\n\t\t\t\\`(height, { event, props }) => {}\\`\n\t\t"]))), onToggle: func(templateObject_16 || (templateObject_16 = __makeTemplateObject(["\n\t\t\tCalled when the user expands or collapses the Submarine. Signature:\n\t\t\t`({ event, props }) => {}`\n\t\t"], ["\n\t\t\tCalled when the user expands or collapses the Submarine. Signature:\n\t\t\t\\`({ event, props }) => {}\\`\n\t\t"]))), }; Submarine.defaultProps = defaultProps; return Submarine; }(react_1.default.Component)); exports.SubmarineDumb = Submarine; exports.default = state_management_1.buildModernHybridComponent(Submarine, { 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; //# sourceMappingURL=Submarine.js.map