@superdispatch/dates 0.21.13 → 0.21.14

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 (62) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +13 -39
  3. package/.babelrc.js +0 -5
  4. package/.turbo/turbo-version.log +0 -26
  5. package/pkg/README.md +0 -10
  6. package/pkg/package.json +0 -32
  7. package/playroom.ts +0 -10
  8. package/src/__tests__/index.spec.ts +0 -48
  9. package/src/base-date-picker/BaseDatePicker.tsx +0 -145
  10. package/src/calendar/Calendar.playroom.tsx +0 -28
  11. package/src/calendar/Calendar.spec.tsx +0 -531
  12. package/src/calendar/Calendar.stories.tsx +0 -50
  13. package/src/calendar/Calendar.tsx +0 -534
  14. package/src/calendar/CalendarQuickSelection.tsx +0 -34
  15. package/src/calendar/InternalCalendarComponents.tsx +0 -79
  16. package/src/date-config/DateConfig.spec.tsx +0 -23
  17. package/src/date-config/DateConfig.tsx +0 -60
  18. package/src/date-field/DateField.playroom.tsx +0 -21
  19. package/src/date-field/DateField.spec.tsx +0 -350
  20. package/src/date-field/DateField.stories.tsx +0 -47
  21. package/src/date-field/DateField.tsx +0 -155
  22. package/src/date-range-field/DateRangeField.playroom.tsx +0 -24
  23. package/src/date-range-field/DateRangeField.spec.tsx +0 -318
  24. package/src/date-range-field/DateRangeField.stories.tsx +0 -51
  25. package/src/date-range-field/DateRangeField.tsx +0 -277
  26. package/src/date-time-utils/DateTimeUtils.spec.ts +0 -652
  27. package/src/date-time-utils/DateTimeUtils.ts +0 -339
  28. package/src/date-utils/DateUtils.spec.ts +0 -234
  29. package/src/date-utils/DateUtils.ts +0 -333
  30. package/src/formatted-date/FormattedDate.spec.tsx +0 -103
  31. package/src/formatted-date/FormattedDate.ts +0 -42
  32. package/src/formatted-relative-time/FormattedRelativeTime.spec.tsx +0 -93
  33. package/src/formatted-relative-time/FormattedRelativeTime.ts +0 -60
  34. package/src/index.ts +0 -12
  35. package/src/time-field/TimeField.playroom.tsx +0 -21
  36. package/src/time-field/TimeField.stories.tsx +0 -35
  37. package/src/time-field/TimeField.tsx +0 -221
  38. package/src/use-date-time/useDateTime.spec.ts +0 -45
  39. package/src/use-date-time/useDateTime.ts +0 -31
  40. package/src/use-date-time-range/useDateTimeRange.spec.ts +0 -53
  41. package/src/use-date-time-range/useDateTimeRange.ts +0 -24
  42. package/tsconfig.json +0 -19
  43. /package/{pkg/dist-node → dist-node}/index.js +0 -0
  44. /package/{pkg/dist-node → dist-node}/index.js.map +0 -0
  45. /package/{pkg/dist-src → dist-src}/base-date-picker/BaseDatePicker.js +0 -0
  46. /package/{pkg/dist-src → dist-src}/calendar/Calendar.js +0 -0
  47. /package/{pkg/dist-src → dist-src}/calendar/CalendarQuickSelection.js +0 -0
  48. /package/{pkg/dist-src → dist-src}/calendar/InternalCalendarComponents.js +0 -0
  49. /package/{pkg/dist-src → dist-src}/date-config/DateConfig.js +0 -0
  50. /package/{pkg/dist-src → dist-src}/date-field/DateField.js +0 -0
  51. /package/{pkg/dist-src → dist-src}/date-range-field/DateRangeField.js +0 -0
  52. /package/{pkg/dist-src → dist-src}/date-time-utils/DateTimeUtils.js +0 -0
  53. /package/{pkg/dist-src → dist-src}/date-utils/DateUtils.js +0 -0
  54. /package/{pkg/dist-src → dist-src}/formatted-date/FormattedDate.js +0 -0
  55. /package/{pkg/dist-src → dist-src}/formatted-relative-time/FormattedRelativeTime.js +0 -0
  56. /package/{pkg/dist-src → dist-src}/index.js +0 -0
  57. /package/{pkg/dist-src → dist-src}/time-field/TimeField.js +0 -0
  58. /package/{pkg/dist-src → dist-src}/use-date-time/useDateTime.js +0 -0
  59. /package/{pkg/dist-src → dist-src}/use-date-time-range/useDateTimeRange.js +0 -0
  60. /package/{pkg/dist-types → dist-types}/index.d.ts +0 -0
  61. /package/{pkg/dist-web → dist-web}/index.js +0 -0
  62. /package/{pkg/dist-web → dist-web}/index.js.map +0 -0
@@ -1,221 +0,0 @@
1
- import {
2
- BaseTextFieldProps,
3
- InputBaseProps,
4
- TextField,
5
- } from '@material-ui/core';
6
- import { Autocomplete, FilterOptionsState } from '@material-ui/lab';
7
- import { DateTime } from 'luxon';
8
- import { forwardRef, useEffect, useMemo, useState } from 'react';
9
- import {
10
- DateConfig,
11
- DateFormat,
12
- useDateConfig,
13
- } from '../date-config/DateConfig';
14
- import {
15
- DatePayload,
16
- formatDate,
17
- NullableDateInput,
18
- toDatePayload,
19
- } from '../date-time-utils/DateTimeUtils';
20
- import { useDateTime } from '../use-date-time/useDateTime';
21
-
22
- const TIME_MATCH_FORMATS = [
23
- 'h:mm a',
24
- 'h:mma',
25
- 'H:mm',
26
- 'h:mm',
27
- 'hmm',
28
- 'Hmm',
29
- 'h',
30
- 'H',
31
- ];
32
-
33
- interface TimeFieldOption {
34
- value: number;
35
- label: string;
36
- pattern: RegExp;
37
- }
38
-
39
- function toTimeFieldOption(
40
- date: DateTime,
41
- config: DateConfig,
42
- ): TimeFieldOption {
43
- return {
44
- value: date.valueOf(),
45
- label: formatDate(date, { variant: 'Time' }, config),
46
- pattern: new RegExp(
47
- `^(${TIME_MATCH_FORMATS.map((format) => date.toFormat(format)).join(
48
- '|',
49
- )})`,
50
- 'i',
51
- ),
52
- };
53
- }
54
-
55
- function normalizeInputValue(inputValue: string): string {
56
- return inputValue.replace(/[\s]/g, '').toLowerCase();
57
- }
58
-
59
- function makeOptions(
60
- config: DateConfig,
61
- ): [
62
- options: TimeFieldOption[],
63
- filterOptions: (
64
- options: TimeFieldOption[],
65
- state: FilterOptionsState<TimeFieldOption>,
66
- ) => TimeFieldOption[],
67
- ] {
68
- const options: TimeFieldOption[] = [];
69
- const now = DateTime.local().startOf('day');
70
-
71
- for (let i = 0; i < 96; i++) {
72
- options.push(toTimeFieldOption(now.set({ minute: i * 15 }), config));
73
- }
74
-
75
- const cache = new Map<string, TimeFieldOption[]>();
76
-
77
- return [
78
- options,
79
- (_, { inputValue }) => {
80
- const query = normalizeInputValue(inputValue);
81
-
82
- if (!query) {
83
- return options;
84
- }
85
-
86
- let filtered = cache.get(query);
87
-
88
- if (!filtered) {
89
- filtered = options.filter((option) => option.pattern.test(query));
90
- cache.set(query, filtered);
91
- }
92
-
93
- return filtered;
94
- },
95
- ];
96
- }
97
-
98
- export interface TimeFieldProps
99
- extends Pick<
100
- BaseTextFieldProps,
101
- | 'disabled'
102
- | 'error'
103
- | 'fullWidth'
104
- | 'helperText'
105
- | 'id'
106
- | 'label'
107
- | 'name'
108
- | 'placeholder'
109
- | 'required'
110
- > {
111
- format?: DateFormat;
112
- value?: NullableDateInput;
113
- onChange?: (value: DatePayload) => void;
114
-
115
- InputProps?: Pick<InputBaseProps, 'startAdornment'>;
116
- }
117
-
118
- export const TimeField = forwardRef<HTMLDivElement, TimeFieldProps>(
119
- (
120
- {
121
- disabled,
122
- onChange,
123
-
124
- value: valueProp,
125
- format: formatProp,
126
- ...props
127
- },
128
- ref,
129
- ) => {
130
- const config = useDateConfig({ format: formatProp });
131
- const date = useDateTime(valueProp, config);
132
- const selectedOption = useMemo(
133
- () => (!date.isValid ? undefined : toTimeFieldOption(date, config)),
134
- [date, config],
135
- );
136
- const [options, filterOptions] = useMemo(
137
- () => makeOptions(config),
138
- [config],
139
- );
140
-
141
- const [inputValue, setInputValue] = useState('');
142
-
143
- function handleChange(nextValue: NullableDateInput): void {
144
- if (onChange) {
145
- onChange(toDatePayload(nextValue, config));
146
- }
147
- }
148
-
149
- function handleType(text: string): void {
150
- text = normalizeInputValue(text);
151
-
152
- for (const timeFormat of TIME_MATCH_FORMATS) {
153
- let nextDate = DateTime.fromFormat(text, timeFormat);
154
-
155
- if (nextDate.isValid) {
156
- if (onChange) {
157
- if (date.isValid) {
158
- nextDate = nextDate.set({
159
- year: date.year,
160
- month: date.month,
161
- day: date.day,
162
- });
163
- }
164
-
165
- onChange(toDatePayload(nextDate, config));
166
- }
167
-
168
- return;
169
- }
170
- }
171
-
172
- setInputValue(selectedOption?.label || '');
173
- }
174
-
175
- useEffect(() => {
176
- if (!date.isValid) {
177
- setInputValue('');
178
- } else {
179
- setInputValue(formatDate(date, { variant: 'Time' }, config));
180
- }
181
- }, [date, config]);
182
-
183
- return (
184
- <Autocomplete
185
- ref={ref}
186
- disabled={disabled}
187
- freeSolo={true}
188
- autoComplete={true}
189
- value={selectedOption}
190
- inputValue={inputValue}
191
- options={options}
192
- includeInputInList={true}
193
- filterOptions={filterOptions}
194
- getOptionLabel={(option: string | TimeFieldOption) =>
195
- typeof option === 'string' ? option : option.label
196
- }
197
- onBlur={(event: React.FocusEvent<HTMLInputElement>) => {
198
- handleType(event.target.value);
199
- }}
200
- onChange={(_: unknown, nextValue: null | string | TimeFieldOption) => {
201
- if (typeof nextValue === 'string') {
202
- handleType(nextValue);
203
- } else {
204
- handleChange(nextValue?.value);
205
- }
206
- }}
207
- onInputChange={(_, nextInputValue) => {
208
- setInputValue(nextInputValue);
209
- }}
210
- renderInput={(params) => (
211
- <TextField
212
- variant="outlined"
213
- {...props}
214
- {...params}
215
- InputProps={params.InputProps}
216
- />
217
- )}
218
- />
219
- );
220
- },
221
- );
@@ -1,45 +0,0 @@
1
- import { mockDate, resetMockDate } from '@superdispatch/ui-testutils';
2
- import { renderHook } from '@testing-library/react-hooks';
3
- import { DateTime } from 'luxon';
4
- import { DateConfig } from '../date-config/DateConfig';
5
- import { NullableDateInput } from '../date-time-utils/DateTimeUtils';
6
- import { useDateTime } from './useDateTime';
7
-
8
- interface Props {
9
- input: NullableDateInput;
10
- options?: Partial<DateConfig>;
11
- }
12
-
13
- beforeEach(() => {
14
- mockDate();
15
- });
16
-
17
- afterEach(() => {
18
- resetMockDate();
19
- });
20
-
21
- test('basic', () => {
22
- const { result } = renderHook<Props, DateTime>(
23
- ({ input, options }) => useDateTime(input, options),
24
- { initialProps: { input: '2020-05-24' } },
25
- );
26
-
27
- expect(result.current.toISO()).toBe('2020-05-24T00:00:00.000-05:00');
28
- });
29
-
30
- test('warnings', () => {
31
- const error = jest.spyOn(console, 'error').mockImplementation();
32
-
33
- const { result } = renderHook<Props, DateTime>(
34
- ({ input, options }) => useDateTime(input, options),
35
- { initialProps: { input: '2020-05-24', options: { format: 'JodaISO' } } },
36
- );
37
-
38
- expect(result.current.toISO()).toBeNull();
39
- expect(error).toHaveBeenCalledTimes(1);
40
- expect(error).toHaveBeenLastCalledWith(
41
- '[useDateTime] Failed to parse "2020-05-24" string with "JodaISO" format.',
42
- );
43
-
44
- error.mockClear();
45
- });
@@ -1,31 +0,0 @@
1
- import { DateTime } from 'luxon';
2
- import { useMemo } from 'react';
3
- import { DateConfig, useDateConfig } from '../date-config/DateConfig';
4
- import {
5
- NullableDateInput,
6
- parseDate,
7
- toPrimitiveDateInput,
8
- } from '../date-time-utils/DateTimeUtils';
9
-
10
- export function useDateTime(
11
- input: NullableDateInput,
12
- options?: Partial<DateConfig>,
13
- ): DateTime {
14
- const config = useDateConfig(options);
15
- const primitiveInput = toPrimitiveDateInput(input);
16
-
17
- return useMemo(() => {
18
- const date = parseDate(primitiveInput, config);
19
-
20
- if (process.env.NODE_ENV !== 'production') {
21
- if (!date.isValid && typeof primitiveInput === 'string') {
22
- // eslint-disable-next-line no-console
23
- console.error(
24
- `[useDateTime] Failed to parse "${primitiveInput}" string with "${config.format}" format.`,
25
- );
26
- }
27
- }
28
-
29
- return date;
30
- }, [config, primitiveInput]);
31
- }
@@ -1,53 +0,0 @@
1
- import { mockDate, resetMockDate } from '@superdispatch/ui-testutils';
2
- import { renderHook } from '@testing-library/react-hooks';
3
- import { DateConfig } from '../date-config/DateConfig';
4
- import {
5
- DateTimeRange,
6
- NullableDateRangeInput,
7
- } from '../date-time-utils/DateTimeUtils';
8
- import { useDateTimeRange } from './useDateTimeRange';
9
-
10
- interface Props {
11
- input: NullableDateRangeInput;
12
- options?: Partial<DateConfig>;
13
- }
14
-
15
- beforeEach(() => {
16
- mockDate();
17
- });
18
-
19
- afterEach(() => {
20
- resetMockDate();
21
- });
22
-
23
- test('basic', () => {
24
- const { result } = renderHook<Props, DateTimeRange>(
25
- ({ input, options }) => useDateTimeRange(input, options),
26
- { initialProps: { input: ['2020-05-24'] } },
27
- );
28
-
29
- expect(result.current[0]?.toISO()).toBe('2020-05-24T00:00:00.000-05:00');
30
- expect(result.current[1]).toBeNull();
31
- });
32
-
33
- test('warnings', () => {
34
- const error = jest.spyOn(console, 'error').mockImplementation();
35
-
36
- const { result } = renderHook<Props, DateTimeRange>(
37
- ({ input, options }) => useDateTimeRange(input, options),
38
- {
39
- initialProps: {
40
- input: [null, '2020-05-24'],
41
- options: { format: 'JodaISO' },
42
- },
43
- },
44
- );
45
-
46
- expect(result.current).toEqual([null, null]);
47
- expect(error).toHaveBeenCalledTimes(1);
48
- expect(error).toHaveBeenLastCalledWith(
49
- '[useDateTime] Failed to parse "2020-05-24" string with "JodaISO" format.',
50
- );
51
-
52
- error.mockClear();
53
- });
@@ -1,24 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { DateConfig, useDateConfig } from '../date-config/DateConfig';
3
- import {
4
- DateTimeRange,
5
- NullableDateRangeInput,
6
- parseDateRange,
7
- toPrimitiveDateRangeInput,
8
- } from '../date-time-utils/DateTimeUtils';
9
- import { useDateTime } from '../use-date-time/useDateTime';
10
-
11
- export function useDateTimeRange(
12
- input: NullableDateRangeInput,
13
- options?: Partial<DateConfig>,
14
- ): DateTimeRange {
15
- const config = useDateConfig(options);
16
- const [startInput, finishInput] = toPrimitiveDateRangeInput(input);
17
- const startDate = useDateTime(startInput, config);
18
- const finishDate = useDateTime(finishInput, config);
19
-
20
- return useMemo(
21
- () => parseDateRange([startDate, finishDate], config),
22
- [config, startDate, finishDate],
23
- );
24
- }
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.build",
3
- "exclude": [
4
- "pkg",
5
- "playroom.ts",
6
- "**/*.spec.*",
7
- "**/*.stories.*",
8
- "**/*.playroom.*",
9
- "**/__tests__/**",
10
- "**/__testutils__/**"
11
- ],
12
- "references": [{ "path": "../ui" }, { "path": "../__testutils__" }],
13
- "compilerOptions": {
14
- "composite": true,
15
- "rootDir": "src",
16
- "outDir": "pkg/dist-types",
17
- "tsBuildInfoFile": "pkg/dist-types/.tsbuildinfo"
18
- }
19
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes