FormCheckbox.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <script setup>
  2. defineOptions({
  3. inheritAttrs: false
  4. })
  5. const props = defineProps({
  6. modelValue: Boolean,
  7. fieldName: {
  8. type: String,
  9. default: '',
  10. required: true
  11. },
  12. label: {
  13. type: String,
  14. default: ''
  15. },
  16. labelClass: {
  17. type: String,
  18. default: ''
  19. },
  20. help: {
  21. type: String,
  22. default: ''
  23. },
  24. isIndented: Boolean,
  25. isDisabled: Boolean,
  26. })
  27. const emit = defineEmits(['update:modelValue'])
  28. const attrs = useAttrs()
  29. const model = computed({
  30. get() {
  31. return props.modelValue;
  32. },
  33. set(value) {
  34. emit("update:modelValue", value);
  35. },
  36. })
  37. function toggleModel() {
  38. if (attrs['disabled'] != true) {
  39. model.value = !model.value
  40. }
  41. }
  42. </script>
  43. <template>
  44. <div class="field is-flex">
  45. <div v-if="isIndented" class="mx-2 pr-1" :style="{ 'opacity': isDisabled ? '0.5' : '1' }">
  46. <FontAwesomeIcon class="has-text-grey" :icon="['fas', 'chevron-right']" transform="rotate-135"/>
  47. </div>
  48. <div>
  49. <input :id="fieldName" type="checkbox" :name="fieldName" class="is-checkradio is-info" v-model="model" :disabled="isDisabled" />
  50. <label tabindex="0" :for="fieldName" class="label" :class="labelClass" v-html="$t(label)" v-on:keypress.space.prevent="toggleModel" />
  51. <p class="help" v-html="$t(help)" v-if="help" />
  52. </div>
  53. </div>
  54. </template>