@primer/components 0.0.0-202192602912 → 0.0.0-2021926114132

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.
Files changed (112) hide show
  1. package/CHANGELOG.md +4 -8
  2. package/dist/browser.esm.js +616 -616
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +177 -177
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList2/Description.d.ts +6 -0
  7. package/lib/ActionList2/Description.js +53 -0
  8. package/lib/ActionList2/Divider.d.ts +8 -0
  9. package/lib/ActionList2/Divider.js +42 -0
  10. package/lib/ActionList2/Group.d.ts +8 -0
  11. package/lib/ActionList2/Group.js +39 -0
  12. package/lib/ActionList2/Header.d.ts +26 -0
  13. package/lib/ActionList2/Header.js +55 -0
  14. package/lib/ActionList2/Item.d.ts +49 -0
  15. package/lib/ActionList2/Item.js +205 -0
  16. package/lib/ActionList2/List.d.ts +11 -0
  17. package/lib/ActionList2/List.js +53 -0
  18. package/lib/ActionList2/Selection.d.ts +5 -0
  19. package/lib/ActionList2/Selection.js +67 -0
  20. package/lib/ActionList2/Visuals.d.ts +11 -0
  21. package/lib/ActionList2/Visuals.js +90 -0
  22. package/lib/ActionList2/hacks.d.ts +30 -0
  23. package/lib/ActionList2/hacks.js +38 -0
  24. package/lib/ActionList2/index.d.ts +26 -0
  25. package/lib/ActionList2/index.js +36 -0
  26. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  27. package/lib/Autocomplete/Autocomplete.d.ts +2 -4
  28. package/lib/Autocomplete/AutocompleteInput.d.ts +2 -4
  29. package/lib/SelectMenu/SelectMenu.d.ts +2 -4
  30. package/lib/TextInputWithTokens.d.ts +2 -4
  31. package/lib/index.d.ts +1 -0
  32. package/lib/index.js +8 -0
  33. package/lib/sx.d.ts +2 -0
  34. package/lib/sx.js +8 -0
  35. package/lib/theme-preval.js +2 -2
  36. package/lib/utils/create-slots.d.ts +17 -0
  37. package/lib/utils/create-slots.js +105 -0
  38. package/lib/utils/testing.d.ts +1 -1
  39. package/lib/utils/use-force-update.d.ts +1 -0
  40. package/lib/utils/use-force-update.js +19 -0
  41. package/lib-esm/ActionList2/Description.d.ts +6 -0
  42. package/lib-esm/ActionList2/Description.js +37 -0
  43. package/lib-esm/ActionList2/Divider.d.ts +8 -0
  44. package/lib-esm/ActionList2/Divider.js +30 -0
  45. package/lib-esm/ActionList2/Group.d.ts +8 -0
  46. package/lib-esm/ActionList2/Group.js +29 -0
  47. package/lib-esm/ActionList2/Header.d.ts +26 -0
  48. package/lib-esm/ActionList2/Header.js +45 -0
  49. package/lib-esm/ActionList2/Item.d.ts +49 -0
  50. package/lib-esm/ActionList2/Item.js +198 -0
  51. package/lib-esm/ActionList2/List.d.ts +11 -0
  52. package/lib-esm/ActionList2/List.js +35 -0
  53. package/lib-esm/ActionList2/Selection.d.ts +5 -0
  54. package/lib-esm/ActionList2/Selection.js +50 -0
  55. package/lib-esm/ActionList2/Visuals.d.ts +11 -0
  56. package/lib-esm/ActionList2/Visuals.js +68 -0
  57. package/lib-esm/ActionList2/hacks.d.ts +30 -0
  58. package/lib-esm/ActionList2/hacks.js +30 -0
  59. package/lib-esm/ActionList2/index.d.ts +26 -0
  60. package/lib-esm/ActionList2/index.js +23 -0
  61. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
  62. package/lib-esm/Autocomplete/Autocomplete.d.ts +2 -4
  63. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +2 -4
  64. package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -4
  65. package/lib-esm/TextInputWithTokens.d.ts +2 -4
  66. package/lib-esm/index.d.ts +1 -0
  67. package/lib-esm/index.js +1 -0
  68. package/lib-esm/sx.d.ts +2 -0
  69. package/lib-esm/sx.js +3 -1
  70. package/lib-esm/theme-preval.js +2 -2
  71. package/lib-esm/utils/create-slots.d.ts +17 -0
  72. package/lib-esm/utils/create-slots.js +84 -0
  73. package/lib-esm/utils/testing.d.ts +1 -1
  74. package/lib-esm/utils/use-force-update.d.ts +1 -0
  75. package/lib-esm/utils/use-force-update.js +6 -0
  76. package/package.json +8 -9
  77. package/lib/DatePicker/DatePicker.d.ts +0 -48
  78. package/lib/DatePicker/DatePicker.js +0 -92
  79. package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
  80. package/lib/DatePicker/DatePickerAnchor.js +0 -158
  81. package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
  82. package/lib/DatePicker/DatePickerOverlay.js +0 -39
  83. package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
  84. package/lib/DatePicker/DatePickerPanel.js +0 -126
  85. package/lib/DatePicker/Day.d.ts +0 -14
  86. package/lib/DatePicker/Day.js +0 -174
  87. package/lib/DatePicker/Month.d.ts +0 -9
  88. package/lib/DatePicker/Month.js +0 -107
  89. package/lib/DatePicker/index.d.ts +0 -2
  90. package/lib/DatePicker/index.js +0 -13
  91. package/lib/DatePicker/useDatePicker.d.ts +0 -83
  92. package/lib/DatePicker/useDatePicker.js +0 -375
  93. package/lib/hooks/useDebounce.d.ts +0 -2
  94. package/lib/hooks/useDebounce.js +0 -24
  95. package/lib-esm/DatePicker/DatePicker.d.ts +0 -48
  96. package/lib-esm/DatePicker/DatePicker.js +0 -75
  97. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
  98. package/lib-esm/DatePicker/DatePickerAnchor.js +0 -132
  99. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
  100. package/lib-esm/DatePicker/DatePickerOverlay.js +0 -24
  101. package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
  102. package/lib-esm/DatePicker/DatePickerPanel.js +0 -100
  103. package/lib-esm/DatePicker/Day.d.ts +0 -14
  104. package/lib-esm/DatePicker/Day.js +0 -151
  105. package/lib-esm/DatePicker/Month.d.ts +0 -9
  106. package/lib-esm/DatePicker/Month.js +0 -83
  107. package/lib-esm/DatePicker/index.d.ts +0 -2
  108. package/lib-esm/DatePicker/index.js +0 -1
  109. package/lib-esm/DatePicker/useDatePicker.d.ts +0 -83
  110. package/lib-esm/DatePicker/useDatePicker.js +0 -347
  111. package/lib-esm/hooks/useDebounce.d.ts +0 -2
  112. package/lib-esm/hooks/useDebounce.js +0 -16
