Skip to content

Commit 8a5707e

Browse files
committed
css最小影响原则
1 parent 25458ab commit 8a5707e

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

src/index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ body {
2424
// 为什么这样写 font-family
2525
// 答案见 https://github.com/zenozeng/fonts.css/
2626
font-family: -apple-system, "Noto Sans", "Helvetica Neue", Helvetica, "Nimbus Sans L", Arial, "Liberation Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN", "Microsoft YaHei", "Wenquanyi Micro Hei", "WenQuanYi Zen Hei", "ST Heiti", SimHei, "WenQuanYi Zen Hei Sharp", sans-serif;
27-
}
27+
}

src/lib/Button.vue

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<button class="zhiwei-button" :class="`theme-${theme}`">
2+
<button class="zhiwei-button" :class="`zhiwei-theme-${theme}`">
33
<slot></slot>
44
</button>
55
</template>
@@ -15,6 +15,39 @@ props:{
1515
};
1616
</script>
1717

18-
<style lang="scss" scoped>
19-
18+
<style lang="scss">
19+
$h: 32px;
20+
$border-color: #d9d9d9;
21+
$color: #333;
22+
$blue: #40a9ff;
23+
$radius: 4px;
24+
.zhiwei-button {
25+
box-sizing: border-box;
26+
height: $h;
27+
padding: 0 12px;
28+
cursor: pointer;
29+
display: inline-flex;
30+
justify-content: center;
31+
align-items: center;
32+
white-space: nowrap;
33+
background: white;
34+
color: $color;
35+
border: 1px solid $border-color;
36+
border-radius: $radius;
37+
box-shadow: 0 1px 0 fade-out(black, 0.95);
38+
& + & {
39+
margin-left: 8px;
40+
}
41+
&:hover,
42+
&:focus {
43+
color: $blue;
44+
border-color: $blue;
45+
}
46+
&:focus {
47+
outline: none;
48+
}
49+
&::-moz-focus-inner {
50+
border: 0;
51+
}
52+
}
2053
</style>

src/lib/Switch.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<button @click="toggle" :class="{checked:value}"><span></span></button>
2+
<button class="zhiwei-switch" @click="toggle" :class="{'zhiwei-checked':value}"><span></span></button>
33
</template>
44
<script lang="ts">
55
export default {
@@ -16,10 +16,10 @@ export default {
1616
}
1717
};
1818
</script>
19-
<style lang="scss" scoped>
19+
<style lang="scss">
2020
$h: 22px;
2121
$h2: $h - 4px;
22-
button {
22+
.zhiwei-switch {
2323
height: $h;
2424
width: $h * 2;
2525
border: none;
@@ -38,7 +38,7 @@ button {
3838
transition: all 250ms;
3939
}
4040
41-
&.checked {
41+
&.zhiwei-checked {
4242
background: #1890ff;
4343
4444
> span {
@@ -56,7 +56,7 @@ button {
5656
}
5757
}
5858
59-
&.checked:active {
59+
&.zhiwei-checked:active {
6060
> span {
6161
width: $h2 + 4px;
6262
margin-left: -4px;

src/lib/zhiwei.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[class^="zhiwei-"], [class*=" zhiwei-"] {
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
font-size: 16px;
6+
// 为什么这样写 font-family
7+
// 答案见 https://github.com/zenozeng/fonts.css/
8+
font-family: -apple-system, "Noto Sans", "Helvetica Neue", Helvetica, "Nimbus Sans L", Arial, "Liberation Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN", "Microsoft YaHei", "Wenquanyi Micro Hei", "WenQuanYi Zen Hei", "ST Heiti", SimHei, "WenQuanYi Zen Hei Sharp", sans-serif;
9+
}

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import "./lib/zhiwei.scss";
2+
import "./index.scss";
13
import { createApp } from "vue";
24
import App from "./App.vue";
3-
import "./index.scss";
45
import { router } from './router';
56

67
const app = createApp(App);

0 commit comments

Comments
 (0)