2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-01-30 14:35:32 +00:00
|
|
|
<div :class="cx('root')" :style="sx('root')" v-bind="getPTOptions('root')" :data-p-highlight="checked" :data-p-disabled="disabled">
|
2024-01-12 07:07:55 +00:00
|
|
|
<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"
|
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
|
|
|
@change="onChange"
|
|
|
|
v-bind="getPTOptions('input')"
|
|
|
|
/>
|
|
|
|
<span :class="cx('slider')" v-bind="getPTOptions('slider')"></span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-24 11:15:28 +00:00
|
|
|
import BaseInputSwitch from './BaseInputSwitch.vue';
|
2023-05-05 13:10:07 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
export default {
|
|
|
|
name: 'InputSwitch',
|
2023-05-24 11:15:28 +00:00
|
|
|
extends: BaseInputSwitch,
|
2024-02-11 08:10:29 +00:00
|
|
|
inheritAttrs: false,
|
2024-01-12 07:07:55 +00:00
|
|
|
emits: ['update:modelValue', 'change', 'focus', 'blur'],
|
2022-09-06 12:03:37 +00:00
|
|
|
methods: {
|
2024-01-12 07:07:55 +00:00
|
|
|
getPTOptions(key) {
|
2024-02-11 08:10:29 +00:00
|
|
|
const _ptm = root === 'root' ? this.ptmi : this.ptm;
|
|
|
|
|
|
|
|
return _ptm(key, {
|
2024-01-12 07:07:55 +00:00
|
|
|
context: {
|
|
|
|
checked: this.checked,
|
|
|
|
disabled: this.disabled
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onChange(event) {
|
|
|
|
if (!this.disabled && !this.readonly) {
|
2022-09-06 12:03:37 +00:00
|
|
|
const newValue = this.checked ? this.falseValue : this.trueValue;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|