UNPKG

lucid-ui

Version:

A UI component library from Xandr.

144 lines 5.94 kB
"use strict"; 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("prop-types")); var style_helpers_1 = require("../../util/style-helpers"); 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 }, passThroughs, { className: cx('&', (_a = {}, _a["&-color-".concat(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: "A basic `svg` icon. Any props that are not explicitly called out below will be passed through to the native `svg` component.", categories: ['visual design', 'icons'], }; exports.propTypes = { /** Classes that are appended to the component defaults. This prop is run through the \`classnames\` library. */ className: any, /** Size variations of the icons. \`size\` directly effects height and width but the developer should also be conscious of the relationship with \`viewBox\`. */ size: number, /** Size handles width and height, whereas \`width\` can manually override the width that would be set by size. */ width: oneOfType([number, string]), /** Size handles width and height, whereas \`height\` can manually override the height that would be set by size. */ height: oneOfType([number, string]), /** \`viewBox\` is very important for SVGs. You can think of \`viewBox\` as the "artboard" for our SVG while \`size\` is the presented height and width. */ viewBox: string, /** Any valid SVG aspect ratio. */ aspectRatio: string, /** Adds styling that makes the icon appear clickable. */ isClickable: bool, /** Adds styling that makes the icon appear disabled. Also forces isClickable to be false. */ isDisabled: bool, /** Called when the user clicks the \`Icon\`. Signature: \`({event, props}) => {}\` */ onClick: func, /** Called when the user clicks an active, clickable \`Icon\`. Signature: \`({event, props}) => {}\` */ onSelect: func, /** Any valid React children. */ children: any, /** Sets the color of the Icon. May not be applicable for icons that are tied to specific colors (e.g. DangerIcon). */ color: oneOf(lodash_1.default.values(Color)), }; exports.Icon.propTypes = exports.propTypes; exports.default = exports.Icon; //# sourceMappingURL=Icon.js.map