onekijs-ui 1.0.4 → 1.0.6
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/dist/components/datetime/FormDatePicker.d.ts +28 -0
- package/dist/components/datetime/FormDateRangePicker.d.ts +28 -0
- package/dist/components/datetime/FormDateTimePicker.d.ts +21 -0
- package/dist/components/datetime/FormDateTimeRangePicker.d.ts +21 -0
- package/dist/components/datetime/hooks/useDateAdapter.d.ts +4 -0
- package/dist/components/datetime/hooks/useDateRangeAdapter.d.ts +5 -0
- package/dist/components/datetime/hooks/useTimestampAdapter.d.ts +8 -0
- package/dist/components/datetime/hooks/useTimestampRangeAdapter.d.ts +17 -2
- package/dist/components/datetime/index.d.ts +8 -8
- package/dist/components/datetime/typings.d.ts +55 -9
- package/dist/components/select/SelectService.d.ts +3 -3
- package/dist/components/wizard/WizardModal.d.ts +2 -2
- package/dist/components/wizard/index.d.ts +2 -2
- package/dist/index.d.ts +73 -70
- package/dist/index.js +2290 -2102
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +2284 -2104
- package/dist/index.module.js.map +1 -1
- package/package.json +3 -3
- package/src/components/button/components/DropdownButtonComponent.tsx +6 -3
- package/src/components/datetime/FormDatePicker.tsx +79 -0
- package/src/components/datetime/FormDateRangePicker.tsx +79 -0
- package/src/components/datetime/FormDateTimePicker.tsx +43 -0
- package/src/components/datetime/FormDateTimeRangePicker.tsx +38 -0
- package/src/components/datetime/components/DatePickerComponent.tsx +8 -4
- package/src/components/datetime/components/DateRangePickerComponent.tsx +8 -4
- package/src/components/datetime/components/DateTimePickerComponent.tsx +8 -4
- package/src/components/datetime/components/DateTimeRangePickerComponent.tsx +8 -4
- package/src/components/datetime/components/TimeComponent.tsx +3 -0
- package/src/components/datetime/components/TimeRangeComponent.tsx +4 -2
- package/src/components/datetime/components/TimeSelectorComponent.tsx +5 -4
- package/src/components/datetime/components/TimeSelectorPartComponent.tsx +16 -1
- package/src/components/datetime/hooks/useDateAdapter.ts +14 -0
- package/src/components/datetime/hooks/useDateRangeAdapter.ts +11 -11
- package/src/components/datetime/hooks/useTimestampAdapter.ts +37 -0
- package/src/components/datetime/hooks/useTimestampRangeAdapter.ts +15 -26
- package/src/components/datetime/style.ts +14 -3
- package/src/components/datetime/typings.ts +66 -10
- package/src/index.ts +96 -130
|
@@ -1,42 +1,31 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
|
-
import { DateRangeAdapter } from '../typings';
|
|
2
|
+
import { DateRangeAdapter, TimestampFormat } from '../typings';
|
|
3
3
|
import { dateToString } from '../util';
|
|
4
|
+
import { fromTimestamp, toTimestamp } from './useTimestampAdapter';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
const toTimestamp = (date: string | undefined | null): number | null => {
|
|
7
|
-
if (!date) return null;
|
|
8
|
-
const d = new Date(date);
|
|
9
|
-
if (isNaN(d as any)) return null;
|
|
10
|
-
const timestamp = d.getTime();
|
|
11
|
-
return format === 'milliseconds' ? timestamp : Math.floor(timestamp / 1000);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const fromTimestamp = (timestamp: number | undefined | null) => {
|
|
15
|
-
if (timestamp === null || timestamp === undefined) return null;
|
|
16
|
-
if (format === 'seconds') {
|
|
17
|
-
timestamp = timestamp * 1000;
|
|
18
|
-
}
|
|
19
|
-
const d = new Date(timestamp);
|
|
20
|
-
if (isNaN(d as any)) return null;
|
|
21
|
-
return dateToString(d);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const ref = useRef({
|
|
6
|
+
export const timestampRangeAdapter = (format: TimestampFormat = 'milliseconds') => ({
|
|
25
7
|
fromDateRange: (range) => {
|
|
26
8
|
return {
|
|
27
|
-
from: toTimestamp(range.from),
|
|
28
|
-
to: toTimestamp(range.to),
|
|
9
|
+
from: toTimestamp(range.from, format),
|
|
10
|
+
to: toTimestamp(range.to, format),
|
|
29
11
|
label: range.label,
|
|
30
12
|
};
|
|
31
13
|
},
|
|
32
14
|
toDateRange: (value) => {
|
|
33
15
|
return {
|
|
34
|
-
from: fromTimestamp(value.from),
|
|
35
|
-
to: fromTimestamp(value.to),
|
|
16
|
+
from: fromTimestamp(value.from, format),
|
|
17
|
+
to: fromTimestamp(value.to, format),
|
|
36
18
|
label: value.label,
|
|
37
19
|
};
|
|
38
20
|
},
|
|
39
|
-
} as DateRangeAdapter<{ from: number | null; to: number | null; label?: string | null }>
|
|
21
|
+
} as DateRangeAdapter<{ from: number | null; to: number | null; label?: string | null }>
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
export const timestampSecondRangeAdapter = timestampRangeAdapter('seconds');
|
|
25
|
+
export const timestampMilliSecondRangeAdapter = timestampRangeAdapter('milliseconds');
|
|
26
|
+
|
|
27
|
+
const useTimestampRangeAdapter = (format: TimestampFormat = 'milliseconds') => {
|
|
28
|
+
const ref = useRef(timestampRangeAdapter(format));
|
|
40
29
|
return ref.current;
|
|
41
30
|
};
|
|
42
31
|
|
|
@@ -20,7 +20,7 @@ import { flexDirection } from '../../styles/flex';
|
|
|
20
20
|
import { gridTemplateColumns } from '../../styles/grid';
|
|
21
21
|
import { cursor, userSelect } from '../../styles/interactivity';
|
|
22
22
|
import { zIndex } from '../../styles/position';
|
|
23
|
-
import { width } from '../../styles/size';
|
|
23
|
+
import { height, width } from '../../styles/size';
|
|
24
24
|
import {
|
|
25
25
|
marginBottom,
|
|
26
26
|
marginLeft,
|
|
@@ -189,12 +189,22 @@ export const datePickerStyle: ComponentStyle<StylableProps> = () => {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
.o-time-container {
|
|
192
|
-
${marginLeft('
|
|
192
|
+
${marginLeft('3xl')}
|
|
193
|
+
${display('flex')}
|
|
194
|
+
${alignItems('center')}
|
|
195
|
+
${height('full')}
|
|
193
196
|
.o-time-separator {
|
|
194
197
|
${marginX('lg')}
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
200
|
|
|
201
|
+
.o-time-selector-part-header {
|
|
202
|
+
${fontWeight('medium')}
|
|
203
|
+
${backgroundColor('lightest')}
|
|
204
|
+
${paddingX('sm')}
|
|
205
|
+
${whiteSpace('nowrap')}
|
|
206
|
+
}
|
|
207
|
+
|
|
198
208
|
.o-time-selector {
|
|
199
209
|
${display('flex')}
|
|
200
210
|
${alignItems('center')}
|
|
@@ -230,8 +240,9 @@ export const datePickerStyle: ComponentStyle<StylableProps> = () => {
|
|
|
230
240
|
|
|
231
241
|
.o-time-container-range {
|
|
232
242
|
${marginLeft('3xl')}
|
|
233
|
-
${marginTop('2xl')}
|
|
234
243
|
${display('flex')}
|
|
244
|
+
${justifyContent('center')}
|
|
245
|
+
${height('full')}
|
|
235
246
|
${flexDirection('column')}
|
|
236
247
|
${gap('xl')}
|
|
237
248
|
.o-time-separator {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Placement } from '@popperjs/core';
|
|
2
|
+
import { AnonymousObject, FormFieldProps } from 'onekijs-framework';
|
|
2
3
|
import { StylableProps } from '../../styles/typings';
|
|
3
4
|
import { DropdownWidthModifier } from '../dropdown/typings';
|
|
4
|
-
import {
|
|
5
|
+
import { FieldDisplayerProps, FieldLayoutProps } from '../field/typings';
|
|
5
6
|
|
|
6
7
|
export type BasePickerProps = StylableProps & {
|
|
7
8
|
animationMs?: number;
|
|
@@ -64,7 +65,7 @@ export type DatePickerDate = {
|
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
export type DatePickerProps<T extends any = any> = BasePickerProps & {
|
|
67
|
-
adapter?: DateAdapter<T
|
|
68
|
+
adapter?: DateAdapter<T> | 'timestamp' | 'date';
|
|
68
69
|
onChange?: (value: T | null) => void;
|
|
69
70
|
value?: T | null;
|
|
70
71
|
};
|
|
@@ -93,19 +94,13 @@ export type DateStringRange = {
|
|
|
93
94
|
label?: string | null;
|
|
94
95
|
};
|
|
95
96
|
|
|
96
|
-
export type TimestampRange = {
|
|
97
|
-
from: number | null;
|
|
98
|
-
to: number | null;
|
|
99
|
-
label?: string | null;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
97
|
export type DateRangeAdapter<T extends any = any> = {
|
|
103
98
|
fromDateRange: (range: DateStringRange) => T;
|
|
104
99
|
toDateRange: (value: T) => DateStringRange;
|
|
105
100
|
};
|
|
106
101
|
|
|
107
102
|
export type DateRangePickerProps<T extends any = any> = BasePickerProps & {
|
|
108
|
-
adapter?: DateRangeAdapter<T
|
|
103
|
+
adapter?: DateRangeAdapter<T> | 'timestamp' | 'date';
|
|
109
104
|
closeOnQuickSelect?: boolean;
|
|
110
105
|
onChange?: (value: T | null) => void;
|
|
111
106
|
quickRanges?: AnonymousObject<DateStringRange>;
|
|
@@ -124,6 +119,55 @@ export type DisplayTime = {
|
|
|
124
119
|
displaySeconds?: boolean;
|
|
125
120
|
};
|
|
126
121
|
|
|
122
|
+
export type FormDatePickerProps<T> = DatePickerProps<T> &
|
|
123
|
+
FormFieldProps &
|
|
124
|
+
FieldLayoutProps & {
|
|
125
|
+
/**
|
|
126
|
+
* The default value of the field if no specific value has been specified
|
|
127
|
+
* A value can be passed to field
|
|
128
|
+
* * either manually by the user filling the form
|
|
129
|
+
* * via the setValue of the form controller (if the field is inside a <Form> component)
|
|
130
|
+
* * via an initial value transmitted to the form
|
|
131
|
+
*
|
|
132
|
+
* @remarks #important#
|
|
133
|
+
*/
|
|
134
|
+
defaultValue?: T;
|
|
135
|
+
/**
|
|
136
|
+
* There are three components used to display the value of an FormInput in the summary step
|
|
137
|
+
* * Displayer: display (label + value)
|
|
138
|
+
* * FieldDisplayer: extract the value from the field and display it
|
|
139
|
+
* * ValueDisplayer: customize how the value is displayed
|
|
140
|
+
*/
|
|
141
|
+
FieldDisplayer?: React.FC<FieldDisplayerProps>;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export type FormDateRangePickerProps<T> = DateRangePickerProps<T> &
|
|
145
|
+
FormFieldProps &
|
|
146
|
+
FieldLayoutProps & {
|
|
147
|
+
/**
|
|
148
|
+
* The default value of the field if no specific value has been specified
|
|
149
|
+
* A value can be passed to field
|
|
150
|
+
* * either manually by the user filling the form
|
|
151
|
+
* * via the setValue of the form controller (if the field is inside a <Form> component)
|
|
152
|
+
* * via an initial value transmitted to the form
|
|
153
|
+
*
|
|
154
|
+
* @remarks #important#
|
|
155
|
+
*/
|
|
156
|
+
defaultValue?: T;
|
|
157
|
+
/**
|
|
158
|
+
* There are three components used to display the value of an FormInput in the summary step
|
|
159
|
+
* * Displayer: display (label + value)
|
|
160
|
+
* * FieldDisplayer: extract the value from the field and display it
|
|
161
|
+
* * ValueDisplayer: customize how the value is displayed
|
|
162
|
+
*/
|
|
163
|
+
FieldDisplayer?: React.FC<FieldDisplayerProps>;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
export type FormDateTimePickerProps<T> = FormDatePickerProps<T> & DisplayTime;
|
|
168
|
+
|
|
169
|
+
export type FormDateTimeRangePickerProps<T> = FormDateRangePickerProps<T> & DisplayTime;
|
|
170
|
+
|
|
127
171
|
export type PickerComponentProps = BasePickerProps &
|
|
128
172
|
DisplayTime & {
|
|
129
173
|
closeOnQuickSelect?: boolean;
|
|
@@ -148,6 +192,7 @@ export type TimeComponentProps = StylableProps &
|
|
|
148
192
|
to: DatePickerDate;
|
|
149
193
|
type: DatePickerType;
|
|
150
194
|
onChange: (value: string, edge: 'from' | 'to') => void;
|
|
195
|
+
displayHeaders?: boolean;
|
|
151
196
|
};
|
|
152
197
|
|
|
153
198
|
export type TimePickerProps = BasePickerProps &
|
|
@@ -161,9 +206,11 @@ export type TimeRangeComponentProps = Required<DisplayTime> & {
|
|
|
161
206
|
value: DatePickerDate;
|
|
162
207
|
type: DatePickerType;
|
|
163
208
|
onChange: (value: string, edge: 'from' | 'to') => void;
|
|
209
|
+
displayHeaders?: boolean;
|
|
164
210
|
};
|
|
165
211
|
|
|
166
212
|
export type TimeSelectorComponentProps = Required<DisplayTime> & {
|
|
213
|
+
displayHeaders?: boolean;
|
|
167
214
|
edge: 'from' | 'to';
|
|
168
215
|
value: DatePickerDate;
|
|
169
216
|
onChange: (value: string, edge: 'from' | 'to') => void;
|
|
@@ -175,4 +222,13 @@ export type TimeSelectorPartComponentProps = {
|
|
|
175
222
|
value: string | number;
|
|
176
223
|
onChange: (value: string) => void;
|
|
177
224
|
size?: 'small' | 'large';
|
|
225
|
+
displayHeaders?: boolean;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export type TimestampFormat = 'seconds' | 'milliseconds';
|
|
229
|
+
|
|
230
|
+
export type TimestampRange = {
|
|
231
|
+
from: number | null;
|
|
232
|
+
to: number | null;
|
|
233
|
+
label?: string | null;
|
|
178
234
|
};
|