@primer/components 0.0.0-2021923214017 → 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-2021923214017
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;
@@ -36,6 +36,7 @@ export interface DatePickerContext {
36
36
  onDayFocus: (date: Date) => void;
37
37
  onDayBlur: (date: Date) => void;
38
38
  revertValue: () => void;
39
+ saveValue: (selection?: Selection) => void;
39
40
  }
40
41
  export declare type Selection = Date | Array<Date> | RangeSelection | null;
41
42
  export declare type StringSelection = string | Array<string> | {
@@ -57,6 +58,7 @@ declare const useDatePicker: (date?: Date | undefined) => {
57
58
  onDayFocus: (date: Date) => void;
58
59
  onDayBlur: (date: Date) => void;
59
60
  revertValue: () => void;
61
+ saveValue: (selection?: Selection | undefined) => void;
60
62
  };
61
63
  export default useDatePicker;
62
64
  export interface DatePickerProviderProps {
@@ -263,10 +263,10 @@ const DatePickerProvider = ({
263
263
  }
264
264
  }
265
265
  }, [configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
266
- const handleSave = (0, _react.useCallback)(updatedSelection => {
267
- setPreviousSelection(updatedSelection);
266
+ const saveValue = (0, _react.useCallback)(updatedSelection => {
267
+ setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
268
268
  closePicker === null || closePicker === void 0 ? void 0 : closePicker();
269
- }, [closePicker]);
269
+ }, [closePicker, selection]);
270
270
  const selectionHandler = (0, _react.useCallback)(date => {
271
271
  if (configuration.selection === 'multi') {
272
272
  const selections = [...selection];
@@ -291,7 +291,7 @@ const DatePickerProvider = ({
291
291
  setHoverRange(null);
292
292
 
293
293
  if (!configuration.confirmation) {
294
- handleSave(updatedSelection);
294
+ saveValue(updatedSelection);
295
295
  }
296
296
  } else {
297
297
  setHoverRange({
@@ -307,10 +307,10 @@ const DatePickerProvider = ({
307
307
  setSelection(date);
308
308
 
309
309
  if (!configuration.confirmation) {
310
- handleSave(date);
310
+ saveValue(date);
311
311
  }
312
312
  }
313
- }, [configuration.confirmation, configuration.selection, handleSave, selection]);
313
+ }, [configuration.confirmation, configuration.selection, saveValue, selection]);
314
314
  const focusHnadler = (0, _react.useCallback)(date => {
315
315
  if (!selection) return;
316
316
 
@@ -343,10 +343,11 @@ const DatePickerProvider = ({
343
343
  onDayFocus: focusHnadler,
344
344
  onSelection: selectionHandler,
345
345
  revertValue,
346
+ saveValue,
346
347
  selectionActive: false,
347
348
  selection
348
349
  };
349
- }, [blurHnadler, configuration, focusHnadler, getFormattedDate, hoverRange, revertValue, selection, selectionHandler]);
350
+ }, [blurHnadler, configuration, focusHnadler, getFormattedDate, hoverRange, revertValue, saveValue, selection, selectionHandler]);
350
351
  return /*#__PURE__*/_react.default.createElement(DatePickerContext.Provider, {
351
352
  value: datePickerCtx
352
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";
@@ -36,6 +36,7 @@ export interface DatePickerContext {
36
36
  onDayFocus: (date: Date) => void;
37
37
  onDayBlur: (date: Date) => void;
38
38
  revertValue: () => void;
39
+ saveValue: (selection?: Selection) => void;
39
40
  }
40
41
  export declare type Selection = Date | Array<Date> | RangeSelection | null;
41
42
  export declare type StringSelection = string | Array<string> | {
@@ -57,6 +58,7 @@ declare const useDatePicker: (date?: Date | undefined) => {
57
58
  onDayFocus: (date: Date) => void;
58
59
  onDayBlur: (date: Date) => void;
59
60
  revertValue: () => void;
61
+ saveValue: (selection?: Selection | undefined) => void;
60
62
  };
61
63
  export default useDatePicker;
62
64
  export interface DatePickerProviderProps {
@@ -237,10 +237,10 @@ export const DatePickerProvider = ({
237
237
  }
238
238
  }
239
239
  }, [configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
240
- const handleSave = useCallback(updatedSelection => {
241
- setPreviousSelection(updatedSelection);
240
+ const saveValue = useCallback(updatedSelection => {
241
+ setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
242
242
  closePicker === null || closePicker === void 0 ? void 0 : closePicker();
243
- }, [closePicker]);
243
+ }, [closePicker, selection]);
244
244
  const selectionHandler = useCallback(date => {
245
245
  if (configuration.selection === 'multi') {
246
246
  const selections = [...selection];
@@ -265,7 +265,7 @@ export const DatePickerProvider = ({
265
265
  setHoverRange(null);
266
266
 
267
267
  if (!configuration.confirmation) {
268
- handleSave(updatedSelection);
268
+ saveValue(updatedSelection);
269
269
  }
270
270
  } else {
271
271
  setHoverRange({
@@ -281,10 +281,10 @@ export const DatePickerProvider = ({
281
281
  setSelection(date);
282
282
 
283
283
  if (!configuration.confirmation) {
284
- handleSave(date);
284
+ saveValue(date);
285
285
  }
286
286
  }
287
- }, [configuration.confirmation, configuration.selection, handleSave, selection]);
287
+ }, [configuration.confirmation, configuration.selection, saveValue, selection]);
288
288
  const focusHnadler = useCallback(date => {
289
289
  if (!selection) return;
290
290
 
@@ -317,10 +317,11 @@ export const DatePickerProvider = ({
317
317
  onDayFocus: focusHnadler,
318
318
  onSelection: selectionHandler,
319
319
  revertValue,
320
+ saveValue,
320
321
  selectionActive: false,
321
322
  selection
322
323
  };
323
- }, [blurHnadler, configuration, focusHnadler, getFormattedDate, hoverRange, revertValue, selection, selectionHandler]);
324
+ }, [blurHnadler, configuration, focusHnadler, getFormattedDate, hoverRange, revertValue, saveValue, selection, selectionHandler]);
324
325
  return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
325
326
  value: datePickerCtx
326
327
  }, children);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-2021923214017",
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",