lucid-ui
Version:
A UI component library from AppNexus.
124 lines • 10.9 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 __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 __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 });
var lodash_1 = __importDefault(require("lodash"));
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("react-peek/prop-types"));
var MinusCircleIcon_1 = __importDefault(require("../Icon/MinusCircleIcon/MinusCircleIcon"));
var SuccessIcon_1 = __importDefault(require("../Icon/SuccessIcon/SuccessIcon"));
var CloseIcon_1 = __importDefault(require("../Icon/CloseIcon/CloseIcon"));
var InfoIcon_1 = __importDefault(require("../Icon/InfoIcon/InfoIcon"));
var WarningIcon_1 = __importDefault(require("../Icon/WarningIcon/WarningIcon"));
var style_helpers_1 = require("../../util/style-helpers");
var component_types_1 = require("../../util/component-types");
var createElement = react_1.default.createElement;
var bool = prop_types_1.default.bool, func = prop_types_1.default.func, string = prop_types_1.default.string, node = prop_types_1.default.node, oneOf = prop_types_1.default.oneOf;
var cx = style_helpers_1.lucidClassNames.bind('&-Selection');
function defaultIcon(kind, responsiveMode) {
return kind === 'default' ? null : kind === 'container' ? null : kind ===
'success' ? (react_1.default.createElement(SuccessIcon_1.default, { className: cx('&-Icon', "&-Icon-is-" + responsiveMode) })) : kind === 'danger' ? (react_1.default.createElement(MinusCircleIcon_1.default, { className: cx('&-Icon', "&-Icon-is-" + responsiveMode) })) : kind === 'info' ? (react_1.default.createElement(InfoIcon_1.default, { className: cx('&-Icon', "&-Icon-is-" + responsiveMode) })) : kind === 'warning' ? (react_1.default.createElement(WarningIcon_1.default, { className: cx('&-Icon', "&-Icon-is-" + responsiveMode) })) : null;
}
var SelectionIcon = function () { return null; };
SelectionIcon.peek = {
description: "\n Icon that is displayed within the Selection. Any of the lucid `*Icon` components should work.\n ",
};
SelectionIcon.displayName = 'Selection.Icon';
SelectionIcon.propName = 'Icon';
var SelectionLabel = function () { return null; };
SelectionLabel.peek = {
description: "\n Label for the Selection.\n ",
};
SelectionLabel.displayName = 'Selection.Label';
SelectionLabel.propName = 'Label';
var defaultProps = {
isRemovable: true,
onRemove: lodash_1.default.noop,
hasBackground: false,
isBold: false,
kind: 'default',
responsiveMode: 'large',
};
var Selection = function (props) {
var className = props.className, isRemovable = props.isRemovable, children = props.children, hasBackground = props.hasBackground, isBold = props.isBold, isFilled = props.isFilled, isTop = props.isTop, kind = props.kind, onRemove = props.onRemove, responsiveMode = props.responsiveMode, passThroughs = __rest(props, ["className", "isRemovable", "children", "hasBackground", "isBold", "isFilled", "isTop", "kind", "onRemove", "responsiveMode"]);
var isSmall = responsiveMode === 'small';
var labelProps = lodash_1.default.get(component_types_1.getFirst(props, Selection.Label), 'props', {});
var iconElement = component_types_1.getFirst(props, Selection.Icon);
var iconChildren = lodash_1.default.get(iconElement, 'props.children');
var icon = iconChildren
? createElement(iconChildren.type, __assign(__assign({}, iconChildren.props), { className: cx('&-Icon', iconChildren.props.className) }))
: defaultIcon(kind, responsiveMode);
return (react_1.default.createElement("div", __assign({}, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(Selection.propTypes)), { className: cx('&', "&-is-" + responsiveMode, kind && "&-" + kind, {
'&-has-background': hasBackground,
'&-is-bold': isBold,
'&-is-filled': isFilled,
'&-is-top': isTop,
'&-no-title': lodash_1.default.isEmpty(labelProps),
}, className) }),
icon,
react_1.default.createElement("div", { className: cx('&-content') },
react_1.default.createElement("div", { className: cx('&-label-container') },
react_1.default.createElement("span", __assign({}, labelProps, { className: cx('&-label', isSmall && '&-label-is-small') })),
isRemovable ? (react_1.default.createElement(CloseIcon_1.default, { isClickable: true, size: !isSmall ? 8 : 16, className: cx('&-close-button', isSmall && '&-close-button-is-small'), onClick: function (_a) {
var event = _a.event;
onRemove({ event: event, props: props });
} })) : null),
!lodash_1.default.isEmpty(children) && (react_1.default.createElement("div", { className: cx('&-children-container') }, lodash_1.default.map(react_1.default.Children.toArray(children), function (child, i) {
if (react_1.default.isValidElement(child) && child.type === Selection) {
return (react_1.default.createElement(Selection, __assign({ key: lodash_1.default.get(component_types_1.getFirst(child.props, Selection.Label), ['props', 'children'], {}) + i }, child.props)));
}
return child;
}))))));
};
Selection.displayName = 'Selection';
Selection.Icon = SelectionIcon;
Selection.Label = SelectionLabel;
Selection.peek = {
description: "\n Used to indicate selections. Selection is very similar to `Tag` but is meant\n to be used in areas of the UI that have more space available to them.\n ",
categories: ['communication'],
};
Selection.defaultProps = defaultProps;
Selection.propTypes = {
className: string(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t"], ["\n\t\t\tAppended to the component-specific class names set on the root element.\n\t\t"]))),
kind: oneOf(['default', 'container', 'success', 'danger', 'info', 'warning'])(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\t\tApplies an icon and styles for the kind of selection.\n\t\t"], ["\n\t\t\tApplies an icon and styles for the kind of selection.\n\t\t"]))),
isTop: bool(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\t\tApply to the top of a nested sequence of Selection components.\n\t\t\tAdds some spacing for a list of top level Selections with nested Selctions inside each.\n\t\t"], ["\n\t\t\tApply to the top of a nested sequence of Selection components.\n\t\t\tAdds some spacing for a list of top level Selections with nested Selctions inside each.\n\t\t"]))),
isFilled: bool(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\t\tOnly applies to `container` Selection components.\n\t\t\tFills with a darker gray background.\n\t\t\tDefaults to false.\n\t\t"], ["\n\t\t\tOnly applies to \\`container\\` Selection components.\n\t\t\tFills with a darker gray background.\n\t\t\tDefaults to false.\n\t\t"]))),
isRemovable: bool(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\t\tShows or hides the little \"x\" for a given item.\n\t\t"], ["\n\t\t\tShows or hides the little \"x\" for a given item.\n\t\t"]))),
hasBackground: bool(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\t\tGives the selection a background. This is desirable when you only have\n\t\t\tone level of nested selections.\n\t\t"], ["\n\t\t\tGives the selection a background. This is desirable when you only have\n\t\t\tone level of nested selections.\n\t\t"]))),
isBold: bool(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\t\tMake the content text bold. This is desirable when you only have one\n\t\t\tlevel of nested selections.\n\t\t"], ["\n\t\t\tMake the content text bold. This is desirable when you only have one\n\t\t\tlevel of nested selections.\n\t\t"]))),
onRemove: func(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n\t\t\tCalled when the close button is clicked.\n\t\t"], ["\n\t\t\tCalled when the close button is clicked.\n\t\t"]))),
Label: node(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n\t\t\tLabel of the component.\n\t\t"], ["\n\t\t\tLabel of the component.\n\t\t"]))),
Icon: node(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n\t\t\tDisplay a custom icon for the selection. Generally you shouldn't need\n\t\t\tthis prop since the `kind` prop will pick the correct icon for you.\n\t\t"], ["\n\t\t\tDisplay a custom icon for the selection. Generally you shouldn't need\n\t\t\tthis prop since the \\`kind\\` prop will pick the correct icon for you.\n\t\t"]))),
children: node(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n\t\t\tArbitrary children.\n\t\t"], ["\n\t\t\tArbitrary children.\n\t\t"]))),
responsiveMode: oneOf(['small', 'medium', 'large'])(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n\t\t\tAdjusts the display of this component. This should typically be driven by\n\t\t\tscreen size. Currently `small` and `large` are explicitly handled by\n\t\t\tthis component.\n\t\t"], ["\n\t\t\tAdjusts the display of this component. This should typically be driven by\n\t\t\tscreen size. Currently \\`small\\` and \\`large\\` are explicitly handled by\n\t\t\tthis component.\n\t\t"]))),
};
exports.default = Selection;
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;
//# sourceMappingURL=Selection.js.map