1 | import { __rest } from "tslib";
|
2 | import classNames from 'classnames';
|
3 | import React, { forwardRef, useRef } from 'react';
|
4 | import { withNativeProps } from '../../utils/native-props';
|
5 | import { mergeProps } from '../../utils/with-default-props';
|
6 | import Button from '../button';
|
7 | import CalendarPickerView from '../calendar-picker-view';
|
8 | import { Context } from '../calendar-picker-view/calendar-picker-view';
|
9 | import { useConfig } from '../config-provider';
|
10 | import Divider from '../divider';
|
11 | import Popup from '../popup';
|
12 | const classPrefix = 'adm-calendar-picker';
|
13 | const defaultProps = {
|
14 | weekStartsOn: 'Sunday',
|
15 | defaultValue: null,
|
16 | allowClear: true,
|
17 | usePopup: true,
|
18 | selectionMode: 'single'
|
19 | };
|
20 | export const CalendarPicker = forwardRef((p, ref) => {
|
21 | const props = mergeProps(defaultProps, p);
|
22 | const {
|
23 | locale
|
24 | } = useConfig();
|
25 | const calendarRef = ref !== null && ref !== void 0 ? ref : useRef(null);
|
26 | const {
|
27 | visible,
|
28 | confirmText,
|
29 | popupClassName,
|
30 | popupStyle,
|
31 | popupBodyStyle,
|
32 | forceRender,
|
33 | closeOnMaskClick,
|
34 | onClose,
|
35 | onConfirm,
|
36 | onMaskClick,
|
37 | getContainer
|
38 | } = props,
|
39 | calendarViewProps = __rest(props, ["visible", "confirmText", "popupClassName", "popupStyle", "popupBodyStyle", "forceRender", "closeOnMaskClick", "onClose", "onConfirm", "onMaskClick", "getContainer"]);
|
40 | const viewContext = React.useMemo(() => ({
|
41 | visible: !!visible
|
42 | }), [visible]);
|
43 | const footer = React.createElement("div", {
|
44 | className: `${classPrefix}-footer`
|
45 | }, React.createElement(Divider, null), React.createElement("div", {
|
46 | className: `${classPrefix}-footer-bottom`
|
47 | }, React.createElement(Button, {
|
48 | color: 'primary',
|
49 | onClick: () => {
|
50 | var _a, _b, _c, _d;
|
51 | const dateRange = (_b = (_a = calendarRef.current) === null || _a === void 0 ? void 0 : _a.getDateRange()) !== null && _b !== void 0 ? _b : null;
|
52 | if (props.selectionMode === 'single') {
|
53 | (_c = props.onConfirm) === null || _c === void 0 ? void 0 : _c.call(props, dateRange ? dateRange[0] : null);
|
54 | } else if (props.selectionMode === 'range') {
|
55 | (_d = props.onConfirm) === null || _d === void 0 ? void 0 : _d.call(props, dateRange);
|
56 | }
|
57 | onClose === null || onClose === void 0 ? void 0 : onClose();
|
58 | }
|
59 | }, confirmText !== null && confirmText !== void 0 ? confirmText : locale.Calendar.confirm)));
|
60 | return withNativeProps(props, React.createElement("div", {
|
61 | className: classPrefix
|
62 | }, React.createElement(Popup, {
|
63 | visible: visible,
|
64 | className: classNames(`${classPrefix}-popup`, popupClassName),
|
65 | showCloseButton: true,
|
66 | forceRender: ref ? true : forceRender,
|
67 | style: popupStyle,
|
68 | bodyStyle: Object.assign({
|
69 | borderTopLeftRadius: '8px',
|
70 | borderTopRightRadius: '8px',
|
71 | minHeight: '80vh',
|
72 | overflow: 'auto'
|
73 | }, popupBodyStyle),
|
74 | onClose: onClose,
|
75 | onMaskClick: () => {
|
76 | onMaskClick === null || onMaskClick === void 0 ? void 0 : onMaskClick();
|
77 | if (closeOnMaskClick) {
|
78 | onClose === null || onClose === void 0 ? void 0 : onClose();
|
79 | }
|
80 | },
|
81 | getContainer: getContainer
|
82 | }, React.createElement(Context.Provider, {
|
83 | value: viewContext
|
84 | }, React.createElement(CalendarPickerView, Object.assign({
|
85 | ref: calendarRef
|
86 | }, calendarViewProps))), footer)));
|
87 | }); |
\ | No newline at end of file |