@nnkogift/dhis2-form-utils-dhis2-ui 0.1.0-alpha.7 → 0.1.0-alpha.9
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/index.cjs +65 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +60 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +66 -86
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -6,34 +6,46 @@ import { ReactNode } from 'react';
|
|
|
6
6
|
type D2FieldProps = {
|
|
7
7
|
field: FieldControlInput;
|
|
8
8
|
};
|
|
9
|
+
declare function D2Field({ field }: D2FieldProps): react_jsx_runtime.JSX.Element | null;
|
|
10
|
+
|
|
9
11
|
type D2FieldWidgetProps = WidgetProps;
|
|
10
12
|
/** Dispatches an already-resolved `FieldControlReturn` to its widget component, without re-deriving field control state. Reused by consumers that build their own chrome (labels, badges, ghost placeholders) around a field. */
|
|
11
13
|
declare function D2FieldWidget({ control }: D2FieldWidgetProps): react_jsx_runtime.JSX.Element;
|
|
12
|
-
declare function D2Field({ field }: D2FieldProps): react_jsx_runtime.JSX.Element | null;
|
|
13
14
|
|
|
14
15
|
declare function D2TextField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
15
16
|
|
|
16
17
|
declare function D2LongTextField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
17
18
|
|
|
18
19
|
declare function D2EmailField(props: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
20
|
+
|
|
19
21
|
declare function D2PhoneField(props: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
22
|
+
|
|
20
23
|
declare function D2NumberField(props: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
24
|
+
|
|
21
25
|
declare function D2IntegerField(props: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
22
27
|
declare function D2PercentageField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
23
28
|
|
|
24
29
|
declare function D2DateField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
30
|
+
|
|
31
|
+
declare function D2AgeField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
32
|
+
|
|
25
33
|
declare function D2TimeField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
34
|
+
|
|
26
35
|
declare function D2DateTimeField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
27
|
-
declare function D2AgeField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
28
36
|
|
|
29
37
|
declare function D2BooleanField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
38
|
+
|
|
30
39
|
declare function D2TrueOnlyField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
40
|
+
|
|
31
41
|
declare function D2SelectField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
42
|
+
|
|
32
43
|
declare function D2MultiSelectField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
33
44
|
|
|
34
45
|
declare function D2OrgUnitField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
35
46
|
|
|
36
47
|
declare function D2FileField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
48
|
+
|
|
37
49
|
declare function D2ImageField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
|
38
50
|
|
|
39
51
|
declare function D2CoordinateField({ control }: WidgetProps): react_jsx_runtime.JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveFieldValidation, computeAgeFromDob, parseMultiTextValue, joinMultiTextValue, useOrgUnitPickerContext, useOrganisationUnitsQuery, useFieldControl, useSectionState, useFormFeedback, useFileResourceUpload } from '@nnkogift/dhis2-form-utils-hooks';
|
|
2
|
-
import {
|
|
2
|
+
import { InputField, TextAreaField, CalendarInput, Field, Radio, CheckboxField, SingleSelectField, SingleSelectOption, MultiSelectField, MultiSelectOption, Button, OrganisationUnitTree, FileInputField, Modal, ModalTitle, ModalContent, ModalActions, Chip, NoticeBox } from '@dhis2/ui';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { useMemo, useState, useEffect, useRef } from 'react';
|
|
5
5
|
import { useConfig } from '@dhis2/app-runtime';
|
|
@@ -53,7 +53,10 @@ function D2LongTextField({ control }) {
|
|
|
53
53
|
}
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function TypedTextField({
|
|
57
|
+
control,
|
|
58
|
+
type
|
|
59
|
+
}) {
|
|
57
60
|
const { fieldConfig, field, isMandatory, isDisabled } = control;
|
|
58
61
|
const { validationText, hasError, hasWarning } = resolveFieldValidation(control);
|
|
59
62
|
return /* @__PURE__ */ jsx(
|
|
@@ -77,16 +80,16 @@ function D2TypedTextField({ control, type }) {
|
|
|
77
80
|
);
|
|
78
81
|
}
|
|
79
82
|
function D2EmailField(props) {
|
|
80
|
-
return /* @__PURE__ */ jsx(
|
|
83
|
+
return /* @__PURE__ */ jsx(TypedTextField, { ...props, type: "email" });
|
|
81
84
|
}
|
|
82
85
|
function D2PhoneField(props) {
|
|
83
|
-
return /* @__PURE__ */ jsx(
|
|
86
|
+
return /* @__PURE__ */ jsx(TypedTextField, { ...props, type: "tel" });
|
|
84
87
|
}
|
|
85
88
|
function D2NumberField(props) {
|
|
86
|
-
return /* @__PURE__ */ jsx(
|
|
89
|
+
return /* @__PURE__ */ jsx(TypedTextField, { ...props, type: "number" });
|
|
87
90
|
}
|
|
88
91
|
function D2IntegerField(props) {
|
|
89
|
-
return /* @__PURE__ */ jsx(
|
|
92
|
+
return /* @__PURE__ */ jsx(TypedTextField, { ...props, type: "number" });
|
|
90
93
|
}
|
|
91
94
|
function D2PercentageField({ control }) {
|
|
92
95
|
return /* @__PURE__ */ jsx(
|
|
@@ -103,14 +106,6 @@ function D2PercentageField({ control }) {
|
|
|
103
106
|
);
|
|
104
107
|
}
|
|
105
108
|
var todayIso = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
106
|
-
var readDatePart = (value) => {
|
|
107
|
-
if (!value) return "";
|
|
108
|
-
return value.includes("T") ? value.slice(0, 10) : value;
|
|
109
|
-
};
|
|
110
|
-
var readTimePart = (value) => {
|
|
111
|
-
if (!value.includes("T")) return "";
|
|
112
|
-
return value.slice(11, 16);
|
|
113
|
-
};
|
|
114
109
|
function D2DateField({ control }) {
|
|
115
110
|
const { fieldConfig, field, isMandatory, isDisabled } = control;
|
|
116
111
|
const { validationText, hasError, hasWarning } = resolveFieldValidation(control);
|
|
@@ -139,6 +134,22 @@ function D2DateField({ control }) {
|
|
|
139
134
|
}
|
|
140
135
|
);
|
|
141
136
|
}
|
|
137
|
+
function D2AgeField({ control }) {
|
|
138
|
+
const age = computeAgeFromDob(control.field.value);
|
|
139
|
+
const helpText = [control.fieldConfig.description, age ? `Age: ${age} years` : void 0].filter(Boolean).join(" \xB7 ");
|
|
140
|
+
return /* @__PURE__ */ jsx(
|
|
141
|
+
D2DateField,
|
|
142
|
+
{
|
|
143
|
+
control: {
|
|
144
|
+
...control,
|
|
145
|
+
fieldConfig: {
|
|
146
|
+
...control.fieldConfig,
|
|
147
|
+
description: helpText || control.fieldConfig.description
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
142
153
|
function D2TimeField({ control }) {
|
|
143
154
|
const { fieldConfig, field, isMandatory, isDisabled } = control;
|
|
144
155
|
const { validationText, hasError, hasWarning } = resolveFieldValidation(control);
|
|
@@ -162,6 +173,14 @@ function D2TimeField({ control }) {
|
|
|
162
173
|
}
|
|
163
174
|
);
|
|
164
175
|
}
|
|
176
|
+
var readDatePart = (value) => {
|
|
177
|
+
if (!value) return "";
|
|
178
|
+
return value.includes("T") ? value.slice(0, 10) : value;
|
|
179
|
+
};
|
|
180
|
+
var readTimePart = (value) => {
|
|
181
|
+
if (!value.includes("T")) return "";
|
|
182
|
+
return value.slice(11, 16);
|
|
183
|
+
};
|
|
165
184
|
function D2DateTimeField({ control }) {
|
|
166
185
|
const { fieldConfig, field, isMandatory, isDisabled } = control;
|
|
167
186
|
const { validationText, hasError, hasWarning } = resolveFieldValidation(control);
|
|
@@ -218,27 +237,10 @@ function D2DateTimeField({ control }) {
|
|
|
218
237
|
)
|
|
219
238
|
] });
|
|
220
239
|
}
|
|
221
|
-
function D2AgeField({ control }) {
|
|
222
|
-
const age = computeAgeFromDob(control.field.value);
|
|
223
|
-
const helpText = [control.fieldConfig.description, age ? `Age: ${age} years` : void 0].filter(Boolean).join(" \xB7 ");
|
|
224
|
-
return /* @__PURE__ */ jsx(
|
|
225
|
-
D2DateField,
|
|
226
|
-
{
|
|
227
|
-
control: {
|
|
228
|
-
...control,
|
|
229
|
-
fieldConfig: {
|
|
230
|
-
...control.fieldConfig,
|
|
231
|
-
description: helpText || control.fieldConfig.description
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
240
|
var BOOLEAN_OPTIONS = [
|
|
238
241
|
{ label: "Yes", value: "true" },
|
|
239
242
|
{ label: "No", value: "false" }
|
|
240
243
|
];
|
|
241
|
-
var RADIO_RENDER_HINTS = /* @__PURE__ */ new Set(["RADIO", "VERTICAL_RADIOBUTTONS", "HORIZONTAL_RADIOBUTTONS"]);
|
|
242
244
|
function D2BooleanField({ control }) {
|
|
243
245
|
const { fieldConfig, field, isMandatory, isDisabled } = useMemo(() => control, [control]);
|
|
244
246
|
const { validationText, hasError, hasWarning } = useMemo(
|
|
@@ -255,30 +257,21 @@ function D2BooleanField({ control }) {
|
|
|
255
257
|
required: isMandatory,
|
|
256
258
|
disabled: isDisabled,
|
|
257
259
|
validationText,
|
|
258
|
-
children: /* @__PURE__ */ jsx(
|
|
259
|
-
|
|
260
|
+
children: /* @__PURE__ */ jsx("div", { className: "d2-boolean-options", children: BOOLEAN_OPTIONS.map((option) => /* @__PURE__ */ jsx(
|
|
261
|
+
Radio,
|
|
260
262
|
{
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
263
|
+
name: field.name,
|
|
264
|
+
label: option.label,
|
|
265
|
+
value: option.value,
|
|
266
|
+
checked: field.value === option.value,
|
|
267
|
+
disabled: isDisabled,
|
|
268
|
+
onChange: ({ value }) => {
|
|
269
|
+
field.onChange(value ?? "");
|
|
264
270
|
},
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
label: option.label,
|
|
270
|
-
value: option.value,
|
|
271
|
-
checked: field.value === option.value,
|
|
272
|
-
disabled: isDisabled,
|
|
273
|
-
onChange: ({ value }) => {
|
|
274
|
-
field.onChange(value ?? "");
|
|
275
|
-
},
|
|
276
|
-
onBlur: field.onBlur
|
|
277
|
-
},
|
|
278
|
-
option.label
|
|
279
|
-
))
|
|
280
|
-
}
|
|
281
|
-
)
|
|
271
|
+
onBlur: field.onBlur
|
|
272
|
+
},
|
|
273
|
+
option.label
|
|
274
|
+
)) })
|
|
282
275
|
}
|
|
283
276
|
);
|
|
284
277
|
}
|
|
@@ -306,6 +299,7 @@ function D2TrueOnlyField({ control }) {
|
|
|
306
299
|
}
|
|
307
300
|
);
|
|
308
301
|
}
|
|
302
|
+
var RADIO_RENDER_HINTS = /* @__PURE__ */ new Set(["RADIO", "VERTICAL_RADIOBUTTONS", "HORIZONTAL_RADIOBUTTONS"]);
|
|
309
303
|
function D2SelectField({ control }) {
|
|
310
304
|
const { fieldConfig, field, isMandatory, isDisabled } = control;
|
|
311
305
|
const { validationText, hasError, hasWarning } = resolveFieldValidation(control);
|
|
@@ -502,13 +496,13 @@ function D2ImageField({ control }) {
|
|
|
502
496
|
{
|
|
503
497
|
src: `${baseUrl}/api/fileResources/${value}/data`,
|
|
504
498
|
alt: fieldConfig.label,
|
|
505
|
-
|
|
499
|
+
className: "d2-image-preview"
|
|
506
500
|
}
|
|
507
501
|
) : null
|
|
508
502
|
] });
|
|
509
503
|
}
|
|
510
504
|
|
|
511
|
-
// ../../packages/map/src/coordinateValue.ts
|
|
505
|
+
// ../../packages/map/src/utils/coordinateValue.ts
|
|
512
506
|
var LNG_MIN = -180;
|
|
513
507
|
var LNG_MAX = 180;
|
|
514
508
|
var LAT_MIN = -90;
|
|
@@ -533,7 +527,7 @@ function joinCoordinateValue(lng, lat) {
|
|
|
533
527
|
return JSON.stringify([lng, lat]);
|
|
534
528
|
}
|
|
535
529
|
|
|
536
|
-
// ../../packages/map/src/geojsonValue.ts
|
|
530
|
+
// ../../packages/map/src/utils/geojsonValue.ts
|
|
537
531
|
var GEOMETRY_TYPES = /* @__PURE__ */ new Set([
|
|
538
532
|
"Point",
|
|
539
533
|
"MultiPoint",
|
|
@@ -564,7 +558,7 @@ function stringifyGeojsonGeometry(geometry) {
|
|
|
564
558
|
return JSON.stringify(geometry);
|
|
565
559
|
}
|
|
566
560
|
|
|
567
|
-
// ../../packages/map/src/defaultMapStyle.ts
|
|
561
|
+
// ../../packages/map/src/utils/defaultMapStyle.ts
|
|
568
562
|
var defaultMapStyle = {
|
|
569
563
|
version: 8,
|
|
570
564
|
sources: {
|
|
@@ -822,33 +816,19 @@ function CoordinateLocationModal({
|
|
|
822
816
|
] })
|
|
823
817
|
] });
|
|
824
818
|
}
|
|
825
|
-
var labelStyle = {
|
|
826
|
-
margin: 0,
|
|
827
|
-
fontSize: 11,
|
|
828
|
-
fontWeight: 600,
|
|
829
|
-
textTransform: "uppercase",
|
|
830
|
-
letterSpacing: 0.4,
|
|
831
|
-
color: colors.grey700
|
|
832
|
-
};
|
|
833
|
-
var valueStyle = {
|
|
834
|
-
margin: 0,
|
|
835
|
-
fontSize: 14,
|
|
836
|
-
fontWeight: 500,
|
|
837
|
-
fontVariantNumeric: "tabular-nums"
|
|
838
|
-
};
|
|
839
819
|
function CoordinateSummary({ value }) {
|
|
840
820
|
const parsed = parseCoordinateValue(value);
|
|
841
821
|
if (!parsed) {
|
|
842
|
-
return /* @__PURE__ */ jsx("span", {
|
|
822
|
+
return /* @__PURE__ */ jsx("span", { className: "d2-field-muted", children: "No location set" });
|
|
843
823
|
}
|
|
844
|
-
return /* @__PURE__ */ jsxs("dl", {
|
|
845
|
-
/* @__PURE__ */ jsxs("div", {
|
|
846
|
-
/* @__PURE__ */ jsx("dt", {
|
|
847
|
-
/* @__PURE__ */ jsx("dd", {
|
|
824
|
+
return /* @__PURE__ */ jsxs("dl", { className: "d2-coordinate-summary", children: [
|
|
825
|
+
/* @__PURE__ */ jsxs("div", { className: "d2-coordinate-axis", children: [
|
|
826
|
+
/* @__PURE__ */ jsx("dt", { className: "d2-coordinate-label", children: "Lat" }),
|
|
827
|
+
/* @__PURE__ */ jsx("dd", { className: "d2-coordinate-value", children: parsed.lat.toFixed(5) })
|
|
848
828
|
] }),
|
|
849
|
-
/* @__PURE__ */ jsxs("div", {
|
|
850
|
-
/* @__PURE__ */ jsx("dt", {
|
|
851
|
-
/* @__PURE__ */ jsx("dd", {
|
|
829
|
+
/* @__PURE__ */ jsxs("div", { className: "d2-coordinate-axis", children: [
|
|
830
|
+
/* @__PURE__ */ jsx("dt", { className: "d2-coordinate-label", children: "Lng" }),
|
|
831
|
+
/* @__PURE__ */ jsx("dd", { className: "d2-coordinate-value", children: parsed.lng.toFixed(5) })
|
|
852
832
|
] })
|
|
853
833
|
] });
|
|
854
834
|
}
|
|
@@ -868,7 +848,7 @@ function D2CoordinateField({ control }) {
|
|
|
868
848
|
disabled: isDisabled,
|
|
869
849
|
validationText,
|
|
870
850
|
children: [
|
|
871
|
-
/* @__PURE__ */ jsxs("div", {
|
|
851
|
+
/* @__PURE__ */ jsxs("div", { className: "d2-field-row", children: [
|
|
872
852
|
/* @__PURE__ */ jsx(CoordinateSummary, { value }),
|
|
873
853
|
/* @__PURE__ */ jsx(
|
|
874
854
|
Button,
|
|
@@ -1004,16 +984,16 @@ function countPositions(geometry) {
|
|
|
1004
984
|
function GeometrySummary({ value }) {
|
|
1005
985
|
const geometry = parseGeojsonGeometry(value);
|
|
1006
986
|
if (!geometry) {
|
|
1007
|
-
return /* @__PURE__ */ jsx("span", {
|
|
987
|
+
return /* @__PURE__ */ jsx("span", { className: "d2-field-muted", children: "No geometry set" });
|
|
1008
988
|
}
|
|
1009
989
|
if (geometry.type === "Point") {
|
|
1010
990
|
return /* @__PURE__ */ jsx(Chip, { dense: true, children: geometry.type });
|
|
1011
991
|
}
|
|
1012
992
|
const count = geometry.type === "GeometryCollection" ? geometry.geometries.length : countPositions(geometry);
|
|
1013
993
|
const noun = geometry.type === "GeometryCollection" ? count === 1 ? "geometry" : "geometries" : "points";
|
|
1014
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
994
|
+
return /* @__PURE__ */ jsxs("div", { className: "d2-geojson-summary", children: [
|
|
1015
995
|
/* @__PURE__ */ jsx(Chip, { dense: true, children: geometry.type }),
|
|
1016
|
-
/* @__PURE__ */ jsxs("span", {
|
|
996
|
+
/* @__PURE__ */ jsxs("span", { className: "d2-geojson-meta", children: [
|
|
1017
997
|
count,
|
|
1018
998
|
" ",
|
|
1019
999
|
noun
|
|
@@ -1036,7 +1016,7 @@ function D2GeoJsonField({ control }) {
|
|
|
1036
1016
|
disabled: isDisabled,
|
|
1037
1017
|
validationText,
|
|
1038
1018
|
children: [
|
|
1039
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1019
|
+
/* @__PURE__ */ jsxs("div", { className: "d2-field-row", children: [
|
|
1040
1020
|
/* @__PURE__ */ jsx(GeometrySummary, { value }),
|
|
1041
1021
|
/* @__PURE__ */ jsx(
|
|
1042
1022
|
Button,
|
|
@@ -1136,8 +1116,8 @@ function FeedbackPanel({ title, items }) {
|
|
|
1136
1116
|
if (!items.length) {
|
|
1137
1117
|
return null;
|
|
1138
1118
|
}
|
|
1139
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1140
|
-
/* @__PURE__ */ jsx("h3", {
|
|
1119
|
+
return /* @__PURE__ */ jsxs("div", { className: "d2-feedback-panel", children: [
|
|
1120
|
+
/* @__PURE__ */ jsx("h3", { className: "d2-feedback-panel-title", children: title }),
|
|
1141
1121
|
items.map((item) => /* @__PURE__ */ jsx(NoticeBox, { title: item.content, children: item.value ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1142
1122
|
/* @__PURE__ */ jsx("strong", { children: item.content }),
|
|
1143
1123
|
": ",
|