@payfit/unity-components 2.12.2 → 2.12.3
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.
|
@@ -143,7 +143,7 @@ export interface InlineFieldGroupProps extends PropsWithChildren {
|
|
|
143
143
|
* - The component automatically exits edit mode on successful form submission
|
|
144
144
|
* - Press Escape to cancel editing and reset form values
|
|
145
145
|
* - Focus moves to the first form field when entering edit mode
|
|
146
|
-
* - Focus returns to the edit button when exiting edit mode
|
|
146
|
+
* - Focus returns to the edit button when exiting edit mode (only if focus hasn't moved elsewhere)
|
|
147
147
|
* - Focus is retained under a scope when in edit mode, to prevent users for leaving unfinished changes
|
|
148
148
|
* - Use `shouldModeChange` to intercept and conditionally prevent mode transitions
|
|
149
149
|
* - Use `successMessage` and `errorMessage` for accessible announcements via live regions
|
|
@@ -1,111 +1,114 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { forwardRef as ie, useRef as a, useState as
|
|
3
|
-
import { uyTv as
|
|
4
|
-
import { useStore as
|
|
5
|
-
import { useId as ue, useKeyboard as le, FocusScope as
|
|
6
|
-
import { useIntl as
|
|
1
|
+
import { jsx as u, jsxs as te } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as ie, useRef as a, useState as K, useEffect as o, useCallback as P, useImperativeHandle as oe, useMemo as re } from "react";
|
|
3
|
+
import { uyTv as ne } from "@payfit/unity-themes";
|
|
4
|
+
import { useStore as se } from "@tanstack/react-form";
|
|
5
|
+
import { useId as ue, useKeyboard as le, FocusScope as ce } from "react-aria";
|
|
6
|
+
import { useIntl as ae } from "react-intl";
|
|
7
7
|
import { useFormContext as me } from "../../hooks/tanstack-form-context.js";
|
|
8
8
|
import { useBreakpointListener as de } from "../../hooks/use-breakpoint-listener.js";
|
|
9
9
|
import { useInlineFieldGroupMode as fe } from "./hooks/useInlineFieldGroupMode.js";
|
|
10
10
|
import { InlineFieldGroupContext as pe } from "./InlineFieldGroup.context.js";
|
|
11
11
|
import { InlineFieldGroupActions as be } from "./parts/InlineFieldGroupActions.js";
|
|
12
|
-
const ve =
|
|
12
|
+
const ve = ne({
|
|
13
13
|
slots: {
|
|
14
14
|
form: "uy:flex uy:flex-col uy:gap-300"
|
|
15
15
|
}
|
|
16
|
-
}), $ = (
|
|
17
|
-
if (!
|
|
18
|
-
const
|
|
16
|
+
}), $ = (m) => {
|
|
17
|
+
if (!m.current) return;
|
|
18
|
+
const d = m.current.querySelector(
|
|
19
19
|
'[aria-invalid="true"]'
|
|
20
20
|
);
|
|
21
|
-
|
|
22
|
-
}, H = 5e3,
|
|
21
|
+
d && d.focus();
|
|
22
|
+
}, H = 5e3, ye = ie(
|
|
23
23
|
({
|
|
24
|
-
children:
|
|
25
|
-
mode:
|
|
24
|
+
children: m,
|
|
25
|
+
mode: d,
|
|
26
26
|
defaultMode: U,
|
|
27
|
-
onModeChange:
|
|
28
|
-
shouldModeChange:
|
|
27
|
+
onModeChange: W,
|
|
28
|
+
shouldModeChange: f,
|
|
29
29
|
isLoading: w,
|
|
30
|
-
className:
|
|
30
|
+
className: z,
|
|
31
31
|
"aria-label": M,
|
|
32
|
-
containFocus:
|
|
33
|
-
successMessage:
|
|
34
|
-
errorMessage:
|
|
32
|
+
containFocus: J = !1,
|
|
33
|
+
successMessage: E,
|
|
34
|
+
errorMessage: p,
|
|
35
35
|
editLabel: _,
|
|
36
36
|
saveLabel: T,
|
|
37
37
|
cancelLabel: V,
|
|
38
38
|
onEditPress: k,
|
|
39
39
|
onSavePress: C,
|
|
40
40
|
onCancelPress: D
|
|
41
|
-
},
|
|
42
|
-
const
|
|
43
|
-
mode:
|
|
41
|
+
}, Q) => {
|
|
42
|
+
const l = ue(), g = `unity-InlineFieldGroup-${l}__header`, q = `unity-InlineFieldGroup-${l}__edit-view`, b = a(null), r = a(null), B = a(!0), [G, h] = K(""), [R, v] = K(""), y = ae(), c = me(), O = de(), X = O === "xs" || O === "sm", { mode: t, enterEditMode: S, exitEditMode: n } = fe({
|
|
43
|
+
mode: d,
|
|
44
44
|
defaultMode: U,
|
|
45
|
-
onModeChange:
|
|
46
|
-
shouldModeChange:
|
|
47
|
-
}), { isSubmitting: i, isValid:
|
|
45
|
+
onModeChange: W,
|
|
46
|
+
shouldModeChange: f
|
|
47
|
+
}), { isSubmitting: i, isValid: I, isSubmitSuccessful: F, submissionAttempts: x } = se(c.store, (e) => ({
|
|
48
48
|
isSubmitting: e.isSubmitting,
|
|
49
49
|
isValid: e.isValid,
|
|
50
50
|
isSubmitSuccessful: e.isSubmitSuccessful,
|
|
51
51
|
submissionAttempts: e.submissionAttempts
|
|
52
|
-
})),
|
|
53
|
-
|
|
54
|
-
i && !
|
|
55
|
-
}, [i]),
|
|
56
|
-
if (
|
|
57
|
-
const
|
|
52
|
+
})), A = a(i), j = a(x);
|
|
53
|
+
o(() => {
|
|
54
|
+
i && !A.current && (h(""), v(""));
|
|
55
|
+
}, [i]), o(() => {
|
|
56
|
+
if (x > j.current && !I) {
|
|
57
|
+
const s = p ?? y.formatMessage({
|
|
58
58
|
id: "unity:component:inline-field-group:validation-error",
|
|
59
59
|
defaultMessage: "Please fix the errors before saving."
|
|
60
60
|
});
|
|
61
|
-
|
|
61
|
+
v(s), $(r);
|
|
62
62
|
}
|
|
63
|
-
}, [
|
|
64
|
-
|
|
65
|
-
}, [i, F,
|
|
66
|
-
if (
|
|
67
|
-
const
|
|
63
|
+
}, [x, I, p, y]), o(() => {
|
|
64
|
+
A.current && !i && F && (E && h(E), n());
|
|
65
|
+
}, [i, F, E, n]), o(() => {
|
|
66
|
+
if (A.current && !i && !F && I) {
|
|
67
|
+
const s = p ?? y.formatMessage({
|
|
68
68
|
id: "unity:component:inline-field-group:save-error",
|
|
69
69
|
defaultMessage: "An error occurred while saving. Please try again."
|
|
70
70
|
});
|
|
71
|
-
|
|
71
|
+
v(s);
|
|
72
72
|
}
|
|
73
|
-
}, [i, F,
|
|
74
|
-
|
|
73
|
+
}, [i, F, I, p, y]), o(() => {
|
|
74
|
+
A.current = i, j.current = x;
|
|
75
75
|
});
|
|
76
76
|
const Y = P(
|
|
77
77
|
(e) => {
|
|
78
|
-
e.preventDefault(), e.stopPropagation(),
|
|
78
|
+
e.preventDefault(), e.stopPropagation(), c.handleSubmit();
|
|
79
79
|
},
|
|
80
|
-
[
|
|
80
|
+
[c]
|
|
81
81
|
), N = P(() => {
|
|
82
|
-
|
|
83
|
-
}, [
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
f !== void 0 && !f(t, "read") || (c.reset(), n());
|
|
83
|
+
}, [c, t, n, f]);
|
|
84
|
+
oe(
|
|
85
|
+
Q,
|
|
86
86
|
() => ({
|
|
87
87
|
focusFirstInvalidField: () => {
|
|
88
|
-
$(
|
|
88
|
+
$(r);
|
|
89
89
|
},
|
|
90
|
-
exitEditMode:
|
|
90
|
+
exitEditMode: n,
|
|
91
91
|
enterEditMode: S
|
|
92
92
|
}),
|
|
93
|
-
[
|
|
94
|
-
),
|
|
95
|
-
if (
|
|
96
|
-
|
|
93
|
+
[n, S]
|
|
94
|
+
), o(() => {
|
|
95
|
+
if (B.current) {
|
|
96
|
+
B.current = !1;
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
if (t === "edit") {
|
|
100
|
-
if (
|
|
101
|
-
const e =
|
|
100
|
+
if (r.current) {
|
|
101
|
+
const e = r.current.querySelectorAll(
|
|
102
102
|
'input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
103
103
|
);
|
|
104
104
|
e.length > 0 && e[0].focus();
|
|
105
105
|
}
|
|
106
106
|
} else
|
|
107
107
|
requestAnimationFrame(() => {
|
|
108
|
-
|
|
108
|
+
const e = r.current?.contains(
|
|
109
|
+
document.activeElement
|
|
110
|
+
), s = document.activeElement === document.body;
|
|
111
|
+
(e || s) && b.current && b.current.focus();
|
|
109
112
|
});
|
|
110
113
|
}, [t]);
|
|
111
114
|
const { keyboardProps: Z } = le({
|
|
@@ -113,36 +116,36 @@ const ve = se({
|
|
|
113
116
|
e.key === "Escape" && t === "edit" && (e.preventDefault(), N());
|
|
114
117
|
}
|
|
115
118
|
});
|
|
116
|
-
|
|
119
|
+
o(() => {
|
|
117
120
|
if (G) {
|
|
118
121
|
const e = setTimeout(() => {
|
|
119
|
-
|
|
122
|
+
h("");
|
|
120
123
|
}, H);
|
|
121
124
|
return () => {
|
|
122
125
|
clearTimeout(e);
|
|
123
126
|
};
|
|
124
127
|
}
|
|
125
|
-
}, [G]),
|
|
126
|
-
if (
|
|
128
|
+
}, [G]), o(() => {
|
|
129
|
+
if (R) {
|
|
127
130
|
const e = setTimeout(() => {
|
|
128
|
-
|
|
131
|
+
v("");
|
|
129
132
|
}, H);
|
|
130
133
|
return () => {
|
|
131
134
|
clearTimeout(e);
|
|
132
135
|
};
|
|
133
136
|
}
|
|
134
|
-
}, [
|
|
135
|
-
const L =
|
|
137
|
+
}, [R]);
|
|
138
|
+
const L = re(
|
|
136
139
|
() => ({
|
|
137
140
|
mode: t,
|
|
138
141
|
enterEditMode: S,
|
|
139
142
|
exitEditMode: N,
|
|
140
|
-
groupId:
|
|
141
|
-
headerId:
|
|
143
|
+
groupId: l,
|
|
144
|
+
headerId: g,
|
|
142
145
|
editViewId: q,
|
|
143
146
|
isLoading: w,
|
|
144
|
-
editButtonRef:
|
|
145
|
-
editViewRef:
|
|
147
|
+
editButtonRef: b,
|
|
148
|
+
editViewRef: r,
|
|
146
149
|
editLabel: _,
|
|
147
150
|
saveLabel: T,
|
|
148
151
|
cancelLabel: V,
|
|
@@ -154,12 +157,12 @@ const ve = se({
|
|
|
154
157
|
t,
|
|
155
158
|
S,
|
|
156
159
|
N,
|
|
157
|
-
|
|
158
|
-
|
|
160
|
+
l,
|
|
161
|
+
g,
|
|
159
162
|
q,
|
|
160
163
|
w,
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
b,
|
|
165
|
+
r,
|
|
163
166
|
_,
|
|
164
167
|
T,
|
|
165
168
|
V,
|
|
@@ -168,19 +171,19 @@ const ve = se({
|
|
|
168
171
|
D
|
|
169
172
|
]
|
|
170
173
|
), { form: ee } = ve();
|
|
171
|
-
return /* @__PURE__ */
|
|
174
|
+
return /* @__PURE__ */ u(pe.Provider, { value: L, children: /* @__PURE__ */ u(
|
|
172
175
|
"form",
|
|
173
176
|
{
|
|
174
177
|
...Z,
|
|
175
|
-
id:
|
|
176
|
-
className: ee({ className:
|
|
178
|
+
id: l,
|
|
179
|
+
className: ee({ className: z }),
|
|
177
180
|
onSubmit: Y,
|
|
178
181
|
"aria-label": M,
|
|
179
|
-
"aria-labelledby": M ? void 0 :
|
|
180
|
-
children: /* @__PURE__ */ te(
|
|
181
|
-
|
|
182
|
-
X && /* @__PURE__ */
|
|
183
|
-
/* @__PURE__ */
|
|
182
|
+
"aria-labelledby": M ? void 0 : g,
|
|
183
|
+
children: /* @__PURE__ */ te(ce, { contain: J && t === "edit", children: [
|
|
184
|
+
m,
|
|
185
|
+
X && /* @__PURE__ */ u("div", { className: "uy:flex", children: /* @__PURE__ */ u(be, { orientation: "vertical" }) }),
|
|
186
|
+
/* @__PURE__ */ u(
|
|
184
187
|
"div",
|
|
185
188
|
{
|
|
186
189
|
role: "status",
|
|
@@ -190,14 +193,14 @@ const ve = se({
|
|
|
190
193
|
children: G
|
|
191
194
|
}
|
|
192
195
|
),
|
|
193
|
-
/* @__PURE__ */
|
|
196
|
+
/* @__PURE__ */ u(
|
|
194
197
|
"div",
|
|
195
198
|
{
|
|
196
199
|
role: "alert",
|
|
197
200
|
"aria-live": "assertive",
|
|
198
201
|
"aria-atomic": "true",
|
|
199
202
|
className: "uy:sr-only",
|
|
200
|
-
children:
|
|
203
|
+
children: R
|
|
201
204
|
}
|
|
202
205
|
)
|
|
203
206
|
] })
|
|
@@ -205,7 +208,7 @@ const ve = se({
|
|
|
205
208
|
) });
|
|
206
209
|
}
|
|
207
210
|
);
|
|
208
|
-
|
|
211
|
+
ye.displayName = "InlineFieldGroup";
|
|
209
212
|
export {
|
|
210
|
-
|
|
213
|
+
ye as InlineFieldGroup
|
|
211
214
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payfit/unity-components",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.3",
|
|
4
4
|
"module": "./dist/esm/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@hookform/devtools": "4.4.0",
|
|
43
43
|
"@hookform/resolvers": "5.2.1",
|
|
44
44
|
"@internationalized/date": "3.11.0",
|
|
45
|
-
"@payfit/unity-illustrations": "2.12.
|
|
45
|
+
"@payfit/unity-illustrations": "2.12.3",
|
|
46
46
|
"@radix-ui/react-avatar": "1.1.11",
|
|
47
47
|
"@radix-ui/react-slot": "1.2.4",
|
|
48
48
|
"@react-aria/interactions": "3.27.0",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"@hookform/devtools": "^4",
|
|
77
|
-
"@payfit/unity-icons": "2.12.
|
|
78
|
-
"@payfit/unity-themes": "2.12.
|
|
77
|
+
"@payfit/unity-icons": "2.12.3",
|
|
78
|
+
"@payfit/unity-themes": "2.12.3",
|
|
79
79
|
"@storybook/react-vite": "^10.2.2",
|
|
80
80
|
"@tanstack/react-query": "^5",
|
|
81
81
|
"@tanstack/react-router": "^1.131",
|
|
@@ -94,9 +94,9 @@
|
|
|
94
94
|
"@payfit/hr-apps-tsconfigs": "0.0.0-use.local",
|
|
95
95
|
"@payfit/storybook-addon-console-errors": "0.0.0-use.local",
|
|
96
96
|
"@payfit/storybook-config": "0.0.0-use.local",
|
|
97
|
-
"@payfit/unity-icons": "2.12.
|
|
98
|
-
"@payfit/unity-illustrations": "2.12.
|
|
99
|
-
"@payfit/unity-themes": "2.12.
|
|
97
|
+
"@payfit/unity-icons": "2.12.3",
|
|
98
|
+
"@payfit/unity-illustrations": "2.12.3",
|
|
99
|
+
"@payfit/unity-themes": "2.12.3",
|
|
100
100
|
"@payfit/vite-configs": "0.0.0-use.local",
|
|
101
101
|
"@storybook/addon-a11y": "10.2.13",
|
|
102
102
|
"@storybook/addon-docs": "10.2.13",
|