mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* style: use prettier * style: just prettier format, no code changes * style: eslint fix object-shorthand, prefer-const * style: fix no-void * style: no-console
85 lines
2.0 KiB
Vue
85 lines
2.0 KiB
Vue
<template>
|
|
<label
|
|
class="el-checkbox-button"
|
|
:class="[
|
|
size ? 'el-checkbox-button--' + size : '',
|
|
{ 'is-disabled': isDisabled },
|
|
{ 'is-checked': isChecked },
|
|
{ 'is-focus': focus },
|
|
]"
|
|
role="checkbox"
|
|
:aria-checked="isChecked"
|
|
:aria-disabled="isDisabled"
|
|
>
|
|
<input
|
|
v-if="trueLabel || falseLabel"
|
|
v-model="model"
|
|
class="el-checkbox-button__original"
|
|
type="checkbox"
|
|
:name="name"
|
|
:disabled="isDisabled"
|
|
:true-value="trueLabel"
|
|
:false-value="falseLabel"
|
|
@change="handleChange"
|
|
@focus="focus = true"
|
|
@blur="focus = false"
|
|
/>
|
|
<input
|
|
v-else
|
|
v-model="model"
|
|
class="el-checkbox-button__original"
|
|
type="checkbox"
|
|
:name="name"
|
|
:disabled="isDisabled"
|
|
:value="label"
|
|
@change="handleChange"
|
|
@focus="focus = true"
|
|
@blur="focus = false"
|
|
/>
|
|
|
|
<span
|
|
v-if="$slots.default || label"
|
|
class="el-checkbox-button__inner"
|
|
:style="isChecked ? activeStyle : null"
|
|
>
|
|
<slot>{{ label }}</slot>
|
|
</span>
|
|
</label>
|
|
</template>
|
|
<script lang="ts">
|
|
import { defineComponent, computed } from 'vue'
|
|
import { UPDATE_MODEL_EVENT } from '@element-plus/utils/constants'
|
|
import { useCheckbox, useCheckboxGroup, useCheckboxProps } from './useCheckbox'
|
|
|
|
export default defineComponent({
|
|
name: 'ElCheckboxButton',
|
|
props: useCheckboxProps,
|
|
emits: [UPDATE_MODEL_EVENT, 'change'],
|
|
setup(props) {
|
|
const { focus, isChecked, isDisabled, size, model, handleChange } =
|
|
useCheckbox(props)
|
|
const { checkboxGroup } = useCheckboxGroup()
|
|
|
|
const activeStyle = computed(() => {
|
|
const fillValue = checkboxGroup?.fill?.value ?? ''
|
|
return {
|
|
backgroundColor: fillValue,
|
|
borderColor: fillValue,
|
|
color: checkboxGroup?.textColor?.value ?? '',
|
|
boxShadow: fillValue ? `-1px 0 0 0 ${fillValue}` : null,
|
|
}
|
|
})
|
|
|
|
return {
|
|
focus,
|
|
isChecked,
|
|
isDisabled,
|
|
model,
|
|
handleChange,
|
|
activeStyle,
|
|
size,
|
|
}
|
|
},
|
|
})
|
|
</script>
|