summaryrefslogtreecommitdiff
path: root/packages/client/src/components/page/page.radio-button.vue
blob: 5a726da22988c69692438ceae487deffae3e74f4 (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
<template>
<div>
	<div>{{ hpml.interpolate(block.title) }}</div>
	<MkRadio v-for="item in block.values" :key="item" :modelValue="value" :value="item" @update:modelValue="updateValue($event)">{{ item }}</MkRadio>
</div>
</template>

<script lang="ts">
import { computed, defineComponent, PropType } from 'vue';
import MkRadio from '../form/radio.vue';
import * as os from '@/os';
import { Hpml } from '@/scripts/hpml/evaluator';
import { RadioButtonVarBlock } from '@/scripts/hpml/block';

export default defineComponent({
	components: {
		MkRadio
	},
	props: {
		block: {
			type: Object as PropType<RadioButtonVarBlock>,
			required: true
		},
		hpml: {
			type: Object as PropType<Hpml>,
			required: true
		}
	},
	setup(props, ctx) {
		const value = computed(() => {
			return props.hpml.vars.value[props.block.name];
		});

		function updateValue(newValue: string) {
			props.hpml.updatePageVar(props.block.name, newValue);
			props.hpml.eval();
		}

		return {
			value,
			updateValue
		};
	}
});
</script>