Refactor #3965 - For InputSwitch
parent
51f2913c48
commit
5b6fd8ac8e
|
@ -0,0 +1,104 @@
|
||||||
|
<script>
|
||||||
|
import BaseComponent from 'primevue/basecomponent';
|
||||||
|
import { useStyle } from 'primevue/usestyle';
|
||||||
|
|
||||||
|
const styles = `
|
||||||
|
.p-inputswitch {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-inputswitch-slider {
|
||||||
|
position: absolute;
|
||||||
|
cursor: pointer;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-inputswitch-slider:before {
|
||||||
|
position: absolute;
|
||||||
|
content: '';
|
||||||
|
top: 50%;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const inlineStyles = {
|
||||||
|
root: { position: 'relative' }
|
||||||
|
};
|
||||||
|
|
||||||
|
const classes = {
|
||||||
|
root: ({ instance, props }) => [
|
||||||
|
'p-inputswitch p-component',
|
||||||
|
{
|
||||||
|
'p-inputswitch-checked': instance.checked,
|
||||||
|
'p-disabled': props.disabled,
|
||||||
|
'p-focus': instance.focused
|
||||||
|
}
|
||||||
|
],
|
||||||
|
hiddenInputWrapper: 'p-hidden-accessible',
|
||||||
|
slider: 'p-inputswitch-slider'
|
||||||
|
};
|
||||||
|
|
||||||
|
const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_inputswitch_style', manual: true });
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'BaseInputSwitch',
|
||||||
|
extends: BaseComponent,
|
||||||
|
props: {
|
||||||
|
modelValue: {
|
||||||
|
type: null,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
trueValue: {
|
||||||
|
type: null,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
falseValue: {
|
||||||
|
type: null,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
inputId: {
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
inputClass: {
|
||||||
|
type: [String, Object],
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
inputStyle: {
|
||||||
|
type: Object,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
inputProps: {
|
||||||
|
type: null,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
'aria-labelledby': {
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
'aria-label': {
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
css: {
|
||||||
|
classes,
|
||||||
|
inlineStyles
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
isUnstyled: {
|
||||||
|
immediate: true,
|
||||||
|
handler(newValue) {
|
||||||
|
!newValue && loadStyle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -104,6 +104,16 @@ export interface InputSwitchProps {
|
||||||
* Establishes a string value that labels the component.
|
* Establishes a string value that labels the component.
|
||||||
*/
|
*/
|
||||||
'aria-label'?: string | undefined;
|
'aria-label'?: string | undefined;
|
||||||
|
/**
|
||||||
|
* Uses to pass attributes to DOM elements inside the component.
|
||||||
|
* @type {InputSwitchPassThroughMethodOptions}
|
||||||
|
*/
|
||||||
|
pt?: InputSwitchPassThroughMethodOptions;
|
||||||
|
/**
|
||||||
|
* When enabled, it removes component related styles in the core.
|
||||||
|
* @defaultValue false
|
||||||
|
*/
|
||||||
|
unstyled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InputSwitchSlots {}
|
export interface InputSwitchSlots {}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="containerClass" @click="onClick($event)" v-bind="ptm('root')">
|
<div :class="cx('root')" :style="sx('root')" @click="onClick($event)" v-bind="ptm('root')">
|
||||||
<div class="p-hidden-accessible" v-bind="ptm('hiddenInputWrapper')">
|
<div :class="cx('hiddenInputWrapper')" :style="sx('hiddenAccessible', isUnstyled)" v-bind="ptm('hiddenInputWrapper')" :data-p-hidden-accessible="true">
|
||||||
<input
|
<input
|
||||||
ref="input"
|
ref="input"
|
||||||
:id="inputId"
|
:id="inputId"
|
||||||
|
@ -18,59 +18,17 @@
|
||||||
v-bind="ptm('hiddenInput')"
|
v-bind="ptm('hiddenInput')"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span class="p-inputswitch-slider" v-bind="{ ...inputProps, ...ptm('slider') }"></span>
|
<span :class="cx('slider')" v-bind="{ ...inputProps, ...ptm('slider') }"></span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import BaseComponent from 'primevue/basecomponent';
|
import BaseInputSwitch from './BaseInputSwitch.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'InputSwitch',
|
name: 'InputSwitch',
|
||||||
extends: BaseComponent,
|
extends: BaseInputSwitch,
|
||||||
emits: ['click', 'update:modelValue', 'change', 'input', 'focus', 'blur'],
|
emits: ['click', 'update:modelValue', 'change', 'input', 'focus', 'blur'],
|
||||||
props: {
|
|
||||||
modelValue: {
|
|
||||||
type: null,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
trueValue: {
|
|
||||||
type: null,
|
|
||||||
default: true
|
|
||||||
},
|
|
||||||
falseValue: {
|
|
||||||
type: null,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
disabled: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
inputId: {
|
|
||||||
type: String,
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
inputClass: {
|
|
||||||
type: [String, Object],
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
inputStyle: {
|
|
||||||
type: Object,
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
inputProps: {
|
|
||||||
type: null,
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
'aria-labelledby': {
|
|
||||||
type: String,
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
'aria-label': {
|
|
||||||
type: String,
|
|
||||||
default: null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
focused: false
|
focused: false
|
||||||
|
@ -100,42 +58,9 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
containerClass() {
|
|
||||||
return [
|
|
||||||
'p-inputswitch p-component',
|
|
||||||
{
|
|
||||||
'p-inputswitch-checked': this.checked,
|
|
||||||
'p-disabled': this.disabled,
|
|
||||||
'p-focus': this.focused
|
|
||||||
}
|
|
||||||
];
|
|
||||||
},
|
|
||||||
checked() {
|
checked() {
|
||||||
return this.modelValue === this.trueValue;
|
return this.modelValue === this.trueValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
|
||||||
.p-inputswitch {
|
|
||||||
position: relative;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-inputswitch-slider {
|
|
||||||
position: absolute;
|
|
||||||
cursor: pointer;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.p-inputswitch-slider:before {
|
|
||||||
position: absolute;
|
|
||||||
content: '';
|
|
||||||
top: 50%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
Loading…
Reference in New Issue