Skip to content

Commit

Permalink
fix(fab): using new dom
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJim committed Apr 23, 2023
1 parent 7d8ac48 commit 5b759aa
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 55 deletions.
2 changes: 2 additions & 0 deletions site/mobile/components/demo-block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ const slotClassName = computed(() => [
['with-padding']: props.padding,
},
]);
console.log(props.padding);
</script>
15 changes: 15 additions & 0 deletions src/fab/demos/advance.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<t-fab :icon="iconFunc" text="按钮文字" :style="customStyle" @click="onClick" />
</template>

<script lang="ts" setup>
import { h } from 'vue';
import { AddIcon } from 'tdesign-icons-vue-next';
const iconFunc = () => h(AddIcon, { size: '24px' });
const customStyle = 'right: 16px; bottom: 32px;';
const onClick = () => {
console.log('click Fab');
};
</script>
8 changes: 2 additions & 6 deletions src/fab/demos/display.vue → src/fab/demos/base.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<template>
<div>
<t-fab :icon="iconFunc" @click="onClick" />
</div>
<t-fab :icon="iconFunc" @click="onClick" />
</template>

<script lang="ts" setup>
import { h } from 'vue';
import { AddIcon } from 'tdesign-icons-vue-next';
const iconFunc = () => h(AddIcon);
const iconFunc = () => h(AddIcon, { size: '24px' });
const onClick = () => {
console.log('click Fab');
};
</script>

<style lang="less" scoped></style>
30 changes: 21 additions & 9 deletions src/fab/demos/mobile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@
<div class="tdesign-mobile-demo">
<h1 class="title">Fab 悬浮按钮</h1>
<p class="summary">当功能使用图标即可表示清楚时,可使用纯图标悬浮按钮,例如:添加、发布。</p>
<tdesign-demo-block title="01 类型" summary="纯图标悬浮按钮">
<div class="toast-demo">
<t-button block size="large" variant="outline" @click="changeType('base')">基础使用</t-button>
<t-button block size="large" variant="outline" @click="changeType('advanced')">进阶使用</t-button>
</div>
<tdesign-demo-block title="01 组件类型" summary="纯图标悬浮按钮" :padding="true">
<t-button v-bind="btnProps" @click="changeType('base')">纯图标悬浮按钮</t-button>
</tdesign-demo-block>
<tdesign-demo-block summary="图标加文字悬浮按钮" :padding="true">
<t-button v-bind="btnProps" @click="changeType('advance')">图标加文字悬浮按钮</t-button>
</tdesign-demo-block>
<BaseDemo v-if="type === 'base'" />
<TextDemo v-if="type === 'advanced'" />
<AdvanceDemo v-if="type === 'advance'" />
</div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import BaseDemo from './display.vue';
import TextDemo from './text.vue';
import BaseDemo from './base.vue';
import AdvanceDemo from './advance.vue';
const type = ref('base');
const changeType = (t: string) => (type.value = t);
const btnProps = {
block: true,
size: 'large',
theme: 'primary',
variant: 'outline',
};
</script>

<style lang="less" scoped></style>
<style lang="less" scoped>
.tdesign-mobile-demo {
background-color: #fff;
min-height: 100vh;
box-sizing: border-box;
}
</style>
21 changes: 0 additions & 21 deletions src/fab/demos/text.vue

This file was deleted.

36 changes: 18 additions & 18 deletions src/fab/fab.vue
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
<template>
<t-button v-bind="customButtonProps" :class="classes" :style="style" @click="onClick">
<t-node v-if="iconTNode" :content="iconTNode" />
<span v-if="text" :class="`${name}__text`">{{ text }}</span>
<t-button
size="large"
theme="primary"
:class="classes"
:style="style"
v-bind="btnProps"
:icon="() => iconTNode"
@click="onClick"
>
{{ text }}
</t-button>
</template>

<script lang="ts">
import { computed, defineComponent, getCurrentInstance } from 'vue';
import { renderTNode, TNode, useEmitEvent } from '../shared';
import { renderTNode, useEmitEvent } from '../shared';
import props from './props';
import config from '../config';
import TButton, { TdButtonProps } from '../button';
import TButton from '../button';
const { prefix } = config;
const name = `${prefix}-fab`;
export default defineComponent({
name,
components: { TNode, TButton },
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,
[`${name}--icononly`]: props.icon && !props.text,
}));
const btnProps = computed(() => ({ shape: props.text ? 'round' : 'circle', ...props.buttonProps }));
const onClick = (e: MouseEvent) => emitEvent('click', { e });
const baseButtonProps = {
size: 'middle',
shape: 'round',
theme: 'primary',
};
const customButtonProps = computed(() => ({ ...(baseButtonProps as TdButtonProps), ...props.buttonProps }));
const internalInstance = getCurrentInstance();
const iconTNode = computed(() => renderTNode(internalInstance, 'icon'));
return {
name,
classes,
btnProps,
iconTNode,
customButtonProps,
onClick,
};
},
Expand Down
2 changes: 1 addition & 1 deletion src/fab/style/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import '../../_common/style/mobile/components/fab/_index.less';
import '../../_common/style/mobile/components/fab/v2/_index.less';

0 comments on commit 5b759aa

Please sign in to comment.