Sharkey/packages/frontend/src/components/MkRadios.vue

81 lines
1.6 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<script lang="ts">
import { VNode, defineComponent, h, ref, watch } from 'vue';
2023-01-07 08:09:46 +02:00
import MkRadio from './MkRadio.vue';
export default defineComponent({
props: {
modelValue: {
2022-06-28 16:32:01 +03:00
required: false,
},
},
setup(props, context) {
const value = ref(props.modelValue);
watch(value, () => {
context.emit('update:modelValue', value.value);
});
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 17:30:12 +03:00
// なぜかFragmentになることがあるため
if (options.length === 1 && options[0].props == null) options = options[0].children as VNode[];
return () => h('div', {
2022-06-28 16:32:01 +03:00
class: 'novjtcto',
}, [
2021-11-28 13:07:37 +02:00
...(label ? [h('div', {
2022-06-28 16:32:01 +03:00
class: 'label',
}, label)] : []),
2021-11-28 13:07:37 +02:00
h('div', {
2022-06-28 16:32:01 +03:00
class: 'body',
2021-11-28 13:07:37 +02:00
}, options.map(option => h(MkRadio, {
2022-06-28 16:32:01 +03:00
key: option.key,
value: option.props?.value,
modelValue: value.value,
'onUpdate:modelValue': _v => value.value = _v,
}, () => option.children)),
2021-11-28 13:07:37 +02:00
),
...(caption ? [h('div', {
2022-06-28 16:32:01 +03:00
class: 'caption',
}, caption)] : []),
]);
2022-06-28 16:32:01 +03:00
},
});
</script>
<style lang="scss">
2021-09-29 18:50:45 +03:00
.novjtcto {
2021-11-28 13:07:37 +02:00
> .label {
font-size: 0.85em;
padding: 0 0 8px 0;
user-select: none;
&:empty {
display: none;
}
}
> .body {
2022-06-28 16:32:01 +03:00
display: flex;
gap: 12px;
flex-wrap: wrap;
2021-09-29 18:50:45 +03:00
}
2021-11-28 13:07:37 +02:00
> .caption {
font-size: 0.85em;
padding: 8px 0 0 0;
color: var(--fgTransparentWeak);
&:empty {
display: none;
}
}
}
</style>