@bitrise/bitkit 12.77.0 → 12.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitrise/bitkit",
|
|
3
3
|
"description": "Bitrise React component library",
|
|
4
|
-
"version": "12.
|
|
4
|
+
"version": "12.78.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build-storybook": "storybook build",
|
|
13
13
|
"lint": "eslint src --ext ts,tsx",
|
|
14
|
+
"lint:fix": "eslint src --ext ts,tsx --fix",
|
|
14
15
|
"release": "release-it minor --ci",
|
|
15
16
|
"release-alpha": "release-it --preRelease=alpha --ci",
|
|
16
17
|
"start": "npm run storybook",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { DateTime } from 'luxon';
|
|
3
3
|
import FocusLock from 'react-focus-lock';
|
|
4
4
|
import { PopoverAnchor } from '@chakra-ui/react';
|
|
@@ -7,6 +7,7 @@ import Popover from '../Popover/Popover';
|
|
|
7
7
|
import PopoverContent from '../Popover/PopoverContent';
|
|
8
8
|
import Box from '../Box/Box';
|
|
9
9
|
import useResponsive from '../../hooks/useResponsive';
|
|
10
|
+
import Button from '../Button/Button';
|
|
10
11
|
import DatePickerMonth from './DatePickerMonth';
|
|
11
12
|
import { DatePickerContext } from './DatePicker.context';
|
|
12
13
|
import DatePickerMonthSelector from './DatePickerMonthSelector';
|
|
@@ -22,6 +23,7 @@ export type DatePickerProps = {
|
|
|
22
23
|
onClose: () => void;
|
|
23
24
|
onClear?: () => void;
|
|
24
25
|
visible: boolean;
|
|
26
|
+
variant?: 'default' | 'filter';
|
|
25
27
|
} & (
|
|
26
28
|
| {
|
|
27
29
|
selected?: DateRange;
|
|
@@ -40,7 +42,9 @@ export type DatePickerProps = {
|
|
|
40
42
|
* range selection.
|
|
41
43
|
*/
|
|
42
44
|
const DatePicker = (props: DatePickerProps) => {
|
|
43
|
-
const { children, onApply, onClose, onClear, visible, selectable, selected, mode } = props;
|
|
45
|
+
const { children, onApply, onClose, onClear, visible, selectable, selected, mode, variant = 'default' } = props;
|
|
46
|
+
|
|
47
|
+
const isSelectionHappened = useRef(false);
|
|
44
48
|
|
|
45
49
|
const { isMobile } = useResponsive();
|
|
46
50
|
const today = DateTime.now().startOf('day');
|
|
@@ -89,6 +93,7 @@ const DatePicker = (props: DatePickerProps) => {
|
|
|
89
93
|
|
|
90
94
|
const [preview, setPreview] = useState<'from' | 'to' | undefined>(undefined);
|
|
91
95
|
const [isMonthSelector, setIsMonthSelector] = useState<'left' | 'right' | undefined>(undefined);
|
|
96
|
+
|
|
92
97
|
const handlePreview = useCallback(
|
|
93
98
|
(date: DateTime) => {
|
|
94
99
|
if (!preview) {
|
|
@@ -105,8 +110,11 @@ const DatePicker = (props: DatePickerProps) => {
|
|
|
105
110
|
},
|
|
106
111
|
[preview, dateFrom, dateTo],
|
|
107
112
|
);
|
|
113
|
+
|
|
108
114
|
const handleSelect = useCallback(
|
|
109
115
|
(date: DateTime) => {
|
|
116
|
+
isSelectionHappened.current = true;
|
|
117
|
+
|
|
110
118
|
setPreview(undefined);
|
|
111
119
|
if (mode === 'day') {
|
|
112
120
|
setDateFrom(date);
|
|
@@ -131,6 +139,21 @@ const DatePicker = (props: DatePickerProps) => {
|
|
|
131
139
|
},
|
|
132
140
|
[dateFrom, dateTo, preview],
|
|
133
141
|
);
|
|
142
|
+
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (variant === 'default') {
|
|
145
|
+
if (!dateFrom || !isSelectionHappened.current || preview) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (mode !== 'day' && !dateTo) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
handleApply();
|
|
154
|
+
}
|
|
155
|
+
}, [dateFrom, dateTo, preview, isSelectionHappened.current]);
|
|
156
|
+
|
|
134
157
|
const currentSelected = useDateRange([dateFrom, dateTo]);
|
|
135
158
|
const ctx = useObjectMemo({
|
|
136
159
|
selectable,
|
|
@@ -188,13 +211,22 @@ const DatePicker = (props: DatePickerProps) => {
|
|
|
188
211
|
/>
|
|
189
212
|
)}
|
|
190
213
|
</Box>
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
214
|
+
{variant === 'filter' && (
|
|
215
|
+
<DatePickerFooter
|
|
216
|
+
onApply={handleApply}
|
|
217
|
+
onClose={handleClose}
|
|
218
|
+
onClear={onClear}
|
|
219
|
+
selected={currentSelected}
|
|
220
|
+
mode={mode || 'range'}
|
|
221
|
+
/>
|
|
222
|
+
)}
|
|
223
|
+
{variant === 'default' && mode === 'day' && (
|
|
224
|
+
<Box display="flex" justifyContent="space-around">
|
|
225
|
+
<Button onClick={() => handleSelect(DateTime.now())} variant="tertiary">
|
|
226
|
+
Today
|
|
227
|
+
</Button>
|
|
228
|
+
</Box>
|
|
229
|
+
)}
|
|
198
230
|
</>
|
|
199
231
|
)}
|
|
200
232
|
</Box>
|
|
@@ -22,12 +22,14 @@ const DatePickerFooter = ({
|
|
|
22
22
|
|
|
23
23
|
const styleGrid = (mobile: string, desktop: string) => (mode === 'day' ? mobile : [mobile, desktop]);
|
|
24
24
|
|
|
25
|
+
const displayDate = selected?.from || selected?.to;
|
|
26
|
+
|
|
25
27
|
return (
|
|
26
28
|
<Box
|
|
27
29
|
display="grid"
|
|
28
30
|
gridTemplateColumns="1fr auto 1fr"
|
|
29
|
-
gridTemplateRows={styleGrid(
|
|
30
|
-
gap={
|
|
31
|
+
gridTemplateRows={styleGrid(displayDate ? '1.25rem 2rem' : '0 2rem', 'unset')}
|
|
32
|
+
gap={displayDate ? 24 : 0}
|
|
31
33
|
data-testid="footer"
|
|
32
34
|
>
|
|
33
35
|
{!!onClear && (
|