lucid-ui
Version:
A UI component library from Xandr.
287 lines • 12.9 kB
JavaScript
"use strict";
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) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
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 = __importStar(require("lodash"));
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("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: "Main pane content that will have a paired `Bar`.",
};
Primary.displayName = 'SplitHorizontal.Primary';
Primary.propName = 'Primary';
var Title = function (_props) { return null; };
Title.peek = {
description: "Sidebar title.",
};
Title.propTypes = {
/**
Content that will be displayed as the title of the Bar. It's only
shown when the user has the Bar expanded.
*/
children: node,
};
Title.propTypes = {
/**
Sidebar title.
*/
children: node,
};
Title.displayName = 'Sidebar.Title';
Title.propName = ['Title', 'title'];
var Bar = function (_props) { return null; };
Bar.peek = {
description: "Content to be placed alongside the `Primary` pane.",
};
Bar.displayName = 'Sidebar.Bar';
Bar.propName = 'Bar';
Bar.propTypes = {
/**
Set the title of the Sidebar. (alias for \`title\` and \`Sidebar.Title\`)
*/
Title: any,
/**
Adds default padding to the sidebar content.
*/
hasGutters: bool,
};
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((0, component_types_1.filterTypes)(children, Sidebar.Primary)), 'props', {}); // props from first Primary
var barProps = lodash_1.default.get(lodash_1.default.first((0, component_types_1.filterTypes)(children, Sidebar.Bar)), 'props', {}); // props from first Bar
var titleProps = lodash_1.default.get((0, component_types_1.findTypes)(barProps, Sidebar.Title).concat((0, 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({}, (0, lodash_1.omit)(passThroughs, [
'width',
'isExpanded',
'isAnimated',
'position',
'isResizeDisabled',
'title',
'Title',
'onResizing',
'onResize',
'onToggle',
].concat('initialState')), { style: __assign({ minWidth: isExpanded
? lodash_1.default.isNumber(width)
? width + 6
: "calc(".concat(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({}, (0, lodash_1.omit)(barProps, ['hasGutters', 'Title'].concat('initialState')), { 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: "`Sidebar` renders a collapsible, resizeable side bar panel next to primary content.",
categories: ['layout'],
};
Sidebar.reducers = reducers;
Sidebar.propTypes = {
/**
Style object that gets applied to the outer element.
*/
style: object,
/**
Appended to the component-specific class names set on the root element.
Value is run through the \`classnames\` library.
*/
className: string,
/**
Direct children must be types {Sidebar.Primary, Sidebar.Bar,
Sidebar.Title}. All content is composed as children of these respective
elements.
*/
children: node,
/**
Sets the starting width of the Bar.
*/
width: oneOfType([number, string]),
/**
Force the Sidebar to be expanded or collapsed.
*/
isExpanded: bool,
/**
Allows animated expand and collapse behavior.
*/
isAnimated: bool,
/**
Render the Sidebar to the left or right of primary content.
*/
position: oneOf(['left', 'right']),
/**
Disable user resizing of the Sidebar.
*/
isResizeDisabled: bool,
/**
Set the title of the Sidebar. (alias for \`Title\` and \`Sidebar.Title\`)
*/
title: any,
/**
Set the title of the Sidebar. (alias for \`title\` and \`Sidebar.Title\`)
*/
Title: any,
/**
Content to be placed alongside the Primary pane.
*/
Bar: any,
/**
Main pane content that will have a paired \`Bar\`.
*/
Primary: any,
/**
Called when the user is currently resizing the Sidebar. Signature:
\`(width, { event, props }) => {}\`
*/
onResizing: func,
/**
Called when the user resizes the Sidebar. Signature: \`(width, { event,
props }) => {}\`
*/
onResize: func,
/**
Called when the user expands or collapses the Sidebar. Signature: \`({
event, props }) => {}\`
*/
onToggle: func,
};
Sidebar.defaultProps = defaultProps;
return Sidebar;
}(react_1.default.Component));
exports.SidebarDumb = Sidebar;
exports.default = (0, state_management_1.buildModernHybridComponent)(Sidebar, { reducers: reducers });
//# sourceMappingURL=Sidebar.js.map