UNPKG

3.04 kBJavaScriptView Raw
1import * as React from 'react';
2import useSelectIcons from '../select/useIcons';
3export function getPlaceholder(locale, picker, customizePlaceholder) {
4 if (customizePlaceholder !== undefined) {
5 return customizePlaceholder;
6 }
7 if (picker === 'year' && locale.lang.yearPlaceholder) {
8 return locale.lang.yearPlaceholder;
9 }
10 if (picker === 'quarter' && locale.lang.quarterPlaceholder) {
11 return locale.lang.quarterPlaceholder;
12 }
13 if (picker === 'month' && locale.lang.monthPlaceholder) {
14 return locale.lang.monthPlaceholder;
15 }
16 if (picker === 'week' && locale.lang.weekPlaceholder) {
17 return locale.lang.weekPlaceholder;
18 }
19 if (picker === 'time' && locale.timePickerLocale.placeholder) {
20 return locale.timePickerLocale.placeholder;
21 }
22 return locale.lang.placeholder;
23}
24export function getRangePlaceholder(locale, picker, customizePlaceholder) {
25 if (customizePlaceholder !== undefined) {
26 return customizePlaceholder;
27 }
28 if (picker === 'year' && locale.lang.yearPlaceholder) {
29 return locale.lang.rangeYearPlaceholder;
30 }
31 if (picker === 'quarter' && locale.lang.quarterPlaceholder) {
32 return locale.lang.rangeQuarterPlaceholder;
33 }
34 if (picker === 'month' && locale.lang.monthPlaceholder) {
35 return locale.lang.rangeMonthPlaceholder;
36 }
37 if (picker === 'week' && locale.lang.weekPlaceholder) {
38 return locale.lang.rangeWeekPlaceholder;
39 }
40 if (picker === 'time' && locale.timePickerLocale.placeholder) {
41 return locale.timePickerLocale.rangePlaceholder;
42 }
43 return locale.lang.rangePlaceholder;
44}
45export function transPlacement2DropdownAlign(direction, placement) {
46 const overflow = {
47 adjustX: 1,
48 adjustY: 1
49 };
50 switch (placement) {
51 case 'bottomLeft':
52 {
53 return {
54 points: ['tl', 'bl'],
55 offset: [0, 4],
56 overflow
57 };
58 }
59 case 'bottomRight':
60 {
61 return {
62 points: ['tr', 'br'],
63 offset: [0, 4],
64 overflow
65 };
66 }
67 case 'topLeft':
68 {
69 return {
70 points: ['bl', 'tl'],
71 offset: [0, -4],
72 overflow
73 };
74 }
75 case 'topRight':
76 {
77 return {
78 points: ['br', 'tr'],
79 offset: [0, -4],
80 overflow
81 };
82 }
83 default:
84 {
85 return {
86 points: direction === 'rtl' ? ['tr', 'br'] : ['tl', 'bl'],
87 offset: [0, 4],
88 overflow
89 };
90 }
91 }
92}
93export function useIcons(props, prefixCls) {
94 const {
95 allowClear = true
96 } = props;
97 const {
98 clearIcon,
99 removeIcon
100 } = useSelectIcons(Object.assign(Object.assign({}, props), {
101 prefixCls,
102 componentName: 'DatePicker'
103 }));
104 const mergedAllowClear = React.useMemo(() => {
105 if (allowClear === false) {
106 return false;
107 }
108 const allowClearConfig = allowClear === true ? {} : allowClear;
109 return Object.assign({
110 clearIcon: clearIcon
111 }, allowClearConfig);
112 }, [allowClear, clearIcon]);
113 return [mergedAllowClear, removeIcon];
114}
\No newline at end of file