@megafon/ui-core 7.4.1 → 7.5.0

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.
@@ -19,7 +19,7 @@ var __rest = this && this.__rest || function (s, e) {
19
19
  return t;
20
20
  };
21
21
  import * as React from 'react';
22
- import { START_DATE, END_DATE, useDatepicker, useMonth } from '@datepicker-react/hooks';
22
+ import { START_DATE, END_DATE, useDatepicker } from '@datepicker-react/hooks';
23
23
  import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
24
24
  import { addMonths, subMonths } from 'date-fns';
25
25
  import differenceInDays from 'date-fns/differenceInDays';
@@ -47,15 +47,6 @@ export var CalendarDirectionTypes = {
47
47
  FUTURE: 'future',
48
48
  BOTH: 'both'
49
49
  };
50
- var weekdayLabelFormat = function weekdayLabelFormat(date) {
51
- return formatDate(date, 'EEEEEE');
52
- };
53
- var dayLabelFormat = function dayLabelFormat(date) {
54
- return formatDate(date, 'd');
55
- };
56
- var monthLabelFormat = function monthLabelFormat(date) {
57
- return formatDate(date, 'LLLL');
58
- };
59
50
  var generateMonthsData = function generateMonthsData(pastMonthsCount, futureMonthsCount, direction) {
60
51
  var months = [];
61
52
  var currentDate = new Date();
@@ -303,18 +294,6 @@ var Calendar = function Calendar(_ref) {
303
294
  return monthsArray.map(function (_ref2) {
304
295
  var month = _ref2.month,
305
296
  year = _ref2.year;
306
- // eslint-disable-next-line react-hooks/rules-of-hooks
307
- var _useMonth = useMonth({
308
- year: year,
309
- month: month,
310
- firstDayOfWeek: firstDayOfWeek,
311
- dayLabelFormat: dayLabelFormat,
312
- weekdayLabelFormat: weekdayLabelFormat,
313
- monthLabelFormat: monthLabelFormat
314
- }),
315
- days = _useMonth.days,
316
- weekdayLabels = _useMonth.weekdayLabels,
317
- monthLabel = _useMonth.monthLabel;
318
297
  var isPrevMonthDisabled = !!minBookingDate && isSameMonth(new Date(year, month, 1), minBookingDate);
319
298
  var isNextMonthDisabled = !!maxBookingDate && isSameMonth(new Date(year, month, 1), maxBookingDate);
320
299
  var isCurrentMonth = new Date().getFullYear() === year && new Date().getMonth() === month;
@@ -328,14 +307,15 @@ var Calendar = function Calendar(_ref) {
328
307
  arrowRight: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.arrowRight
329
308
  },
330
309
  year: year,
331
- weekdayLabels: weekdayLabels,
332
- monthLabel: monthLabel,
310
+ month: month,
311
+ firstDayOfWeek: firstDayOfWeek,
333
312
  isPrevMonthDisabled: isModernType || isPrevMonthDisabled,
334
313
  isNextMonthDisabled: isModernType || isNextMonthDisabled,
335
314
  goToPreviousMonth: goToPreviousMonths,
336
315
  goToNextMonth: goToNextMonths,
337
- isModern: isModernType
338
- }, renderDays(days)));
316
+ isModern: isModernType,
317
+ renderDays: renderDays
318
+ }));
339
319
  });
340
320
  };
341
321
  return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { FirstDayOfWeek, MonthType } from '@datepicker-react/hooks';
2
+ import { FirstDayOfWeek, MonthType, UseMonthResult } from '@datepicker-react/hooks';
3
3
  import './Month.scss';
