UNPKG

tav-ui

Version:
92 lines (85 loc) 3.23 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var Iconify = require('@iconify/iconify'); var is = require('../../../utils/is2.js'); var propTypes = require('../../../utils/propTypes2.js'); var index = require('../../icon-svg/index2.js'); var pluginVue_exportHelper = require('../../../../_virtual/plugin-vue_export-helper.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var Iconify__default = /*#__PURE__*/_interopDefaultLegacy(Iconify); const SVG_END_WITH_FLAG = "|svg"; const _sfc_main = vue.defineComponent({ name: "TaIcon", components: { SvgIcon: index.TaIconSvg }, props: { icon: propTypes.propTypes.string, color: propTypes.propTypes.string, size: { type: [String, Number], default: 16 }, spin: propTypes.propTypes.bool.def(false), prefix: propTypes.propTypes.string.def("") }, setup(props) { const elRef = vue.ref(null); const isSvgIcon = vue.computed(() => props.icon?.endsWith(SVG_END_WITH_FLAG)); const getSvgIcon = vue.computed(() => props.icon.replace(SVG_END_WITH_FLAG, "")); const getIconRef = vue.computed(() => `${props.prefix ? `${props.prefix}:` : ""}${props.icon}`); const update = async () => { if (vue.unref(isSvgIcon)) return; const el = vue.unref(elRef); if (!el) return; await vue.nextTick(); const icon = vue.unref(getIconRef); if (!icon) return; const svg = Iconify__default["default"].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 = vue.computed(() => { const { size, color } = props; let fs = size; if (is.isString(size)) fs = parseInt(size, 10); return { fontSize: `${fs}px`, color, display: "inline-flex" }; }); vue.watch(() => props.icon, update, { flush: "post" }); vue.onMounted(update); return { elRef, getWrapStyle, isSvgIcon, getSvgIcon }; } }); function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_SvgIcon = vue.resolveComponent("SvgIcon"); return _ctx.isSvgIcon ? (vue.openBlock(), vue.createBlock(_component_SvgIcon, { key: 0, size: _ctx.size, name: _ctx.getSvgIcon, class: vue.normalizeClass([_ctx.$attrs.class, "anticon"]), spin: _ctx.spin }, null, 8, ["size", "name", "class", "spin"])) : (vue.openBlock(), vue.createElementBlock("span", { key: 1, ref: "elRef", class: vue.normalizeClass([_ctx.$attrs.class, "app-iconify anticon", _ctx.spin && "app-iconify-spin"]), style: vue.normalizeStyle(_ctx.getWrapStyle) }, null, 6)); } var Icon = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/tav-ui/tav-ui/packages/components/icon/src/icon.vue"]]); exports["default"] = Icon; //# sourceMappingURL=icon2.js.map