2020-11-25 13:31:34 +01:00
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent, h } from 'vue';
|
2021-03-23 09:30:14 +01:00
|
|
|
import MkRadio from '@client/components/ui/radio.vue';
|
2020-11-25 13:31:34 +01:00
|
|
|
import './form.scss';
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
MkRadio
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
modelValue: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
value: this.modelValue,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
2021-04-22 15:29:33 +02:00
|
|
|
modelValue() {
|
|
|
|
this.value = this.modelValue;
|
|
|
|
},
|
2020-11-25 13:31:34 +01:00
|
|
|
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;
|
2020-11-25 13:31:34 +01:00
|
|
|
|
|
|
|
return h('div', {
|
|
|
|
class: 'cnklmpwm _formItem'
|
|
|
|
}, [
|
|
|
|
h('div', {
|
|
|
|
class: '_formLabel',
|
|
|
|
}, label),
|
|
|
|
...options.map(option => h('button', {
|
|
|
|
class: '_button _formPanel _formClickable',
|
2021-07-19 16:30:12 +02:00
|
|
|
key: option.key,
|
2020-11-25 13:31:34 +01:00
|
|
|
onClick: () => this.value = option.props.value,
|
|
|
|
}, [h('span', {
|
|
|
|
class: ['check', { checked: this.value === option.props.value }],
|
|
|
|
}), option.children]))
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.cnklmpwm {
|
|
|
|
> button {
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
box-sizing: border-box;
|
|
|
|
padding: 14px 18px;
|
|
|
|
text-align: left;
|
|
|
|
|
|
|
|
&:not(:first-of-type) {
|
|
|
|
border-top: none !important;
|
|
|
|
border-top-left-radius: 0;
|
|
|
|
border-top-right-radius: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:not(:last-of-type) {
|
|
|
|
border-bottom: solid 0.5px var(--divider);
|
|
|
|
border-bottom-left-radius: 0;
|
|
|
|
border-bottom-right-radius: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .check {
|
|
|
|
display: inline-block;
|
|
|
|
vertical-align: bottom;
|
|
|
|
position: relative;
|
2021-04-12 16:13:58 +02:00
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
2020-11-25 13:31:34 +01:00
|
|
|
margin-right: 8px;
|
|
|
|
background: none;
|
|
|
|
border: 2px solid var(--inputBorder);
|
|
|
|
border-radius: 100%;
|
|
|
|
transition: inherit;
|
|
|
|
|
|
|
|
&:after {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
top: 3px;
|
|
|
|
right: 3px;
|
|
|
|
bottom: 3px;
|
|
|
|
left: 3px;
|
|
|
|
border-radius: 100%;
|
|
|
|
opacity: 0;
|
|
|
|
transform: scale(0);
|
|
|
|
transition: .4s cubic-bezier(.25,.8,.25,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.checked {
|
|
|
|
border-color: var(--accent);
|
|
|
|
|
|
|
|
&:after {
|
|
|
|
background-color: var(--accent);
|
|
|
|
transform: scale(1);
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|