Files
axp-ui/src/components/PickerDays.vue
T

59 lines
1.3 KiB
Vue
Raw Normal View History

2023-09-20 14:09:22 +03:00
<script lang="ts">
export type TUiPickerDaysProps = {
2023-07-27 15:36:52 +03:00
modelValue?: number[]
label?: string
error?: string
readonly?: boolean
disabled?: boolean
2023-09-20 14:09:22 +03:00
}
export type TUiPickerDaysEmits = {
(e: 'update:modelValue', v: number[]): void
}
</script>
<script setup lang="ts">
import UiFieldCheckbox from './FieldCheckbox.vue'
// Props.
const props = defineProps<TUiPickerDaysProps>()
2023-07-27 15:36:52 +03:00
// Emits.
2023-09-20 14:09:22 +03:00
const emit = defineEmits<TUiPickerDaysEmits>()
2023-07-27 15:36:52 +03:00
// Init data.
const days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс']
// Handlers.
const inputHandler = (index: number) => {
const number = index + 1
let result: number[] = props.modelValue || []
if (result.includes(number)) {
result = result.filter(e => e !== number)
} else {
result.push(number)
}
emit('update:modelValue', result.sort())
}
</script>
<template>
2023-07-28 13:10:15 +03:00
<div class="ui-picker ui-picker-days">
2023-07-27 15:36:52 +03:00
<div v-if="props.label" class="label mb-2">
<span>{{props.label}}:</span>
</div>
2023-07-28 13:10:15 +03:00
<div class="ui-picker-content flex items-center">
2023-07-27 15:36:52 +03:00
<ui-field-checkbox
v-for="(item, index) in days"
class="mr-4"
:modelValue="props.modelValue?.includes(index + 1)"
:label="item"
:disabled="props.disabled"
:readonly="props.readonly"
@input="inputHandler(index)"
/>
</div>
<div v-if="error" class="mt-2 text-error">{{ error }}</div>
</div>
</template>