4
4
  export interface IMonthPickerProps {
5
5
  firstDayOfWeek: FirstDayOfWeek;
@@ -16,12 +16,12 @@ export interface IMonthProps {
16
16
  isPrevMonthDisabled: boolean;
17
17
  isNextMonthDisabled: boolean;
18
18
  year: number;
19
- monthLabel: string;
20
- weekdayLabels: string[];
19
+ month: number;
20
+ firstDayOfWeek?: FirstDayOfWeek;
21
21
  goToPreviousMonth: () => void;
22
22
  goToNextMonth: () => void;
23
23
  isModern?: boolean;
24
- children?: React.ReactNode;
24
+ renderDays: (days: UseMonthResult['days']) => React.ReactNode;
25
25
  }
26
26
  declare const Month: React.FC<IMonthProps>;
27
27
  export default Month;
@@ -2,7 +2,10 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import "core-js/modules/es.array.concat.js";
3
3
  import "core-js/modules/es.array.map.js";
4
4
  import * as React from 'react';
5
+ import { useMonth } from '@datepicker-react/hooks';
5
6
  import { checkEventIsClickOrEnterPress, cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
7
+ import format from 'date-fns/format';
8
+ import ruLocale from 'date-fns/locale/ru';
6
9
  import "./Month.css";
7
10
  var ArrowLeft = function ArrowLeft(props) {
8
11
  return /*#__PURE__*/React.createElement("svg", _extends({
@@ -22,19 +25,45 @@ var ArrowRight = function ArrowRight(props) {
22
25
  clipRule: "evenodd"
23
26
  }));
24
27
  };
28
+ var formatDate = function formatDate(date, pattern) {
29
+ var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ruLocale;
30
+ return format(date, pattern, {
31
+ locale: locale
32
+ });
33
+ };
34
+ var weekdayLabelFormat = function weekdayLabelFormat(date) {
35
+ return formatDate(date, 'EEEEEE');
36
+ };
37
+ var dayLabelFormat = function dayLabelFormat(date) {
38
+ return formatDate(date, 'd');
39
+ };
40
+ var monthLabelFormat = function monthLabelFormat(date) {
41
+ return formatDate(date, 'LLLL');
42
+ };
25
43
  var cn = cnCreate('mfui-month');
26
44
  var Month = function Month(_ref) {
27
45
  var dataAttrs = _ref.dataAttrs,
28
46
  isPrevMonthDisabled = _ref.isPrevMonthDisabled,
29
47
  isNextMonthDisabled = _ref.isNextMonthDisabled,
30
48
  year = _ref.year,
31
- monthLabel = _ref.monthLabel,
32
- weekdayLabels = _ref.weekdayLabels,
49
+ month = _ref.month,
50
+ firstDayOfWeek = _ref.firstDayOfWeek,
33
51
  goToPreviousMonth = _ref.goToPreviousMonth,
34
52
  goToNextMonth = _ref.goToNextMonth,
35
53
  _ref$isModern = _ref.isModern,
36
54
  isModern = _ref$isModern === void 0 ? false : _ref$isModern,
37
- children = _ref.children;
55
+ renderDays = _ref.renderDays;
56
+ var _useMonth = useMonth({
57
+ year: year,
58
+ month: month,
59
+ firstDayOfWeek: firstDayOfWeek,
60
+ dayLabelFormat: dayLabelFormat,
61
+ weekdayLabelFormat: weekdayLabelFormat,
62
+ monthLabelFormat: monthLabelFormat
63
+ }),
64
+ days = _useMonth.days,
65
+ weekdayLabels = _useMonth.weekdayLabels,
66
+ monthLabel = _useMonth.monthLabel;
38
67
  var handleArrowLeftClick = function handleArrowLeftClick(e) {
39
68
  if (checkEventIsClickOrEnterPress(e)) {
40
69
  !isPrevMonthDisabled && goToPreviousMonth();
@@ -83,6 +112,6 @@ var Month = function Month(_ref) {
83
112
  }, dayLabel);
84
113
  })), /*#__PURE__*/React.createElement("div", {
85
114
  className: cn('days')
86
- }, children));
115
+ }, renderDays(days)));
87
116
  };
88
117
  export default Month;
@@ -56,15 +56,6 @@ var CalendarDirectionTypes = exports.CalendarDirectionTypes = {
56
56
  FUTURE: 'future',
57
57
  BOTH: 'both'
58
58
  };
