|
19 | 19 | tabindex="0" |
20 | 20 | @click="onClick(col.value)" |
21 | 21 | @keydown.enter="onClick(col.value)" |
| 22 | + @mouseover="hoverValue = col.value" |
22 | 23 | > |
23 | 24 | <div :class="col.className"> |
24 | 25 | <slot v-if="$slots.item" name="item" :item="col" /> |
|
43 | 44 |
|
44 | 45 | <script lang="ts" setup> |
45 | 46 | import { computed, inject, onBeforeUpdate, onMounted, PropType, ref } from 'vue'; |
| 47 | + import { setMonth, setYear } from 'date-fns'; |
46 | 48 |
|
47 | 49 | import { IDefaultSelect, DynamicClass } from '../interfaces'; |
48 | 50 | import { getKey, unrefElement } from '../utils/util'; |
| 51 | + import { isDateBetween, isDateEqual } from '../utils/date-utils'; |
49 | 52 |
|
50 | 53 | const emit = defineEmits(['update:modelValue', 'selected', 'toggle', 'reset-flow']); |
51 | 54 |
|
52 | 55 | const props = defineProps({ |
53 | 56 | items: { type: Array as PropType<IDefaultSelect[][]>, default: () => [] }, |
54 | 57 | modelValue: { type: [String, Number] as PropType<string | number>, default: null }, |
| 58 | + multiModelValue: { type: Array as PropType<Date[]>, default: () => [] }, |
55 | 59 | disabledValues: { type: Array as PropType<number[]>, default: () => [] }, |
56 | 60 | minValue: { type: [Number, String] as PropType<number | string>, default: null }, |
57 | 61 | maxValue: { type: [Number, String] as PropType<number | string>, default: null }, |
| 62 | + year: { type: Number as PropType<number>, default: 0 }, |
58 | 63 | }); |
59 | 64 |
|
60 | 65 | const scrollable = ref(false); |
61 | 66 | const selectionActiveRef = ref(null); |
62 | 67 | const gridWrapRef = ref(null); |
63 | 68 | const autoApply = inject('autoApply', false); |
64 | 69 | const textInput = inject('textInput', ref(false)); |
| 70 | + const hoverValue = ref(); |
65 | 71 |
|
66 | 72 | onBeforeUpdate(() => { |
67 | 73 | selectionActiveRef.value = null; |
|
102 | 108 | .map((itemVal) => { |
103 | 109 | const disabled = |
104 | 110 | props.disabledValues.some((val) => val === itemVal.value) || checkMinMaxValue(itemVal.value); |
| 111 | + const active = props.multiModelValue?.length |
| 112 | + ? props.multiModelValue?.some((value) => |
| 113 | + isDateEqual(value, setYear(setMonth(new Date(), itemVal.value), props.year)), |
| 114 | + ) |
| 115 | + : itemVal.value === props.modelValue; |
| 116 | +
|
105 | 117 | return { |
106 | 118 | ...itemVal, |
107 | 119 | className: { |
108 | | - dp__overlay_cell_active: itemVal.value === props.modelValue, |
109 | | - dp__overlay_cell: itemVal.value !== props.modelValue, |
| 120 | + dp__overlay_cell_active: active, |
| 121 | + dp__overlay_cell: !active, |
110 | 122 | dp__overlay_cell_disabled: disabled, |
111 | | - dp__overlay_cell_active_disabled: disabled && itemVal.value === props.modelValue, |
| 123 | + dp__overlay_cell_active_disabled: disabled && active, |
112 | 124 | dp__overlay_cell_pad: true, |
| 125 | + dp__cell_in_between: props.multiModelValue?.length ? rangeActive(itemVal.value) : false, |
113 | 126 | }, |
114 | 127 | }; |
115 | 128 | }); |
|
168 | 181 | } |
169 | 182 | }; |
170 | 183 |
|
| 184 | + const rangeActive = (value: number): boolean => { |
| 185 | + return isDateBetween( |
| 186 | + props.multiModelValue, |
| 187 | + setYear(setMonth(new Date(), hoverValue.value || 0), props.year), |
| 188 | + setYear(setMonth(new Date(), value), props.year), |
| 189 | + ); |
| 190 | + }; |
| 191 | +
|
171 | 192 | const toggle = () => { |
172 | 193 | emit('toggle'); |
173 | 194 | emit('reset-flow'); |
|
0 commit comments