@primer/components 0.0.0-202192231947 → 0.0.0-202192543046

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 (177) 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 +14 -8
  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/Month.js +16 -6
  36. package/lib/DatePicker/useDatePicker.d.ts +18 -2
  37. package/lib/DatePicker/useDatePicker.js +155 -51
  38. package/lib/Dialog.js +1 -1
  39. package/lib/FilteredActionList/FilteredActionList.js +5 -31
  40. package/lib/Flash.js +16 -16
  41. package/lib/Label.js +1 -1
  42. package/lib/Overlay.d.ts +1 -0
  43. package/lib/Overlay.js +3 -1
  44. package/lib/Pagination/Pagination.js +1 -1
  45. package/lib/ProgressBar.js +1 -1
  46. package/lib/SelectMenu/SelectMenu.d.ts +12 -10
  47. package/lib/StateLabel.js +13 -19
  48. package/lib/TextInput.d.ts +5 -13
  49. package/lib/TextInput.js +4 -46
  50. package/lib/TextInputWithTokens.d.ts +325 -0
  51. package/lib/TextInputWithTokens.js +245 -0
  52. package/lib/Token/AvatarToken.d.ts +7 -0
  53. package/lib/Token/AvatarToken.js +64 -0
  54. package/lib/Token/IssueLabelToken.d.ts +14 -0
  55. package/lib/Token/IssueLabelToken.js +144 -0
  56. package/lib/Token/Token.d.ts +15 -0
  57. package/lib/Token/Token.js +94 -0
  58. package/lib/Token/TokenBase.d.ts +31 -0
  59. package/lib/Token/TokenBase.js +108 -0
  60. package/lib/Token/_RemoveTokenButton.d.ts +12 -0
  61. package/lib/Token/_RemoveTokenButton.js +77 -0
  62. package/lib/Token/_TokenTextContainer.d.ts +3 -0
  63. package/lib/Token/_TokenTextContainer.js +17 -0
  64. package/lib/Token/index.d.ts +3 -0
  65. package/lib/Token/index.js +31 -0
  66. package/lib/_TextInputWrapper.d.ts +10 -0
  67. package/lib/_TextInputWrapper.js +51 -0
  68. package/lib/_UnstyledTextInput.d.ts +2 -0
  69. package/lib/_UnstyledTextInput.js +20 -0
  70. package/lib/behaviors/scrollIntoViewingArea.d.ts +1 -0
  71. package/lib/behaviors/scrollIntoViewingArea.js +39 -0
  72. package/lib/hooks/useOpenAndCloseFocus.d.ts +2 -1
  73. package/lib/hooks/useOpenAndCloseFocus.js +7 -2
  74. package/lib/hooks/useOverlay.d.ts +2 -1
  75. package/lib/hooks/useOverlay.js +4 -2
  76. package/lib/index.d.ts +5 -0
  77. package/lib/index.js +36 -0
  78. package/lib/theme-preval.js +372 -3102
  79. package/lib/utils/testing.d.ts +51 -494
  80. package/lib/utils/{types.d.ts → types/AriaRole.d.ts} +0 -13
  81. package/lib/utils/{types.js → types/AriaRole.js} +0 -0
  82. package/lib/utils/types/ComponentProps.d.ts +9 -0
  83. package/lib/utils/types/ComponentProps.js +1 -0
  84. package/lib/utils/types/Flatten.d.ts +4 -0
  85. package/lib/utils/types/Flatten.js +1 -0
  86. package/lib/utils/types/MandateProps.d.ts +3 -0
  87. package/lib/utils/types/MandateProps.js +1 -0
  88. package/lib/utils/types/Merge.d.ts +19 -0
  89. package/lib/utils/types/Merge.js +1 -0
  90. package/lib/utils/types/index.d.ts +5 -0
  91. package/lib/utils/types/index.js +70 -0
  92. package/lib-esm/ActionList/Item.js +4 -4
  93. package/lib-esm/ActionList/List.d.ts +2 -1
  94. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +6 -3
  95. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +11 -3
  96. package/lib-esm/Autocomplete/Autocomplete.d.ts +306 -0
  97. package/lib-esm/Autocomplete/Autocomplete.js +123 -0
  98. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +17 -0
  99. package/lib-esm/Autocomplete/AutocompleteContext.js +2 -0
  100. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +294 -0
  101. package/lib-esm/Autocomplete/AutocompleteInput.js +138 -0
  102. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +72 -0
  103. package/lib-esm/Autocomplete/AutocompleteMenu.js +205 -0
  104. package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +20 -0
  105. package/lib-esm/Autocomplete/AutocompleteOverlay.js +62 -0
  106. package/lib-esm/Autocomplete/index.d.ts +2 -0
  107. package/lib-esm/Autocomplete/index.js +1 -0
  108. package/lib-esm/BaseStyles.js +1 -1
  109. package/lib-esm/BorderBox.js +1 -1
  110. package/lib-esm/Button/Button.js +1 -1
  111. package/lib-esm/Button/ButtonInvisible.js +1 -1
  112. package/lib-esm/Button/ButtonTableList.js +1 -1
  113. package/lib-esm/Caret.js +2 -2
  114. package/lib-esm/DatePicker/DatePicker.js +13 -6
  115. package/lib-esm/DatePicker/DatePickerAnchor.js +7 -2
  116. package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
  117. package/lib-esm/DatePicker/DatePickerOverlay.js +24 -0
  118. package/lib-esm/DatePicker/DatePickerPanel.js +86 -10
  119. package/lib-esm/DatePicker/Day.js +2 -1
  120. package/lib-esm/DatePicker/Month.js +15 -6
  121. package/lib-esm/DatePicker/useDatePicker.d.ts +18 -2
  122. package/lib-esm/DatePicker/useDatePicker.js +156 -52
  123. package/lib-esm/Dialog.js +1 -1
  124. package/lib-esm/FilteredActionList/FilteredActionList.js +3 -31
  125. package/lib-esm/Flash.js +16 -16
  126. package/lib-esm/Label.js +1 -1
  127. package/lib-esm/Overlay.d.ts +1 -0
  128. package/lib-esm/Overlay.js +3 -1
  129. package/lib-esm/Pagination/Pagination.js +1 -1
  130. package/lib-esm/ProgressBar.js +1 -1
  131. package/lib-esm/SelectMenu/SelectMenu.d.ts +12 -10
  132. package/lib-esm/StateLabel.js +13 -19
  133. package/lib-esm/TextInput.d.ts +5 -13
  134. package/lib-esm/TextInput.js +4 -37
  135. package/lib-esm/TextInputWithTokens.d.ts +325 -0
  136. package/lib-esm/TextInputWithTokens.js +220 -0
  137. package/lib-esm/Token/AvatarToken.d.ts +7 -0
  138. package/lib-esm/Token/AvatarToken.js +43 -0
  139. package/lib-esm/Token/IssueLabelToken.d.ts +14 -0
  140. package/lib-esm/Token/IssueLabelToken.js +124 -0
  141. package/lib-esm/Token/Token.d.ts +15 -0
  142. package/lib-esm/Token/Token.js +73 -0
  143. package/lib-esm/Token/TokenBase.d.ts +31 -0
  144. package/lib-esm/Token/TokenBase.js +87 -0
  145. package/lib-esm/Token/_RemoveTokenButton.d.ts +12 -0
  146. package/lib-esm/Token/_RemoveTokenButton.js +60 -0
  147. package/lib-esm/Token/_TokenTextContainer.d.ts +3 -0
  148. package/lib-esm/Token/_TokenTextContainer.js +6 -0
  149. package/lib-esm/Token/index.d.ts +3 -0
  150. package/lib-esm/Token/index.js +3 -0
  151. package/lib-esm/_TextInputWrapper.d.ts +10 -0
  152. package/lib-esm/_TextInputWrapper.js +31 -0
  153. package/lib-esm/_UnstyledTextInput.d.ts +2 -0
  154. package/lib-esm/_UnstyledTextInput.js +7 -0
  155. package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +1 -0
  156. package/lib-esm/behaviors/scrollIntoViewingArea.js +30 -0
  157. package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +2 -1
  158. package/lib-esm/hooks/useOpenAndCloseFocus.js +7 -2
  159. package/lib-esm/hooks/useOverlay.d.ts +2 -1
  160. package/lib-esm/hooks/useOverlay.js +4 -2
  161. package/lib-esm/index.d.ts +5 -0
  162. package/lib-esm/index.js +3 -0
  163. package/lib-esm/theme-preval.js +372 -3102
  164. package/lib-esm/utils/testing.d.ts +51 -494
  165. package/lib-esm/utils/{types.d.ts → types/AriaRole.d.ts} +0 -13
  166. package/lib-esm/utils/{types.js → types/AriaRole.js} +0 -0
  167. package/lib-esm/utils/types/ComponentProps.d.ts +9 -0
  168. package/lib-esm/utils/types/ComponentProps.js +1 -0
  169. package/lib-esm/utils/types/Flatten.d.ts +4 -0
  170. package/lib-esm/utils/types/Flatten.js +1 -0
  171. package/lib-esm/utils/types/MandateProps.d.ts +3 -0
  172. package/lib-esm/utils/types/MandateProps.js +1 -0
  173. package/lib-esm/utils/types/Merge.d.ts +19 -0
  174. package/lib-esm/utils/types/Merge.js +1 -0
  175. package/lib-esm/utils/types/index.d.ts +5 -0
  176. package/lib-esm/utils/types/index.js +5 -0
  177. package/package.json +10 -9
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  export declare type AnchorVariant = 'input' | 'button' | 'icon-only';
3
3
  export declare type DateFormat = 'short' | 'long' | string;
