tav-ui
Version:
84 lines (81 loc) • 2.95 kB
JavaScript
import { defineComponent, ref, computed, unref, nextTick, watch, onMounted, resolveComponent, openBlock, createBlock, normalizeClass, createElementBlock, normalizeStyle } from 'vue';
import Iconify from '@iconify/iconify';
import { isString } from '../../../utils/is2.mjs';
import { propTypes } from '../../../utils/propTypes2.mjs';
import { TaIconSvg } from '../../icon-svg/index2.mjs';
import _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs';
const SVG_END_WITH_FLAG = "|svg";
const _sfc_main = defineComponent({
name: "TaIcon",
components: { SvgIcon: TaIconSvg },
props: {
icon: propTypes.string,
color: propTypes.string,
size: {
type: [String, Number],
default: 16
},
spin: propTypes.bool.def(false),
prefix: propTypes.string.def("")
},
setup(props) {
const elRef = ref(null);
const isSvgIcon = computed(() => props.icon?.endsWith(SVG_END_WITH_FLAG));
const getSvgIcon = computed(() => props.icon.replace(SVG_END_WITH_FLAG, ""));
const getIconRef = computed(() => `${props.prefix ? `${props.prefix}:` : ""}${props.icon}`);
const update = async () => {
if (unref(isSvgIcon))
return;
const el = unref(elRef);
if (!el)
return;
await nextTick();
const icon = unref(getIconRef);
if (!icon)
return;
const svg = Iconify.renderSVG(icon, {});
if (svg) {
el.textContent = "";
el.appendChild(svg);
} else {
const span = document.createElement("span");
span.className = "iconify";
span.dataset.icon = icon;
el.textContent = "";
el.appendChild(span);
}
};
const getWrapStyle = computed(() => {
const { size, color } = props;
let fs = size;
if (isString(size))
fs = parseInt(size, 10);
return {
fontSize: `${fs}px`,
color,
display: "inline-flex"
};
});
watch(() => props.icon, update, { flush: "post" });
onMounted(update);
return { elRef, getWrapStyle, isSvgIcon, getSvgIcon };
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_SvgIcon = resolveComponent("SvgIcon");
return _ctx.isSvgIcon ? (openBlock(), createBlock(_component_SvgIcon, {
key: 0,
size: _ctx.size,
name: _ctx.getSvgIcon,
class: normalizeClass([_ctx.$attrs.class, "anticon"]),
spin: _ctx.spin
}, null, 8, ["size", "name", "class", "spin"])) : (openBlock(), createElementBlock("span", {
key: 1,
ref: "elRef",
class: normalizeClass([_ctx.$attrs.class, "app-iconify anticon", _ctx.spin && "app-iconify-spin"]),
style: normalizeStyle(_ctx.getWrapStyle)
}, null, 6));
}
var Icon = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/tav-ui/tav-ui/packages/components/icon/src/icon.vue"]]);
export { Icon as default };
//# sourceMappingURL=icon2.mjs.map