2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-05-29 09:19:55 +00:00
|
|
|
<div :class="cx('root')" :style="sx('root')" @click="onClick($event)" v-bind="ptm('root')" data-pc-name="inputswitch">
|
2023-05-24 11:15:28 +00:00
|
|
|
<div :class="cx('hiddenInputWrapper')" :style="sx('hiddenAccessible', isUnstyled)" v-bind="ptm('hiddenInputWrapper')" :data-p-hidden-accessible="true">
|
2022-09-14 11:26:01 +00:00
|
|
|
<input
|
|
|
|
ref="input"
|
|
|
|
:id="inputId"
|
|
|
|
type="checkbox"
|
|
|
|
role="switch"
|
|
|
|
:class="inputClass"
|
|
|
|
:style="inputStyle"
|
|
|
|
:checked="checked"
|
|
|
|
:disabled="disabled"
|
|
|
|
:aria-checked="checked"
|
|
|
|
:aria-labelledby="ariaLabelledby"
|
|
|
|
:aria-label="ariaLabel"
|
|
|
|
@focus="onFocus($event)"
|
|
|
|
@blur="onBlur($event)"
|
2023-06-05 10:23:17 +00:00
|
|
|
v-bind="{ ...inputProps, ...ptm('hiddenInput') }"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2023-06-05 10:23:17 +00:00
|
|
|
<span :class="cx('slider')" v-bind="ptm('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,
|
2022-09-06 12:03:37 +00:00
|
|
|
emits: ['click', 'update:modelValue', 'change', 'input', 'focus', 'blur'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
focused: false
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onClick(event) {
|
|
|
|
if (!this.disabled) {
|
|
|
|
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('click', event);
|
|
|
|
this.$emit('update:modelValue', newValue);
|
|
|
|
this.$emit('change', event);
|
|
|
|
this.$emit('input', newValue);
|
|
|
|
this.$refs.input.focus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onFocus(event) {
|
|
|
|
this.focused = true;
|
|
|
|
this.$emit('focus', event);
|
|
|
|
},
|
|
|
|
onBlur(event) {
|
|
|
|
this.focused = false;
|
|
|
|
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>
|