4
+ export declare type SelectionVariant = 'single' | 'multi' | 'range';
4
5
  export interface DatePickerConfiguration {
5
6
  anchorVariant?: AnchorVariant;
6
7
  blockedDates?: Array<Date>;
@@ -12,8 +13,9 @@ export interface DatePickerConfiguration {
12
13
  maxDate?: Date;
13
14
  placeholder?: string;
14
15
  rangeIncrement?: number;
15
- selection?: 'single' | 'multi' | 'range';
16
+ selection?: SelectionVariant;
16
17
  view?: '1-month' | '2-month';
18
+ weekStartsOn?: 'Sunday' | 'Monday';
17
19
  }
18
20
  export declare type RangeSelection = {
19
21
  from: Date;
@@ -26,13 +28,20 @@ export declare type StringRangeSelection = {
26
28
  export interface DatePickerContext {
27
29
  disabled?: boolean;
28
30
  configuration: DatePickerConfiguration;
31
+ currentViewingDate: Date;
32
+ goToMonth: (date: Date) => void;
33
+ hoverRange?: RangeSelection | null;
29
34
  selection?: Selection;
30
35
  softSelection?: Partial<RangeSelection> | null;
31
36
  selectionActive?: boolean;
32
37
  formattedDate: string;
38
+ nextMonth: () => void;
33
39
  onSelection: (date: Date) => void;
34
40
  onDayFocus: (date: Date) => void;
35
41
  onDayBlur: (date: Date) => void;
42
+ previousMonth: () => void;
43
+ revertValue: () => void;
44
+ saveValue: (selection?: Selection) => void;
36
45
  }
37
46
  export declare type Selection = Date | Array<Date> | RangeSelection | null;
38
47
  export declare type StringSelection = string | Array<string> | {
@@ -45,13 +54,20 @@ declare const useDatePicker: (date?: Date | undefined) => {
45
54
  disabled: boolean;
46
55
  selected: DaySelection;
47
56
  configuration: DatePickerConfiguration;
57
+ currentViewingDate: Date;
58
+ goToMonth: (date: Date) => void;
59
+ hoverRange?: RangeSelection | null | undefined;
48
60
  selection?: Selection | undefined;
49
61
  softSelection?: Partial<RangeSelection> | null | undefined;
50
62
  selectionActive?: boolean | undefined;
51
63
  formattedDate: string;
64
+ nextMonth: () => void;
52
65
  onSelection: (date: Date) => void;
53
66
  onDayFocus: (date: Date) => void;
54
67
  onDayBlur: (date: Date) => void;
68
+ previousMonth: () => void;
69
+ revertValue: () => void;
70
+ saveValue: (selection?: Selection | undefined) => void;
55
71
  };
56
72
  export default useDatePicker;
57
73
  export interface DatePickerProviderProps {
@@ -60,7 +76,7 @@ export interface DatePickerProviderProps {
60
76
  value?: Selection | StringSelection;
61
77
  }
62
78
  export declare function isSingleSelection(selection: Selection): selection is Date;
63
- export declare function isMultiSelection(selection: Selection): selection is Array<Date>;
79
+ export declare function isMultiSelection(selection: Selection | StringSelection): selection is Array<Date> | Array<string>;
64
80
  export declare function isRangeSelection(selection: Selection | StringSelection): selection is RangeSelection | StringRangeSelection;
65
81
  export declare function isStringRangeSelection(selection: StringSelection): selection is StringRangeSelection;
66
82
  export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;
@@ -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
 
@@ -93,7 +141,8 @@ const defaultConfiguration = {
93
141
  dimWeekends: false,
94
142
  placeholder: 'Select a Date...',
95
143
  selection: 'single',
96
- view: '2-month'
144
+ view: '2-month',
145
+ weekStartsOn: 'Sunday'
97
146
  };
98
147
  export const DatePickerProvider = ({
99
148
  configuration: externalConfig = {},
@@ -102,11 +151,24 @@ export const DatePickerProvider = ({
102
151
  value
103
152
  }) => {
104
153
  const [configuration, setConfiguration] = useState(deepmerge(defaultConfiguration, externalConfig));
105
- const [selection, setSelection] = useState(parseSelection(value));
154
+ const [previousSelection, setPreviousSelection] = useState(parseSelection(value, configuration.selection));
155
+ const [selection, setSelection] = useState(parseSelection(value, configuration.selection));
106
156
  const [hoverRange, setHoverRange] = useState(null);
157
+ const [currentViewingDate, setCurrentViewingDate] = useState(new Date());
107
158
  useEffect(() => {
108
159
  setConfiguration(deepmerge(defaultConfiguration, externalConfig));
109
- }, [externalConfig]);
160
+ setSelection(parseSelection(selection, configuration.selection)); // Don't want this to run every time selection gets updated
161
+ // eslint-disable-next-line react-hooks/exhaustive-deps
162
+ }, [configuration.selection, externalConfig]);
163
+ const goToMonth = useCallback(date => {
164
+ setCurrentViewingDate(new Date(new Date(date).toDateString()));
165
+ }, []);
166
+ const nextMonth = useCallback(() => {
167
+ setCurrentViewingDate(addMonths(currentViewingDate, 1));
168
+ }, [currentViewingDate]);
169
+ const previousMonth = useCallback(() => {
170
+ setCurrentViewingDate(subMonths(currentViewingDate, 1));
171
+ }, [currentViewingDate]);
110
172
  const getFormattedDate = useMemo(() => {
111
173
  if (!selection) {
112
174
  return configuration.placeholder;
@@ -135,6 +197,10 @@ export const DatePickerProvider = ({
135
197
  {
136
198
  if (selection instanceof Date) {
137
199
  return format(selection, template);
200
+ } else if (Array.isArray(selection)) {
201
+ return format(selection[0], template);
202
+ } else if (isRangeSelection(selection)) {
203
+ return format(selection.from, template);
138
204
  } else {
139
205
  return 'Invalid Selection';
140
206
  }
@@ -143,7 +209,13 @@ export const DatePickerProvider = ({
143
209
  case 'multi':
144
210
  {
145
211
  if (Array.isArray(selection)) {
146
- return selection.map(d => format(d, template)).join(', ');
212
+ if (selection.length > 3) return `${selection.length} Selected`;
213
+ const formatted = selection.map(d => format(d, template)).join(', ');
214
+ return formatted;
215
+ } else if (selection instanceof Date) {
216
+ return [selection].map(d => format(d, template)).join(', ');
217
+ } else if (isRangeSelection(selection)) {
218
+ return [selection.to, selection.from].map(d => d ? format(d, template) : '').join(', ');
147
219
  } else {
148
220
  return 'Invalid Selection';
149
221
  }
@@ -153,6 +225,18 @@ export const DatePickerProvider = ({
153
225
  {
154
226
  if (isRangeSelection(selection)) {
155
227
  return Object.entries(selection).map(([_, date]) => date ? format(date, template) : '').join(' - ');
228
+ } else if (selection instanceof Date) {
229
+ return Object.entries({
230
+ from: selection,
231
+ to: null
232
+ }).map(([_, date]) => date ? format(date, template) : '').join(' - ');
233
+ } else if (Array.isArray(selection)) {
234
+ return Object.entries({
235
+ from: selection[0],
236
+ to: selection[1]
237
+ }) // to date can still be null
238
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
239
+ .map(([_, date]) => date ? format(date, template) : '').join(' - ');
156
240
  } else {
157
241
  return 'Invalid Selection';
158
242
  }
@@ -164,30 +248,41 @@ export const DatePickerProvider = ({
164
248
  }
165
249
  }
166
250
  }, [configuration.dateFormat, configuration.placeholder, configuration.selection, selection]);
251
+ const saveValue = useCallback(updatedSelection => {
252
+ setPreviousSelection(updatedSelection !== null && updatedSelection !== void 0 ? updatedSelection : selection);
253
+ closePicker === null || closePicker === void 0 ? void 0 : closePicker();
254
+ }, [closePicker, selection]);
167
255
  const selectionHandler = useCallback(date => {
168
256
  if (configuration.selection === 'multi') {
169
- const selections = selection;
257
+ const selections = [...selection];
170
258
  const existingIndex = selections.findIndex(s => isEqual(s, date));
171
259
 
172
260
  if (existingIndex > -1) {
173
- setSelection(selections.splice(existingIndex, 1));
261
+ selections.splice(existingIndex, 1);
262
+ setSelection(selections.sort((a, b) => a.getTime() - b.getTime()));
174
263
  } else {
175
- setSelection([...selections, date]);
264
+ setSelection([...selections, date].sort((a, b) => a.getTime() - b.getTime()));
176
265
  }
177
266
  } else if (configuration.selection === 'range') {
178
267
  if (selection && isRangeSelection(selection) && !selection.to) {
179
- setSelection(isBefore(date, selection.from) ? {
268
+ const updatedSelection = isBefore(date, selection.from) ? {
180
269
  from: date,
181
270
  to: selection.from
182
271
  } : {
183
272
  from: selection.from,
184
273
  to: date
185
- });
274
+ };
275
+ setSelection(updatedSelection);
276
+ setHoverRange(null);
186
277
 
187
278
  if (!configuration.confirmation) {
188
- closePicker === null || closePicker === void 0 ? void 0 : closePicker();
279
+ saveValue(updatedSelection);
189
280
  }
190
281
  } else {
282
+ setHoverRange({
283
+ from: date,
284
+ to: date
285
+ });
191
286
  setSelection({
192
287
  from: date,
193
288
  to: null
@@ -197,14 +292,14 @@ export const DatePickerProvider = ({
197
292
  setSelection(date);
198
293
 
199
294
  if (!configuration.confirmation) {
200
- closePicker === null || closePicker === void 0 ? void 0 : closePicker();
295
+ saveValue(date);
201
296
  }
202
297
  }
203
- }, [closePicker, configuration.confirmation, configuration.selection, selection]);
298
+ }, [configuration.confirmation, configuration.selection, saveValue, selection]);
204
299
  const focusHnadler = useCallback(date => {
205
300
  if (!selection) return;
206
301
 
207
- if (configuration.selection === 'range' && isRangeSelection(selection)) {
302
+ if (configuration.selection === 'range' && isRangeSelection(selection) && hoverRange) {
208
303
  setHoverRange(isBefore(date, selection.from) ? {
209
304
  from: date,
210
305
  to: selection.from
@@ -213,26 +308,35 @@ export const DatePickerProvider = ({
213
308
  to: date
214
309
  });
215
310
  }
216
- }, [configuration.selection, selection]);
311
+ }, [configuration.selection, hoverRange, selection]);
217
312
  const blurHnadler = useCallback(date => {
218
313
  if (!selection || !hoverRange) return;
219
314
 
220
- if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {
221
- setHoverRange(null);
315
+ if (configuration.selection === 'range' && isRangeSelection(selection) && (hoverRange.from === date || hoverRange.to === date)) {// setHoverRange({from: hoverRange.from, to: hoverRange.from})
222
316
  }
223
317
  }, [configuration.selection, hoverRange, selection]);
318
+ const revertValue = useCallback(() => {
319
+ setSelection(previousSelection);
320
+ }, [previousSelection]);
224
321
  const datePickerCtx = useMemo(() => {
225
322
  return {
226
323
  configuration,
324
+ currentViewingDate,
227
325
  disabled: false,
228
326
  formattedDate: getFormattedDate,
327
+ goToMonth,
328
+ hoverRange,
329
+ nextMonth,
229
330
  onDayBlur: blurHnadler,
230
331
  onDayFocus: focusHnadler,
231
332
  onSelection: selectionHandler,
333
+ previousMonth,
334
+ revertValue,
335
+ saveValue,
232
336
  selectionActive: false,
233
337
  selection
234
338
  };
235
- }, [blurHnadler, configuration, focusHnadler, getFormattedDate, selection, selectionHandler]);
339
+ }, [blurHnadler, configuration, currentViewingDate, focusHnadler, getFormattedDate, goToMonth, hoverRange, nextMonth, previousMonth, revertValue, saveValue, selection, selectionHandler]);
236
340
  return /*#__PURE__*/React.createElement(DatePickerContext.Provider, {
237
341
  value: datePickerCtx
238
342
  }, 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;