@primer/components 0.0.0-2021922204627 → 0.0.0-202192422618

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-2021922204627
3
+ ## 0.0.0-202192422618
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -20,6 +20,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
20
20
  const DatePicker = ({
21
21
  anchorVariant,
22
22
  anchorRef: externalAnchorRef,
23
+ confirmation,
23
24
  focusTrapSettings,
24
25
  focusZoneSettings,
25
26
  onOpen: onOpenExternal,
@@ -35,6 +36,7 @@ const DatePicker = ({
35
36
  const [isOpen, setIsOpen] = (0, _react.useState)(false);
36
37
  const datePickerConfiguration = {
37
38
  anchorVariant,
39
+ confirmation,
38
40
  selection,
39
41
  view
40
42
  };
@@ -19,24 +19,71 @@ var _constants = require("../constants");
19
19
 
20
20
  var _useDatePicker = _interopRequireDefault(require("./useDatePicker"));
21
21
 
22
+ var _octiconsReact = require("@primer/octicons-react");
23
+
24
+ var _StyledOcticon = _interopRequireDefault(require("../StyledOcticon"));
25
+
26
+ var _Button = _interopRequireWildcard(require("../Button"));
27
+
28
+ 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
+
30
+ 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
+
22
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
33
 
24
34
  const DatePickerPanelContainer = (0, _styledComponents.default)(_Box.default).withConfig({
25
35
  displayName: "DatePickerPanel__DatePickerPanelContainer",
26
36
  componentId: "sc-19upxpo-0"
27
- })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";"], (0, _constants.get)('space.6'), (0, _constants.get)('space.3'));
37
+ })(["align-items:stretch;display:flex;flex-direction:column;"]);
38
+ const DatePickerPanelMonths = (0, _styledComponents.default)(_Box.default).withConfig({
39
+ displayName: "DatePickerPanel__DatePickerPanelMonths",
40
+ componentId: "sc-19upxpo-1"
41
+ })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";position:relative;"], (0, _constants.get)('space.6'), (0, _constants.get)('space.3'));
42
+ const DatePickerPanelFooter = (0, _styledComponents.default)(_Box.default).withConfig({
43
+ displayName: "DatePickerPanel__DatePickerPanelFooter",
44
+ componentId: "sc-19upxpo-2"
45
+ })(["align-items:flex-start;border-top:1px solid;border-top-color:", ";display:flex;gap:", ";padding-top:12px;padding-bottom:12px;padding-left:", ";padding-right:", ";flex-direction:row;justify-content:space-between;position:relative;"], (0, _constants.get)('colors.border.default'), (0, _constants.get)('space.6'), (0, _constants.get)('space.3'), (0, _constants.get)('space.3'));
46
+ const ArrowButton = (0, _styledComponents.default)(_Button.default).withConfig({
47
+ displayName: "DatePickerPanel__ArrowButton",
48
+ componentId: "sc-19upxpo-3"
49
+ })(["position:absolute;width:40px;height:28px;top:12px;", ";"], props => `${props.side}: ${(0, _constants.get)('space.3')(props)}`);
28
50
 
