Skip to content

Commit 45b2b69

Browse files
committed
Add radio component
1 parent 334efea commit 45b2b69

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

src/assets/less/radio.less

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@import "./var.less";
2+
3+
.@{css-prefix}-radio {
4+
position: absolute;
5+
left: -@selectabl-span;
6+
color: #1f2d3d;
7+
user-select: none;
8+
9+
&.is-checked .@{css-prefix}-radio__inner {
10+
background-color: @color-primary;
11+
border-color: darken(@color-primary, 10%);
12+
13+
&:after {
14+
transform: translate(-50%, -50%) scale(1);
15+
}
16+
}
17+
18+
.@{css-prefix}-radio__inner {
19+
border: 1px solid @border-color;
20+
border-radius: 100%;
21+
width: 16px;
22+
height: 16px;
23+
vertical-align: middle;
24+
background-color: #fff;
25+
position: relative;
26+
cursor: pointer;
27+
display: inline-block;
28+
box-sizing: border-box;
29+
30+
&:after {
31+
width: 4px;
32+
height: 4px;
33+
border-radius: 100%;
34+
background-color: #fff;
35+
content: "";
36+
position: absolute;
37+
left: 50%;
38+
top: 50%;
39+
transform: translate(-50%, -50%) scale(0);
40+
transition: transform .15s ease-in;
41+
}
42+
}
43+
44+
.@{css-prefix}-radio__original {
45+
opacity: 0;
46+
outline: none;
47+
position: absolute;
48+
z-index: -1;
49+
top: 0;
50+
left: 0;
51+
right: 0;
52+
bottom: 0;
53+
margin: 0;
54+
}
55+
}

src/components/radio.vue

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<!-- click.stop 避免向上冒泡触发 tree.vue 的 click 事件-->
3+
<label :class="[ 'vjs-radio', model === currentPath ? 'is-checked': '' ]" @click.stop>
4+
<span class="vjs-radio__inner"></span>
5+
<input
6+
class="vjs-radio__original"
7+
type="radio"
8+
v-model="model"
9+
:value="currentPath"
10+
@change="test"
11+
@focus="focus = true"
12+
@blur="focus = false">
13+
</label>
14+
</template>
15+
16+
<script>
17+
export default {
18+
props: {
19+
path: String,
20+
value: {
21+
type: String,
22+
default: ''
23+
}
24+
},
25+
data () {
26+
return {
27+
focus: false
28+
}
29+
},
30+
computed: {
31+
currentPath () {
32+
return this.path
33+
},
34+
35+
model: {
36+
get () {
37+
return this.value
38+
},
39+
set (val) {
40+
this.$emit('input', val)
41+
}
42+
}
43+
},
44+
methods: {
45+
test () {
46+
this.$emit('change', this.model)
47+
}
48+
}
49+
}
50+
</script>

0 commit comments

Comments
 (0)