woodpecker/web/src/components/form/CheckboxesField.vue
Anbraten 58838f225c
Rewrite of WebUI (#245)
Rewrite of the UI using Typescript, Vue3, Windicss and Vite. The design should  be close to the current one with some changes:
- latest pipeline in a sidebar on the right
- secrets and registry as part of the repo-settings (secrets and registry entries shouldn't be used as much so they can be "hidden" under settings IMO)
- start page shows list of active repositories with button to enable / add new ones (currently you see all repositories and in most cases you only add new repositories once in a while)
2021-11-03 17:40:31 +01:00

66 lines
1.5 KiB
Vue

<template>
<Checkbox
v-for="option in options"
:key="option.value"
:model-value="innerValue.includes(option.value)"
:label="option.text"
class="mb-2"
@update:model-value="clickOption(option)"
/>
</template>
<script lang="ts">
import { computed, defineComponent, PropType, toRef } from 'vue';
import Checkbox from './Checkbox.vue';
import { CheckboxOption } from './form.types';
export default defineComponent({
name: 'CheckboxesField',
components: { Checkbox },
props: {
// used by toRef
// eslint-disable-next-line vue/no-unused-properties
modelValue: {
type: Array as PropType<CheckboxOption['value'][]>,
default: () => [],
},
options: {
type: Array as PropType<CheckboxOption[]>,
required: true,
},
},
emits: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
'update:modelValue': (_value: CheckboxOption['value'][]): boolean => true,
},
setup: (props, ctx) => {
const modelValue = toRef(props, 'modelValue');
const innerValue = computed({
get: () => modelValue.value,
set: (value) => {
ctx.emit('update:modelValue', value);
},
});
function clickOption(option: CheckboxOption) {
if (innerValue.value.includes(option.value)) {
innerValue.value = innerValue.value.filter((o) => o !== option.value);
} else {
innerValue.value.push(option.value);
}
}
return {
innerValue,
clickOption,
};
},
});
</script>