@kwiz/fluentui 1.0.51 → 1.0.53
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/controls/date.d.ts +7 -3
- package/dist/controls/date.js +41 -24
- package/dist/controls/date.js.map +1 -1
- package/package.json +2 -1
- package/src/controls/date.tsx +74 -28
package/dist/controls/date.d.ts
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
import { DatePickerProps } from '@fluentui/react-datepicker-compat';
|
2
|
+
import { TimePickerProps } from '@fluentui/react-timepicker-compat';
|
2
3
|
import * as React from 'react';
|
3
|
-
interface IProps
|
4
|
-
|
5
|
-
|
4
|
+
interface IProps {
|
5
|
+
onDateChange: (newDateObject: Date) => void;
|
6
|
+
value: Date;
|
7
|
+
showTime?: boolean;
|
8
|
+
datePickerProps?: DatePickerProps;
|
9
|
+
timePickerProps?: TimePickerProps;
|
6
10
|
}
|
7
11
|
export declare const DatePickerEx: React.FunctionComponent<React.PropsWithChildren<IProps>>;
|
8
12
|
export {};
|
package/dist/controls/date.js
CHANGED
@@ -1,32 +1,49 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
2
|
import { DatePicker } from '@fluentui/react-datepicker-compat';
|
3
|
+
import { TimePicker } from '@fluentui/react-timepicker-compat';
|
3
4
|
import { CalendarCancelRegular } from '@fluentui/react-icons';
|
4
|
-
import { isDate
|
5
|
+
import { isDate } from '@kwiz/common';
|
5
6
|
import * as React from 'react';
|
6
7
|
import { useKWIZFluentContext } from '../helpers/context';
|
8
|
+
import { useStateEX } from '../helpers/hooks';
|
9
|
+
import { Horizontal } from './horizontal';
|
7
10
|
export const DatePickerEx = (props) => {
|
8
11
|
const ctx = useKWIZFluentContext();
|
9
|
-
|
10
|
-
const
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
12
|
+
//time value will always have a value even when clearing the date
|
13
|
+
const [timeValue, setTimeValue] = useStateEX(isDate(props.value) ? props.value : new Date());
|
14
|
+
const { showClear, dateValue } = React.useMemo(() => {
|
15
|
+
const showClear = isDate(props.value);
|
16
|
+
const dateValue = props.value;
|
17
|
+
return { showClear, dateValue };
|
18
|
+
}, [props.value]);
|
19
|
+
function reset() {
|
20
|
+
props.onDateChange(null);
|
21
|
+
}
|
22
|
+
const changeDateHandler = React.useCallback((newDateValue) => {
|
23
|
+
const newDate = new Date(newDateValue);
|
24
|
+
// Use the old time values.
|
25
|
+
newDate.setHours(timeValue ? timeValue.getHours() : 0, timeValue ? timeValue.getMinutes() : 0, 0, 0);
|
26
|
+
props.onDateChange(newDate);
|
27
|
+
}, [timeValue]);
|
28
|
+
const changeTimeHandler = React.useCallback((newTimeValue) => {
|
29
|
+
//update our state
|
30
|
+
setTimeValue(newTimeValue);
|
31
|
+
// Use the old date value.
|
32
|
+
const newDate = isDate(dateValue) ? new Date(dateValue) : new Date();
|
33
|
+
newDate.setHours(newTimeValue.getHours(), newTimeValue.getMinutes(), 0, 0);
|
34
|
+
props.onDateChange(newDate);
|
35
|
+
}, [dateValue]);
|
36
|
+
const DatePickerControl = _jsx(DatePicker, Object.assign({}, (props.datePickerProps || {}), { appearance: ctx.inputAppearance, mountNode: ctx.mountNode, value: isDate(dateValue) ? dateValue : null, onSelectDate: (newDate) => {
|
37
|
+
changeDateHandler(newDate);
|
38
|
+
}, contentBefore: showClear && _jsx(CalendarCancelRegular, { title: 'Clear', onClick: () => reset() }) }));
|
39
|
+
const TimePickerControl = _jsx(TimePicker, Object.assign({ appearance: ctx.inputAppearance, mountNode: ctx.mountNode }, props.timePickerProps, {
|
40
|
+
//only show time value when there is a selected date. timeValue will never be null.
|
41
|
+
value: isDate(dateValue) ? timeValue.toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit", hour12: true }) : "", onTimeChange: (e, date) => {
|
42
|
+
const newDate = date.selectedTime;
|
43
|
+
changeTimeHandler(newDate);
|
44
|
+
} }));
|
45
|
+
return (props.showTime
|
46
|
+
? _jsxs(Horizontal, { children: [DatePickerControl, TimePickerControl] })
|
47
|
+
: DatePickerControl);
|
31
48
|
};
|
32
49
|
//# sourceMappingURL=date.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/controls/date.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/controls/date.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,UAAU,EAAmB,MAAM,mCAAmC,CAAC;AAEhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAS1C,MAAM,CAAC,MAAM,YAAY,GAA6D,CAAC,KAAK,EAAE,EAAE;IAC5F,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IAEnC,iEAAiE;IACjE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,UAAU,CAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CA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ACb,CAAC,CAAC,iBAAiB,CAC1B,CAAC;AACN,CAAC,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kwiz/fluentui",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.53",
|
4
4
|
"description": "KWIZ common controls for FluentUI",
|
5
5
|
"module": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -57,6 +57,7 @@
|
|
57
57
|
"typescript": "^5.3.3"
|
58
58
|
},
|
59
59
|
"dependencies": {
|
60
|
+
"@fluentui/react-timepicker-compat": "^0.2.42",
|
60
61
|
"@kwiz/common": "^1.0.103",
|
61
62
|
"esbuild": "^0.19.12",
|
62
63
|
"get-tsconfig": "^4.7.2",
|
package/src/controls/date.tsx
CHANGED
@@ -1,40 +1,86 @@
|
|
1
1
|
import { DatePicker, DatePickerProps } from '@fluentui/react-datepicker-compat';
|
2
|
+
import { TimePicker, TimePickerProps } from '@fluentui/react-timepicker-compat';
|
3
|
+
|
2
4
|
import { CalendarCancelRegular } from '@fluentui/react-icons';
|
3
|
-
import { isDate
|
5
|
+
import { isDate } from '@kwiz/common';
|
4
6
|
import * as React from 'react';
|
5
7
|
import { useKWIZFluentContext } from '../helpers/context';
|
8
|
+
import { useStateEX } from '../helpers/hooks';
|
9
|
+
import { Horizontal } from './horizontal';
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
interface IProps {
|
12
|
+
onDateChange: (newDateObject: Date) => void;
|
13
|
+
value: Date;
|
14
|
+
showTime?: boolean;
|
15
|
+
datePickerProps?: DatePickerProps;
|
16
|
+
timePickerProps?: TimePickerProps;
|
11
17
|
}
|
12
18
|
export const DatePickerEx: React.FunctionComponent<React.PropsWithChildren<IProps>> = (props) => {
|
13
19
|
const ctx = useKWIZFluentContext();
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
|
21
|
+
//time value will always have a value even when clearing the date
|
22
|
+
const [timeValue, setTimeValue] = useStateEX<Date>(isDate(props.value) ? props.value : new Date());
|
23
|
+
const { showClear, dateValue } = React.useMemo(() => {
|
24
|
+
const showClear = isDate(props.value);
|
25
|
+
const dateValue = props.value;
|
26
|
+
return { showClear, dateValue };
|
27
|
+
}, [props.value]);
|
28
|
+
|
29
|
+
function reset() {
|
30
|
+
props.onDateChange(null);
|
31
|
+
}
|
32
|
+
|
33
|
+
const changeDateHandler = React.useCallback((newDateValue: Date): void => {
|
34
|
+
const newDate = new Date(newDateValue);
|
35
|
+
// Use the old time values.
|
36
|
+
newDate.setHours(
|
37
|
+
timeValue ? timeValue.getHours() : 0,
|
38
|
+
timeValue ? timeValue.getMinutes() : 0, 0, 0
|
39
|
+
);
|
40
|
+
props.onDateChange(newDate);
|
41
|
+
}, [timeValue]);
|
42
|
+
|
43
|
+
const changeTimeHandler = React.useCallback((newTimeValue: Date): void => {
|
44
|
+
//update our state
|
45
|
+
setTimeValue(newTimeValue);
|
46
|
+
// Use the old date value.
|
47
|
+
const newDate = isDate(dateValue) ? new Date(dateValue) : new Date();
|
48
|
+
newDate.setHours(
|
49
|
+
newTimeValue.getHours(),
|
50
|
+
newTimeValue.getMinutes(), 0, 0
|
51
|
+
);
|
52
|
+
props.onDateChange(newDate);
|
53
|
+
}, [dateValue]);
|
54
|
+
|
55
|
+
const DatePickerControl = <DatePicker
|
56
|
+
{...(props.datePickerProps || {})}
|
57
|
+
appearance={ctx.inputAppearance}
|
58
|
+
mountNode={ctx.mountNode}
|
59
|
+
value={isDate(dateValue) ? dateValue : null}
|
60
|
+
onSelectDate={(newDate) => {
|
61
|
+
changeDateHandler(newDate);
|
62
|
+
}}
|
63
|
+
contentBefore={showClear && <CalendarCancelRegular title='Clear' onClick={() => reset()} />}
|
64
|
+
/>
|
65
|
+
|
66
|
+
const TimePickerControl = <TimePicker
|
67
|
+
appearance={ctx.inputAppearance}
|
68
|
+
mountNode={ctx.mountNode}
|
69
|
+
{...props.timePickerProps}
|
70
|
+
//only show time value when there is a selected date. timeValue will never be null.
|
71
|
+
value={isDate(dateValue) ? timeValue.toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit", hour12: true }) : ""}
|
72
|
+
onTimeChange={(e, date) => {
|
73
|
+
const newDate = date.selectedTime;
|
74
|
+
changeTimeHandler(newDate);
|
75
|
+
}}
|
76
|
+
/>
|
19
77
|
|
20
78
|
return (
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
setShowClear(!isNullOrEmptyString(data.value));
|
28
|
-
if (isFunction(props.onChange)) props.onChange(e, data);
|
29
|
-
}}
|
30
|
-
onKeyDown={isFunction(props.onOK) || isFunction(props.onCancel)
|
31
|
-
? e => {
|
32
|
-
if (isFunction(props.onOK) && e.key === "Enter") props.onOK();
|
33
|
-
else if (isFunction(props.onCancel) && e.key === "Escape") props.onCancel();
|
34
|
-
}
|
35
|
-
: undefined
|
36
|
-
}
|
37
|
-
contentBefore={showClear && <CalendarCancelRegular title='Clear' onClick={() => reset()} />}
|
38
|
-
/>
|
79
|
+
props.showTime
|
80
|
+
? <Horizontal>
|
81
|
+
{DatePickerControl}
|
82
|
+
{TimePickerControl}
|
83
|
+
</Horizontal>
|
84
|
+
: DatePickerControl
|
39
85
|
);
|
40
86
|
}
|