Skip to content

Commit ce1d47e

Browse files
committed
refactor(badge): move to script setup
1 parent 2a9d7a0 commit ce1d47e

12 files changed

Lines changed: 190 additions & 182 deletions

File tree

src/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@
719719
"name": "Badge",
720720
"cName": "徽标",
721721
"desc": "徽标",
722+
"setup": true,
722723
"author": "liqiong"
723724
},
724725
{
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<template>
2+
<view class="nut-badge">
3+
<view v-show="!hidden && !dot && $slots.icon" class="nut-badge__icon" :style="style">
4+
<slot name="icon"></slot>
5+
</view>
6+
<slot></slot>
7+
<view
8+
v-show="!hidden && (content || dot)"
9+
class="nut-badge__content nut-badge__content--sup"
10+
:class="{ 'nut-badge__content--dot': dot, 'nut-badge__content--bubble': !dot && bubble }"
11+
:style="style"
12+
>
13+
{{ content }}
14+
</view>
15+
</view>
16+
</template>
17+
18+
<script setup lang="ts">
19+
import { computed } from 'vue'
20+
21+
defineOptions({
22+
name: 'NutBadge'
23+
})
24+
25+
export type BadgeProps = Partial<{
26+
value: string | number
27+
max: number
28+
dot: boolean
29+
bubble: boolean
30+
hidden: boolean
31+
top: string
32+
right: string
33+
zIndex: number
34+
color: string
35+
}>
36+
37+
const props = withDefaults(defineProps<BadgeProps>(), {
38+
max: 10000,
39+
dot: false,
40+
bubble: false,
41+
hidden: false,
42+
top: '0',
43+
right: '0',
44+
zIndex: 9,
45+
color: ''
46+
})
47+
48+
const style = computed(() => {
49+
return {
50+
top: `${props.top}px`,
51+
right: `${props.right}px`,
52+
zIndex: props.zIndex,
53+
background: props.color
54+
}
55+
})
56+
57+
const content = computed(() => {
58+
if (props.dot) return
59+
const value = props.value
60+
const max = props.max
61+
if (typeof value === 'number' && typeof max === 'number') {
62+
return max < value ? `${max}+` : value
63+
}
64+
return value
65+
})
66+
</script>

src/packages/__VUE/badge/badge.vue

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<template>
2+
<view class="nut-badge">
3+
<view v-show="!hidden && !dot && $slots.icon" class="nut-badge__icon" :style="style">
4+
<slot name="icon"></slot>
5+
</view>
6+
<slot></slot>
7+
<view
8+
v-show="!hidden && (content || dot)"
9+
class="nut-badge__content nut-badge__content--sup"
10+
:class="{ 'nut-badge__content--dot': dot, 'nut-badge__content--bubble': !dot && bubble }"
11+
:style="style"
12+
>
13+
{{ content }}
14+
</view>
15+
</view>
16+
</template>
17+
18+
<script setup lang="ts">
19+
import { computed } from 'vue'
20+
21+
defineOptions({
22+
name: 'NutBadge'
23+
})
24+
25+
export type BadgeProps = Partial<{
26+
value: string | number
27+
max: number
28+
dot: boolean
29+
bubble: boolean
30+
hidden: boolean
31+
top: string
32+
right: string
33+
zIndex: number
34+
color: string
35+
}>
36+
37+
const props = withDefaults(defineProps<BadgeProps>(), {
38+
max: 10000,
39+
dot: false,
40+
bubble: false,
41+
hidden: false,
42+
top: '0',
43+
right: '0',
44+
zIndex: 9,
45+
color: ''
46+
})
47+
48+
const style = computed(() => {
49+
return {
50+
top: `${props.top}px`,
51+
right: `${props.right}px`,
52+
zIndex: props.zIndex,
53+
background: props.color
54+
}
55+
})
56+
57+
const content = computed(() => {
58+
if (props.dot) return
59+
const value = props.value
60+
const max = props.max
61+
if (typeof value === 'number' && typeof max === 'number') {
62+
return max < value ? `${max}+` : value
63+
}
64+
return value
65+
})
66+
</script>

src/packages/__VUE/badge/doc.en-US.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ app.use(Badge)
5757
| default | Default slot |
5858
| icon | Icon slot |
5959

60+
### Types version
61+
62+
The component exports the following type definitions:
63+
64+
```js
65+
import type {
66+
BadgeProps,
67+
BadgeInstance
68+
} from '@nutui/nutui'
69+
```
70+
6071
## Theming
6172

6273
### CSS Variables

src/packages/__VUE/badge/doc.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ app.use(Badge)
5757
| default | 徽标包裹的子元素 |
5858
| icon | 徽标自定义 |
5959

60+
### 类型定义 version
61+
62+
组件导出以下类型定义:
63+
64+
```js
65+
import type {
66+
BadgeProps,
67+
BadgeInstance
68+
} from '@nutui/nutui'
69+
```
70+
6071
## 主题定制
6172

6273
### 样式变量

src/packages/__VUE/badge/doc.taro.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ app.use(Badge)
5757
| default | 徽标包裹的子元素 |
5858
| icon | 徽标自定义 |
5959

60+
### 类型定义 version
61+
62+
组件导出以下类型定义:
63+
64+
```js
65+
import type {
66+
BadgeProps,
67+
BadgeInstance
68+
} from '@nutui/nutui-taro'
69+
```
70+
6071
## 主题定制
6172

6273
### 样式变量
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Badge from './badge.taro.vue'
2+
import type { ComponentPublicInstance } from 'vue'
3+
import { withInstall } from '@/packages/utils'
4+
5+
withInstall(Badge)
6+
7+
export type { BadgeProps } from './badge.taro.vue'
8+
9+
export type BadgeInstance = ComponentPublicInstance & InstanceType<typeof Badge>
10+
11+
export { Badge, Badge as default }

src/packages/__VUE/badge/index.taro.vue

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/packages/__VUE/badge/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Badge from './badge.vue'
2+
import type { ComponentPublicInstance } from 'vue'
3+
import { withInstall } from '@/packages/utils'
4+
5+
withInstall(Badge)
6+
7+
export type { BadgeProps } from './badge.vue'
8+
9+
export type BadgeInstance = ComponentPublicInstance & InstanceType<typeof Badge>
10+
11+
export { Badge, Badge as default }

0 commit comments

Comments
 (0)