@trionesdev/antd-taro-react 0.0.2-beta.10 → 0.0.2-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,27 +1,28 @@
1
1
  import { FC } from 'react';
2
2
  import './style.scss';
3
+ import dayjs, { ConfigType } from "dayjs";
3
4
  export type CalendarGridProps = {
4
- mouth?: Date;
5
+ month?: dayjs.Dayjs;
5
6
  /**
6
7
  * @description 值,如果是区间模式,则 0,1 索引的值有效,0是开始时间,1是结束时间
7
8
  */
8
- value?: Date[];
9
+ value?: dayjs.Dayjs[];
9
10
  /**
10
11
  * @description 默认值,如果是区间模式,则 0,1 索引的值有效,0是开始时间,1是结束时间
11
12
  */
12
- defaultValue?: Date[];
13
- onChange?: (value: Date[]) => void;
13
+ defaultValue?: dayjs.Dayjs[];
14
+ onChange?: (value: dayjs.Dayjs[]) => void;
14
15
  /**
15
16
  * @description 是否为范围选择
16
17
  */
17
18
  range?: boolean;
18
- onSelect?: (date: Date) => void;
19
+ onSelect?: (date: ConfigType) => void;
19
20
  };
20
21
  export type CalendarCellProps = {
21
- mouth?: Date;
22
- date?: Date;
23
- value?: Date[];
22
+ month?: dayjs.Dayjs;
23
+ date?: dayjs.Dayjs;
24
+ value?: dayjs.Dayjs[];
24
25
  range?: boolean;
25
- onSelect?: (date: Date) => void;
26
+ onSelect?: (date: dayjs.Dayjs) => void;
26
27
  };
27
28
  export declare const CalendarGrid: FC<CalendarGridProps>;
@@ -1,8 +1,4 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
2
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
4
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -16,40 +12,32 @@ import classNames from 'classnames';
16
12
  import { isEmpty } from 'lodash-es';
17
13
  import React, { forwardRef, memo, useEffect, useMemo, useState } from 'react';
18
14
  import "./style.scss";
15
+ import dayjs from "dayjs";
16
+ import { isSame } from "../utils/dayjs";
19
17
  var calendarCls = 'triones-antm-calendar';
20
18
  var CalendarCell = /*#__PURE__*/memo(function (_ref) {
21
- var _ref$mouth = _ref.mouth,
22
- mouth = _ref$mouth === void 0 ? new Date() : _ref$mouth,
19
+ var _ref$month = _ref.month,
20
+ month = _ref$month === void 0 ? dayjs() : _ref$month,
23
21
  _ref$date = _ref.date,
24
- date = _ref$date === void 0 ? new Date() : _ref$date,
22
+ date = _ref$date === void 0 ? dayjs() : _ref$date,
25
23
  value = _ref.value,
26
24
  range = _ref.range,
27
25
  onSelect = _ref.onSelect;
28
26
  var disabled = useMemo(function () {
29
- return date.getMonth() !== mouth.getMonth();
30
- }, [date, mouth]);
27
+ return !isSame(date, month, 'month');
28
+ }, [date, month]);
31
29
  var selected = useMemo(function () {
32
30
  if (disabled || isEmpty(value)) {
33
31
  return false;
34
32
  }
35
- if (value !== null && value !== void 0 && value[0]) {
36
- var _value$;
37
- value === null || value === void 0 || (_value$ = value[0]) === null || _value$ === void 0 || _value$.setHours(0, 0, 0, 0);
38
- }
39
- if (value !== null && value !== void 0 && value[1]) {
40
- var _value$2;
41
- value === null || value === void 0 || (_value$2 = value[1]) === null || _value$2 === void 0 || _value$2.setHours(0, 0, 0, 0);
42
- }
43
- date.setHours(0, 0, 0, 0);
44
33
  if (range) {
45
34
  var startDate = value === null || value === void 0 ? void 0 : value[0];
46
35
  var endDate = value === null || value === void 0 ? void 0 : value[1];
47
- return date.getTime() === (startDate === null || startDate === void 0 ? void 0 : startDate.getTime()) || date.getTime() === (endDate === null || endDate === void 0 ? void 0 : endDate.getTime());
36
+ return isSame(date, startDate, 'date') || isSame(date, endDate, 'date');
48
37
  } else {
49
- var _value$3;
50
- return date.getTime() === (value === null || value === void 0 || (_value$3 = value[0]) === null || _value$3 === void 0 ? void 0 : _value$3.getTime());
38
+ return isSame(date, value === null || value === void 0 ? void 0 : value[0], 'date');
51
39
  }
52
- }, [mouth, date, value]);
40
+ }, [month, date, value]);
53
41
  var selectedRange = useMemo(function () {
54
42
  if (disabled || !range) {
55
43
  return false;
@@ -59,13 +47,10 @@ var CalendarCell = /*#__PURE__*/memo(function (_ref) {
59
47
  if (!startDate || !endDate) {
60
48
  return false;
61
49
  }
62
- date.setHours(0, 0, 0, 0);
63
- startDate.setHours(0, 0, 0, 0);
64
- endDate.setHours(0, 0, 0, 0);
65
- return date.getTime() > startDate.getTime() && date.getTime() < endDate.getTime();
66
- }, [mouth, date, value]);
50
+ return dayjs(date).isAfter(startDate, 'date') && dayjs(date).isBefore(endDate, 'date');
51
+ }, [month, date, value]);
67
52
  return /*#__PURE__*/React.createElement("div", {
68
- className: classNames("".concat(calendarCls, "-cell"), _defineProperty(_defineProperty(_defineProperty({}, "".concat(calendarCls, "-cell-disabled"), disabled), "".concat(calendarCls, "-cell-selected"), selected), "".concat(calendarCls, "-cell-selected-range"), selectedRange))
53
+ className: classNames("".concat(calendarCls, "-cell"), _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, "".concat(calendarCls, "-cell-disabled"), disabled), "".concat(calendarCls, "-cell-selected"), selected), "".concat(calendarCls, "-cell-today"), isSame(date, dayjs(), 'day')), "".concat(calendarCls, "-cell-selected-range"), selectedRange))
69
54
  // style={{ width: size, height: size }}
70
55
  ,
71
56
  onClick: function onClick() {
@@ -73,14 +58,14 @@ var CalendarCell = /*#__PURE__*/memo(function (_ref) {
73
58
  }
74
59
  }, /*#__PURE__*/React.createElement("div", {
75
60
  className: classNames("".concat(calendarCls, "-cell-date"))
76
- }, date.getDate()), date.getDate() === 1 && /*#__PURE__*/React.createElement("div", {
61
+ }, dayjs(date).date()), dayjs(date).date() === 1 && /*#__PURE__*/React.createElement("div", {
77
62
  className: classNames("".concat(calendarCls, "-cell-mouth"))
78
- }, "".concat(date.getMonth() + 1, "\u6708")));
63
+ }, "".concat(dayjs(date).month() + 1, "\u6708")));
79
64
  });
