@c-rex/components 0.1.32 → 0.1.36
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.
- package/package.json +1 -1
- package/src/autocomplete.tsx +60 -37
- package/src/results/pagination.tsx +18 -8
- package/src/search-input.tsx +1 -1
- /package/src/results/{cards.analysis.md → analysis/cards.analysis.md} +0 -0
- /package/src/results/{dialog-filter.analysis.md → analysis/dialog-filter.analysis.md} +0 -0
- /package/src/results/{empty.analysis.md → analysis/empty.analysis.md} +0 -0
- /package/src/results/{filter-navbar.analysis.md → analysis/filter-navbar.analysis.md} +0 -0
- /package/src/results/{pagination.analysis.md → analysis/pagination.analysis.md} +0 -0
- /package/src/results/{table-with-images.analysis.md → analysis/table-with-images.analysis.md} +0 -0
- /package/src/results/{table.analysis.md → analysis/table.analysis.md} +0 -0
package/package.json
CHANGED
package/src/autocomplete.tsx
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@c-rex/ui/input-group";
|
|
5
5
|
import { useTranslations } from "next-intl";
|
|
6
6
|
import { SuggestionQueryParams } from "@c-rex/interfaces";
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import { useRouter } from 'next/navigation';
|
|
7
|
+
import { X } from "lucide-react";
|
|
8
|
+
import { useRouter, useSearchParams } from "next/navigation";
|
|
10
9
|
import { suggestionRequest } from "./generated/create-suggestions-request";
|
|
11
10
|
import { useQueryState } from "nuqs";
|
|
12
11
|
|
|
@@ -18,11 +17,13 @@ export type AutoCompleteProps = {
|
|
|
18
17
|
onSelectParams?: { key: string, value: string }[];
|
|
19
18
|
onSelectPath: string
|
|
20
19
|
inputClass?: string
|
|
20
|
+
keepParams?: boolean;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export const AutoComplete = ({
|
|
24
24
|
initialValue = "",
|
|
25
25
|
embedded = true,
|
|
26
|
+
keepParams = false,
|
|
26
27
|
endpoint,
|
|
27
28
|
queryParams,
|
|
28
29
|
onSelectParams,
|
|
@@ -33,6 +34,7 @@ export const AutoComplete = ({
|
|
|
33
34
|
const [pkg] = useQueryState("package");
|
|
34
35
|
|
|
35
36
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
37
|
+
const searchParams = useSearchParams();
|
|
36
38
|
const router = useRouter();
|
|
37
39
|
const [open, setOpen] = useState(false);
|
|
38
40
|
const [query, setQuery] = useState(initialValue);
|
|
@@ -46,30 +48,33 @@ export const AutoComplete = ({
|
|
|
46
48
|
const results = await suggestionRequest({ endpoint, prefix, queryParams: params });
|
|
47
49
|
|
|
48
50
|
return results.data;
|
|
49
|
-
}, [endpoint, queryParams]);
|
|
51
|
+
}, [endpoint, pkg, queryParams]);
|
|
50
52
|
|
|
51
53
|
const handleSelect = (value: string) => {
|
|
52
54
|
setQuery(value);
|
|
53
55
|
setOpen(false);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
const nextParams = new URLSearchParams(keepParams ? searchParams.toString() : "");
|
|
57
|
+
nextParams.set("page", "1");
|
|
58
|
+
nextParams.set("search", value);
|
|
59
|
+
onSelectParams?.forEach(param => {
|
|
60
|
+
nextParams.set(param.key, param.value);
|
|
61
|
+
});
|
|
56
62
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const searchSettings = useSearchSettingsStore.getState();
|
|
63
|
+
router.push(`${onSelectPath}?${nextParams.toString()}`);
|
|
64
|
+
};
|
|
60
65
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
const clearSearch = () => {
|
|
67
|
+
setQuery("");
|
|
68
|
+
setOpen(false);
|
|
69
|
+
const nextParams = new URLSearchParams(keepParams ? searchParams.toString() : "");
|
|
70
|
+
nextParams.set("page", "1");
|
|
71
|
+
nextParams.delete("search");
|
|
72
|
+
const queryString = nextParams.toString();
|
|
67
73
|
|
|
68
74
|
onSelectParams?.forEach(param => {
|
|
69
|
-
|
|
75
|
+
nextParams.set(param.key, param.value);
|
|
70
76
|
});
|
|
71
|
-
|
|
72
|
-
router.push(`${onSelectPath}?${params.toString()}`);
|
|
77
|
+
router.push(queryString ? `${onSelectPath}?${queryString}` : onSelectPath);
|
|
73
78
|
};
|
|
74
79
|
|
|
75
80
|
useEffect(() => {
|
|
@@ -105,23 +110,37 @@ export const AutoComplete = ({
|
|
|
105
110
|
|
|
106
111
|
return (
|
|
107
112
|
<div className="relative flex-1" ref={containerRef}>
|
|
108
|
-
<
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
e.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
113
|
+
<InputGroup variant={embedded ? "embedded" : "default"}>
|
|
114
|
+
<InputGroupInput
|
|
115
|
+
variant={embedded ? "embedded" : undefined}
|
|
116
|
+
className={inputClass}
|
|
117
|
+
type="text"
|
|
118
|
+
placeholder={t("search")}
|
|
119
|
+
value={query}
|
|
120
|
+
onChange={(e) => {
|
|
121
|
+
setQuery(e.target.value);
|
|
122
|
+
setOpen(true);
|
|
123
|
+
}}
|
|
124
|
+
onKeyDown={(e) => {
|
|
125
|
+
if (e.key === "Enter") {
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
handleSelect(query);
|
|
128
|
+
}
|
|
129
|
+
}}
|
|
130
|
+
/>
|
|
131
|
+
{query.length > 0 && (
|
|
132
|
+
<InputGroupAddon align="inline-end">
|
|
133
|
+
<InputGroupButton
|
|
134
|
+
size="icon-xs"
|
|
135
|
+
variant="ghost"
|
|
136
|
+
aria-label="Clear search"
|
|
137
|
+
onClick={clearSearch}
|
|
138
|
+
>
|
|
139
|
+
<X className="size-3" />
|
|
140
|
+
</InputGroupButton>
|
|
141
|
+
</InputGroupAddon>
|
|
142
|
+
)}
|
|
143
|
+
</InputGroup>
|
|
125
144
|
|
|
126
145
|
{open && (
|
|
127
146
|
<ul className="suggestions-list absolute z-10 w-full bg-white border border-gray-300 rounded-lg shadow-lg max-h-60 overflow-y-auto">
|
|
@@ -139,7 +158,11 @@ export const AutoComplete = ({
|
|
|
139
158
|
<li
|
|
140
159
|
key={option}
|
|
141
160
|
className="px-4 py-2 hover:bg-accent cursor-pointer text-sm"
|
|
142
|
-
onClick={() =>
|
|
161
|
+
onClick={() => {
|
|
162
|
+
//handleSelect(`"${option}"`)
|
|
163
|
+
// TODO: check if the quotes are necessary
|
|
164
|
+
handleSelect(option)
|
|
165
|
+
}}
|
|
143
166
|
>
|
|
144
167
|
{option}
|
|
145
168
|
</li>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { FC } from "react";
|
|
3
|
+
import { FC, MouseEvent } from "react";
|
|
4
4
|
import {
|
|
5
5
|
Pagination as PaginationUI,
|
|
6
6
|
PaginationContent,
|
|
@@ -19,15 +19,25 @@ interface PaginationProps {
|
|
|
19
19
|
export const Pagination: FC<PaginationProps> = ({ pageInfo }) => {
|
|
20
20
|
const disabledClass = "opacity-50 pointer-events-none";
|
|
21
21
|
|
|
22
|
-
const [
|
|
22
|
+
const [, setPage] = useQueryState('page',
|
|
23
23
|
parseAsInteger.withOptions({
|
|
24
24
|
history: 'push',
|
|
25
25
|
shallow: false,
|
|
26
26
|
})
|
|
27
27
|
)
|
|
28
28
|
|
|
29
|
-
const onChangePage = (pageNumber: number) => {
|
|
30
|
-
|
|
29
|
+
const onChangePage = (event: MouseEvent<HTMLAnchorElement>, pageNumber: number) => {
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
pageNumber < 1
|
|
34
|
+
|| (pageInfo.pageCount !== undefined && pageNumber > pageInfo.pageCount)
|
|
35
|
+
|| pageNumber === pageInfo.pageNumber
|
|
36
|
+
) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
void setPage(pageNumber);
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
return (
|
|
@@ -37,7 +47,7 @@ export const Pagination: FC<PaginationProps> = ({ pageInfo }) => {
|
|
|
37
47
|
<PaginationPrevious
|
|
38
48
|
href="#"
|
|
39
49
|
className={pageInfo.pageNumber === 1 ? disabledClass : ""}
|
|
40
|
-
onClick={() => onChangePage(pageInfo.pageNumber! - 1)}
|
|
50
|
+
onClick={(event) => onChangePage(event, pageInfo.pageNumber! - 1)}
|
|
41
51
|
/>
|
|
42
52
|
</PaginationItem>
|
|
43
53
|
|
|
@@ -46,7 +56,7 @@ export const Pagination: FC<PaginationProps> = ({ pageInfo }) => {
|
|
|
46
56
|
<PaginationLink
|
|
47
57
|
href="#"
|
|
48
58
|
isActive={page === pageInfo.pageNumber}
|
|
49
|
-
onClick={() => onChangePage(page)}
|
|
59
|
+
onClick={(event) => onChangePage(event, page)}
|
|
50
60
|
>
|
|
51
61
|
{page}
|
|
52
62
|
</PaginationLink>
|
|
@@ -61,11 +71,11 @@ export const Pagination: FC<PaginationProps> = ({ pageInfo }) => {
|
|
|
61
71
|
<PaginationItem>
|
|
62
72
|
<PaginationNext
|
|
63
73
|
href="#"
|
|
64
|
-
onClick={() => onChangePage(pageInfo.pageNumber! + 1)}
|
|
74
|
+
onClick={(event) => onChangePage(event, pageInfo.pageNumber! + 1)}
|
|
65
75
|
className={pageInfo.pageNumber === pageInfo.pageCount ? disabledClass : ""}
|
|
66
76
|
/>
|
|
67
77
|
</PaginationItem>
|
|
68
78
|
</PaginationContent>
|
|
69
79
|
</PaginationUI>
|
|
70
80
|
)
|
|
71
|
-
}
|
|
81
|
+
}
|
package/src/search-input.tsx
CHANGED
|
@@ -44,7 +44,7 @@ export const SearchInput: FC<Props> = ({
|
|
|
44
44
|
<>
|
|
45
45
|
<Search className="shrink-0 opacity-50" />
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
<AutocompleteComponent
|
|
49
49
|
onSelectParams={
|
|
50
50
|
(pkg && checked && showPkgFilter) ? [{ key: "packages", value: pkg }] : []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/results/{table-with-images.analysis.md → analysis/table-with-images.analysis.md}
RENAMED
|
File without changes
|
|
File without changes
|