lucid-ui
Version:
A UI component library from AppNexus.
216 lines • 16.1 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.SidebarDumb = 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("./Sidebar.reducers"));
var SplitVertical_1 = __importDefault(require("../SplitVertical/SplitVertical"));
var Button_1 = __importDefault(require("../Button/Button"));
var ChevronIcon_1 = __importDefault(require("../Icon/ChevronIcon/ChevronIcon"));
var GripperVerticalIcon_1 = __importDefault(require("../Icon/GripperVerticalIcon/GripperVerticalIcon"));
var cx = style_helpers_1.lucidClassNames.bind('&-Sidebar');
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, object = prop_types_1.default.object, oneOf = prop_types_1.default.oneOf, oneOfType = prop_types_1.default.oneOfType;
var defaultProps = {
isExpanded: true,
isAnimated: true,
width: 250,
position: 'left',
isResizeDisabled: false,
onResizing: lodash_1.default.noop,
onResize: lodash_1.default.noop,
onToggle: lodash_1.default.noop,
};
var Primary = function (_props) { return null; };
Primary.peek = {
description: "\n\t\tMain pane content that will have a paired `Bar`.\n\t",
};
Primary.displayName = 'SplitHorizontal.Primary';
Primary.propName = 'Primary';
var Title = function (_props) { return null; };
Title.peek = {
description: "\n\t\tSidebar title;\n\t",
};
Title.propTypes = {
children: node(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\tContent that will be displayed as the title of the Bar. It's only\n\t\tshown when the user has the Bar expanded.\n\t"], ["\n\t\tContent that will be displayed as the title of the Bar. It's only\n\t\tshown when the user has the Bar expanded.\n\t"]))),
};
Title.propTypes = {
children: node(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\tSidebar title.\n\t"], ["\n\t\tSidebar title.\n\t"]))),
};
Title.displayName = 'Sidebar.Title';
Title.propName = ['Title', 'title'];
var Bar = function (_props) { return null; };
Bar.peek = {
description: "\n\t\tContent to be placed alongside the Primary pane.\n\t",
};
Bar.displayName = 'Sidebar.Bar';
Bar.propName = 'Bar';
Bar.propTypes = {
Title: any(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\tSet the title of the Sidebar. (alias for `title` and `Sidebar.Title`)\n\t"], ["\n\t\tSet the title of the Sidebar. (alias for \\`title\\` and \\`Sidebar.Title\\`)\n\t"]))),
title: any(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\tSet the title of the Sidebar. (alias for `Title` and `Sidebar.Title`)\n\t"], ["\n\t\tSet the title of the Sidebar. (alias for \\`Title\\` and \\`Sidebar.Title\\`)\n\t"]))),
hasGutters: bool(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\tAdds default padding to the sidebar content.\n\t"], ["\n\t\tAdds default padding to the sidebar content.\n\t"]))),
};
Bar.defaultProps = {
hasGutters: true,
};
var Sidebar = /** @class */ (function (_super) {
__extends(Sidebar, _super);
function Sidebar() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.handleExpanderClick = function (event) {
var onToggle = _this.props.onToggle;
onToggle && onToggle({ props: _this.props, event: event });
};
_this.handleResizing = function (width, _a) {
var event = _a.event;
var onResizing = _this.props.onResizing;
onResizing && onResizing(width, { props: _this.props, event: event });
};
_this.handleResize = function (width, _a) {
var event = _a.event;
var onResize = _this.props.onResize;
onResize && onResize(width, { props: _this.props, event: event });
};
return _this;
}
Sidebar.prototype.render = function () {
var _a = this.props, children = _a.children, style = _a.style, className = _a.className, isExpanded = _a.isExpanded, isAnimated = _a.isAnimated, position = _a.position, isResizeDisabled = _a.isResizeDisabled, width = _a.width, passThroughs = __rest(_a, ["children", "style", "className", "isExpanded", "isAnimated", "position", "isResizeDisabled", "width"]);
var primaryProps = lodash_1.default.get(lodash_1.default.first(component_types_1.filterTypes(children, Sidebar.Primary)), 'props', {}); // props from first Primary
var barProps = lodash_1.default.get(lodash_1.default.first(component_types_1.filterTypes(children, Sidebar.Bar)), 'props', {}); // props from first Bar
var titleProps = lodash_1.default.get(component_types_1.findTypes(barProps, Sidebar.Title).concat(component_types_1.findTypes(this.props, Sidebar.Title)), // get titles from Bar and parent Sidebar
'[0].props', // select props from the first title element
{ children: 'Title' } // default props
);
var PrimaryPane, BarPane; // using Left/Right Pane as primary depends on position
if (position !== 'right') {
PrimaryPane = SplitVertical_1.default.RightPane;
BarPane = SplitVertical_1.default.LeftPane;
}
else {
PrimaryPane = SplitVertical_1.default.LeftPane;
BarPane = SplitVertical_1.default.RightPane;
}
return (react_1.default.createElement(SplitVertical_1.default, __assign({}, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(Sidebar.propTypes), false), { style: __assign({ minWidth: isExpanded
? lodash_1.default.isNumber(width)
? width + 6
: "calc(" + width + " + 6px)"
: undefined }, style), className: cx('&', {
'&-is-resize-disabled': isResizeDisabled,
'&-is-position-right': position === 'right',
'&-is-position-left': position !== 'right',
}, className), isAnimated: isAnimated, isExpanded: isExpanded, collapseShift: 33, onResizing: this.handleResizing, onResize: this.handleResize }),
react_1.default.createElement(BarPane, __assign({}, component_types_1.omitProps(barProps, undefined, lodash_1.default.keys(Sidebar.Bar.propTypes), false), { className: cx('&-Bar', barProps.className), width: width, style: {
overflow: isExpanded ? 'auto' : 'hidden',
} }),
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', titleProps.className) })),
react_1.default.createElement(Button_1.default, { className: cx('&-expander'), kind: 'invisible', onMouseDown: this.handleExpanderClick, hasOnlyIcon: true },
react_1.default.createElement(ChevronIcon_1.default, { direction: (isExpanded && position === 'right') ||
(!isExpanded && position !== 'right')
? 'right'
: 'left' }))),
react_1.default.createElement("div", { className: cx('&-Bar-content', {
'&-Bar-content-has-gutters': barProps.hasGutters,
}) }, barProps.children)),
react_1.default.createElement(SplitVertical_1.default.Divider, { className: cx('&-Divider') },
react_1.default.createElement(GripperVerticalIcon_1.default, { className: cx('&-Divider-gripper') })),
react_1.default.createElement(PrimaryPane, __assign({}, primaryProps, { className: cx('&-Primary', primaryProps.className), isPrimary: true }))));
};
Sidebar.displayName = 'Sidebar';
Sidebar.Bar = Bar;
Sidebar.Primary = Primary;
Sidebar.Title = Title;
Sidebar.peek = {
description: "\n\t\t\t\t\t`Sidebar` renders a collapsible, resizeable side bar panel next to\n\t\t\t\t\tprimary content.\n\t\t\t\t",
categories: ['layout'],
};
Sidebar.reducers = reducers;
Sidebar.propTypes = {
style: object(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\t\tStyle object that gets applied to the outer element.\n\t\t"], ["\n\t\t\tStyle object that gets applied to the outer element.\n\t\t"]))),
className: string(templateObject_7 || (templateObject_7 = __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_8 || (templateObject_8 = __makeTemplateObject(["\n\t\t\tDirect children must be types {Sidebar.Primary, Sidebar.Bar,\n\t\t\tSidebar.Title}. All content is composed as children of these respective\n\t\t\telements.\n\t\t"], ["\n\t\t\tDirect children must be types {Sidebar.Primary, Sidebar.Bar,\n\t\t\tSidebar.Title}. All content is composed as children of these respective\n\t\t\telements.\n\t\t"]))),
width: oneOfType([number, string])(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n\t\t\tSets the starting width of the Bar.\n\t\t"], ["\n\t\t\tSets the starting width of the Bar.\n\t\t"]))),
isExpanded: bool(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n\t\t\tForce the Sidebar to be expanded or collapsed.\n\t\t"], ["\n\t\t\tForce the Sidebar to be expanded or collapsed.\n\t\t"]))),
isAnimated: bool(templateObject_11 || (templateObject_11 = __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(['left', 'right'])(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n\t\t\tRender the Sidebar to the left or right of primary content.\n\t\t"], ["\n\t\t\tRender the Sidebar to the left or right of primary content.\n\t\t"]))),
isResizeDisabled: bool(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n\t\t\tDisable user resizing of the Sidebar.\n\t\t"], ["\n\t\t\tDisable user resizing of the Sidebar.\n\t\t"]))),
title: any(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n\t\t\tSet the title of the Sidebar. (alias for `Title` and `Sidebar.Title`)\n\t\t"], ["\n\t\t\tSet the title of the Sidebar. (alias for \\`Title\\` and \\`Sidebar.Title\\`)\n\t\t"]))),
Title: any(templateObject_15 || (templateObject_15 = __makeTemplateObject(["\n\t\t\tSet the title of the Sidebar. (alias for `title` and `Sidebar.Title`)\n\t\t"], ["\n\t\t\tSet the title of the Sidebar. (alias for \\`title\\` and \\`Sidebar.Title\\`)\n\t\t"]))),
Bar: any(templateObject_16 || (templateObject_16 = __makeTemplateObject(["\n\t\t\tContent to be placed alongside the Primary pane.\n\t\t"], ["\n\t\t\tContent to be placed alongside the Primary pane.\n\t\t"]))),
Primary: any(templateObject_17 || (templateObject_17 = __makeTemplateObject(["\n\t\t\tMain pane content that will have a paired `Bar`.\n\t\t"], ["\n\t\t\tMain pane content that will have a paired \\`Bar\\`.\n\t\t"]))),
onResizing: func(templateObject_18 || (templateObject_18 = __makeTemplateObject(["\n\t\t\tCalled when the user is currently resizing the Sidebar. Signature:\n\t\t\t`(width, { event, props }) => {}`\n\t\t"], ["\n\t\t\tCalled when the user is currently resizing the Sidebar. Signature:\n\t\t\t\\`(width, { event, props }) => {}\\`\n\t\t"]))),
onResize: func(templateObject_19 || (templateObject_19 = __makeTemplateObject(["\n\t\t\tCalled when the user resizes the Sidebar. Signature: `(width, { event,\n\t\t\tprops }) => {}`\n\t\t"], ["\n\t\t\tCalled when the user resizes the Sidebar. Signature: \\`(width, { event,\n\t\t\tprops }) => {}\\`\n\t\t"]))),
onToggle: func(templateObject_20 || (templateObject_20 = __makeTemplateObject(["\n\t\t\tCalled when the user expands or collapses the Sidebar. Signature: `({\n\t\t\tevent, props }) => {}`\n\t\t"], ["\n\t\t\tCalled when the user expands or collapses the Sidebar. Signature: \\`({\n\t\t\tevent, props }) => {}\\`\n\t\t"]))),
};
Sidebar.defaultProps = defaultProps;
return Sidebar;
}(react_1.default.Component));
exports.SidebarDumb = Sidebar;
exports.default = state_management_1.buildModernHybridComponent(Sidebar, { 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=Sidebar.js.map