80
65
  export var CalendarGrid = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref2, ref) {
81
66
  var _ref3;
82
- var _ref2$mouth = _ref2.mouth,
83
- mouth = _ref2$mouth === void 0 ? new Date() : _ref2$mouth,
67
+ var _ref2$month = _ref2.month,
68
+ month = _ref2$month === void 0 ? dayjs() : _ref2$month,
84
69
  value = _ref2.value,
85
70
  defaultValue = _ref2.defaultValue,
86
71
  _ref2$range = _ref2.range,
@@ -92,14 +77,13 @@ export var CalendarGrid = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_
92
77
  innerValue = _useState2[0],
93
78
  setInnerValue = _useState2[1];
94
79
  var handleSelect = function handleSelect(date) {
95
- date.setHours(0, 0, 0, 0);
96
80
  var _value = innerValue;
97
81
  if (range) {
98
82
  if (!_value[0]) {
99
83
  _value = [date];
100
84
  } else if (!_value[1]) {
101
85
  var startDate = _value[0];
102
- if (date.getTime() < startDate.getTime()) {
86
+ if (dayjs(date).isBefore(startDate, 'date')) {
103
87
  _value = [date, startDate];
104
88
  } else {
105
89
  _value = [startDate, date];
@@ -115,35 +99,27 @@ export var CalendarGrid = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_
115
99
  onChange === null || onChange === void 0 || onChange(_value);
116
100
  };
117
101
  var cells = useMemo(function () {
118
- var firstDate = new Date(mouth.getFullYear(), mouth.getMonth(), 1);
119
- var lastDate = new Date(mouth.getFullYear(), mouth.getMonth() + 1, 0);
120
- var beforeDays = Array.from({
121
- length: firstDate.getDay()
122
- }).map(function (_, index) {
123
- var date = new Date(firstDate);
124
- date.setDate(firstDate.getDate() - (firstDate.getDay() - index));
125
- return date;
126
- });
127
- var afterDays = Array.from({
128
- length: 6 - lastDate.getDay()
129
- }).map(function (_, index) {
130
- var date = new Date(lastDate);
131
- date.setDate(lastDate.getDate() + index + 1);
132
- return date;
102
+ var firstDate = dayjs(month).startOf('month');
103
+
104
+ // 固定生成42天的日期网格(6行7列)
105
+ var startDate = firstDate.subtract(firstDate.day(), 'day');
106
+ var cells = Array.from({
107
+ length: 42
108
+ }, function (_, index) {
109
+ return startDate.add(index, 'day');
133
110
  });
134
- var mouthDays = Array.from({
135
- length: lastDate.getDate()
136
- }).map(function (_, index) {
137
- var date = new Date(firstDate);
138
- date.setDate(date.getDate() + index);
139
- return date;
140
- });
141
- return [].concat(_toConsumableArray(beforeDays), _toConsumableArray(mouthDays), _toConsumableArray(afterDays));
142
- }, [mouth]);
111
+ return cells;
112
+ }, [month]);
143
113
  useEffect(function () {
144
114
  if (value !== undefined) {
145
- if (value !== innerValue) {
146
- setInnerValue(value);
115
+ if (range) {
116
+ if (!isSame(value[0], innerValue[0], 'day') || !isSame(value[1], innerValue[1], 'day')) {
117
+ setInnerValue(value);
118
+ }
119
+ } else {
120
+ if (!isSame(value[0], innerValue[0], 'day')) {
121
+ setInnerValue(value);
122
+ }
147
123
  }
148
124
  }
149
125
  }, [value]);
@@ -153,7 +129,7 @@ export var CalendarGrid = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_
153
129
  }, cells.map(function (item, index) {
154
130
  return /*#__PURE__*/React.createElement(CalendarCell, {
155
131
  key: index,
156
- mouth: mouth,
132
+ month: month,
157
133
  date: item,
158
134
  value: innerValue,
159
135
  range: range,
@@ -1,7 +1,8 @@
1
1
  import { FC } from "react";
2
+ import dayjs from "dayjs";
2
3
  type CalendarHeaderProps = {
3
- mouth: Date;
4
- onChange: (mouth: Date) => void;
4
+ month: dayjs.Dayjs;
5
+ onChange: (mouth: dayjs.Dayjs) => void;
5
6
  };
6
7
  export declare const CalendarHeader: FC<CalendarHeaderProps>;
7
8
  export {};
@@ -3,33 +3,36 @@ import classNames from "classnames";
3
3
  import ConfigProvider from "../ConfigProvider";
4
4
  var calendarCls = 'triones-antm-calendar';
5
5
  export var CalendarHeader = function CalendarHeader(_ref) {
6
- var mouth = _ref.mouth,
6
+ var month = _ref.month,
7
7
  onChange = _ref.onChange;
8
8
  var _ConfigProvider$useCo = ConfigProvider.useConfig(),
9
9
  locale = _ConfigProvider$useCo.locale;
10
+ if (!month) {
11
+ return null;
12
+ }
10
13
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
11
14
  className: classNames("".concat(calendarCls, "-header"))
12
15
  }, /*#__PURE__*/React.createElement("div", {
13
16
  className: classNames("".concat(calendarCls, "-header-button")),
14
17
  onClick: function onClick() {
15
- onChange(new Date(mouth.getFullYear() - 1, mouth.getMonth(), 1));
18
+ onChange(month.subtract(1, 'year'));
16
19
  }
17
20
  }, "<<"), /*#__PURE__*/React.createElement("div", {
18
21
  className: classNames("".concat(calendarCls, "-header-button")),
19
22
  onClick: function onClick() {
20
- onChange(new Date(mouth.getFullYear(), mouth.getMonth() - 1, 1));
23
+ onChange(month.subtract(1, 'month'));
21
24
  }
22
25
  }, "<"), /*#__PURE__*/React.createElement("div", {
23
26
  className: classNames("".concat(calendarCls, "-header-title"))
24
- }, "".concat(mouth.getFullYear(), "\u5E74").concat(mouth.getMonth() + 1, "\u6708")), /*#__PURE__*/React.createElement("div", {
27
+ }, "".concat(month.year(), "\u5E74").concat(month.month() + 1, "\u6708")), /*#__PURE__*/React.createElement("div", {
25
28
  className: classNames("".concat(calendarCls, "-header-button")),
26
29
  onClick: function onClick() {
27
- onChange(new Date(mouth.getFullYear(), mouth.getMonth() + 1, 1));
30
+ onChange(month.add(1, 'month'));
28
31
  }
29
32
  }, ">"), /*#__PURE__*/React.createElement("div", {
30
33
  className: classNames("".concat(calendarCls, "-header-button")),
31
34
  onClick: function onClick() {
32
- onChange(new Date(mouth.getFullYear() + 1, mouth.getMonth(), 1));
35
+ onChange(month.add(1, 'year'));
33
36
  }
34
37
  }, ">>")), /*#__PURE__*/React.createElement("div", {
35
38
  className: classNames("".concat(calendarCls, "-week"))
@@ -1,9 +1,10 @@
1
1
  import { FC } from 'react';
2
2
  import './style.scss';
3
+ import dayjs from "dayjs";
3
4
  type CalendarProps = {
4
- mouth?: Date;
5
- value?: Date[];
6
- onChange?: (date: Date[]) => void;
5
+ month?: dayjs.Dayjs | Date;
6
+ value?: dayjs.Dayjs[] | Date[];
7
+ onChange?: (date: dayjs.Dayjs[]) => void;
7
8
  slideable?: boolean;
8
9
  };
9
10
  export declare const CalendarRange: FC<CalendarProps>;
@@ -5,49 +5,53 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
5
5
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import classNames from 'classnames';
8
- import _ from 'lodash-es';
9
8
  import React, { memo, useEffect, useRef, useState } from 'react';
10
9
  import { CalendarGrid } from "./calendar-grid";
11
10
  import { CalendarHeader } from "./calendar-header";
12
11
  import "./style.scss";
13
12
  import { TouchableCalendarGrid } from "./touchable-calendar-grid";
13
+ import dayjs from "dayjs";
14
+ import { isSame, toDayjsArray } from "../utils/dayjs";
14
15
  var calendarCls = 'triones-antm-calendar';
15
16
  export var CalendarRange = /*#__PURE__*/memo(function (_ref) {
16
- var _ref2, _ref3;
17
- var _ref$mouth = _ref.mouth,
18
- mouth = _ref$mouth === void 0 ? new Date() : _ref$mouth,
19
- value = _ref.value,
17
+ var _ref2, _toDayjsArray, _ref3, _toDayjsArray2;
18
+ var month = _ref.month,
19
+ _ref$value = _ref.value,
20
+ value = _ref$value === void 0 ? [] : _ref$value,
20
21
  _onChange = _ref.onChange,
21
22
  slideable = _ref.slideable;
22
- var _useState = useState(mouth),
23
+ var _useState = useState(dayjs(month)),
23
24
  _useState2 = _slicedToArray(_useState, 2),
24
- currentMouth = _useState2[0],
25
- setCurrentMouth = _useState2[1];
26
- var valueRef = useRef();
25
+ currentMonth = _useState2[0],
26
+ setCurrentMonth = _useState2[1];
27
+ var valueRef = useRef(value ? value.map(function (v) {
28
+ return dayjs(v);
29
+ }) : []);
27
30
  useEffect(function () {
28
31
  if (value !== undefined) {
29
- if (!_.isEqual(value, valueRef.current)) {
30
- valueRef.current = value;
32
+ var _valueRef$current, _valueRef$current2;
33
+ if (!isSame(value === null || value === void 0 ? void 0 : value[0], (_valueRef$current = valueRef.current) === null || _valueRef$current === void 0 ? void 0 : _valueRef$current[0], 'day') || !isSame(value === null || value === void 0 ? void 0 : value[1], (_valueRef$current2 = valueRef.current) === null || _valueRef$current2 === void 0 ? void 0 : _valueRef$current2[1], 'day')) {
34
+ valueRef.current = toDayjsArray(value) || [];
31
35
  }
32
36
  }
33
37
  }, [value]);
34
38
  return /*#__PURE__*/React.createElement("div", {
35
39
  className: classNames("".concat(calendarCls))
36
40
  }, /*#__PURE__*/React.createElement(CalendarHeader, {
37
- mouth: currentMouth,
38
- onChange: setCurrentMouth
41
+ month: currentMonth,
42
+ onChange: setCurrentMonth
39
43
  }), slideable ? /*#__PURE__*/React.createElement(TouchableCalendarGrid, {
40
- mouth: currentMouth,
41
- value: (_ref2 = value !== null && value !== void 0 ? value : valueRef.current) !== null && _ref2 !== void 0 ? _ref2 : [],
42
- onMouthChange: setCurrentMouth,
44
+ month: currentMonth,
45
+ value: (_ref2 = (_toDayjsArray = toDayjsArray(value)) !== null && _toDayjsArray !== void 0 ? _toDayjsArray : valueRef.current) !== null && _ref2 !== void 0 ? _ref2 : [],
46
+ onMonthChange: setCurrentMonth,
43
47
  onChange: function onChange(value) {
44
48
  valueRef.current = value;
45
49
  _onChange === null || _onChange === void 0 || _onChange(value);
46
50
  },
47
51
  range: true
48
52
  }) : /*#__PURE__*/React.createElement(CalendarGrid, {
49
- mouth: currentMouth,
50
- value: (_ref3 = value !== null && value !== void 0 ? value : valueRef.current) !== null && _ref3 !== void 0 ? _ref3 : [],
53
+ month: currentMonth,
54
+ value: (_ref3 = (_toDayjsArray2 = toDayjsArray(value)) !== null && _toDayjsArray2 !== void 0 ? _toDayjsArray2 : valueRef.current) !== null && _ref3 !== void 0 ? _ref3 : [],
51
55
  onChange: function onChange(value) {
52
56
  valueRef.current = value;
53
57
  _onChange === null || _onChange === void 0 || _onChange(value);
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import './style.scss';
3
+ import dayjs from "dayjs";
3
4
  export type CalendarProps = {
4
- mouth?: Date;
5
- value?: Date;
6
- onChange?: (date: Date) => void;
7
- onMouthChange?: (mouth: Date) => void;
5
+ month?: dayjs.Dayjs | Date;
6
+ value?: dayjs.Dayjs | Date;
7
+ onChange?: (date: dayjs.Dayjs) => void;
8
+ onMonthChange?: (month: dayjs.Dayjs) => void;
8
9
  slideable?: boolean;
9
10
  };
10
11
  export declare const Calendar: React.MemoExoticComponent<React.ForwardRefExoticComponent<CalendarProps & React.RefAttributes<HTMLDivElement>>>;
@@ -6,42 +6,55 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { CalendarGrid } from "./..";
8
8
  import classNames from 'classnames';
9
- import React, { forwardRef, memo, useState } from 'react';
9
+ import React, { forwardRef, memo, useEffect, useState } from 'react';
10
10
  import { CalendarHeader } from "./calendar-header";
11
11
  import "./style.scss";
12
12
  import { TouchableCalendarGrid } from "./touchable-calendar-grid";
13
- import { cloneDeep } from "lodash-es";
13
+ import dayjs from "dayjs";
14
+ import { isSame } from "../utils/dayjs";
14
15
  var calendarCls = 'triones-antm-calendar';
15
16
  export var Calendar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_ref, ref) {
16
- var mouth = _ref.mouth,
17
+ var month = _ref.month,
17
18
  value = _ref.value,
18
19
  _onChange = _ref.onChange,
19
- _onMouthChange = _ref.onMouthChange,
20
+ onMonthChange = _ref.onMonthChange,
20
21
  _ref$slideable = _ref.slideable,
21
22
  slideable = _ref$slideable === void 0 ? false : _ref$slideable;
22
- var _useState = useState(mouth || new Date()),
23
+ var _useState = useState(dayjs(month)),
23
24
  _useState2 = _slicedToArray(_useState, 2),
24
- currentMouth = _useState2[0],
25
- setCurrentMouth = _useState2[1];
25
+ currentMonth = _useState2[0],
26
+ setCurrentMonth = _useState2[1];
27
+ var handleMonthChange = function handleMonthChange(newMonth) {
28
+ if (isSame(currentMonth, newMonth, 'month')) {
29
+ return;
30
+ }
31
+ setCurrentMonth(newMonth);
32
+ onMonthChange === null || onMonthChange === void 0 || onMonthChange(newMonth);
33
+ };
34
+ useEffect(function () {
35
+ if (month == undefined) {
36
+ return;
37
+ }
38
+ if (!isSame(month, currentMonth, 'month')) {
39
+ setCurrentMonth(dayjs(month));
40
+ }
41
+ }, [month]);
26
42
  return /*#__PURE__*/React.createElement("div", {
27
43
  ref: ref,
28
44
  className: classNames("".concat(calendarCls))
29
45
  }, /*#__PURE__*/React.createElement(CalendarHeader, {
30
- mouth: currentMouth,
31
- onChange: setCurrentMouth
46
+ month: currentMonth,
47
+ onChange: handleMonthChange
32
48
  }), slideable ? /*#__PURE__*/React.createElement(TouchableCalendarGrid, {
33
- mouth: currentMouth,
34
- value: value ? [cloneDeep(value)] : [],
35
- onMouthChange: function onMouthChange(newMouth) {
36
- setCurrentMouth(newMouth);
37
- _onMouthChange === null || _onMouthChange === void 0 || _onMouthChange(newMouth);
38
- },
49
+ month: currentMonth,
50
+ value: value ? [dayjs(value)] : [],
51
+ onMonthChange: handleMonthChange,
39
52
  onChange: function onChange(value) {
40
53
  _onChange === null || _onChange === void 0 || _onChange(value === null || value === void 0 ? void 0 : value[0]);
41
54
  }
42
55
  }) : /*#__PURE__*/React.createElement(CalendarGrid, {
43
- mouth: currentMouth,
44
- value: value ? [cloneDeep(value)] : [],
56
+ month: currentMonth,
57
+ value: value ? [dayjs(value)] : [],
45
58
  onChange: function onChange(value) {
46
59
  _onChange === null || _onChange === void 0 || _onChange(value === null || value === void 0 ? void 0 : value[0]);
47
60
  }
@@ -34,10 +34,13 @@ $calendarCls: 'triones-antm-calendar';
34
34
  }
35
35
 
36
36
  &.#{$calendarCls}-cell {
37
+ box-sizing: border-box;
37
38
  &-disabled {
38
39
  color: #999999;
39
40
  }
40
-
41
+ &-today{
42
+ border: 1Px solid variable.$trionesColorPrimary;
43
+ }
41
44
  &-selected {
42
45
  background-color: variable.$trionesColorPrimary;
43
46
  color: white;
@@ -1,10 +1,11 @@
1
1
  import { FC } from 'react';
2
+ import dayjs from "dayjs";
2
3
  type CalendarPickerViewProps = {
3
- mouth?: Date;
4
- value?: Date[];
5
- defaultValue?: Date[];
6
- onChange?: (value: Date[]) => void;
7
- onMouthChange?: (mouth: Date) => void;
4
+ month?: dayjs.Dayjs;
5
+ value?: dayjs.Dayjs[];
6
+ defaultValue?: dayjs.Dayjs[];
7
+ onChange?: (value: dayjs.Dayjs[]) => void;
8
+ onMonthChange?: (mouth: dayjs.Dayjs) => void;
8
9
  range?: boolean;
9
10
  };
10
11
  /**
@@ -15,30 +15,32 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
15
  import React, { memo, useEffect, useRef, useState } from 'react';
16
16
  import Taro from '@tarojs/taro';
17
17
  import { CalendarGrid } from "../Calendar";
18
- import { useTaro } from "../hooks/useTaro";
18
+ import { useTaro } from "../hooks";
19
19
  import { RandomUtils } from "../utils/random-utils";
20
20
  import classNames from "classnames";
21
+ import dayjs from "dayjs";
22
+ var monthLines = 6;
23
+
21
24
  /**
22
25
  * 可以手势滑动的日历组件
23
26
  */
24
27
  export var TouchableCalendarGrid = /*#__PURE__*/memo(function (_ref) {
25
28
  var _wrapperRef$current3;
26
- var _ref$mouth = _ref.mouth,
27
- mouth = _ref$mouth === void 0 ? new Date() : _ref$mouth,
29
+ var month = _ref.month,
28
30
  value = _ref.value,
29
31
  defaultValue = _ref.defaultValue,
30
32
  onChange = _ref.onChange,
31
- onMouthChange = _ref.onMouthChange,
33
+ onMonthChange = _ref.onMonthChange,
32
34
  range = _ref.range;
33
35
  var _useTaro = useTaro(),
34
36
  isTaroEnv = _useTaro.isTaroEnv,
35
37
  isTaroWeApp = _useTaro.isTaroWeApp;
36
38
  var wrapperRef = useRef();
37
39
  var wrapperUniqueRef = React.useRef(RandomUtils.random());
38
- var _useState = useState(mouth),
40
+ var _useState = useState(month || dayjs()),
39
41
  _useState2 = _slicedToArray(_useState, 2),
40
- currentMouth = _useState2[0],
41
- setCurrentMouth = _useState2[1];
42
+ currentMonth = _useState2[0],
43
+ setCurrentMonth = _useState2[1];
42
44
  var waiting = false;
43
45
  var _useState3 = useState(200),
44
46
  _useState4 = _slicedToArray(_useState3, 2),
@@ -139,16 +141,16 @@ export var TouchableCalendarGrid = /*#__PURE__*/memo(function (_ref) {
139
141
  * @param mouth
140
142
  */
141
143
  var mouthLines = function mouthLines(mouth) {
142
- var firstDate = new Date(mouth.getFullYear(), mouth.getMonth(), 1);
143
- var lastDate = new Date(mouth.getFullYear(), mouth.getMonth() + 1, 0);
144
- var beforeDays = firstDate.getDay();
145
- var afterDays = 6 - lastDate.getDay();
146
- var countDays = beforeDays + lastDate.getDate() + afterDays;
144
+ var firstDate = dayjs(new Date(mouth.year(), mouth.month(), 1));
145
+ var lastDate = dayjs(new Date(mouth.year(), mouth.month() + 1, 0));
146
+ var beforeDays = firstDate.day();
147
+ var afterDays = 6 - lastDate.day();
148
+ var countDays = beforeDays + lastDate.date() + afterDays;
147
149
  return Math.ceil(countDays / 7);
148
150
  };
149
151
  var handleInsertMouth = /*#__PURE__*/function () {
150
152
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
151
- var firstMouth, insertMouth, newMouths, insertMouthLines, insertMouthHeight;
153
+ var firstMouth, insertMouth, newMouths, insertMouthHeight;
152
154
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
153
155
  while (1) switch (_context3.prev = _context3.next) {
154
156
  case 0:
@@ -158,19 +160,19 @@ export var TouchableCalendarGrid = /*#__PURE__*/memo(function (_ref) {
158
160
  // debugger
159
161
  // waiting = true
160
162
  firstMouth = mouths[0];
161
- insertMouth = new Date(firstMouth.getFullYear(), firstMouth.getMonth() - 1, 1);
163
+ insertMouth = dayjs(new Date(firstMouth.year(), firstMouth.month() - 1, 1));
162
164
  newMouths = [insertMouth].concat(_toConsumableArray(mouths));
163
165
  setMouths(newMouths);
164
- insertMouthLines = mouthLines(insertMouth);
165
- _context3.t0 = insertMouthLines;
166
- _context3.next = 8;
166
+ // const insertMouthLines = mouthLines(insertMouth);
167
+ _context3.t0 = monthLines;
168
+ _context3.next = 7;
167
169
  return cellSize();
168
- case 8:
170
+ case 7:
169
171
  _context3.t1 = _context3.sent;
170
172
  insertMouthHeight = _context3.t0 * _context3.t1;
171
173
  setTranslateY(translateY - insertMouthHeight);
172
174
  // waiting = false
173
- case 11:
175
+ case 10:
174
176
  case "end":
175
177
  return _context3.stop();
176
178
  }
@@ -186,13 +188,13 @@ export var TouchableCalendarGrid = /*#__PURE__*/memo(function (_ref) {
186
188
  // }
187
189
  // waiting = true
188
190
  var lastMouth = mouths[mouths.length - 1];
189
- var appendMouth = new Date(lastMouth.getFullYear(), lastMouth.getMonth() + 1, 1);
191
+ var appendMouth = lastMouth.add(1, 'month');
190
192
  var newMouths = [].concat(_toConsumableArray(mouths), [appendMouth]);
191
193
  setMouths(newMouths);
192
194
  // waiting = false
193
195
  };
194
196
  useEffect(function () {
195
- var initMouths = [new Date(currentMouth.getFullYear(), currentMouth.getMonth() - 1, 1), new Date(currentMouth.getFullYear(), currentMouth.getMonth(), 1), new Date(currentMouth.getFullYear(), currentMouth.getMonth() + 1, 1)];
197
+ var initMouths = [currentMonth.clone().subtract(1, 'month'), currentMonth.clone(), currentMonth.clone().add(1, 'month')];
196
198
  Promise.all([]).then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
197
199
  var firstMouthHeight;
198
200
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
@@ -200,14 +202,14 @@ export var TouchableCalendarGrid = /*#__PURE__*/memo(function (_ref) {
200
202
  case 0:
201
203
  setMouths(initMouths);
202
204
  _context4.t0 = setMouthHeight;
203
- _context4.t1 = mouthLines(currentMouth);
205
+ _context4.t1 = monthLines;
204
206
  _context4.next = 5;
205
207
  return cellSize();
206
208
  case 5:
207
209
  _context4.t2 = _context4.sent;
208
210
  _context4.t3 = _context4.t1 * _context4.t2;
209
211
  (0, _context4.t0)(_context4.t3);
210
- _context4.t4 = mouthLines(initMouths[0]);
212
+ _context4.t4 = monthLines;
211
213
  _context4.next = 11;
212
214
  return cellSize();
213
215
  case 11:
@@ -220,15 +222,15 @@ export var TouchableCalendarGrid = /*#__PURE__*/memo(function (_ref) {
220
222
  }
221
223
  }, _callee4);
222
224
  })));
223
- }, [currentMouth]);
225
+ }, [currentMonth]);
224
226
  useEffect(function () {
225
- if (mouth !== undefined) {
226
- var newMouth = new Date(mouth.getFullYear(), mouth.getMonth(), 1);
227
- if (currentMouth === null || !(currentMouth.getFullYear() === newMouth.getFullYear() && currentMouth.getMonth() === newMouth.getMonth())) {
228
- setCurrentMouth(newMouth);
227
+ if (month !== undefined) {
228
+ var newMouth = dayjs(new Date(month.year(), month.month(), 1));
229
+ if (currentMonth === null || !(currentMonth !== null && currentMonth !== void 0 && currentMonth.isSame(newMouth, 'month'))) {
230
+ setCurrentMonth(newMouth);
229
231
  }
230
232
  }
231
- }, [mouth]);
233
+ }, [month]);
232
234
  useEffect(function () {
233
235
  if (value !== undefined) {}
234
236
  }, [value]);
@@ -265,7 +267,7 @@ export var TouchableCalendarGrid = /*#__PURE__*/memo(function (_ref) {
265
267
  event.preventDefault();
266
268
  event.stopPropagation();
267
269
  if (!touching) {
268
- _context5.next = 33;
270
+ _context5.next = 30;
269
271
  break;
270
272
  }
271
273
  movePoint = {
@@ -291,38 +293,36 @@ export var TouchableCalendarGrid = /*#__PURE__*/memo(function (_ref) {
291
293
  }
292
294
  return _context5.abrupt("return");
293
295
  case 14:
294
- console.log('move', movePoint.clientY - touchPoint.clientY);
296
+ // console.log('move', movePoint.clientY - touchPoint.clientY);
295
297
  newTranslateY = translateY + (movePoint.clientY - touchPoint.clientY);
296
298
  setTranslateY(newTranslateY);
297
299
  setTouchPoint(movePoint);
298
300
  // console.log(newTranslateY,minTranslateY())
299
301
  if (!(newTranslateY > -10)) {
300
- _context5.next = 24;
302
+ _context5.next = 22;
301
303
  break;
302
304
  }
303
- //当向下滑动,顶部距离视窗顶部距离小于10,则插入上一个月份
304
- console.log('insert');
305
- _context5.next = 22;
305
+ _context5.next = 20;
306
306
  return handleInsertMouth();
307
- case 22:
308
- _context5.next = 33;
307
+ case 20:
308
+ _context5.next = 30;
309
309
  break;
310
- case 24:
310
+ case 22:
311
311
  _context5.t4 = newTranslateY;
312
- _context5.next = 27;
312
+ _context5.next = 25;
313
313
  return minTranslateY();
314
- case 27:
314
+ case 25:
315
315
  _context5.t5 = _context5.sent;
316
316
  _context5.t6 = 0 - _context5.t5;
317
317
  _context5.t7 = _context5.t6 + 10;
318
318
  if (!(_context5.t4 < _context5.t7)) {
319
- _context5.next = 33;
319
+ _context5.next = 30;
320
320
  break;
321
321
  }
322
322
  //当向下滑动,底部距离视窗底部距离小于10,则追加下一个月份
323
- console.log('append');
323
+ // console.log('append');
324
324
  handleAppendMouth();
325
- case 33:
325
+ case 30:
326
326
  case "end":
327
327
  return _context5.stop();
328
328
  }
@@ -351,66 +351,67 @@ export var TouchableCalendarGrid = /*#__PURE__*/memo(function (_ref) {
351
351
  i = 0;
352
352
  case 6:
353
353
  if (!(i < mouths.length)) {
354
- _context6.next = 40;
354
+ _context6.next = 28;
355
355
  break;
356
356
  }
357
- console.log('mouthHeight', mouthHeight);
358
- console.log('mouths[i]', mouths[i], i);
359
- _context6.t0 = mouthLines(mouths[i]);
360
- _context6.next = 12;
357
+ _context6.t0 = monthLines;
358
+ _context6.next = 10;
361
359
  return cellSize();
362
- case 12:
360
+ case 10:
363
361
  _context6.t1 = _context6.sent;
364
362
  _mouthHeight = _context6.t0 * _context6.t1;
365
363
  _mouthHeightSum += _mouthHeight;
366
- console.log('_mouthHeightSum', _mouthHeightSum);
367
- console.log('translateY', translateY);
364
+ // console.log('_mouthHeightSum', _mouthHeightSum);
365
+ // console.log('translateY', translateY);
368
366
  _topLineY = 0 - (_mouthHeightSum - _mouthHeight); //该月份区域顶部,对于顶点的偏移量
369
- console.log('_topLineY', _topLineY);
367
+ // console.log('_topLineY', _topLineY);
370
368
  if (!(_topLineY <= translateY && _topLineY >= translateY - mouthHeight)) {
371
- _context6.next = 27;
369
+ _context6.next = 19;
372
370
  break;
373
371
  }
374
372
  //该月份区域的顶部在视窗内
375
- console.log('top_in');
373
+ // console.log('top_in');
376
374
  _windowDisplayHeight = _mouthHeightSum - (0 - translateY); //该月份区域底部距离视窗顶部的距离
377
- console.log('_windowDisplayHeight——top', _windowDisplayHeight);
375
+ // console.log('_windowDisplayHeight——top', _windowDisplayHeight);
378
376
  if (!(_windowDisplayHeight >= mouthHeight / 2)) {
379
- _context6.next = 27;
377
+ _context6.next = 19;
380
378
  break;
381
379
  }
382
- console.log('displayMouth', mouths[i]);
380
+ // console.log('displayMouth', mouths[i]);
383
381
  displayMouth = mouths[i];
384
- return _context6.abrupt("break", 40);
385
- case 27:
382
+ return _context6.abrupt("break", 28);
383
+ case 19:
386
384
  _bottomLineY = 0 - _mouthHeightSum; //该月份区域底部,对于顶点的偏移量
387
- console.log('_bottomLineY', _bottomLineY);
385
+ // console.log('_bottomLineY', _bottomLineY);
388
386
  if (!(_bottomLineY <= translateY && _bottomLineY >= translateY - mouthHeight)) {
389
- _context6.next = 37;
387
+ _context6.next = 25;
390
388
  break;
391
389
  }
392
390
  //该月份区域的底部在视窗内
393
- console.log('bottom_in');
391
+ // console.log('bottom_in');
394
392
  _windowDisplayHeight2 = _mouthHeightSum - (0 - translateY); //该月份区域底部距离视窗顶部的距离
395
- console.log('_windowDisplayHeight-bottom', _windowDisplayHeight2);
393
+ // console.log(
394
+ // '_windowDisplayHeight-bottom',
395
+ // _windowDisplayHeight,
396
+ // );
396
397
  if (!(_windowDisplayHeight2 >= mouthHeight / 2)) {
397
- _context6.next = 37;
398
+ _context6.next = 25;
398
399
  break;
399
400
  }
400
- console.log('displayMouth', mouths[i]);
401
+ // console.log('displayMouth', mouths[i]);
401
402
  displayMouth = mouths[i];
402
- return _context6.abrupt("break", 40);
403
- case 37:
403
+ return _context6.abrupt("break", 28);
404
+ case 25:
404
405
  i++;
405
406
  _context6.next = 6;
406
407
  break;
407
- case 40:
408
+ case 28:
408
409
  //endregion
409
410
  if (displayMouth) {
410
- setCurrentMouth(displayMouth);
411
- onMouthChange === null || onMouthChange === void 0 || onMouthChange(displayMouth);
411
+ setCurrentMonth(displayMouth);
412
+ onMonthChange === null || onMonthChange === void 0 || onMonthChange(displayMouth);
412
413
  }
413
- case 41:
414
+ case 29:
414
415
  case "end":
415
416
  return _context6.stop();
416
417
  }
@@ -423,7 +424,7 @@ export var TouchableCalendarGrid = /*#__PURE__*/memo(function (_ref) {
423
424
  }, mouths.map(function (mouth, index) {
424
425
  return /*#__PURE__*/React.createElement(CalendarGrid, {
425
426
  key: index,
426
- mouth: mouth,
427
+ month: mouth,
427
428
  value: value,
428
429
  defaultValue: defaultValue,
429
430
  onChange: onChange,
@@ -1,10 +1,11 @@
1
1
  import { FC } from 'react';
2
2
  import './style.scss';
3
+ import dayjs from "dayjs";
3
4
  export type CalendarDatetimePickerProps = {
4
5
  placeholder?: string;
5
- value?: Date;
6
+ value?: dayjs.Dayjs | Date;
6
7
  format?: string;
7
- onChange?: (value?: Date) => void;
8
+ onChange?: (value?: dayjs.Dayjs) => void;
8
9
  align?: 'left' | 'right' | 'center';
9
10
  };
10
11
  export declare const CalendarDatetimePicker: FC<CalendarDatetimePickerProps>;
@@ -14,6 +14,7 @@ import "./style.scss";
14
14
  import { cls } from "./types";
15
15
  import CalendarDatetimePopup from "../CalendarDatetimePopup";
16
16
  import dayjs from "dayjs";
17
+ import { isSame } from "../utils/dayjs";
17
18
  export var CalendarDatetimePicker = function CalendarDatetimePicker(_ref) {
18
19
  var _ref$placeholder = _ref.placeholder,
19
20
  placeholder = _ref$placeholder === void 0 ? '请选择' : _ref$placeholder,
@@ -27,13 +28,13 @@ export var CalendarDatetimePicker = function CalendarDatetimePicker(_ref) {
27
28
  _React$useState2 = _slicedToArray(_React$useState, 2),
28
29
  innerOpen = _React$useState2[0],
29
30
  setInnerOpen = _React$useState2[1];
30
- var _useState = useState(value),
31
+ var _useState = useState(value ? dayjs(value) : undefined),
31
32
  _useState2 = _slicedToArray(_useState, 2),
32
33
  internalValue = _useState2[0],
33
34
  setInternalValue = _useState2[1];
34
35
  var handleValueRender = function handleValueRender() {
35
36
  if (internalValue) {
36
- return dayjs(internalValue).format(format);
37
+ return internalValue.format(format);
37
38
  }
38
39
  return null;
39
40
  };
@@ -41,13 +42,13 @@ export var CalendarDatetimePicker = function CalendarDatetimePicker(_ref) {
41
42
  if (value === undefined) {
42
43
  return;
43
44
  }
44
- if (value !== internalValue) {
45
- setInternalValue(value);
45
+ if (!isSame(value, internalValue)) {
46
+ setInternalValue(dayjs(value));
46
47
  }
47
48
  }, [value]);
48
49
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CalendarDatetimePopup, {
49
50
  open: innerOpen,
50
- value: internalValue,
51
+ value: internalValue || dayjs(),
51
52
  onClose: function onClose() {
52
53
  setInnerOpen(false);
53
54
  },
@@ -1,10 +1,11 @@
1
1
  import { FC } from 'react';
2
2
  import './style.scss';
3
+ import dayjs from "dayjs";
3
4
  export type CalendarDatetimePopupProps = {
4
5
  open?: boolean;
5
6
  afterOpenChange?: (open: boolean) => void;
6
- value?: Date;
7
- onOk?: (value?: Date) => void;
7
+ value?: dayjs.Dayjs | Date;
8
+ onOk?: (value?: dayjs.Dayjs) => void;
8
9
  onClose?: () => void;
9
10
  };
10
11
  export declare const CalendarDatetimePopup: FC<CalendarDatetimePopupProps>;
@@ -20,23 +20,22 @@ import { DateTimeSwitch } from "./DateTimeSwitch";
20
20
  import "./style.scss";
21
21
  import { cls, Mode } from "./types";
22
22
  import { DatetimeUtils } from "../utils/datetime-utils";
23
+ import dayjs from "dayjs";
23
24
  export var CalendarDatetimePopup = function CalendarDatetimePopup(_ref) {
24
- var _bodyRef$current;
25
25
  var open = _ref.open,
26
- afterOpenChange = _ref.afterOpenChange,
26
+ _afterOpenChange = _ref.afterOpenChange,
27
27
  value = _ref.value,
28
28
  onOk = _ref.onOk,
29
29
  _onClose = _ref.onClose;
30
30
  var _ConfigProvider$useCo = ConfigProvider.useConfig(),
31
31
  locale = _ConfigProvider$useCo.locale;
32
32
  var _useTaro = useTaro(),
33
- isTaroEnv = _useTaro.isTaroEnv,
34
33
  isTaroWeApp = _useTaro.isTaroWeApp;
35
34
  var _useState = useState(Mode.date),
36
35
  _useState2 = _slicedToArray(_useState, 2),
37
36
  mode = _useState2[0],
38
37
  setMode = _useState2[1];
39
- var valueRef = useRef(value || new Date());
38
+ var valueRef = useRef(dayjs(value));
40
39
  var bodyRef = useRef(null);
41
40
  var datetimeSwitchRef = useRef();
42
41
  var _useState3 = useState(300),
@@ -55,7 +54,7 @@ export var CalendarDatetimePopup = function CalendarDatetimePopup(_ref) {
55
54
  return _regeneratorRuntime().wrap(function _callee$(_context) {
56
55
  while (1) switch (_context.prev = _context.next) {
57
56
  case 0:
58
- if (!(isTaroEnv && isTaroWeApp)) {
57
+ if (!isTaroWeApp) {
59
58
  _context.next = 2;
60
59
  break;
61
60
  }
@@ -89,11 +88,11 @@ export var CalendarDatetimePopup = function CalendarDatetimePopup(_ref) {
89
88
  return /*#__PURE__*/React.createElement(React.Fragment, null, mode === Mode.date && /*#__PURE__*/React.createElement("div", {
90
89
  style: {}
91
90
  }, /*#__PURE__*/React.createElement(Calendar, {
92
- mouth: value,
91
+ month: value,
93
92
  value: value,
94
93
  onChange: function onChange(date) {
95
94
  var _datetimeSwitchRef$cu;
96
- valueRef.current = new Date(date.getFullYear(), date.getMonth(), date.getDate(), valueRef.current.getHours(), valueRef.current.getMinutes());
95
+ valueRef.current = dayjs(new Date(date.year(), date.month(), date.date(), valueRef.current.hour(), valueRef.current.minute()));
97
96
  (_datetimeSwitchRef$cu = datetimeSwitchRef.current) === null || _datetimeSwitchRef$cu === void 0 || _datetimeSwitchRef$cu.setDatetime(valueRef.current);
98
97
  }
99
98
  })), mode === Mode.time && /*#__PURE__*/React.createElement("div", {
@@ -106,11 +105,11 @@ export var CalendarDatetimePopup = function CalendarDatetimePopup(_ref) {
106
105
  style: {
107
106
  height: bodyHeight
108
107
  },
109
- value: [valueRef === null || valueRef === void 0 ? void 0 : valueRef.current.getHours(), valueRef === null || valueRef === void 0 ? void 0 : valueRef.current.getMinutes()],
108
+ value: [valueRef === null || valueRef === void 0 ? void 0 : valueRef.current.hour(), valueRef === null || valueRef === void 0 ? void 0 : valueRef.current.minute()],
110
109
  onChange: function onChange(e) {
111
110
  var _datetimeSwitchRef$cu2;
112
111
  var v = e.detail.value;
113
- valueRef.current = new Date(valueRef.current.getFullYear(), valueRef.current.getMonth(), valueRef.current.getDate(), v[0], v[1]);
112
+ valueRef.current = dayjs(new Date(valueRef.current.year(), valueRef.current.month(), valueRef.current.date(), v[0], v[1]));
114
113
  (_datetimeSwitchRef$cu2 = datetimeSwitchRef.current) === null || _datetimeSwitchRef$cu2 === void 0 || _datetimeSwitchRef$cu2.setDatetime(valueRef.current);
115
114
  }
116
115
  }, /*#__PURE__*/React.createElement(PickerViewColumn, null, Array(24).fill(0).map(function (_, i) {
@@ -128,6 +127,12 @@ export var CalendarDatetimePopup = function CalendarDatetimePopup(_ref) {
128
127
  return /*#__PURE__*/React.createElement(Popup, {
129
128
  open: open,
130
129
  round: true,
130
+ afterOpenChange: function afterOpenChange(o) {
131
+ if (!o) {
132
+ setMode(Mode.date);
133
+ }
134
+ _afterOpenChange === null || _afterOpenChange === void 0 || _afterOpenChange(o);
135
+ },
131
136
  onClose: function onClose() {
132
137
  _onClose === null || _onClose === void 0 || _onClose();
133
138
  }
@@ -151,13 +156,9 @@ export var CalendarDatetimePopup = function CalendarDatetimePopup(_ref) {
151
156
  }), /*#__PURE__*/React.createElement("a", {
152
157
  className: classNames("".concat(cls, "-header-button"), "".concat(cls, "-header-button-ok")),
153
158
  onClick: handleOk
154
- }, locale.common.confirm)), isTaroEnv ? /*#__PURE__*/React.createElement(CustomWrapper, {
159
+ }, locale.common.confirm)), /*#__PURE__*/React.createElement(CustomWrapper, {
155
160
  ref: bodyRef
156
161
  }, /*#__PURE__*/React.createElement("div", {
157
162
  className: "".concat(cls, "-body")
158
- }, bodyRender())) : /*#__PURE__*/React.createElement("div", {
159
- className: "".concat(cls, "-body"),
160
- ref: bodyRef,
161
- id: (_bodyRef$current = bodyRef.current) === null || _bodyRef$current === void 0 ? void 0 : _bodyRef$current.uid
162
- }, bodyRender())));
163
+ }, bodyRender()))));
163
164
  };
@@ -1,14 +1,15 @@
1
1
  import React from 'react';
2
2
  import './style.scss';
3
3
  import { Mode } from './types';
4
+ import dayjs from "dayjs";
4
5
  export interface DateTimeSwitchHandle {
5
- setDatetime: (datetime: Date) => void;
6
+ setDatetime: (datetime: dayjs.Dayjs) => void;
6
7
  }
7
8
  type DateTimeSwitchProps = {
8
9
  onDateTabTap?: () => void;
9
10
  onTimeTabTap?: () => void;
10
11
  mode?: Mode;
11
- value?: Date;
12
+ value?: dayjs.Dayjs;
12
13
  };
13
14
  export declare const DateTimeSwitch: React.ForwardRefExoticComponent<DateTimeSwitchProps & React.RefAttributes<DateTimeSwitchHandle>>;
14
15
  export {};
@@ -32,8 +32,8 @@ export var DateTimeSwitch = /*#__PURE__*/forwardRef(function (_ref, ref) {
32
32
  }, /*#__PURE__*/React.createElement("div", {
33
33
  className: classNames("".concat(cls, "-header-display-date"), _defineProperty({}, "".concat(cls, "-header-display-active"), mode === Mode.date)),
34
34
  onClick: onDateTabTap
35
- }, datetime ? "".concat(datetime.getFullYear(), "-").concat(DatetimeUtils.twoDigits(datetime.getMonth() + 1), "-").concat(DatetimeUtils.twoDigits(datetime.getDate())) : ''), /*#__PURE__*/React.createElement("div", {
35
+ }, datetime ? "".concat(datetime.year(), "-").concat(DatetimeUtils.twoDigits(datetime.month() + 1), "-").concat(DatetimeUtils.twoDigits(datetime.date())) : ''), /*#__PURE__*/React.createElement("div", {
36
36
  className: classNames("".concat(cls, "-header-display-time"), _defineProperty({}, "".concat(cls, "-header-display-active"), mode === Mode.time)),
37
37
  onClick: onTimeTabTap
38
- }, datetime ? "".concat(DatetimeUtils.twoDigits(datetime.getHours()), ":").concat(DatetimeUtils.twoDigits(datetime.getMinutes())) : ''));
38
+ }, datetime ? "".concat(DatetimeUtils.twoDigits(datetime.hour()), ":").concat(DatetimeUtils.twoDigits(datetime.minute())) : ''));
39
39
  });
@@ -11,13 +11,14 @@ import ConfigProvider from "../ConfigProvider";
11
11
  import Popup from "../Popup";
12
12
  import "./style.scss";
13
13
  import { cls } from "./types";
14
+ import dayjs from "dayjs";
14
15
  export var CalendarPopup = /*#__PURE__*/memo(function (_ref) {
15
- var mouth = _ref.mouth,
16
+ var month = _ref.month,
16
17
  open = _ref.open,
17
18
  title = _ref.title,
18
19
  afterOpenChange = _ref.afterOpenChange,
19
20
  _ref$value = _ref.value,
20
- value = _ref$value === void 0 ? new Date() : _ref$value,
21
+ value = _ref$value === void 0 ? dayjs() : _ref$value,
21
22
  onOk = _ref.onOk,
22
23
  onCancel = _ref.onCancel,
23
24
  _onClose = _ref.onClose;
@@ -81,7 +82,7 @@ export var CalendarPopup = /*#__PURE__*/memo(function (_ref) {
81
82
  }, locale.common.confirm)), /*#__PURE__*/React.createElement("div", {
82
83
  className: classNames("".concat(cls, "-body"))
83
84
  }, /*#__PURE__*/React.createElement(Calendar, {
84
- mouth: mouth,
85
+ month: month,
85
86
  value: value,
86
87
  onChange: function onChange(date) {
87
88
  valueRef.current = date;
@@ -12,7 +12,7 @@ import "./style.scss";
12
12
  import { cls } from "./types";
13
13
  import ConfigProvider from "../ConfigProvider";
14
14
  export var CalendarRangePopup = /*#__PURE__*/memo(function (_ref) {
15
- var mouth = _ref.mouth,
15
+ var month = _ref.month,
16
16
  open = _ref.open,
17
17
  title = _ref.title,
18
18
  afterOpenChange = _ref.afterOpenChange,
@@ -80,7 +80,7 @@ export var CalendarRangePopup = /*#__PURE__*/memo(function (_ref) {
80
80
  }, locale.common.confirm)), /*#__PURE__*/React.createElement("div", {
81
81
  className: classNames("".concat(cls, "-body"))
82
82
  }, /*#__PURE__*/React.createElement(Calendar.Range, {
83
- mouth: mouth,
83
+ month: month,
84
84
  value: value,
85
85
  onChange: function onChange(date) {
86
86
  valueRef.current = date;
@@ -1,22 +1,23 @@
1
1
  import React from "react";
2
+ import dayjs from "dayjs";
2
3
  export declare const cls = "triones-antm-calendar-popup";
3
4
  export type CalendarPopupProps = {
4
- mouth?: Date;
5
+ month?: dayjs.Dayjs;
5
6
  open?: boolean;
6
7
  title?: React.ReactNode;
7
8
  afterOpenChange?: (open: boolean) => void;
8
- value?: Date;
9
- onOk?: (value?: Date) => void;
9
+ value?: dayjs.Dayjs;
10
+ onOk?: (value?: dayjs.Dayjs) => void;
10
11
  onCancel?: () => void;
11
12
  onClose?: () => void;
12
13
  };
13
14
  export type CalendarPopupRangeProps = {
14
- mouth?: Date;
15
+ month?: dayjs.Dayjs;
15
16
  open?: boolean;
16
17
  title?: React.ReactNode;
17
18
  afterOpenChange?: (open: boolean) => void;
18
- value?: Date[];
19
- onOk?: (value?: Date[]) => void;
19
+ value?: dayjs.Dayjs[];
20
+ onOk?: (value?: dayjs.Dayjs[]) => void;
20
21
  onCancel?: () => void;
21
22
  onClose?: () => void;
22
23
  };
@@ -5,7 +5,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
5
5
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import classNames from 'classnames';
8
- import React, { useState } from 'react';
8
+ import { size } from 'lodash-es';
9
+ import React, { useEffect, useState } from 'react';
9
10
  import ConfigProvider from "../ConfigProvider";
10
11
  import PickerView from "../PickerView";
11
12
  import Popup from "../Popup";
@@ -15,7 +16,8 @@ export var Picker = /*#__PURE__*/React.memo(function (_ref) {
15
16
  var open = _ref.open,
16
17
  afterOpenChange = _ref.afterOpenChange,
17
18
  title = _ref.title,
18
- columns = _ref.columns,
19
+ _ref$columns = _ref.columns,
20
+ columns = _ref$columns === void 0 ? [] : _ref$columns,
19
21
  _ref$labelInValue = _ref.labelInValue,
20
22
  labelInValue = _ref$labelInValue === void 0 ? false : _ref$labelInValue,
21
23
  value = _ref.value,
@@ -24,7 +26,7 @@ export var Picker = /*#__PURE__*/React.memo(function (_ref) {
24
26
  onClose = _ref.onClose;
25
27
  var _ConfigProvider$useCo = ConfigProvider.useConfig(),
26
28
  locale = _ConfigProvider$useCo.locale;
27
- var _useState = useState([]),
29
+ var _useState = useState(value || []),
28
30
  _useState2 = _slicedToArray(_useState, 2),
29
31
  internalValue = _useState2[0],
30
32
  setInternalValue = _useState2[1];
@@ -39,6 +41,30 @@ export var Picker = /*#__PURE__*/React.memo(function (_ref) {
39
41
  onCancel === null || onCancel === void 0 || onCancel();
40
42
  handleClose();
41
43
  };
44
+ useEffect(function () {
45
+ if (!value || size(value) === 0 || size(value) !== size(columns)) {
46
+ if (labelInValue) {
47
+ setInternalValue(columns.map(function (column, index) {
48
+ if (index < size(value)) {
49
+ return column.find(function (option) {
50
+ return option.value === value[index].value;
51
+ });
52
+ }
53
+ return column[0];
54
+ }));
55
+ } else {
56
+ setInternalValue(columns.map(function (column, index) {
57
+ if (index < size(value)) {
58
+ var _column$find;
59
+ return (_column$find = column.find(function (option) {
60
+ return option.value === value[index];
61
+ })) === null || _column$find === void 0 ? void 0 : _column$find.value;
62
+ }
63
+ return column[0].value;
64
+ }));
65
+ }
66
+ }
67
+ }, [columns]);
42
68
  return /*#__PURE__*/React.createElement(Popup, {
43
69
  open: open,
44
70
  onClose: function onClose() {
@@ -55,7 +81,7 @@ export var Picker = /*#__PURE__*/React.memo(function (_ref) {
55
81
  }, /*#__PURE__*/React.createElement("div", {
56
82
  className: classNames("".concat(pickerCls, "-header"))
57
83
  }, /*#__PURE__*/React.createElement("a", {
58
- className: classNames("".concat(pickerCls, "-header-button")),
84
+ className: classNames("".concat(pickerCls, "-header-button"), "".concat(pickerCls, "-header-button-cancel")),
59
85
  onClick: handelCancel
60
86
  }, locale.common.cancel), title && /*#__PURE__*/React.createElement("div", {
61
87
  className: classNames("".concat(pickerCls, "-header-title"))
@@ -0,0 +1,3 @@
1
+ import dayjs, { OpUnitType } from "dayjs";
2
+ export declare const toDayjsArray: (dateArr?: Date[] | dayjs.Dayjs[]) => dayjs.Dayjs[] | undefined;
3
+ export declare const isSame: (x?: dayjs.Dayjs | Date, y?: dayjs.Dayjs | Date, unit?: OpUnitType) => boolean;
@@ -0,0 +1,29 @@
1
+ import dayjs from "dayjs";
2
+ import { isEmpty, isNil } from "lodash-es";
3
+ export var toDayjsArray = function toDayjsArray(dateArr) {
4
+ if (isNil(dateArr)) {
5
+ return dateArr;
6
+ }
7
+ if (isEmpty(dateArr)) {
8
+ return [];
9
+ }
10
+ return dateArr === null || dateArr === void 0 ? void 0 : dateArr.map(function (date) {
11
+ if (isNil(date)) {
12
+ return date;
13
+ } else {
14
+ return dayjs(date);
15
+ }
16
+ });
17
+ };
18
+ export var isSame = function isSame(x, y, unit) {
19
+ if (isNil(x) && isNil(y)) {
20
+ return true;
21
+ } else if (isNil(x) && !isNil(y)) {
22
+ return false;
23
+ } else if (!isNil(x) && isNil(y)) {
24
+ return false;
25
+ } else {
26
+ var _dayjs;
27
+ return Boolean((_dayjs = dayjs(x)) === null || _dayjs === void 0 ? void 0 : _dayjs.isSame(y, unit));
28
+ }
29
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trionesdev/antd-taro-react",
3
- "version": "0.0.2-beta.10",
3
+ "version": "0.0.2-beta.12",
4
4
  "description": "antd taro react",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@tarojs/components": "^4.1.8",
59
- "@trionesdev/antd-mobile-base-react": "^0.0.2-beta.10",
59
+ "@trionesdev/antd-mobile-base-react": "^0.0.2-beta.12",
60
60
  "crypto-js": "^4.2.0",
61
61
  "dayjs": "^1.11.19",
62
62
  "rc-field-form": "^2.7.0",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "optionalDependencies": {
66
66
  "@trionesdev/antd-mobile-base-react": "workspace:*",
67
- "@trionesdev/antd-mobile-icons-react": "0.0.2-beta.9"
67
+ "@trionesdev/antd-mobile-icons-react": "0.0.2-beta.10"
68
68
  },
69
- "gitHead": "c062f3bd8651ea933f9385279c05a1ab0245b2b8"
69
+ "gitHead": "ac56b7bd2ded2ad9bf30daeb7d9f52b8a43745a6"
70
70
  }