UNPKG

@navinc/base-react-components

Version:
58 lines 2.64 kB
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 { useEffect } from 'react'; import styled from 'styled-components'; import { iconsMap } from './icons'; import { deprecationWarning } from '@navinc/utils'; const bifilter = (filter, arr) => { const truthy = []; const falsey = []; arr.forEach((item) => { if (filter(item)) { truthy.push(item); } else { falsey.push(item); } }); return [truthy, falsey]; }; const handlerRegExp = /^on[A-Z]/; const partitionHandlerProps = (props) => { const [handlers, nonHandlers] = bifilter(([propName]) => handlerRegExp.test(propName), Object.entries(props)); return [Object.fromEntries(handlers), Object.fromEntries(nonHandlers)]; }; export const Icon = (_a) => { var { name, size = '24' } = _a, props = __rest(_a, ["name", "size"]); const IconComponent = iconsMap[name]; return IconComponent ? (_jsx(IconComponent, Object.assign({ width: size, height: size, viewBox: "0 0 24 24", "data-testid": `icon:${name}` }, props))) : null; }; const NoStyleButton = styled.button.withConfig({ displayName: "brc-sc-NoStyleButton", componentId: "brc-sc-wgddp1" }) ` background: none; color: inherit; border: none; padding: 0; font: inherit; cursor: inherit; outline: inherit; line-height: 0; `; /** Pass all event handler props to a wrapper button to avoid rerendering the icon and causing flicker */ const InteractiveIconInternal = (props) => { useEffect(() => deprecationWarning(true, `The \`InteractiveIcon\` component from Base React Component is deprecated and support will be removed in a future version. Please use \`IconButton\` instead.`), []); const [handlers, nonHandlers] = partitionHandlerProps(props); return (_jsx(NoStyleButton, Object.assign({}, handlers, { children: _jsx(Icon, Object.assign({}, nonHandlers)) }))); }; export const InteractiveIcon = styled(InteractiveIconInternal).withConfig({ displayName: "brc-sc-InteractiveIcon", componentId: "brc-sc-p8eqir" }) ``; export default styled(Icon).withConfig({ componentId: "brc-sc-14pb1u5" }) ``; //# sourceMappingURL=icon.js.map