@garagem-ai/site-sdk 0.4.0 → 0.4.1
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/README.md +41 -8
- package/dist/index.d.mts +7 -58
- package/dist/index.d.ts +7 -58
- package/dist/index.js +59 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +33 -6
- package/dist/react.d.ts +33 -6
- package/dist/react.js +517 -463
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +515 -462
- package/dist/react.mjs.map +1 -1
- package/dist/{listing-card-model-D7iR4asd.d.mts → search-engine-D4EZkNrQ.d.mts} +67 -1
- package/dist/{listing-card-model-D7iR4asd.d.ts → search-engine-D4EZkNrQ.d.ts} +67 -1
- package/package.json +9 -4
- package/src/index.ts +2 -0
- package/src/presentation.ts +7 -0
- package/src/react/filter-panel.tsx +39 -42
- package/src/react/icons.tsx +46 -0
- package/src/react/index.ts +7 -1
- package/src/react/listing-card.tsx +14 -71
- package/src/react/search-chrome.tsx +24 -23
- package/src/react/search-page.tsx +210 -111
- package/src/react/search-pagination.tsx +50 -40
- package/src/react/search-query-form.tsx +31 -26
- package/src/react/search.css +717 -0
- package/src/react/styles/index.ts +1 -0
- package/src/react/styles/search-chrome-css.generated.ts +5 -0
- package/src/react/styles/search-chrome-styles.tsx +12 -0
- package/src/react/types.ts +18 -0
- package/src/react/use-public-search.ts +7 -0
- package/src/search-engine.ts +79 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import type { ReactElement } from "react";
|
|
3
|
+
import type { MouseEvent, ReactElement } from "react";
|
|
4
4
|
import Link from "next/link";
|
|
5
5
|
|
|
6
|
-
import { paginationPages } from "../search-engine";
|
|
7
|
-
import { cn } from "./cn";
|
|
6
|
+
import { hrefWithExplicitPage, paginationPages } from "../search-engine";
|
|
8
7
|
|
|
9
8
|
export type SearchPaginationProps = {
|
|
10
9
|
page: number;
|
|
11
10
|
totalPages: number;
|
|
12
11
|
hrefForPage: (page: number) => string;
|
|
12
|
+
onNavigate?: (href: string) => void;
|
|
13
13
|
className?: string;
|
|
14
14
|
};
|
|
15
15
|
|
|
@@ -18,36 +18,44 @@ function NavItem({
|
|
|
18
18
|
label,
|
|
19
19
|
disabled,
|
|
20
20
|
current,
|
|
21
|
-
|
|
21
|
+
onNavigate,
|
|
22
22
|
}: {
|
|
23
23
|
href?: string;
|
|
24
24
|
label: string;
|
|
25
25
|
disabled?: boolean;
|
|
26
26
|
current?: boolean;
|
|
27
|
-
|
|
27
|
+
onNavigate?: (href: string) => void;
|
|
28
28
|
}): ReactElement {
|
|
29
|
-
const itemClass = cn(
|
|
30
|
-
"inline-flex size-8 cursor-pointer items-center justify-center rounded-md border text-xs font-medium md:size-9",
|
|
31
|
-
current && "bg-primary text-primary-foreground",
|
|
32
|
-
disabled && "cursor-not-allowed text-muted-foreground",
|
|
33
|
-
className
|
|
34
|
-
);
|
|
35
29
|
if (disabled || !href || current) {
|
|
36
30
|
return (
|
|
37
|
-
<li
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
<li
|
|
32
|
+
data-slot="search-pagination-item"
|
|
33
|
+
data-current={current ? "true" : undefined}
|
|
34
|
+
data-disabled={disabled ? "true" : undefined}
|
|
35
|
+
>
|
|
36
|
+
<span>{label}</span>
|
|
41
37
|
</li>
|
|
42
38
|
);
|
|
43
39
|
}
|
|
40
|
+
|
|
41
|
+
function handleClick(event: MouseEvent<HTMLAnchorElement>) {
|
|
42
|
+
if (!onNavigate || !href) return;
|
|
43
|
+
if (
|
|
44
|
+
event.metaKey ||
|
|
45
|
+
event.ctrlKey ||
|
|
46
|
+
event.shiftKey ||
|
|
47
|
+
event.altKey ||
|
|
48
|
+
event.button !== 0
|
|
49
|
+
) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
onNavigate(href);
|
|
54
|
+
}
|
|
55
|
+
|
|
44
56
|
return (
|
|
45
|
-
<li
|
|
46
|
-
<Link
|
|
47
|
-
href={href}
|
|
48
|
-
className="flex size-full items-center justify-center"
|
|
49
|
-
aria-label={label}
|
|
50
|
-
>
|
|
57
|
+
<li data-slot="search-pagination-item">
|
|
58
|
+
<Link href={href} onClick={handleClick} aria-label={label}>
|
|
51
59
|
{label}
|
|
52
60
|
</Link>
|
|
53
61
|
</li>
|
|
@@ -58,51 +66,53 @@ export function SearchPagination({
|
|
|
58
66
|
page,
|
|
59
67
|
totalPages,
|
|
60
68
|
hrefForPage,
|
|
69
|
+
onNavigate,
|
|
61
70
|
className,
|
|
62
71
|
}: SearchPaginationProps): ReactElement | null {
|
|
63
72
|
if (totalPages <= 1) return null;
|
|
64
|
-
const
|
|
65
|
-
const desktop = paginationPages(page, totalPages, 2);
|
|
73
|
+
const pages = paginationPages(page, totalPages, 2);
|
|
66
74
|
return (
|
|
67
75
|
<nav
|
|
68
76
|
data-slot="search-pagination"
|
|
69
|
-
className={
|
|
77
|
+
className={className}
|
|
70
78
|
aria-label="Paginação"
|
|
71
79
|
>
|
|
72
|
-
<ul
|
|
73
|
-
<NavItem href={hrefForPage(1)} label="‹‹" disabled={page <= 1} />
|
|
80
|
+
<ul>
|
|
74
81
|
<NavItem
|
|
75
|
-
href={hrefForPage(
|
|
82
|
+
href={hrefWithExplicitPage(hrefForPage(1), 1)}
|
|
83
|
+
label="‹‹"
|
|
84
|
+
disabled={page <= 1}
|
|
85
|
+
onNavigate={onNavigate}
|
|
86
|
+
/>
|
|
87
|
+
<NavItem
|
|
88
|
+
href={hrefWithExplicitPage(
|
|
89
|
+
hrefForPage(Math.max(1, page - 1)),
|
|
90
|
+
Math.max(1, page - 1)
|
|
91
|
+
)}
|
|
76
92
|
label="‹"
|
|
77
93
|
disabled={page <= 1}
|
|
94
|
+
onNavigate={onNavigate}
|
|
78
95
|
/>
|
|
79
|
-
{
|
|
80
|
-
<NavItem
|
|
81
|
-
key={`m-${n}`}
|
|
82
|
-
href={hrefForPage(n)}
|
|
83
|
-
label={String(n)}
|
|
84
|
-
current={n === page}
|
|
85
|
-
className="md:hidden"
|
|
86
|
-
/>
|
|
87
|
-
))}
|
|
88
|
-
{desktop.map((n) => (
|
|
96
|
+
{pages.map((n) => (
|
|
89
97
|
<NavItem
|
|
90
|
-
key={
|
|
91
|
-
href={hrefForPage(n)}
|
|
98
|
+
key={n}
|
|
99
|
+
href={hrefWithExplicitPage(hrefForPage(n), n)}
|
|
92
100
|
label={String(n)}
|
|
93
101
|
current={n === page}
|
|
94
|
-
|
|
102
|
+
onNavigate={onNavigate}
|
|
95
103
|
/>
|
|
96
104
|
))}
|
|
97
105
|
<NavItem
|
|
98
106
|
href={hrefForPage(Math.min(totalPages, page + 1))}
|
|
99
107
|
label="›"
|
|
100
108
|
disabled={page >= totalPages}
|
|
109
|
+
onNavigate={onNavigate}
|
|
101
110
|
/>
|
|
102
111
|
<NavItem
|
|
103
112
|
href={hrefForPage(totalPages)}
|
|
104
113
|
label="››"
|
|
105
114
|
disabled={page >= totalPages}
|
|
115
|
+
onNavigate={onNavigate}
|
|
106
116
|
/>
|
|
107
117
|
</ul>
|
|
108
118
|
</nav>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import type { FormEvent, ReactElement } from "react";
|
|
3
|
+
import type { FormEvent, ReactElement, ReactNode } from "react";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { SearchClearIcon, SearchLensIcon } from "./icons";
|
|
6
6
|
|
|
7
7
|
export type SearchQueryFormProps = {
|
|
8
8
|
value: string;
|
|
@@ -10,6 +10,9 @@ export type SearchQueryFormProps = {
|
|
|
10
10
|
onSubmit: () => void;
|
|
11
11
|
onClear: () => void;
|
|
12
12
|
className?: string;
|
|
13
|
+
iconClassName?: string;
|
|
14
|
+
searchIcon?: ReactNode;
|
|
15
|
+
clearIcon?: ReactNode;
|
|
13
16
|
};
|
|
14
17
|
|
|
15
18
|
export function SearchQueryForm({
|
|
@@ -18,6 +21,9 @@ export function SearchQueryForm({
|
|
|
18
21
|
onSubmit,
|
|
19
22
|
onClear,
|
|
20
23
|
className,
|
|
24
|
+
iconClassName,
|
|
25
|
+
searchIcon,
|
|
26
|
+
clearIcon,
|
|
21
27
|
}: SearchQueryFormProps): ReactElement {
|
|
22
28
|
function handleSubmit(event: FormEvent) {
|
|
23
29
|
event.preventDefault();
|
|
@@ -29,45 +35,44 @@ export function SearchQueryForm({
|
|
|
29
35
|
role="search"
|
|
30
36
|
data-slot="search-query"
|
|
31
37
|
onSubmit={handleSubmit}
|
|
32
|
-
className={
|
|
38
|
+
className={className}
|
|
33
39
|
>
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
className="min-h-12 w-full rounded-xl border border-border bg-background px-4 pr-20 outline-none focus:border-primary"
|
|
52
|
-
/>
|
|
40
|
+
<label htmlFor="garagem-search-q" data-slot="search-label">
|
|
41
|
+
Busca
|
|
42
|
+
</label>
|
|
43
|
+
<div data-slot="search-query-field">
|
|
44
|
+
<input
|
|
45
|
+
id="garagem-search-q"
|
|
46
|
+
name="q"
|
|
47
|
+
type="text"
|
|
48
|
+
inputMode="search"
|
|
49
|
+
autoComplete="off"
|
|
50
|
+
enterKeyHint="search"
|
|
51
|
+
value={value}
|
|
52
|
+
onChange={(event) => onChange(event.target.value)}
|
|
53
|
+
placeholder="Busque por bairro, rua ou código"
|
|
54
|
+
data-slot="search-query-input"
|
|
55
|
+
/>
|
|
56
|
+
<div data-slot="search-query-actions">
|
|
53
57
|
{value ? (
|
|
54
58
|
<button
|
|
55
59
|
type="button"
|
|
56
60
|
title="Limpar busca"
|
|
57
61
|
aria-label="Limpar busca"
|
|
58
62
|
onClick={onClear}
|
|
59
|
-
|
|
63
|
+
data-slot="search-icon-button"
|
|
64
|
+
data-kind="clear"
|
|
60
65
|
>
|
|
61
|
-
|
|
66
|
+
{clearIcon ?? <SearchClearIcon className={iconClassName} />}
|
|
62
67
|
</button>
|
|
63
68
|
) : null}
|
|
64
69
|
<button
|
|
65
70
|
type="submit"
|
|
66
71
|
title="Buscar"
|
|
67
72
|
aria-label="Buscar"
|
|
68
|
-
|
|
73
|
+
data-slot="search-icon-button"
|
|
69
74
|
>
|
|
70
|
-
|
|
75
|
+
{searchIcon ?? <SearchLensIcon className={iconClassName} />}
|
|
71
76
|
</button>
|
|
72
77
|
</div>
|
|
73
78
|
</div>
|