import { h, PropType } from 'vue' import { defineVxeComponent } from '../../ui/src/comp' import { VxeUI } from '@vxe-ui/core' import XEUtils from 'xe-utils' import type { VxeIconPropTypes, VxeIconEmits, IconMethods, IconPrivateMethods, VxeIconConstructor, VxeIconPrivateMethods, ValueOf } from '../../../types' const { getConfig, createEvent, useFns } = VxeUI export default /* define-vxe-component start */ defineVxeComponent({ name: 'VxeIcon', props: { name: String as PropType, className: String as PropType, roll: Boolean as PropType, status: String as PropType, size: { type: String as PropType, default: () => getConfig().icon.size || getConfig().size } }, emits: ['click'] as VxeIconEmits, setup(props, context) { const { emit } = context const xID = XEUtils.uniqueId() const { computeSize } = useFns.useSize(props) const $xeIcon = { xID, props, context } as unknown as VxeIconConstructor & VxeIconPrivateMethods const clickEvent = (evnt: KeyboardEvent) => { emit('click', createEvent(evnt, {})) } const dispatchEvent = (type: ValueOf, params: Record, evnt: Event | null) => { emit(type, createEvent(evnt, { $icon: $xeIcon }, params)) } const iconMethods: IconMethods = { dispatchEvent } const iconPrivateMethods: IconPrivateMethods = {} Object.assign($xeIcon, iconMethods, iconPrivateMethods) const renderVN = () => { const { name, roll, status, className } = props const vSize = computeSize.value return h('i', { class: [ 'vxe-icon', `vxe-icon-${name}`, `${className || ''}`, { [`size--${vSize}`]: vSize, [`theme--${status}`]: status, roll: roll } ], onClick: clickEvent }) } $xeIcon.renderVN = renderVN return $xeIcon }, render() { return this.renderVN() } }) /* define-vxe-component end */