Skip to content

Commit 8da9000

Browse files
committed
添加size属性,类名class优化
1 parent 8a5707e commit 8da9000

File tree

2 files changed

+64
-7
lines changed

2 files changed

+64
-7
lines changed

src/components/ButtonDemo.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
<template>
22
<div>
3-
<h1>Button 示例</h1>
3+
<h1>Button 示例 1</h1>
44
<div>
55
<Button @click="onClick">你好</Button>
66
<Button @click="onClick" theme="button">你好</Button>
77
<Button @click="onClick" theme="text">你好</Button>
88
<Button @click="onClick" theme="link">你好</Button>
99
</div>
10+
<h1>Button 示例 2</h1>
11+
<div>
12+
<Button>你好</Button>
13+
<Button size="big">你好</Button>
14+
<Button size="small">你好</Button>
15+
<Button size="mini">你好</Button>
16+
</div>
1017
</div>
1118
</template>
1219
<script lang="ts">

src/lib/Button.vue

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
<template>
2-
<button class="zhiwei-button" :class="`zhiwei-theme-${theme}`">
2+
<button class="zhiwei-button" :class="classes">
33
<slot></slot>
44
</button>
55
</template>
66

77
<script lang="ts">
8+
import { computed } from 'vue'
89
export default {
9-
props:{
10-
theme:{
11-
type:String,
12-
default: 'button'
10+
props:{
11+
theme:{
12+
type:String,
13+
default: 'button'
14+
},
15+
size:{
16+
type: String,
17+
default: 'normal'
18+
}
19+
},
20+
setup(props){
21+
const { theme,size } = props
22+
const classes = computed(()=>{
23+
return {
24+
[`zhiwei-theme-${theme}`]:theme,
25+
[`zhiwei-size-${size}`]:size
26+
}
27+
})
28+
return {
29+
classes
30+
}
1331
}
14-
}
1532
};
1633
</script>
1734

@@ -49,5 +66,38 @@ $radius: 4px;
4966
&::-moz-focus-inner {
5067
border: 0;
5168
}
69+
&.zhiwei-theme-link {
70+
border-color: transparent;
71+
box-shadow: none;
72+
color: $blue;
73+
&:hover,
74+
&:focus {
75+
color: lighten($blue, 10%);
76+
}
77+
}
78+
&.zhiwei-theme-text {
79+
border-color: transparent;
80+
box-shadow: none;
81+
color: inherit;
82+
&:hover,
83+
&:focus {
84+
background: darken(white, 5%);
85+
}
86+
}
87+
&.zhiwei-size-big {
88+
font-size: 24px;
89+
height: 48px;
90+
padding: 0 16px;
91+
}
92+
&.zhiwei-size-small {
93+
font-size: 12px;
94+
height: 20px;
95+
padding: 0 4px;
96+
}
97+
&.zhiwei-size-mini {
98+
font-size: 10px;
99+
height: 16px;
100+
padding: 0 2px;
101+
}
52102
}
53103
</style>

0 commit comments

Comments
 (0)