mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-10 09:22:34 +00:00
Refactor #5612 - InputSwitch / ToggleSwitch
This commit is contained in:
parent
1428cc12df
commit
f240b953b4
16 changed files with 384 additions and 263 deletions
|
@ -1,66 +1,11 @@
|
|||
<template>
|
||||
<div :class="cx('root')" :style="sx('root')" v-bind="getPTOptions('root')" :data-p-highlight="checked" :data-p-disabled="disabled">
|
||||
<input
|
||||
:id="inputId"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
:class="[cx('input'), inputClass]"
|
||||
:style="inputStyle"
|
||||
:checked="checked"
|
||||
:tabindex="tabindex"
|
||||
:disabled="disabled"
|
||||
:readonly="readonly"
|
||||
:aria-checked="checked"
|
||||
:aria-labelledby="ariaLabelledby"
|
||||
:aria-label="ariaLabel"
|
||||
:aria-invalid="invalid || undefined"
|
||||
@focus="onFocus"
|
||||
@blur="onBlur"
|
||||
@change="onChange"
|
||||
v-bind="getPTOptions('input')"
|
||||
/>
|
||||
<span :class="cx('slider')" v-bind="getPTOptions('slider')"></span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BaseInputSwitch from './BaseInputSwitch.vue';
|
||||
import ToggleSwitch from 'primevue/toggleswitch';
|
||||
|
||||
export default {
|
||||
name: 'InputSwitch',
|
||||
extends: BaseInputSwitch,
|
||||
inheritAttrs: false,
|
||||
emits: ['update:modelValue', 'change', 'focus', 'blur'],
|
||||
methods: {
|
||||
getPTOptions(key) {
|
||||
const _ptm = key === 'root' ? this.ptmi : this.ptm;
|
||||
|
||||
return _ptm(key, {
|
||||
context: {
|
||||
checked: this.checked,
|
||||
disabled: this.disabled
|
||||
}
|
||||
});
|
||||
},
|
||||
onChange(event) {
|
||||
if (!this.disabled && !this.readonly) {
|
||||
const newValue = this.checked ? this.falseValue : this.trueValue;
|
||||
|
||||
this.$emit('update:modelValue', newValue);
|
||||
this.$emit('change', event);
|
||||
}
|
||||
},
|
||||
onFocus(event) {
|
||||
this.$emit('focus', event);
|
||||
},
|
||||
onBlur(event) {
|
||||
this.$emit('blur', event);
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
checked() {
|
||||
return this.modelValue === this.trueValue;
|
||||
}
|
||||
extends: ToggleSwitch,
|
||||
mounted() {
|
||||
console.warn('Deprecated since v4. Use ToggleSwitch component instead.');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue