@superdispatch/dates 0.21.8 → 0.21.13
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/.babelrc.js +5 -0
- package/.turbo/turbo-version.log +26 -0
- package/package.json +58 -32
- package/pkg/README.md +10 -0
- package/{dist-types → pkg/dist-types}/index.d.ts +237 -237
- package/pkg/package.json +32 -0
- package/playroom.ts +10 -0
- package/src/__tests__/index.spec.ts +48 -0
- package/src/base-date-picker/BaseDatePicker.tsx +145 -0
- package/src/calendar/Calendar.playroom.tsx +28 -0
- package/src/calendar/Calendar.spec.tsx +531 -0
- package/src/calendar/Calendar.stories.tsx +50 -0
- package/src/calendar/Calendar.tsx +534 -0
- package/src/calendar/CalendarQuickSelection.tsx +34 -0
- package/src/calendar/InternalCalendarComponents.tsx +79 -0
- package/src/date-config/DateConfig.spec.tsx +23 -0
- package/src/date-config/DateConfig.tsx +60 -0
- package/src/date-field/DateField.playroom.tsx +21 -0
- package/src/date-field/DateField.spec.tsx +350 -0
- package/src/date-field/DateField.stories.tsx +47 -0
- package/src/date-field/DateField.tsx +155 -0
- package/src/date-range-field/DateRangeField.playroom.tsx +24 -0
- package/src/date-range-field/DateRangeField.spec.tsx +318 -0
- package/src/date-range-field/DateRangeField.stories.tsx +51 -0
- package/src/date-range-field/DateRangeField.tsx +277 -0
- package/src/date-time-utils/DateTimeUtils.spec.ts +652 -0
- package/src/date-time-utils/DateTimeUtils.ts +339 -0
- package/src/date-utils/DateUtils.spec.ts +234 -0
- package/src/date-utils/DateUtils.ts +333 -0
- package/src/formatted-date/FormattedDate.spec.tsx +103 -0
- package/src/formatted-date/FormattedDate.ts +42 -0
- package/src/formatted-relative-time/FormattedRelativeTime.spec.tsx +93 -0
- package/src/formatted-relative-time/FormattedRelativeTime.ts +60 -0
- package/src/index.ts +12 -0
- package/src/time-field/TimeField.playroom.tsx +21 -0
- package/src/time-field/TimeField.stories.tsx +35 -0
- package/src/time-field/TimeField.tsx +221 -0
- package/src/use-date-time/useDateTime.spec.ts +45 -0
- package/src/use-date-time/useDateTime.ts +31 -0
- package/src/use-date-time-range/useDateTimeRange.spec.ts +53 -0
- package/src/use-date-time-range/useDateTimeRange.ts +24 -0
- package/tsconfig.json +19 -0
- package/LICENSE +0 -21
- /package/{dist-node → pkg/dist-node}/index.js +0 -0
- /package/{dist-node → pkg/dist-node}/index.js.map +0 -0
- /package/{dist-src → pkg/dist-src}/base-date-picker/BaseDatePicker.js +0 -0
- /package/{dist-src → pkg/dist-src}/calendar/Calendar.js +0 -0
- /package/{dist-src → pkg/dist-src}/calendar/CalendarQuickSelection.js +0 -0
- /package/{dist-src → pkg/dist-src}/calendar/InternalCalendarComponents.js +0 -0
- /package/{dist-src → pkg/dist-src}/date-config/DateConfig.js +0 -0
- /package/{dist-src → pkg/dist-src}/date-field/DateField.js +0 -0
- /package/{dist-src → pkg/dist-src}/date-range-field/DateRangeField.js +0 -0
- /package/{dist-src → pkg/dist-src}/date-time-utils/DateTimeUtils.js +0 -0
- /package/{dist-src → pkg/dist-src}/date-utils/DateUtils.js +0 -0
- /package/{dist-src → pkg/dist-src}/formatted-date/FormattedDate.js +0 -0
- /package/{dist-src → pkg/dist-src}/formatted-relative-time/FormattedRelativeTime.js +0 -0
- /package/{dist-src → pkg/dist-src}/index.js +0 -0
- /package/{dist-src → pkg/dist-src}/time-field/TimeField.js +0 -0
- /package/{dist-src → pkg/dist-src}/use-date-time/useDateTime.js +0 -0
- /package/{dist-src → pkg/dist-src}/use-date-time-range/useDateTimeRange.js +0 -0
- /package/{dist-web → pkg/dist-web}/index.js +0 -0
- /package/{dist-web → pkg/dist-web}/index.js.map +0 -0
package/pkg/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@superdispatch/dates",
|
|
3
|
+
"version": "0.21.8",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist-*/",
|
|
7
|
+
"bin/"
|
|
8
|
+
],
|
|
9
|
+
"pika": true,
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/superdispatch/ui.git"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@superdispatch/ui": "^0.21.8",
|
|
17
|
+
"luxon": "^1.27.0",
|
|
18
|
+
"react-day-picker": "7.4.10"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@babel/runtime": "^7.0.0",
|
|
22
|
+
"@material-ui/lab": "^4.0.0-alpha.40"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"directory": "pkg"
|
|
27
|
+
},
|
|
28
|
+
"esnext": "dist-src/index.js",
|
|
29
|
+
"module": "dist-web/index.js",
|
|
30
|
+
"main": "dist-node/index.js",
|
|
31
|
+
"types": "dist-types/index.d.ts"
|
|
32
|
+
}
|
package/playroom.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as api from '..';
|
|
2
|
+
|
|
3
|
+
it('exposes public api', () => {
|
|
4
|
+
expect(api).toMatchInlineSnapshot(`
|
|
5
|
+
Object {
|
|
6
|
+
"Calendar": React.forwardRef(Calendar),
|
|
7
|
+
"CalendarQuickSelection": React.forwardRef(CalendarQuickSelection),
|
|
8
|
+
"CalendarQuickSelectionItem": React.forwardRef(CalendarQuickSelectionItem),
|
|
9
|
+
"DateConfigProvider": [Function],
|
|
10
|
+
"DateField": React.forwardRef(DateField),
|
|
11
|
+
"DateRangeField": React.forwardRef(DateRangeField),
|
|
12
|
+
"DateUtils": [Function],
|
|
13
|
+
"FormattedDate": [Function],
|
|
14
|
+
"FormattedRelativeTime": [Function],
|
|
15
|
+
"TimeField": React.forwardRef(TimeField),
|
|
16
|
+
"defaultDateConfig": Object {
|
|
17
|
+
"format": "DateTimeISO",
|
|
18
|
+
},
|
|
19
|
+
"formatDate": [Function],
|
|
20
|
+
"formatDateRange": [Function],
|
|
21
|
+
"formatRelativeTime": [Function],
|
|
22
|
+
"isDate": [Function],
|
|
23
|
+
"isDateLike": [Function],
|
|
24
|
+
"isDateRange": [Function],
|
|
25
|
+
"isDateRangeLike": [Function],
|
|
26
|
+
"isValidDate": [Function],
|
|
27
|
+
"isValidDateRange": [Function],
|
|
28
|
+
"parseDate": [Function],
|
|
29
|
+
"parseDateRange": [Function],
|
|
30
|
+
"setDefaultTimeZone": [Function],
|
|
31
|
+
"stringifyDate": [Function],
|
|
32
|
+
"stringifyDateRange": [Function],
|
|
33
|
+
"toDate": [Function],
|
|
34
|
+
"toDatePayload": [Function],
|
|
35
|
+
"toDateRange": [Function],
|
|
36
|
+
"toDateRangePayload": [Function],
|
|
37
|
+
"toPrimitiveDateInput": [Function],
|
|
38
|
+
"toPrimitiveDateRangeInput": [Function],
|
|
39
|
+
"useDateConfig": [Function],
|
|
40
|
+
"useDateTime": [Function],
|
|
41
|
+
"useDateTimeRange": [Function],
|
|
42
|
+
"useDateUtils": [Function],
|
|
43
|
+
"useDefaultTimeZone": [Function],
|
|
44
|
+
"useFormattedDate": [Function],
|
|
45
|
+
"useFormattedRelativeTime": [Function],
|
|
46
|
+
}
|
|
47
|
+
`);
|
|
48
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseTextFieldProps,
|
|
3
|
+
IconButton,
|
|
4
|
+
InputAdornment,
|
|
5
|
+
InputProps,
|
|
6
|
+
Popover,
|
|
7
|
+
SvgIcon,
|
|
8
|
+
TextField,
|
|
9
|
+
} from '@material-ui/core';
|
|
10
|
+
import { Clear } from '@material-ui/icons';
|
|
11
|
+
import { mdiCalendarMonth } from '@mdi/js';
|
|
12
|
+
import { useValueObserver } from '@superdispatch/hooks';
|
|
13
|
+
import { mergeRefs, useUID } from '@superdispatch/ui';
|
|
14
|
+
import { forwardRef, Ref, useImperativeHandle, useRef, useState } from 'react';
|
|
15
|
+
|
|
16
|
+
export interface InternalBaseDateFieldAPI {
|
|
17
|
+
close: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface BaseDatePickerProps
|
|
21
|
+
extends Omit<BaseTextFieldProps, 'variant'> {
|
|
22
|
+
api?: Ref<InternalBaseDateFieldAPI>;
|
|
23
|
+
onClear?: () => void;
|
|
24
|
+
onClose?: () => void;
|
|
25
|
+
enableClearable?: boolean;
|
|
26
|
+
InputProps?: InputProps;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const BaseDatePicker = forwardRef<HTMLDivElement, BaseDatePickerProps>(
|
|
30
|
+
(
|
|
31
|
+
{
|
|
32
|
+
id,
|
|
33
|
+
api,
|
|
34
|
+
onClear,
|
|
35
|
+
onClick,
|
|
36
|
+
onClose,
|
|
37
|
+
onKeyDown,
|
|
38
|
+
|
|
39
|
+
disabled,
|
|
40
|
+
children,
|
|
41
|
+
enableClearable,
|
|
42
|
+
|
|
43
|
+
inputRef: inputRefProp,
|
|
44
|
+
InputProps: inputProps,
|
|
45
|
+
|
|
46
|
+
...textFieldProps
|
|
47
|
+
},
|
|
48
|
+
ref,
|
|
49
|
+
) => {
|
|
50
|
+
const uid = useUID(id);
|
|
51
|
+
const labelID = `${uid}-label`;
|
|
52
|
+
const clearIconID = `${uid}-clear-icon`;
|
|
53
|
+
|
|
54
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
55
|
+
const textFieldRef = useRef<HTMLDivElement>(null);
|
|
56
|
+
const [popoverAnchor, setPopoverAnchor] = useState<null | HTMLElement>(
|
|
57
|
+
null,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
function handleOpen(): void {
|
|
61
|
+
if (!disabled && textFieldRef.current) {
|
|
62
|
+
setPopoverAnchor(textFieldRef.current);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function handleClose(): void {
|
|
67
|
+
setPopoverAnchor(null);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
useImperativeHandle(api, () => ({ close: handleClose }));
|
|
71
|
+
|
|
72
|
+
// We want to trigger close event only when UI will be ready after updates.
|
|
73
|
+
useValueObserver(popoverAnchor, () => {
|
|
74
|
+
if (!popoverAnchor) {
|
|
75
|
+
onClose?.();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<>
|
|
81
|
+
<Popover
|
|
82
|
+
open={!!popoverAnchor}
|
|
83
|
+
onClose={handleClose}
|
|
84
|
+
anchorEl={popoverAnchor}
|
|
85
|
+
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
|
|
86
|
+
transformOrigin={{ vertical: 'top', horizontal: 'left' }}
|
|
87
|
+
>
|
|
88
|
+
{children}
|
|
89
|
+
</Popover>
|
|
90
|
+
|
|
91
|
+
<TextField
|
|
92
|
+
{...textFieldProps}
|
|
93
|
+
id={uid}
|
|
94
|
+
ref={mergeRefs(ref, textFieldRef)}
|
|
95
|
+
disabled={disabled}
|
|
96
|
+
inputRef={mergeRefs(inputRef, inputRefProp)}
|
|
97
|
+
onClick={(event) => {
|
|
98
|
+
onClick?.(event);
|
|
99
|
+
if (!event.defaultPrevented) {
|
|
100
|
+
handleOpen();
|
|
101
|
+
}
|
|
102
|
+
}}
|
|
103
|
+
onKeyDown={(event) => {
|
|
104
|
+
onKeyDown?.(event);
|
|
105
|
+
|
|
106
|
+
if (
|
|
107
|
+
!event.defaultPrevented &&
|
|
108
|
+
(event.key === ' ' || event.key === 'Enter')
|
|
109
|
+
) {
|
|
110
|
+
handleOpen();
|
|
111
|
+
}
|
|
112
|
+
}}
|
|
113
|
+
inputProps={{ readOnly: true }}
|
|
114
|
+
InputProps={{
|
|
115
|
+
...inputProps,
|
|
116
|
+
endAdornment: (
|
|
117
|
+
<InputAdornment position="end">
|
|
118
|
+
{enableClearable ? (
|
|
119
|
+
<IconButton
|
|
120
|
+
disabled={disabled}
|
|
121
|
+
aria-labelledby={`${clearIconID} ${labelID}`}
|
|
122
|
+
onClick={(event) => {
|
|
123
|
+
// Do not bubble up clicks.
|
|
124
|
+
event.stopPropagation();
|
|
125
|
+
|
|
126
|
+
onClear?.();
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
<Clear id={clearIconID} aria-label="clear" />
|
|
130
|
+
</IconButton>
|
|
131
|
+
) : (
|
|
132
|
+
<IconButton disabled={disabled}>
|
|
133
|
+
<SvgIcon>
|
|
134
|
+
<path d={mdiCalendarMonth} />
|
|
135
|
+
</SvgIcon>
|
|
136
|
+
</IconButton>
|
|
137
|
+
)}
|
|
138
|
+
</InputAdornment>
|
|
139
|
+
),
|
|
140
|
+
}}
|
|
141
|
+
/>
|
|
142
|
+
</>
|
|
143
|
+
);
|
|
144
|
+
},
|
|
145
|
+
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { forwardRef, useState } from 'react';
|
|
2
|
+
import { NullableDateInput } from '../date-time-utils/DateTimeUtils';
|
|
3
|
+
import { Calendar as SDCalendar, CalendarProps } from './Calendar';
|
|
4
|
+
|
|
5
|
+
export const Calendar = forwardRef<HTMLDivElement, CalendarProps>(
|
|
6
|
+
({ onDayClick, selectedDays, ...props }, ref) => {
|
|
7
|
+
const [value, setValue] = useState<NullableDateInput>();
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<SDCalendar
|
|
11
|
+
{...props}
|
|
12
|
+
ref={ref}
|
|
13
|
+
selectedDays={selectedDays || ((event) => value === event.stringValue)}
|
|
14
|
+
onDayClick={(event) => {
|
|
15
|
+
onDayClick?.(event);
|
|
16
|
+
|
|
17
|
+
if (!event.disabled) {
|
|
18
|
+
if (!event.selected) {
|
|
19
|
+
setValue(event.stringValue);
|
|
20
|
+
} else {
|
|
21
|
+
setValue(undefined);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
},
|
|
28
|
+
);
|