29
51
  const DatePickerPanel = () => {
30
52
  const {
31
- configuration
53
+ configuration,
54
+ saveValue,
55
+ revertValue
32
56
  } = (0, _useDatePicker.default)();
33
- return /*#__PURE__*/_react.default.createElement(DatePickerPanelContainer, null, /*#__PURE__*/_react.default.createElement(_Month.Month, {
57
+ return /*#__PURE__*/_react.default.createElement(DatePickerPanelContainer, null, /*#__PURE__*/_react.default.createElement(DatePickerPanelMonths, null, /*#__PURE__*/_react.default.createElement(ArrowButton, {
58
+ variant: "small",
59
+ side: "left"
60
+ }, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
61
+ icon: _octiconsReact.ChevronLeftIcon,
62
+ color: "fg.muted"
63
+ })), /*#__PURE__*/_react.default.createElement(_Month.Month, {
34
64
  month: new Date().getMonth(),
35
65
  year: new Date().getFullYear()
36
66
  }), configuration.view === '2-month' && /*#__PURE__*/_react.default.createElement(_Month.Month, {
37
67
  month: (0, _dateFns.addMonths)(new Date(), 1).getMonth(),
38
68
  year: (0, _dateFns.addMonths)(new Date(), 1).getFullYear()
39
- }));
69
+ }), /*#__PURE__*/_react.default.createElement(ArrowButton, {
70
+ variant: "small",
71
+ side: "right"
72
+ }, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
73
+ icon: _octiconsReact.ChevronRightIcon,
74
+ color: "fg.muted"
75
+ }))), /*#__PURE__*/_react.default.createElement(DatePickerPanelFooter, null, /*#__PURE__*/_react.default.createElement(_Box.default, null, /*#__PURE__*/_react.default.createElement(_Button.default, {
76
+ variant: "small",
77
+ sx: {
78
+ mr: 1
79
+ },
80
+ onClick: () => revertValue()
81
+ }, "Reset"), /*#__PURE__*/_react.default.createElement(_Button.default, {
82
+ variant: "small"
83
+ }, "Today")), configuration.confirmation && /*#__PURE__*/_react.default.createElement(_Button.ButtonPrimary, {
84
+ variant: "small",
85
+ onClick: () => saveValue()
86
+ }, "Apply")));
40
87
  };
41
88
 
42
89
  exports.DatePickerPanel = DatePickerPanel;
