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

118 lines
1.8 KiB
Vue
Raw Normal View History

<script lang="ts">
2023-04-08 02:01:42 +02:00
import { defineComponent, h } from "vue";
import MkRadio from "./radio.vue";
export default defineComponent({
components: {
2022-06-28 15:32:01 +02:00
MkRadio,
},
props: {
modelValue: {
2022-06-28 15:32:01 +02:00
required: false,
},
},
data() {
return {
value: this.modelValue,
};
},
watch: {
value() {
2023-04-08 02:01:42 +02:00
this.$emit("update:modelValue", this.value);
2022-06-28 15:32:01 +02:00
},
},
render() {
2021-07-19 16:30:12 +02:00
let options = this.$slots.default();
2021-11-28 12:07:37 +01:00
const label = this.$slots.label && this.$slots.label();
const caption = this.$slots.caption && this.$slots.caption();
2021-07-19 16:30:12 +02:00
// なぜかFragmentになることがあるため
2023-04-08 02:01:42 +02:00
if (options.length === 1 && options[0].props == null)
options = options[0].children;
2023-04-08 02:01:42 +02:00
return h(
2023-05-15 22:19:33 +02:00
"fieldset",
2023-04-08 02:01:42 +02:00
{
class: "novjtcto",
},
[
...(label
? [
h(
2023-05-15 22:19:33 +02:00
"legend",
2023-04-08 02:01:42 +02:00
{
class: "label",
},
[label]
),
]
: []),
h(
"div",
{
class: "body",
},
options.map((option) =>
h(
MkRadio,
{
key: option.key,
value: option.props?.value,
disabled: option.props?.disabled,
2023-04-08 02:01:42 +02:00
modelValue: this.value,
"onUpdate:modelValue": (value) =>
(this.value = value),
},
option.children
)
)
),
...(caption
? [
h(
"div",
{
class: "caption",
},
[caption]
),
]
: []),
]
);
2022-06-28 15:32:01 +02:00
},
});
</script>
<style lang="scss">
2021-09-29 17:50:45 +02:00
.novjtcto {
2023-05-15 22:19:33 +02:00
border: 0;
padding: 0;
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;
2023-04-08 02:01:42 +02:00
gap: 12px;
flex-wrap: wrap;
2021-09-29 17:50:45 +02: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;
}
}
}
</style>