-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor #5612 - InputSwitch / ToggleSwitch
- Loading branch information
1 parent
1428cc1
commit f240b95
Showing
16 changed files
with
384 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { BaseStyle } from '../../base/style'; | ||
import { ToggleSwitchStyle } from '../../toggleswitch/style/ToggleSwitchStyle'; | ||
|
||
export interface InputSwitchStyle extends BaseStyle {} | ||
export interface InputSwitchStyle extends ToggleSwitchStyle {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,5 @@ | ||
import BaseStyle from 'primevue/base/style'; | ||
|
||
const inlineStyles = { | ||
root: { position: 'relative' } | ||
}; | ||
|
||
const classes = { | ||
root: ({ instance, props }) => [ | ||
'p-toggleswitch p-component', | ||
{ | ||
'p-toggleswitch-checked': instance.checked, | ||
'p-disabled': props.disabled, | ||
'p-invalid': props.invalid | ||
} | ||
], | ||
input: 'p-toggleswitch-input', | ||
slider: 'p-toggleswitch-slider' | ||
}; | ||
|
||
export default BaseStyle.extend({ | ||
name: 'inputswitch', | ||
classes, | ||
inlineStyles | ||
name: 'inputswitch' | ||
}); |
Oops, something went wrong.