@phillips/seldon 1.67.2 → 1.68.0
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.
|
@@ -7,6 +7,10 @@ export interface SearchProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
7
7
|
* @returns void
|
|
8
8
|
*/
|
|
9
9
|
onSearch?: (searchQuery: string) => void;
|
|
10
|
+
/**
|
|
11
|
+
* called when the search is cancelled
|
|
12
|
+
*/
|
|
13
|
+
onCancel?: () => void;
|
|
10
14
|
/**
|
|
11
15
|
* The search results to display
|
|
12
16
|
*/
|
|
@@ -40,5 +44,5 @@ export interface SearchProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
40
44
|
*/
|
|
41
45
|
invalidText?: string;
|
|
42
46
|
}
|
|
43
|
-
declare const Search: ({ onSearch, searchResults, state, defaultValue, className, placeholder, searchButtonText, loadingText, invalidText, getAllResultsText, getAllResultsLink, ...props }: React.PropsWithChildren<SearchProps>) => import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
declare const Search: ({ onSearch, onCancel, searchResults, state, defaultValue, className, placeholder, searchButtonText, loadingText, invalidText, getAllResultsText, getAllResultsLink, ...props }: React.PropsWithChildren<SearchProps>) => import("react/jsx-runtime").JSX.Element;
|
|
44
48
|
export default Search;
|
|
@@ -1,145 +1,149 @@
|
|
|
1
1
|
import { jsx as a, jsxs as u } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import { getCommonProps as
|
|
2
|
+
import c, { useEffect as V } from "react";
|
|
3
|
+
import { getCommonProps as j, px as D, encodeURLSearchParams as I } from "../../utils/index.js";
|
|
4
4
|
import f from "../../node_modules/classnames/index.js";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { TextVariants as
|
|
9
|
-
import
|
|
10
|
-
import { useOnClickOutside as
|
|
11
|
-
import { HeaderContext as
|
|
12
|
-
import { SearchButton as
|
|
13
|
-
import
|
|
5
|
+
import H from "../Input/Input.js";
|
|
6
|
+
import O from "../Link/Link.js";
|
|
7
|
+
import A from "./SearchResults/SearchResults.js";
|
|
8
|
+
import { TextVariants as F } from "../Text/types.js";
|
|
9
|
+
import K from "../Text/Text.js";
|
|
10
|
+
import { useOnClickOutside as M } from "../../node_modules/usehooks-ts/dist/index.js";
|
|
11
|
+
import { HeaderContext as U } from "../../site-furniture/Header/Header.js";
|
|
12
|
+
import { SearchButton as q } from "./SearchButton.js";
|
|
13
|
+
import z from "../../node_modules/react-transition-group/esm/CSSTransition.js";
|
|
14
14
|
const ne = ({
|
|
15
|
-
onSearch:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
onSearch: _,
|
|
16
|
+
onCancel: i,
|
|
17
|
+
searchResults: E = [],
|
|
18
|
+
state: l = "idle",
|
|
19
|
+
defaultValue: R = "",
|
|
20
|
+
className: b,
|
|
21
|
+
placeholder: w = "",
|
|
22
|
+
searchButtonText: d = "Search",
|
|
23
|
+
loadingText: C = "Search In Progress...",
|
|
24
|
+
invalidText: k = "Invalid search",
|
|
25
|
+
getAllResultsText: L = (r) => `View all results for ${r}`,
|
|
26
|
+
getAllResultsLink: S = (r) => `/Search?Search=${r}`,
|
|
27
|
+
...v
|
|
27
28
|
}) => {
|
|
28
29
|
var N;
|
|
29
|
-
const { className:
|
|
30
|
-
|
|
30
|
+
const { className: r, "data-testid": m, ...P } = j(v, "Search"), o = c.useContext(U), h = c.useRef(null), p = c.useRef(null), x = c.useRef(null), t = o.isSearchExpanded, s = (N = h.current) == null ? void 0 : N.value, T = _ ? (e) => {
|
|
31
|
+
_(e.target.value);
|
|
31
32
|
} : void 0;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
M(x, (e) => {
|
|
34
|
+
i == null || i(), g(!1), e.stopPropagation();
|
|
35
|
+
});
|
|
36
|
+
const $ = (e) => {
|
|
37
|
+
var n;
|
|
38
|
+
if (e.stopPropagation(), e.key === "Enter") {
|
|
39
|
+
if (e.preventDefault(), s && s.length > 2) {
|
|
40
|
+
const y = I(S(s));
|
|
41
|
+
window.location.href = y;
|
|
39
42
|
}
|
|
40
|
-
|
|
43
|
+
e.currentTarget instanceof HTMLAnchorElement && e.currentTarget.click();
|
|
41
44
|
}
|
|
42
|
-
|
|
45
|
+
e.key === "Escape" && (o.setIsSearchExpanded(!1), (n = p.current) == null || n.reset());
|
|
43
46
|
};
|
|
44
|
-
|
|
45
|
-
var
|
|
47
|
+
V(() => {
|
|
48
|
+
var e;
|
|
46
49
|
if (t) {
|
|
47
|
-
(
|
|
50
|
+
(e = h.current) == null || e.focus();
|
|
48
51
|
return;
|
|
49
52
|
}
|
|
50
53
|
}, [t]);
|
|
51
|
-
const
|
|
52
|
-
var
|
|
53
|
-
o.setIsSearchExpanded(
|
|
54
|
+
const g = (e) => {
|
|
55
|
+
var n;
|
|
56
|
+
o.setIsSearchExpanded(e), (n = p.current) == null || n.reset();
|
|
54
57
|
};
|
|
55
|
-
return /* @__PURE__ */ a("div", { className: `${
|
|
58
|
+
return /* @__PURE__ */ a("div", { className: `${r}__container`, children: /* @__PURE__ */ u(
|
|
56
59
|
"div",
|
|
57
60
|
{
|
|
58
61
|
onClick: () => o.setIsSearchExpanded(!0),
|
|
59
|
-
className: `${
|
|
60
|
-
ref:
|
|
62
|
+
className: `${r}__container__inner`,
|
|
63
|
+
ref: x,
|
|
61
64
|
children: [
|
|
62
|
-
/* @__PURE__ */ a(
|
|
65
|
+
/* @__PURE__ */ a(K, { variant: F.heading4, className: `${r}__container__inner__label`, children: d }),
|
|
63
66
|
/* @__PURE__ */ a(
|
|
64
67
|
"div",
|
|
65
68
|
{
|
|
66
|
-
...
|
|
67
|
-
className: f(
|
|
68
|
-
"data-testid":
|
|
69
|
+
...P,
|
|
70
|
+
className: f(r, b, { [`${r}--active`]: t }),
|
|
71
|
+
"data-testid": m,
|
|
69
72
|
role: "search",
|
|
70
|
-
...
|
|
73
|
+
...v,
|
|
71
74
|
children: /* @__PURE__ */ u(
|
|
72
75
|
"form",
|
|
73
76
|
{
|
|
74
|
-
"data-testid": `${
|
|
75
|
-
className: f(`${
|
|
76
|
-
[`${
|
|
77
|
+
"data-testid": `${m}-form`,
|
|
78
|
+
className: f(`${r}__form`, {
|
|
79
|
+
[`${r}__form--active`]: t
|
|
77
80
|
}),
|
|
78
|
-
ref:
|
|
81
|
+
ref: p,
|
|
79
82
|
children: [
|
|
80
83
|
/* @__PURE__ */ u(
|
|
81
84
|
"div",
|
|
82
85
|
{
|
|
83
|
-
className: f(`${
|
|
84
|
-
[`${
|
|
86
|
+
className: f(`${r}__content-wrapper`, {
|
|
87
|
+
[`${r}__content-wrapper--active`]: t
|
|
85
88
|
}),
|
|
86
89
|
role: "combobox",
|
|
87
90
|
"aria-haspopup": "listbox",
|
|
88
91
|
children: [
|
|
89
92
|
/* @__PURE__ */ a(
|
|
90
|
-
|
|
93
|
+
z,
|
|
91
94
|
{
|
|
92
95
|
in: t,
|
|
93
|
-
classNames: `${
|
|
96
|
+
classNames: `${D}-input`,
|
|
94
97
|
addEndListener: () => {
|
|
95
98
|
},
|
|
96
99
|
children: /* @__PURE__ */ a(
|
|
97
|
-
|
|
100
|
+
H,
|
|
98
101
|
{
|
|
99
102
|
"aria-hidden": !t,
|
|
100
|
-
className: `${
|
|
103
|
+
className: `${r}__input`,
|
|
101
104
|
id: "search-input",
|
|
102
105
|
hideLabel: !0,
|
|
103
|
-
labelText:
|
|
104
|
-
placeholder: t ?
|
|
106
|
+
labelText: d,
|
|
107
|
+
placeholder: t ? w : "",
|
|
105
108
|
type: "text",
|
|
106
|
-
defaultValue:
|
|
107
|
-
invalid:
|
|
108
|
-
invalidText:
|
|
109
|
-
onKeyDown:
|
|
109
|
+
defaultValue: R,
|
|
110
|
+
invalid: l === "invalid",
|
|
111
|
+
invalidText: k,
|
|
112
|
+
onKeyDown: $,
|
|
110
113
|
onChange: T,
|
|
111
|
-
ref:
|
|
114
|
+
ref: h
|
|
112
115
|
}
|
|
113
116
|
)
|
|
114
117
|
}
|
|
115
118
|
),
|
|
116
119
|
/* @__PURE__ */ a(
|
|
117
|
-
|
|
120
|
+
q,
|
|
118
121
|
{
|
|
119
|
-
className:
|
|
120
|
-
searchButtonText:
|
|
121
|
-
state:
|
|
122
|
-
testId:
|
|
122
|
+
className: r,
|
|
123
|
+
searchButtonText: d,
|
|
124
|
+
state: l,
|
|
125
|
+
testId: m,
|
|
123
126
|
isSearchExpanded: t,
|
|
124
|
-
setIsSearchExpanded:
|
|
127
|
+
setIsSearchExpanded: g,
|
|
128
|
+
onCancel: i
|
|
125
129
|
}
|
|
126
130
|
)
|
|
127
131
|
]
|
|
128
132
|
}
|
|
129
133
|
),
|
|
130
|
-
|
|
131
|
-
|
|
134
|
+
s && s.length > 2 ? /* @__PURE__ */ a(
|
|
135
|
+
A,
|
|
132
136
|
{
|
|
133
|
-
autoCompleteResults:
|
|
134
|
-
isLoading:
|
|
135
|
-
loadingText:
|
|
136
|
-
onKeyDown:
|
|
137
|
-
userInputValue:
|
|
138
|
-
children: /* @__PURE__ */ a("li", { className: `${
|
|
139
|
-
|
|
137
|
+
autoCompleteResults: E,
|
|
138
|
+
isLoading: l === "loading",
|
|
139
|
+
loadingText: C,
|
|
140
|
+
onKeyDown: $,
|
|
141
|
+
userInputValue: s,
|
|
142
|
+
children: /* @__PURE__ */ a("li", { className: `${r}__result`, children: /* @__PURE__ */ a(
|
|
143
|
+
O,
|
|
140
144
|
{
|
|
141
|
-
href: ((
|
|
142
|
-
children: /* @__PURE__ */ a("p", { children:
|
|
145
|
+
href: ((e) => I(S(e)))(s),
|
|
146
|
+
children: /* @__PURE__ */ a("p", { children: L(s) })
|
|
143
147
|
}
|
|
144
148
|
) }, "viewAllSearchResults")
|
|
145
149
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SearchProps } from './Search';
|
|
2
2
|
import { ComponentProps } from 'react';
|
|
3
|
-
export declare const SearchButton: ({ state, isSearchExpanded, setIsSearchExpanded, searchButtonText, className, testId, ...props }: {
|
|
3
|
+
export declare const SearchButton: ({ state, isSearchExpanded, setIsSearchExpanded, searchButtonText, className, testId, onCancel, ...props }: {
|
|
4
4
|
testId: string;
|
|
5
5
|
isSearchExpanded: boolean;
|
|
6
6
|
setIsSearchExpanded: React.Dispatch<React.SetStateAction<boolean>>;
|
|
7
|
-
} & Pick<SearchProps, "state" | "searchButtonText"> & import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement>) => import("react/jsx-runtime").JSX.Element | null;
|
|
7
|
+
} & Pick<SearchProps, "onCancel" | "state" | "searchButtonText"> & import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement>) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
state:
|
|
6
|
-
isSearchExpanded:
|
|
7
|
-
setIsSearchExpanded:
|
|
8
|
-
searchButtonText:
|
|
1
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import e from "../../assets/search.svg.js";
|
|
3
|
+
import l from "../../assets/close.svg.js";
|
|
4
|
+
const p = ({
|
|
5
|
+
state: $,
|
|
6
|
+
isSearchExpanded: u,
|
|
7
|
+
setIsSearchExpanded: _,
|
|
8
|
+
searchButtonText: a,
|
|
9
9
|
className: t,
|
|
10
10
|
testId: o,
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
onCancel: i,
|
|
12
|
+
...b
|
|
13
|
+
}) => u ? u ? /* @__PURE__ */ r(
|
|
13
14
|
"button",
|
|
14
15
|
{
|
|
15
|
-
...
|
|
16
|
+
...b,
|
|
16
17
|
type: "button",
|
|
17
18
|
"data-testid": `${o}-close-button`,
|
|
18
19
|
"aria-label": "Close Search",
|
|
19
20
|
className: `${t}__button ${t}__button--close`,
|
|
20
|
-
onClick: (
|
|
21
|
-
|
|
21
|
+
onClick: (n) => {
|
|
22
|
+
i == null || i(), _(!1), n.stopPropagation();
|
|
22
23
|
},
|
|
23
|
-
children: /* @__PURE__ */
|
|
24
|
+
children: /* @__PURE__ */ r(l, { "data-testid": `${o}-form-icon`, className: `${t}__button__icon` })
|
|
24
25
|
}
|
|
25
|
-
) : null : /* @__PURE__ */
|
|
26
|
+
) : null : /* @__PURE__ */ r(
|
|
26
27
|
"button",
|
|
27
28
|
{
|
|
28
|
-
...
|
|
29
|
+
...b,
|
|
29
30
|
type: "button",
|
|
30
31
|
"data-testid": `${o}-button`,
|
|
31
|
-
"aria-label":
|
|
32
|
+
"aria-label": a,
|
|
32
33
|
className: `${t}__button ${t}__button--search`,
|
|
33
|
-
onClick: (
|
|
34
|
-
|
|
34
|
+
onClick: (n) => {
|
|
35
|
+
_(!0), n.stopPropagation();
|
|
35
36
|
},
|
|
36
|
-
children: /* @__PURE__ */
|
|
37
|
+
children: /* @__PURE__ */ r(e, { "data-testid": `${o}-button-icon`, className: `${t}__button__icon` })
|
|
37
38
|
}
|
|
38
39
|
);
|
|
39
40
|
export {
|
|
40
|
-
|
|
41
|
+
p as SearchButton
|
|
41
42
|
};
|