UNPKG

comic-plus

Version:

<p align="center"> <img width="200px" src="./logo.png"/> </p>

35 lines (34 loc) 954 B
import { defineComponent, computed, warn, h } from "vue"; import { iconProps } from "./icon.props.mjs"; import * as components from "./components.mjs"; import "../style/icon.css"; const enums = (() => { return Object.keys(components).reduce((sum, acc) => { let key = acc.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase(); sum[key] = acc; return sum; }, {}); })(); const Icon = defineComponent({ name: "CuIcon", props: { ...iconProps, name: { type: String, required: true } }, setup(props) { const currentIcon = computed(() => { if (!enums[props.name]) { warn("The icon with that name does not exist in the library. Please check if the name is legal"); return null; } return h(components[enums[props.name]], props); }); return () => h("i", { class: "cu-icon" }, currentIcon.value); } }); export { Icon as default };