2020-11-25 12:31:34 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent, h } from 'vue';
|
2021-09-29 15:50:45 +00:00
|
|
|
import MkRadio from './radio.vue';
|
2020-11-25 12:31:34 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
MkRadio
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
modelValue: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
value: this.modelValue,
|
2022-06-10 05:36:55 +00:00
|
|
|
};
|
2020-11-25 12:31:34 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
value() {
|
|
|
|
this.$emit('update:modelValue', this.value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render() {
|
2021-07-19 14:30:12 +00:00
|
|
|
let options = this.$slots.default();
|
2021-11-28 11:07:37 +00:00
|
|
|
const label = this.$slots.label && this.$slots.label();
|
|
|
|
const caption = this.$slots.caption && this.$slots.caption();
|
2021-07-19 14:30:12 +00:00
|
|
|
|
|
|
|
// なぜかFragmentになることがあるため
|
|
|
|
if (options.length === 1 && options[0].props == null) options = options[0].children;
|
2020-11-25 12:31:34 +00:00
|
|
|
|
|
|
|
return h('div', {
|
2021-09-29 15:50:45 +00:00
|
|
|
class: 'novjtcto'
|
2020-11-25 12:31:34 +00:00
|
|
|
}, [
|
2021-11-28 11:07:37 +00:00
|
|
|
...(label ? [h('div', {
|
|
|
|
class: 'label'
|
|
|
|
}, [label])] : []),
|
|
|
|
h('div', {
|
|
|
|
class: 'body'
|
|
|
|
}, options.map(option => h(MkRadio, {
|
|
|
|
key: option.key,
|
|
|
|
value: option.props.value,
|
|
|
|
modelValue: this.value,
|
|
|
|
'onUpdate:modelValue': value => this.value = value,
|
|
|
|
}, option.children)),
|
|
|
|
),
|
|
|
|
...(caption ? [h('div', {
|
|
|
|
class: 'caption'
|
|
|
|
}, [caption])] : []),
|
2020-11-25 12:31:34 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-09-29 15:50:45 +00:00
|
|
|
.novjtcto {
|
2021-11-28 11:07:37 +00:00
|
|
|
> .label {
|
|
|
|
font-size: 0.85em;
|
|
|
|
padding: 0 0 8px 0;
|
|
|
|
user-select: none;
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
|
|
|
grid-gap: 12px;
|
2021-09-29 15:50:45 +00:00
|
|
|
}
|
2020-11-25 12:31:34 +00:00
|
|
|
|
2021-11-28 11:07:37 +00:00
|
|
|
> .caption {
|
|
|
|
font-size: 0.85em;
|
|
|
|
padding: 8px 0 0 0;
|
|
|
|
color: var(--fgTransparentWeak);
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
2020-11-25 12:31:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|