lucid-ui
Version:
A UI component library from Xandr.
272 lines • 12.7 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.SubmarineDumb = 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("./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: "Primary content rendered beside the Submarine.",
};
Primary.displayName = 'SplitHorizontal.Primary';
Primary.propName = 'Primary';
var Title = function (_props) { return null; };
Title.peek = {
description: "Submarine title.",
};
Title.displayName = 'Submarine.Title';
Title.propName = 'Title';
var Bar = function (_props) { return null; };
Bar.peek = {
description: "Submarine bar.",
};
Bar.displayName = 'Submarine.Bar';
Bar.propName = 'Bar';
Bar.propTypes = {
/**
Set the title of the Submarine. (alias for \`Submarine.Title\`)
*/
Title: any,
};
/** Submarine */
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((0, component_types_1.filterTypes)(children, Submarine.Primary)), 'props', {}); // props from first Primary
var barProps = lodash_1.default.get(lodash_1.default.first((0, component_types_1.filterTypes)(children, Submarine.Bar)), 'props', {}); // props from first Bar
var titleProps = lodash_1.default.get((0, component_types_1.findTypes)(barProps, Submarine.Title).concat((0, 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({}, (0, lodash_1.omit)(passThroughs, [
'className',
'children',
'height',
'isExpanded',
'isHidden',
'isTitleShownCollapsed',
'isAnimated',
'position',
'isResizeDisabled',
'Title',
'Bar',
'Primary',
'onResizing',
'onResize',
'onToggle',
].concat('initialState')), { 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({}, (0, lodash_1.omit)(barProps, ['Title'].concat('initialState')), { 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: "`Submarine` renders a collapsible, resizeable side bar panel next to primary content.",
categories: ['layout'],
madeFrom: ['SplitHorizontal', 'ChevronIcon', 'GripperHorizontalIcon'],
};
Submarine.reducers = reducers;
Submarine.propTypes = {
/**
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 {Submarine.Primary, Submarine.Bar,
Submarine.Title}. All content is composed as children of these
respective elements.
*/
children: node,
/**
Sets the starting height of the Bar.
*/
height: oneOfType([number, string]),
/**
Force the Submarine to be expanded or collapsed.
*/
isExpanded: bool,
/**
Indicates if the Submarine should be shown or not. This will override
the value of isExpanded.
*/
isHidden: bool,
/**
Indicates if the Title should be shown when the Submarine is collapsed
*/
isTitleShownCollapsed: bool,
/**
Allows animated expand and collapse behavior.
*/
isAnimated: bool,
/**
Render the Submarine to the top or bottom of primary content.
*/
position: oneOf(['top', 'bottom']),
/**
Disable user resizing of the Submarine.
*/
isResizeDisabled: bool,
/**
Set the title of the Submarine.
*/
Title: any,
/**
Set the Submarine Bar content.
*/
Bar: any,
/**
Set the primary content of the Submarine.
*/
Primary: any,
/**
Called when the user is currently resizing the Submarine. Signature:
\`(height, { event, props }) => {}\`
*/
onResizing: func,
/**
Called when the user resizes the Submarine. Signature:
\`(height, { event, props }) => {}\`
*/
onResize: func,
/**
Called when the user expands or collapses the Submarine. Signature:
\`({ event, props }) => {}\`
*/
onToggle: func,
};
Submarine.defaultProps = defaultProps;
return Submarine;
}(react_1.default.Component));
exports.SubmarineDumb = Submarine;
exports.default = (0, state_management_1.buildModernHybridComponent)(Submarine, { reducers: reducers });
//# sourceMappingURL=Submarine.js.map