Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Convert Toogle component to Composition API #145

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions lib/components/base/Toggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@
:id="id"
type="checkbox"
class="switch stylized-toggle"
:disabled="disabled"
:checked="checked"
@change="toggle"
/>
</template>

<script>
export default {
props: {
id: {
type: String,
required: true,
},
modelValue: {
type: Boolean,
},
checked: {
type: Boolean,
required: true,
},
},
emits: ['update:modelValue'],
methods: {
toggle() {
if (!this.disabled) {
this.$emit('update:modelValue', !this.modelValue)
}
},
},
<script setup lang="ts">
const emit = defineEmits<{
'update:modelValue': [boolean]
}>()

const props = withDefaults(
defineProps<{
id: string
modelValue: boolean
checked: boolean
disabled?: boolean
}>(),
{
disabled: false,
}
)

function toggle() {
if (!props.disabled) {
emit('update:modelValue', !props.modelValue)
}
}
</script>