feat(Tag): add show prop and fix transition

This commit is contained in:
chenjiahan 2020-07-25 16:12:12 +08:00
parent 73d538be05
commit 7317a1379b
4 changed files with 21 additions and 19 deletions

View File

@ -68,19 +68,19 @@ Vue.use(Tag);
```html ```html
<van-tag <van-tag
v-if="show.primary"
closeable closeable
size="medium" size="medium"
type="primary" type="primary"
:show="show.primary"
@close="close('primary')" @close="close('primary')"
> >
Tag Tag
</van-tag> </van-tag>
<van-tag <van-tag
v-if="show.success"
closeable closeable
size="medium" size="medium"
type="success" type="success"
:show="show.success"
@close="close('success')" @close="close('success')"
> >
Tag Tag
@ -114,6 +114,7 @@ export default {
| type | Type, can be set to `primary` `success` `danger` `warning` | _string_ | `default` | | type | Type, can be set to `primary` `success` `danger` `warning` | _string_ | `default` |
| size | Size, can be set to `large` `medium` | _string_ | - | | size | Size, can be set to `large` `medium` | _string_ | - |
| color | Custom color | _string_ | - | | color | Custom color | _string_ | - |
| show | Whether to show tag | _boolean_ | `true` |
| plain | Whether to be plain style | _boolean_ | `false` | | plain | Whether to be plain style | _boolean_ | `false` |
| round | Whether to be round style | _boolean_ | `false` | | round | Whether to be round style | _boolean_ | `false` |
| mark | Whether to be mark style | _boolean_ | `false` | | mark | Whether to be mark style | _boolean_ | `false` |

View File

@ -78,19 +78,19 @@ Vue.use(Tag);
```html ```html
<van-tag <van-tag
v-if="show.primary"
closeable closeable
size="medium" size="medium"
type="primary" type="primary"
:show="show.primary"
@close="close('primary')" @close="close('primary')"
> >
标签 标签
</van-tag> </van-tag>
<van-tag <van-tag
v-if="show.success"
closeable closeable
size="medium" size="medium"
type="success" type="success"
:show="show.success"
@close="close('success')" @close="close('success')"
> >
标签 标签
@ -124,6 +124,7 @@ export default {
| type | 类型,可选值为`primary` `success` `danger` `warning` | _string_ | `default` | | type | 类型,可选值为`primary` `success` `danger` `warning` | _string_ | `default` |
| size | 大小, 可选值为`large` `medium` | _string_ | - | | size | 大小, 可选值为`large` `medium` | _string_ | - |
| color | 标签颜色 | _string_ | - | | color | 标签颜色 | _string_ | - |
| show | 是否展示标签 | _boolean_ | `true` |
| plain | 是否为空心样式 | _boolean_ | `false` | | plain | 是否为空心样式 | _boolean_ | `false` |
| round | 是否为圆角样式 | _boolean_ | `false` | | round | 是否为圆角样式 | _boolean_ | `false` |
| mark | 是否为标记样式 | _boolean_ | `false` | | mark | 是否为标记样式 | _boolean_ | `false` |

View File

@ -43,8 +43,8 @@
<demo-block :title="t('closeable')"> <demo-block :title="t('closeable')">
<van-tag <van-tag
v-if="show.primary"
size="medium" size="medium"
:show="show.primary"
closeable closeable
type="primary" type="primary"
@close="close('primary')" @close="close('primary')"
@ -52,8 +52,8 @@
{{ t('tag') }} {{ t('tag') }}
</van-tag> </van-tag>
<van-tag <van-tag
v-if="show.success"
size="medium" size="medium"
:show="show.success"
closeable closeable
type="success" type="success"
@close="close('success')" @close="close('success')"

View File

@ -1,7 +1,5 @@
// Utils import { Transition } from 'vue';
import { createNamespace } from '../utils'; import { createNamespace } from '../utils';
// Components
import Icon from '../icon'; import Icon from '../icon';
const [createComponent, bem] = createNamespace('tag'); const [createComponent, bem] = createNamespace('tag');
@ -19,6 +17,10 @@ export default createComponent({
type: String, type: String,
default: 'default', default: 'default',
}, },
show: {
type: Boolean,
default: true,
},
}, },
emits: ['close'], emits: ['close'],
@ -51,16 +53,14 @@ export default createComponent({
); );
return ( return (
<transition name={props.closeable ? 'van-fade' : null}> <Transition name={props.closeable ? 'van-fade' : null}>
<span {props.show ? (
key="content" <span key="content" style={style} class={bem([classes, type])}>
style={style} {slots.default?.()}
class={bem([classes, type])} {CloseIcon}
> </span>
{slots.default?.()} ) : null}
{CloseIcon} </Transition>
</span>
</transition>
); );
}; };
}, },