@payfit/unity-components 2.12.1 → 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.
@@ -34,7 +34,7 @@ function x({
34
34
  m(t.target.value), p(s(t.target.value));
35
35
  },
36
36
  disabled: i,
37
- className: "uy:appearance-none uy:box-border uy:w-[var(--uy-selected-item-width)] uy:bg-transparent uy:border-none uy:rounded-50 uy:capitalize uy:text-content-form-enabled uy:typography-action-large uy:cursor-pointer uy:pr-300 uy:disabled:text-content-form-disabled uy:data-[focus-visible='true']:outline-2 uy:data-[focus-visible='true']:outline-offset-2 uy:data-[focus-visible='true']:outline-utility-focus-ring [-webkit-tap-highlight-color:transparent] [background-color:transparent]",
37
+ className: "uy:appearance-none uy:box-border uy:w-[var(--uy-selected-item-width)] uy:bg-transparent uy:border-none uy:rounded-50 uy:capitalize uy:text-content-form-enabled uy:typography-action-large uy:cursor-pointer uy:pr-300 uy:disabled:text-content-form-disabled uy:data-[focus-visible='true']:outline-2 uy:data-[focus-visible='true']:outline-offset-2 uy:data-[focus-visible='true']:outline-utility-focus-ring [background-color:transparent] [-webkit-tap-highlight-color:transparent]",
38
38
  style: {
39
39
  "--uy-selected-item-width": `calc(var(--uy-spacing-300) + ${y.length}ch)`
40
40
  },
@@ -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 n, jsxs as te } from "react/jsx-runtime";
2
- import { forwardRef as ie, useRef as a, useState as O, useEffect as r, useCallback as P, useImperativeHandle as re, useMemo as oe } from "react";
3
- import { uyTv as se } from "@payfit/unity-themes";
4
- import { useStore as ne } from "@tanstack/react-form";
5
- import { useId as ue, useKeyboard as le, FocusScope as ae } from "react-aria";
6
- import { useIntl as ce } from "react-intl";
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 = se({
12
+ const ve = ne({
13
13
  slots: {
14
14
  form: "uy:flex uy:flex-col uy:gap-300"
15
15
  }
16
- }), $ = (c) => {
17
- if (!c.current) return;
18
- const m = c.current.querySelector(
16
+ }), $ = (m) => {
17
+ if (!m.current) return;
18
+ const d = m.current.querySelector(
19
19
  '[aria-invalid="true"]'
20
20
  );
21
- m && m.focus();
22
- }, H = 5e3, Se = ie(
21
+ d && d.focus();
22
+ }, H = 5e3, ye = ie(
23
23
  ({
24
- children: c,
25
- mode: m,
24
+ children: m,
25
+ mode: d,
26
26
  defaultMode: U,
27
- onModeChange: z,
28
- shouldModeChange: d,
27
+ onModeChange: W,
28
+ shouldModeChange: f,
29
29
  isLoading: w,
30
- className: J,
30
+ className: z,
31
31
  "aria-label": M,
32
- containFocus: Q = !1,
33
- successMessage: g,
34
- errorMessage: f,
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
- }, W) => {
42
- const u = ue(), E = `unity-InlineFieldGroup-${u}__header`, q = `unity-InlineFieldGroup-${u}__edit-view`, p = a(null), o = a(null), j = a(!0), [G, R] = O(""), [h, b] = O(""), v = ce(), l = me(), B = de(), X = B === "xs" || B === "sm", { mode: t, enterEditMode: S, exitEditMode: s } = fe({
43
- mode: m,
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: z,
46
- shouldModeChange: d
47
- }), { isSubmitting: i, isValid: y, isSubmitSuccessful: F, submissionAttempts: I } = ne(l.store, (e) => ({
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
- })), x = a(i), K = a(I);
53
- r(() => {
54
- i && !x.current && (R(""), b(""));
55
- }, [i]), r(() => {
56
- if (I > K.current && !y) {
57
- const A = f ?? v.formatMessage({
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
- b(A), $(o);
61
+ v(s), $(r);
62
62
  }
63
- }, [I, y, f, v]), r(() => {
64
- x.current && !i && F && (g && R(g), s());
65
- }, [i, F, g, s]), r(() => {
66
- if (x.current && !i && !F && y) {
67
- const A = f ?? v.formatMessage({
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
- b(A);
71
+ v(s);
72
72
  }
73
- }, [i, F, y, f, v]), r(() => {
74
- x.current = i, K.current = I;
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(), l.handleSubmit();
78
+ e.preventDefault(), e.stopPropagation(), c.handleSubmit();
79
79
  },
80
- [l]
80
+ [c]
81
81
  ), N = P(() => {
82
- d !== void 0 && !d(t, "read") || (l.reset(), s());
83
- }, [l, t, s, d]);
84
- re(
85
- W,
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
- $(o);
88
+ $(r);
89
89
  },
90
- exitEditMode: s,
90
+ exitEditMode: n,
91
91
  enterEditMode: S
92
92
  }),
93
- [s, S]
94
- ), r(() => {
95
- if (j.current) {
96
- j.current = !1;
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 (o.current) {
101
- const e = o.current.querySelectorAll(
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
- p.current && p.current.focus();
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
- r(() => {
119
+ o(() => {
117
120
  if (G) {
118
121
  const e = setTimeout(() => {
119
- R("");
122
+ h("");
120
123
  }, H);
121
124
  return () => {
122
125
  clearTimeout(e);
123
126
  };
124
127
  }
125
- }, [G]), r(() => {
126
- if (h) {
128
+ }, [G]), o(() => {
129
+ if (R) {
127
130
  const e = setTimeout(() => {
128
- b("");
131
+ v("");
129
132
  }, H);
130
133
  return () => {
131
134
  clearTimeout(e);
132
135
  };
133
136
  }
134
- }, [h]);
135
- const L = oe(
137
+ }, [R]);
138
+ const L = re(
136
139
  () => ({
137
140
  mode: t,
138
141
  enterEditMode: S,
139
142
  exitEditMode: N,
140
- groupId: u,
141
- headerId: E,
143
+ groupId: l,
144
+ headerId: g,
142
145
  editViewId: q,
143
146
  isLoading: w,
144
- editButtonRef: p,
145
- editViewRef: o,
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
- u,
158
- E,
160
+ l,
161
+ g,
159
162
  q,
160
163
  w,
161
- p,
162
- o,
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__ */ n(pe.Provider, { value: L, children: /* @__PURE__ */ n(
174
+ return /* @__PURE__ */ u(pe.Provider, { value: L, children: /* @__PURE__ */ u(
172
175
  "form",
173
176
  {
174
177
  ...Z,
175
- id: u,
176
- className: ee({ className: J }),
178
+ id: l,
179
+ className: ee({ className: z }),
177
180
  onSubmit: Y,
178
181
  "aria-label": M,
179
- "aria-labelledby": M ? void 0 : E,
180
- children: /* @__PURE__ */ te(ae, { contain: Q && t === "edit", children: [
181
- c,
182
- X && /* @__PURE__ */ n("div", { className: "uy:flex", children: /* @__PURE__ */ n(be, { orientation: "vertical" }) }),
183
- /* @__PURE__ */ n(
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__ */ n(
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: h
203
+ children: R
201
204
  }
202
205
  )
203
206
  ] })
@@ -205,7 +208,7 @@ const ve = se({
205
208
  ) });
206
209
  }
207
210
  );
208
- Se.displayName = "InlineFieldGroup";
211
+ ye.displayName = "InlineFieldGroup";
209
212
  export {
210
- Se as InlineFieldGroup
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.1",
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.1",
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.1",
78
- "@payfit/unity-themes": "2.12.1",
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.1",
98
- "@payfit/unity-illustrations": "2.12.1",
99
- "@payfit/unity-themes": "2.12.1",
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",