lucid-ui
Version:
A UI component library from AppNexus.
105 lines • 8.54 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 });
exports.propTypes = exports.Icon = exports.Color = 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 cx = style_helpers_1.lucidClassNames.bind('&-Icon');
var any = prop_types_1.default.any, string = prop_types_1.default.string, number = prop_types_1.default.number, bool = prop_types_1.default.bool, func = prop_types_1.default.func, oneOf = prop_types_1.default.oneOf, oneOfType = prop_types_1.default.oneOfType;
var Color;
(function (Color) {
Color["neutral-dark"] = "neutral-dark";
Color["neutral-light"] = "neutral-light";
Color["primary"] = "primary";
Color["white"] = "white";
Color["success"] = "success";
Color["warning"] = "warning";
Color["secondary-one"] = "secondary-one";
Color["secondary-two"] = "secondary-two";
Color["secondary-three"] = "secondary-three";
})(Color = exports.Color || (exports.Color = {}));
var defaultProps = {
size: 16,
aspectRatio: 'xMidYMid meet',
viewBox: '0 0 16 16',
isDisabled: false,
isClickable: false,
color: Color.primary,
onClick: lodash_1.default.noop,
onSelect: lodash_1.default.noop,
};
var Icon = function (props) {
var _a;
var className = props.className, children = props.children, color = props.color, size = props.size, width = props.width, height = props.height, viewBox = props.viewBox, aspectRatio = props.aspectRatio, isClickable = props.isClickable, isDisabled = props.isDisabled, onClick = props.onClick, onSelect = props.onSelect, passThroughs = __rest(props, ["className", "children", "color", "size", "width", "height", "viewBox", "aspectRatio", "isClickable", "isDisabled", "onClick", "onSelect"]);
var svgRef = react_1.default.createRef();
function handleClick(event) {
onClick && onClick({ event: event, props: props });
if (isClickable && !isDisabled) {
onSelect && onSelect({ event: event, props: props });
if (svgRef.current) {
svgRef.current.focus();
}
}
}
return (react_1.default.createElement("svg", __assign({ width: width ? width : size, height: height ? height : size, viewBox: viewBox, preserveAspectRatio: aspectRatio }, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(exports.Icon.propTypes)), { className: cx('&', (_a = {},
_a["&-color-" + color] = true,
_a['&-is-clickable'] = !isDisabled && isClickable,
_a['&-is-disabled'] = isDisabled,
_a), className), ref: svgRef, onClick: handleClick }), children));
};
exports.Icon = Icon;
exports.Icon.displayName = 'Icon';
exports.Icon.defaultProps = defaultProps;
exports.Icon.peek = {
description: "\n\t\tA basic svg icon. Any props that are not explicitly called out below\n\t\twill be passed through to the native `svg` component.\n\t",
categories: ['visual design', 'icons'],
};
exports.propTypes = {
className: any(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\tClasses that are appended to the component defaults. This prop is run\n\t\tthrough the `classnames` library.\n\t"], ["\n\t\tClasses that are appended to the component defaults. This prop is run\n\t\tthrough the \\`classnames\\` library.\n\t"]))),
size: number(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\tSize variations of the icons. `size` directly effects height and width\n\t\tbut the developer should also be conscious of the relationship with\n\t\t`viewBox`.\n\t"], ["\n\t\tSize variations of the icons. \\`size\\` directly effects height and width\n\t\tbut the developer should also be conscious of the relationship with\n\t\t\\`viewBox\\`.\n\t"]))),
width: oneOfType([number, string])(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\tSize handles width and height, whereas `width` can manually override the width that would be set by size.\n\t"], ["\n\t\tSize handles width and height, whereas \\`width\\` can manually override the width that would be set by size.\n\t"]))),
height: oneOfType([number, string])(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\tSize handles width and height, whereas `height` can manually override the height that would be set by size.\n\t"], ["\n\t\tSize handles width and height, whereas \\`height\\` can manually override the height that would be set by size.\n\t"]))),
viewBox: string(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\t`viewBox` is very important for SVGs. You can think of `viewBox` as\n\t\tthe \"artboard\" for our SVG while `size` is the presented height and\n\t\twidth.\n\t"], ["\n\t\t\\`viewBox\\` is very important for SVGs. You can think of \\`viewBox\\` as\n\t\tthe \"artboard\" for our SVG while \\`size\\` is the presented height and\n\t\twidth.\n\t"]))),
aspectRatio: string(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\tAny valid SVG aspect ratio.\n\t"], ["\n\t\tAny valid SVG aspect ratio.\n\t"]))),
isClickable: bool(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\tAdds styling that makes the icon appear clickable.\n\t"], ["\n\t\tAdds styling that makes the icon appear clickable.\n\t"]))),
isDisabled: bool(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n\t\tAdds styling that makes the icon appear disabled. Also forces\n\t\tisClickable to be false.\n\t"], ["\n\t\tAdds styling that makes the icon appear disabled. Also forces\n\t\tisClickable to be false.\n\t"]))),
onClick: func(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n\t\tCalled when the user clicks the `Icon`. Signature:\n\t\t`({event, props}) => {}`\n\t"], ["\n\t\tCalled when the user clicks the \\`Icon\\`. Signature:\n\t\t\\`({event, props}) => {}\\`\n\t"]))),
onSelect: func(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n\t\tCalled when the user clicks an active, clickable `Icon`. Signature:\n\t\t`({event, props}) => {}`\n\t"], ["\n\t\tCalled when the user clicks an active, clickable \\`Icon\\`. Signature:\n\t\t\\`({event, props}) => {}\\`\n\t"]))),
children: any(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n\t\tAny valid React children.\n\t"], ["\n\t\tAny valid React children.\n\t"]))),
color: oneOf(lodash_1.default.values(Color))(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n\t\tSets the color of the Icon. May not be applicable for icons that are tied\n\t\tto specific colors (e.g. DangerIcon).\n\t"], ["\n\t\tSets the color of the Icon. May not be applicable for icons that are tied\n\t\tto specific colors (e.g. DangerIcon).\n\t"]))),
};
exports.Icon.propTypes = exports.propTypes;
exports.default = exports.Icon;
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=Icon.js.map