@headless-adminapp/fluent 0.0.17-alpha.46 → 0.0.17-alpha.47
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.
|
@@ -7,23 +7,95 @@ exports.DateTimeControl = DateTimeControl;
|
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
8
|
const react_components_1 = require("@fluentui/react-components");
|
|
9
9
|
const react_datepicker_compat_1 = require("@fluentui/react-datepicker-compat");
|
|
10
|
+
const react_timepicker_compat_1 = require("@fluentui/react-timepicker-compat");
|
|
10
11
|
const icons_1 = require("@headless-adminapp/icons");
|
|
11
12
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
13
|
+
const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat"));
|
|
14
|
+
const react_1 = require("react");
|
|
15
|
+
dayjs_1.default.extend(customParseFormat_1.default);
|
|
12
16
|
function DateTimeControl({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, readOnly, }) {
|
|
13
17
|
// const { shortDate: dateFormat } = useLocale();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
const [internalTimeValue, setInternalTimeValue] = (0, react_1.useState)(value ? (0, dayjs_1.default)(value).format('hh:mm A') : '');
|
|
19
|
+
const internalTimeValueRef = (0, react_1.useRef)(internalTimeValue);
|
|
20
|
+
internalTimeValueRef.current = internalTimeValue;
|
|
21
|
+
(0, react_1.useEffect)(() => {
|
|
22
|
+
const updatedValue = value ? (0, dayjs_1.default)(value).format('hh:mm A') : '';
|
|
23
|
+
if (internalTimeValueRef.current !== updatedValue) {
|
|
24
|
+
setInternalTimeValue(updatedValue);
|
|
25
|
+
}
|
|
26
|
+
}, [value]);
|
|
27
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
28
|
+
display: 'flex',
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
gap: react_components_1.tokens.spacingHorizontalS,
|
|
31
|
+
}, children: [(0, jsx_runtime_1.jsx)(react_datepicker_compat_1.DatePicker, { id: id, name: name, onFocus: () => onFocus === null || onFocus === void 0 ? void 0 : onFocus(), onBlur: () => onBlur === null || onBlur === void 0 ? void 0 : onBlur(), placeholder: placeholder, appearance: "filled-darker", formatDate: (date) => (date ? (0, dayjs_1.default)(date).format('YYYY-MM-DD') : ''), disabled: disabled, readOnly: readOnly, value: value ? new Date(value) : null, onSelectDate: (date) => {
|
|
32
|
+
if (!date) {
|
|
33
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(null);
|
|
34
|
+
}
|
|
35
|
+
else if (!value) {
|
|
36
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(date.toISOString());
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
onChange === null || onChange === void 0 ? void 0 : onChange((0, dayjs_1.default)(date)
|
|
40
|
+
.set('hour', (0, dayjs_1.default)(value).hour())
|
|
41
|
+
.set('minute', (0, dayjs_1.default)(value).minute())
|
|
42
|
+
.toISOString());
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
// allowTextInput={true}
|
|
46
|
+
contentAfter: (0, jsx_runtime_1.jsx)("div", { style: {
|
|
47
|
+
display: 'flex',
|
|
48
|
+
alignItems: 'center',
|
|
49
|
+
justifyContent: 'center',
|
|
50
|
+
marginRight: -4,
|
|
51
|
+
color: react_components_1.tokens.colorNeutralForeground2,
|
|
52
|
+
}, children: (0, jsx_runtime_1.jsx)(icons_1.Icons.Calendar, { size: 20 }) }), style: { flex: 1 }, input: {
|
|
53
|
+
style: { minWidth: 0, width: '100%' },
|
|
54
|
+
} }), (0, jsx_runtime_1.jsx)(react_timepicker_compat_1.TimePicker, { appearance: "filled-darker", style: { flex: 1, minWidth: 0 }, input: {
|
|
55
|
+
style: { minWidth: 0 },
|
|
56
|
+
}, readOnly: readOnly || disabled || !value, selectedTime: value ? new Date(value) : null, freeform: true, value: internalTimeValue, onTimeChange: (_, data) => {
|
|
57
|
+
const dateValue = value ? new Date(value) : new Date();
|
|
58
|
+
if (data.selectedTime) {
|
|
59
|
+
onChange === null || onChange === void 0 ? void 0 : onChange((0, dayjs_1.default)(dateValue)
|
|
60
|
+
.set('hour', data.selectedTime.getHours())
|
|
61
|
+
.set('minute', data.selectedTime.getMinutes())
|
|
62
|
+
.toISOString());
|
|
63
|
+
}
|
|
64
|
+
else if (data.selectedTimeText) {
|
|
65
|
+
let resolvedTime = resolveTimeValue(data.selectedTimeText);
|
|
66
|
+
if (!resolvedTime) {
|
|
67
|
+
setInternalTimeValue(value ? (0, dayjs_1.default)(value).format('hh:mm A') : '');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const newValue = (0, dayjs_1.default)(dateValue)
|
|
71
|
+
.set('hour', resolvedTime.getHours())
|
|
72
|
+
.set('minute', resolvedTime.getMinutes())
|
|
73
|
+
.toISOString();
|
|
74
|
+
if (newValue !== value) {
|
|
75
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
76
|
+
}
|
|
77
|
+
setInternalTimeValue(newValue ? (0, dayjs_1.default)(newValue).format('hh:mm A') : '');
|
|
78
|
+
}
|
|
79
|
+
}, onInput: (e) => {
|
|
80
|
+
setInternalTimeValue(e.currentTarget.value);
|
|
81
|
+
}, onBlur: () => {
|
|
82
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
83
|
+
}, expandIcon: (0, jsx_runtime_1.jsx)("div", { style: {
|
|
84
|
+
display: 'flex',
|
|
85
|
+
alignItems: 'center',
|
|
86
|
+
justifyContent: 'center',
|
|
87
|
+
marginRight: -4,
|
|
88
|
+
color: react_components_1.tokens.colorNeutralForeground2,
|
|
89
|
+
}, children: (0, jsx_runtime_1.jsx)(icons_1.Icons.Clock, { size: 20 }) }) })] }));
|
|
90
|
+
}
|
|
91
|
+
function resolveTimeValue(value) {
|
|
92
|
+
if (!value) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const time = (0, dayjs_1.default)(value, 'hh:mm A');
|
|
96
|
+
console.log('resolveTimeValue', time);
|
|
97
|
+
if (!time.isValid()) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
return time.toDate();
|
|
29
101
|
}
|
|
@@ -5,8 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
/* eslint-disable unused-imports/no-unused-vars */
|
|
6
6
|
const react_components_1 = require("@fluentui/react-components");
|
|
7
7
|
function IntegerControl({ value, onChange, id, name, onBlur, onFocus, error, disabled, placeholder, borderOnFocusOnly, readOnly, }) {
|
|
8
|
-
|
|
9
|
-
return ((0, jsx_runtime_1.jsx)(react_components_1.SpinButton, { appearance: "filled-darker", placeholder: placeholder, id: id, name: name, value: value, onChange: (e, data) => {
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.SpinButton, { appearance: "filled-darker", placeholder: placeholder, id: id, name: name, value: value !== null && value !== void 0 ? value : null, onChange: (e, data) => {
|
|
10
9
|
if (data.value !== undefined) {
|
|
11
10
|
onChange === null || onChange === void 0 ? void 0 : onChange(data.value);
|
|
12
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/fluent",
|
|
3
|
-
"version": "0.0.17-alpha.
|
|
3
|
+
"version": "0.0.17-alpha.47",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -29,8 +29,9 @@
|
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@fluentui/react-components": "9.54.4",
|
|
32
|
-
"@fluentui/react-datepicker-compat": "
|
|
33
|
-
"@fluentui/react-nav-preview": "
|
|
32
|
+
"@fluentui/react-datepicker-compat": "0.4.43",
|
|
33
|
+
"@fluentui/react-nav-preview": "0.5.1",
|
|
34
|
+
"@fluentui/react-timepicker-compat": "0.2.46",
|
|
34
35
|
"@hookform/resolvers": "^3.9.0",
|
|
35
36
|
"@tanstack/react-query": "5.51.1",
|
|
36
37
|
"@tanstack/react-table": "^8.20.1",
|
|
@@ -48,5 +49,5 @@
|
|
|
48
49
|
"uuid": "11.0.3",
|
|
49
50
|
"yup": "^1.4.0"
|
|
50
51
|
},
|
|
51
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "749a69f512d51c82f33fe27f8bbe5046fdeab4c5"
|
|
52
53
|
}
|