|
| 1 | +<template> |
| 2 | + <div class="m-form-group"> |
| 3 | + <fieldset class="m-checkbox-group"> |
| 4 | + <legend class="m-checkbox-group__legend"> |
| 5 | + <h3 class="m-checkbox-group__heading"> |
| 6 | + {{ heading }} |
| 7 | + </h3> |
| 8 | + </legend> |
| 9 | + <div class="m-checkboxes m-checkboxes--collapse"> |
| 10 | + <slot name="checkboxes" /> |
| 11 | + <div |
| 12 | + v-if="$slots.collapsableCheckboxes" |
| 13 | + class="m-checkboxes__collapse__container" |
| 14 | + :class="isCollapsed" |
| 15 | + > |
| 16 | + <slot name="collapsableCheckboxes" /> |
| 17 | + </div> |
| 18 | + <muc-button |
| 19 | + v-if="$slots.collapsableCheckboxes" |
| 20 | + variant="ghost" |
| 21 | + @click="toggleCollapse" |
| 22 | + :aria-expanded="!collapsed" |
| 23 | + > |
| 24 | + <span>Mehr </span> |
| 25 | + <svg |
| 26 | + aria-hidden="true" |
| 27 | + class="icon icon--after" |
| 28 | + > |
| 29 | + <use :href="'#icon-chevron-' + buttonIcon"></use> |
| 30 | + </svg> |
| 31 | + </muc-button> |
| 32 | + </div> |
| 33 | + </fieldset> |
| 34 | + </div> |
| 35 | +</template> |
| 36 | + |
| 37 | +<script setup lang="ts"> |
| 38 | +import { computed, ref } from "vue"; |
| 39 | +
|
| 40 | +import { MucButton } from "../Button"; |
| 41 | +
|
| 42 | +/** |
| 43 | + * Internal state for the collapsed section |
| 44 | + */ |
| 45 | +const collapsed = ref(true); |
| 46 | +
|
| 47 | +defineProps<{ |
| 48 | + /** |
| 49 | + * Display a heading above the slots. |
| 50 | + */ |
| 51 | + heading?: string; |
| 52 | +}>(); |
| 53 | +
|
| 54 | +defineSlots<{ |
| 55 | + /** |
| 56 | + * Slot directly beneath the heading which will be displayed at all times. |
| 57 | + */ |
| 58 | + checkboxes(): any; |
| 59 | +
|
| 60 | + /** |
| 61 | + * Slot beneath the regular checkbox slot which will be collapsed at first. |
| 62 | + */ |
| 63 | + collapsableCheckboxes(): any; |
| 64 | +}>(); |
| 65 | +
|
| 66 | +/** |
| 67 | + * Switches the collapse class for the collapsable container. |
| 68 | + */ |
| 69 | +const isCollapsed = computed(() => (collapsed.value ? "collapse" : "")); |
| 70 | +
|
| 71 | +/** |
| 72 | + * Switches the icon in the button to collapse / expand the container. |
| 73 | + */ |
| 74 | +const buttonIcon = computed(() => (collapsed.value ? "down" : "up")); |
| 75 | +
|
| 76 | +/** |
| 77 | + * Toggles the internal state for the collapsed container. |
| 78 | + */ |
| 79 | +const toggleCollapse = () => (collapsed.value = !collapsed.value); |
| 80 | +</script> |
0 commit comments