aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/StudipRadioButton.vue
blob: 2fbdbe8cc0199e5f26dcf4351a8b7c557204820b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<script setup lang="ts">
import {computed} from "vue";

const props = defineProps({
    modelValue: {
        type: [String, Number, Boolean],
        required: true,
    },
    name: {
        type: String,
        required: true,
    },
    value: {
        type: [String, Number, Boolean],
        required: true
    }
});

const emit = defineEmits(['update:modelValue']);

const model = computed({
    get() {
        return props.modelValue;
    },
    set(newValue) {
        emit('update:modelValue', newValue);
    }
})


const shape = computed(() => {
    return model.value === props.value ? 'radiobutton-checked' : 'radiobutton-unchecked';
})
</script>

<template>
    <label class="as-link studip-radiobutton">
        <input type="radio"
               v-model="model"
               :value="value"
               :name="name"
               class="sr-only"
        >

        <StudipIcon :shape="shape" aria-hidden="true"></StudipIcon>

        <slot>
            No content provided for slot
        </slot>
    </label>
</template>

<style lang="scss">
.studip-radiobutton {
    display: block;

    .studip-icon {
        vertical-align: text-bottom;
    }
}
</style>