@primer/components 0.0.0-202192231947 → 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.
Files changed (175) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/codemods/deprecateUtilityComponents.js +1 -1
  3. package/dist/browser.esm.js +880 -770
  4. package/dist/browser.esm.js.map +1 -1
  5. package/dist/browser.umd.js +883 -773
  6. package/dist/browser.umd.js.map +1 -1
  7. package/lib/ActionList/Item.js +4 -4
  8. package/lib/ActionList/List.d.ts +2 -1
  9. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +6 -3
  10. package/lib/AnchoredOverlay/AnchoredOverlay.js +11 -3
  11. package/lib/Autocomplete/Autocomplete.d.ts +306 -0
  12. package/lib/Autocomplete/Autocomplete.js +145 -0
  13. package/lib/Autocomplete/AutocompleteContext.d.ts +17 -0
  14. package/lib/Autocomplete/AutocompleteContext.js +11 -0
  15. package/lib/Autocomplete/AutocompleteInput.d.ts +294 -0
  16. package/lib/Autocomplete/AutocompleteInput.js +157 -0
  17. package/lib/Autocomplete/AutocompleteMenu.d.ts +72 -0
  18. package/lib/Autocomplete/AutocompleteMenu.js +224 -0
  19. package/lib/Autocomplete/AutocompleteOverlay.d.ts +20 -0
  20. package/lib/Autocomplete/AutocompleteOverlay.js +80 -0
  21. package/lib/Autocomplete/index.d.ts +2 -0
  22. package/lib/Autocomplete/index.js +15 -0
  23. package/lib/BaseStyles.js +1 -1
  24. package/lib/BorderBox.js +1 -1
  25. package/lib/Button/Button.js +1 -1
  26. package/lib/Button/ButtonInvisible.js +1 -1
  27. package/lib/Button/ButtonTableList.js +1 -1
  28. package/lib/Caret.js +2 -2
  29. package/lib/DatePicker/DatePicker.js +10 -6
  30. package/lib/DatePicker/DatePickerAnchor.js +7 -2
  31. package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
  32. package/lib/DatePicker/DatePickerOverlay.js +39 -0
  33. package/lib/DatePicker/DatePickerPanel.js +92 -9
  34. package/lib/DatePicker/Day.js +2 -1
  35. package/lib/DatePicker/useDatePicker.d.ts +17 -2
  36. package/lib/DatePicker/useDatePicker.js +153 -50
  37. package/lib/Dialog.js +1 -1
  38. package/lib/FilteredActionList/FilteredActionList.js +5 -31
  39. package/lib/Flash.js +16 -16
  40. package/lib/Label.js +1 -1
  41. package/lib/Overlay.d.ts +1 -0
  42. package/lib/Overlay.js +3 -1
  43. package/lib/Pagination/Pagination.js +1 -1
  44. package/lib/ProgressBar.js +1 -1
  45. package/lib/SelectMenu/SelectMenu.d.ts +12 -10
  46. package/lib/StateLabel.js +13 -19
  47. package/lib/TextInput.d.ts +5 -13
  48. package/lib/TextInput.js +4 -46
  49. package/lib/TextInputWithTokens.d.ts +325 -0
  50. package/lib/TextInputWithTokens.js +245 -0
  51. package/lib/Token/AvatarToken.d.ts +7 -0
  52. package/lib/Token/AvatarToken.js +64 -0
  53. package/lib/Token/IssueLabelToken.d.ts +14 -0
  54. package/lib/Token/IssueLabelToken.js +144 -0
  55. package/lib/Token/Token.d.ts +15 -0
  56. package/lib/Token/Token.js +94 -0
  57. package/lib/Token/TokenBase.d.ts +31 -0
  58. package/lib/Token/TokenBase.js +108 -0
  59. package/lib/Token/_RemoveTokenButton.d.ts +12 -0
  60. package/lib/Token/_RemoveTokenButton.js +77 -0
  61. package/lib/Token/_TokenTextContainer.d.ts +3 -0
  62. package/lib/Token/_TokenTextContainer.js +17 -0
  63. package/lib/Token/index.d.ts +3 -0
  64. package/lib/Token/index.js +31 -0
  65. package/lib/_TextInputWrapper.d.ts +10 -0
  66. package/lib/_TextInputWrapper.js +51 -0
  67. package/lib/_UnstyledTextInput.d.ts +2 -0
  68. package/lib/_UnstyledTextInput.js +20 -0
  69. package/lib/behaviors/scrollIntoViewingArea.d.ts +1 -0
  70. package/lib/behaviors/scrollIntoViewingArea.js +39 -0
  71. package/lib/hooks/useOpenAndCloseFocus.d.ts +2 -1
  72. package/lib/hooks/useOpenAndCloseFocus.js +7 -2
  73. package/lib/hooks/useOverlay.d.ts +2 -1
  74. package/lib/hooks/useOverlay.js +4 -2
  75. package/lib/index.d.ts +5 -0
  76. package/lib/index.js +36 -0
  77. package/lib/theme-preval.js +372 -3102
  78. package/lib/utils/testing.d.ts +51 -494
  79. package/lib/utils/{types.d.ts → types/AriaRole.d.ts} +0 -13
  80. package/lib/utils/{types.js → types/AriaRole.js} +0 -0
  81. package/lib/utils/types/ComponentProps.d.ts +9 -0
  82. package/lib/utils/types/ComponentProps.js +1 -0
  83. package/lib/utils/types/Flatten.d.ts +4 -0
  84. package/lib/utils/types/Flatten.js +1 -0
  85. package/lib/utils/types/MandateProps.d.ts +3 -0
  86. package/lib/utils/types/MandateProps.js +1 -0
  87. package/lib/utils/types/Merge.d.ts +19 -0
  88. package/lib/utils/types/Merge.js +1 -0
  89. package/lib/utils/types/index.d.ts +5 -0
  90. package/lib/utils/types/index.js +70 -0
  91. package/lib-esm/ActionList/Item.js +4 -4
  92. package/lib-esm/ActionList/List.d.ts +2 -1
  93. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +6 -3
  94. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +11 -3
  95. package/lib-esm/Autocomplete/Autocomplete.d.ts +306 -0
  96. package/lib-esm/Autocomplete/Autocomplete.js +123 -0
  97. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +17 -0
  98. package/lib-esm/Autocomplete/AutocompleteContext.js +2 -0
  99. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +294 -0
  100. package/lib-esm/Autocomplete/AutocompleteInput.js +138 -0
  101. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +72 -0
  102. package/lib-esm/Autocomplete/AutocompleteMenu.js +205 -0
  103. package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +20 -0
  104. package/lib-esm/Autocomplete/AutocompleteOverlay.js +62 -0
  105. package/lib-esm/Autocomplete/index.d.ts +2 -0
  106. package/lib-esm/Autocomplete/index.js +1 -0
  107. package/lib-esm/BaseStyles.js +1 -1
  108. package/lib-esm/BorderBox.js +1 -1
  109. package/lib-esm/Button/Button.js +1 -1
  110. package/lib-esm/Button/ButtonInvisible.js +1 -1
  111. package/lib-esm/Button/ButtonTableList.js +1 -1
  112. package/lib-esm/Caret.js +2 -2
  113. package/lib-esm/DatePicker/DatePicker.js +9 -4
  114. package/lib-esm/DatePicker/DatePickerAnchor.js +7 -2
  115. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
  116. package/lib-esm/DatePicker/DatePickerOverlay.js +24 -0
  117. package/lib-esm/DatePicker/DatePickerPanel.js +86 -10
  118. package/lib-esm/DatePicker/Day.js +2 -1
  119. package/lib-esm/DatePicker/useDatePicker.d.ts +17 -2
  120. package/lib-esm/DatePicker/useDatePicker.js +154 -51
  121. package/lib-esm/Dialog.js +1 -1
  122. package/lib-esm/FilteredActionList/FilteredActionList.js +3 -31
  123. package/lib-esm/Flash.js +16 -16
  124. package/lib-esm/Label.js +1 -1
  125. package/lib-esm/Overlay.d.ts +1 -0
  126. package/lib-esm/Overlay.js +3 -1
  127. package/lib-esm/Pagination/Pagination.js +1 -1
  128. package/lib-esm/ProgressBar.js +1 -1
  129. package/lib-esm/SelectMenu/SelectMenu.d.ts +12 -10
  130. package/lib-esm/StateLabel.js +13 -19
  131. package/lib-esm/TextInput.d.ts +5 -13
  132. package/lib-esm/TextInput.js +4 -37
  133. package/lib-esm/TextInputWithTokens.d.ts +325 -0
  134. package/lib-esm/TextInputWithTokens.js +220 -0
  135. package/lib-esm/Token/AvatarToken.d.ts +7 -0
  136. package/lib-esm/Token/AvatarToken.js +43 -0
  137. package/lib-esm/Token/IssueLabelToken.d.ts +14 -0
  138. package/lib-esm/Token/IssueLabelToken.js +124 -0
  139. package/lib-esm/Token/Token.d.ts +15 -0
  140. package/lib-esm/Token/Token.js +73 -0
  141. package/lib-esm/Token/TokenBase.d.ts +31 -0
  142. package/lib-esm/Token/TokenBase.js +87 -0
  143. package/lib-esm/Token/_RemoveTokenButton.d.ts +12 -0
  144. package/lib-esm/Token/_RemoveTokenButton.js +60 -0
  145. package/lib-esm/Token/_TokenTextContainer.d.ts +3 -0
  146. package/lib-esm/Token/_TokenTextContainer.js +6 -0
  147. package/lib-esm/Token/index.d.ts +3 -0
  148. package/lib-esm/Token/index.js +3 -0
  149. package/lib-esm/_TextInputWrapper.d.ts +10 -0
  150. package/lib-esm/_TextInputWrapper.js +31 -0
  151. package/lib-esm/_UnstyledTextInput.d.ts +2 -0
  152. package/lib-esm/_UnstyledTextInput.js +7 -0
  153. package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +1 -0
  154. package/lib-esm/behaviors/scrollIntoViewingArea.js +30 -0
  155. package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +2 -1
  156. package/lib-esm/hooks/useOpenAndCloseFocus.js +7 -2
  157. package/lib-esm/hooks/useOverlay.d.ts +2 -1
  158. package/lib-esm/hooks/useOverlay.js +4 -2
  159. package/lib-esm/index.d.ts +5 -0
  160. package/lib-esm/index.js +3 -0
  161. package/lib-esm/theme-preval.js +372 -3102
  162. package/lib-esm/utils/testing.d.ts +51 -494
  163. package/lib-esm/utils/{types.d.ts → types/AriaRole.d.ts} +0 -13
  164. package/lib-esm/utils/{types.js → types/AriaRole.js} +0 -0
  165. package/lib-esm/utils/types/ComponentProps.d.ts +9 -0
  166. package/lib-esm/utils/types/ComponentProps.js +1 -0
  167. package/lib-esm/utils/types/Flatten.d.ts +4 -0
  168. package/lib-esm/utils/types/Flatten.js +1 -0
  169. package/lib-esm/utils/types/MandateProps.d.ts +3 -0
  170. package/lib-esm/utils/types/MandateProps.js +1 -0
  171. package/lib-esm/utils/types/Merge.d.ts +19 -0
  172. package/lib-esm/utils/types/Merge.js +1 -0
  173. package/lib-esm/utils/types/index.d.ts +5 -0
  174. package/lib-esm/utils/types/index.js +5 -0
  175. package/package.json +10 -9
