@nice2dev/ui 1.4.17 → 1.4.19

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.
@@ -1,208 +1,111 @@
1
- import { jsxs as f, jsx as h } from "react/jsx-runtime";
2
- import { useNiceTranslation as Q, useControllableState as U, useRovingFocus as j, NiceIcon as Z, themePreviewRoles as ee } from "@nice2dev/ui-core";
3
- import q, { useState as S, useRef as V } from "react";
4
- import { NiceModal as te } from "../feedback/NiceModal.mjs";
5
- import { NICE_THEME_CATALOG_ENTRIES as ae, NICE_THEME_CATALOG as re } from "./themeCatalog.mjs";
1
+ import { jsxs as u, jsx as r } from "react/jsx-runtime";
2
+ import { useNiceTranslation as K, useControllableState as Q, useRovingFocus as B, NiceIcon as U, themePreviewRoles as Z } from "@nice2dev/ui-core";
3
+ import { useState as N, useRef as j } from "react";
4
+ import { NiceModal as ee } from "../feedback/NiceModal.mjs";
5
+ import { NICE_THEME_CATALOG_ENTRIES as ae, NICE_THEME_CATALOG as te } from "./themeCatalog.mjs";
6
6
  /* empty css */
7
- const T = (e, y) => ({
8
- backgroundColor: e,
9
- backgroundImage: y
10
- }), ne = ({ roles: e, width: y = 240, label: v }) => {
11
- const d = y, i = Math.round(d * 0.62), n = Math.round(i * 0.13), s = Math.round(d * 0.24), r = Math.max(4, Math.round(d * 0.035)), a = Math.max(2, Math.round(i * 0.035)), p = Math.round((i - n) * 0.1), u = s + r, M = d - u - r, o = (l) => /* @__PURE__ */ h("span", { style: { position: "absolute", ...l } }), w = n + r * 2 + a * 2, x = Math.round(i * 0.2), _ = Math.round((M - r) / 2), c = w + x + r, k = i - c - r * 2 - a * 3, C = [0.45, 0.7, 0.55, 0.9, 0.65, 0.8], N = Math.round((M - r * 2) / (C.length * 1.6)), R = i - r - a * 3;
12
- return /* @__PURE__ */ f(
7
+ const w = (a, s) => ({
8
+ backgroundColor: a,
9
+ backgroundImage: s
10
+ }), le = ({ roles: a, width: s = 240, label: _ }) => {
11
+ const c = s, g = Math.round(c * 0.62), n = Math.round(g * 0.18), h = Math.round(c * 0.26), t = Math.max(5, Math.round(c * 0.05)), l = Math.max(3, Math.round(g * 0.07)), p = h + t, y = n + t, b = c - p - t, v = g - y - t, C = Math.max(2, Math.round(c * 0.02)), d = (k) => /* @__PURE__ */ r("span", { style: { position: "absolute", ...k } });
12
+ return /* @__PURE__ */ u(
13
13
  "span",
14
14
  {
15
15
  className: "nice-theme-gallery__preview",
16
16
  role: "img",
17
- "aria-label": v,
17
+ "aria-label": _,
18
18
  style: {
19
- width: d,
20
- height: i,
21
- ...T(e.body, e.bodyImage),
22
- borderColor: e.panelBorder
19
+ width: c,
20
+ height: g,
21
+ ...w(a.body, a.bodyImage),
22
+ borderColor: a.panelBorder
23
23
  },
24
24
  children: [
25
- o({ top: 0, left: 0, right: 0, height: n, ...T(e.topNav, e.topNavImage) }),
26
- o({
27
- top: Math.round(n * 0.28),
28
- left: r,
29
- width: Math.round(n * 0.44),
30
- height: Math.round(n * 0.44),
31
- borderRadius: "30%",
32
- background: e.primary
33
- }),
34
- o({
35
- top: Math.round(n * 0.42),
36
- left: r + n,
37
- width: Math.round(d * 0.2),
38
- height: a,
39
- borderRadius: a,
40
- background: e.topNavText,
41
- opacity: 0.85
42
- }),
43
- o({
44
- top: Math.round(n * 0.22),
45
- right: r,
46
- width: Math.round(n * 0.56),
47
- height: Math.round(n * 0.56),
48
- borderRadius: "50%",
49
- background: e.accent
50
- }),
51
- o({
25
+ d({ top: 0, left: 0, right: 0, height: n, ...w(a.topNav, a.topNavImage) }),
26
+ d({
52
27
  top: n,
53
28
  bottom: 0,
54
29
  left: 0,
55
- width: s,
56
- ...T(e.sideNav, e.sideNavImage)
30
+ width: h,
31
+ ...w(a.sideNav, a.sideNavImage)
57
32
  }),
58
- e.headers.map((l, m) => /* @__PURE__ */ f(q.Fragment, { children: [
59
- o({ top: n + m * p, left: 0, width: s, height: p, background: l }),
60
- o({
61
- top: n + m * p + Math.round((p - a) / 2),
62
- left: r,
63
- width: Math.round(s * (0.6 - m * 0.1)),
64
- height: a,
65
- borderRadius: a,
66
- background: e.headerTexts[m] ?? e.sideNavText,
67
- opacity: 0.8
68
- })
69
- ] }, m)),
70
- o({
71
- top: n + e.headers.length * p + Math.round(p * 0.3),
33
+ d({
34
+ top: n + t,
72
35
  left: 0,
73
- width: s,
74
- height: p,
75
- background: e.highlight
36
+ width: h,
37
+ height: l * 2,
38
+ background: a.highlight
76
39
  }),
77
- [0, 1, 2].map(
78
- (l) => o({
79
- top: n + (e.headers.length + 1.6 + l) * p + Math.round((p - a) / 2),
80
- left: r,
81
- width: Math.round(s * (0.55 - l * 0.08)),
82
- height: a,
83
- borderRadius: a,
84
- background: e.sideNavText,
85
- opacity: 0.55
86
- })
87
- ),
88
- o({
89
- top: n + r,
90
- left: u,
91
- width: Math.round(M * 0.45),
92
- height: a * 1.6,
93
- borderRadius: a,
94
- background: e.text,
95
- opacity: 0.9
40
+ d({
41
+ top: y,
42
+ left: p,
43
+ width: b,
44
+ height: v,
45
+ ...w(a.panel, a.panelImage),
46
+ border: `1px solid ${a.panelBorder}`,
47
+ borderRadius: C
96
48
  }),
97
- [0, 1].map((l) => /* @__PURE__ */ f(q.Fragment, { children: [
98
- o({
99
- top: w,
100
- left: u + l * (_ + r),
101
- width: _,
102
- height: x,
103
- ...T(e.panel, e.panelImage),
104
- border: `1px solid ${e.panelBorder}`,
105
- borderRadius: Math.max(2, Math.round(d * 0.012))
106
- }),
107
- o({
108
- top: w + Math.round(x * 0.22),
109
- left: u + l * (_ + r) + r,
110
- width: Math.round(_ * 0.45),
111
- height: a,
112
- borderRadius: a,
113
- background: e.text,
114
- opacity: 0.5
115
- }),
116
- o({
117
- top: w + Math.round(x * 0.55),
118
- left: u + l * (_ + r) + r,
119
- width: Math.round(_ * 0.6),
120
- height: a * 2,
121
- borderRadius: a,
122
- background: l === 0 ? e.primary : e.accent
123
- })
124
- ] }, l)),
125
- o({
126
- top: c,
127
- left: u,
128
- width: M,
129
- height: k,
130
- ...T(e.panel, e.panelImage),
131
- border: `1px solid ${e.panelBorder}`,
132
- borderRadius: Math.max(2, Math.round(d * 0.012))
133
- }),
134
- C.map(
135
- (l, m) => o({
136
- bottom: i - c - k + r,
137
- left: u + r + Math.round(m * N * 1.6),
138
- width: N,
139
- height: Math.round((k - r * 2) * l),
140
- borderRadius: `${Math.max(1, Math.round(N * 0.25))}px ${Math.max(1, Math.round(N * 0.25))}px 0 0`,
141
- background: m % 3 === 2 ? e.accent : e.primary,
142
- opacity: m % 3 === 1 ? 0.65 : 1
143
- })
144
- ),
145
- o({
146
- top: R,
147
- left: u,
148
- width: Math.round(M * 0.3),
149
- height: a * 3,
150
- borderRadius: a * 1.5,
151
- background: e.primary
49
+ d({
50
+ top: y + t,
51
+ left: p + t,
52
+ width: Math.round((b - t * 2) * 0.7),
53
+ height: l,
54
+ borderRadius: l,
55
+ background: a.text,
56
+ opacity: 0.85
152
57
  }),
153
- o({
154
- top: R,
155
- left: u + Math.round(M * 0.3) + r,
156
- width: Math.round(M * 0.3),
157
- height: a * 3,
158
- borderRadius: a * 1.5,
159
- border: `1px solid ${e.primary}`,
160
- boxSizing: "border-box"
58
+ d({
59
+ bottom: t * 2,
60
+ left: p + t,
61
+ width: Math.round((b - t * 2) * 0.42),
62
+ height: l * 2,
63
+ borderRadius: l,
64
+ background: a.primary
161
65
  }),
162
- o({
163
- top: R + Math.round(a * 0.5),
164
- right: r,
165
- width: Math.round(M * 0.18),
166
- height: a * 2,
167
- borderRadius: a,
168
- background: e.accent,
169
- opacity: 0.85
66
+ d({
67
+ bottom: t * 2 + Math.round(l / 2),
68
+ right: t * 2,
69
+ width: Math.round((b - t * 2) * 0.24),
70
+ height: l,
71
+ borderRadius: l,
72
+ background: a.accent
170
73
  })
171
74
  ]
172
75
  }
173
76
  );
174
- }, oe = /* @__PURE__ */ re.map(
175
- ({ id: e, label: y }) => ({ id: e, label: y })
77
+ }, re = /* @__PURE__ */ te.map(
78
+ ({ id: a, label: s }) => ({ id: a, label: s })
176
79
  );
177
- function le({
178
- item: e,
179
- selected: y,
180
- width: v,
181
- categoryLabel: d,
182
- previewLabel: i,
80
+ function ne({
81
+ item: a,
82
+ selected: s,
83
+ width: _,
84
+ categoryLabel: c,
85
+ previewLabel: g,
183
86
  extra: n,
184
- className: s,
185
- onPick: r
87
+ className: h,
88
+ onPick: t
186
89
  }) {
187
- const a = ee(e.theme);
188
- return /* @__PURE__ */ f(
90
+ const l = Z(a.theme);
91
+ return /* @__PURE__ */ u(
189
92
  "button",
190
93
  {
191
94
  type: "button",
192
- "aria-pressed": y,
193
- className: `nice-theme-gallery__card${s ? ` ${s}` : ""}`,
95
+ "aria-pressed": s,
96
+ className: `nice-theme-gallery__card${h ? ` ${h}` : ""}`,
194
97
  style: {
195
- "--nice-tgp-accent": a.primary,
196
- "--nice-tgp-surface": a.panel,
197
- "--nice-tgp-text": a.text
98
+ "--nice-tgp-accent": l.primary,
99
+ "--nice-tgp-surface": l.panel,
100
+ "--nice-tgp-text": l.text
198
101
  },
199
- title: e.name,
200
- onClick: r,
102
+ title: a.name,
103
+ onClick: t,
201
104
  children: [
202
- /* @__PURE__ */ h(ne, { roles: a, width: v, label: i }),
203
- /* @__PURE__ */ f("span", { className: "nice-theme-gallery__footer", children: [
204
- /* @__PURE__ */ h("span", { className: "nice-theme-gallery__name", children: e.name }),
205
- d && /* @__PURE__ */ h("span", { className: "nice-theme-gallery__meta", children: d })
105
+ /* @__PURE__ */ r(le, { roles: l, width: _, label: g }),
106
+ /* @__PURE__ */ u("span", { className: "nice-theme-gallery__footer", children: [
107
+ /* @__PURE__ */ r("span", { className: "nice-theme-gallery__name", children: a.name }),
108
+ c && /* @__PURE__ */ r("span", { className: "nice-theme-gallery__meta", children: c })
206
109
  ] }),
207
110
  n
208
111
  ]
@@ -210,145 +113,145 @@ function le({
210
113
  );
211
114
  }
212
115
  const me = ({
213
- themes: e = ae,
214
- categories: y = oe,
215
- value: v,
216
- defaultValue: d,
217
- onChange: i,
116
+ themes: a = ae,
117
+ categories: s = re,
118
+ value: _,
119
+ defaultValue: c,
120
+ onChange: g,
218
121
  limit: n,
219
- previewWidth: s = 240,
220
- searchable: r = !1,
221
- renderCardExtra: a,
122
+ previewWidth: h = 240,
123
+ searchable: t = !1,
124
+ renderCardExtra: l,
222
125
  cardClassName: p,
223
- className: u,
224
- style: M,
225
- id: o,
226
- title: w,
227
- label: x,
228
- "data-testid": _
126
+ className: y,
127
+ style: b,
128
+ id: v,
129
+ title: C,
130
+ label: d,
131
+ "data-testid": k
229
132
  }) => {
230
- const { t: c } = Q(), [k, C] = U({
231
- value: v,
232
- defaultValue: d,
133
+ const { t: m } = K(), [x, W] = Q({
134
+ value: _,
135
+ defaultValue: c,
233
136
  fallbackValue: null,
234
137
  componentName: "NiceThemeGalleryPicker"
235
- }), [N, R] = S(""), [l, m] = S(!1), [A, X] = S(""), [$, D] = S(""), L = V(null), F = V(null);
236
- j(L, {
138
+ }), [S, q] = N(""), [V, R] = N(!1), [E, X] = N(""), [M, Y] = N(""), I = j(null), A = j(null);
139
+ B(I, {
237
140
  orientation: n ? "horizontal" : "grid",
238
141
  itemSelector: ".nice-theme-gallery__card"
239
- }), j(F, { orientation: "grid", itemSelector: ".nice-theme-gallery__card" });
240
- const G = x ?? c("themeGallery.title", "Theme gallery"), J = c("pickerCommons.themePreview", "Theme preview"), I = (t) => {
241
- if (!t)
142
+ }), B(A, { orientation: "grid", itemSelector: ".nice-theme-gallery__card" });
143
+ const f = d ?? m("themeGallery.title", "Theme gallery"), D = m("pickerCommons.themePreview", "Theme preview"), T = (e) => {
144
+ if (!e)
242
145
  return;
243
- const g = y.find((b) => b.id === t);
244
- return c(`theme.category.${t}`, g?.label ?? t);
245
- }, P = (t, g) => {
246
- const b = g.trim().toLowerCase();
247
- return !b || t.name.toLowerCase().includes(b) || (I(t.category) ?? "").toLowerCase().includes(b);
248
- }, H = (() => {
249
- const t = e.filter((E) => P(E, N));
250
- if (!n || t.length <= n)
251
- return t;
252
- const g = t.slice(0, n), b = t.find((E) => E.name === k);
253
- return b && !g.includes(b) && (g[g.length - 1] = b), g;
254
- })(), O = y.filter((t) => e.some((g) => g.category === t.id)), z = e.filter(
255
- (t) => (!$ || t.category === $) && P(t, A)
256
- ), K = (t) => {
257
- C(t.name), i?.(t.name, t);
258
- }, B = (t) => /* @__PURE__ */ h(
259
- le,
146
+ const o = s.find((i) => i.id === e);
147
+ return m(`theme.category.${e}`, o?.label ?? e);
148
+ }, L = (e, o) => {
149
+ const i = o.trim().toLowerCase();
150
+ return !i || e.name.toLowerCase().includes(i) || (T(e.category) ?? "").toLowerCase().includes(i);
151
+ }, $ = (() => {
152
+ const e = a.filter((G) => L(G, S));
153
+ if (!n || e.length <= n)
154
+ return e;
155
+ const o = e.slice(0, n), i = e.find((G) => G.name === x);
156
+ return i && !o.includes(i) && (o[o.length - 1] = i), o;
157
+ })(), P = s.filter((e) => a.some((o) => o.category === e.id)), O = a.filter(
158
+ (e) => (!M || e.category === M) && L(e, E)
159
+ ), J = (e) => {
160
+ W(e.name), g?.(e.name, e);
161
+ }, F = (e) => /* @__PURE__ */ r(
162
+ ne,
260
163
  {
261
- item: t,
262
- selected: t.name === k,
263
- width: s,
264
- categoryLabel: I(t.category),
265
- previewLabel: J,
266
- extra: a?.(t),
267
- className: p?.(t),
268
- onPick: () => K(t)
164
+ item: e,
165
+ selected: e.name === x,
166
+ width: h,
167
+ categoryLabel: T(e.category),
168
+ previewLabel: D,
169
+ extra: l?.(e),
170
+ className: p?.(e),
171
+ onPick: () => J(e)
269
172
  },
270
- t.name
271
- ), W = (t, g) => /* @__PURE__ */ h(
173
+ e.name
174
+ ), H = (e, o) => /* @__PURE__ */ r(
272
175
  "input",
273
176
  {
274
177
  type: "search",
275
178
  className: "nice-input nice-theme-gallery__search",
276
- value: t,
277
- onChange: (b) => g(b.target.value),
278
- placeholder: c("themeGallery.search", "Search themes…"),
279
- "aria-label": c("themeGallery.search", "Search themes…")
179
+ value: e,
180
+ onChange: (i) => o(i.target.value),
181
+ placeholder: m("themeGallery.search", "Search themes…"),
182
+ "aria-label": m("themeGallery.search", "Search themes…")
280
183
  }
281
- ), Y = { "--nice-tgp-card-width": `${s + 20}px` };
282
- return /* @__PURE__ */ f(
184
+ ), z = { "--nice-tgp-card-width": `${h + 20}px` };
185
+ return /* @__PURE__ */ u(
283
186
  "div",
284
187
  {
285
- id: o,
286
- className: `nice-theme-gallery${u ? ` ${u}` : ""}`,
287
- style: { ...Y, ...M },
288
- title: w,
289
- "data-testid": _,
188
+ id: v,
189
+ className: `nice-theme-gallery${y ? ` ${y}` : ""}`,
190
+ style: { ...z, ...b },
191
+ title: C,
192
+ "data-testid": k,
290
193
  children: [
291
- r && W(N, R),
292
- /* @__PURE__ */ h(
194
+ t && H(S, q),
195
+ /* @__PURE__ */ r(
293
196
  "div",
294
197
  {
295
- ref: L,
198
+ ref: I,
296
199
  className: `nice-theme-gallery__grid${n ? " nice-theme-gallery__grid--row" : ""}`,
297
200
  role: "group",
298
- "aria-label": G,
299
- children: H.map(B)
201
+ "aria-label": f,
202
+ children: $.map(F)
300
203
  }
301
204
  ),
302
- H.length === 0 && /* @__PURE__ */ h("p", { className: "nice-theme-gallery__empty", children: c("themeGallery.empty", "No theme matches the search.") }),
303
- n !== void 0 && e.length > n && /* @__PURE__ */ f(
205
+ $.length === 0 && /* @__PURE__ */ r("p", { className: "nice-theme-gallery__empty", children: m("themeGallery.empty", "No theme matches the search.") }),
206
+ n !== void 0 && a.length > n && /* @__PURE__ */ u(
304
207
  "button",
305
208
  {
306
209
  type: "button",
307
210
  className: "nice-theme-gallery__more",
308
- onClick: () => m(!0),
211
+ onClick: () => R(!0),
309
212
  "aria-haspopup": "dialog",
310
213
  children: [
311
- /* @__PURE__ */ h(Z, { name: "grid", size: 14 }),
214
+ /* @__PURE__ */ r(U, { name: "grid", size: 14 }),
312
215
  " ",
313
- c("themeGallery.showMore", "Show more"),
314
- /* @__PURE__ */ h("span", { className: "nice-theme-gallery__count", children: e.length })
216
+ m("themeGallery.showMore", "Show more"),
217
+ /* @__PURE__ */ r("span", { className: "nice-theme-gallery__count", children: a.length })
315
218
  ]
316
219
  }
317
220
  ),
318
- /* @__PURE__ */ h(
319
- te,
221
+ /* @__PURE__ */ r(
222
+ ee,
320
223
  {
321
- open: l,
322
- onClose: () => m(!1),
323
- title: G,
224
+ open: V,
225
+ onClose: () => R(!1),
226
+ title: f,
324
227
  size: "xl",
325
228
  className: "nice-theme-gallery__modal",
326
- children: /* @__PURE__ */ f("div", { className: "nice-theme-gallery", style: Y, children: [
327
- /* @__PURE__ */ f("div", { className: "nice-theme-gallery__toolbar", children: [
328
- W(A, X),
329
- O.length > 1 && /* @__PURE__ */ h("div", { className: "nice-theme-gallery__tabs", role: "group", "aria-label": G, children: [{ id: "", label: c("themeGallery.all", "All") }, ...O].map((t) => /* @__PURE__ */ h(
229
+ children: /* @__PURE__ */ u("div", { className: "nice-theme-gallery", style: z, children: [
230
+ /* @__PURE__ */ u("div", { className: "nice-theme-gallery__toolbar", children: [
231
+ H(E, X),
232
+ P.length > 1 && /* @__PURE__ */ r("div", { className: "nice-theme-gallery__tabs", role: "group", "aria-label": f, children: [{ id: "", label: m("themeGallery.all", "All") }, ...P].map((e) => /* @__PURE__ */ r(
330
233
  "button",
331
234
  {
332
235
  type: "button",
333
236
  className: "nice-theme-gallery__tab",
334
- "aria-pressed": $ === t.id,
335
- onClick: () => D(t.id),
336
- children: t.id ? I(t.id) : t.label
237
+ "aria-pressed": M === e.id,
238
+ onClick: () => Y(e.id),
239
+ children: e.id ? T(e.id) : e.label
337
240
  },
338
- t.id
241
+ e.id
339
242
  )) })
340
243
  ] }),
341
- /* @__PURE__ */ h(
244
+ /* @__PURE__ */ r(
342
245
  "div",
343
246
  {
344
- ref: F,
247
+ ref: A,
345
248
  className: "nice-theme-gallery__grid",
346
249
  role: "group",
347
- "aria-label": G,
348
- children: z.map(B)
250
+ "aria-label": f,
251
+ children: O.map(F)
349
252
  }
350
253
  ),
351
- z.length === 0 && /* @__PURE__ */ h("p", { className: "nice-theme-gallery__empty", children: c("themeGallery.empty", "No theme matches the search.") })
254
+ O.length === 0 && /* @__PURE__ */ r("p", { className: "nice-theme-gallery__empty", children: m("themeGallery.empty", "No theme matches the search.") })
352
255
  ] })
353
256
  }
354
257
  )
@@ -358,5 +261,5 @@ const me = ({
358
261
  };
359
262
  export {
360
263
  me as NiceThemeGalleryPicker,
361
- ne as NiceThemeGalleryPreview
264
+ le as NiceThemeGalleryPreview
362
265
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nice2dev/ui",
3
- "version": "1.4.17",
3
+ "version": "1.4.19",
4
4
  "description": "Nice2Dev UI — Universal, themeable, i18n-ready React component library",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -97,12 +97,12 @@
97
97
  "react-dom": ">=17.0.0"
98
98
  },
99
99
  "dependencies": {
100
- "@nice2dev/i18n": "^1.4.17",
101
- "@nice2dev/ui-core": "^1.4.17",
100
+ "@nice2dev/i18n": "^1.4.19",
101
+ "@nice2dev/ui-core": "^1.4.19",
102
102
  "country-flag-icons": "^1.6.20"
103
103
  },
104
104
  "devDependencies": {
105
- "@nice2dev/testing": "^1.4.17",
105
+ "@nice2dev/testing": "^1.4.19",
106
106
  "@playwright/test": "^1.62.1",
107
107
  "@testing-library/dom": "^10.4.1",
108
108
  "@testing-library/jest-dom": "^7.0.1",