/
radio-button.vue
60 lines (55 loc) 路 1.44 KB
/
radio-button.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<template>
<label
:class="[
ns.b('button'),
ns.is('active', modelValue === actualValue),
ns.is('disabled', disabled),
ns.is('focus', focus),
ns.bm('button', size),
]"
>
<input
ref="radioRef"
v-model="modelValue"
:class="ns.be('button', 'original-radio')"
:value="actualValue"
type="radio"
:name="name || radioGroup?.name"
:disabled="disabled"
@focus="focus = true"
@blur="focus = false"
@click.stop
/>
<span
:class="ns.be('button', 'inner')"
:style="modelValue === actualValue ? activeStyle : {}"
@keydown.stop
>
<slot>
{{ label }}
</slot>
</span>
</label>
</template>
<script lang="ts" setup>
import { computed } from 'vue'
import { useNamespace } from '@element-plus/hooks'
import { useRadio } from './use-radio'
import { radioButtonProps } from './radio-button'
import type { CSSProperties } from 'vue'
defineOptions({
name: 'ElRadioButton',
})
const props = defineProps(radioButtonProps)
const ns = useNamespace('radio')
const { radioRef, focus, size, disabled, modelValue, radioGroup, actualValue } =
useRadio(props)
const activeStyle = computed<CSSProperties>(() => {
return {
backgroundColor: radioGroup?.fill || '',
borderColor: radioGroup?.fill || '',
boxShadow: radioGroup?.fill ? `-1px 0 0 0 ${radioGroup.fill}` : '',
color: radioGroup?.textColor || '',
}
})
</script>