@nutui/icons-react-taro
Version:
京东风格的icon库-V15
177 lines (176 loc) • 3.98 kB
JavaScript
import React from "react";
import { globalConfig } from "./internal.js";
import { Image } from "@tarojs/components";
const defaultProps$1 = {
className: "",
style: void 0,
name: "",
width: "",
height: "",
size: "",
svg64: "",
svgSrc: "",
onClick: () => void 0
};
const Icon$1 = (props) => {
const classPrefix = globalConfig.classPrefix;
const {
className,
style,
name,
color,
width,
height,
size,
svg64,
svgSrc,
children,
onClick,
ariaRole,
ariaLabel,
ariaRoledescription,
ariaHidden,
ariaChecked,
ariaSelected,
fallback = !globalConfig.useSvg
} = { ...defaultProps$1, ...props };
const handleClick = (e) => {
onClick && onClick(e);
};
const pxCheck = (value) => {
if (value === "")
return "";
return isNaN(Number(value)) ? String(value) : value + "px";
};
const classes = () => {
const iconName = fallback ? name == null ? void 0 : name.toLowerCase() : name;
return `${fallback ? globalConfig.fontClassName : ""} ${classPrefix} ${classPrefix}-${iconName} ${className}`;
};
const props2Style = {};
const checkedWidth = pxCheck(width || size || "");
const checkedHeight = pxCheck(height || size || "");
if (checkedWidth) {
props2Style["width"] = checkedWidth;
}
if (checkedHeight) {
props2Style["height"] = checkedHeight;
}
const svg64Style = process.env.TARO_ENV === "h5" ? {
mask: `url('${svg64}') 0 0/100% 100% no-repeat`,
WebkitMask: `url('${svg64}') 0 0/100% 100% no-repeat`
} : {
mask: `url('${svg64}') 0 0/100% 100% no-repeat`,
"-webkitMask": `url('${svg64}') 0 0/100% 100% no-repeat`
};
const getStyle = () => {
return {
...style,
...fallback ? {} : {
backgroundColor: color || "currentColor",
...svg64Style
},
...props2Style
};
};
return React.createElement(
globalConfig.tag,
{
className: classes(),
style: getStyle(),
onClick: handleClick,
color,
role: ariaRole,
"aria-label": ariaLabel,
"aria-roledescription": ariaRoledescription,
"aria-hidden": ariaHidden,
"aria-checked": ariaChecked,
"aria-selected": ariaSelected
},
children
);
};
const Icon$2 = Icon$1;
const defaultProps = {
className: "",
style: void 0,
name: "",
width: "",
height: "",
size: "",
svg64: "",
svgSrc: "",
onClick: () => void 0
};
const Icon = (props) => {
const classPrefix = globalConfig.classPrefix;
const {
className,
style,
name,
color,
width,
height,
size,
svgSrc,
children,
onClick,
ariaRole,
ariaLabel,
ariaRoledescription,
ariaHidden,
ariaChecked,
ariaSelected,
fallback = !globalConfig.useSvg
} = { ...defaultProps, ...props };
const handleClick = (e) => {
onClick && onClick(e);
};
const pxCheck = (value) => {
if (value === "")
return 0;
return parseInt(value);
};
const classes = () => {
const iconName = fallback ? name == null ? void 0 : name.toLowerCase() : name;
return `${fallback ? globalConfig.fontClassName : ""} ${classPrefix} ${classPrefix}-${iconName} ${className}`;
};
const props2Style = {};
const checkedWidth = pxCheck(width || size || "");
const checkedHeight = pxCheck(height || size || "");
if (checkedWidth) {
props2Style["width"] = checkedWidth;
}
if (checkedHeight) {
props2Style["height"] = checkedHeight;
}
const getStyle = () => {
return {
...style,
...props2Style,
color
};
};
return React.createElement(
Image,
{
src: svgSrc,
className: classes(),
style: getStyle(),
onClick: handleClick,
svg: true,
ariaRole,
ariaLabel,
ariaRoledescription,
ariaHidden,
ariaChecked,
ariaSelected
},
children
);
};
const Icon2 = Icon;
export {
Icon$2 as I,
Icon2 as a,
defaultProps$1 as d
};