@oneblink/apps-react 7.3.0-beta.2 → 8.0.0-beta.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/dist/OneBlinkFormBase.d.ts +1 -2
- package/dist/OneBlinkFormBase.js +137 -135
- package/dist/OneBlinkFormBase.js.map +1 -1
- package/dist/components/formStore/table/Pickers.d.ts +21 -1
- package/dist/components/formStore/table/Pickers.js +1 -1
- package/dist/components/formStore/table/Pickers.js.map +1 -1
- package/dist/components/renderer/PageFormElements.js +1 -2
- package/dist/components/renderer/PageFormElements.js.map +1 -1
- package/dist/form-elements/FormElementDate.js +31 -35
- package/dist/form-elements/FormElementDate.js.map +1 -1
- package/dist/form-elements/FormElementDateTime.js +30 -39
- package/dist/form-elements/FormElementDateTime.js.map +1 -1
- package/dist/form-elements/FormElementTime.js +28 -32
- package/dist/form-elements/FormElementTime.js.map +1 -1
- package/dist/hooks/form-date-picker/useFormDatePickerProps.d.ts +26 -0
- package/dist/hooks/form-date-picker/useFormDatePickerProps.js +57 -0
- package/dist/hooks/form-date-picker/useFormDatePickerProps.js.map +1 -0
- package/dist/styles.css +0 -915
- package/dist/styles.scss +0 -2
- package/package.json +1 -2
- package/dist/hooks/useFlatpickr.d.ts +0 -14
- package/dist/hooks/useFlatpickr.js +0 -111
- package/dist/hooks/useFlatpickr.js.map +0 -1
- package/dist/hooks/useFlatpickrGuid.d.ts +0 -7
- package/dist/hooks/useFlatpickrGuid.js +0 -12
- package/dist/hooks/useFlatpickrGuid.js.map +0 -1
- package/dist/styles/date.scss +0 -7
@@ -1,47 +1,43 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { localisationService } from '@oneblink/apps';
|
3
|
+
import { DatePicker } from '@mui/x-date-pickers';
|
4
|
+
import { format } from 'date-fns';
|
3
5
|
import CopyToClipboardButton from '../components/renderer/CopyToClipboardButton';
|
4
|
-
import useFlatpickr from '../hooks/useFlatpickr';
|
5
6
|
import LookupButton from '../components/renderer/LookupButton';
|
6
7
|
import FormElementLabelContainer from '../components/renderer/FormElementLabelContainer';
|
7
8
|
import { parseDateValue } from '../services/generate-default-data';
|
8
9
|
import useFormElementDateFromTo from '../hooks/useFormElementDateFromTo';
|
9
10
|
import { LookupNotificationContext } from '../hooks/useLookupNotification';
|
10
11
|
import useElementAriaDescribedby from '../hooks/useElementAriaDescribedby';
|
11
|
-
import
|
12
|
+
import useFormDatePickerProps from '../hooks/form-date-picker/useFormDatePickerProps';
|
13
|
+
const shortDateFormat = localisationService.getDateFnsFormats().shortDate;
|
12
14
|
function FormElementDate({ id, element, value, onChange, validationMessage, displayValidationMessage, isDirty, setIsDirty, autocompleteAttributes, }) {
|
13
15
|
const ariaDescribedby = useElementAriaDescribedby(id, element);
|
14
|
-
const htmlDivElementRef = React.useRef(null);
|
15
16
|
const { fromDate, fromDaysOffset, toDate, toDaysOffset } = useFormElementDateFromTo(element);
|
16
|
-
const
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
value: fromDate,
|
24
|
-
}),
|
25
|
-
maxDate: parseDateValue({
|
26
|
-
dateOnly: false,
|
27
|
-
daysOffset: toDaysOffset,
|
28
|
-
value: toDate,
|
29
|
-
}),
|
30
|
-
defaultDate: undefined,
|
31
|
-
allowInvalidPreload: true,
|
32
|
-
onClose: setIsDirty,
|
33
|
-
};
|
34
|
-
return opts;
|
35
|
-
}, [fromDate, fromDaysOffset, setIsDirty, toDate, toDaysOffset]);
|
36
|
-
const handleChange = React.useCallback((newValue) => onChange(element, {
|
37
|
-
value: newValue,
|
38
|
-
}), [element, onChange]);
|
39
|
-
const { onBlur } = useFlatpickr({
|
17
|
+
const handleChange = React.useCallback((newValue) => {
|
18
|
+
onChange(element, {
|
19
|
+
value: newValue ? format(new Date(newValue), 'yyyy-MM-dd') : undefined,
|
20
|
+
});
|
21
|
+
setIsDirty();
|
22
|
+
}, [element, onChange, setIsDirty]);
|
23
|
+
const commonProps = useFormDatePickerProps({
|
40
24
|
id,
|
41
|
-
value,
|
42
|
-
|
43
|
-
|
44
|
-
|
25
|
+
value: typeof value === 'string' ? value : undefined,
|
26
|
+
maxDate: parseDateValue({
|
27
|
+
dateOnly: true,
|
28
|
+
daysOffset: toDaysOffset,
|
29
|
+
value: toDate,
|
30
|
+
}),
|
31
|
+
minDate: parseDateValue({
|
32
|
+
dateOnly: true,
|
33
|
+
daysOffset: fromDaysOffset,
|
34
|
+
value: fromDate,
|
35
|
+
}),
|
36
|
+
icon: 'event',
|
37
|
+
ariaDescribedby,
|
38
|
+
autocompleteAttributes,
|
39
|
+
placeholder: element.placeholderValue,
|
40
|
+
});
|
45
41
|
const text = React.useMemo(() => {
|
46
42
|
if (typeof value === 'string') {
|
47
43
|
const date = localisationService.generateDate({
|
@@ -57,13 +53,13 @@ function FormElementDate({ id, element, value, onChange, validationMessage, disp
|
|
57
53
|
}, [value]);
|
58
54
|
const { isLookingUp } = React.useContext(LookupNotificationContext);
|
59
55
|
const isDisplayingValidationMessage = (displayValidationMessage || isDirty) && !!validationMessage && !isLookingUp;
|
60
|
-
return (React.createElement("div", { className: "cypress-date-element"
|
56
|
+
return (React.createElement("div", { className: "cypress-date-element" },
|
61
57
|
React.createElement(FormElementLabelContainer, { className: "ob-date", id: id, element: element, required: element.required },
|
62
58
|
React.createElement("div", { className: "field has-addons" },
|
63
59
|
React.createElement("div", { className: "control is-expanded has-icons-right" },
|
64
|
-
React.createElement(
|
65
|
-
|
66
|
-
|
60
|
+
React.createElement(DatePicker, { label: element.label, format: shortDateFormat, ...commonProps, onAccept: (newDate) => {
|
61
|
+
handleChange(newDate === null || newDate === void 0 ? void 0 : newDate.toISOString());
|
62
|
+
}, disabled: element.readOnly })),
|
67
63
|
!!element.readOnly && !!text && (React.createElement("div", { className: "control" },
|
68
64
|
React.createElement(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }))),
|
69
65
|
React.createElement(LookupButton, { isInputButton: true, value: value, validationMessage: validationMessage, lookupButtonConfig: element.lookupButton })),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FormElementDate.js","sourceRoot":"","sources":["../../src/form-elements/FormElementDate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,qBAAqB,MAAM,
|
1
|
+
{"version":3,"file":"FormElementDate.js","sourceRoot":"","sources":["../../src/form-elements/FormElementDate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,qBAAqB,MAAM,8CAA8C,CAAA;AAChF,OAAO,YAAY,MAAM,qCAAqC,CAAA;AAE9D,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAElE,OAAO,wBAAwB,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,yBAAyB,MAAM,oCAAoC,CAAA;AAC1E,OAAO,sBAAsB,MAAM,kDAAkD,CAAA;AAErF,MAAM,eAAe,GAAG,mBAAmB,CAAC,iBAAiB,EAAE,CAAC,SAAS,CAAA;AAYzE,SAAS,eAAe,CAAC,EACvB,EAAE,EACF,OAAO,EACP,KAAK,EACL,QAAQ,EACR,iBAAiB,EACjB,wBAAwB,EACxB,OAAO,EACP,UAAU,EACV,sBAAsB,GAChB;IACN,MAAM,eAAe,GAAG,yBAAyB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAE9D,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE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AAiB,CACd,CACF,CACP,CACyB,CACxB,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { localisationService } from '@oneblink/apps'\nimport { FormTypes } from '@oneblink/types'\nimport { DatePicker } from '@mui/x-date-pickers'\nimport { format } from 'date-fns'\n\nimport CopyToClipboardButton from '../components/renderer/CopyToClipboardButton'\nimport LookupButton from '../components/renderer/LookupButton'\n\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport { parseDateValue } from '../services/generate-default-data'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\nimport useFormElementDateFromTo from '../hooks/useFormElementDateFromTo'\nimport { LookupNotificationContext } from '../hooks/useLookupNotification'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport useFormDatePickerProps from '../hooks/form-date-picker/useFormDatePickerProps'\n\nconst shortDateFormat = localisationService.getDateFnsFormats().shortDate\n\ntype Props = {\n id: string\n element: FormTypes.DateElement\n value: unknown | undefined\n onChange: FormElementValueChangeHandler<string>\n displayValidationMessage: boolean\n validationMessage: string | undefined\n autocompleteAttributes?: string\n} & IsDirtyProps\n\nfunction FormElementDate({\n id,\n element,\n value,\n onChange,\n validationMessage,\n displayValidationMessage,\n isDirty,\n setIsDirty,\n autocompleteAttributes,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n\n const { fromDate, fromDaysOffset, toDate, toDaysOffset } =\n useFormElementDateFromTo(element)\n\n const handleChange = React.useCallback(\n (newValue: string | undefined) => {\n onChange(element, {\n value: newValue ? format(new Date(newValue), 'yyyy-MM-dd') : undefined,\n })\n setIsDirty()\n },\n\n [element, onChange, setIsDirty],\n )\n\n const commonProps = useFormDatePickerProps({\n id,\n value: typeof value === 'string' ? value : undefined,\n maxDate: parseDateValue({\n dateOnly: true,\n daysOffset: toDaysOffset,\n value: toDate,\n }),\n minDate: parseDateValue({\n dateOnly: true,\n daysOffset: fromDaysOffset,\n value: fromDate,\n }),\n icon: 'event',\n ariaDescribedby,\n autocompleteAttributes,\n placeholder: element.placeholderValue,\n })\n\n const text = React.useMemo(() => {\n if (typeof value === 'string') {\n const date = localisationService.generateDate({\n daysOffset: undefined,\n value,\n dateOnly: true,\n })\n if (date) {\n return localisationService.formatDate(date)\n }\n }\n return null\n }, [value])\n\n const { isLookingUp } = React.useContext(LookupNotificationContext)\n const isDisplayingValidationMessage =\n (displayValidationMessage || isDirty) && !!validationMessage && !isLookingUp\n\n return (\n <div className=\"cypress-date-element\">\n <FormElementLabelContainer\n className=\"ob-date\"\n id={id}\n element={element}\n required={element.required}\n >\n <div className=\"field has-addons\">\n <div className=\"control is-expanded has-icons-right\">\n <DatePicker\n label={element.label}\n format={shortDateFormat}\n {...commonProps}\n onAccept={(newDate) => {\n handleChange(newDate?.toISOString())\n }}\n disabled={element.readOnly}\n />\n </div>\n {!!element.readOnly && !!text && (\n <div className=\"control\">\n <CopyToClipboardButton\n className=\"button is-input-addon copy-button cypress-copy-to-clipboard-button\"\n text={text}\n />\n </div>\n )}\n <LookupButton\n isInputButton\n value={value}\n validationMessage={validationMessage}\n lookupButtonConfig={element.lookupButton}\n />\n </div>\n\n {isDisplayingValidationMessage && (\n <div role=\"alert\" className=\"has-margin-top-8\">\n <div className=\"has-text-danger ob-error__text cypress-validation-message\">\n {validationMessage}\n </div>\n </div>\n )}\n </FormElementLabelContainer>\n </div>\n )\n}\n\nexport default React.memo(FormElementDate)\n"]}
|
@@ -1,51 +1,42 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { localisationService } from '@oneblink/apps';
|
3
|
+
import { DateTimePicker } from '@mui/x-date-pickers';
|
3
4
|
import CopyToClipboardButton from '../components/renderer/CopyToClipboardButton';
|
4
|
-
import useFlatpickr from '../hooks/useFlatpickr';
|
5
5
|
import LookupButton from '../components/renderer/LookupButton';
|
6
6
|
import FormElementLabelContainer from '../components/renderer/FormElementLabelContainer';
|
7
7
|
import { parseDateValue } from '../services/generate-default-data';
|
8
8
|
import useFormElementDateFromTo from '../hooks/useFormElementDateFromTo';
|
9
9
|
import { LookupNotificationContext } from '../hooks/useLookupNotification';
|
10
10
|
import useElementAriaDescribedby from '../hooks/useElementAriaDescribedby';
|
11
|
-
import
|
11
|
+
import useFormDatePickerProps from '../hooks/form-date-picker/useFormDatePickerProps';
|
12
|
+
const shortDateTimeFormat = localisationService.getDateFnsFormats().shortDateTime;
|
12
13
|
function FormElementDateTime({ id, element, value, onChange, validationMessage, displayValidationMessage, isDirty, setIsDirty, autocompleteAttributes, }) {
|
13
14
|
const ariaDescribedby = useElementAriaDescribedby(id, element);
|
14
|
-
const htmlDivElementRef = React.useRef(null);
|
15
15
|
const { fromDate, fromDaysOffset, toDate, toDaysOffset } = useFormElementDateFromTo(element);
|
16
|
-
const
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
minDate: parseDateValue({
|
24
|
-
dateOnly: false,
|
25
|
-
daysOffset: fromDaysOffset,
|
26
|
-
value: fromDate,
|
27
|
-
}),
|
28
|
-
maxDate: parseDateValue({
|
29
|
-
dateOnly: false,
|
30
|
-
daysOffset: toDaysOffset,
|
31
|
-
value: toDate,
|
32
|
-
}),
|
33
|
-
defaultDate: undefined,
|
34
|
-
enableTime: true,
|
35
|
-
allowInvalidPreload: true,
|
36
|
-
onClose: setIsDirty,
|
37
|
-
};
|
38
|
-
return opts;
|
39
|
-
}, [fromDate, fromDaysOffset, setIsDirty, toDate, toDaysOffset]);
|
40
|
-
const handleChange = React.useCallback((newValue) => onChange(element, {
|
41
|
-
value: newValue,
|
42
|
-
}), [element, onChange]);
|
43
|
-
useFlatpickr({
|
16
|
+
const handleChange = React.useCallback((newValue) => {
|
17
|
+
onChange(element, {
|
18
|
+
value: newValue,
|
19
|
+
});
|
20
|
+
setIsDirty();
|
21
|
+
}, [element, onChange, setIsDirty]);
|
22
|
+
const commonProps = useFormDatePickerProps({
|
44
23
|
id,
|
45
|
-
value,
|
46
|
-
|
47
|
-
|
48
|
-
|
24
|
+
value: typeof value === 'string' ? value : undefined,
|
25
|
+
maxDate: parseDateValue({
|
26
|
+
dateOnly: false,
|
27
|
+
daysOffset: toDaysOffset,
|
28
|
+
value: toDate,
|
29
|
+
}),
|
30
|
+
minDate: parseDateValue({
|
31
|
+
dateOnly: false,
|
32
|
+
daysOffset: fromDaysOffset,
|
33
|
+
value: fromDate,
|
34
|
+
}),
|
35
|
+
icon: 'date_range',
|
36
|
+
ariaDescribedby,
|
37
|
+
autocompleteAttributes,
|
38
|
+
placeholder: element.placeholderValue,
|
39
|
+
});
|
49
40
|
const text = React.useMemo(() => {
|
50
41
|
if (typeof value !== 'string') {
|
51
42
|
return null;
|
@@ -54,13 +45,13 @@ function FormElementDateTime({ id, element, value, onChange, validationMessage,
|
|
54
45
|
}, [value]);
|
55
46
|
const { isLookingUp } = React.useContext(LookupNotificationContext);
|
56
47
|
const isDisplayingValidationMessage = (isDirty || displayValidationMessage) && !!validationMessage && !isLookingUp;
|
57
|
-
return (React.createElement("div", { className: "cypress-datetime-element"
|
48
|
+
return (React.createElement("div", { className: "cypress-datetime-element" },
|
58
49
|
React.createElement(FormElementLabelContainer, { className: "ob-datetime", id: id, element: element, required: element.required },
|
59
50
|
React.createElement("div", { className: "field has-addons" },
|
60
51
|
React.createElement("div", { className: "control is-expanded has-icons-right" },
|
61
|
-
React.createElement(
|
62
|
-
|
63
|
-
|
52
|
+
React.createElement(DateTimePicker, { label: element.label, format: shortDateTimeFormat, ...commonProps, onAccept: (newDate) => {
|
53
|
+
handleChange(newDate === null || newDate === void 0 ? void 0 : newDate.toISOString());
|
54
|
+
}, disabled: element.readOnly, timeSteps: { minutes: 1 } })),
|
64
55
|
!!element.readOnly && !!text && (React.createElement("div", { className: "control" },
|
65
56
|
React.createElement(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }))),
|
66
57
|
React.createElement(LookupButton, { isInputButton: true, value: value, validationMessage: validationMessage, lookupButtonConfig: element.lookupButton })),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FormElementDateTime.js","sourceRoot":"","sources":["../../src/form-elements/FormElementDateTime.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,
|
1
|
+
{"version":3,"file":"FormElementDateTime.js","sourceRoot":"","sources":["../../src/form-elements/FormElementDateTime.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,OAAO,qBAAqB,MAAM,8CAA8C,CAAA;AAChF,OAAO,YAAY,MAAM,qCAAqC,CAAA;AAE9D,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAElE,OAAO,wBAAwB,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,yBAAyB,MAAM,oCAAoC,CAAA;AAC1E,OAAO,sBAAsB,MAAM,kDAAkD,CAAA;AAErF,MAAM,mBAAmB,GACvB,mBAAmB,CAAC,iBAAiB,EAAE,CAAC,aAAa,CAAA;AAYvD,SAAS,mBAAmB,CAAC,EAC3B,EAAE,EACF,OAAO,EACP,KAAK,EACL,QAAQ,EACR,iBAAiB,EACjB,wBAAwB,EACxB,OAAO,EACP,UAAU,EACV,sBAAsB,GAChB;IACN,MAAM,eAAe,GAAG,yBAAyB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAE9D,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,GACtD,wBAA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AK,SAAS,EAAC,0BAA0B;QACvC,oBAAC,yBAAyB,IACxB,SAAS,EAAC,aAAa,EACvB,EAAE,EAAE,EAAE,EACN,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAE1B,6BAAK,SAAS,EAAC,kBAAkB;gBAC/B,6BAAK,SAAS,EAAC,qCAAqC;oBAClD,oBAAC,cAAc,IACb,KAAK,EAAE,OAAO,CAAC,KAAK,EACpB,MAAM,EAAE,mBAAmB,KACvB,WAAW,EACf,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE;4BACpB,YAAY,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAE,CAAC,CAAA;wBACtC,CAAC,EACD,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAC1B,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,GACzB,CACE;gBACL,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAI,IAAI,CAC/B,6BAAK,SAAS,EAAC,SAAS;oBACtB,oBAAC,qBAAqB,IACpB,SAAS,EAAC,oEAAoE,EAC9E,IAAI,EAAE,IAAI,GACV,CACE,CACP;gBACD,oBAAC,YAAY,IACX,aAAa,QACb,KAAK,EAAE,KAAK,EACZ,iBAAiB,EAAE,iBAAiB,EACpC,kBAAkB,EAAE,OAAO,CAAC,YAAY,GACxC,CACE;YAEL,6BAA6B,IAAI,CAChC,6BAAK,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,kBAAkB;gBAC5C,6BAAK,SAAS,EAAC,2DAA2D,IACvE,iBAAiB,CACd,CACF,CACP,CACyB,CACxB,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { localisationService } from '@oneblink/apps'\nimport { FormTypes } from '@oneblink/types'\nimport { DateTimePicker } from '@mui/x-date-pickers'\n\nimport CopyToClipboardButton from '../components/renderer/CopyToClipboardButton'\nimport LookupButton from '../components/renderer/LookupButton'\n\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport { parseDateValue } from '../services/generate-default-data'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\nimport useFormElementDateFromTo from '../hooks/useFormElementDateFromTo'\nimport { LookupNotificationContext } from '../hooks/useLookupNotification'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport useFormDatePickerProps from '../hooks/form-date-picker/useFormDatePickerProps'\n\nconst shortDateTimeFormat =\n localisationService.getDateFnsFormats().shortDateTime\n\ntype Props = {\n id: string\n element: FormTypes.DateTimeElement\n value: unknown | undefined\n onChange: FormElementValueChangeHandler<string>\n displayValidationMessage: boolean\n validationMessage: string | undefined\n autocompleteAttributes?: string\n} & IsDirtyProps\n\nfunction FormElementDateTime({\n id,\n element,\n value,\n onChange,\n validationMessage,\n displayValidationMessage,\n isDirty,\n setIsDirty,\n autocompleteAttributes,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n\n const { fromDate, fromDaysOffset, toDate, toDaysOffset } =\n useFormElementDateFromTo(element)\n\n const handleChange = React.useCallback(\n (newValue: string | undefined) => {\n onChange(element, {\n value: newValue,\n })\n setIsDirty()\n },\n [element, onChange, setIsDirty],\n )\n\n const commonProps = useFormDatePickerProps({\n id,\n value: typeof value === 'string' ? value : undefined,\n maxDate: parseDateValue({\n dateOnly: false,\n daysOffset: toDaysOffset,\n value: toDate,\n }),\n minDate: parseDateValue({\n dateOnly: false,\n daysOffset: fromDaysOffset,\n value: fromDate,\n }),\n icon: 'date_range',\n ariaDescribedby,\n autocompleteAttributes,\n placeholder: element.placeholderValue,\n })\n\n const text = React.useMemo(() => {\n if (typeof value !== 'string') {\n return null\n }\n return localisationService.formatDatetime(new Date(value))\n }, [value])\n\n const { isLookingUp } = React.useContext(LookupNotificationContext)\n const isDisplayingValidationMessage =\n (isDirty || displayValidationMessage) && !!validationMessage && !isLookingUp\n\n return (\n <div className=\"cypress-datetime-element\">\n <FormElementLabelContainer\n className=\"ob-datetime\"\n id={id}\n element={element}\n required={element.required}\n >\n <div className=\"field has-addons\">\n <div className=\"control is-expanded has-icons-right\">\n <DateTimePicker\n label={element.label}\n format={shortDateTimeFormat}\n {...commonProps}\n onAccept={(newDate) => {\n handleChange(newDate?.toISOString())\n }}\n disabled={element.readOnly}\n timeSteps={{ minutes: 1 }}\n />\n </div>\n {!!element.readOnly && !!text && (\n <div className=\"control\">\n <CopyToClipboardButton\n className=\"button is-input-addon copy-button cypress-copy-to-clipboard-button\"\n text={text}\n />\n </div>\n )}\n <LookupButton\n isInputButton\n value={value}\n validationMessage={validationMessage}\n lookupButtonConfig={element.lookupButton}\n />\n </div>\n\n {isDisplayingValidationMessage && (\n <div role=\"alert\" className=\"has-margin-top-8\">\n <div className=\"has-text-danger ob-error__text cypress-validation-message\">\n {validationMessage}\n </div>\n </div>\n )}\n </FormElementLabelContainer>\n </div>\n )\n}\n\nexport default React.memo(FormElementDateTime)\n"]}
|
@@ -1,41 +1,37 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { localisationService } from '@oneblink/apps';
|
3
|
+
import { TimePicker } from '@mui/x-date-pickers';
|
3
4
|
import CopyToClipboardButton from '../components/renderer/CopyToClipboardButton';
|
4
|
-
import useFlatpickr from '../hooks/useFlatpickr';
|
5
5
|
import LookupButton from '../components/renderer/LookupButton';
|
6
6
|
import FormElementLabelContainer from '../components/renderer/FormElementLabelContainer';
|
7
7
|
import { LookupNotificationContext } from '../hooks/useLookupNotification';
|
8
8
|
import useElementAriaDescribedby from '../hooks/useElementAriaDescribedby';
|
9
|
-
import
|
9
|
+
import useFormDatePickerProps from '../hooks/form-date-picker/useFormDatePickerProps';
|
10
|
+
const timeFormat = localisationService.getDateFnsFormats().time;
|
10
11
|
function FormElementTime({ id, element, value, onChange, validationMessage, displayValidationMessage, isDirty, setIsDirty, autocompleteAttributes, }) {
|
11
12
|
const ariaDescribedby = useElementAriaDescribedby(id, element);
|
12
|
-
const
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
altInputClass: 'input ob-input cypress-time-control',
|
20
|
-
minDate: undefined,
|
21
|
-
maxDate: undefined,
|
22
|
-
defaultDate: undefined,
|
23
|
-
enableTime: true,
|
24
|
-
noCalendar: true,
|
25
|
-
time_24hr: false,
|
26
|
-
onClose: setIsDirty,
|
27
|
-
};
|
28
|
-
return opts;
|
29
|
-
}, [setIsDirty]);
|
30
|
-
const handleChange = React.useCallback((newValue) => onChange(element, {
|
31
|
-
value: newValue,
|
32
|
-
}), [element, onChange]);
|
33
|
-
useFlatpickr({
|
13
|
+
const handleChange = React.useCallback((newValue) => {
|
14
|
+
onChange(element, {
|
15
|
+
value: newValue,
|
16
|
+
});
|
17
|
+
setIsDirty();
|
18
|
+
}, [element, onChange, setIsDirty]);
|
19
|
+
const commonProps = useFormDatePickerProps({
|
34
20
|
id,
|
35
|
-
value,
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
value: typeof value === 'string' ? value : undefined,
|
22
|
+
maxDate: undefined,
|
23
|
+
minDate: undefined,
|
24
|
+
icon: 'schedule',
|
25
|
+
ariaDescribedby,
|
26
|
+
autocompleteAttributes,
|
27
|
+
placeholder: element.placeholderValue,
|
28
|
+
});
|
29
|
+
const timeProps = React.useMemo(() => {
|
30
|
+
// maxDate and minDate not applicable to a timepicker
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
32
|
+
const { maxDate, minDate, ...rest } = commonProps;
|
33
|
+
return rest;
|
34
|
+
}, [commonProps]);
|
39
35
|
const text = React.useMemo(() => {
|
40
36
|
if (typeof value !== 'string') {
|
41
37
|
return null;
|
@@ -44,13 +40,13 @@ function FormElementTime({ id, element, value, onChange, validationMessage, disp
|
|
44
40
|
}, [value]);
|
45
41
|
const { isLookingUp } = React.useContext(LookupNotificationContext);
|
46
42
|
const isDisplayingValidationMessage = (isDirty || displayValidationMessage) && !!validationMessage && !isLookingUp;
|
47
|
-
return (React.createElement("div", { className: "cypress-time-element"
|
43
|
+
return (React.createElement("div", { className: "cypress-time-element" },
|
48
44
|
React.createElement(FormElementLabelContainer, { className: "ob-time", id: id, element: element, required: element.required },
|
49
45
|
React.createElement("div", { className: "field has-addons" },
|
50
46
|
React.createElement("div", { className: "control is-expanded has-icons-right" },
|
51
|
-
React.createElement(
|
52
|
-
|
53
|
-
|
47
|
+
React.createElement(TimePicker, { label: element.label, format: timeFormat, ...timeProps, onAccept: (newDate) => {
|
48
|
+
handleChange(newDate === null || newDate === void 0 ? void 0 : newDate.toISOString());
|
49
|
+
}, disabled: element.readOnly, timeSteps: { minutes: 1 } })),
|
54
50
|
!!element.readOnly && !!text && (React.createElement("div", { className: "control" },
|
55
51
|
React.createElement(CopyToClipboardButton, { className: "button is-input-addon copy-button cypress-copy-to-clipboard-button", text: text }))),
|
56
52
|
React.createElement(LookupButton, { isInputButton: true, value: value, validationMessage: validationMessage, lookupButtonConfig: element.lookupButton })),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FormElementTime.js","sourceRoot":"","sources":["../../src/form-elements/FormElementTime.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,
|
1
|
+
{"version":3,"file":"FormElementTime.js","sourceRoot":"","sources":["../../src/form-elements/FormElementTime.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,OAAO,qBAAqB,MAAM,8CAA8C,CAAA;AAChF,OAAO,YAAY,MAAM,qCAAqC,CAAA;AAE9D,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AAExF,OA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,EACZ,iBAAiB,EAAE,iBAAiB,EACpC,kBAAkB,EAAE,OAAO,CAAC,YAAY,GACxC,CACE;YAEL,6BAA6B,IAAI,CAChC,6BAAK,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,kBAAkB;gBAC5C,6BAAK,SAAS,EAAC,2DAA2D,IACvE,iBAAiB,CACd,CACF,CACP,CACyB,CACxB,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { localisationService } from '@oneblink/apps'\nimport { FormTypes } from '@oneblink/types'\nimport { TimePicker } from '@mui/x-date-pickers'\n\nimport CopyToClipboardButton from '../components/renderer/CopyToClipboardButton'\nimport LookupButton from '../components/renderer/LookupButton'\n\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\nimport { LookupNotificationContext } from '../hooks/useLookupNotification'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport useFormDatePickerProps from '../hooks/form-date-picker/useFormDatePickerProps'\n\ntype Props = {\n id: string\n element: FormTypes.TimeElement\n value: unknown | undefined\n onChange: FormElementValueChangeHandler<string>\n displayValidationMessage: boolean\n validationMessage: string | undefined\n autocompleteAttributes?: string\n} & IsDirtyProps\n\nconst timeFormat = localisationService.getDateFnsFormats().time\n\nfunction FormElementTime({\n id,\n element,\n value,\n onChange,\n validationMessage,\n displayValidationMessage,\n isDirty,\n setIsDirty,\n autocompleteAttributes,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n\n const handleChange = React.useCallback(\n (newValue: string | undefined) => {\n onChange(element, {\n value: newValue,\n })\n setIsDirty()\n },\n [element, onChange, setIsDirty],\n )\n\n const commonProps = useFormDatePickerProps({\n id,\n value: typeof value === 'string' ? value : undefined,\n maxDate: undefined,\n minDate: undefined,\n icon: 'schedule',\n ariaDescribedby,\n autocompleteAttributes,\n placeholder: element.placeholderValue,\n })\n\n const timeProps = React.useMemo(() => {\n // maxDate and minDate not applicable to a timepicker\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { maxDate, minDate, ...rest } = commonProps\n return rest\n }, [commonProps])\n\n const text = React.useMemo(() => {\n if (typeof value !== 'string') {\n return null\n }\n return localisationService.formatTime(new Date(value))\n }, [value])\n\n const { isLookingUp } = React.useContext(LookupNotificationContext)\n const isDisplayingValidationMessage =\n (isDirty || displayValidationMessage) && !!validationMessage && !isLookingUp\n return (\n <div className=\"cypress-time-element\">\n <FormElementLabelContainer\n className=\"ob-time\"\n id={id}\n element={element}\n required={element.required}\n >\n <div className=\"field has-addons\">\n <div className=\"control is-expanded has-icons-right\">\n <TimePicker\n label={element.label}\n format={timeFormat}\n {...timeProps}\n onAccept={(newDate) => {\n handleChange(newDate?.toISOString())\n }}\n disabled={element.readOnly}\n timeSteps={{ minutes: 1 }}\n />\n </div>\n {!!element.readOnly && !!text && (\n <div className=\"control\">\n <CopyToClipboardButton\n className=\"button is-input-addon copy-button cypress-copy-to-clipboard-button\"\n text={text}\n />\n </div>\n )}\n <LookupButton\n isInputButton\n value={value}\n validationMessage={validationMessage}\n lookupButtonConfig={element.lookupButton}\n />\n </div>\n\n {isDisplayingValidationMessage && (\n <div role=\"alert\" className=\"has-margin-top-8\">\n <div className=\"has-text-danger ob-error__text cypress-validation-message\">\n {validationMessage}\n </div>\n </div>\n )}\n </FormElementLabelContainer>\n </div>\n )\n}\n\nexport default React.memo(FormElementTime)\n"]}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { TextFieldProps } from '@mui/material';
|
3
|
+
import { PickersActionBarAction } from '@mui/x-date-pickers';
|
4
|
+
export default function useFormDatePickerProps({ id, value, maxDate, minDate, icon, ariaDescribedby, autocompleteAttributes, placeholder, }: {
|
5
|
+
id: string;
|
6
|
+
value: string | undefined;
|
7
|
+
maxDate: string | undefined;
|
8
|
+
minDate: string | undefined;
|
9
|
+
icon: 'event' | 'date_range' | 'schedule';
|
10
|
+
ariaDescribedby: string | undefined;
|
11
|
+
autocompleteAttributes: string | undefined;
|
12
|
+
placeholder: string | undefined;
|
13
|
+
}): {
|
14
|
+
slots: {
|
15
|
+
textField: (params: React.PropsWithChildren<TextFieldProps>) => React.JSX.Element;
|
16
|
+
openPickerIcon: () => React.JSX.Element;
|
17
|
+
};
|
18
|
+
slotProps: {
|
19
|
+
actionBar: {
|
20
|
+
actions: PickersActionBarAction[];
|
21
|
+
};
|
22
|
+
};
|
23
|
+
maxDate: Date | null;
|
24
|
+
minDate: Date | null;
|
25
|
+
value: Date | null;
|
26
|
+
};
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { TextField, styled } from '@mui/material';
|
3
|
+
import clsx from 'clsx';
|
4
|
+
import MaterialIcon from '../../components/MaterialIcon';
|
5
|
+
const StyledTextField = styled(TextField)(() => ({
|
6
|
+
'& .MuiOutlinedInput-root': {
|
7
|
+
fontFamily: 'inherit',
|
8
|
+
'& fieldset': {
|
9
|
+
borderColor: '#dbdbdb',
|
10
|
+
},
|
11
|
+
'&:hover fieldset': {
|
12
|
+
borderColor: '#b5b5b5',
|
13
|
+
},
|
14
|
+
'&.Mui-focused fieldset': {
|
15
|
+
borderColor: '#485fc7',
|
16
|
+
borderWidth: '1px',
|
17
|
+
},
|
18
|
+
},
|
19
|
+
}));
|
20
|
+
export default function useFormDatePickerProps({ id, value, maxDate, minDate, icon, ariaDescribedby, autocompleteAttributes, placeholder, }) {
|
21
|
+
const valueMemo = React.useMemo(() => {
|
22
|
+
return value ? new Date(value) : null;
|
23
|
+
}, [value]);
|
24
|
+
const maxDateMemo = React.useMemo(() => (maxDate ? new Date(maxDate) : null), [maxDate]);
|
25
|
+
const minDateMemo = React.useMemo(() => (minDate ? new Date(minDate) : null), [minDate]);
|
26
|
+
//must be a fuction
|
27
|
+
const openPickerIcon = React.useCallback(() => React.createElement(MaterialIcon, { className: "is-size-5" }, icon), [icon]);
|
28
|
+
return {
|
29
|
+
slots: {
|
30
|
+
textField: (params) => {
|
31
|
+
var _a;
|
32
|
+
return (React.createElement(StyledTextField, { ...params, id: id, variant: "outlined", margin: "dense", size: "small", label: undefined, placeholder: placeholder, autoComplete: autocompleteAttributes, "aria-describedby": "once once", inputProps: {
|
33
|
+
...params.inputProps,
|
34
|
+
className: clsx((_a = params.inputProps) === null || _a === void 0 ? void 0 : _a.className, 'input ob-input'),
|
35
|
+
ariaDescribedby: ariaDescribedby,
|
36
|
+
}, fullWidth: true,
|
37
|
+
//we have our own error and helper text state
|
38
|
+
error: undefined }));
|
39
|
+
},
|
40
|
+
openPickerIcon,
|
41
|
+
},
|
42
|
+
slotProps: {
|
43
|
+
actionBar: {
|
44
|
+
actions: [
|
45
|
+
'clear',
|
46
|
+
'today',
|
47
|
+
'cancel',
|
48
|
+
'accept',
|
49
|
+
],
|
50
|
+
},
|
51
|
+
},
|
52
|
+
maxDate: maxDateMemo,
|
53
|
+
minDate: minDateMemo,
|
54
|
+
value: valueMemo,
|
55
|
+
};
|
56
|
+
}
|
57
|
+
//# sourceMappingURL=useFormDatePickerProps.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useFormDatePickerProps.js","sourceRoot":"","sources":["../../../src/hooks/form-date-picker/useFormDatePickerProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAkB,MAAM,EAAE,MAAM,eAAe,CAAA;AAEjE,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,YAAY,MAAM,+BAA+B,CAAA;AAExD,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/C,0BAA0B,EAAE;QAC1B,UAAU,EAAE,SAAS;QACrB,YAAY,EAAE;YACZ,WAAW,EAAE,SAAS;SACvB;QACD,kBAAkB,EAAE;YAClB,WAAW,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O,EACZ,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,sBAAsB,sBACnB,WAAW,EAC5B,UAAU,EAAE;wBACV,GAAG,MAAM,CAAC,UAAU;wBACpB,SAAS,EAAE,IAAI,CAAC,MAAA,MAAM,CAAC,UAAU,0CAAE,SAAS,EAAE,gBAAgB,CAAC;wBAC/D,eAAe,EAAE,eAAe;qBACjC,EACD,SAAS;oBACT,6CAA6C;oBAC7C,KAAK,EAAE,SAAS,GAChB,CACH,CAAA;aAAA;YACD,cAAc;SACf;QACD,SAAS,EAAE;YACT,SAAS,EAAE;gBACT,OAAO,EAAE;oBACP,OAAO;oBACP,OAAO;oBACP,QAAQ;oBACR,QAAQ;iBACmB;aAC9B;SACF;QACD,OAAO,EAAE,WAAW;QACpB,OAAO,EAAE,WAAW;QACpB,KAAK,EAAE,SAAS;KACjB,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { TextField, TextFieldProps, styled } from '@mui/material'\nimport { PickersActionBarAction } from '@mui/x-date-pickers'\nimport clsx from 'clsx'\nimport MaterialIcon from '../../components/MaterialIcon'\n\nconst StyledTextField = styled(TextField)(() => ({\n '& .MuiOutlinedInput-root': {\n fontFamily: 'inherit',\n '& fieldset': {\n borderColor: '#dbdbdb',\n },\n '&:hover fieldset': {\n borderColor: '#b5b5b5',\n },\n '&.Mui-focused fieldset': {\n borderColor: '#485fc7',\n borderWidth: '1px',\n },\n },\n}))\n\nexport default function useFormDatePickerProps({\n id,\n value,\n maxDate,\n minDate,\n icon,\n ariaDescribedby,\n autocompleteAttributes,\n placeholder,\n}: {\n id: string\n value: string | undefined\n maxDate: string | undefined\n minDate: string | undefined\n icon: 'event' | 'date_range' | 'schedule'\n ariaDescribedby: string | undefined\n autocompleteAttributes: string | undefined\n placeholder: string | undefined\n}) {\n const valueMemo = React.useMemo(() => {\n return value ? new Date(value) : null\n }, [value])\n\n const maxDateMemo = React.useMemo(\n () => (maxDate ? new Date(maxDate) : null),\n [maxDate],\n )\n const minDateMemo = React.useMemo(\n () => (minDate ? new Date(minDate) : null),\n [minDate],\n )\n\n //must be a fuction\n const openPickerIcon = React.useCallback(\n () => <MaterialIcon className=\"is-size-5\">{icon}</MaterialIcon>,\n [icon],\n )\n\n return {\n slots: {\n textField: (params: React.PropsWithChildren<TextFieldProps>) => (\n <StyledTextField\n {...params}\n id={id}\n variant=\"outlined\"\n margin=\"dense\"\n size=\"small\"\n label={undefined}\n placeholder={placeholder}\n autoComplete={autocompleteAttributes}\n aria-describedby=\"once once\"\n inputProps={{\n ...params.inputProps,\n className: clsx(params.inputProps?.className, 'input ob-input'),\n ariaDescribedby: ariaDescribedby,\n }}\n fullWidth\n //we have our own error and helper text state\n error={undefined}\n />\n ),\n openPickerIcon,\n },\n slotProps: {\n actionBar: {\n actions: [\n 'clear',\n 'today',\n 'cancel',\n 'accept',\n ] as PickersActionBarAction[],\n },\n },\n maxDate: maxDateMemo,\n minDate: minDateMemo,\n value: valueMemo,\n }\n}\n"]}
|