59
- var weekdayLabelFormat = function weekdayLabelFormat(date) {
60
- return formatDate(date, 'EEEEEE');
61
- };
62
- var dayLabelFormat = function dayLabelFormat(date) {
63
- return formatDate(date, 'd');
64
- };
65
- var monthLabelFormat = function monthLabelFormat(date) {
66
- return formatDate(date, 'LLLL');
67
- };
68
59
  var generateMonthsData = function generateMonthsData(pastMonthsCount, futureMonthsCount, direction) {
69
60
  var months = [];
70
61
  var currentDate = new Date();
@@ -312,18 +303,6 @@ var Calendar = function Calendar(_ref) {
312
303
  return monthsArray.map(function (_ref2) {
313
304
  var month = _ref2.month,
314
305
  year = _ref2.year;
315
- // eslint-disable-next-line react-hooks/rules-of-hooks
316
- var _useMonth = (0, _hooks.useMonth)({
317
- year: year,
318
- month: month,
319
- firstDayOfWeek: firstDayOfWeek,
320
- dayLabelFormat: dayLabelFormat,
321
- weekdayLabelFormat: weekdayLabelFormat,
322
- monthLabelFormat: monthLabelFormat
323
- }),
324
- days = _useMonth.days,
325
- weekdayLabels = _useMonth.weekdayLabels,
326
- monthLabel = _useMonth.monthLabel;
327
306
  var isPrevMonthDisabled = !!minBookingDate && (0, _isSameMonth["default"])(new Date(year, month, 1), minBookingDate);
328
307
  var isNextMonthDisabled = !!maxBookingDate && (0, _isSameMonth["default"])(new Date(year, month, 1), maxBookingDate);
329
308
  var isCurrentMonth = new Date().getFullYear() === year && new Date().getMonth() === month;
@@ -337,14 +316,15 @@ var Calendar = function Calendar(_ref) {
337
316
  arrowRight: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.arrowRight
338
317
  },
339
318
  year: year,
340
- weekdayLabels: weekdayLabels,
341
- monthLabel: monthLabel,
319
+ month: month,
320
+ firstDayOfWeek: firstDayOfWeek,
342
321
  isPrevMonthDisabled: isModernType || isPrevMonthDisabled,
343
322
  isNextMonthDisabled: isModernType || isNextMonthDisabled,
344
323
  goToPreviousMonth: goToPreviousMonths,
345
324
  goToNextMonth: goToNextMonths,
346
- isModern: isModernType
347
- }, renderDays(days)));
325
+ isModern: isModernType,
326
+ renderDays: renderDays
327
+ }));
348
328
  });
349
329
  };
350
330
  return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { FirstDayOfWeek, MonthType } from '@datepicker-react/hooks';
2
+ import { FirstDayOfWeek, MonthType, UseMonthResult } from '@datepicker-react/hooks';
3
3
  import './Month.scss';
4
4
  export interface IMonthPickerProps {
5
5
  firstDayOfWeek: FirstDayOfWeek;
@@ -16,12 +16,12 @@ export interface IMonthProps {
16
16
  isPrevMonthDisabled: boolean;
17
17
  isNextMonthDisabled: boolean;
18
18
  year: number;
19
- monthLabel: string;
20
- weekdayLabels: string[];
19
+ month: number;
20
+ firstDayOfWeek?: FirstDayOfWeek;
21
21
  goToPreviousMonth: () => void;
22
22
  goToNextMonth: () => void;
23
23
  isModern?: boolean;
24
- children?: React.ReactNode;
24
+ renderDays: (days: UseMonthResult['days']) => React.ReactNode;
25
25
  }
26
26
  declare const Month: React.FC<IMonthProps>;
27
27
  export default Month;
@@ -9,7 +9,10 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
  require("core-js/modules/es.array.concat.js");
10
10
  require("core-js/modules/es.array.map.js");
11
11
  var React = _interopRequireWildcard(require("react"));
12
+ var _hooks = require("@datepicker-react/hooks");
12
13
  var _uiHelpers = require("@megafon/ui-helpers");
14
+ var _format = _interopRequireDefault(require("date-fns/format"));
15
+ var _ru = _interopRequireDefault(require("date-fns/locale/ru"));
13
16
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
14
17
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
15
18
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
@@ -31,19 +34,45 @@ var ArrowRight = function ArrowRight(props) {
31
34
  clipRule: "evenodd"
32
35
  }));
