2024-08-23 15:28:21 +02:00
|
|
|
<template>
|
|
|
|
|
<input-wrapper v-bind="inputWrapperProps">
|
|
|
|
|
<template #label>
|
|
|
|
|
<slot name="label" />
|
|
|
|
|
</template>
|
|
|
|
|
<div
|
2024-09-04 11:51:38 +02:00
|
|
|
class="border border-gray-300 overflow-x-auto"
|
2024-08-23 15:28:21 +02:00
|
|
|
:class="[
|
|
|
|
|
theme.default.borderRadius,
|
|
|
|
|
{
|
|
|
|
|
'!ring-red-500 !ring-2 !border-transparent': hasError,
|
|
|
|
|
},
|
|
|
|
|
]"
|
|
|
|
|
>
|
2024-09-04 11:51:38 +02:00
|
|
|
<table class="w-full table-auto">
|
2024-08-23 15:28:21 +02:00
|
|
|
<thead class="">
|
|
|
|
|
<tr>
|
2024-09-04 11:51:38 +02:00
|
|
|
<th class="text-left p-2 w-auto max-w-xs" />
|
2024-08-23 15:28:21 +02:00
|
|
|
<td
|
|
|
|
|
v-for="column in columns"
|
|
|
|
|
:key="column"
|
2024-09-04 11:51:38 +02:00
|
|
|
class="border-l border-gray-300 max-w-24 overflow-hidden"
|
2024-08-23 15:28:21 +02:00
|
|
|
>
|
2024-09-04 11:51:38 +02:00
|
|
|
<div class="p-2 w-full flex items-center justify-center text-sm">
|
2024-08-23 15:28:21 +02:00
|
|
|
{{ column }}
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr
|
|
|
|
|
v-for="row, rowIndex in rows"
|
|
|
|
|
:key="rowIndex"
|
|
|
|
|
class="border-t border-gray-300"
|
|
|
|
|
>
|
2024-09-04 11:51:38 +02:00
|
|
|
<td class="text-left w-auto max-w-24 overflow-hidden">
|
|
|
|
|
<div class="w-full p-2 text-sm">
|
2024-08-23 15:28:21 +02:00
|
|
|
{{ row }}
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
<td
|
|
|
|
|
v-for="column in columns"
|
|
|
|
|
:key="row + column"
|
|
|
|
|
class="border-l border-gray-300 hover:!bg-gray-100 dark:hover:!bg-gray-800"
|
2024-11-20 17:06:11 +01:00
|
|
|
:class="{
|
|
|
|
|
'!cursor-not-allowed !bg-gray-200 dark:!bg-gray-800 hover:!bg-gray-200 dark:hover:!bg-gray-800': disabled,
|
|
|
|
|
}"
|
2024-08-23 15:28:21 +02:00
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
v-if="compVal"
|
|
|
|
|
class="w-full flex items-center justify-center"
|
|
|
|
|
role="radio"
|
|
|
|
|
:aria-checked="compVal[row] === column"
|
|
|
|
|
:class="[
|
|
|
|
|
theme.FlatSelectInput.spacing.vertical,
|
|
|
|
|
theme.FlatSelectInput.fontSize,
|
|
|
|
|
theme.FlatSelectInput.option,
|
2024-11-20 17:06:11 +01:00
|
|
|
{
|
|
|
|
|
'!cursor-not-allowed !bg-transparent hover:!bg-transparent dark:hover:!bg-transparent': disabled,
|
|
|
|
|
}
|
2024-08-23 15:28:21 +02:00
|
|
|
]"
|
|
|
|
|
@click="onSelect(row, column)"
|
|
|
|
|
>
|
|
|
|
|
<RadioButtonIcon
|
|
|
|
|
:key="row+column"
|
|
|
|
|
:is-checked="compVal[row] === column"
|
|
|
|
|
:color="color"
|
|
|
|
|
:theme="theme"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
<template #help>
|
|
|
|
|
<slot name="help" />
|
|
|
|
|
</template>
|
|
|
|
|
<template #error>
|
|
|
|
|
<slot name="error" />
|
|
|
|
|
</template>
|
|
|
|
|
</input-wrapper>
|
|
|
|
|
</template>
|
2024-11-20 17:06:11 +01:00
|
|
|
<script>
|
|
|
|
|
import {inputProps, useFormInput} from "./useFormInput.js"
|
|
|
|
|
import InputWrapper from "./components/InputWrapper.vue"
|
|
|
|
|
import RadioButtonIcon from "./components/RadioButtonIcon.vue"
|
|
|
|
|
export default {
|
|
|
|
|
name: "MatrixInput",
|
|
|
|
|
components: {InputWrapper, RadioButtonIcon},
|
|
|
|
|
props: {
|
|
|
|
|
...inputProps,
|
|
|
|
|
rows: {type: Array, required: true},
|
|
|
|
|
columns: {type: Array, required: true},
|
|
|
|
|
},
|
|
|
|
|
setup(props, context) {
|
|
|
|
|
return {
|
|
|
|
|
...useFormInput(props, context),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2024-08-23 15:28:21 +02:00
|
|
|
}
|
|
|
|
|
},
|
2024-11-20 17:06:11 +01:00
|
|
|
computed: {},
|
|
|
|
|
mounted() {
|
|
|
|
|
if (!this.compVal || typeof this.compVal !== 'object') {
|
|
|
|
|
this.compVal = {}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
onSelect(row, column) {
|
|
|
|
|
if (this.disabled) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (this.compVal[row] === column && !this.required) {
|
|
|
|
|
this.compVal[row] = null
|
|
|
|
|
} else {
|
|
|
|
|
this.compVal[row] = column
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
</script>
|