@hortiview/shared-components 0.0.11587 → 0.0.11747
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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# HortiView Shared Components
|
|
2
2
|
|
|
3
|
-
This is a shared
|
|
3
|
+
This is a shared components library. It should be used in the HortiView platform and its modules.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -10,10 +10,9 @@ This is a shared component library. It should used in the HortiView platform and
|
|
|
10
10
|
|
|
11
11
|
## Prerequisites
|
|
12
12
|
|
|
13
|
-
This library is based
|
|
14
|
-
To get access to this restricted package please contact your Bayer contact person.
|
|
13
|
+
This library is based on a public version of Bayer's Element component library.
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
Use `yarn add @element-public/react-components @element-public/themes` or `npm i @element-public/react-components @element-public/themes` to add the packages to your solution.
|
|
17
16
|
|
|
18
17
|
## Remarks
|
|
19
18
|
|
|
@@ -63,6 +62,7 @@ Additionally the library provides form components using [react-hook-form](https:
|
|
|
63
62
|
1. [useBreakpoints](#usebreakpoints)
|
|
64
63
|
1. [capitalizeFirstLetters](#capitalizefirstletters)
|
|
65
64
|
1. [trimLeadingAndTrailingSpaces](#trimleadingandtrailingspaces)
|
|
65
|
+
1. [getNumberAsLocaleString](#getnumberaslocalestring)
|
|
66
66
|
|
|
67
67
|
## Available Components:
|
|
68
68
|
|
|
@@ -1,140 +1,130 @@
|
|
|
1
|
-
import { jsx as t, Fragment as
|
|
2
|
-
import { T as
|
|
3
|
-
import { a as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}, ee = ({
|
|
1
|
+
import { jsx as t, Fragment as v, jsxs as z } from "react/jsx-runtime";
|
|
2
|
+
import { T as M } from "../../../index.es-25EARqhH.js";
|
|
3
|
+
import { a as P } from "../../../index.es-CF_xy2ns.js";
|
|
4
|
+
import { useState as V, useCallback as W, useMemo as m } from "react";
|
|
5
|
+
import { useFormContext as D, Controller as _ } from "react-hook-form";
|
|
6
|
+
import { useHelperText as E } from "../../../hooks/useHelperText.js";
|
|
7
|
+
import '../../../assets/FormText.css';const G = "_formTextAreaHelperText_168p8_1", I = "_invalid_168p8_7", J = "_required_168p8_11", K = "_formTextArea_168p8_1", O = "_characterCount_168p8_25", Q = "_withoutCharacterCount_168p8_31", r = {
|
|
8
|
+
formTextAreaHelperText: G,
|
|
9
|
+
invalid: I,
|
|
10
|
+
required: J,
|
|
11
|
+
formTextArea: K,
|
|
12
|
+
characterCount: O,
|
|
13
|
+
withoutCharacterCount: Q
|
|
14
|
+
}, U = ({
|
|
16
15
|
count: e,
|
|
17
|
-
maxCount:
|
|
18
|
-
invalid:
|
|
19
|
-
hasRequiredText:
|
|
16
|
+
maxCount: u,
|
|
17
|
+
invalid: s = !1,
|
|
18
|
+
hasRequiredText: n = !1
|
|
20
19
|
}) => /* @__PURE__ */ t(
|
|
21
20
|
"div",
|
|
22
21
|
{
|
|
23
22
|
"data-testid": "character-counter-container",
|
|
24
|
-
className: `${
|
|
25
|
-
children: /* @__PURE__ */ t(
|
|
23
|
+
className: `${r.formTextAreaHelperText} ${s ? r.invalid : ""} ${n ? r.required : ""}`,
|
|
24
|
+
children: /* @__PURE__ */ t(P, { children: `${e}/${u}` })
|
|
26
25
|
}
|
|
27
|
-
),
|
|
26
|
+
), re = (e) => e.textarea ? /* @__PURE__ */ t(X, { ...e }) : /* @__PURE__ */ t(Y, { ...e }), X = (e) => /* @__PURE__ */ t("div", { "data-testid": "form-text-area", className: r.formTextArea, children: /* @__PURE__ */ t(A, { ...e }) }), Y = (e) => /* @__PURE__ */ t(
|
|
28
27
|
"div",
|
|
29
28
|
{
|
|
30
29
|
"data-testid": "form-text-field",
|
|
31
|
-
className: `${e.hasCharacterCount ?
|
|
32
|
-
children: /* @__PURE__ */ t(
|
|
30
|
+
className: `${e.hasCharacterCount ? r.characterCount : r.withoutCharacterCount}`,
|
|
31
|
+
children: /* @__PURE__ */ t(A, { ...e })
|
|
33
32
|
}
|
|
34
|
-
),
|
|
33
|
+
), A = ({
|
|
35
34
|
propertyName: e,
|
|
36
|
-
label:
|
|
37
|
-
disabled:
|
|
38
|
-
textarea:
|
|
39
|
-
hasCharacterCount:
|
|
40
|
-
hidden:
|
|
41
|
-
placeholder:
|
|
42
|
-
type:
|
|
43
|
-
prefixText:
|
|
44
|
-
inputMode:
|
|
45
|
-
trailingIcon:
|
|
46
|
-
trigger:
|
|
35
|
+
label: u,
|
|
36
|
+
disabled: s = !1,
|
|
37
|
+
textarea: n = !1,
|
|
38
|
+
hasCharacterCount: o = !1,
|
|
39
|
+
hidden: $ = !1,
|
|
40
|
+
placeholder: F,
|
|
41
|
+
type: q,
|
|
42
|
+
prefixText: H,
|
|
43
|
+
inputMode: L,
|
|
44
|
+
trailingIcon: w,
|
|
45
|
+
trigger: x = "likeForm",
|
|
47
46
|
rules: a,
|
|
48
47
|
...i
|
|
49
48
|
}) => {
|
|
50
|
-
const { control:
|
|
49
|
+
const { control: f, getFieldState: d, trigger: T } = D(), [B, C] = V(0), S = W(
|
|
51
50
|
(h) => {
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
if (!(!n && !o)) {
|
|
52
|
+
if (h) {
|
|
53
|
+
C(h.length);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
C(0);
|
|
55
57
|
}
|
|
56
|
-
if (h) {
|
|
57
|
-
m(h.length);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
m(0);
|
|
61
58
|
},
|
|
62
|
-
[o]
|
|
63
|
-
), l =
|
|
64
|
-
() => i.maxlength
|
|
59
|
+
[o, n]
|
|
60
|
+
), l = m(
|
|
61
|
+
() => i.maxlength ? i.maxlength : a?.maxLength?.value,
|
|
65
62
|
[a, i.maxlength]
|
|
66
|
-
),
|
|
63
|
+
), j = m(
|
|
67
64
|
() => a?.minLength?.value,
|
|
68
65
|
[a]
|
|
69
|
-
),
|
|
66
|
+
), g = m(
|
|
70
67
|
() => a?.required?.message,
|
|
71
68
|
[a]
|
|
72
|
-
), { helperText:
|
|
69
|
+
), { helperText: k, helperTextPersistent: R } = E({
|
|
73
70
|
propertyName: e,
|
|
74
71
|
helperText: i.helperText,
|
|
75
|
-
requiredText:
|
|
72
|
+
requiredText: g,
|
|
76
73
|
maxLength: l,
|
|
77
|
-
hasCharacterCount:
|
|
74
|
+
hasCharacterCount: n || o
|
|
78
75
|
});
|
|
79
|
-
return
|
|
80
|
-
|
|
81
|
-
}, [o, r, c, l, f]), w ? /* @__PURE__ */ t(H, { name: e, control: g, render: () => /* @__PURE__ */ t(F, {}) }) : /* @__PURE__ */ t(
|
|
82
|
-
H,
|
|
76
|
+
return $ ? /* @__PURE__ */ t(_, { name: e, control: f, render: () => /* @__PURE__ */ t(v, {}) }) : /* @__PURE__ */ t(
|
|
77
|
+
_,
|
|
83
78
|
{
|
|
84
79
|
name: e,
|
|
85
80
|
rules: a,
|
|
86
|
-
control:
|
|
87
|
-
render: ({ field: { ref: h, ...
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
hasRequiredText: !!i.helperText || !!_
|
|
131
|
-
}
|
|
132
|
-
)
|
|
133
|
-
] });
|
|
134
|
-
}
|
|
81
|
+
control: f,
|
|
82
|
+
render: ({ field: { ref: h, ...c } }) => (S(c.value), /* @__PURE__ */ z(v, { children: [
|
|
83
|
+
/* @__PURE__ */ t(
|
|
84
|
+
M,
|
|
85
|
+
{
|
|
86
|
+
...i,
|
|
87
|
+
...c,
|
|
88
|
+
value: c.value ?? "",
|
|
89
|
+
type: q,
|
|
90
|
+
fullWidth: !0,
|
|
91
|
+
"data-testid": `textfield-${e}`,
|
|
92
|
+
inputMode: L,
|
|
93
|
+
placeholder: F,
|
|
94
|
+
prefixText: H,
|
|
95
|
+
disabled: s,
|
|
96
|
+
helperText: k,
|
|
97
|
+
helperTextPersistent: R,
|
|
98
|
+
label: u,
|
|
99
|
+
variant: "outlined",
|
|
100
|
+
maxlength: l,
|
|
101
|
+
minLength: j,
|
|
102
|
+
textarea: n,
|
|
103
|
+
noResize: !1,
|
|
104
|
+
onBlur: () => {
|
|
105
|
+
x === "onBlur" && T(e), i.onBlur?.();
|
|
106
|
+
},
|
|
107
|
+
onChange: (b) => {
|
|
108
|
+
c.onChange(b), x === "onChange" && T(e);
|
|
109
|
+
},
|
|
110
|
+
valid: !d(e).invalid,
|
|
111
|
+
className: `${r.formText} ${d(e).invalid ? r.invalid : ""}`,
|
|
112
|
+
trailingIcon: w
|
|
113
|
+
}
|
|
114
|
+
),
|
|
115
|
+
l !== void 0 && (o || n) && /* @__PURE__ */ t(
|
|
116
|
+
U,
|
|
117
|
+
{
|
|
118
|
+
count: B,
|
|
119
|
+
maxCount: l,
|
|
120
|
+
invalid: d(e).invalid,
|
|
121
|
+
hasRequiredText: !!i.helperText || !!g
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
] }))
|
|
135
125
|
}
|
|
136
126
|
);
|
|
137
127
|
};
|
|
138
128
|
export {
|
|
139
|
-
|
|
129
|
+
re as FormText
|
|
140
130
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
-
import { a as s, s as r, f as
|
|
2
|
+
import { a as s, s as r, f as i } from "../../../react.esm-DNwojocF.js";
|
|
3
3
|
import { FormText as o } from "./FormText.js";
|
|
4
4
|
import { v as a, d as u, t as l, g as e } from "../../../vi.CjhMlMwf-BCJNwXvu.js";
|
|
5
|
-
const
|
|
5
|
+
const d = a.fn();
|
|
6
6
|
a.mock("react-hook-form", () => ({
|
|
7
7
|
...a.importActual("react-hook-form"),
|
|
8
8
|
Controller: ({
|
|
@@ -10,7 +10,7 @@ a.mock("react-hook-form", () => ({
|
|
|
10
10
|
}) => t({
|
|
11
11
|
field: {
|
|
12
12
|
ref: void 0,
|
|
13
|
-
onChange:
|
|
13
|
+
onChange: d,
|
|
14
14
|
value: "test"
|
|
15
15
|
},
|
|
16
16
|
formState: { defaultValue: {} }
|
|
@@ -62,23 +62,9 @@ u("FormText Test", () => {
|
|
|
62
62
|
const t = r.getByRole("textbox");
|
|
63
63
|
e(t).toBeInTheDocument(), e(t).toBeInstanceOf(HTMLInputElement), e(t).toHaveAttribute("maxlength", "100"), e(r.getByText("address.line2")).toBeInTheDocument();
|
|
64
64
|
}), l("change value of single line text field", () => {
|
|
65
|
-
s(
|
|
66
|
-
/* @__PURE__ */ n(
|
|
67
|
-
o,
|
|
68
|
-
{
|
|
69
|
-
rules: {
|
|
70
|
-
maxLength: {
|
|
71
|
-
value: 100,
|
|
72
|
-
message: "max length is 100"
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
label: "address.line2",
|
|
76
|
-
propertyName: "addressLine2"
|
|
77
|
-
}
|
|
78
|
-
)
|
|
79
|
-
);
|
|
65
|
+
s(/* @__PURE__ */ n(o, { label: "address.line2", propertyName: "addressLine2" }));
|
|
80
66
|
const t = r.getByRole("textbox");
|
|
81
|
-
e(t).toHaveValue("test"),
|
|
67
|
+
e(t).toHaveValue("test"), i.change(t, { target: { value: "test-change" } }), e(d).toHaveBeenCalled();
|
|
82
68
|
}), l("render FormText and return text area", () => {
|
|
83
69
|
s(
|
|
84
70
|
/* @__PURE__ */ n(
|
|
@@ -103,22 +89,7 @@ u("FormText Test", () => {
|
|
|
103
89
|
const t = r.getByRole("textbox");
|
|
104
90
|
e(t).toBeInTheDocument(), e(t).toBeInstanceOf(HTMLTextAreaElement), e(t).toHaveAttribute("maxlength", "200"), e(r.getByText("address.line1")).toBeInTheDocument(), e(r.getByText("required")).toBeInTheDocument();
|
|
105
91
|
}), l("render FormText with maxLength indicator", () => {
|
|
106
|
-
s(
|
|
107
|
-
/* @__PURE__ */ n(
|
|
108
|
-
o,
|
|
109
|
-
{
|
|
110
|
-
rules: {
|
|
111
|
-
maxLength: {
|
|
112
|
-
value: 200,
|
|
113
|
-
message: "max length is 200"
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
label: "address.line1",
|
|
117
|
-
propertyName: "addressLine1",
|
|
118
|
-
textarea: !0
|
|
119
|
-
}
|
|
120
|
-
)
|
|
121
|
-
), e(r.getByText("address.line1")).toBeInTheDocument(), e(r.queryByText("required")).not.toBeInTheDocument(), e(r.getByText("0/200")).toBeInTheDocument();
|
|
92
|
+
s(/* @__PURE__ */ n(o, { maxlength: 200, label: "address.line1", propertyName: "addressLine1", textarea: !0 })), e(r.getByText("address.line1")).toBeInTheDocument(), e(r.queryByText("required")).not.toBeInTheDocument(), e(r.getByText("4/200")).toBeInTheDocument();
|
|
122
93
|
}), l("change value of text area", () => {
|
|
123
94
|
s(
|
|
124
95
|
/* @__PURE__ */ n(
|
|
@@ -128,10 +99,6 @@ u("FormText Test", () => {
|
|
|
128
99
|
required: {
|
|
129
100
|
value: !0,
|
|
130
101
|
message: "required"
|
|
131
|
-
},
|
|
132
|
-
maxLength: {
|
|
133
|
-
value: 200,
|
|
134
|
-
message: "max length is 200"
|
|
135
102
|
}
|
|
136
103
|
},
|
|
137
104
|
label: "address.line1",
|
|
@@ -141,6 +108,6 @@ u("FormText Test", () => {
|
|
|
141
108
|
)
|
|
142
109
|
);
|
|
143
110
|
const t = r.getByRole("textbox");
|
|
144
|
-
|
|
111
|
+
i.change(t, { target: { value: "test-change" } }), e(d).toHaveBeenCalled();
|
|
145
112
|
});
|
|
146
113
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hortiview/shared-components",
|
|
3
3
|
"description": "This is a shared component library. It should used in the HortiView platform and its modules.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.11747",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared",
|
|
7
7
|
"author": "Falk Menge <falk.menge.ext@bayer.com>",
|