@kwiz/fluentui 1.0.51 → 1.0.52
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 +35 -24
- package/dist/controls/date.js.map +1 -1
- package/package.json +2 -1
- package/src/controls/date.tsx +69 -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,43 @@
|
|
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 { Horizontal } from './horizontal';
|
7
9
|
export const DatePickerEx = (props) => {
|
8
10
|
const ctx = useKWIZFluentContext();
|
9
|
-
const
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}, [
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
11
|
+
const { showClear, dateValue, timeValue } = React.useMemo(() => {
|
12
|
+
const showClear = isDate(props.value);
|
13
|
+
const dateValue = props.value;
|
14
|
+
const timeValue = props.value;
|
15
|
+
return { showClear, dateValue, timeValue };
|
16
|
+
}, [props.value]);
|
17
|
+
function reset() {
|
18
|
+
props.onDateChange(null);
|
19
|
+
}
|
20
|
+
const changeDateHandler = React.useCallback((newDateValue) => {
|
21
|
+
const newDate = new Date(newDateValue);
|
22
|
+
// Use the old time values.
|
23
|
+
newDate.setHours(timeValue.getHours(), timeValue.getMinutes(), 0, 0);
|
24
|
+
props.onDateChange(newDate);
|
25
|
+
}, [timeValue]);
|
26
|
+
const changeTimeHandler = React.useCallback((newTimeValue) => {
|
27
|
+
// Use the old date value.
|
28
|
+
const newDate = new Date(dateValue);
|
29
|
+
newDate.setHours(newTimeValue.getHours(), newTimeValue.getMinutes(), 0, 0);
|
30
|
+
props.onDateChange(newDate);
|
31
|
+
}, [dateValue]);
|
32
|
+
const DatePickerControl = _jsx(DatePicker, Object.assign({}, (props.datePickerProps || {}), { appearance: ctx.inputAppearance, mountNode: ctx.mountNode, value: dateValue, onSelectDate: (newDate) => {
|
33
|
+
changeDateHandler(newDate);
|
34
|
+
}, contentBefore: showClear && _jsx(CalendarCancelRegular, { title: 'Clear', onClick: () => reset() }) }));
|
35
|
+
const TimePickerControl = _jsx(TimePicker, Object.assign({ appearance: ctx.inputAppearance, mountNode: ctx.mountNode }, props.timePickerProps, { value: timeValue.toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit", hour12: true }), onTimeChange: (e, date) => {
|
36
|
+
const newDate = date.selectedTime;
|
37
|
+
changeTimeHandler(newDate);
|
38
|
+
} }));
|
39
|
+
return (props.showTime
|
40
|
+
? _jsxs(Horizontal, { children: [DatePickerControl, TimePickerControl] })
|
41
|
+
: DatePickerControl);
|
31
42
|
};
|
32
43
|
//# 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,cAAc,CAAC;AAS1C,MAAM,CAAC,MAAM,YAAY,GAA6D,CAAC,KAAK,EAAE,EAAE;IAC5F,MAAM,GAAG,GAAG,oBAAoB,EAAE,CAAC;IAEnC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAC3D,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtC,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;QAC9B,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;QAC9B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;IAC/C,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAElB,SAAS,KAAK;QACV,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,iBAAiB,GAAG,K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,CAAC,SAAS,IACpB,KAAK,CAAC,eAAe,IACzB,KAAK,EAAE,SAAS,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAC/F,YAAY,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;YACtB,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC;YAClC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC,IACH,CAAA;IAEF,OAAO,CACH,KAAK,CAAC,QAAQ;QACV,CAAC,CAAC,MAAC,UAAU,eACR,iBAAiB,EACjB,iBAAiB,IACT;QACb,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.52",
|
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,81 @@
|
|
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 { Horizontal } from './horizontal';
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
interface IProps {
|
11
|
+
onDateChange: (newDateObject: Date) => void;
|
12
|
+
value: Date;
|
13
|
+
showTime?: boolean;
|
14
|
+
datePickerProps?: DatePickerProps;
|
15
|
+
timePickerProps?: TimePickerProps;
|
11
16
|
}
|
12
17
|
export const DatePickerEx: React.FunctionComponent<React.PropsWithChildren<IProps>> = (props) => {
|
13
18
|
const ctx = useKWIZFluentContext();
|
14
|
-
|
15
|
-
const
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
|
20
|
+
const { showClear, dateValue, timeValue } = React.useMemo(() => {
|
21
|
+
const showClear = isDate(props.value);
|
22
|
+
const dateValue = props.value;
|
23
|
+
const timeValue = props.value;
|
24
|
+
return { showClear, dateValue, timeValue };
|
25
|
+
}, [props.value]);
|
26
|
+
|
27
|
+
function reset() {
|
28
|
+
props.onDateChange(null);
|
29
|
+
}
|
30
|
+
|
31
|
+
const changeDateHandler = React.useCallback((newDateValue: Date): void => {
|
32
|
+
const newDate = new Date(newDateValue);
|
33
|
+
// Use the old time values.
|
34
|
+
newDate.setHours(
|
35
|
+
timeValue.getHours(),
|
36
|
+
timeValue.getMinutes(), 0, 0
|
37
|
+
);
|
38
|
+
props.onDateChange(newDate);
|
39
|
+
}, [timeValue]);
|
40
|
+
|
41
|
+
const changeTimeHandler = React.useCallback((newTimeValue: Date): void => {
|
42
|
+
// Use the old date value.
|
43
|
+
const newDate = new Date(dateValue);
|
44
|
+
newDate.setHours(
|
45
|
+
newTimeValue.getHours(),
|
46
|
+
newTimeValue.getMinutes(), 0, 0
|
47
|
+
);
|
48
|
+
props.onDateChange(newDate);
|
49
|
+
}, [dateValue]);
|
50
|
+
|
51
|
+
const DatePickerControl = <DatePicker
|
52
|
+
{...(props.datePickerProps || {})}
|
53
|
+
appearance={ctx.inputAppearance}
|
54
|
+
mountNode={ctx.mountNode}
|
55
|
+
value={dateValue}
|
56
|
+
onSelectDate={(newDate) => {
|
57
|
+
changeDateHandler(newDate);
|
58
|
+
}}
|
59
|
+
contentBefore={showClear && <CalendarCancelRegular title='Clear' onClick={() => reset()} />}
|
60
|
+
/>
|
61
|
+
|
62
|
+
const TimePickerControl = <TimePicker
|
63
|
+
appearance={ctx.inputAppearance}
|
64
|
+
mountNode={ctx.mountNode}
|
65
|
+
{...props.timePickerProps}
|
66
|
+
value={timeValue.toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit", hour12: true })}
|
67
|
+
onTimeChange={(e, date) => {
|
68
|
+
const newDate = date.selectedTime;
|
69
|
+
changeTimeHandler(newDate);
|
70
|
+
}}
|
71
|
+
/>
|
19
72
|
|
20
73
|
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
|
-
/>
|
74
|
+
props.showTime
|
75
|
+
? <Horizontal>
|
76
|
+
{DatePickerControl}
|
77
|
+
{TimePickerControl}
|
78
|
+
</Horizontal>
|
79
|
+
: DatePickerControl
|
39
80
|
);
|
40
81
|
}
|