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