2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-11-25 13:31:34 +01:00
|
|
|
<script lang="ts">
|
2023-05-14 05:23:39 +02:00
|
|
|
import { VNode, defineComponent, h, ref, watch } from 'vue';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkRadio from './MkRadio.vue';
|
2020-11-25 13:31:34 +01:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
|
|
|
modelValue: {
|
2022-06-28 15:32:01 +02:00
|
|
|
required: false,
|
2020-11-25 13:31:34 +01:00
|
|
|
},
|
|
|
|
},
|
2023-05-14 05:23:39 +02:00
|
|
|
setup(props, context) {
|
|
|
|
const value = ref(props.modelValue);
|
|
|
|
watch(value, () => {
|
|
|
|
context.emit('update:modelValue', value.value);
|
|
|
|
});
|
2024-01-19 12:51:49 +01:00
|
|
|
watch(() => props.modelValue, v => {
|
|
|
|
value.value = v;
|
|
|
|
});
|
2023-05-14 05:23:39 +02:00
|
|
|
if (!context.slots.default) return null;
|
|
|
|
let options = context.slots.default();
|
|
|
|
const label = context.slots.label && context.slots.label();
|
|
|
|
const caption = context.slots.caption && context.slots.caption();
|
2021-07-19 16:30:12 +02:00
|
|
|
|
|
|
|
// なぜかFragmentになることがあるため
|
2023-04-15 14:35:19 +02:00
|
|
|
if (options.length === 1 && options[0].props == null) options = options[0].children as VNode[];
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
return () => h('div', {
|
2022-06-28 15:32:01 +02:00
|
|
|
class: 'novjtcto',
|
2020-11-25 13:31:34 +01:00
|
|
|
}, [
|
2021-11-28 12:07:37 +01:00
|
|
|
...(label ? [h('div', {
|
2022-06-28 15:32:01 +02:00
|
|
|
class: 'label',
|
2023-04-15 14:35:19 +02:00
|
|
|
}, label)] : []),
|
2021-11-28 12:07:37 +01:00
|
|
|
h('div', {
|
2022-06-28 15:32:01 +02:00
|
|
|
class: 'body',
|
2021-11-28 12:07:37 +01:00
|
|
|
}, options.map(option => h(MkRadio, {
|
2024-01-30 11:53:53 +01:00
|
|
|
key: option.key as string,
|
2023-04-15 14:35:19 +02:00
|
|
|
value: option.props?.value,
|
2023-05-14 05:23:39 +02:00
|
|
|
modelValue: value.value,
|
|
|
|
'onUpdate:modelValue': _v => value.value = _v,
|
2023-04-15 14:35:19 +02:00
|
|
|
}, () => option.children)),
|
2021-11-28 12:07:37 +01:00
|
|
|
),
|
|
|
|
...(caption ? [h('div', {
|
2022-06-28 15:32:01 +02:00
|
|
|
class: 'caption',
|
2023-04-15 14:35:19 +02:00
|
|
|
}, caption)] : []),
|
2020-11-25 13:31:34 +01:00
|
|
|
]);
|
2022-06-28 15:32:01 +02:00
|
|
|
},
|
2020-11-25 13:31:34 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-09-29 17:50:45 +02:00
|
|
|
.novjtcto {
|
2021-11-28 12:07:37 +01:00
|
|
|
> .label {
|
|
|
|
font-size: 0.85em;
|
|
|
|
padding: 0 0 8px 0;
|
|
|
|
user-select: none;
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
2022-06-28 15:32:01 +02:00
|
|
|
display: flex;
|
|
|
|
gap: 12px;
|
|
|
|
flex-wrap: wrap;
|
2021-09-29 17:50:45 +02:00
|
|
|
}
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2021-11-28 12:07:37 +01:00
|
|
|
> .caption {
|
|
|
|
font-size: 0.85em;
|
|
|
|
padding: 8px 0 0 0;
|
|
|
|
color: var(--fgTransparentWeak);
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
2020-11-25 13:31:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|