@navinc/base-react-components
Version:
Nav's Pattern Library
32 lines • 1.66 kB
JavaScript
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;
};
import { jsx as _jsx } from "react/jsx-runtime";
import { lazy, Suspense, useMemo } from 'react';
import propTypes from 'prop-types';
import styled from 'styled-components';
const Null = () => null;
export const Icon = (_a) => {
var { name = '' } = _a, props = __rest(_a, ["name"]);
const IconComponent = import(`./icons/${name}.js`);
const LazyIcon = 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 = useMemo(() => _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 _jsx(Suspense, Object.assign({ fallback: _jsx(Null, {}, void 0) }, { children: StableIcon }), void 0);
};
Icon.propTypes = {
name: propTypes.string,
};
export default styled(Icon) ``;
//# sourceMappingURL=icon.js.map