@@ -1,39 +1,54 @@
1
- import { format, isEqual, isAfter, isBefore } from 'date-fns';
1
+ import { format, isEqual, isAfter, isBefore, addMonths, subMonths } from 'date-fns';
2
2
  import deepmerge from 'deepmerge';
3
3
  import React, { createContext, useCallback, useContext, useMemo, useEffect, useState } from 'react';
4
4
  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
@@ -56,7 +71,7 @@ export function isSingleSelection(selection) {
56
71
  return selection instanceof Date;
57
72
  }
58
73
  export function isMultiSelection(selection) {
59
- return Array.isArray(selection) && selection.every(d => d instanceof Date);
74
+ return Array.isArray(selection);
60
75
  }
61
76
  export function isRangeSelection(selection) {
62
77
  return !!selection.from;
@@ -65,24 +80,57 @@ export function isStringRangeSelection(selection) {
65
80
  return !!selection.from;
66
81
  }
67
82
 
68
- function parseSelection(selection) {
83
+ function parseSelection(selection, variant) {
69
84
  if (!selection) return;
70
85
 
71
- if (Array.isArray(selection)) {
72
- const parsedSelection = [];
86
+ if (variant === 'multi') {
87
+ if (isMultiSelection(selection)) {
88
+ const parsedSelection = [];
73
89
 
74
- for (const d of selection) {
75
- parsedSelection.push(new Date(new Date(d).toDateString()));
76
- }
90
+ for (const d of selection) {
91
+ parsedSelection.push(new Date(new Date(d).toDateString()));
92
+ }
77
93
 
78
- return parsedSelection.sort((a, b) => b.getMilliseconds() - a.getMilliseconds());
79
- } else if (isRangeSelection(selection)) {
80
- return {
81
- from: new Date(new Date(selection.from).toDateString()),
82
- to: selection.to ? new Date(new Date(selection.to).toDateString()) : null
83
- };
94
+ return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
95
+ } else if (selection instanceof Date) {
96
+ return [new Date(new Date(selection).toDateString())];
97
+ } else if (isRangeSelection(selection)) {
98
+ const parsedSelection = [];
99
+ parsedSelection.push(new Date(new Date(selection.from).toDateString()));
100
+
101
+ if (selection.to) {
102
+ parsedSelection.push(new Date(new Date(selection.to).toDateString()));
103
+ }
104
+
105
+ return parsedSelection.sort((a, b) => a.getTime() - b.getTime());
106
+ }
107
+ } else if (variant === 'range') {
108
+ if (isRangeSelection(selection)) {
109
+ return {
110
+ from: new Date(new Date(selection.from).toDateString()),
111
+ to: selection.to ? new Date(new Date(selection.to).toDateString()) : null
112
+ };
113
+ } else if (isMultiSelection(selection)) {
114
+ return {
115
+ from: new Date(new Date(selection[0]).toDateString()),
116
+ to: selection[1] ? new Date(new Date(selection[1]).toDateString()) : null
117
+ };
118
+ } else if (selection instanceof Date) {
119
+ return {
120
+ from: new Date(new Date(selection).toDateString()),
121
+ to: null
122
+ };
123
+ }
84
124
  } else {
85
- return new Date(new Date(selection).toDateString());
125
+ if (selection instanceof Date) {
126
+ return new Date(new Date(selection).toDateString());
127
+ } else if (isMultiSelection(selection)) {
128
+ return new Date(new Date(selection[0]).toDateString());
129
+ } else if (isRangeSelection(selection)) {
130
+ return new Date(new Date(selection.from).toDateString());
131
+ } else {
132
+ return;
133
+ }
86
134
  }
87
135
  }
88
136
 
@@ -102,11 +150,24 @@ export const DatePickerProvider = ({
102
150
  value
103
151
  }) => {
104
152
  const [configuration, setConfiguration] = useState(deepmerge(defaultConfiguration, externalConfig));
105
- const [selection, setSelection] = useState(parseSelection(value));
153
+ const [previousSelection, setPreviousSelection] = useState(parseSelection(value, configuration.selection));
154
+ const [selection, setSelection] = useState(parseSelection(value, configuration.selection));
106
155
  const [hoverRange, setHoverRange] = useState(null);
156
+ const [currentViewingDate, setCurrentViewingDate] = useState(new Date());
107
157
  useEffect(() => {
108
158
  setConfiguration(deepmerge(defaultConfiguration, externalConfig));
109
- }, [externalConfig]);
159
+ setSelection(parseSelection(selection, configuration.selection)); // Don't want this to run every time selection gets updated
160
+ // eslint-disable-next-line react-hooks/exhaustive-deps
161
+ }, [configuration.selection, externalConfig]);
162
+ const goToMonth = useCallback(date => {
163
+ setCurrentViewingDate(new Date(new Date(date).toDateString()));
164
+ }, []);
165
+ const nextMonth = useCallback(() => {
166
+ setCurrentViewingDate(addMonths(currentViewingDate, 1));
167
+ }, [currentViewingDate]);
168
+ const previousMonth = useCallback(() => {
169
+ setCurrentViewingDate(subMonths(currentViewingDate, 1));
170
+ }, [currentViewingDate]);
110
171
  const getFormattedDate = useMemo(() => {
111
172
  if (!selection) {
112
173
  return configuration.placeholder;
@@ -135,6 +196,10 @@ export const DatePickerProvider = ({
135
196
  {
136
197
  if (selection instanceof Date) {
137
198
  return format(selection, template);
199
+ } else if (Array.isArray(selection)) {
200
+ return format(selection[0], template);
201
+ } else if (isRangeSelection(selection)) {
202
+ return format(selection.from, template);
138
203
  } else {
139
204
  return 'Invalid Selection';
140
205
  }
@@ -143,7 +208,13 @@ export const DatePickerProvider = ({
143
208
  case 'multi':
144
209
  {
145
210
  if (Array.isArray(selection)) {
146
- return selection.map(d => format(d, template)).join(', ');
211
+ if (selection.length > 3) return `${selection.length} Selected`;
212
+ const formatted = selection.map(d => format(d, template)).join(', ');
213
+ return formatted;
214
+ } else if (selection instanceof Date) {
215
+ return [selection].map(d => format(d, template)).join(', ');
216
+ } else if (isRangeSelection(selection)) {
217
+ return [selection.to, selection.from].map(d => d ? format(d, template) : '').join(', ');
147
218
  } else {
148
219
  return 'Invalid Selection';
149
220
  }
@@ -153,6 +224,18 @@ export const DatePickerProvider = ({
153
224
  {
154
225
  if (isRangeSelection(selection)) {
155
226
  return Object.entries(selection).map(([_, date]) => date ? format(date, template) : '').join(' - ');
227
+ } else if (selection instanceof Date) {
228
+ return Object.entries({
229
+ from: selection,
230
+ to: null
231
+ }).map(([_, date]) => date ? format(date, template) : '').join(' - ');
232
+ } else if (Array.isArray(selection)) {
233
+ return Object.entries({
234
+ from: selection[0],
235
+ to: selection[1]
236
+ }) // to date can still be null
237
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
238
+ .map(([_, date]) => date ? format(date, template) : '').join(' - ');
156
239
  } else {
157
240
  return 'Invalid Selection';
158
241
  }
@@ -164,30 +247,41 @@ export const DatePickerProvider = ({
164
247
  }
165
248
  }
166
249
  }, [configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
250
+ const saveValue = useCallback(updatedSelection => {
251
+ setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
252
+ closePicker === null || closePicker === void 0 ? void 0 : closePicker();
253
+ }, [closePicker, selection]);
167
254
  const selectionHandler = useCallback(date => {
168
255
  if (configuration.selection === 'multi') {
169
- const selections = selection;
256
+ const selections = [...selection];
170
257
  const existingIndex = selections.findIndex(s => isEqual(s, date));
171
258
 
172
259
  if (existingIndex > -1) {
173
- setSelection(selections.splice(existingIndex, 1));
260
+ selections.splice(existingIndex, 1);
261
+ setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
174
262
  } else {
175
- setSelection([...selections, date]);
263
+ setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
176
264
  }
177
265
  } else if (configuration.selection === 'range') {
178
266
  if (selection && isRangeSelection(selection) && !selection.to) {
179
- setSelection(isBefore(date, selection.from) ? {
267
+ const updatedSelection = isBefore(date, selection.from) ? {
180
268
  from: date,
181
269
  to: selection.from
182
270
  } : {
183
271
  from: selection.from,
184
272
  to: date
185
- });
273
+ };
274
+ setSelection(updatedSelection);
275
+ setHoverRange(null);
186
276
 
187
277
  if (!configuration.confirmation) {
188
- closePicker === null || closePicker === void 0 ? void 0 : closePicker();
278
+ saveValue(updatedSelection);
189
279
  }
190
280
  } else {
281
+ setHoverRange({
282
+ from: date,
283
+ to: date
284
+ });
191
285
  setSelection({
192
286
  from: date,
193
287
  to: null
@@ -197,14 +291,14 @@ export const DatePickerProvider = ({
197
291
  setSelection(date);
198
292
 
199
293
  if (!configuration.confirmation) {
200
- closePicker === null || closePicker === void 0 ? void 0 : closePicker();
294
+ saveValue(date);
201
295
  }
202
296
  }
203
- }, [closePicker, configuration.confirmation, configuration.selection, selection]);
297
+ }, [configuration.confirmation, configuration.selection, saveValue, selection]);
204
298
  const focusHnadler = useCallback(date => {
205
299
  if (!selection) return;
206
300
 
207
- if (configuration.selection === 'range' && isRangeSelection(selection)) {
301
+ if (configuration.selection === 'range' && isRangeSelection(selection) && hoverRange) {
208
302
  setHoverRange(isBefore(date, selection.from) ? {
209
303
  from: date,
210
304
  to: selection.from
@@ -213,26 +307,35 @@ export const DatePickerProvider = ({
213
307
  to: date
214
308
  });
215
309
  }
216
- }, [configuration.selection, selection]);
310
+ }, [configuration.selection, hoverRange, selection]);
217
311
  const blurHnadler = useCallback(date => {
218
312
  if (!selection || !hoverRange) return;
219
313
 
220
- if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {
221
- setHoverRange(null);
314
+ if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {// setHoverRange({from: hoverRange.from, to: hoverRange.from})
222
315
  }
223
316
  }, [configuration.selection, hoverRange, selection]);
317
+ const revertValue = useCallback(() => {
318
+ setSelection(previousSelection);
319
+ }, [previousSelection]);
224
320
  const datePickerCtx = useMemo(() => {
225
321
  return {
226
322
  configuration,
323
+ currentViewingDate,
227
324
  disabled: false,
228
325
  formattedDate: getFormattedDate,
326
+ goToMonth,
327
+ hoverRange,
328
+ nextMonth,
229
329
  onDayBlur: blurHnadler,
230
330
  onDayFocus: focusHnadler,
231
331
  onSelection: selectionHandler,
332
+ previousMonth,
333
+ revertValue,
334
+ saveValue,
232
335
  selectionActive: false,
233
336
  selection
234
337
  };
235
- }, [blurHnadler, configuration, focusHnadler, getFormattedDate, selection, selectionHandler]);
338
+ }, [blurHnadler, configuration, currentViewingDate, focusHnadler, getFormattedDate, goToMonth, hoverRange, nextMonth, previousMonth, revertValue, saveValue, selection, selectionHandler]);
236
339
  return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
237
340
  value: datePickerCtx
238
341
  }, children);
package/lib-esm/Dialog.js CHANGED
@@ -98,7 +98,7 @@ const Dialog = /*#__PURE__*/forwardRef(({
98
98
  }), children)) : null;
99
99
  });
100
100
  DialogHeader.defaultProps = {
101
- backgroundColor: 'bg.tertiary'
101
+ backgroundColor: 'canvas.subtle'
102
102
  };
103
103
  DialogHeader.propTypes = { ...Box.propTypes
104
104
  };
@@ -1,6 +1,7 @@
1
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import React, { useCallback, useEffect, useRef } from 'react';
4
+ import { useSSRSafeId } from '@react-aria/ssr';
4
5
  import TextInput from '../TextInput';
5
6
  import Box from '../Box';
6
7
  import { ActionList } from '../ActionList';
@@ -11,36 +12,7 @@ import styled from 'styled-components';
11
12
  import { get } from '../constants';
12
13
  import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate';
13
14
  import useScrollFlash from '../hooks/useScrollFlash';
14
- import { useSSRSafeId } from '@react-aria/ssr';
15
-
16
- function scrollIntoViewingArea(child, container, margin = 8, behavior = 'smooth') {
17
- const {
18
- top: childTop,
19
- bottom: childBottom
20
- } = child.getBoundingClientRect();
21
- const {
22
- top: containerTop,
23
- bottom: containerBottom
24
- } = container.getBoundingClientRect();
25
- const isChildTopAboveViewingArea = childTop < containerTop + margin;
26
- const isChildBottomBelowViewingArea = childBottom > containerBottom - margin;
27
-
28
- if (isChildTopAboveViewingArea) {
29
- const scrollHeightToChildTop = childTop - containerTop + container.scrollTop;
30
- container.scrollTo({
31
- behavior,
32
- top: scrollHeightToChildTop - margin
33
- });
34
- } else if (isChildBottomBelowViewingArea) {
35
- const scrollHeightToChildBottom = childBottom - containerBottom + container.scrollTop;
36
- container.scrollTo({
37
- behavior,
38
- top: scrollHeightToChildBottom + margin
39
- });
40
- } // either completely in view or outside viewing area on both ends, don't scroll
41
-
42
- }
43
-
15
+ import { scrollIntoViewingArea } from '../behaviors/scrollIntoViewingArea';
44
16
  const StyledHeader = styled.div.withConfig({
45
17
  displayName: "FilteredActionList__StyledHeader",
46
18
  componentId: "yg3jkv-0"
@@ -95,7 +67,7 @@ export function FilteredActionList({
95
67
  useEffect(() => {
96
68
  // if items changed, we want to instantly move active descendant into view
97
69
  if (activeDescendantRef.current && scrollContainerRef.current) {
98
- scrollIntoViewingArea(activeDescendantRef.current, scrollContainerRef.current, undefined, 'auto');
70
+ scrollIntoViewingArea(activeDescendantRef.current, scrollContainerRef.current, 'vertical', undefined, undefined, 'auto');
99
71
  }
100
72
  }, [items]);
101
73
  useScrollFlash(scrollContainerRef);
package/lib-esm/Flash.js CHANGED
@@ -5,35 +5,35 @@ import sx from './sx';
5
5
  const variants = variant({
6
6
  variants: {
7
7
  default: {
8
- color: 'alert.info.text',
9
- backgroundColor: 'alert.info.bg',
10
- borderColor: 'alert.info.border',
8
+ color: 'fg.default',
9
+ backgroundColor: 'accent.subtle',
10
+ borderColor: 'accent.muted',
11
11
  svg: {
12
- color: 'alert.info.icon'
12
+ color: 'accent.fg'
13
13
  }
14
14
  },
15
15
  success: {
16
- color: 'alert.success.text',
17
- backgroundColor: 'alert.success.bg',
18
- borderColor: 'alert.success.border',
16
+ color: 'fg.default',
17
+ backgroundColor: 'success.subtle',
18
+ borderColor: 'success.muted',
19
19
  svg: {
20
- color: 'alert.success.icon'
20
+ color: 'success.fg'
21
21
  }
22
22
  },
23
23
  danger: {
24
- color: 'alert.error.text',
25
- backgroundColor: 'alert.error.bg',
26
- borderColor: 'alert.error.border',
24
+ color: 'fg.default',
25
+ backgroundColor: 'danger.subtle',
26
+ borderColor: 'danger.muted',
27
27
  svg: {
28
- color: 'alert.error.icon'
28
+ color: 'danger.fg'
29
29
  }
30
30
  },
31
31
  warning: {
32
- color: 'alert.warn.text',
33
- backgroundColor: 'alert.warn.bg',
34
- borderColor: 'alert.warn.border',
32
+ color: 'fg.default',
33
+ backgroundColor: 'attention.subtle',
34
+ borderColor: 'attention.muted',
35
35
  svg: {
36
- color: 'alert.warn.icon'
36
+ color: 'attention.fg'
37
37
  }
38
38
  }
39
39
  }
package/lib-esm/Label.js CHANGED
@@ -33,7 +33,7 @@ const Label = styled.span.withConfig({
33
33
  componentId: "sc-1t3ykp0-0"
34
34
  })(["display:inline-block;font-weight:", ";color:", ";border-radius:", ";&:hover{text-decoration:none;}", " ", " ", " ", " ", ""], get('fontWeights.semibold'), get('colors.fg.onEmphasis'), get('radii.3'), sizeVariant, COMMON, props => props.dropshadow ? 'box-shadow: inset 0 -1px 0 rgba(27, 31, 35, 0.12)' : '', props => props.outline ? outlineStyles : '', sx);
35
35
  Label.defaultProps = {
36
- bg: 'label.primary.border',
36
+ bg: 'neutral.emphasis',
37
37
  variant: 'medium'
38
38
  };
39
39
  export default Label;
@@ -40,6 +40,7 @@ export declare type OverlayProps = {
40
40
  top: number;
41
41
  left: number;
42
42
  portalContainerName?: string;
43
+ preventFocusOnOpen?: boolean;
43
44
  } & Omit<ComponentProps<typeof StyledOverlay>, 'visibility' | keyof SystemPositionProps>;
44
45
  /**
45
46
  * An `Overlay` is a flexible floating surface, used to display transient content such as menus,
@@ -92,6 +92,7 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
92
92
  left,
93
93
  anchorSide,
94
94
  portalContainerName,
95
+ preventFocusOnOpen,
95
96
  ...rest
96
97
  }, forwardedRef) => {
97
98
  const overlayRef = useRef(null);
@@ -107,7 +108,8 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
107
108
  onEscape,
108
109
  ignoreClickRefs,
109
110
  onClickOutside,
110
- initialFocusRef
111
+ initialFocusRef,
112
+ preventFocusOnOpen
111
113
  });
112
114
  useEffect(() => {
113
115
  var _combinedRef$current;
@@ -9,7 +9,7 @@ import { buildComponentData, buildPaginationModel } from './model';
9
9
  const Page = styled.a.withConfig({
10
10
  displayName: "Pagination__Page",
11
11
  componentId: "b80nss-0"
12
- })(["display:inline-block;min-width:32px;padding:5px 10px;font-style:normal;line-height:20px;color:", ";text-align:center;white-space:nowrap;vertical-align:middle;cursor:pointer;user-select:none;text-decoration:none;margin-right:", ";&:last-child{margin-right:0;}border:", " solid transparent;border-radius:", ";transition:border-color 0.2s cubic-bezier(0.3,0,0.5,1);&:hover,&:focus{text-decoration:none;border-color:", ";outline:0;transition-duration:0.1s;}&:active{border-color:", ";}&[rel='prev'],&[rel='next']{color:", ";}&[aria-current],&[aria-current]:hover{color:", ";background-color:", ";border-color:transparent;}&[aria-disabled],&[aria-disabled]:hover{color:", ";cursor:default;border-color:transparent;}@supports (clip-path:polygon(50% 0,100% 50%,50% 100%)){&[rel='prev']::before,&[rel='next']::after{display:inline-block;width:16px;height:16px;vertical-align:text-bottom;content:'';background-color:currentColor;}&[rel='prev']::before{margin-right:", ";clip-path:polygon( 9.8px 12.8px,8.7px 12.8px,4.5px 8.5px,4.5px 7.5px,8.7px 3.2px,9.8px 4.3px,6.1px 8px,9.8px 11.7px,9.8px 12.8px );}&[rel='next']::after{margin-left:", ";clip-path:polygon( 6.2px 3.2px,7.3px 3.2px,11.5px 7.5px,11.5px 8.5px,7.3px 12.8px,6.2px 11.7px,9.9px 8px,6.2px 4.3px,6.2px 3.2px );}}", ";"], get('colors.fg.default'), get('space.1'), get('borderWidths.1'), get('radii.2'), get('colors.border.default'), get('colors.border.muted'), get('colors.accent.fg'), get('colors.fg.onEmphasis'), get('colors.accent.emphasis'), get('colors.fg.muted'), get('space.1'), get('space.1'), COMMON);
12
+ })(["display:inline-block;min-width:32px;padding:5px 10px;font-style:normal;line-height:20px;color:", ";text-align:center;white-space:nowrap;vertical-align:middle;cursor:pointer;user-select:none;text-decoration:none;margin-right:", ";&:last-child{margin-right:0;}border:", " solid transparent;border-radius:", ";transition:border-color 0.2s cubic-bezier(0.3,0,0.5,1);&:hover,&:focus{text-decoration:none;border-color:", ";outline:0;transition-duration:0.1s;}&:active{border-color:", ";}&[rel='prev'],&[rel='next']{color:", ";}&[aria-current],&[aria-current]:hover{color:", ";background-color:", ";border-color:transparent;}&[aria-disabled],&[aria-disabled]:hover{color:", ";cursor:default;border-color:transparent;}@supports (clip-path:polygon(50% 0,100% 50%,50% 100%)){&[rel='prev']::before,&[rel='next']::after{display:inline-block;width:16px;height:16px;vertical-align:text-bottom;content:'';background-color:currentColor;}&[rel='prev']::before{margin-right:", ";clip-path:polygon( 9.8px 12.8px,8.7px 12.8px,4.5px 8.5px,4.5px 7.5px,8.7px 3.2px,9.8px 4.3px,6.1px 8px,9.8px 11.7px,9.8px 12.8px );}&[rel='next']::after{margin-left:", ";clip-path:polygon( 6.2px 3.2px,7.3px 3.2px,11.5px 7.5px,11.5px 8.5px,7.3px 12.8px,6.2px 11.7px,9.9px 8px,6.2px 4.3px,6.2px 3.2px );}}", ";"], get('colors.fg.default'), get('space.1'), get('borderWidths.1'), get('radii.2'), get('colors.border.default'), get('colors.border.muted'), get('colors.accent.fg'), get('colors.fg.onEmphasis'), get('colors.accent.emphasis'), get('colors.primer.fg.disabled'), get('space.1'), get('space.1'), COMMON);
13
13
 
14
14
  function usePaginationPages({
15
15
  theme,
@@ -36,7 +36,7 @@ function ProgressBar({
36
36
 
37
37
  ProgressBar.displayName = "ProgressBar";
38
38
  ProgressBar.defaultProps = {
39
- bg: 'bg.successInverse',
39
+ bg: 'success.emphasis',
40
40
  barSize: 'default'
41
41
  };
42
42
  export default ProgressBar;
@@ -32,7 +32,17 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
32
32
  Divider: import("styled-components").StyledComponent<"div", any, SystemCommonProps & SxProp, never>;
33
33
  Filter: React.ForwardRefExoticComponent<Pick<{
34
34
  value?: string | undefined;
35
- } & Pick<{
35
+ } & Pick<Omit<Pick<({
36
+ [x: string]: any;
37
+ [x: number]: any;
38
+ } & {
39
+ theme?: any;
40
+ } & ({} | {
41
+ children?: React.ReactNode;
42
+ })) & {
43
+ as?: string | React.ComponentType<any> | undefined;
44
+ forwardedAs?: string | React.ComponentType<any> | undefined;
45
+ }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
36
46
  className?: string | undefined;
37
47
  icon?: React.ComponentType<{
38
48
  className?: string | undefined;
@@ -307,15 +317,7 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
307
317
  contrast?: boolean | undefined;
308
318
  } & {
309
319
  theme?: any;
310
- }, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "sx" | "disabled" | "variant" | "contrast"> & Omit<Pick<{
311
- [x: string]: any;
312
- [x: number]: any;
313
- } & {
314
- theme?: any;
315
- } & {
316
- as?: string | React.ComponentType<any> | undefined;
317
- forwardedAs?: string | React.ComponentType<any> | undefined;
318
- }, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
320
+ }, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "sx" | "disabled" | "variant" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
319
321
  Footer: import("styled-components").StyledComponent<"footer", any, SystemCommonProps & SxProp, never>;
320
322
  Item: React.ForwardRefExoticComponent<Pick<{
321
323
  as?: React.ElementType<any> | undefined;
@@ -19,34 +19,28 @@ const colorVariants = variant({
19
19
  prop: 'status',
20
20
  variants: {
21
21
  issueClosed: {
22
- backgroundColor: 'prState.closed.bg',
23
- color: 'prState.closed.text',
24
- borderColor: 'prState.closed.border'
22
+ backgroundColor: 'danger.emphasis',
23
+ color: 'fg.onEmphasis'
25
24
  },
26
25
  pullClosed: {
27
- backgroundColor: 'prState.closed.bg',
28
- color: 'prState.closed.text',
29
- borderColor: 'prState.closed.border'
26
+ backgroundColor: 'danger.emphasis',
27
+ color: 'fg.onEmphasis'
30
28
  },
31
29
  pullMerged: {
32
- backgroundColor: 'prState.merged.bg',
33
- color: 'prState.merged.text',
34
- borderColor: 'prState.merged.border'
30
+ backgroundColor: 'done.emphasis',
31
+ color: 'fg.onEmphasis'
35
32
  },
36
33
  issueOpened: {
37
- backgroundColor: 'prState.open.bg',
38
- color: 'prState.open.text',
39
- borderColor: 'prState.open.border'
34
+ backgroundColor: 'success.emphasis',
35
+ color: 'fg.onEmphasis'
40
36
  },
41
37
  pullOpened: {
42
- backgroundColor: 'prState.open.bg',
43
- color: 'prState.open.text',
44
- borderColor: 'prState.open.border'
38
+ backgroundColor: 'success.emphasis',
39
+ color: 'fg.onEmphasis'
45
40
  },
46
41
  draft: {
47
- backgroundColor: 'prState.draft.bg',
48
- color: 'prState.draft.text',
49
- borderColor: 'prState.draft.border'
42
+ backgroundColor: 'neutral.emphasis',
43
+ color: 'fg.onEmphasis'
50
44
  }
51
45
  }
52
46
  });
@@ -68,7 +62,7 @@ const sizeVariants = variant({
68
62
  const StateLabelBase = styled.span.withConfig({
69
63
  displayName: "StateLabel__StateLabelBase",
70
64
  componentId: "k4pd9e-0"
71
- })(["display:inline-flex;align-items:center;font-weight:", ";line-height:16px;color:", ";text-align:center;border-radius:", ";border-width:1px;border-style:solid;", ";", ";", ";", ";"], get('fontWeights.bold'), get('colors.canvas.default'), get('radii.3'), colorVariants, sizeVariants, COMMON, sx);
65
+ })(["display:inline-flex;align-items:center;font-weight:", ";line-height:16px;color:", ";text-align:center;border-radius:", ";", ";", ";", ";", ";"], get('fontWeights.bold'), get('colors.canvas.default'), get('radii.3'), colorVariants, sizeVariants, COMMON, sx);
72
66
 
73
67
  function StateLabel({
74
68
  children,
@@ -1,22 +1,14 @@
1
1
  import React from 'react';
2
- import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
3
- import { SxProp } from './sx';
4
- import { ComponentProps } from './utils/types';
5
- declare const Input: import("styled-components").StyledComponent<"input", any, {}, never>;
6
- declare const Wrapper: import("styled-components").StyledComponent<"span", any, {
7
- disabled?: boolean | undefined;
8
- hasIcon?: boolean | undefined;
9
- block?: boolean | undefined;
10
- contrast?: boolean | undefined;
11
- variant?: "large" | "small" | undefined;
12
- } & WidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Width<import("styled-system").TLengthStyledSystem>> & MinWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MinWidth<import("styled-system").TLengthStyledSystem>> & MaxWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>> & SxProp, never>;
2
+ import { ComponentProps, Merge } from './utils/types';
3
+ import UnstyledTextInput from './_UnstyledTextInput';
4
+ import TextInputWrapper from './_TextInputWrapper';
13
5
  declare type NonPassthroughProps = {
14
6
  className?: string;
15
7
  icon?: React.ComponentType<{
16
8
  className?: string;
17
9
  }>;
18
- } & Pick<ComponentProps<typeof Wrapper>, 'block' | 'contrast' | 'disabled' | 'sx' | 'theme' | 'width' | 'maxWidth' | 'minWidth' | 'variant'>;
19
- declare type TextInputInternalProps = NonPassthroughProps & Omit<React.ComponentPropsWithoutRef<typeof Input>, keyof NonPassthroughProps>;
10
+ } & Pick<ComponentProps<typeof TextInputWrapper>, 'block' | 'contrast' | 'disabled' | 'sx' | 'theme' | 'width' | 'maxWidth' | 'minWidth' | 'variant'>;
11
+ declare type TextInputInternalProps = Merge<React.ComponentPropsWithoutRef<typeof UnstyledTextInput>, NonPassthroughProps>;
20
12
  declare const TextInput: React.ForwardRefExoticComponent<Pick<TextInputInternalProps, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
21
13
  export declare type TextInputProps = ComponentProps<typeof TextInput>;
22
14
  export default TextInput;