Skip to content

Commit

Permalink
refactor(fab): using setup (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJim committed Jun 25, 2023
1 parent 1bbd645 commit 346aa37
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions src/fab/fab.vue
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
<template>
<div :class="classes" :style="style" @click="onClick">
<t-button size="large" theme="primary" :class="[`${name}__button`]" v-bind="btnProps" :icon="() => iconTNode">
<t-button
size="large"
theme="primary"
:shape="props.text ? 'round' : 'circle'"
:class="[`${name}__button`]"
v-bind="buttonProps"
:icon="() => iconTNode"
>
{{ text }}
</t-button>
</div>
</template>

<script lang="ts">
import { computed, defineComponent, getCurrentInstance } from 'vue';
import { computed, defineProps, defineEmits, getCurrentInstance } from 'vue';
import { renderTNode, useEmitEvent } from '../shared';
import props from './props';
import fabProps from './props';
import config from '../config';
import TButton, { ButtonProps } from '../button';
import TButton from '../button';
const { prefix } = config;
const name = `${prefix}-fab`;
export default defineComponent({
export default {
name,
components: { TButton },
props,
emits: ['click'],
setup(props, context) {
const internalInstance = getCurrentInstance();
const iconTNode = computed(() => renderTNode(internalInstance, 'icon'));
const emitEvent = useEmitEvent(props, context.emit);
const classes = computed(() => ({
[`${name}`]: true,
}));
const btnProps = computed<ButtonProps>(() => ({ shape: props.text ? 'round' : 'circle', ...props.buttonProps }));
const onClick = (e: MouseEvent) => emitEvent('click', { e });
return {
name,
classes,
btnProps,
iconTNode,
onClick,
};
},
});
};
</script>

<script lang="ts" setup>
const props = defineProps(fabProps);
const emit = defineEmits(['click']);
const internalInstance = getCurrentInstance();
const iconTNode = computed(() => renderTNode(internalInstance, 'icon'));
const emitEvent = useEmitEvent(props, emit);
const classes = computed(() => ({
[`${name}`]: true,
}));
const onClick = (e: MouseEvent) => emitEvent('click', { e });
</script>

0 comments on commit 346aa37

Please sign in to comment.