index.vue 1.0 KB
Newer Older
richard_1015's avatar
richard_1015 已提交
1
<script lang="ts">
richard_1015's avatar
richard_1015 已提交
2
import { h, PropType } from 'vue';
richard_1015's avatar
richard_1015 已提交
3 4 5 6 7
import { createComponent } from '@/utils/create';
const { componentName, create } = createComponent('icon');

export default create({
  props: {
richard_1015's avatar
richard_1015 已提交
8 9
    name: {
      type: String,
richard_1015's avatar
richard_1015 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22
      default: ''
    },
    size: {
      type: String,
      default: ''
    },
    classPrefix: {
      type: String,
      default: 'nutui-iconfont'
    },
    color: {
      type: String,
      default: ''
richard_1015's avatar
richard_1015 已提交
23 24 25 26 27
    },
    tag: {
      type: String as PropType<keyof HTMLElementTagNameMap>,
      default: 'i'
    }
richard_1015's avatar
richard_1015 已提交
28 29 30
  },
  components: {},
  emits: ['click'],
richard_1015's avatar
richard_1015 已提交
31 32

  setup(props, { emit, slots }) {
richard_1015's avatar
richard_1015 已提交
33 34 35 36
    const handleClick = (event: Event) => {
      emit('click', event);
    };

richard_1015's avatar
richard_1015 已提交
37 38
    return () =>
      h(
richard_1015's avatar
richard_1015 已提交
39
        props.tag,
richard_1015's avatar
richard_1015 已提交
40
        {
richard_1015's avatar
richard_1015 已提交
41 42
          class: `${props.classPrefix} ${componentName}-${props.name}`,
          style: { color: props.color, fontSize: props.size },
richard_1015's avatar
richard_1015 已提交
43 44 45 46
          onClick: handleClick
        },
        slots.default?.()
      );
richard_1015's avatar
richard_1015 已提交
47 48 49 50 51 52 53
  }
});
</script>

<style lang="scss">
@import 'index.scss';
</style>