|
| 1 | +<template> |
| 2 | + <div class="input-group"> |
| 3 | + <div class="checkbox-line"> |
| 4 | + <label v-if="props.label" :for="props.name">{{ props.label }} <slot></slot></label> |
| 5 | + <input class="checkbox checkbox-checkmark-onoff" type="checkbox" :value="props.value" :name="props.name" v-model="props.modelValue" @change="emits('update:modelValue', props.modelValue)" /> |
| 6 | + <div :class="{ 'checkmark-onoff': true, 'checkmark-onoff-checked': checked }"> |
| 7 | + <div class="dot"></div> |
| 8 | + </div> |
| 9 | + </div> |
| 10 | + </div> |
| 11 | +</template> |
| 12 | + |
| 13 | +<script setup> |
| 14 | +import { computed } from 'vue' |
| 15 | +
|
| 16 | +const emits = defineEmits(['update:modelValue', 'change']) |
| 17 | +const props = defineProps({ |
| 18 | + name: { type: String }, |
| 19 | + modelValue: { type: [Array, Boolean] }, |
| 20 | + value: { type: String, required: true }, |
| 21 | + label: { type: String, required: true }, |
| 22 | +}) |
| 23 | +
|
| 24 | +const checked = computed(() => { |
| 25 | + if (props.modelValue instanceof Array) { |
| 26 | + return props.modelValue.includes(props.value) |
| 27 | + } |
| 28 | + return props.modelValue |
| 29 | +}) |
| 30 | +</script> |
| 31 | + |
| 32 | +<style> |
| 33 | +@import './css/input-root.css'; |
| 34 | +</style> |
| 35 | + |
| 36 | +<style scoped> |
| 37 | +@import './css/input.css'; |
| 38 | +</style> |
| 39 | + |
| 40 | +<!-- |
| 41 | +
|
| 42 | + // Multiple Array with strings values |
| 43 | + let money = ref(['card','cash']) // Default selected in array |
| 44 | +
|
| 45 | + <Checkbox label="Cash" value="cash" v-model="money" name="pay_cash" /> |
| 46 | + <Checkbox label="Card" value="card" v-model="money" name="pay_card" /> |
| 47 | +
|
| 48 | + // Single (true|false) |
| 49 | + let remember_me = ref(true) |
| 50 | +
|
| 51 | + <Checkbox label="Remember me 1" value="1" v-model="remember_me" name="remember_me" /> |
| 52 | +
|
| 53 | +--> |
0 commit comments