-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathyear-calendar-panel.tsx
52 lines (49 loc) · 1.73 KB
/
year-calendar-panel.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { defineComponent } from 'vue';
import type { SetupContext } from 'vue';
import { useNamespace } from '@devui/shared/utils';
import useYearCalendarPanel from '../composables/use-year-calendar-panel';
import { datePickerProPanelProps, DatePickerProPanelProps } from '../date-picker-pro-types';
import { yearPickerHeight, yearCalendarItemHeight } from '../const';
import { VirtualList } from '../../../virtual-list';
export default defineComponent({
name: 'YearCalendarPanel',
props: datePickerProPanelProps,
emits: ['selectedDate', 'changeRangeFocusType'],
setup(props: DatePickerProPanelProps, ctx: SetupContext) {
const ns = useNamespace('date-picker-pro');
const { yarListScrollRef, yearList, getYearItemCls, handlerSelectYear } = useYearCalendarPanel(props, ctx);
return () => {
const yearItemSlots = {
item: (years: number[]) => {
return (
<div class={ns.e('year-list-item')}>
{years.map((year: number) => (
<div
key={year}
class={getYearItemCls(year)}
onClick={(e: MouseEvent) => {
e.preventDefault();
e.stopPropagation();
handlerSelectYear(year);
}}>
{year}
</div>
))}
</div>
);
},
};
return (
<div class={ns.e('year-calendar-panel')}>
<VirtualList
ref={yarListScrollRef}
class={ns.e('year-list')}
data={yearList.value}
height={yearPickerHeight}
itemHeight={yearCalendarItemHeight}
v-slots={yearItemSlots}></VirtualList>
</div>
);
};
},
});