@primer/components 0.0.0-20219253356 → 0.0.0-20219254849

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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @primer/components
2
2
 
3
- ## 0.0.0-20219253356
3
+ ## 0.0.0-20219254849
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -23,6 +23,8 @@ const DatePicker = ({
23
23
  confirmation,
24
24
  focusTrapSettings,
25
25
  focusZoneSettings,
26
+ maxDate,
27
+ minDate,
26
28
  onOpen: onOpenExternal,
27
29
  onClose: onCloseExternal,
28
30
  open,
@@ -37,6 +39,8 @@ const DatePicker = ({
37
39
  const datePickerConfiguration = {
38
40
  anchorVariant,
39
41
  confirmation,
42
+ maxDate,
43
+ minDate,
40
44
  selection,
41
45
  view
42
46
  };
@@ -7,7 +7,7 @@ exports.DatePickerPanel = void 0;
7
7
 
8
8
  var _dateFns = require("date-fns");
9
9
 
10
- var _react = _interopRequireDefault(require("react"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
11
 
12
12
  var _Box = _interopRequireDefault(require("../Box"));
13
13
 
@@ -25,12 +25,12 @@ var _StyledOcticon = _interopRequireDefault(require("../StyledOcticon"));
25
25
 
26
26
  var _Button = _interopRequireWildcard(require("../Button"));
27
27
 
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+
28
30
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
31
 
30
32
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
33
 
32
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
-
34
34
  const DatePickerPanelContainer = (0, _styledComponents.default)(_Box.default).withConfig({
35
35
  displayName: "DatePickerPanel__DatePickerPanelContainer",
36
36
  componentId: "sc-19upxpo-0"
@@ -58,10 +58,38 @@ const DatePickerPanel = () => {
58
58
  nextMonth,
59
59
  previousMonth
60
60
  } = (0, _useDatePicker.default)();
61
+ const previousDisabled = (0, _react.useMemo)(() => {
62
+ const {
63
+ minDate
64
+ } = configuration;
65
+ if (!minDate) return false;
66
+ const previous = (0, _dateFns.subMonths)(currentViewingDate, 1);
67
+
68
+ if (minDate.getFullYear() >= previous.getFullYear() && minDate.getMonth() > previous.getMonth()) {
69
+ return true;
70
+ }
71
+
72
+ return false;
73
+ }, [configuration, currentViewingDate]);
74
+ const nextDisabled = (0, _react.useMemo)(() => {
75
+ const {
76
+ maxDate,
77
+ view
78
+ } = configuration;
79
+ if (!maxDate) return false;
80
+ const next = (0, _dateFns.addMonths)(currentViewingDate, view === '2-month' ? 2 : 1);
81
+
82
+ if (maxDate.getFullYear() <= next.getFullYear() && maxDate.getMonth() < next.getMonth()) {
83
+ return true;
84
+ }
85
+
86
+ return false;
87
+ }, [configuration, currentViewingDate]);
61
88
  return /*#__PURE__*/_react.default.createElement(DatePickerPanelContainer, null, /*#__PURE__*/_react.default.createElement(DatePickerPanelMonths, null, /*#__PURE__*/_react.default.createElement(ArrowButton, {
62
89
  variant: "small",
63
90
  side: "left",
64
- onClick: previousMonth
91
+ onClick: previousMonth,
92
+ disabled: previousDisabled
65
93
  }, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
66
94
  icon: _octiconsReact.ChevronLeftIcon,
67
95
  color: "fg.muted"
@@ -74,7 +102,8 @@ const DatePickerPanel = () => {
74
102
  }), /*#__PURE__*/_react.default.createElement(ArrowButton, {
75
103
  variant: "small",
76
104
  side: "right",
77
- onClick: nextMonth
105
+ onClick: nextMonth,
106
+ disabled: nextDisabled
78
107
  }, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
79
108
  icon: _octiconsReact.ChevronRightIcon,
80
109
  color: "fg.muted"
@@ -8,6 +8,8 @@ export const DatePicker = ({
8
8
  confirmation,
9
9
  focusTrapSettings,
10
10
  focusZoneSettings,
11
+ maxDate,
12
+ minDate,
11
13
  onOpen: onOpenExternal,
12
14
  onClose: onCloseExternal,
13
15
  open,
@@ -22,6 +24,8 @@ export const DatePicker = ({
22
24
  const datePickerConfiguration = {
23
25
  anchorVariant,
24
26
  confirmation,
27
+ maxDate,
28
+ minDate,
25
29
  selection,
26
30
  view
27
31
  };
@@ -1,5 +1,5 @@
1
- import { addMonths } from 'date-fns';
2
- import React from 'react';
1
+ import { addMonths, subMonths } from 'date-fns';
2
+ import React, { useMemo } from 'react';
3
3
  import Box from '../Box';
4
4
  import { Month } from './Month';
5
5
  import styled from 'styled-components';
@@ -34,10 +34,38 @@ export const DatePickerPanel = () => {
34
34
  nextMonth,
35
35
  previousMonth
36
36
  } = useDatePicker();
37
+ const previousDisabled = useMemo(() => {
38
+ const {
39
+ minDate
40
+ } = configuration;
41
+ if (!minDate) return false;
42
+ const previous = subMonths(currentViewingDate, 1);
43
+
44
+ if (minDate.getFullYear() >= previous.getFullYear() && minDate.getMonth() > previous.getMonth()) {
45
+ return true;
46
+ }
47
+
48
+ return false;
49
+ }, [configuration, currentViewingDate]);
50
+ const nextDisabled = useMemo(() => {
51
+ const {
52
+ maxDate,
53
+ view
54
+ } = configuration;
55
+ if (!maxDate) return false;
56
+ const next = addMonths(currentViewingDate, view === '2-month' ? 2 : 1);
57
+
58
+ if (maxDate.getFullYear() <= next.getFullYear() && maxDate.getMonth() < next.getMonth()) {
59
+ return true;
60
+ }
61
+
62
+ return false;
63
+ }, [configuration, currentViewingDate]);
37
64
  return /*#__PURE__*/React.createElement(DatePickerPanelContainer, null, /*#__PURE__*/React.createElement(DatePickerPanelMonths, null, /*#__PURE__*/React.createElement(ArrowButton, {
38
65
  variant: "small",
39
66
  side: "left",
40
- onClick: previousMonth
67
+ onClick: previousMonth,
68
+ disabled: previousDisabled
41
69
  }, /*#__PURE__*/React.createElement(StyledOcticon, {
42
70
  icon: ChevronLeftIcon,
43
71
  color: "fg.muted"
@@ -50,7 +78,8 @@ export const DatePickerPanel = () => {
50
78
  }), /*#__PURE__*/React.createElement(ArrowButton, {
51
79
  variant: "small",
52
80
  side: "right",
53
- onClick: nextMonth
81
+ onClick: nextMonth,
82
+ disabled: nextDisabled
54
83
  }, /*#__PURE__*/React.createElement(StyledOcticon, {
55
84
  icon: ChevronRightIcon,
56
85
  color: "fg.muted"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-20219253356",
3
+ "version": "0.0.0-20219254849",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",