UNPKG

@hugeicons/react-native

Version:

Hugeicons React Native Component Library https://hugeicons.com

70 lines (69 loc) 2.7 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 { createElement, forwardRef } from 'react'; import { Circle, G, Line, Path, Rect, Svg } from 'react-native-svg'; const SVGComponents = { svg: Svg, path: Path, circle: Circle, rect: Rect, line: Line, g: G, }; const defaultAttributes = { width: 24, height: 24, viewBox: '0 0 24 24', fill: 'none', }; let cssInterop; try { cssInterop = require('nativewind').cssInterop; } catch (e) { // NativeWind is not installed cssInterop = null; } const BaseHugeiconsIcon = forwardRef((_a, ref) => { var { color = '#000', size = 24, strokeWidth, absoluteStrokeWidth = false, className, style, icon, altIcon, showAlt = false } = _a, rest = __rest(_a, ["color", "size", "strokeWidth", "absoluteStrokeWidth", "className", "style", "icon", "altIcon", "showAlt"]); const calculatedStrokeWidth = strokeWidth !== undefined ? (absoluteStrokeWidth ? (Number(strokeWidth) * 24) / Number(size) : strokeWidth) : undefined; const strokeProps = calculatedStrokeWidth !== undefined ? { strokeWidth: calculatedStrokeWidth, stroke: 'currentColor' } : {}; const elementProps = Object.assign(Object.assign(Object.assign(Object.assign({ ref }, defaultAttributes), { width: size, height: size, color }), strokeProps), rest); const currentIcon = showAlt && altIcon ? altIcon : icon; const svgChildren = currentIcon.map((element, index) => { const tag = element[0]; const attrs = element[1]; const SvgComponent = SVGComponents[tag.toLowerCase()]; if (!SvgComponent) return null; return createElement(SvgComponent, Object.assign(Object.assign(Object.assign({}, attrs), strokeProps), { key: `${tag}-${index}` })); }); return createElement(Svg, elementProps, svgChildren); }); // Export a single component that is either styled with NativeWind or not export const HugeiconsIcon = (cssInterop ? cssInterop(BaseHugeiconsIcon, { className: { target: false, nativeStyleToProp: { color: 'color', height: 'height', width: 'width' }, }, }) : BaseHugeiconsIcon);