@netlify/spark-ui 0.0.25 → 0.0.27

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.
@@ -67,18 +67,17 @@ function K(t) {
67
67
  function J(t = { className: "", children: null }) {
68
68
  const [s, o] = N(!1);
69
69
  v(() => {
70
+ let f;
70
71
  const y = () => {
71
- window.pagefind && (o(!0), d && clearInterval(d));
72
+ window.pagefind && (o(!0), f && clearInterval(f));
72
73
  };
73
- y();
74
- const d = setInterval(y, 100);
75
- return () => clearInterval(d);
74
+ return y(), f = setInterval(y, 100), () => clearInterval(f);
76
75
  }, []);
77
- const { children: c, className: l, ...e } = t, { state: r, actions: a } = L(), [u, S] = N(!1), f = () => S(!0), m = () => S(!1), i = O(null), g = K(m);
78
- return k(s, f), j(s, a.setSearchTerm, f), E(s, u, f, m), P(s, i, u, m), v(() => {
76
+ const { children: c, className: l, ...e } = t, { state: r, actions: a } = L(), [u, S] = N(!1), m = () => S(!0), d = () => S(!1), i = O(null), g = K(d);
77
+ return k(s, m), j(s, a.setSearchTerm, m), E(s, u, m, d), P(s, i, u, d), v(() => {
79
78
  i.current && (u ? i.current.showModal() : i.current.close());
80
79
  }, [u]), /* @__PURE__ */ n(T, { ref: i, className: A(l, "n-search-modal"), ...e, children: /* @__PURE__ */ n("div", { ref: g, className: "n-search-container", children: [
81
- /* @__PURE__ */ n("form", { className: "n-search-bar", children: /* @__PURE__ */ n(I, { setSearchTerm: a.setSearchTerm, initialValue: r.searchTerm }) }),
80
+ /* @__PURE__ */ n(I, { setSearchTerm: a.setSearchTerm, initialValue: r.searchTerm }),
82
81
  /* @__PURE__ */ n(
83
82
  b,
84
83
  {
@@ -4,27 +4,27 @@ import t from "./SearchHeading/SearchHeading.js";
4
4
  import a from "./SearchLink/SearchLink.js";
5
5
  const h = ({
6
6
  searchLoading: i,
7
- searchTerm: n,
8
- results: r
7
+ searchTerm: r,
8
+ results: n
9
9
  }) => {
10
10
  if (i)
11
11
  return /* @__PURE__ */ e(t, { children: [
12
12
  "Searching for ",
13
- /* @__PURE__ */ e("span", { className: "n-search-term", children: n }),
13
+ /* @__PURE__ */ e("span", { className: "n-search-term", children: r }),
14
14
  " ..."
15
15
  ] });
16
- if (!r || r.length === 0)
16
+ if (!n || n.length === 0)
17
17
  return /* @__PURE__ */ e(t, { children: [
18
18
  "0 results for ",
19
- /* @__PURE__ */ e("span", { className: "n-search-term", children: n })
19
+ /* @__PURE__ */ e("span", { className: "n-search-term", children: r })
20
20
  ] });
21
- const l = o(() => r.map((s, c) => /* @__PURE__ */ e("li", { className: "n-results-list-item", children: /* @__PURE__ */ e(a, { ...s }) }, c)), [r]);
21
+ const l = o(() => n.map((s, c) => /* @__PURE__ */ e("li", { className: "n-results-list-item", children: /* @__PURE__ */ e(a, { ...s }) }, c)), [n]);
22
22
  return /* @__PURE__ */ e("ul", { className: "n-results-list", role: "list", children: l });
23
23
  };
24
24
  function N({
25
25
  searchLoading: i,
26
- searchTerm: n,
27
- results: r,
26
+ searchTerm: r,
27
+ results: n,
28
28
  children: l
29
29
  }) {
30
30
  return /* @__PURE__ */ e("div", { className: "n-search-window", children: /* @__PURE__ */ e("div", { className: "search-links", children: [
@@ -33,7 +33,14 @@ function N({
33
33
  label: "Ask Netlify AI",
34
34
  url: "https://docs.netlify.com/ask-netlify/"
35
35
  } }),
36
- n ? /* @__PURE__ */ e(h, { searchLoading: i, searchTerm: n, results: r }) : l || null
36
+ r && r.length > 3 ? /* @__PURE__ */ e(
37
+ h,
38
+ {
39
+ searchLoading: i,
40
+ searchTerm: r,
41
+ results: n
42
+ }
43
+ ) : l || null
37
44
  ] }) });
38
45
  }
39
46
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@netlify/spark-ui",
3
3
  "description": "Assets, design tokens, components, and utilities",
4
- "version": "0.0.25",
4
+ "version": "0.0.27",
5
5
  "type": "module",
6
6
  "main": "dist/components/preact/index.js",
7
7
  "types": "dist/components/preact/index.d.ts",
@@ -131,9 +131,10 @@
131
131
  .n-search-modal {
132
132
  transition: display .2s allow-discrete, overlay .2s allow-discrete;
133
133
  animation: closeSearch .2s forwards;
134
- &[open] {
135
- animation: openSearch .2s forwards;
136
- }
134
+ }
135
+
136
+ .n-search-modal[open] {
137
+ animation: openSearch .2s forwards;
137
138
  }
138
139
 
139
140
  @keyframes openSearch {
@@ -27,6 +27,8 @@ function SearchModal(props: Props = {className: '', children: null}) {
27
27
 
28
28
  // Poll for the existence of window.pagefind.
29
29
  useEffect(() => {
30
+ let intervalId:number;
31
+
30
32
  const checkForPagefind = () => {
31
33
  if (window.pagefind) {
32
34
  setIsPagefindLoaded(true);
@@ -36,7 +38,7 @@ function SearchModal(props: Props = {className: '', children: null}) {
36
38
 
37
39
  // Check immediately and then start polling every 100ms.
38
40
  checkForPagefind();
39
- const intervalId = setInterval(checkForPagefind, 100);
41
+ intervalId = setInterval(checkForPagefind, 100);
40
42
 
41
43
  // Cleanup the interval when the component unmounts.
42
44
  return () => clearInterval(intervalId);
@@ -66,9 +68,7 @@ function SearchModal(props: Props = {className: '', children: null}) {
66
68
  return (
67
69
  <Modal ref={modalRef} className={cn(className, 'n-search-modal')} {...rest}>
68
70
  <div ref={containerRef} className="n-search-container">
69
- <form className="n-search-bar">
70
71
  <SearchInput setSearchTerm={actions.setSearchTerm} initialValue={state.searchTerm} />
71
- </form>
72
72
 
73
73
  <SearchWindow
74
74
  searchLoading={state.isLoading}
@@ -20,9 +20,9 @@ const SearchResults: FunctionComponent<SearchResultsProps> = ({
20
20
 
21
21
  if (!results || results.length === 0) {
22
22
  return (
23
- <SearchHeading>
24
- 0 results for <span className="n-search-term">{searchTerm}</span>
25
- </SearchHeading>
23
+ <SearchHeading>
24
+ 0 results for <span className="n-search-term">{searchTerm}</span>
25
+ </SearchHeading>
26
26
  );
27
27
  }
28
28
 
@@ -58,8 +58,12 @@ export default function SearchWindow({
58
58
  <div className="n-search-window">
59
59
  <div className="search-links">
60
60
  <SearchLink {...askNetlify} />
61
- {searchTerm ? (
62
- <SearchResults searchLoading={searchLoading} searchTerm={searchTerm} results={results} />
61
+ {searchTerm && searchTerm.length > 3 ? (
62
+ <SearchResults
63
+ searchLoading={searchLoading}
64
+ searchTerm={searchTerm}
65
+ results={results}
66
+ />
63
67
  ) : DefaultWindow ? (
64
68
  DefaultWindow
65
69
  ) : null}