33
36
  };
37
+ var formatDate = function formatDate(date, pattern) {
38
+ var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ru["default"];
39
+ return (0, _format["default"])(date, pattern, {
40
+ locale: locale
41
+ });
42
+ };
43
+ var weekdayLabelFormat = function weekdayLabelFormat(date) {
44
+ return formatDate(date, 'EEEEEE');
45
+ };
46
+ var dayLabelFormat = function dayLabelFormat(date) {
47
+ return formatDate(date, 'd');
48
+ };
49
+ var monthLabelFormat = function monthLabelFormat(date) {
50
+ return formatDate(date, 'LLLL');
51
+ };
34
52
  var cn = (0, _uiHelpers.cnCreate)('mfui-month');
35
53
  var Month = function Month(_ref) {
36
54
  var dataAttrs = _ref.dataAttrs,
37
55
  isPrevMonthDisabled = _ref.isPrevMonthDisabled,
38
56
  isNextMonthDisabled = _ref.isNextMonthDisabled,
39
57
  year = _ref.year,
40
- monthLabel = _ref.monthLabel,
41
- weekdayLabels = _ref.weekdayLabels,
58
+ month = _ref.month,
59
+ firstDayOfWeek = _ref.firstDayOfWeek,
42
60
  goToPreviousMonth = _ref.goToPreviousMonth,
43
61
  goToNextMonth = _ref.goToNextMonth,
44
62
  _ref$isModern = _ref.isModern,
45
63
  isModern = _ref$isModern === void 0 ? false : _ref$isModern,
46
- children = _ref.children;
64
+ renderDays = _ref.renderDays;
65
+ var _useMonth = (0, _hooks.useMonth)({
66
+ year: year,
67
+ month: month,
68
+ firstDayOfWeek: firstDayOfWeek,
69
+ dayLabelFormat: dayLabelFormat,
70
+ weekdayLabelFormat: weekdayLabelFormat,
71
+ monthLabelFormat: monthLabelFormat
72
+ }),
73
+ days = _useMonth.days,
74
+ weekdayLabels = _useMonth.weekdayLabels,
75
+ monthLabel = _useMonth.monthLabel;
47
76
  var handleArrowLeftClick = function handleArrowLeftClick(e) {
48
77
  if ((0, _uiHelpers.checkEventIsClickOrEnterPress)(e)) {
49
78
  !isPrevMonthDisabled && goToPreviousMonth();
@@ -92,6 +121,6 @@ var Month = function Month(_ref) {
92
121
  }, dayLabel);
93
122
  })), /*#__PURE__*/React.createElement("div", {
94
123
  className: cn('days')
95
- }, children));
124
+ }, renderDays(days)));
96
125
  };
97
126
  var _default = exports["default"] = Month;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megafon/ui-core",
3
- "version": "7.4.1",
3
+ "version": "7.5.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "styles"
@@ -50,7 +50,7 @@
50
50
  "@babel/preset-env": "^7.8.6",
51
51
  "@babel/preset-react": "^7.8.3",
52
52
  "@babel/preset-typescript": "^7.8.3",
53
- "@megafon/ui-icons": "^3.3.0",
53
+ "@megafon/ui-icons": "^3.4.0",
54
54
  "@svgr/core": "^2.4.1",
55
55
  "@testing-library/jest-dom": "^6.5.0",
56
56
  "@testing-library/react": "^16.0.1",
@@ -104,5 +104,5 @@
104
104
  "simplebar-react": "^3.2.5",
105
105
  "swiper": "^11.1.1"
106
106
  },
107
- "gitHead": "0e2e21bc1f63599d5c0c1c606178422e1d70e787"
107
+ "gitHead": "2254ae9321758f64bbf0756457946865b494cedb"
108
108
  }