@@ -1,126 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.DatePickerPanel = void 0;
7
-
8
- var _dateFns = require("date-fns");
9
-
10
- var _react = _interopRequireWildcard(require("react"));
11
-
12
- var _Box = _interopRequireDefault(require("../Box"));
13
-
14
- var _Month = require("./Month");
15
-
16
- var _styledComponents = _interopRequireDefault(require("styled-components"));
17
-
18
- var _constants = require("../constants");
19
-
20
- var _useDatePicker = _interopRequireDefault(require("./useDatePicker"));
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
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); }
31
-
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; }
33
-
34
- const DatePickerPanelContainer = (0, _styledComponents.default)(_Box.default).withConfig({
35
- displayName: "DatePickerPanel__DatePickerPanelContainer",
36
- componentId: "sc-19upxpo-0"
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)}`);
50
-
51
- const DatePickerPanel = () => {
52
- const {
53
- configuration,
54
- saveValue,
55
- revertValue,
56
- currentViewingDate,
57
- goToMonth,
58
- nextMonth,
59
- previousMonth
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]);
88
- return /*#__PURE__*/_react.default.createElement(DatePickerPanelContainer, null, /*#__PURE__*/_react.default.createElement(DatePickerPanelMonths, null, /*#__PURE__*/_react.default.createElement(ArrowButton, {
89
- variant: "small",
90
- side: "left",
91
- onClick: previousMonth,
92
- disabled: previousDisabled
93
- }, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
94
- icon: _octiconsReact.ChevronLeftIcon,
95
- color: "fg.muted"
96
- })), /*#__PURE__*/_react.default.createElement(_Month.Month, {
97
- month: currentViewingDate.getMonth(),
98
- year: currentViewingDate.getFullYear()
99
- }), configuration.view === '2-month' && /*#__PURE__*/_react.default.createElement(_Month.Month, {
100
- month: (0, _dateFns.addMonths)(currentViewingDate, 1).getMonth(),
101
- year: (0, _dateFns.addMonths)(currentViewingDate, 1).getFullYear()
102
- }), /*#__PURE__*/_react.default.createElement(ArrowButton, {
103
- variant: "small",
104
- side: "right",
105
- onClick: nextMonth,
106
- disabled: nextDisabled
107
- }, /*#__PURE__*/_react.default.createElement(_StyledOcticon.default, {
108
- icon: _octiconsReact.ChevronRightIcon,
109
- color: "fg.muted"
110
- }))), /*#__PURE__*/_react.default.createElement(DatePickerPanelFooter, null, /*#__PURE__*/_react.default.createElement(_Box.default, null, /*#__PURE__*/_react.default.createElement(_Button.default, {
111
- variant: "small",
112
- sx: {
113
- mr: 1
114
- },
115
- onClick: () => revertValue()
116
- }, "Reset"), /*#__PURE__*/_react.default.createElement(_Button.default, {
117
- variant: "small",
118
- onClick: () => goToMonth(new Date())
119
- }, "Today")), configuration.confirmation && /*#__PURE__*/_react.default.createElement(_Button.ButtonPrimary, {
120
- variant: "small",
121
- onClick: () => saveValue()
122
- }, "Apply")));
123
- };
124
-
125
- exports.DatePickerPanel = DatePickerPanel;
126
- DatePickerPanel.displayName = "DatePickerPanel";
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import { FontSizeProps } from 'styled-system';
3
- import { SystemCommonProps, SystemLayoutProps } from '../constants';
4
- import { SxProp } from '../sx';
5
- import { DaySelection } from './useDatePicker';
6
- export interface DayProps extends FontSizeProps, SystemCommonProps, SxProp, SystemLayoutProps {
7
- blocked?: boolean;
8
- disabled?: boolean;
9
- onAction?: (date: Date, event?: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
10
- selected?: DaySelection;
11
- date: Date;
12
- }
13
- export declare const Day: React.FC<DayProps>;
14
- export declare const BlankDay: import("styled-components").StyledComponent<"div", any, import("styled-system").SpaceProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").ColorProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").TypographyProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").LayoutProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").FlexboxProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").GridProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").BackgroundProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Background<import("styled-system").TLengthStyledSystem>> & import("styled-system").BorderProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>> & import("styled-system").PositionProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").ShadowProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & SxProp, never>;
@@ -1,174 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BlankDay = exports.Day = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _styledComponents = _interopRequireDefault(require("styled-components"));
11
-
12
- var _Box = _interopRequireDefault(require("../Box"));
13
-
14
- var _Text = _interopRequireDefault(require("../Text"));
15
-
16
- var _constants = require("../constants");
17
-
18
- var _useDatePicker = _interopRequireDefault(require("./useDatePicker"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- 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); }
23
-
24
- 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; }
25
-
26
- const DayBaseComponent = (0, _styledComponents.default)(_Box.default).withConfig({
27
- displayName: "Day__DayBaseComponent",
28
- componentId: "sc-1japneh-0"
29
- })(["align-content:center;display:flex;justify-content:center;min-width:38px;min-height:38px;padding:", ";"], (0, _constants.get)('space.1'));
30
- const states = {
31
- blocked: {
32
- background: (0, _constants.get)('colors.neutral.subtle'),
33
- borderRadius: (0, _constants.get)('radii.2'),
34
- color: (0, _constants.get)('colors.fg.subtle')
35
- },
36
- disabled: {
37
- background: (0, _constants.get)('colors.canvas.primary'),
38
- borderRadius: (0, _constants.get)('radii.2'),
39
- color: (0, _constants.get)('colors.fg.subtle')
40
- },
41
- selected: {
42
- default: {
43
- background: (0, _constants.get)('colors.accent.emphasis'),
44
- borderRadius: (0, _constants.get)('radii.2'),
45
- color: (0, _constants.get)('colors.fg.onEmphasis')
46
- },
47
- start: {
48
- background: (0, _constants.get)('colors.accent.emphasis'),
49
- borderRadius: '4px 0 0 4px',
50
- color: (0, _constants.get)('colors.fg.onEmphasis')
51
- },
52
- middle: {
53
- background: (0, _constants.get)('colors.accent.subtle'),
54
- borderRadius: '0',
55
- color: (0, _constants.get)('colors.fg.default')
56
- },
57
- end: {
58
- background: (0, _constants.get)('colors.accent.emphasis'),
59
- borderRadius: '0 4px 4px 0',
60
- color: (0, _constants.get)('colors.fg.onEmphasis')
61
- }
62
- },
63
- default: {
64
- normal: {
65
- background: (0, _constants.get)('colors.canvas.primary'),
66
- borderRadius: (0, _constants.get)('radii.2'),
67
- color: (0, _constants.get)('colors.fg.default')
68
- },
69
- hover: {
70
- background: (0, _constants.get)('colors.neutral.muted'),
71
- borderRadius: (0, _constants.get)('radii.2'),
72
- color: (0, _constants.get)('colors.fg.default')
73
- },
74
- pressed: {
75
- background: (0, _constants.get)('colors.neutral.emphasis'),
76
- borderRadius: (0, _constants.get)('radii.2'),
77
- color: (0, _constants.get)('colors.fg.onEmphasis')
78
- }
79
- }
80
- };
81
-
82
- const getStateStyles = (props, prop, state) => {
83
- const {
84
- blocked,
85
- disabled,
86
- selected
87
- } = props;
88
-
89
- if (blocked) {
90
- return states.blocked[prop];
91
- } else if (disabled) {
92
- return states.disabled[prop];
93
- } else if (selected) {
94
- switch (selected) {
95
- case 'start':
96
- return states.selected.start[prop];
97
-
98
- case 'middle':
99
- return states.selected.middle[prop];
100
-
101
- case 'end':
102
- return states.selected.end[prop];
103
-
104
- default:
105
- return states.selected.default[prop];
106
- }
107
- } else {
108
- return states.default[state][prop];
109
- }
110
- };
111
-
112
- const DayComponent = (0, _styledComponents.default)(DayBaseComponent).attrs(props => ({
113
- background: getStateStyles(props, 'background', 'normal'),
114
- borderRadius: getStateStyles(props, 'borderRadius', 'normal'),
115
- textColor: getStateStyles(props, 'color', 'normal'),
116
- backgroundHover: getStateStyles(props, 'background', 'hover'),
117
- textColorHover: getStateStyles(props, 'color', 'hover'),
118
- backgroundPressed: getStateStyles(props, 'background', 'pressed'),
119
- textColorPressed: getStateStyles(props, 'color', 'pressed')
120
- })).withConfig({
121
- displayName: "Day__DayComponent",
122
- componentId: "sc-1japneh-1"
123
- })(["background-color:", ";border-radius:", ";transition:0.1s background-color ease;& ", "{align-self:center;color:", ";display:flex;font-family:", ";font-size:", ";justify-self:center;user-select:none;transition:0.1s color ease;}&:hover{background-color:", ";cursor:pointer;transition:0.05s background-color ease;& ", "{color:", ";transition:0.1s color ease;}}&:active{background-color:", ";box-shadow:inset ", ";transition:0.1s background-color ease,0.1s box-shadow ease,0.1s color ease;& ", "{color:", ";transition:0.1s color ease;}}"], props => props.background, props => props.borderRadius, _Text.default, props => props.textColor, (0, _constants.get)('fonts.mono'), (0, _constants.get)('fontSizes.0'), props => props.backgroundHover, _Text.default, props => props.textColorHover, props => props.backgroundPressed, (0, _constants.get)('shadows.shadow.medium'), _Text.default, props => props.textColorPressed);
124
-
125
- const Day = ({
126
- date,
127
- onAction
128
- }) => {
129
- const {
130
- onDayFocus,
131
- onDayBlur,
132
- onSelection,
133
- disabled,
134
- blocked,
135
- selected
136
- } = (0, _useDatePicker.default)(date);
137
- const keyPressHandler = (0, _react.useCallback)(event => {
138
- if (disabled) {
139
- return;
140
- }
141
-
142
- if ([' ', 'Enter'].includes(event.key)) {
143
- onSelection(date);
144
- onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
145
- }
146
- }, [disabled, onSelection, onAction, date]);
147
- const clickHandler = (0, _react.useCallback)(event => {
148
- if (disabled) {
149
- return;
150
- }
151
-
152
- onSelection(date);
153
- onAction === null || onAction === void 0 ? void 0 : onAction(date, event);
154
- }, [disabled, onSelection, date, onAction]);
155
- return /*#__PURE__*/_react.default.createElement(DayComponent, {
156
- role: "button",
157
- blocked: blocked,
158
- disabled: disabled,
159
- selected: selected,
160
- onClick: clickHandler,
161
- onMouseEnter: () => onDayFocus(date),
162
- onFocus: () => onDayFocus(date),
163
- onBlur: () => onDayBlur(date),
164
- onKeyPress: keyPressHandler
165
- }, /*#__PURE__*/_react.default.createElement(_Text.default, null, date.getDate()));
166
- };
167
-
168
- exports.Day = Day;
169
- Day.displayName = "Day";
170
- const BlankDay = (0, _styledComponents.default)(DayBaseComponent).withConfig({
171
- displayName: "Day__BlankDay",
172
- componentId: "sc-1japneh-2"
173
- })(["background-color:", ";"], (0, _constants.get)('colors.canvas.primary'));
174
- exports.BlankDay = BlankDay;
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { FontSizeProps } from 'styled-system';
3
- import { SystemCommonProps, SystemLayoutProps } from '../constants';
4
- import { SxProp } from '../sx';
5
- export interface MonthProps extends FontSizeProps, SystemCommonProps, SxProp, SystemLayoutProps {
6
- month: number;
7
- year: number;
8
- }
9
- export declare const Month: React.FC<MonthProps>;
@@ -1,107 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Month = void 0;
7
-
8
- var _dateFns = require("date-fns");
9
-
10
- var _react = _interopRequireWildcard(require("react"));
11
-
12
- var _styledComponents = _interopRequireDefault(require("styled-components"));
13
-
14
- var _Box = _interopRequireDefault(require("../Box"));
15
-
16
- var _Text = _interopRequireDefault(require("../Text"));
17
-
18
- var _constants = require("../constants");
19
-
20
- var _Day = require("./Day");
21
-
22
- var _useDatePicker = _interopRequireDefault(require("./useDatePicker"));
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- 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); }
27
-
28
- 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; }
29
-
30
- const MonthComponent = (0, _styledComponents.default)(_Box.default).withConfig({
31
- displayName: "Month__MonthComponent",
32
- componentId: "l6j7o0-0"
33
- })(["display:grid;grid-auto-rows:min-content;grid-template-columns:repeat(1fr,7);grid-template-rows:1fr;gap:0px 0px;grid-template-areas:'month month month month month month month' 'sunday monday tuesday wednesday thursday friday saturday';justify-items:stretch;align-items:stretch;"]);
34
- const MonthTitle = (0, _styledComponents.default)(_Text.default).withConfig({
35
- displayName: "Month__MonthTitle",
36
- componentId: "l6j7o0-1"
37
- })(["font-size:", ";font-weight:", ";grid-area:month;justify-self:center;"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('fontWeights.bold'));
38
- const WeekdayHeader = (0, _styledComponents.default)(_Text.default).withConfig({
39
- displayName: "Month__WeekdayHeader",
40
- componentId: "l6j7o0-2"
41
- })(["color:", ";font-family:", ";font-size:", ";justify-self:center;padding:", " 0 ", ";"], (0, _constants.get)('colors.fg.subtle'), (0, _constants.get)('fonts.mono'), (0, _constants.get)('fontSizes.0'), (0, _constants.get)('space.3'), (0, _constants.get)('space.2'));
42
-
43
- const Month = ({
44
- month,
45
- year
46
- }) => {
47
- const {
48
- configuration
49
- } = (0, _useDatePicker.default)();
50
- const [selectedDay, setSelectedDay] = (0, _react.useState)(null);
51
- const getTitle = (0, _react.useMemo)(() => `${(0, _dateFns.format)(new Date(year, month), 'MMMM yyyy')}`, [month, year]);
52
- const weekdayHeaders = (0, _react.useMemo)(() => {
53
- const now = new Date(year, month);
54
- const weekOptions = {
55
- weekStartsOn: configuration.weekStartsOn === 'Sunday' ? 0 : 1
56
- };
57
- return (0, _dateFns.eachDayOfInterval)({
58
- start: (0, _dateFns.startOfWeek)(now, weekOptions),
59
- end: (0, _dateFns.endOfWeek)(now, weekOptions)
60
- }).map(d => /*#__PURE__*/_react.default.createElement(WeekdayHeader, {
61
- key: `weekday-${d}-header`
62
- }, (0, _dateFns.format)(d, 'EEEEEE')));
63
- }, [configuration.weekStartsOn, month, year]);
64
-
65
- const dayAction = date => {
66
- setSelectedDay(date);
67
- };
68
-
69
- const dayComponents = (0, _react.useMemo)(() => {
70
- const components = [];
71
- const firstDay = new Date(year, month, 1);
72
- const preBlanks = configuration.weekStartsOn === 'Sunday' ? firstDay.getDay() : (firstDay.getDay() + 6) % 7;
73
-
74
- for (let i = 0; i < preBlanks; i++) {
75
- components.push( /*#__PURE__*/_react.default.createElement(_Day.BlankDay, {
76
- key: `month-pre-blank-${i}`
77
- }));
78
- }
79
-
80
- for (let i = 1; i <= (0, _dateFns.getDaysInMonth)(firstDay); i++) {
81
- const date = new Date(year, month, i);
82
- components.push( /*#__PURE__*/_react.default.createElement(_Day.Day, {
83
- key: `day-component-${date.toString()}`,
84
- date: date,
85
- selected: selectedDay ? (0, _dateFns.isEqual)(date, selectedDay) : false,
86
- onAction: dayAction
87
- }));
88
- }
89
-
90
- const lastDay = (0, _dateFns.lastDayOfMonth)(firstDay);
91
- const postBlanks = configuration.weekStartsOn === 'Sunday' ? lastDay.getDay() : (lastDay.getDay() + 6) % 7;
92
-
93
- for (let i = 6; i > postBlanks; i--) {
94
- components.push( /*#__PURE__*/_react.default.createElement(_Day.BlankDay, {
95
- key: `month-post-blank-${i}`
96
- }));
97
- }
98
-
99
- return components;
100
- }, [configuration.weekStartsOn, month, selectedDay, year]);
101
- return /*#__PURE__*/_react.default.createElement(MonthComponent, {
102
- role: "grid"
103
- }, /*#__PURE__*/_react.default.createElement(MonthTitle, null, getTitle), weekdayHeaders, dayComponents);
104
- };
105
-
106
- exports.Month = Month;
107
- Month.displayName = "Month";
@@ -1,2 +0,0 @@
1
- export { DatePicker } from './DatePicker';
2
- export type { DatePickerProps } from './DatePicker';
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "DatePicker", {
7
- enumerable: true,
8
- get: function () {
9
- return _DatePicker.DatePicker;
10
- }
11
- });
12
-
13
- var _DatePicker = require("./DatePicker");
@@ -1,83 +0,0 @@
1
- import React from 'react';
2
- export declare type AnchorVariant = 'input' | 'button' | 'icon-only';
3
- export declare type DateFormat = 'short' | 'long' | string;
4
- export declare type SelectionVariant = 'single' | 'multi' | 'range';
5
- export interface DatePickerConfiguration {
6
- anchorVariant?: AnchorVariant;
7
- blockedDates?: Array<Date>;
8
- confirmation?: boolean;
9
- contiguousSelection?: boolean;
10
- dateFormat?: DateFormat;
11
- dimWeekends?: boolean;
12
- iconPlacement?: 'start' | 'end' | 'none';
13
- minDate?: Date;
14
- maxDate?: Date;
15
- placeholder?: string;
16
- rangeIncrement?: number;
17
- selection?: SelectionVariant;
18
- view?: '1-month' | '2-month';
19
- weekStartsOn?: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
20
- }
21
- export declare type RangeSelection = {
22
- from: Date;
23
- to: Date | null;
24
- };
25
- export declare type StringRangeSelection = {
26
- from: string;
27
- to: string;
28
- };
29
- export interface DatePickerContext {
30
- disabled?: boolean;
31
- configuration: DatePickerConfiguration;
32
- currentViewingDate: Date;
33
- goToMonth: (date: Date) => void;
34
- hoverRange?: RangeSelection | null;
35
- selection?: Selection;
36
- softSelection?: Partial<RangeSelection> | null;
37
- selectionActive?: boolean;
38
- formattedDate: string;
39
- nextMonth: () => void;
40
- onSelection: (date: Date) => void;
41
- onDayFocus: (date: Date) => void;
42
- onDayBlur: (date: Date) => void;
43
- previousMonth: () => void;
44
- revertValue: () => void;
45
- saveValue: (selection?: Selection) => void;
46
- }
47
- export declare type Selection = Date | Array<Date> | RangeSelection | null;
48
- export declare type StringSelection = string | Array<string> | {
49
- to: string;
50
- from: string;
51
- } | null;
52
- export declare type DaySelection = boolean | 'start' | 'middle' | 'end';
53
- declare const useDatePicker: (date?: Date | undefined) => {
54
- blocked: boolean | undefined;
55
- disabled: boolean;
56
- selected: DaySelection;
57
- configuration: DatePickerConfiguration;
58
- currentViewingDate: Date;
59
- goToMonth: (date: Date) => void;
60
- hoverRange?: RangeSelection | null | undefined;
61
- selection?: Selection | undefined;
62
- softSelection?: Partial<RangeSelection> | null | undefined;
63
- selectionActive?: boolean | undefined;
64
- formattedDate: string;
65
- nextMonth: () => void;
66
- onSelection: (date: Date) => void;
67
- onDayFocus: (date: Date) => void;
68
- onDayBlur: (date: Date) => void;
69
- previousMonth: () => void;
70
- revertValue: () => void;
71
- saveValue: (selection?: Selection | undefined) => void;
72
- };
73
- export default useDatePicker;
74
- export interface DatePickerProviderProps {
75
- closePicker?: () => void;
76
- configuration?: DatePickerConfiguration;
77
- value?: Selection | StringSelection;
78
- }
79
- export declare function isSingleSelection(selection: Selection): selection is Date;
80
- export declare function isMultiSelection(selection: Selection | StringSelection): selection is Array<Date> | Array<string>;
81
- export declare function isRangeSelection(selection: Selection | StringSelection): selection is RangeSelection | StringRangeSelection;
82
- export declare function isStringRangeSelection(selection: StringSelection): selection is StringRangeSelection;
83
- export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;