UNPKG

@navinc/base-react-components

Version:
58 lines 3 kB
"use strict"; 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.Icon = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const prop_types_1 = __importDefault(require("prop-types")); const styled_components_1 = __importDefault(require("styled-components")); const Null = () => null; const Icon = (_a) => { var { name = '' } = _a, props = __rest(_a, ["name"]); const IconComponent = Promise.resolve().then(() => __importStar(require(`./icons/${name}.js`))); const LazyIcon = (0, react_1.lazy)(() => IconComponent); // Without a memoized version, rerendering of the same SVG icon sometimes causes a flicker. This stableizes it so it doesn't even try to rerender the same icon const StableIcon = (0, react_1.useMemo)(() => (0, jsx_runtime_1.jsx)(LazyIcon, Object.assign({ width: "24", height: "24", viewBox: "0 0 24 24", "data-testid": `icon:${name}` }, props), void 0), // eslint doesn't recognize that what is happening here actually is being exhaustive in the dependency array // eslint-disable-next-line react-hooks/exhaustive-deps [name, ...Object.values(props)]); return (0, jsx_runtime_1.jsx)(react_1.Suspense, Object.assign({ fallback: (0, jsx_runtime_1.jsx)(Null, {}, void 0) }, { children: StableIcon }), void 0); }; exports.Icon = Icon; exports.Icon.propTypes = { name: prop_types_1.default.string, }; exports.default = (0, styled_components_1.default)(exports.Icon) ``; //# sourceMappingURL=icon.js.map