@@ -158,6 +158,7 @@ const Day = ({
158
158
  disabled: disabled,
159
159
  selected: selected,
160
160
  onClick: clickHandler,
161
+ onMouseEnter: () => onDayFocus(date),
161
162
  onFocus: () => onDayFocus(date),
162
163
  onBlur: () => onDayBlur(date),
163
164
  onKeyPress: keyPressHandler
@@ -27,6 +27,7 @@ export declare type StringRangeSelection = {
27
27
  export interface DatePickerContext {
28
28
  disabled?: boolean;
29
29
  configuration: DatePickerConfiguration;
30
+ hoverRange?: RangeSelection | null;
30
31
  selection?: Selection;
31
32
  softSelection?: Partial<RangeSelection> | null;
32
33
  selectionActive?: boolean;
@@ -35,6 +36,7 @@ export interface DatePickerContext {
35
36
  onDayFocus: (date: Date) => void;
36
37
  onDayBlur: (date: Date) => void;
37
38
  revertValue: () => void;
39
+ saveValue: (selection?: Selection) => void;
38
40
  }
39
41
  export declare type Selection = Date | Array<Date> | RangeSelection | null;
40
42
  export declare type StringSelection = string | Array<string> | {
@@ -47,6 +49,7 @@ declare const useDatePicker: (date?: Date | undefined) => {
47
49
  disabled: boolean;
48
50
  selected: DaySelection;
49
51
  configuration: DatePickerConfiguration;
52
+ hoverRange?: RangeSelection | null | undefined;
50
53
  selection?: Selection | undefined;
51
54
  softSelection?: Partial<RangeSelection> | null | undefined;
52
55
  selectionActive?: boolean | undefined;
@@ -55,6 +58,7 @@ declare const useDatePicker: (date?: Date | undefined) => {
55
58
  onDayFocus: (date: Date) => void;
56
59
  onDayBlur: (date: Date) => void;
57
60
  revertValue: () => void;
61
+ saveValue: (selection?: Selection | undefined) => void;
58
62
  };
59
63
  export default useDatePicker;
60
64
  export interface DatePickerProviderProps {
@@ -25,35 +25,50 @@ const DatePickerContext = /*#__PURE__*/(0, _react.createContext)(null);
25
25
 
26
26
  const useDatePicker = date => {
27
27
  const value = (0, _react.useContext)(DatePickerContext);
28
+ const [selected, setSelected] = (0, _react.useState)(false);
28
29
 
29
30
  if (!value) {
30
31
  throw new Error('useDatePicker must be used inside a DatePickerProvider');
31
32
  }
32
33
 
33
- let selected = false;
34
- let blocked,
35
- disabled = false;
36
-
37
- if (date) {
38
- if (value.selection) {
39
- if (isMultiSelection(value.selection)) {
40
- selected = !!value.selection.find(d => (0, _dateFns.isEqual)(d, date));
41
- } else if (isRangeSelection(value.selection)) {
42
- if ((0, _dateFns.isEqual)(date, value.selection.from)) {
43
- selected = 'start';
44
- } else if (value.selection.to && (0, _dateFns.isEqual)(date, value.selection.to)) {
45
- selected = 'end';
46
- } else if ((0, _dateFns.isAfter)(date, value.selection.from) && value.selection.to && (0, _dateFns.isBefore)(date, value.selection.to)) {
47
- selected = 'middle';
34
+ (0, _react.useEffect)(() => {
35
+ if (date) {
36
+ if (value.hoverRange) {
37
+ if (isRangeSelection(value.hoverRange)) {
38
+ if ((0, _dateFns.isEqual)(date, value.hoverRange.from)) {
39
+ setSelected('start');
40
+ } else if (value.hoverRange.to && (0, _dateFns.isEqual)(date, value.hoverRange.to)) {
41
+ setSelected('end');
42
+ } else if ((0, _dateFns.isAfter)(date, value.hoverRange.from) && value.hoverRange.to && (0, _dateFns.isBefore)(date, value.hoverRange.to)) {
43
+ setSelected('middle');
44
+ } else {
45
+ setSelected(false);
46
+ }
47
+ }
48
+ } else if (value.selection) {
49
+ if (isMultiSelection(value.selection)) {
50
+ setSelected(!!value.selection.find(d => (0, _dateFns.isEqual)(d, date)));
51
+ } else if (isRangeSelection(value.selection)) {
52
+ if ((0, _dateFns.isEqual)(date, value.selection.from)) {
53
+ setSelected('start');
54
+ } else if (value.selection.to && (0, _dateFns.isEqual)(date, value.selection.to)) {
55
+ setSelected('end');
56
+ } else if ((0, _dateFns.isAfter)(date, value.selection.from) && value.selection.to && (0, _dateFns.isBefore)(date, value.selection.to)) {
57
+ setSelected('middle');
58
+ } else {
59
+ setSelected(false);
60
+ }
48
61
  } else {
49
- selected = false;
62
+ setSelected((0, _dateFns.isEqual)(date, value.selection));
50
63
  }
51
- } else {
52
- selected = (0, _dateFns.isEqual)(date, value.selection);
53
64
  }
54
- } // Determine if date is blocked out
55
-
65
+ }
66
+ }, [date, value.hoverRange, value.selection]);
67
+ let blocked,
68
+ disabled = false;
56
69
 
70
+ if (date) {
71
+ // Determine if date is blocked out
57
72
  if (value.configuration.blockedDates) {
58
73
  blocked = !!value.configuration.blockedDates.find(d => (0, _dateFns.isEqual)(d, date));
59
74
  } // Determine if date is disabled
@@ -248,10 +263,10 @@ const DatePickerProvider = ({
248
263
  }
249
264
  }
250
265
  }, [configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
251
- const handleSave = (0, _react.useCallback)(updatedSelection => {
252
- setPreviousSelection(updatedSelection);
266
+ const saveValue = (0, _react.useCallback)(updatedSelection => {
267
+ setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
253
268
  closePicker === null || closePicker === void 0 ? void 0 : closePicker();
254
- }, [closePicker]);
269
+ }, [closePicker, selection]);
255
270
  const selectionHandler = (0, _react.useCallback)(date => {
256
271
  if (configuration.selection === 'multi') {
257
272
  const selections = [...selection];
@@ -273,11 +288,16 @@ const DatePickerProvider = ({
273
288
  to: date
274
289
  };
275
290
  setSelection(updatedSelection);
291
+ setHoverRange(null);
276
292
 
277
293
  if (!configuration.confirmation) {
278
- handleSave(updatedSelection);
294
+ saveValue(updatedSelection);
279
295
  }
280
296
  } else {
297
+ setHoverRange({
298
+ from: date,
299
+ to: date
300
+ });
281
301
  setSelection({
282
302
  from: date,
283
303
  to: null
@@ -287,14 +307,14 @@ const DatePickerProvider = ({
287
307
  setSelection(date);
288
308
 
289
309
  if (!configuration.confirmation) {
290
- handleSave(date);
310
+ saveValue(date);
291
311
  }
292
312
  }
293
- }, [configuration.confirmation, configuration.selection, handleSave, selection]);
313
+ }, [configuration.confirmation, configuration.selection, saveValue, selection]);
294
314
  const focusHnadler = (0, _react.useCallback)(date => {
295
315
  if (!selection) return;
296
316
 
297
- if (configuration.selection === 'range' && isRangeSelection(selection)) {
317
+ if (configuration.selection === 'range' && isRangeSelection(selection) && hoverRange) {
298
318
  setHoverRange((0, _dateFns.isBefore)(date, selection.from) ? {
299
319
  from: date,
300
320
  to: selection.from
@@ -303,12 +323,11 @@ const DatePickerProvider = ({
303
323
  to: date
304
324
  });
305
325
  }
306
- }, [configuration.selection, selection]);
326
+ }, [configuration.selection, hoverRange, selection]);
307
327
  const blurHnadler = (0, _react.useCallback)(date => {
308
328
  if (!selection || !hoverRange) return;
309
329
 
310
- if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {
311
- setHoverRange(null);
330
+ if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {// setHoverRange({from: hoverRange.from, to: hoverRange.from})
312
331
  }
313
332
  }, [configuration.selection, hoverRange, selection]);
314
333
  const revertValue = (0, _react.useCallback)(() => {
@@ -319,14 +338,16 @@ const DatePickerProvider = ({
319
338
  configuration,
320
339
  disabled: false,
321
340
  formattedDate: getFormattedDate,
341
+ hoverRange,
322
342
  onDayBlur: blurHnadler,
323
343
  onDayFocus: focusHnadler,
324
344
  onSelection: selectionHandler,
325
345
  revertValue,
346
+ saveValue,
326
347
  selectionActive: false,
327
348
  selection
328
349
  };
329
- }, [blurHnadler, configuration, focusHnadler, getFormattedDate, revertValue, selection, selectionHandler]);
350
+ }, [blurHnadler, configuration, focusHnadler, getFormattedDate, hoverRange, revertValue, saveValue, selection, selectionHandler]);
330
351
  return /*#__PURE__*/_react.default.createElement(DatePickerContext.Provider, {
331
352
  value: datePickerCtx
332
353
  }, children);
@@ -5,6 +5,7 @@ import { DatePickerOverlay } from './DatePickerOverlay';
5
5
  export const DatePicker = ({
6
6
  anchorVariant,
7
7
  anchorRef: externalAnchorRef,
8
+ confirmation,
8
9
  focusTrapSettings,
9
10
  focusZoneSettings,
10
11
  onOpen: onOpenExternal,
@@ -20,6 +21,7 @@ export const DatePicker = ({
20
21
  const [isOpen, setIsOpen] = useState(false);
21
22
  const datePickerConfiguration = {
22
23
  anchorVariant,
24
+ confirmation,
23
25
  selection,
24
26
  view
25
27
  };
@@ -5,20 +5,60 @@ import { Month } from './Month';
5
5
  import styled from 'styled-components';
6
6
  import { get } from '../constants';
7
7
  import useDatePicker from './useDatePicker';
8
+ import { ChevronLeftIcon, ChevronRightIcon } from '@primer/octicons-react';
9
+ import StyledOcticon from '../StyledOcticon';
10
+ import Button, { ButtonPrimary } from '../Button';
8
11
  const DatePickerPanelContainer = styled(Box).withConfig({
9
12
  displayName: "DatePickerPanel__DatePickerPanelContainer",
10
13
  componentId: "sc-19upxpo-0"
11
- })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";"], get('space.6'), get('space.3'));
14
+ })(["align-items:stretch;display:flex;flex-direction:column;"]);
15
+ const DatePickerPanelMonths = styled(Box).withConfig({
16
+ displayName: "DatePickerPanel__DatePickerPanelMonths",
17
+ componentId: "sc-19upxpo-1"
18
+ })(["align-items:flex-start;display:flex;flex-direction:row;gap:", ";padding:", ";position:relative;"], get('space.6'), get('space.3'));
19
+ const DatePickerPanelFooter = styled(Box).withConfig({
20
+ displayName: "DatePickerPanel__DatePickerPanelFooter",
21
+ componentId: "sc-19upxpo-2"
22
+ })(["align-items:flex-start;border-top:1px solid;border-top-color:", ";display:flex;gap:", ";padding-top:12px;padding-bottom:12px;padding-left:", ";padding-right:", ";flex-direction:row;justify-content:space-between;position:relative;"], get('colors.border.default'), get('space.6'), get('space.3'), get('space.3'));
23
+ const ArrowButton = styled(Button).withConfig({
24
+ displayName: "DatePickerPanel__ArrowButton",
25
+ componentId: "sc-19upxpo-3"
26
+ })(["position:absolute;width:40px;height:28px;top:12px;", ";"], props => `${props.side}: ${get('space.3')(props)}`);
12
27
  export const DatePickerPanel = () => {
13
28
  const {
14
- configuration
29
+ configuration,
30
+ saveValue,
31
+ revertValue
15
32
  } = useDatePicker();
16
- return /*#__PURE__*/React.createElement(DatePickerPanelContainer, null, /*#__PURE__*/React.createElement(Month, {
33
+ return /*#__PURE__*/React.createElement(DatePickerPanelContainer, null, /*#__PURE__*/React.createElement(DatePickerPanelMonths, null, /*#__PURE__*/React.createElement(ArrowButton, {
34
+ variant: "small",
35
+ side: "left"
36
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
37
+ icon: ChevronLeftIcon,
38
+ color: "fg.muted"
39
+ })), /*#__PURE__*/React.createElement(Month, {
17
40
  month: new Date().getMonth(),
18
41
  year: new Date().getFullYear()
19
42
  }), configuration.view === '2-month' && /*#__PURE__*/React.createElement(Month, {
20
43
  month: addMonths(new Date(), 1).getMonth(),
21
44
  year: addMonths(new Date(), 1).getFullYear()
22
- }));
45
+ }), /*#__PURE__*/React.createElement(ArrowButton, {
46
+ variant: "small",
47
+ side: "right"
48
+ }, /*#__PURE__*/React.createElement(StyledOcticon, {
49
+ icon: ChevronRightIcon,
50
+ color: "fg.muted"
51
+ }))), /*#__PURE__*/React.createElement(DatePickerPanelFooter, null, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Button, {
52
+ variant: "small",
53
+ sx: {
54
+ mr: 1
55
+ },
56
+ onClick: () => revertValue()
57
+ }, "Reset"), /*#__PURE__*/React.createElement(Button, {
58
+ variant: "small"
59
+ }, "Today")), configuration.confirmation && /*#__PURE__*/React.createElement(ButtonPrimary, {
60
+ variant: "small",
61
+ onClick: () => saveValue()
62
+ }, "Apply")));
23
63
  };
24
64
  DatePickerPanel.displayName = "DatePickerPanel";
@@ -138,6 +138,7 @@ export const Day = ({
138
138
  disabled: disabled,
139
139
  selected: selected,
140
140
  onClick: clickHandler,
141
+ onMouseEnter: () => onDayFocus(date),
141
142
  onFocus: () => onDayFocus(date),
142
143
  onBlur: () => onDayBlur(date),
143
144
  onKeyPress: keyPressHandler
@@ -27,6 +27,7 @@ export declare type StringRangeSelection = {
27
27
  export interface DatePickerContext {
28
28
  disabled?: boolean;
29
29
  configuration: DatePickerConfiguration;
30
+ hoverRange?: RangeSelection | null;
30
31
  selection?: Selection;
31
32
  softSelection?: Partial<RangeSelection> | null;
32
33
  selectionActive?: boolean;
@@ -35,6 +36,7 @@ export interface DatePickerContext {
35
36
  onDayFocus: (date: Date) => void;
36
37
  onDayBlur: (date: Date) => void;
37
38
  revertValue: () => void;
39
+ saveValue: (selection?: Selection) => void;
38
40
  }
39
41
  export declare type Selection = Date | Array<Date> | RangeSelection | null;
40
42
  export declare type StringSelection = string | Array<string> | {
@@ -47,6 +49,7 @@ declare const useDatePicker: (date?: Date | undefined) => {
47
49
  disabled: boolean;
48
50
  selected: DaySelection;
49
51
  configuration: DatePickerConfiguration;
52
+ hoverRange?: RangeSelection | null | undefined;
50
53
  selection?: Selection | undefined;
51
54
  softSelection?: Partial<RangeSelection> | null | undefined;
52
55
  selectionActive?: boolean | undefined;
@@ -55,6 +58,7 @@ declare const useDatePicker: (date?: Date | undefined) => {
55
58
  onDayFocus: (date: Date) => void;
56
59
  onDayBlur: (date: Date) => void;
57
60
  revertValue: () => void;
61
+ saveValue: (selection?: Selection | undefined) => void;
58
62
  };
59
63
  export default useDatePicker;
60
64
  export interface DatePickerProviderProps {
@@ -5,35 +5,50 @@ const DatePickerContext = /*#__PURE__*/createContext(null);
5
5
 
6
6
  const useDatePicker = date => {
7
7
  const value = useContext(DatePickerContext);
8
+ const [selected, setSelected] = useState(false);
8
9
 
9
10
  if (!value) {
10
11
  throw new Error('useDatePicker must be used inside a DatePickerProvider');
11
12
  }
12
13
 
13
- let selected = false;
14
- let blocked,
15
- disabled = false;
16
-
17
- if (date) {
18
- if (value.selection) {
19
- if (isMultiSelection(value.selection)) {
20
- selected = !!value.selection.find(d => isEqual(d, date));
21
- } else if (isRangeSelection(value.selection)) {
22
- if (isEqual(date, value.selection.from)) {
23
- selected = 'start';
24
- } else if (value.selection.to && isEqual(date, value.selection.to)) {
25
- selected = 'end';
26
- } else if (isAfter(date, value.selection.from) && value.selection.to && isBefore(date, value.selection.to)) {
27
- selected = 'middle';
14
+ useEffect(() => {
15
+ if (date) {
16
+ if (value.hoverRange) {
17
+ if (isRangeSelection(value.hoverRange)) {
18
+ if (isEqual(date, value.hoverRange.from)) {
19
+ setSelected('start');
20
+ } else if (value.hoverRange.to && isEqual(date, value.hoverRange.to)) {
21
+ setSelected('end');
22
+ } else if (isAfter(date, value.hoverRange.from) && value.hoverRange.to && isBefore(date, value.hoverRange.to)) {
23
+ setSelected('middle');
24
+ } else {
25
+ setSelected(false);
26
+ }
27
+ }
28
+ } else if (value.selection) {
29
+ if (isMultiSelection(value.selection)) {
30
+ setSelected(!!value.selection.find(d => isEqual(d, date)));
31
+ } else if (isRangeSelection(value.selection)) {
32
+ if (isEqual(date, value.selection.from)) {
33
+ setSelected('start');
34
+ } else if (value.selection.to && isEqual(date, value.selection.to)) {
35
+ setSelected('end');
36
+ } else if (isAfter(date, value.selection.from) && value.selection.to && isBefore(date, value.selection.to)) {
37
+ setSelected('middle');
38
+ } else {
39
+ setSelected(false);
40
+ }
28
41
  } else {
29
- selected = false;
42
+ setSelected(isEqual(date, value.selection));
30
43
  }
31
- } else {
32
- selected = isEqual(date, value.selection);
33
44
  }
34
- } // Determine if date is blocked out
35
-
45
+ }
46
+ }, [date, value.hoverRange, value.selection]);
47
+ let blocked,
48
+ disabled = false;
36
49
 
50
+ if (date) {
51
+ // Determine if date is blocked out
37
52
  if (value.configuration.blockedDates) {
38
53
  blocked = !!value.configuration.blockedDates.find(d => isEqual(d, date));
39
54
  } // Determine if date is disabled
@@ -222,10 +237,10 @@ export const DatePickerProvider = ({
222
237
  }
223
238
  }
224
239
  }, [configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
225
- const handleSave = useCallback(updatedSelection => {
226
- setPreviousSelection(updatedSelection);
240
+ const saveValue = useCallback(updatedSelection => {
241
+ setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
227
242
  closePicker === null || closePicker === void 0 ? void 0 : closePicker();
228
- }, [closePicker]);
243
+ }, [closePicker, selection]);
229
244
  const selectionHandler = useCallback(date => {
230
245
  if (configuration.selection === 'multi') {
231
246
  const selections = [...selection];
@@ -247,11 +262,16 @@ export const DatePickerProvider = ({
247
262
  to: date
248
263
  };
249
264
  setSelection(updatedSelection);
265
+ setHoverRange(null);
250
266
 
251
267
  if (!configuration.confirmation) {
252
- handleSave(updatedSelection);
268
+ saveValue(updatedSelection);
253
269
  }
254
270
  } else {
271
+ setHoverRange({
272
+ from: date,
273
+ to: date
274
+ });
255
275
  setSelection({
256
276
  from: date,
257
277
  to: null
@@ -261,14 +281,14 @@ export const DatePickerProvider = ({
261
281
  setSelection(date);
262
282
 
263
283
  if (!configuration.confirmation) {
264
- handleSave(date);
284
+ saveValue(date);
265
285
  }
266
286
  }
267
- }, [configuration.confirmation, configuration.selection, handleSave, selection]);
287
+ }, [configuration.confirmation, configuration.selection, saveValue, selection]);
268
288
  const focusHnadler = useCallback(date => {
269
289
  if (!selection) return;
270
290
 
271
- if (configuration.selection === 'range' && isRangeSelection(selection)) {
291
+ if (configuration.selection === 'range' && isRangeSelection(selection) && hoverRange) {
272
292
  setHoverRange(isBefore(date, selection.from) ? {
273
293
  from: date,
274
294
  to: selection.from
@@ -277,12 +297,11 @@ export const DatePickerProvider = ({
277
297
  to: date
278
298
  });
279
299
  }
280
- }, [configuration.selection, selection]);
300
+ }, [configuration.selection, hoverRange, selection]);
281
301
  const blurHnadler = useCallback(date => {
282
302
  if (!selection || !hoverRange) return;
283
303
 
284
- if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {
285
- setHoverRange(null);
304
+ if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {// setHoverRange({from: hoverRange.from, to: hoverRange.from})
286
305
  }
287
306
  }, [configuration.selection, hoverRange, selection]);
288
307
  const revertValue = useCallback(() => {
@@ -293,14 +312,16 @@ export const DatePickerProvider = ({
293
312
  configuration,
294
313
  disabled: false,
295
314
  formattedDate: getFormattedDate,
315
+ hoverRange,
296
316
  onDayBlur: blurHnadler,
297
317
  onDayFocus: focusHnadler,
298
318
  onSelection: selectionHandler,
299
319
  revertValue,
320
+ saveValue,
300
321
  selectionActive: false,
301
322
  selection
302
323
  };
303
- }, [blurHnadler, configuration, focusHnadler, getFormattedDate, revertValue, selection, selectionHandler]);
324
+ }, [blurHnadler, configuration, focusHnadler, getFormattedDate, hoverRange, revertValue, saveValue, selection, selectionHandler]);
304
325
  return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
305
326
  value: datePickerCtx
306
327
  }, children);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-2021922204627",
3
+ "version": "0.0.0-202192422618",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",