iceshrimp-legacy/src/client/components/form/radios.vue

67 lines
1.1 KiB
Vue
Raw Normal View History

<script lang="ts">
import { defineComponent, h } from 'vue';
2021-09-29 17:50:45 +02:00
import MkRadio from './radio.vue';
export default defineComponent({
components: {
MkRadio
},
props: {
modelValue: {
required: false
},
},
data() {
return {
value: this.modelValue,
}
},
watch: {
value() {
this.$emit('update:modelValue', this.value);
}
},
render() {
const label = this.$slots.desc();
2021-07-19 16:30:12 +02:00
let options = this.$slots.default();
// なぜかFragmentになることがあるため
if (options.length === 1 && options[0].props == null) options = options[0].children;
return h('div', {
2021-09-29 17:50:45 +02:00
class: 'novjtcto'
}, [
2021-09-29 17:50:45 +02:00
h('div', { class: 'label' }, label),
...options.map(option => h(MkRadio, {
2021-07-19 16:30:12 +02:00
key: option.key,
2021-09-29 17:50:45 +02:00
value: option.props.value,
modelValue: this.value,
'onUpdate:modelValue': value => this.value = value,
}, option.children))
]);
}
});
</script>
<style lang="scss">
2021-09-29 17:50:45 +02:00
.novjtcto {
> .label {
font-size: 0.85em;
padding: 0 0 8px 12px;
user-select: none;
2021-09-29 17:50:45 +02:00
&:empty {
display: none;
}
2021-09-29 17:50:45 +02:00
}
2021-09-29 17:50:45 +02:00
&:first-child {
margin-top: 0;
}
2021-09-29 17:50:45 +02:00
&:last-child {
margin-bottom: 0;
}
}
</style>