Commit fdafcd2cc519033af68dca396078cb1f1b00beb1
1 parent
0ff50807
Badge add text prop
Showing
4 changed files
with
28 additions
and
6 deletions
Show diff stats
examples/routers/badge.vue
@@ -14,14 +14,17 @@ | @@ -14,14 +14,17 @@ | ||
14 | </style> | 14 | </style> |
15 | <template> | 15 | <template> |
16 | <div> | 16 | <div> |
17 | - <Badge dot :count="count"> | 17 | + <Badge :count="count"> |
18 | <a href="#" class="demo-badge"></a> | 18 | <a href="#" class="demo-badge"></a> |
19 | </Badge> | 19 | </Badge> |
20 | <Badge :count="0" showZero> | 20 | <Badge :count="0" showZero> |
21 | <a href="#" class="demo-badge"></a> | 21 | <a href="#" class="demo-badge"></a> |
22 | </Badge> | 22 | </Badge> |
23 | <Button @click="setCount">set count</Button> | 23 | <Button @click="setCount">set count</Button> |
24 | - | 24 | + <br><br> |
25 | + <Badge text="hot"> | ||
26 | + <Button type="ghost">Hello</Button> | ||
27 | + </Badge> | ||
25 | </div> | 28 | </div> |
26 | </template> | 29 | </template> |
27 | <script> | 30 | <script> |
@@ -29,7 +32,7 @@ | @@ -29,7 +32,7 @@ | ||
29 | props: {}, | 32 | props: {}, |
30 | data () { | 33 | data () { |
31 | return { | 34 | return { |
32 | - count: 50 | 35 | + count: 5 |
33 | }; | 36 | }; |
34 | }, | 37 | }, |
35 | methods: { | 38 | methods: { |
examples/routers/cell.vue
@@ -2,7 +2,9 @@ | @@ -2,7 +2,9 @@ | ||
2 | <div style="margin: 100px;background: #f8f8f9;padding: 100px;"> | 2 | <div style="margin: 100px;background: #f8f8f9;padding: 100px;"> |
3 | <Card title="选项" :padding="0" shadow style="width: 300px;"> | 3 | <Card title="选项" :padding="0" shadow style="width: 300px;"> |
4 | <CellGroup @on-click="handleClick"> | 4 | <CellGroup @on-click="handleClick"> |
5 | - <Cell title="标题一" name="a1" label="附属内容" to="/button"></Cell> | 5 | + <Cell title="标题一" name="a1" label="附属内容" to="/button"> |
6 | + <Badge count="10" slot="extra"></Badge> | ||
7 | + </Cell> | ||
6 | <Cell title="标题一" name="a2" label="附属内容" extra="详细信息"></Cell> | 8 | <Cell title="标题一" name="a2" label="附属内容" extra="详细信息"></Cell> |
7 | <Cell title="标题一" name="a3" label="附属内容" extra="详细信息" to="/button"></Cell> | 9 | <Cell title="标题一" name="a3" label="附属内容" extra="详细信息" to="/button"></Cell> |
8 | <Cell title="标题一" name="a4" label="附属内容" selected></Cell> | 10 | <Cell title="标题一" name="a4" label="附属内容" selected></Cell> |
src/components/badge/badge.vue
@@ -9,12 +9,13 @@ | @@ -9,12 +9,13 @@ | ||
9 | </span> | 9 | </span> |
10 | </template> | 10 | </template> |
11 | <script> | 11 | <script> |
12 | + import { oneOf } from '../../utils/assist'; | ||
12 | const prefixCls = 'ivu-badge'; | 13 | const prefixCls = 'ivu-badge'; |
13 | 14 | ||
14 | export default { | 15 | export default { |
15 | name: 'Badge', | 16 | name: 'Badge', |
16 | props: { | 17 | props: { |
17 | - count: [Number, String], | 18 | + count: Number, |
18 | dot: { | 19 | dot: { |
19 | type: Boolean, | 20 | type: Boolean, |
20 | default: false | 21 | default: false |
@@ -27,6 +28,18 @@ | @@ -27,6 +28,18 @@ | ||
27 | showZero: { | 28 | showZero: { |
28 | type: Boolean, | 29 | type: Boolean, |
29 | default: false | 30 | default: false |
31 | + }, | ||
32 | + text: { | ||
33 | + type: String, | ||
34 | + default: '' | ||
35 | + }, | ||
36 | + status: { | ||
37 | + validator (value) { | ||
38 | + return oneOf(value, ['success', 'processing', 'default', 'error', 'warning']); | ||
39 | + } | ||
40 | + }, | ||
41 | + offset: { | ||
42 | + type: Array | ||
30 | } | 43 | } |
31 | }, | 44 | }, |
32 | computed: { | 45 | computed: { |
@@ -46,6 +59,7 @@ | @@ -46,6 +59,7 @@ | ||
46 | ]; | 59 | ]; |
47 | }, | 60 | }, |
48 | finalCount () { | 61 | finalCount () { |
62 | + if (this.text !== '') return this.text; | ||
49 | return parseInt(this.count) >= parseInt(this.overflowCount) ? `${this.overflowCount}+` : this.count; | 63 | return parseInt(this.count) >= parseInt(this.overflowCount) ? `${this.overflowCount}+` : this.count; |
50 | }, | 64 | }, |
51 | badge () { | 65 | badge () { |
@@ -64,10 +78,12 @@ | @@ -64,10 +78,12 @@ | ||
64 | } | 78 | } |
65 | } | 79 | } |
66 | 80 | ||
81 | + if (this.text !== '') status = true; | ||
82 | + | ||
67 | return status || this.showZero; | 83 | return status || this.showZero; |
68 | }, | 84 | }, |
69 | hasCount() { | 85 | hasCount() { |
70 | - if(this.count) return true; | 86 | + if(this.count || this.text !== '') return true; |
71 | if(this.showZero && parseInt(this.count) === 0) return true; | 87 | if(this.showZero && parseInt(this.count) === 0) return true; |
72 | else return false; | 88 | else return false; |
73 | }, | 89 | }, |
src/styles/components/badge.less
1 | @badge-prefix-cls: ~"@{css-prefix}badge"; | 1 | @badge-prefix-cls: ~"@{css-prefix}badge"; |
2 | 2 | ||
3 | .@{badge-prefix-cls} { | 3 | .@{badge-prefix-cls} { |
4 | + font-family: "Monospaced Number"; | ||
4 | position: relative; | 5 | position: relative; |
5 | display: inline-block; | 6 | display: inline-block; |
6 | line-height: 1; | 7 | line-height: 1; |