@telia-ace/knowledge-widget-components-search 1.1.8 → 1.2.2

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,981 +0,0 @@
1
- import { jsxs as O, jsx as y, Fragment as ke } from "react/jsx-runtime";
2
- import { css as j } from "@emotion/react";
3
- import z from "@emotion/styled";
4
- import { borderTabStyle as J, Text as se, Link as ie, SymbolBadge as X, useProperties as K, useDispatch as M, useRouteData as ae, useEventListener as U, useKeyPress as Q, Tooltip as xe, ItemTree as $e, contentBox as ce, useScroll as we, useContainer as le, Loader as Ce, useDebounce as Ae, usePrevious as ee, useChildren as Se, useWidgetEvent as ve, useTransitionEnd as Ie, convertToStringAttributes as Ee, Input as qe, Button as de } from "@telia-ace/knowledge-widget-ui";
5
- import { Component as ze } from "@telia-ace/widget-types-grid";
6
- import { appendClassNames as Y, deepClone as Le, categoryTrail as De } from "@telia-ace/widget-utilities";
7
- import { useRef as Z, useState as D, useCallback as I, useEffect as T, useMemo as Fe } from "react";
8
- const Ne = ({
9
- text: e,
10
- className: t,
11
- filterType: o,
12
- handleClick: c,
13
- deleteAriaLabel: d = "",
14
- ...l
15
- }) => {
16
- const r = Z(), [w, k] = D(
17
- document.activeElement === r.current
18
- );
19
- return /* @__PURE__ */ O(
20
- se,
21
- {
22
- className: Y(
23
- t,
24
- "humany-filter-badge",
25
- w ? "humany-filter-badge-focused" : ""
26
- ),
27
- onKeyDown: (x) => {
28
- x.key === "Enter" && c(x, o);
29
- },
30
- children: [
31
- e,
32
- /* @__PURE__ */ y(
33
- ie,
34
- {
35
- ...l,
36
- ref: r,
37
- tabIndex: 0,
38
- onFocus: () => {
39
- k(!0);
40
- },
41
- onBlur: () => {
42
- k(!1);
43
- },
44
- role: "button",
45
- "aria-label": d.replace("{{item}}", e),
46
- onClick: (x) => c(x, o),
47
- children: /* @__PURE__ */ y(X, { size: 13, symbol: { type: "Svg", content: "close" } })
48
- }
49
- )
50
- ]
51
- }
52
- );
53
- }, Be = ({
54
- inputHasFocus: e,
55
- searchContainerRef: t,
56
- showTag: o,
57
- showGuideCategory: c,
58
- position: d
59
- }) => {
60
- const { activeFilterBadges: l, deleteFilterBadgeAriaLabel: r = "" } = K(), w = M(), { name: k, params: x } = ae(), [E, g] = D(!1), S = I((i) => {
61
- const { key: a } = i;
62
- ["ArrowLeft", "ArrowRight"].indexOf(a) === -1 && g(!1);
63
- }, []);
64
- U("keydown", S, window), U("click", S, window);
65
- const { guideCategory: C, tag: m, tooltip: $ } = l || {}, u = (i) => {
66
- const a = i.querySelectorAll(
67
- ".humany-filter-badge > a"
68
- );
69
- return {
70
- badges: a,
71
- index: Array.from(a).findIndex((h) => document.activeElement === h)
72
- };
73
- }, n = I(
74
- (i, a, h) => {
75
- i.preventDefault(), w("quick-filter:remove", { types: [a], ids: [h] });
76
- },
77
- [w]
78
- ), f = (i, a) => {
79
- if (!t)
80
- return;
81
- const { badges: h, index: b } = u(t);
82
- if (h.length) {
83
- let q = null;
84
- i === "left" ? b === -1 ? q = h.item(h.length - 1) : b > 0 && (q = h.item(b - 1)) : i === "right" && (b === h.length - 1 ? a && a.focus() : h.item(b + 1) && (q = h.item(b + 1))), q && (q.focus(), g(!0));
85
- }
86
- };
87
- Q(
88
- "ArrowLeft",
89
- I(() => {
90
- if (!t)
91
- return;
92
- const { index: i } = u(t);
93
- if (e || i > -1) {
94
- const a = t.querySelector('[data-type="search"]'), h = a && a.selectionStart !== null && a.selectionStart <= 0, b = i > -1;
95
- (h || b) && f("left", a);
96
- }
97
- }, [e, t])
98
- ), Q(
99
- "ArrowRight",
100
- I(() => {
101
- if (!t)
102
- return;
103
- const { index: i } = u(t);
104
- if (i > -1) {
105
- const a = t.querySelector('[data-type="search"]');
106
- i > -1 && f("right", a);
107
- }
108
- }, [t])
109
- ), Q(
110
- "Backspace",
111
- I(
112
- (i) => {
113
- if (!t)
114
- return;
115
- let a = [];
116
- const { index: h } = u(t), b = t.querySelector('[data-type="search"]');
117
- if (h > -1)
118
- h === 0 ? c ? a = ["guideCategory"] : o && (a = ["tag"]) : h === 1 && (a = ["tag"]);
119
- else {
120
- const p = document.activeElement === b;
121
- b && b.selectionStart !== null && b.selectionStart <= 0 && p && (l != null && l.tag.length ? a = ["tag"] : l != null && l.guideCategory && (a = ["guideCategory"]));
122
- }
123
- if (a.length > 0) {
124
- i.preventDefault();
125
- let p;
126
- if (a.includes("tag")) {
127
- const F = l == null ? void 0 : l.tag.at(-1);
128
- p = F == null ? void 0 : F.id;
129
- }
130
- w("quick-filter:remove", {
131
- types: a,
132
- ids: [p]
133
- });
134
- }
135
- },
136
- [
137
- t,
138
- l,
139
- o,
140
- c,
141
- w
142
- ]
143
- )
144
- );
145
- const s = I(
146
- (i) => i === "guideCategory" && C && c ? /* @__PURE__ */ y(
147
- te,
148
- {
149
- text: `@${C.title}`,
150
- routeName: k,
151
- filterType: "guideCategory",
152
- handleClick: n,
153
- deleteAriaLabel: r,
154
- params: {
155
- ...x,
156
- guideCategory: void 0
157
- }
158
- }
159
- ) : i === "tag" && (m != null && m.length) && o ? m.map((a) => {
160
- const h = m.reduce((b, q) => (q.id !== a.id && b.push(q.id), b), []);
161
- return /* @__PURE__ */ y(
162
- te,
163
- {
164
- className: "humany-filter-badge",
165
- text: `#${a.title}`,
166
- routeName: k,
167
- filterType: "tag",
168
- handleClick: (b) => n(b, "tag", a.id),
169
- deleteAriaLabel: r,
170
- params: {
171
- ...x,
172
- tag: h
173
- }
174
- },
175
- a.id
176
- );
177
- }) : null,
178
- // eslint-disable-next-line react-hooks/exhaustive-deps
179
- [
180
- C,
181
- m,
182
- k,
183
- x,
184
- c,
185
- o,
186
- E,
187
- n
188
- ]
189
- );
190
- return !C && !m ? null : /* @__PURE__ */ O(Oe, { className: "humany-filter-badges", position: d, children: [
191
- C && $ ? (
192
- // eslint-disable-next-line react/jsx-no-useless-fragment
193
- /* @__PURE__ */ y(xe, { content: /* @__PURE__ */ y(ke, { children: $ }), sticky: !1, children: s("guideCategory") })
194
- ) : s("guideCategory"),
195
- m && s("tag")
196
- ] });
197
- }, Oe = z.div`
198
- display: flex;
199
- align-items: center;
200
- flex-wrap: wrap;
201
-
202
- ${(e) => {
203
- var t, o;
204
- return e.position === "inside" ? j`
205
- &:not(:first-child) {
206
- margin: 0 0 0 ${(t = e.theme.sizes) == null ? void 0 : t.normal};
207
- }
208
- ` : j`
209
- margin: ${(o = e.theme.sizes) == null ? void 0 : o.small} 0 0 0;
210
- span:first-child {
211
- margin-left: 0;
212
- }
213
- `;
214
- }}
215
- `, te = z(Ne)`
216
- display: flex;
217
- align-items: center;
218
- padding: ${(e) => {
219
- var t, o;
220
- return `${(t = e.theme.sizes) == null ? void 0 : t.small} calc(${(o = e.theme.sizes) == null ? void 0 : o.normal}/2) `;
221
- }};
222
- background-color: ${(e) => {
223
- var t;
224
- return (t = e.theme.colors) == null ? void 0 : t.primary;
225
- }};
226
- border-radius: ${(e) => e.theme.borderRadius};
227
- font-weight: 300;
228
- font-size: ${(e) => {
229
- var t;
230
- return (t = e.theme.fonts) == null ? void 0 : t.normal;
231
- }};
232
- font-style: italic;
233
- color: #ffffff;
234
- text-decoration: none;
235
- white-space: nowrap;
236
-
237
- margin: calc(${(e) => {
238
- var t;
239
- return (t = e.theme.sizes) == null ? void 0 : t.small;
240
- }} / 2);
241
-
242
- &.humany-filter-badge-focused:focus-within {
243
- ${J}
244
- background-color: transparent;
245
-
246
- svg {
247
- path {
248
- stroke: ${(e) => {
249
- var t;
250
- return (t = e.theme.colors) == null ? void 0 : t.primary;
251
- }};
252
- }
253
- }
254
- a {
255
- outline: none;
256
- }
257
- }
258
-
259
- svg {
260
- width: 17px;
261
- height: 11px;
262
- margin: 1px 0 0 ${(e) => {
263
- var t;
264
- return (t = e.theme.sizes) == null ? void 0 : t.small;
265
- }};
266
- path {
267
- stroke: #ffffff;
268
- stroke-width: 2px;
269
- }
270
- order: 1;
271
- }
272
- `, B = (e, t) => !t || !e ? !0 : e.toLowerCase().indexOf(t.toLowerCase()) > -1, Te = (e = [], t, o) => {
273
- if (!o)
274
- return e;
275
- const c = Le(e);
276
- if (t === "tag")
277
- return c.filter((r) => B(r.title, o));
278
- const d = je(c, o);
279
- return ue(
280
- c,
281
- (r) => d.indexOf(r.id) > -1
282
- );
283
- }, ue = (e, t) => e.filter((o) => (o.items && o.items.length && (o.items = ue(o.items, t)), t(o))), je = (e, t) => {
284
- const c = fe(e).filter((l) => B(l.title, t)).map((l) => l.id);
285
- let d = [];
286
- return c.forEach((l) => {
287
- const r = De(l, e);
288
- d = d.concat(r);
289
- }), d;
290
- }, fe = (e) => {
291
- let t = [];
292
- return e.forEach((o) => {
293
- t.push(o), Array.isArray(o.items) && (t = t.concat(fe(o.items)));
294
- }), t;
295
- }, G = (e) => {
296
- const t = Array.from((e == null ? void 0 : e.getElementsByTagName("A")) || []).filter(
297
- (o) => o.getAttribute("disabled") === null
298
- );
299
- return {
300
- anchors: t,
301
- focusedIndex: t.findIndex((o) => document.activeElement === o)
302
- };
303
- }, Ke = (e) => e ? e.querySelector(
304
- '[data-type="search"], input[type="search"]'
305
- ) : null, H = (e) => {
306
- if (!e)
307
- return;
308
- const t = Ke(e);
309
- t && t.focus();
310
- }, Pe = ({
311
- filterPhrase: e,
312
- items: t,
313
- filterType: o,
314
- filterContainer: c,
315
- searchContainer: d,
316
- inputHasFocus: l
317
- }) => {
318
- const [r, w] = D(t || []), [k, x] = D(null), E = M(), { activeFilterBadges: g, quickFilters: S } = K(), C = typeof S == "object" && !!S.autoSelect || typeof S == "boolean" && !!S;
319
- T(() => {
320
- w(Te(t, o, e));
321
- }, [e, o, t]), T(() => {
322
- var u;
323
- if (c) {
324
- const { anchors: n } = G(c), f = (u = n[0]) == null ? void 0 : u.getAttribute("data-id");
325
- f && x(f);
326
- }
327
- }, [r, c]);
328
- const m = I(
329
- (u, n) => {
330
- let f = ((g == null ? void 0 : g.tag) || []).map((i) => i.id);
331
- n === "tag" && u.id && (f = f.includes(u.id) ? f.filter((i) => i !== u.id) : [...f, u.id]);
332
- const s = {
333
- category: g != null && g.guideCategory ? g.guideCategory.id : void 0,
334
- tagIds: f
335
- };
336
- n === "guideCategory" && (s.category = u.id), E("quick-filter:add", s);
337
- },
338
- [g, E]
339
- ), $ = (u) => u === "guideCategory" ? {
340
- renderItem: (n, f) => /* @__PURE__ */ y(
341
- re,
342
- {
343
- autoSelect: C && l && n.id === k,
344
- disabled: !B(n.title, e),
345
- tabIndex: B(n.title, e) ? 0 : -1,
346
- onKeyDown: (s) => {
347
- s.key === "Enter" && m(n, u);
348
- },
349
- "data-level": f,
350
- onClick: () => {
351
- m(n, u);
352
- },
353
- "data-id": n.id,
354
- children: /* @__PURE__ */ y(
355
- oe,
356
- {
357
- title: n.title,
358
- phrase: e,
359
- matches: B(n.title, e)
360
- }
361
- )
362
- }
363
- )
364
- } : {
365
- renderLi: !0,
366
- renderItem: (n) => /* @__PURE__ */ y(
367
- re,
368
- {
369
- autoSelect: C && l && n.id === k,
370
- onKeyDown: (f) => {
371
- f.key === "Enter" && m(n, u);
372
- },
373
- onClick: () => {
374
- m(n, u);
375
- },
376
- "data-id": n.id,
377
- children: /* @__PURE__ */ y(
378
- oe,
379
- {
380
- symbol: "#",
381
- title: n.title,
382
- phrase: e,
383
- matches: B(n.title, e)
384
- }
385
- )
386
- }
387
- )
388
- };
389
- return U(
390
- "keydown",
391
- (u) => {
392
- var q;
393
- const { key: n } = u;
394
- if (!c || !(n === "ArrowDown" || n === "ArrowUp" || n === "Enter"))
395
- return;
396
- const { anchors: f, focusedIndex: s } = G(c);
397
- if (n === "Enter") {
398
- if (l && C) {
399
- const p = (q = f[0]) == null ? void 0 : q.getAttribute("data-id");
400
- p && m({ id: p }, o);
401
- }
402
- return;
403
- }
404
- const i = () => {
405
- var p;
406
- return (p = f[0]) == null ? void 0 : p.focus();
407
- }, a = () => {
408
- var p;
409
- return (p = f[f.length - 1]) == null ? void 0 : p.focus();
410
- }, h = () => {
411
- var p;
412
- return (p = f[s + 1]) == null ? void 0 : p.focus();
413
- }, b = () => {
414
- var p;
415
- return (p = f[s - 1]) == null ? void 0 : p.focus();
416
- };
417
- l ? (u.preventDefault(), n === "ArrowDown" ? i() : a()) : s > -1 && (u.preventDefault(), n === "ArrowDown" ? f.length > s + 1 ? h() : H(d) : s - 1 < 0 ? H(d) : b());
418
- },
419
- window
420
- ), /* @__PURE__ */ y(
421
- $e,
422
- {
423
- tree: r,
424
- renderEmpty: !1,
425
- ulProps: { role: "listbox" },
426
- liProps: { role: "option" },
427
- ...$(o)
428
- }
429
- );
430
- }, oe = ({
431
- title: e,
432
- phrase: t,
433
- matches: o,
434
- symbol: c = ""
435
- }) => {
436
- const d = () => {
437
- if (!o || !t)
438
- return [e];
439
- const k = e.toLowerCase().indexOf(t.toLowerCase()), x = e.substr(0, k), E = e.slice(k, k + t.length), g = e.substr(k + t.length);
440
- return [x, E, g];
441
- }, [l, r, w] = d();
442
- return /* @__PURE__ */ O(se, { children: [
443
- c,
444
- l,
445
- r ? /* @__PURE__ */ y("strong", { children: r }) : null,
446
- w || null
447
- ] });
448
- }, We = j`
449
- opacity: 0.5;
450
- pointer-events: none;
451
- `, ne = (e) => {
452
- var t, o;
453
- return j`
454
- background-color: ${(t = e.theme.colors) == null ? void 0 : t.text};
455
- color: #ffffff;
456
- outline: none;
457
-
458
- span:first-child {
459
- border-color: ${(o = e.theme.colors) == null ? void 0 : o.text};
460
- }
461
- `;
462
- }, re = z(ie)`
463
- display: block;
464
- text-decoration: none;
465
- font-size: ${(e) => {
466
- var t;
467
- return (t = e.theme.fonts) == null ? void 0 : t.normal;
468
- }};
469
-
470
- ${(e) => e.disabled && We}
471
- color: ${(e) => {
472
- var t;
473
- return (t = e.theme.colors) == null ? void 0 : t.text;
474
- }};
475
- background-color: transparent;
476
-
477
- span {
478
- display: block;
479
- ${(e) => {
480
- var t, o, c, d;
481
- return e["data-level"] ? `padding: calc(${(t = e.theme.sizes) == null ? void 0 : t.normal} / 2) ${(o = e.theme.sizes) == null ? void 0 : o.normal};` : `padding: calc(${(c = e.theme.sizes) == null ? void 0 : c.normal} / 2) ${(d = e.theme.sizes) == null ? void 0 : d.medium}; `;
482
- }}
483
- ${(e) => e["data-level"] && "border-left: 2px solid"}
484
- }
485
-
486
- span:first-child {
487
- border-color: #e7e7e7;
488
- }
489
-
490
- ${(e) => {
491
- var t;
492
- return e["data-level"] && `padding: 0 calc(${(t = e.theme.sizes) == null ? void 0 : t.medium} * ${e["data-level"]});`;
493
- }}
494
-
495
- ${(e) => e.autoSelect && ne}
496
-
497
- &:hover,
498
- &:focus {
499
- ${ne}
500
- }
501
- `, Me = ({ phrase: e = "", inputHasFocus: t, searchContainerRef: o }) => {
502
- const {
503
- quickFilter: c = {
504
- open: !1,
505
- loading: !1,
506
- symbol: "",
507
- type: "",
508
- items: []
509
- },
510
- activeFilterBadges: d,
511
- noMatchesLabel: l = "No matching items"
512
- } = K(), [r, w] = we(!0), k = le(), { events: x } = k.get("$widget"), E = Z(), g = I(
513
- (s) => (s && s.addEventListener(
514
- "keydown",
515
- () => {
516
- G(s).focusedIndex > -1 && x.subscribeOnce("router:changed", () => {
517
- H(o);
518
- });
519
- },
520
- !0
521
- ), E.current = s, s),
522
- // eslint-disable-next-line react-hooks/exhaustive-deps
523
- [o]
524
- ), { items: S = [], symbol: C, type: m, open: $, loading: u } = c, n = Fe(() => {
525
- const s = ((d == null ? void 0 : d.tag) || []).map((i) => i.id);
526
- return S.filter((i) => !s.includes(i.id));
527
- }, [S, d]);
528
- if (!$ || !C)
529
- return null;
530
- const f = e.slice(e.indexOf(C) + 1);
531
- return /* @__PURE__ */ O(
532
- Qe,
533
- {
534
- ref: g,
535
- "data-loading": u,
536
- className: Y(
537
- "humany-quick-filter-dropdown",
538
- [m === "guideCategory", "humany-quick-filter-guide-categories"],
539
- [m === "tag", "humany-quick-filter-tags"]
540
- ),
541
- children: [
542
- /* @__PURE__ */ y(Xe, { className: "humany-quick-filter-dropdown-inner", css: r, ref: w, children: n.length > 0 ? /* @__PURE__ */ y(
543
- Pe,
544
- {
545
- filterType: m,
546
- items: n,
547
- filterPhrase: f,
548
- filterContainer: w.current,
549
- searchContainer: o,
550
- inputHasFocus: t
551
- }
552
- ) : /* @__PURE__ */ y(Ue, { children: l }) }),
553
- /* @__PURE__ */ y(Ce, { loading: u })
554
- ]
555
- }
556
- );
557
- }, Qe = z.div`
558
- ${(e) => ce(e)};
559
- position: absolute;
560
- top: calc(100% + ${(e) => {
561
- var t;
562
- return (t = e.theme.sizes) == null ? void 0 : t.normal;
563
- }});
564
- left: 0;
565
- right: 0;
566
- z-index: 1;
567
- overflow: hidden;
568
- `, Xe = z.div`
569
- max-height: 300px;
570
- overflow: auto;
571
- padding: ${(e) => {
572
- var t;
573
- return (t = e.theme.sizes) == null ? void 0 : t.medium;
574
- }} 0;
575
- ${(e) => e.css}
576
- ul {
577
- list-style: none;
578
- padding: 0;
579
- margin: 0;
580
- }
581
- li div {
582
- ${(e) => {
583
- var t;
584
- return `margin: ${(t = e.theme.sizes) == null ? void 0 : t.normal} 0;`;
585
- }}
586
- }
587
- `, Ue = z.p`
588
- margin: 0 ${(e) => {
589
- var t;
590
- return (t = e.theme.sizes) == null ? void 0 : t.normal;
591
- }};
592
- color: ${(e) => {
593
- var t;
594
- return (t = e.theme.colors) == null ? void 0 : t.text;
595
- }};
596
- `, W = (e, t) => {
597
- if (e && !t || !e && t)
598
- return !0;
599
- if (e && t) {
600
- if (!Array.isArray(e) && !Array.isArray(t)) {
601
- if (e.id !== t.id)
602
- return !0;
603
- } else if (!((c, d) => c.length === d.length ? c.every((l, r) => l === d[r]) : !1)(e, t))
604
- return !0;
605
- }
606
- return !1;
607
- }, Ge = (e, t = {}, o = !0) => {
608
- const c = M(), {
609
- quickFilters: d = !1,
610
- quickFilter: l = { open: !1 },
611
- activeFilterBadges: r,
612
- filterBadges: w = !1,
613
- incremental: k = 600
614
- } = K(), x = Ae(
615
- e,
616
- typeof k == "boolean" ? 600 : k
617
- ), E = ee(x), g = ee(r), S = Z(null), C = I(
618
- (n = "") => {
619
- var f;
620
- if (w) {
621
- const s = W(
622
- r == null ? void 0 : r.guideCategory,
623
- g == null ? void 0 : g.guideCategory
624
- ) || W(r == null ? void 0 : r.tag, g == null ? void 0 : g.tag);
625
- return c("search", {
626
- value: n,
627
- filtersChanged: s,
628
- filters: {
629
- tagIds: ((r == null ? void 0 : r.tag) || []).map((i) => i.id),
630
- guideCategoryId: ((f = r == null ? void 0 : r.guideCategory) == null ? void 0 : f.id) || null
631
- }
632
- });
633
- }
634
- return c("search", { value: n });
635
- },
636
- [c, r]
637
- ), m = I(
638
- (n) => {
639
- c("clear", { navigateToHome: n });
640
- },
641
- [c]
642
- ), $ = (n) => d ? n.replace(/([@#].*)/g, "") : n, u = I(
643
- (n) => {
644
- if (l.open && n.preventDefault) {
645
- n.preventDefault();
646
- return;
647
- }
648
- const f = document.activeElement, s = S.current && typeof S.current.contains == "function" ? S.current.contains(f) : !1, i = $(e);
649
- typeof n == "boolean" && n || i.length && s || r != null && r.guideCategory || r != null && r.tag.length && s ? C(i) : m(s);
650
- },
651
- [
652
- S,
653
- e,
654
- l,
655
- m,
656
- r,
657
- C
658
- ]
659
- );
660
- return T(() => {
661
- const n = W(
662
- r == null ? void 0 : r.guideCategory,
663
- g == null ? void 0 : g.guideCategory
664
- ) || W(r == null ? void 0 : r.tag, g == null ? void 0 : g.tag), f = x && $(x), s = E && $(E);
665
- typeof s < "u" && s !== f && f !== t.phrase && o && !l.open && u(n);
666
- }, [x, l.open, r, u]), T(() => {
667
- if (e && d) {
668
- const n = typeof d == "boolean" && !!d || typeof d == "object" && !!d.guideCategory, f = typeof d == "boolean" && !!d || typeof d == "object" && !!d.tag;
669
- n && e.indexOf("@") === e.length - 1 && c("quick-filter:open", { type: "guideCategory", symbol: "@" }), f && e.indexOf("#") === e.length - 1 && c("quick-filter:open", { type: "tag", symbol: "#" });
670
- }
671
- l.open && e.indexOf("@") === -1 && e.indexOf("#") === -1 && c("quick-filter:close");
672
- }, [e]), [u, m, S];
673
- }, rt = ({ className: e, ...t }) => {
674
- const {
675
- showSearchButton: o,
676
- showClearButton: c,
677
- role: d = "search",
678
- autoFocus: l,
679
- placeholder: r,
680
- searchButtonLabel: w,
681
- clearButtonLabel: k,
682
- ariaLabel: x,
683
- route: E = "search",
684
- incremental: g = !0,
685
- showChildren: S = !1,
686
- quickFilter: C,
687
- quickFilters: m,
688
- filterBadges: $
689
- } = K(), { params: u } = ae(), [n, f] = D(!1), [s, i] = D(u.phrase || ""), [a, h] = D({
690
- guideCategory: !1,
691
- tag: !1
692
- }), b = le(), q = Se(), p = M(), { position: F = "inside" } = typeof $ == "object" ? $ : {};
693
- T(() => {
694
- const { guideCategory: A, tag: v } = u, L = typeof $ == "object" ? !!$.guideCategory : !!$, be = typeof $ == "object" ? !!$.tag : !!$;
695
- h({
696
- guideCategory: L && !!A,
697
- tag: be && !!v
698
- });
699
- }, [$, u]), ve(
700
- "router:changed",
701
- () => {
702
- if (C) {
703
- const { open: A, symbol: v } = C;
704
- if (A) {
705
- if (v) {
706
- const L = s.replace(
707
- s.slice(s.indexOf(v)),
708
- ""
709
- );
710
- i(L);
711
- }
712
- p("quick-filter:close");
713
- }
714
- }
715
- },
716
- [C, s, i, p]
717
- );
718
- const [_, P, N] = Ge(s, u, !!g);
719
- T(() => {
720
- i(u.phrase || "");
721
- }, [u.phrase]);
722
- const ge = I(
723
- (A) => {
724
- i(A);
725
- },
726
- [i]
727
- ), me = I(() => {
728
- p("quick-filter:close").then(() => P(!0));
729
- }, [p, P]), he = I(() => {
730
- var A, v;
731
- l && !n && ((v = (A = N.current) == null ? void 0 : A.getElementsByTagName("input")[0]) == null || v.focus());
732
- }, [l, n, N]), pe = I(() => {
733
- b.getAsync("router").then((A) => {
734
- const v = A.getInitialRoute(), L = A.getRouteData();
735
- (v == null ? void 0 : v.name) === L.name && (v == null ? void 0 : v.name) !== E ? i("") : P(!0);
736
- });
737
- }, [b, i, P]), R = (A) => {
738
- if (A !== F)
739
- return null;
740
- if (a.guideCategory || a.tag)
741
- return /* @__PURE__ */ y(
742
- Be,
743
- {
744
- position: A,
745
- inputHasFocus: n,
746
- showGuideCategory: a.guideCategory,
747
- showTag: a.tag,
748
- searchContainerRef: N.current
749
- }
750
- );
751
- };
752
- Ie(he);
753
- const V = c && (a.guideCategory || a.tag || s), ye = m ? Ee({
754
- role: "combobox",
755
- "aria-autocomplete": "list",
756
- autoComplete: "off",
757
- "aria-haspopup": "listbox"
758
- }) : {};
759
- return /* @__PURE__ */ O(
760
- He,
761
- {
762
- ...t,
763
- ref: N,
764
- role: d,
765
- className: Y(e, "humany-search"),
766
- "data-has-phrase": !!s,
767
- "data-has-focus": n,
768
- "data-has-search-symbol": o ? "true" : "false",
769
- children: [
770
- /* @__PURE__ */ O(
771
- Je,
772
- {
773
- action: ".",
774
- onSubmit: (A) => {
775
- var v, L;
776
- A.preventDefault(), (L = (v = N.current) == null ? void 0 : v.getElementsByTagName("input")[0]) == null || L.blur();
777
- },
778
- "data-has-focus": n,
779
- children: [
780
- o && /* @__PURE__ */ y(
781
- Ye,
782
- {
783
- "aria-label": w,
784
- type: "submit",
785
- title: w,
786
- disabled: !s,
787
- onClick: _,
788
- "data-has-phrase": !!s,
789
- "data-has-focus": n,
790
- children: /* @__PURE__ */ y(
791
- X,
792
- {
793
- size: 32,
794
- symbol: { type: "Svg", content: "search" }
795
- }
796
- )
797
- }
798
- ),
799
- R("inside"),
800
- /* @__PURE__ */ y(
801
- qe,
802
- {
803
- crossOrigin: void 0,
804
- type: "search",
805
- "aria-label": x,
806
- ...ye,
807
- placeholder: a.guideCategory || a.tag ? "" : r,
808
- onFocusChange: f,
809
- onEscape: me,
810
- onEnter: _,
811
- onChange: ge,
812
- value: s
813
- }
814
- ),
815
- V && /* @__PURE__ */ y(
816
- Ze,
817
- {
818
- "aria-label": k,
819
- type: "reset",
820
- hasFocus: n,
821
- title: k,
822
- onClick: pe,
823
- children: /* @__PURE__ */ y(X, { size: 27, symbol: { type: "Svg", content: "clear" } })
824
- }
825
- ),
826
- S && !V && q.map((A) => /* @__PURE__ */ y(ze, { id: A.id, branch: "default" }, A.id)),
827
- /* @__PURE__ */ y(
828
- Me,
829
- {
830
- inputHasFocus: n,
831
- phrase: s,
832
- searchContainerRef: N.current
833
- }
834
- )
835
- ]
836
- }
837
- ),
838
- R("below")
839
- ]
840
- }
841
- );
842
- }, He = z.div`
843
- ${ce};
844
- width: 100%;
845
- padding: ${(e) => {
846
- var t;
847
- return (t = e.theme.sizes) == null ? void 0 : t.large;
848
- }};
849
-
850
- input {
851
- background-color: transparent;
852
- border: none;
853
- outline: none;
854
- min-width: 25%;
855
- flex: 1;
856
- font-size: ${(e) => {
857
- var t;
858
- return (t = e.theme.fonts) == null ? void 0 : t.normal;
859
- }};
860
- font-weight: 300;
861
- font-style: italic;
862
- padding: 1em 0;
863
- color: ${(e) => {
864
- var t;
865
- return (t = e.theme.colors) == null ? void 0 : t.text;
866
- }};
867
- -webkit-appearance: none;
868
-
869
- ${(e) => {
870
- var t;
871
- return e["data-has-search-symbol"] === "true" && `text-indent: ${(t = e.theme.sizes) == null ? void 0 : t.normal};`;
872
- }}
873
-
874
- ::placeholder {
875
- color: ${(e) => {
876
- var t;
877
- return (t = e.theme.colors) == null ? void 0 : t.text;
878
- }};
879
- }
880
- /* removes the 'X' from IE */
881
- &[type='search']::-ms-clear {
882
- display: none;
883
- width: 0;
884
- height: 0;
885
- }
886
- &[type='search']::-ms-reveal {
887
- display: none;
888
- width: 0;
889
- height: 0;
890
- }
891
-
892
- /* removes the 'X' from Chrome */
893
- &[type='search']::-webkit-search-decoration,
894
- &[type='search']::-webkit-search-cancel-button,
895
- &[type='search']::-webkit-search-results-button,
896
- &[type='search']::-webkit-search-results-decoration {
897
- display: none;
898
- }
899
-
900
- &:focus {
901
- outline: none;
902
- }
903
- }
904
-
905
- button {
906
- background: transparent;
907
- border: none;
908
- padding: 0;
909
- font-size: ${(e) => {
910
- var t;
911
- return (t = e.theme.fonts) == null ? void 0 : t.large;
912
- }};
913
- transition: color 200ms ease-out;
914
- color: ${(e) => {
915
- var t;
916
- return e["data-has-focus"] || e["data-has-phrase"] ? (t = e.theme.colors) == null ? void 0 : t.primary : "#000000";
917
- }};
918
- cursor: pointer;
919
- > svg {
920
- height: 100%;
921
- }
922
- }
923
- `, Je = z.form`
924
- display: flex;
925
- flex-wrap: nowrap;
926
- align-items: center;
927
- border: ${(e) => e.theme.inputBorder};
928
- border-radius: ${(e) => e.theme.borderRadius};
929
- background-color: #ffffff;
930
- position: relative;
931
- padding: 0 ${(e) => {
932
- var t;
933
- return (t = e.theme.sizes) == null ? void 0 : t.normal;
934
- }};
935
-
936
- ${(e) => {
937
- var t, o;
938
- return e["data-has-focus"] && j`
939
- ${(t = e.theme.accessibility) != null && t.isTabbing ? J(e) : `
940
- border-color: ${(o = e.theme.colors) == null ? void 0 : o.primary};
941
- outline: none;
942
- input {
943
- outline: none;
944
- }
945
- `}
946
- `;
947
- }};
948
- `, Ye = z(de)`
949
- padding: 0;
950
- height: 2em;
951
-
952
- svg {
953
- circle,
954
- line {
955
- stroke: ${(e) => {
956
- var t;
957
- return e["data-has-focus"] ? (t = e.theme.colors) == null ? void 0 : t.primary : "#000000";
958
- }};
959
- }
960
- }
961
- `, Ze = z(de)`
962
- &:focus-visible svg {
963
- ${J}
964
- }
965
-
966
- svg {
967
- vertical-align: top;
968
-
969
- circle,
970
- line,
971
- path {
972
- stroke: ${(e) => {
973
- var t, o;
974
- return e.hasFocus ? (t = e.theme.colors) == null ? void 0 : t.primary : (o = e.theme.colors) == null ? void 0 : o.text;
975
- }};
976
- }
977
- }
978
- `;
979
- export {
980
- rt as default
981
- };