@headless-adminapp/fluent 1.2.4 → 1.3.1
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/DataGrid/useTableColumns.js +1 -11
- package/Insights/Header.js +1 -1
- package/Insights/WidgetSection.js +1 -0
- package/Insights/WidgetTableContainer.js +37 -14
- package/PageEntityForm/PageEntityFormDesktopContainer.js +2 -1
- package/PageEntityForm/RecordCard.js +7 -5
- package/form/controls/DateControl.js +7 -6
- package/form/controls/DateRangeControl/CalendarItem.d.ts +13 -0
- package/form/controls/DateRangeControl/CalendarItem.js +53 -0
- package/form/controls/DateRangeControl/DateRangeControl.d.ts +6 -0
- package/form/controls/DateRangeControl/DateRangeControl.js +37 -0
- package/form/controls/DateRangeControl/PopoverContent.d.ts +11 -0
- package/form/controls/DateRangeControl/PopoverContent.js +80 -0
- package/form/controls/DateRangeControl/index.d.ts +1 -0
- package/form/controls/DateRangeControl/index.js +5 -0
- package/form/controls/DateRangeControl/utils.d.ts +13 -0
- package/form/controls/DateRangeControl/utils.js +129 -0
- package/form/controls/DateRangeControl.d.ts +7 -1
- package/form/controls/DateRangeControl.js +274 -28
- package/form/controls/DateTimeControl.js +3 -12
- package/form/controls/EmailControl.js +1 -0
- package/form/controls/IntegerControl.js +3 -1
- package/form/controls/MultiSelectControl.js +3 -1
- package/form/controls/MultiSelectLookupControl.js +1 -1
- package/form/controls/SelectControl.js +1 -1
- package/form/controls/TextAreaControl.js +3 -1
- package/form/controls/TimeControl/TimeControl.d.ts +4 -0
- package/form/controls/TimeControl/TimeControl.js +78 -0
- package/form/controls/TimeControl/index.d.ts +1 -0
- package/form/controls/TimeControl/index.js +5 -0
- package/form/controls/TimeControl/utils.d.ts +1 -0
- package/form/controls/TimeControl/utils.js +42 -0
- package/package.json +2 -2
|
@@ -258,7 +258,6 @@ function renderCellHeaderContent({ column, props, disableColumnResize, disableCo
|
|
|
258
258
|
return ((0, jsx_runtime_1.jsx)(GridColumnHeader_1.TableHeaderFilterCell, { columnName: column.name, sortDirection: props.column.getIsSorted() || undefined, minWidth: props.header.getSize(), column: column, resizable: !disableColumnResize, disableFilter: disableColumnFilter, disableSort: disableColumnSort, onChangeSortDirection: onChangeSortDirection, attribute: attribute, onResetSize: props.column.resetSize, resizeHandler: props.header.getResizeHandler(), children: column.label }, column.id));
|
|
259
259
|
}
|
|
260
260
|
function renderCellContent({ info, column, schema, schemaStore, locale, routeResolver, openRecord, recordSetSetter, router, }) {
|
|
261
|
-
const { currency, dateFormats, timezone, timeFormats } = locale;
|
|
262
261
|
let attribute;
|
|
263
262
|
let value;
|
|
264
263
|
if (column.expandedKey) {
|
|
@@ -273,16 +272,7 @@ function renderCellContent({ info, column, schema, schemaStore, locale, routeRes
|
|
|
273
272
|
attribute = schema.attributes[column.name];
|
|
274
273
|
value = info.getValue();
|
|
275
274
|
}
|
|
276
|
-
const formattedValue = (0, utils_1.getAttributeFormattedValue)(attribute, value,
|
|
277
|
-
currency: currency.currency,
|
|
278
|
-
dateFormat: dateFormats.short,
|
|
279
|
-
timeFormat: timeFormats.short,
|
|
280
|
-
timezone,
|
|
281
|
-
currencyDisplay: currency.currencyDisplay,
|
|
282
|
-
currencySign: currency.currencySign,
|
|
283
|
-
locale: locale.locale,
|
|
284
|
-
region: locale.region,
|
|
285
|
-
}) ?? '';
|
|
275
|
+
const formattedValue = (0, utils_1.getAttributeFormattedValue)(attribute, value, locale) ?? '';
|
|
286
276
|
if (column.plainText) {
|
|
287
277
|
return ((0, jsx_runtime_1.jsx)(TableCell_1.TableCellText, { value: formattedValue, width: info.column.getSize() }, column.id));
|
|
288
278
|
}
|
package/Insights/Header.js
CHANGED
|
@@ -43,7 +43,7 @@ const Header = () => {
|
|
|
43
43
|
eventManager.emit('INSIGHT_REFRESH_TRIGGER');
|
|
44
44
|
}, children: "Refresh" }) })] }), !!config.filterAttributes && ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_components_1.Divider, { style: { opacity: 0.2 } }), (0, jsx_runtime_1.jsx)("div", { style: { display: 'flex', gap: react_components_1.tokens.spacingHorizontalS }, children: Object.entries(config.filterAttributes).map(([attributeName, attribute]) => {
|
|
45
45
|
return ((0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { control: filterForm.control, name: attributeName, render: ({ field }) => {
|
|
46
|
-
return ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(StandardControl_1.StandardControl, { attribute: attribute, name: attributeName, value: field.value, onChange: field.onChange, onBlur: field.onBlur }) }));
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: { width: 210, minWidth: 210 }, children: (0, jsx_runtime_1.jsx)(StandardControl_1.StandardControl, { attribute: attribute, name: attributeName, value: field.value, onChange: field.onChange, onBlur: field.onBlur }) }));
|
|
47
47
|
} }, attributeName));
|
|
48
48
|
}) })] }))] }));
|
|
49
49
|
};
|
|
@@ -3,15 +3,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WidgetTableContainer = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_components_1 = require("@fluentui/react-components");
|
|
6
|
+
const locale_1 = require("@headless-adminapp/app/locale");
|
|
6
7
|
const utils_1 = require("@headless-adminapp/app/utils");
|
|
7
8
|
const BodyLoading_1 = require("../components/BodyLoading");
|
|
8
9
|
const WidgetSection_1 = require("./WidgetSection");
|
|
9
10
|
const WidgetTitleBar_1 = require("./WidgetTitleBar");
|
|
11
|
+
const useStyles = (0, react_components_1.makeStyles)({
|
|
12
|
+
table: {
|
|
13
|
+
borderCollapse: 'collapse',
|
|
14
|
+
width: '100%',
|
|
15
|
+
'& tr': {
|
|
16
|
+
borderBottom: `${react_components_1.tokens.strokeWidthThin} solid ${react_components_1.tokens.colorNeutralStroke3}`,
|
|
17
|
+
},
|
|
18
|
+
'& th': {
|
|
19
|
+
fontWeight: react_components_1.tokens.fontWeightMedium,
|
|
20
|
+
minWidth: '32px',
|
|
21
|
+
flexShrink: 0,
|
|
22
|
+
flex: 1,
|
|
23
|
+
position: 'sticky',
|
|
24
|
+
background: react_components_1.tokens.colorNeutralBackground3,
|
|
25
|
+
borderBottom: `${react_components_1.tokens.strokeWidthThin} solid ${react_components_1.tokens.colorNeutralStroke3}`,
|
|
26
|
+
},
|
|
27
|
+
'& td': {
|
|
28
|
+
height: '36px',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
headerAlignRight: {
|
|
32
|
+
textAlign: 'right',
|
|
33
|
+
'& > div': {
|
|
34
|
+
justifyContent: 'flex-end',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
10
38
|
const WidgetTableContainer = ({ title, columns, attributes, isPending, isFetching, commands, data, }) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}, children: [(0, jsx_runtime_1.jsx)(react_components_1.TableHeader, { style: {
|
|
39
|
+
const locale = (0, locale_1.useLocale)();
|
|
40
|
+
const styles = useStyles();
|
|
41
|
+
return ((0, jsx_runtime_1.jsxs)(WidgetSection_1.WidgetSection, { children: [(0, jsx_runtime_1.jsx)(WidgetTitleBar_1.WidgetTitleBar, { title: title, commands: commands }), (0, jsx_runtime_1.jsxs)("div", { style: { flex: 1, position: 'relative', overflow: 'auto' }, children: [!isPending && ((0, jsx_runtime_1.jsxs)(react_components_1.Table, { className: styles.table, children: [(0, jsx_runtime_1.jsx)(react_components_1.TableHeader, { style: {
|
|
15
42
|
position: 'sticky',
|
|
16
43
|
top: 0,
|
|
17
44
|
background: react_components_1.tokens.colorNeutralBackground3,
|
|
@@ -22,21 +49,17 @@ const WidgetTableContainer = ({ title, columns, attributes, isPending, isFetchin
|
|
|
22
49
|
minWidth: 'calc(100% - 16px)',
|
|
23
50
|
}, children: columns.map((column, index) => {
|
|
24
51
|
const attribute = attributes[column];
|
|
25
|
-
return ((0, jsx_runtime_1.jsx)(react_components_1.TableHeaderCell, {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
flex: 1,
|
|
29
|
-
position: 'sticky',
|
|
30
|
-
background: react_components_1.tokens.colorNeutralBackground3,
|
|
31
|
-
borderBottom: `${react_components_1.tokens.strokeWidthThin} solid ${react_components_1.tokens.colorNeutralStroke3}`,
|
|
32
|
-
}, children: attribute.label }, column + String(index)));
|
|
52
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.TableHeaderCell, { align: "right", className: attribute?.type === 'money'
|
|
53
|
+
? styles.headerAlignRight
|
|
54
|
+
: '', children: attribute.label }, column + String(index)));
|
|
33
55
|
}) }) }), (0, jsx_runtime_1.jsx)(react_components_1.TableBody, { children: data.map((row, index) => ((0, jsx_runtime_1.jsx)(react_components_1.TableRow, { children: columns.map((column) => {
|
|
34
56
|
const attribute = attributes[column];
|
|
35
57
|
const value = row[column];
|
|
36
|
-
const formattedValue = (0, utils_1.getAttributeFormattedValue)(attribute, value) ??
|
|
58
|
+
const formattedValue = (0, utils_1.getAttributeFormattedValue)(attribute, value, locale) ??
|
|
59
|
+
'';
|
|
37
60
|
switch (attribute?.type) {
|
|
38
61
|
case 'money':
|
|
39
|
-
return ((0, jsx_runtime_1.jsx)(react_components_1.TableCell, { children: formattedValue }, column));
|
|
62
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.TableCell, { style: { textAlign: 'right' }, children: formattedValue }, column));
|
|
40
63
|
case 'lookup':
|
|
41
64
|
return null;
|
|
42
65
|
}
|
|
@@ -26,6 +26,7 @@ let previousCachedActiveTabInfo = null;
|
|
|
26
26
|
const PageEntityFormDesktopContainer = () => {
|
|
27
27
|
const dataState = (0, mutable_1.useContextSelector)(dataform_1.DataFormContext, (state) => state.dataState);
|
|
28
28
|
const strings = (0, PageEntityFormStringContext_1.usePageEntityFormStrings)();
|
|
29
|
+
const locale = (0, locale_1.useLocale)();
|
|
29
30
|
const recordId = (0, hooks_1.useRecordId)();
|
|
30
31
|
const record = (0, mutable_1.useContextSelector)(dataform_1.DataFormContext, (state) => state.record);
|
|
31
32
|
const activeTab = (0, mutable_1.useContextSelector)(dataform_1.DataFormContext, (state) => state.activeTab);
|
|
@@ -120,7 +121,7 @@ const PageEntityFormDesktopContainer = () => {
|
|
|
120
121
|
width: react_components_1.tokens.spacingHorizontalXXL,
|
|
121
122
|
opacity: 0.5,
|
|
122
123
|
} })), (0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)(react_components_1.Body1, { style: { color: react_components_1.tokens.colorNeutralForeground4 }, children: attribute.label }), (0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { control: formInstance.control, name: controlName, render: ({ field }) => {
|
|
123
|
-
return ((0, jsx_runtime_1.jsx)(react_components_1.Body1, { children: (0, utils_2.getAttributeFormattedValue)(attribute, field.value) }));
|
|
124
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.Body1, { children: (0, utils_2.getAttributeFormattedValue)(attribute, field.value, locale) }));
|
|
124
125
|
} })] })] }, controlName));
|
|
125
126
|
}) })] }), !!processFlowSteps?.length && ((0, jsx_runtime_1.jsx)(ProcessFlow_1.ProcessFlow, { height: 28, rounded: false, items: processFlowSteps })), (0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', paddingBottom: react_components_1.tokens.spacingVerticalS }, children: [(0, jsx_runtime_1.jsxs)(react_components_1.TabList, { selectedValue: activeTab, onTabSelect: (e, value) => {
|
|
126
127
|
setActiveTab(value.value);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RecordCard = RecordCard;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_components_1 = require("@fluentui/react-components");
|
|
6
|
+
const locale_1 = require("@headless-adminapp/app/locale");
|
|
6
7
|
const utils_1 = require("@headless-adminapp/app/utils");
|
|
7
8
|
const ChoiceBadge_1 = require("../components/ChoiceBadge");
|
|
8
9
|
const useStyles = (0, react_components_1.makeStyles)({
|
|
@@ -36,6 +37,7 @@ function createIntial(name) {
|
|
|
36
37
|
}
|
|
37
38
|
function RecordCard({ schema, cardView, record, selected, }) {
|
|
38
39
|
const styles = useStyles();
|
|
40
|
+
const locale = (0, locale_1.useLocale)();
|
|
39
41
|
const _record = record;
|
|
40
42
|
const recordTitle = _record[schema.primaryAttribute];
|
|
41
43
|
const initials = createIntial(recordTitle);
|
|
@@ -60,7 +62,7 @@ function RecordCard({ schema, cardView, record, selected, }) {
|
|
|
60
62
|
display: 'flex',
|
|
61
63
|
flexDirection: 'column',
|
|
62
64
|
flex: 1,
|
|
63
|
-
}, children: [(0, jsx_runtime_1.jsx)(react_components_1.Body1, { style: { wordBreak: 'break-all' }, children: (0, utils_1.getAttributeFormattedValue)(schema.attributes[cardView.primaryColumn], _record[cardView.primaryColumn]) }), cardView.secondaryColumns?.map((column) => ((0, jsx_runtime_1.jsx)(SecondaryColumnContent, { record: _record, column: column, schema: schema }, column.name)))] }), !!cardView.rightColumn?.length && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
65
|
+
}, children: [(0, jsx_runtime_1.jsx)(react_components_1.Body1, { style: { wordBreak: 'break-all' }, children: (0, utils_1.getAttributeFormattedValue)(schema.attributes[cardView.primaryColumn], _record[cardView.primaryColumn], locale) }), cardView.secondaryColumns?.map((column) => ((0, jsx_runtime_1.jsx)(SecondaryColumnContent, { record: _record, column: column, schema: schema, locale: locale }, column.name)))] }), !!cardView.rightColumn?.length && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
64
66
|
display: 'flex',
|
|
65
67
|
flexDirection: 'column',
|
|
66
68
|
alignItems: 'flex-end',
|
|
@@ -76,12 +78,12 @@ function RecordCard({ schema, cardView, record, selected, }) {
|
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
if (column.variant === 'strong') {
|
|
79
|
-
return ((0, jsx_runtime_1.jsx)(react_components_1.Body1Strong, { children: (0, utils_1.getAttributeFormattedValue)(value, attribute) }, column.name));
|
|
81
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.Body1Strong, { children: (0, utils_1.getAttributeFormattedValue)(value, attribute, locale) }, column.name));
|
|
80
82
|
}
|
|
81
|
-
return ((0, jsx_runtime_1.jsx)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4 }, children: (0, utils_1.getAttributeFormattedValue)(value, attribute) }, column.name));
|
|
83
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4 }, children: (0, utils_1.getAttributeFormattedValue)(value, attribute, locale) }, column.name));
|
|
82
84
|
}) }))] }));
|
|
83
85
|
}
|
|
84
|
-
function SecondaryColumnContent({ record: _record, column, schema, }) {
|
|
86
|
+
function SecondaryColumnContent({ record: _record, column, schema, locale, }) {
|
|
85
87
|
const value = _record[column.name];
|
|
86
88
|
if (!value) {
|
|
87
89
|
return null;
|
|
@@ -110,7 +112,7 @@ function SecondaryColumnContent({ record: _record, column, schema, }) {
|
|
|
110
112
|
}, children: choices.map((choice) => ((0, jsx_runtime_1.jsx)(ChoiceTag, { attribute: attribute, value: choice.value }, choice.value))) }, column.name));
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
|
-
return ((0, jsx_runtime_1.jsxs)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4 }, children: [!!label && `${label}: `, (0, utils_1.getAttributeFormattedValue)(attribute, value)] }, column.name));
|
|
115
|
+
return ((0, jsx_runtime_1.jsxs)(react_components_1.Caption1, { style: { color: react_components_1.tokens.colorNeutralForeground4 }, children: [!!label && `${label}: `, (0, utils_1.getAttributeFormattedValue)(attribute, value, locale)] }, column.name));
|
|
114
116
|
}
|
|
115
117
|
const ChoiceTag = ({ attribute, value, }) => {
|
|
116
118
|
return (0, jsx_runtime_1.jsx)(ChoiceBadge_1.ChoiceBadge, { attribute: attribute, value: value, size: "small" });
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DateControl = DateControl;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_calendar_compat_1 = require("@fluentui/react-calendar-compat");
|
|
8
9
|
const react_components_1 = require("@fluentui/react-components");
|
|
9
10
|
const react_datepicker_compat_1 = require("@fluentui/react-datepicker-compat");
|
|
10
11
|
const locale_1 = require("@headless-adminapp/app/locale");
|
|
@@ -16,13 +17,13 @@ const AppStringContext_1 = require("../../App/AppStringContext");
|
|
|
16
17
|
dayjs_1.default.extend(utc_1.default);
|
|
17
18
|
dayjs_1.default.extend(timezone_1.default);
|
|
18
19
|
function DateControl({ value, onChange, id, name, onBlur, onFocus, placeholder, disabled, readOnly, }) {
|
|
19
|
-
const { dateFormats
|
|
20
|
+
const { dateFormats } = (0, locale_1.useLocale)();
|
|
20
21
|
const { datePickerStrings } = (0, AppStringContext_1.useAppStrings)();
|
|
21
|
-
return ((0, jsx_runtime_1.jsx)(react_datepicker_compat_1.DatePicker, { id: id, name: name, onFocus: () => onFocus?.(), onBlur: () => onBlur?.(), placeholder: placeholder, appearance: "filled-darker", disabled: disabled, readOnly: readOnly, formatDate: (date) => date ? (0, dayjs_1.default)(date).
|
|
22
|
-
onChange?.(date
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(react_datepicker_compat_1.DatePicker, { id: id, name: name, onFocus: () => onFocus?.(), onBlur: () => onBlur?.(), placeholder: placeholder, appearance: "filled-darker", firstDayOfWeek: react_calendar_compat_1.DayOfWeek.Monday, showMonthPickerAsOverlay: true, disabled: disabled, readOnly: readOnly, formatDate: (date) => (date ? (0, dayjs_1.default)(date).format(dateFormats.short) : ''), value: value ? new Date(value) : null, onSelectDate: (date) => {
|
|
23
|
+
onChange?.(date ? (0, dayjs_1.default)(date).format('YYYY-MM-DD') : null);
|
|
24
|
+
}, strings: datePickerStrings, style: {
|
|
25
|
+
width: '100%',
|
|
26
|
+
}, contentAfter: (0, jsx_runtime_1.jsx)("div", { style: {
|
|
26
27
|
display: 'flex',
|
|
27
28
|
alignItems: 'center',
|
|
28
29
|
justifyContent: 'center',
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
interface CalendarItemProps {
|
|
4
|
+
date1: dayjs.Dayjs | null;
|
|
5
|
+
date2: dayjs.Dayjs | null;
|
|
6
|
+
navigatedDate: dayjs.Dayjs;
|
|
7
|
+
maxDate?: Date;
|
|
8
|
+
minDate?: Date;
|
|
9
|
+
onNavigateDate?: (date: Date) => void;
|
|
10
|
+
onSelectDate?: (date: Date) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const CalendarItem: FC<CalendarItemProps>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CalendarItem = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_calendar_compat_1 = require("@fluentui/react-calendar-compat");
|
|
9
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
10
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
11
|
+
const react_1 = require("react");
|
|
12
|
+
const AppStringContext_1 = require("../../../App/AppStringContext");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
const useStyles = (0, react_components_1.makeStyles)({
|
|
15
|
+
selected: {
|
|
16
|
+
color: `${react_components_1.tokens.colorNeutralForeground1Static} !important`,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const CalendarItem = ({ date1, date2, navigatedDate, maxDate, minDate, onNavigateDate, onSelectDate, }) => {
|
|
20
|
+
const { datePickerStrings } = (0, AppStringContext_1.useAppStrings)();
|
|
21
|
+
const date1Ref = (0, react_1.useRef)(date1);
|
|
22
|
+
const date2Ref = (0, react_1.useRef)(date2);
|
|
23
|
+
const navigatedDateRef = (0, react_1.useRef)(navigatedDate);
|
|
24
|
+
date1Ref.current = date1;
|
|
25
|
+
date2Ref.current = date2;
|
|
26
|
+
navigatedDateRef.current = navigatedDate;
|
|
27
|
+
const styles = useStyles();
|
|
28
|
+
const customDayCellRef = (0, react_1.useCallback)((element, date, classNames) => {
|
|
29
|
+
if (!element) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!classNames.daySelected) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
(0, utils_1.applyRoundedStyles)({
|
|
36
|
+
element,
|
|
37
|
+
navigatedDate: navigatedDateRef.current,
|
|
38
|
+
date: (0, dayjs_1.default)(date),
|
|
39
|
+
selectedDate1: date1Ref.current,
|
|
40
|
+
selectedDate2: date2Ref.current,
|
|
41
|
+
daySelectedClassNames: classNames.daySelected + ' ' + styles.selected,
|
|
42
|
+
});
|
|
43
|
+
}, [styles.selected]);
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(react_calendar_compat_1.Calendar, { showMonthPickerAsOverlay: true, showGoToToday: false, highlightSelectedMonth: false, highlightCurrentMonth: false, firstDayOfWeek: react_calendar_compat_1.DayOfWeek.Monday, strings: datePickerStrings, calendarDayProps: {
|
|
45
|
+
customDayCellRef: customDayCellRef,
|
|
46
|
+
onNavigateDate: onNavigateDate,
|
|
47
|
+
navigatedDate: navigatedDate.toDate(),
|
|
48
|
+
}, calendarMonthProps: {
|
|
49
|
+
navigatedDate: navigatedDate.toDate(),
|
|
50
|
+
onNavigateDate: onNavigateDate,
|
|
51
|
+
}, maxDate: maxDate, minDate: minDate, onSelectDate: onSelectDate }));
|
|
52
|
+
};
|
|
53
|
+
exports.CalendarItem = CalendarItem;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ControlProps } from '../types';
|
|
2
|
+
export interface DateRangeControlProps extends ControlProps<[string, string]> {
|
|
3
|
+
maxDate?: Date;
|
|
4
|
+
minDate?: Date;
|
|
5
|
+
}
|
|
6
|
+
export declare function DateRangeControl({ value, onChange, onBlur, onFocus, disabled, maxDate, minDate, readOnly, }: Readonly<DateRangeControlProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateRangeControl = DateRangeControl;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
6
|
+
const locale_1 = require("@headless-adminapp/app/locale");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const PopoverContent_1 = require("./PopoverContent");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const useStyles = (0, react_components_1.makeStyles)({
|
|
11
|
+
input: {
|
|
12
|
+
'& > input': {
|
|
13
|
+
cursor: 'pointer',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
function DateRangeControl({ value, onChange, onBlur, onFocus, disabled, maxDate, minDate, readOnly, }) {
|
|
18
|
+
const [open, setOpen] = (0, react_1.useState)(false);
|
|
19
|
+
const styles = useStyles();
|
|
20
|
+
const { dateRangeFormats } = (0, locale_1.useLocale)();
|
|
21
|
+
const formattedValue = (0, react_1.useMemo)(() => {
|
|
22
|
+
return (0, utils_1.formatDateRange)(value, dateRangeFormats.short);
|
|
23
|
+
}, [value, dateRangeFormats]);
|
|
24
|
+
return ((0, jsx_runtime_1.jsxs)(react_components_1.Popover, { open: open, onOpenChange: (_, data) => {
|
|
25
|
+
if (readOnly || disabled) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
onFocus?.();
|
|
29
|
+
setOpen(data.open);
|
|
30
|
+
}, positioning: "below-start", children: [(0, jsx_runtime_1.jsx)(react_components_1.PopoverTrigger, { disableButtonEnhancement: true, children: (0, jsx_runtime_1.jsx)(react_components_1.Input, { appearance: "filled-darker", readOnly: true, className: styles.input, value: formattedValue, onChange: () => { }, style: {
|
|
31
|
+
width: '100%',
|
|
32
|
+
} }) }), (0, jsx_runtime_1.jsx)(react_components_1.PopoverSurface, { style: { padding: 0 }, children: (0, jsx_runtime_1.jsx)(PopoverContent_1.PopoverContent, { value: value, minDate: minDate, maxDate: maxDate, onChange: (value) => {
|
|
33
|
+
setOpen(false);
|
|
34
|
+
onChange?.(value);
|
|
35
|
+
onBlur?.();
|
|
36
|
+
} }) })] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
interface PopoverContentProps {
|
|
3
|
+
value: [string, string] | null;
|
|
4
|
+
minDate?: Date;
|
|
5
|
+
maxDate?: Date;
|
|
6
|
+
onChange?: (value: [string, string] | null) => void;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
showApplyButton?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const PopoverContent: FC<PopoverContentProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PopoverContent = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
9
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const CalendarItem_1 = require("./CalendarItem");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const PopoverContent = ({ value, minDate, maxDate, onChange, required, showApplyButton, }) => {
|
|
14
|
+
const [internalValue, setInternalValue] = (0, react_1.useState)([value ? (0, dayjs_1.default)(value[0]) : null, value ? (0, dayjs_1.default)(value[1]) : null]);
|
|
15
|
+
const [navigationDate1, setNavigationDate1] = (0, react_1.useState)(value ? (0, dayjs_1.default)(value[0]) : (0, dayjs_1.default)());
|
|
16
|
+
const [navigationDate2, setNavigationDate2] = (0, react_1.useState)(value
|
|
17
|
+
? (0, utils_1.selectMaxDate)((0, dayjs_1.default)(internalValue[0]).add(1, 'month'), internalValue[1])
|
|
18
|
+
: (0, dayjs_1.default)().add(1, 'month'));
|
|
19
|
+
const [date1, date2] = internalValue;
|
|
20
|
+
const leftMaxDate = !date1 && date2
|
|
21
|
+
? (0, dayjs_1.default)(date2).subtract(1, 'month').endOf('month').toDate()
|
|
22
|
+
: undefined;
|
|
23
|
+
const rightMinDate = !date2 && date1
|
|
24
|
+
? (0, dayjs_1.default)(date1).add(1, 'month').startOf('month').toDate()
|
|
25
|
+
: undefined;
|
|
26
|
+
const handleCalendarChange = (date, isLeftCalendar) => {
|
|
27
|
+
if ((date1 && date2) || (!date1 && !date2)) {
|
|
28
|
+
if (isLeftCalendar) {
|
|
29
|
+
setInternalValue([(0, dayjs_1.default)(date), null]);
|
|
30
|
+
setNavigationDate2((0, dayjs_1.default)(date).add(1, 'month'));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
setInternalValue([null, (0, dayjs_1.default)(date)]);
|
|
34
|
+
setNavigationDate1((0, dayjs_1.default)(date).subtract(1, 'month'));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const v = [date1, date2].filter(Boolean);
|
|
39
|
+
v.push((0, dayjs_1.default)(date));
|
|
40
|
+
v.sort((a, b) => a.valueOf() - b.valueOf());
|
|
41
|
+
setInternalValue(v.map((d) => d));
|
|
42
|
+
if (!showApplyButton) {
|
|
43
|
+
onChange?.([v[0].format('YYYY-MM-DD'), v[1].format('YYYY-MM-DD')]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const actions = [];
|
|
48
|
+
if (!required) {
|
|
49
|
+
actions.push((0, jsx_runtime_1.jsx)(react_components_1.Button, { size: "small", appearance: "secondary", onClick: () => {
|
|
50
|
+
onChange?.(null);
|
|
51
|
+
setInternalValue([null, null]);
|
|
52
|
+
}, children: "Clear" }, "clear"));
|
|
53
|
+
}
|
|
54
|
+
if (showApplyButton) {
|
|
55
|
+
actions.push((0, jsx_runtime_1.jsx)(react_components_1.Button, { size: "small", appearance: "primary", disabled: !internalValue[0] || !internalValue[1], onClick: () => {
|
|
56
|
+
if (!internalValue[0] || !internalValue[1]) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
onChange?.([
|
|
60
|
+
(0, dayjs_1.default)(internalValue[0]).format('YYYY-MM-DD'),
|
|
61
|
+
(0, dayjs_1.default)(internalValue[1]).format('YYYY-MM-DD'),
|
|
62
|
+
]);
|
|
63
|
+
}, children: "Apply" }, "apply"));
|
|
64
|
+
}
|
|
65
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: { display: 'flex' }, children: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex' }, children: [(0, jsx_runtime_1.jsx)(CalendarItem_1.CalendarItem, { date1: date1, date2: date2, navigatedDate: navigationDate1, maxDate: leftMaxDate ?? maxDate, minDate: minDate, onSelectDate: (date) => {
|
|
66
|
+
handleCalendarChange(date, true);
|
|
67
|
+
}, onNavigateDate: (date) => {
|
|
68
|
+
setNavigationDate1((0, dayjs_1.default)(date));
|
|
69
|
+
} }), (0, jsx_runtime_1.jsx)(react_components_1.Divider, { vertical: true, style: { opacity: 0.2 } }), (0, jsx_runtime_1.jsx)(CalendarItem_1.CalendarItem, { date1: date1, date2: date2, navigatedDate: navigationDate2, minDate: rightMinDate ?? minDate, maxDate: maxDate, onSelectDate: (date) => {
|
|
70
|
+
handleCalendarChange(date, false);
|
|
71
|
+
}, onNavigateDate: (date) => {
|
|
72
|
+
setNavigationDate2((0, dayjs_1.default)(date));
|
|
73
|
+
} })] }), (0, jsx_runtime_1.jsx)(react_components_1.Divider, { style: { opacity: 0.5 } }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
74
|
+
display: 'flex',
|
|
75
|
+
gap: react_components_1.tokens.spacingHorizontalS,
|
|
76
|
+
padding: react_components_1.tokens.spacingVerticalS,
|
|
77
|
+
justifyContent: 'flex-end',
|
|
78
|
+
}, children: actions })] }) }));
|
|
79
|
+
};
|
|
80
|
+
exports.PopoverContent = PopoverContent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DateRangeControl, type DateRangeControlProps, } from './DateRangeControl';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateRangeControl = void 0;
|
|
4
|
+
var DateRangeControl_1 = require("./DateRangeControl");
|
|
5
|
+
Object.defineProperty(exports, "DateRangeControl", { enumerable: true, get: function () { return DateRangeControl_1.DateRangeControl; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DateRangeFormat } from '@headless-adminapp/core/experience/locale/types';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
export declare function formatDateRange(value: [string, string] | null, dateRangeFormat: DateRangeFormat): string;
|
|
4
|
+
export declare function applyRoundedStyles({ element, date, navigatedDate, selectedDate1, selectedDate2, daySelectedClassNames, }: {
|
|
5
|
+
element: HTMLElement;
|
|
6
|
+
date: dayjs.Dayjs;
|
|
7
|
+
navigatedDate: dayjs.Dayjs;
|
|
8
|
+
selectedDate1: dayjs.Dayjs | null;
|
|
9
|
+
selectedDate2: dayjs.Dayjs | null;
|
|
10
|
+
daySelectedClassNames: string;
|
|
11
|
+
}): void;
|
|
12
|
+
export declare function selectMaxDate(date1: dayjs.Dayjs, date2: dayjs.Dayjs | null): dayjs.Dayjs;
|
|
13
|
+
export declare function selectMinDate(date1: dayjs.Dayjs, date2: dayjs.Dayjs | null): dayjs.Dayjs;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatDateRange = formatDateRange;
|
|
7
|
+
exports.applyRoundedStyles = applyRoundedStyles;
|
|
8
|
+
exports.selectMaxDate = selectMaxDate;
|
|
9
|
+
exports.selectMinDate = selectMinDate;
|
|
10
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
11
|
+
function formatDateRange(value, dateRangeFormat) {
|
|
12
|
+
if (!value || value.length !== 2) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
const [start, end] = value.map((date) => (0, dayjs_1.default)(date));
|
|
16
|
+
if (start.isSame(end, 'year')) {
|
|
17
|
+
if (start.isSame(end, 'month')) {
|
|
18
|
+
if (start.isSame(end, 'day')) {
|
|
19
|
+
return start.format(dateRangeFormat.date);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return (start.format(dateRangeFormat.sameMonth[0]) +
|
|
23
|
+
dateRangeFormat.separator +
|
|
24
|
+
end.format(dateRangeFormat.sameMonth[1]));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return (start.format(dateRangeFormat.sameYear[0]) +
|
|
29
|
+
dateRangeFormat.separator +
|
|
30
|
+
end.format(dateRangeFormat.sameYear[1]));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return (start.format(dateRangeFormat.date) +
|
|
35
|
+
dateRangeFormat.separator +
|
|
36
|
+
end.format(dateRangeFormat.date));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const cornersClassNames = {
|
|
40
|
+
topRightCornerDate: 'fui-CalendarDayGrid__topRightCornerDate',
|
|
41
|
+
topLeftCornerDate: 'fui-CalendarDayGrid__topLeftCornerDate',
|
|
42
|
+
bottomRightCornerDate: 'fui-CalendarDayGrid__bottomRightCornerDate',
|
|
43
|
+
bottomLeftCornerDate: 'fui-CalendarDayGrid__bottomLeftCornerDate',
|
|
44
|
+
};
|
|
45
|
+
function checkIsSameMonth(date1, date2) {
|
|
46
|
+
return date1.isSame(date2, 'month');
|
|
47
|
+
}
|
|
48
|
+
function applyRoundedStyles({ element, date, navigatedDate, selectedDate1, selectedDate2, daySelectedClassNames, }) {
|
|
49
|
+
const _date = date;
|
|
50
|
+
const _navigatedDate = navigatedDate;
|
|
51
|
+
const _selectedDate1 = selectedDate1;
|
|
52
|
+
const _selectedDate2 = selectedDate2;
|
|
53
|
+
const isSameMonth = checkIsSameMonth(_navigatedDate, _date);
|
|
54
|
+
const isSelected = isSameMonth &&
|
|
55
|
+
selectedDate1 &&
|
|
56
|
+
selectedDate2 &&
|
|
57
|
+
date >= selectedDate1 &&
|
|
58
|
+
date <= selectedDate2;
|
|
59
|
+
if (!isSelected) {
|
|
60
|
+
element.classList.remove(...daySelectedClassNames.split(' '));
|
|
61
|
+
element.classList.add(cornersClassNames.topLeftCornerDate);
|
|
62
|
+
element.classList.add(cornersClassNames.topRightCornerDate);
|
|
63
|
+
element.classList.add(cornersClassNames.bottomLeftCornerDate);
|
|
64
|
+
element.classList.add(cornersClassNames.bottomRightCornerDate);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const aboveDate = _date.subtract(7, 'day');
|
|
68
|
+
const belowDate = _date.add(7, 'day');
|
|
69
|
+
const leftDate = _date.subtract(1, 'day');
|
|
70
|
+
const rightDate = _date.add(1, 'day');
|
|
71
|
+
const isFirstDay = _date.day() === 1; // Monday
|
|
72
|
+
const isLastDay = _date.day() === 0; // Sunday
|
|
73
|
+
const isAboveDateInRange = !aboveDate.isBefore(_selectedDate1);
|
|
74
|
+
const isBelowDateInRange = !belowDate.isAfter(_selectedDate2);
|
|
75
|
+
const isLeftDateInRange = !leftDate.isBefore(_selectedDate1);
|
|
76
|
+
const isRightDateInRange = !rightDate.isAfter(_selectedDate2);
|
|
77
|
+
const isAboveDateInSameMonth = checkIsSameMonth(aboveDate, _navigatedDate);
|
|
78
|
+
const isBelowDateInSameMonth = checkIsSameMonth(belowDate, _navigatedDate);
|
|
79
|
+
const isLeftDateInSameMonth = checkIsSameMonth(leftDate, _navigatedDate);
|
|
80
|
+
const isRightDateInSameMonth = checkIsSameMonth(rightDate, _navigatedDate);
|
|
81
|
+
const nothingOnLeft = !isLeftDateInRange || isFirstDay || !isLeftDateInSameMonth;
|
|
82
|
+
const nothingOnRight = !isRightDateInRange || isLastDay || !isRightDateInSameMonth;
|
|
83
|
+
const nothingAbove = !isAboveDateInRange || !isAboveDateInSameMonth;
|
|
84
|
+
const nothingBelow = !isBelowDateInRange || !isBelowDateInSameMonth;
|
|
85
|
+
const hasTopLeftRadius = nothingOnLeft && nothingAbove;
|
|
86
|
+
const hasTopRightRadius = nothingOnRight && nothingAbove;
|
|
87
|
+
const hasBottomLeftRadius = nothingOnLeft && nothingBelow;
|
|
88
|
+
const hasBottomRightRadius = nothingOnRight && nothingBelow;
|
|
89
|
+
const classToAdd = daySelectedClassNames.split(' ');
|
|
90
|
+
const classToRemove = [];
|
|
91
|
+
if (hasTopLeftRadius) {
|
|
92
|
+
classToAdd.push(cornersClassNames.topLeftCornerDate);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
classToRemove.push(cornersClassNames.topLeftCornerDate);
|
|
96
|
+
}
|
|
97
|
+
if (hasTopRightRadius) {
|
|
98
|
+
classToAdd.push(cornersClassNames.topRightCornerDate);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
classToRemove.push(cornersClassNames.topRightCornerDate);
|
|
102
|
+
}
|
|
103
|
+
if (hasBottomLeftRadius) {
|
|
104
|
+
classToAdd.push(cornersClassNames.bottomLeftCornerDate);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
classToRemove.push(cornersClassNames.bottomLeftCornerDate);
|
|
108
|
+
}
|
|
109
|
+
if (hasBottomRightRadius) {
|
|
110
|
+
classToAdd.push(cornersClassNames.bottomRightCornerDate);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
classToRemove.push(cornersClassNames.bottomRightCornerDate);
|
|
114
|
+
}
|
|
115
|
+
element.classList.add(...classToAdd);
|
|
116
|
+
element.classList.remove(...classToRemove);
|
|
117
|
+
}
|
|
118
|
+
function selectMaxDate(date1, date2) {
|
|
119
|
+
if (!date2) {
|
|
120
|
+
return date1;
|
|
121
|
+
}
|
|
122
|
+
return date1.isAfter(date2) ? date1 : date2;
|
|
123
|
+
}
|
|
124
|
+
function selectMinDate(date1, date2) {
|
|
125
|
+
if (!date2) {
|
|
126
|
+
return date1;
|
|
127
|
+
}
|
|
128
|
+
return date1.isBefore(date2) ? date1 : date2;
|
|
129
|
+
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { ControlProps } from './types';
|
|
2
|
-
export interface DateRangeControlProps extends ControlProps<[string
|
|
2
|
+
export interface DateRangeControlProps extends ControlProps<[string, string]> {
|
|
3
3
|
maxDate?: Date;
|
|
4
4
|
minDate?: Date;
|
|
5
5
|
}
|
|
6
6
|
export declare function DateRangeControl({ value, onChange, id, name, onBlur, onFocus, disabled, maxDate, minDate, readOnly, }: DateRangeControlProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare const cornersClassNames: {
|
|
8
|
+
topRightCornerDate: string;
|
|
9
|
+
topLeftCornerDate: string;
|
|
10
|
+
bottomRightCornerDate: string;
|
|
11
|
+
bottomLeftCornerDate: string;
|
|
12
|
+
};
|
|
@@ -3,45 +3,291 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cornersClassNames = void 0;
|
|
6
7
|
exports.DateRangeControl = DateRangeControl;
|
|
7
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const
|
|
9
|
+
const react_calendar_compat_1 = require("@fluentui/react-calendar-compat");
|
|
10
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
9
11
|
const locale_1 = require("@headless-adminapp/app/locale");
|
|
10
12
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
11
13
|
const react_1 = require("react");
|
|
12
14
|
const AppStringContext_1 = require("../../App/AppStringContext");
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
(
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
function formatDateRange(value, dateRangeFormat) {
|
|
16
|
+
if (!value || value.length !== 2) {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
const [start, end] = value.map((date) => (0, dayjs_1.default)(date)); //.tz(timezone));
|
|
20
|
+
if (start.isSame(end, 'year')) {
|
|
21
|
+
if (start.isSame(end, 'month')) {
|
|
22
|
+
if (start.isSame(end, 'day')) {
|
|
23
|
+
return start.format(dateRangeFormat.date);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return (start.format(dateRangeFormat.sameMonth[0]) +
|
|
27
|
+
dateRangeFormat.separator +
|
|
28
|
+
end.format(dateRangeFormat.sameMonth[1]));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return (start.format(dateRangeFormat.sameYear[0]) +
|
|
33
|
+
dateRangeFormat.separator +
|
|
34
|
+
end.format(dateRangeFormat.sameYear[1]));
|
|
22
35
|
}
|
|
23
|
-
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return (start.format(dateRangeFormat.date) +
|
|
39
|
+
dateRangeFormat.separator +
|
|
40
|
+
end.format(dateRangeFormat.date));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function DateRangeControl({ value, onChange, id, name, onBlur, onFocus, disabled, maxDate, minDate, readOnly, }) {
|
|
44
|
+
const [open, setOpen] = (0, react_1.useState)(false);
|
|
45
|
+
const { dateRangeFormats } = (0, locale_1.useLocale)();
|
|
46
|
+
const formattedValue = (0, react_1.useMemo)(() => {
|
|
47
|
+
return formatDateRange(value, dateRangeFormats.short);
|
|
48
|
+
}, [value, dateRangeFormats]);
|
|
49
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: { display: 'flex', flexDirection: 'column' }, children: (0, jsx_runtime_1.jsxs)(react_components_1.Popover, { open: open, onOpenChange: (_, data) => {
|
|
50
|
+
if (readOnly || disabled) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
onFocus?.();
|
|
54
|
+
setOpen(data.open);
|
|
55
|
+
}, positioning: "below-start", children: [(0, jsx_runtime_1.jsx)(react_components_1.PopoverTrigger, { disableButtonEnhancement: true, children: (0, jsx_runtime_1.jsx)(react_components_1.Input, { appearance: "filled-darker", readOnly: true, style: { cursor: 'pointer' }, value: formattedValue, onChange: () => { } }) }), (0, jsx_runtime_1.jsx)(react_components_1.PopoverSurface, { style: { padding: 0 }, children: (0, jsx_runtime_1.jsx)(PopoverContent, { value: value, minDate: minDate, maxDate: maxDate, onChange: (value) => {
|
|
56
|
+
setOpen(false);
|
|
57
|
+
onChange?.(value);
|
|
58
|
+
onBlur?.();
|
|
59
|
+
} }) })] }) }));
|
|
60
|
+
}
|
|
61
|
+
const PopoverContent = ({ value, minDate, maxDate, onChange, required, }) => {
|
|
62
|
+
const [internalValue, setInternalValue] = (0, react_1.useState)([value ? new Date(value[0]) : null, value ? new Date(value[1]) : null]);
|
|
63
|
+
// const [date1, setDate1] = useState<string | null>(null);
|
|
64
|
+
// const [date2, setDate2] = useState<string | null>(null);
|
|
65
|
+
const [navigationDate1, setNavigationDate1] = (0, react_1.useState)(internalValue[0] ?? (0, dayjs_1.default)().toDate());
|
|
66
|
+
const [navigationDate2, setNavigationDate2] = (0, react_1.useState)(internalValue[1] ?? (0, dayjs_1.default)().add(1, 'month').toDate());
|
|
67
|
+
const [date1, date2] = internalValue;
|
|
68
|
+
// useEffect(() => {
|
|
69
|
+
// if (value) {
|
|
70
|
+
// let d1 = new Date(value[0]);
|
|
71
|
+
// let d2 = new Date(value[1]);
|
|
72
|
+
// if (d1 > d2) {
|
|
73
|
+
// const temp = d1;
|
|
74
|
+
// d1 = d2;
|
|
75
|
+
// d2 = temp;
|
|
76
|
+
// }
|
|
77
|
+
// setDate1(d1.toISOString());
|
|
78
|
+
// setDate2(d2.toISOString());
|
|
79
|
+
// }
|
|
80
|
+
// }, [value]);
|
|
81
|
+
const leftMaxDate = !date1 && date2
|
|
82
|
+
? (0, dayjs_1.default)(date2).subtract(1, 'month').endOf('month').toDate()
|
|
83
|
+
: undefined;
|
|
84
|
+
const rightMinDate = !date2 && date1
|
|
85
|
+
? (0, dayjs_1.default)(date1).add(1, 'month').startOf('month').toDate()
|
|
86
|
+
: undefined;
|
|
24
87
|
const _minDate = minDate
|
|
25
88
|
? new Date(minDate)
|
|
26
|
-
:
|
|
27
|
-
? new Date(
|
|
89
|
+
: date1
|
|
90
|
+
? new Date(date1)
|
|
91
|
+
: undefined;
|
|
92
|
+
const _maxDate = maxDate
|
|
93
|
+
? new Date(maxDate)
|
|
94
|
+
: date2
|
|
95
|
+
? new Date(date2)
|
|
28
96
|
: undefined;
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
97
|
+
// const date1Ref = useRef<string | null>(date1);
|
|
98
|
+
// const date2Ref = useRef<string | null>(date2);
|
|
99
|
+
// date1Ref.current = date1;
|
|
100
|
+
// date2Ref.current = date2;
|
|
101
|
+
const handleCalendarChange = (date, isLeftCalendar) => {
|
|
102
|
+
if ((date1 && date2) || (!date1 && !date2)) {
|
|
103
|
+
if (isLeftCalendar) {
|
|
104
|
+
setInternalValue([date, null]);
|
|
105
|
+
// setDate1(date.toISOString());
|
|
106
|
+
// setDate2(null);
|
|
107
|
+
setNavigationDate2((0, dayjs_1.default)(date).add(1, 'month').toDate());
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
setInternalValue([null, date]);
|
|
111
|
+
// setDate2(date.toISOString());
|
|
112
|
+
// setDate1(null);
|
|
113
|
+
setNavigationDate1((0, dayjs_1.default)(date).subtract(1, 'month').toDate());
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
let d1 = date1;
|
|
118
|
+
let d2 = date2;
|
|
119
|
+
const v = [date1, date2].filter(Boolean);
|
|
120
|
+
v.push(date);
|
|
121
|
+
v.sort((a, b) => a.getTime() - b.getTime());
|
|
122
|
+
// setDate1(v[0]);
|
|
123
|
+
// setDate2(v[1]);
|
|
124
|
+
console.log('v', v);
|
|
125
|
+
setInternalValue(v.map((d) => new Date(d)));
|
|
126
|
+
}
|
|
127
|
+
// const newValues = [...__values] as [string | null, string | null];
|
|
128
|
+
// if (newValues[0] && newValues[1]) {
|
|
129
|
+
// newValues[0] = null;
|
|
130
|
+
// newValues[1] = null;
|
|
34
131
|
// }
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
132
|
+
// if (!newValues[0]) {
|
|
133
|
+
// newValues[0] = date.toISOString();
|
|
134
|
+
// } else {
|
|
135
|
+
// newValues[1] = date.toISOString();
|
|
136
|
+
// }
|
|
137
|
+
// // Swap values if the first date is after the second date
|
|
138
|
+
// if (
|
|
139
|
+
// newValues[0] &&
|
|
140
|
+
// newValues[1] &&
|
|
141
|
+
// new Date(newValues[0]) > new Date(newValues[1])
|
|
142
|
+
// ) {
|
|
143
|
+
// const temp = newValues[0];
|
|
144
|
+
// newValues[0] = newValues[1];
|
|
145
|
+
// newValues[1] = temp;
|
|
40
146
|
// }
|
|
147
|
+
// __setValues(newValues);
|
|
41
148
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
149
|
+
// date1, date2
|
|
150
|
+
// [from, to]
|
|
151
|
+
// navigate date1
|
|
152
|
+
// navigate date2
|
|
153
|
+
// First selection in left calendar is start date
|
|
154
|
+
// First selection in right calendar is end date
|
|
155
|
+
// Second selection is conditional
|
|
156
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex' }, children: [JSON.stringify(internalValue), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex' }, children: [(0, jsx_runtime_1.jsx)(CalendarItem, { date1: date1, date2: date2, navigatedDate: navigationDate1, maxDate: leftMaxDate ?? maxDate, minDate: minDate, onSelectDate: (date) => {
|
|
157
|
+
handleCalendarChange(date, true);
|
|
158
|
+
}, onNavigateDate: (date) => {
|
|
159
|
+
setNavigationDate1(date);
|
|
160
|
+
} }), (0, jsx_runtime_1.jsx)(react_components_1.Divider, { vertical: true, style: { opacity: 0.2 } }), (0, jsx_runtime_1.jsx)(CalendarItem, { date1: date1, date2: date2, navigatedDate: navigationDate2, minDate: rightMinDate ?? minDate, maxDate: maxDate, onSelectDate: (date) => {
|
|
161
|
+
handleCalendarChange(date, false);
|
|
162
|
+
}, onNavigateDate: (date) => {
|
|
163
|
+
setNavigationDate2(date);
|
|
164
|
+
} })] }), (0, jsx_runtime_1.jsx)(react_components_1.Divider, { style: { opacity: 0.5 } }), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
165
|
+
display: 'flex',
|
|
166
|
+
gap: react_components_1.tokens.spacingHorizontalS,
|
|
167
|
+
padding: react_components_1.tokens.spacingVerticalS,
|
|
168
|
+
justifyContent: 'flex-end',
|
|
169
|
+
}, children: [!required && ((0, jsx_runtime_1.jsx)(react_components_1.Button, { size: "small", appearance: "secondary", onClick: () => {
|
|
170
|
+
onChange?.(null);
|
|
171
|
+
setInternalValue([null, null]);
|
|
172
|
+
}, children: "Clear" })), (0, jsx_runtime_1.jsx)(react_components_1.Button, { size: "small", appearance: "primary", disabled: !internalValue[0] || !internalValue[1], onClick: () => {
|
|
173
|
+
if (!internalValue[0] || !internalValue[1]) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
onChange?.([
|
|
177
|
+
(0, dayjs_1.default)(internalValue[0]).format('YYYY-MM-DD'),
|
|
178
|
+
(0, dayjs_1.default)(internalValue[1]).format('YYYY-MM-DD'),
|
|
179
|
+
]);
|
|
180
|
+
}, children: "Apply" })] })] })] }));
|
|
181
|
+
};
|
|
182
|
+
exports.cornersClassNames = {
|
|
183
|
+
topRightCornerDate: 'fui-CalendarDayGrid__topRightCornerDate',
|
|
184
|
+
topLeftCornerDate: 'fui-CalendarDayGrid__topLeftCornerDate',
|
|
185
|
+
bottomRightCornerDate: 'fui-CalendarDayGrid__bottomRightCornerDate',
|
|
186
|
+
bottomLeftCornerDate: 'fui-CalendarDayGrid__bottomLeftCornerDate',
|
|
187
|
+
};
|
|
188
|
+
function checkIsSameMonth(date1, date2) {
|
|
189
|
+
return date1.isSame(date2, 'month');
|
|
47
190
|
}
|
|
191
|
+
function applyRoundedStyles({ element, date, navigatedDate, selectedDate1, selectedDate2, classNames, }) {
|
|
192
|
+
if (!classNames.daySelected) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const _date = (0, dayjs_1.default)(date); //.tz(timezone);
|
|
196
|
+
const _navigatedDate = (0, dayjs_1.default)(navigatedDate); //.tz(timezone);
|
|
197
|
+
const _selectedDate1 = (0, dayjs_1.default)(selectedDate1); //.tz(timezone);
|
|
198
|
+
const _selectedDate2 = (0, dayjs_1.default)(selectedDate2); //.tz(timezone);
|
|
199
|
+
const isSameMonth = checkIsSameMonth(_navigatedDate, _date);
|
|
200
|
+
const isSelected = isSameMonth &&
|
|
201
|
+
selectedDate1 &&
|
|
202
|
+
selectedDate2 &&
|
|
203
|
+
date >= selectedDate1 &&
|
|
204
|
+
date <= selectedDate2;
|
|
205
|
+
if (!isSelected) {
|
|
206
|
+
element.classList.remove(...classNames.daySelected.split(' '));
|
|
207
|
+
element.classList.add(exports.cornersClassNames.topLeftCornerDate);
|
|
208
|
+
element.classList.add(exports.cornersClassNames.topRightCornerDate);
|
|
209
|
+
element.classList.add(exports.cornersClassNames.bottomLeftCornerDate);
|
|
210
|
+
element.classList.add(exports.cornersClassNames.bottomRightCornerDate);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const aboveDate = _date.subtract(7, 'day');
|
|
214
|
+
const belowDate = _date.add(7, 'day');
|
|
215
|
+
const leftDate = _date.subtract(1, 'day');
|
|
216
|
+
const rightDate = _date.add(1, 'day');
|
|
217
|
+
const isFirstDay = _date.day() === 1; // Monday
|
|
218
|
+
const isLastDay = _date.day() === 0; // Sunday
|
|
219
|
+
const isAboveDateInRange = !aboveDate.isBefore(_selectedDate1);
|
|
220
|
+
const isBelowDateInRange = !belowDate.isAfter(_selectedDate2);
|
|
221
|
+
const isLeftDateInRange = !leftDate.isBefore(_selectedDate1);
|
|
222
|
+
const isRightDateInRange = !rightDate.isAfter(_selectedDate2);
|
|
223
|
+
const isAboveDateInSameMonth = checkIsSameMonth(aboveDate, _navigatedDate);
|
|
224
|
+
const isBelowDateInSameMonth = checkIsSameMonth(belowDate, _navigatedDate);
|
|
225
|
+
const isLeftDateInSameMonth = checkIsSameMonth(leftDate, _navigatedDate);
|
|
226
|
+
const isRightDateInSameMonth = checkIsSameMonth(rightDate, _navigatedDate);
|
|
227
|
+
const nothingOnLeft = !isLeftDateInRange || isFirstDay || !isLeftDateInSameMonth;
|
|
228
|
+
const nothingOnRight = !isRightDateInRange || isLastDay || !isRightDateInSameMonth;
|
|
229
|
+
const nothingAbove = !isAboveDateInRange || !isAboveDateInSameMonth;
|
|
230
|
+
const nothingBelow = !isBelowDateInRange || !isBelowDateInSameMonth;
|
|
231
|
+
const hasTopLeftRadius = nothingOnLeft && nothingAbove;
|
|
232
|
+
const hasTopRightRadius = nothingOnRight && nothingAbove;
|
|
233
|
+
const hasBottomLeftRadius = nothingOnLeft && nothingBelow;
|
|
234
|
+
const hasBottomRightRadius = nothingOnRight && nothingBelow;
|
|
235
|
+
const classToAdd = classNames.daySelected.split(' ');
|
|
236
|
+
const classToRemove = [];
|
|
237
|
+
if (hasTopLeftRadius) {
|
|
238
|
+
classToAdd.push(exports.cornersClassNames.topLeftCornerDate);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
classToRemove.push(exports.cornersClassNames.topLeftCornerDate);
|
|
242
|
+
}
|
|
243
|
+
if (hasTopRightRadius) {
|
|
244
|
+
classToAdd.push(exports.cornersClassNames.topRightCornerDate);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
classToRemove.push(exports.cornersClassNames.topRightCornerDate);
|
|
248
|
+
}
|
|
249
|
+
if (hasBottomLeftRadius) {
|
|
250
|
+
classToAdd.push(exports.cornersClassNames.bottomLeftCornerDate);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
classToRemove.push(exports.cornersClassNames.bottomLeftCornerDate);
|
|
254
|
+
}
|
|
255
|
+
if (hasBottomRightRadius) {
|
|
256
|
+
classToAdd.push(exports.cornersClassNames.bottomRightCornerDate);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
classToRemove.push(exports.cornersClassNames.bottomRightCornerDate);
|
|
260
|
+
}
|
|
261
|
+
element.classList.add(...classToAdd);
|
|
262
|
+
element.classList.remove(...classToRemove);
|
|
263
|
+
}
|
|
264
|
+
const CalendarItem = ({ date1, date2, navigatedDate, maxDate, minDate, onNavigateDate, onSelectDate, }) => {
|
|
265
|
+
const { datePickerStrings } = (0, AppStringContext_1.useAppStrings)();
|
|
266
|
+
const date1Ref = (0, react_1.useRef)(date1);
|
|
267
|
+
const date2Ref = (0, react_1.useRef)(date2);
|
|
268
|
+
const navigatedDateRef = (0, react_1.useRef)(navigatedDate);
|
|
269
|
+
date1Ref.current = date1;
|
|
270
|
+
date2Ref.current = date2;
|
|
271
|
+
navigatedDateRef.current = navigatedDate;
|
|
272
|
+
const customDayCellRef = (0, react_1.useCallback)((element, date, classNames) => {
|
|
273
|
+
if (!element) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
applyRoundedStyles({
|
|
277
|
+
element,
|
|
278
|
+
navigatedDate: navigatedDateRef.current,
|
|
279
|
+
date,
|
|
280
|
+
selectedDate1: date1Ref.current,
|
|
281
|
+
selectedDate2: date2Ref.current,
|
|
282
|
+
classNames,
|
|
283
|
+
});
|
|
284
|
+
}, []);
|
|
285
|
+
return ((0, jsx_runtime_1.jsx)(react_calendar_compat_1.Calendar, { showMonthPickerAsOverlay: true, showGoToToday: false, highlightSelectedMonth: false, highlightCurrentMonth: false, firstDayOfWeek: react_calendar_compat_1.DayOfWeek.Monday, strings: datePickerStrings, calendarDayProps: {
|
|
286
|
+
customDayCellRef: customDayCellRef,
|
|
287
|
+
onNavigateDate: onNavigateDate,
|
|
288
|
+
navigatedDate: navigatedDate,
|
|
289
|
+
}, calendarMonthProps: {
|
|
290
|
+
navigatedDate: navigatedDate,
|
|
291
|
+
onNavigateDate: onNavigateDate,
|
|
292
|
+
}, maxDate: maxDate, minDate: minDate, onSelectDate: onSelectDate }));
|
|
293
|
+
};
|
|
@@ -15,6 +15,7 @@ const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFor
|
|
|
15
15
|
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
16
16
|
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
17
17
|
const react_1 = require("react");
|
|
18
|
+
const utils_1 = require("./TimeControl/utils");
|
|
18
19
|
dayjs_1.default.extend(customParseFormat_1.default);
|
|
19
20
|
dayjs_1.default.extend(utc_1.default);
|
|
20
21
|
dayjs_1.default.extend(timezone_1.default);
|
|
@@ -45,7 +46,7 @@ function DateTimeControl({ value, onChange, id, name, onBlur, onFocus, placehold
|
|
|
45
46
|
if (!isOpen) {
|
|
46
47
|
onBlur?.();
|
|
47
48
|
}
|
|
48
|
-
}, onFocus: () => onFocus?.(), onBlur: () => onBlur?.(), placeholder: placeholder, appearance: "filled-darker", formatDate: (date) => date ? (0, dayjs_1.default)(date).tz(timezone).format(dateFormat) : '', readOnly: isReadonly, value: value ? new Date(value) : null, onSelectDate: (date) => {
|
|
49
|
+
}, onFocus: () => onFocus?.(), onBlur: () => onBlur?.(), placeholder: placeholder, appearance: "filled-darker", showMonthPickerAsOverlay: true, formatDate: (date) => date ? (0, dayjs_1.default)(date).tz(timezone).format(dateFormat) : '', readOnly: isReadonly, value: value ? new Date(value) : null, onSelectDate: (date) => {
|
|
49
50
|
if (!date) {
|
|
50
51
|
onChange?.(null);
|
|
51
52
|
}
|
|
@@ -99,7 +100,7 @@ function DateTimeControl({ value, onChange, id, name, onBlur, onFocus, placehold
|
|
|
99
100
|
.toISOString());
|
|
100
101
|
}
|
|
101
102
|
else if (data.selectedTimeText) {
|
|
102
|
-
let resolvedTime = resolveTimeValue(data.selectedTimeText, timeFormat);
|
|
103
|
+
let resolvedTime = (0, utils_1.resolveTimeValue)(data.selectedTimeText, timeFormat);
|
|
103
104
|
if (!resolvedTime) {
|
|
104
105
|
setInternalTimeValue(value ? (0, dayjs_1.default)(value).format(timeFormat) : '');
|
|
105
106
|
return;
|
|
@@ -125,13 +126,3 @@ function DateTimeControl({ value, onChange, id, name, onBlur, onFocus, placehold
|
|
|
125
126
|
color: react_components_1.tokens.colorNeutralForeground2,
|
|
126
127
|
}, children: (0, jsx_runtime_1.jsx)(icons_1.Icons.Clock, { size: 20 }) }) })] }));
|
|
127
128
|
}
|
|
128
|
-
function resolveTimeValue(value, timeFormat) {
|
|
129
|
-
if (!value) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const time = (0, dayjs_1.default)(value, timeFormat);
|
|
133
|
-
if (!time.isValid()) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
return time.toDate();
|
|
137
|
-
}
|
|
@@ -18,5 +18,6 @@ function EmailControl({ value, onChange, id, name, onBlur, onFocus, placeholder,
|
|
|
18
18
|
readOnly: disabled || readOnly, autoComplete: autoComplete, style: {
|
|
19
19
|
flex: 1,
|
|
20
20
|
paddingRight: react_components_1.tokens.spacingHorizontalXS,
|
|
21
|
+
width: '100%',
|
|
21
22
|
}, contentAfter: !!value ? ((0, jsx_runtime_1.jsx)(react_components_1.Button, { onClick: () => window.open(`mailto:${value}`, '_blank'), color: "primary", appearance: "transparent", icon: (0, jsx_runtime_1.jsx)(icons_1.Icons.Mail, {}), size: "small" })) : undefined }));
|
|
22
23
|
}
|
|
@@ -5,7 +5,9 @@ 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
|
-
return ((0, jsx_runtime_1.jsx)(react_components_1.SpinButton, { appearance: "filled-darker", placeholder: placeholder, id: id, name: name, value: value ?? null, readOnly: readOnly || disabled,
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(react_components_1.SpinButton, { appearance: "filled-darker", placeholder: placeholder, id: id, name: name, value: value ?? null, readOnly: readOnly || disabled, style: {
|
|
9
|
+
width: '100%',
|
|
10
|
+
}, onChange: (e, data) => {
|
|
9
11
|
if (data.value !== undefined) {
|
|
10
12
|
onChange?.(data.value);
|
|
11
13
|
}
|
|
@@ -13,5 +13,7 @@ function MultiSelectControl({ value, onChange, options, id, name, disabled, onBl
|
|
|
13
13
|
const selectedOptions = (0, react_1.useMemo)(() => options.filter((x) => value?.includes(x.value)), [options, value]);
|
|
14
14
|
return ((0, jsx_runtime_1.jsx)(react_components_1.Dropdown, { placeholder: placeholder, id: id, name: name, appearance: "filled-darker", multiselect: true, value: selectedOptions.map((x) => x.label).join(', '), selectedOptions: value ? value.map(String) : [], onOptionSelect: (event, data) => {
|
|
15
15
|
handleChange(data.selectedOptions);
|
|
16
|
-
}, onBlur: () => onBlur?.(), onFocus: () => onFocus?.(), disabled: disabled,
|
|
16
|
+
}, onBlur: () => onBlur?.(), onFocus: () => onFocus?.(), disabled: disabled, style: {
|
|
17
|
+
width: '100%',
|
|
18
|
+
}, children: transformedOptions.map((x) => ((0, jsx_runtime_1.jsx)(react_components_1.Option, { value: x.value, children: x.label }, x.value))) }));
|
|
17
19
|
}
|
|
@@ -129,7 +129,7 @@ const LookupControlMd = ({ value, onChange, id, name, onBlur, onFocus, placehold
|
|
|
129
129
|
left: inputLeft,
|
|
130
130
|
height: 30,
|
|
131
131
|
},
|
|
132
|
-
}, placeholder: placeholder, inputMode: "search", style: { width: '100%', height: '100%' }, autoComplete: "off", readOnly: readOnly || disabled, open: open && !readOnly && !disabled, value: searchText, onOpenChange: (e, data) => {
|
|
132
|
+
}, placeholder: placeholder, inputMode: "search", style: { width: '100%', height: '100%', minWidth: 'unset' }, autoComplete: "off", readOnly: readOnly || disabled, open: open && !readOnly && !disabled, value: searchText, onOpenChange: (e, data) => {
|
|
133
133
|
setOpen(data.open);
|
|
134
134
|
}, onChange: (e) => {
|
|
135
135
|
setSearchText(e.target.value);
|
|
@@ -22,5 +22,5 @@ function SelectControl({ value, onChange, options, id, name, disabled, onBlur, o
|
|
|
22
22
|
// onChange={(e, v) => handleChange(v as string)}
|
|
23
23
|
selectedOptions: value ? [String(value)] : [], onOptionSelect: (event, data) => {
|
|
24
24
|
handleChange(data.optionValue);
|
|
25
|
-
}, onBlur: () => onBlur?.(), onFocus: () => onFocus?.(), style: { pointerEvents: disabled ? 'none' : undefined }, children: transformedOptions.map((x) => ((0, jsx_runtime_1.jsx)(react_components_1.Option, { value: x.value, children: x.label }, x.value))) }));
|
|
25
|
+
}, onBlur: () => onBlur?.(), onFocus: () => onFocus?.(), style: { pointerEvents: disabled ? 'none' : undefined, width: '100%' }, children: transformedOptions.map((x) => ((0, jsx_runtime_1.jsx)(react_components_1.Option, { value: x.value, children: x.label }, x.value))) }));
|
|
26
26
|
}
|
|
@@ -37,5 +37,7 @@ function TextAreaControl({ value, onChange, id, name, placeholder, onBlur, onFoc
|
|
|
37
37
|
};
|
|
38
38
|
return ((0, jsx_runtime_1.jsx)(react_components_1.Textarea, { ref: textAreaRef, placeholder: placeholder, id: id, appearance: "filled-darker", name: name, value: value ?? '', onChange: handleInput, onBlur: () => onBlur?.(), onFocus: () => onFocus?.(),
|
|
39
39
|
// error={error}
|
|
40
|
-
readOnly: disabled || readOnly, rows: rows
|
|
40
|
+
readOnly: disabled || readOnly, rows: rows, style: {
|
|
41
|
+
width: '100%',
|
|
42
|
+
} }));
|
|
41
43
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ControlProps } from '../types';
|
|
2
|
+
export interface TimeControlProps extends ControlProps<number> {
|
|
3
|
+
}
|
|
4
|
+
export declare function TimeControl({ value, onChange, id, name, onBlur, placeholder, disabled, readOnly, }: Readonly<TimeControlProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TimeControl = TimeControl;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_components_1 = require("@fluentui/react-components");
|
|
9
|
+
const react_timepicker_compat_1 = require("@fluentui/react-timepicker-compat");
|
|
10
|
+
const locale_1 = require("@headless-adminapp/app/locale");
|
|
11
|
+
const icons_1 = require("@headless-adminapp/icons");
|
|
12
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
13
|
+
const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat"));
|
|
14
|
+
const react_1 = require("react");
|
|
15
|
+
const utils_1 = require("./utils");
|
|
16
|
+
dayjs_1.default.extend(customParseFormat_1.default);
|
|
17
|
+
function TimeControl({ value, onChange, id, name, onBlur, placeholder, disabled, readOnly, }) {
|
|
18
|
+
const { timeFormats: { short: timeFormat }, timezone, } = (0, locale_1.useLocale)();
|
|
19
|
+
const [internalTimeValue, setInternalTimeValue] = (0, react_1.useState)(value ? (0, dayjs_1.default)().startOf('day').add(value, 'minutes').format(timeFormat) : '');
|
|
20
|
+
const internalTimeValueRef = (0, react_1.useRef)(internalTimeValue);
|
|
21
|
+
internalTimeValueRef.current = internalTimeValue;
|
|
22
|
+
(0, react_1.useEffect)(() => {
|
|
23
|
+
const updatedValue = typeof value === 'number'
|
|
24
|
+
? (0, dayjs_1.default)().startOf('day').add(value, 'minutes').format(timeFormat)
|
|
25
|
+
: '';
|
|
26
|
+
if (internalTimeValueRef.current !== updatedValue) {
|
|
27
|
+
setInternalTimeValue(updatedValue);
|
|
28
|
+
}
|
|
29
|
+
}, [value, timezone, timeFormat]);
|
|
30
|
+
const isReadonly = readOnly || disabled;
|
|
31
|
+
const selectedTime = (0, react_1.useMemo)(() => {
|
|
32
|
+
if (typeof value !== 'number') {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return (0, dayjs_1.default)().startOf('day').add(value, 'minutes').toDate();
|
|
36
|
+
}, [value]);
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
38
|
+
display: 'flex',
|
|
39
|
+
alignItems: 'center',
|
|
40
|
+
gap: react_components_1.tokens.spacingHorizontalS,
|
|
41
|
+
}, children: (0, jsx_runtime_1.jsx)(react_timepicker_compat_1.TimePicker, { appearance: "filled-darker", style: {
|
|
42
|
+
flex: 1,
|
|
43
|
+
minWidth: 0,
|
|
44
|
+
pointerEvents: isReadonly ? 'none' : 'auto',
|
|
45
|
+
}, placeholder: placeholder, id: id, name: name, input: {
|
|
46
|
+
style: { minWidth: 0 },
|
|
47
|
+
}, readOnly: isReadonly, selectedTime: selectedTime, freeform: true, value: internalTimeValue, onTimeChange: (_, data) => {
|
|
48
|
+
if (data.selectedTime) {
|
|
49
|
+
onChange?.((0, dayjs_1.default)(data.selectedTime).diff((0, dayjs_1.default)().startOf('day'), 'minutes'));
|
|
50
|
+
}
|
|
51
|
+
else if (data.selectedTimeText) {
|
|
52
|
+
let resolvedTime = (0, utils_1.resolveTimeValue)(data.selectedTimeText, timeFormat);
|
|
53
|
+
if (!resolvedTime) {
|
|
54
|
+
setInternalTimeValue(value ? (0, dayjs_1.default)(value).format(timeFormat) : '');
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const newValue = (0, dayjs_1.default)(resolvedTime).diff((0, dayjs_1.default)().startOf('day'), 'minutes');
|
|
58
|
+
if (newValue !== value) {
|
|
59
|
+
onChange?.(newValue);
|
|
60
|
+
}
|
|
61
|
+
setInternalTimeValue((0, dayjs_1.default)(resolvedTime).format(timeFormat));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
setInternalTimeValue('');
|
|
65
|
+
onChange?.(null);
|
|
66
|
+
}
|
|
67
|
+
}, onInput: (e) => {
|
|
68
|
+
setInternalTimeValue(e.currentTarget.value);
|
|
69
|
+
}, onBlur: () => {
|
|
70
|
+
onBlur?.();
|
|
71
|
+
}, expandIcon: (0, jsx_runtime_1.jsx)("div", { style: {
|
|
72
|
+
display: 'flex',
|
|
73
|
+
alignItems: 'center',
|
|
74
|
+
justifyContent: 'center',
|
|
75
|
+
marginRight: -4,
|
|
76
|
+
color: react_components_1.tokens.colorNeutralForeground2,
|
|
77
|
+
}, children: (0, jsx_runtime_1.jsx)(icons_1.Icons.Clock, { size: 20 }) }) }) }));
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TimeControl, TimeControlProps } from './TimeControl';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimeControl = void 0;
|
|
4
|
+
var TimeControl_1 = require("./TimeControl");
|
|
5
|
+
Object.defineProperty(exports, "TimeControl", { enumerable: true, get: function () { return TimeControl_1.TimeControl; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveTimeValue(value: string, timeFormat: string): Date | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveTimeValue = resolveTimeValue;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
const STANDARD_TIME_REGEX = /^(\d{1,2}):?(\d{2})?([ap]m)?$/i;
|
|
9
|
+
function resolveTimeValue(value, timeFormat) {
|
|
10
|
+
if (!value) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
// Check if the value matches the standard time format (H, HH, H:MM, HH:MM, H:MM AM/PM, HH:MM AM/PM)
|
|
14
|
+
const standardTimeMatch = STANDARD_TIME_REGEX.exec(value);
|
|
15
|
+
if (standardTimeMatch) {
|
|
16
|
+
const hour = Number(standardTimeMatch[1]);
|
|
17
|
+
const minute = standardTimeMatch[2] ? Number(standardTimeMatch[2]) : 0;
|
|
18
|
+
const isPM = standardTimeMatch[3]
|
|
19
|
+
? standardTimeMatch[3].toLowerCase().startsWith('p')
|
|
20
|
+
: false;
|
|
21
|
+
if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
let adjustedHour = hour;
|
|
25
|
+
if (isPM && hour < 12) {
|
|
26
|
+
adjustedHour += 12; // Convert PM hour to 24-hour format
|
|
27
|
+
}
|
|
28
|
+
if (!isPM && standardTimeMatch[3] && hour === 12) {
|
|
29
|
+
adjustedHour = 0; // Convert 12 AM to 0 hours
|
|
30
|
+
}
|
|
31
|
+
return (0, dayjs_1.default)()
|
|
32
|
+
.set('hour', adjustedHour)
|
|
33
|
+
.set('minute', minute)
|
|
34
|
+
.set('second', 0)
|
|
35
|
+
.toDate();
|
|
36
|
+
}
|
|
37
|
+
const time = (0, dayjs_1.default)(value, timeFormat);
|
|
38
|
+
if (!time.isValid()) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
return time.toDate();
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/fluent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"uuid": "11.0.3",
|
|
53
53
|
"yup": "^1.4.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "019339a44fae0fcce5466041f922710b08b79172"
|
|
56
56
|
}
|