@garagem-ai/site-sdk 0.3.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 +59 -3
- package/dist/index.d.mts +27 -361
- package/dist/index.d.ts +27 -361
- package/dist/index.js +530 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +493 -46
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +163 -0
- package/dist/react.d.ts +163 -0
- package/dist/react.js +2124 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +2083 -0
- package/dist/react.mjs.map +1 -0
- package/dist/search-engine-D4EZkNrQ.d.mts +468 -0
- package/dist/search-engine-D4EZkNrQ.d.ts +468 -0
- package/package.json +42 -4
- package/src/fetchers.ts +27 -18
- package/src/index.ts +44 -0
- package/src/internal/url.ts +14 -0
- package/src/listing-card-model.ts +90 -0
- package/src/presentation.ts +79 -0
- package/src/react/cn.ts +3 -0
- package/src/react/filter-panel.tsx +248 -0
- package/src/react/icons.tsx +46 -0
- package/src/react/index.ts +26 -0
- package/src/react/listing-card.tsx +86 -0
- package/src/react/search-chrome.tsx +73 -0
- package/src/react/search-page.tsx +465 -0
- package/src/react/search-pagination.tsx +120 -0
- package/src/react/search-query-form.tsx +81 -0
- 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 +106 -0
- package/src/react/use-public-search.ts +304 -0
- package/src/search-engine.ts +483 -0
package/src/index.ts
CHANGED
|
@@ -84,6 +84,50 @@ export {
|
|
|
84
84
|
|
|
85
85
|
export { listingLookupKey, listingPublicPath } from "./listing-path";
|
|
86
86
|
|
|
87
|
+
export {
|
|
88
|
+
toListingCardModel,
|
|
89
|
+
listingLocationLabel,
|
|
90
|
+
type ListingCardModel,
|
|
91
|
+
} from "./listing-card-model";
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
SEARCH_CSS_RECIPE,
|
|
95
|
+
SEARCH_CSS_VARS,
|
|
96
|
+
formatAreaM2,
|
|
97
|
+
formatGroupedInteger,
|
|
98
|
+
formatListingPrice,
|
|
99
|
+
listingBusinessLabel,
|
|
100
|
+
parseGroupedInteger,
|
|
101
|
+
} from "./presentation";
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
FORBIDDEN_SEARCH_QUERY_KEYS,
|
|
105
|
+
SEARCH_SORT_RELEVANCE,
|
|
106
|
+
TOOLBAR_PRIMARY_FILTER_IDS,
|
|
107
|
+
applyPathFilter,
|
|
108
|
+
buildQueryListingsParams,
|
|
109
|
+
canonicalizeSearchHref,
|
|
110
|
+
clearStagedPathFilters,
|
|
111
|
+
countFacetChoices,
|
|
112
|
+
countOptionLabel,
|
|
113
|
+
displayPathLocation,
|
|
114
|
+
hrefForAppliedChange,
|
|
115
|
+
hrefForPathFilters,
|
|
116
|
+
hrefWithExplicitPage,
|
|
117
|
+
isListingDetailPath,
|
|
118
|
+
paginationPages,
|
|
119
|
+
pathFilterHasOption,
|
|
120
|
+
pathFilterValue,
|
|
121
|
+
publicSearchHref,
|
|
122
|
+
readPublicSearch,
|
|
123
|
+
searchHrefUsesLegacyFilterQuery,
|
|
124
|
+
searchSortOptions,
|
|
125
|
+
toolbarFilterIds,
|
|
126
|
+
visibleSearchFilters,
|
|
127
|
+
searchResultsHeading,
|
|
128
|
+
type LocationNameTables,
|
|
129
|
+
} from "./search-engine";
|
|
130
|
+
|
|
87
131
|
export {
|
|
88
132
|
composeSearchPublicPath,
|
|
89
133
|
parseSearchPublicPath,
|
package/src/internal/url.ts
CHANGED
|
@@ -8,6 +8,20 @@ export function normalizeBaseUrl(baseUrl: string | undefined): string {
|
|
|
8
8
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* v0 often writes `getListings({ siteId: resolveSiteId(host) })` without
|
|
13
|
+
* await, which interpolates as `/api/sites/[object Promise]/listings`.
|
|
14
|
+
*/
|
|
15
|
+
export async function coerceSiteId(siteId: unknown): Promise<string> {
|
|
16
|
+
const value = await Promise.resolve(siteId);
|
|
17
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
18
|
+
throw new TypeError(
|
|
19
|
+
"Garagem SDK: siteId must be a string. Await resolveSiteId(...) before getListings / getSearchUi / queryListings."
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
|
|
11
25
|
/**
|
|
12
26
|
* Serialize listing filters into URLSearchParams. Skips undefined/null
|
|
13
27
|
* values so the URL stays clean. Kept separate from the fetcher so it's
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { listingPublicPath } from "./listing-path";
|
|
2
|
+
import { formatListingPrice, listingBusinessLabel } from "./presentation";
|
|
3
|
+
import type {
|
|
4
|
+
Listing,
|
|
5
|
+
ListingBusinessType,
|
|
6
|
+
ListingPriceVisibility,
|
|
7
|
+
} from "./types";
|
|
8
|
+
|
|
9
|
+
/** Fields every listing card must have — no JSX. */
|
|
10
|
+
export type ListingCardModel = {
|
|
11
|
+
href: string;
|
|
12
|
+
title: string;
|
|
13
|
+
businessType: ListingBusinessType;
|
|
14
|
+
businessLabel: string;
|
|
15
|
+
priceVisibility: ListingPriceVisibility;
|
|
16
|
+
price: number | null;
|
|
17
|
+
priceLabel: string;
|
|
18
|
+
pricePeriod: string | null;
|
|
19
|
+
locationLabel: string;
|
|
20
|
+
propertyType: string | null;
|
|
21
|
+
coverSrc: string | null;
|
|
22
|
+
coverAlt: string;
|
|
23
|
+
bedrooms: number | null;
|
|
24
|
+
bathrooms: number | null;
|
|
25
|
+
parkingSpaces: number | null;
|
|
26
|
+
areaM2: number | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function listingLocationLabel(location: {
|
|
30
|
+
neighborhood?: string | null;
|
|
31
|
+
city?: string | null;
|
|
32
|
+
state?: string | null;
|
|
33
|
+
}): string {
|
|
34
|
+
return [location.neighborhood, location.city, location.state]
|
|
35
|
+
.map((part) => (part ? String(part).trim() : ""))
|
|
36
|
+
.filter(Boolean)
|
|
37
|
+
.join(", ");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function toListingCardModel(
|
|
41
|
+
listing: Pick<
|
|
42
|
+
Listing,
|
|
43
|
+
| "id"
|
|
44
|
+
| "listingCode"
|
|
45
|
+
| "path"
|
|
46
|
+
| "title"
|
|
47
|
+
| "businessType"
|
|
48
|
+
| "price"
|
|
49
|
+
| "priceVisibility"
|
|
50
|
+
| "coverImage"
|
|
51
|
+
> & {
|
|
52
|
+
property?: {
|
|
53
|
+
type?: string | null;
|
|
54
|
+
bedrooms?: number | null;
|
|
55
|
+
bathrooms?: number | null;
|
|
56
|
+
parkingSpaces?: number | null;
|
|
57
|
+
usableArea?: number | null;
|
|
58
|
+
totalArea?: number | null;
|
|
59
|
+
};
|
|
60
|
+
location?: {
|
|
61
|
+
neighborhood?: string | null;
|
|
62
|
+
city?: string | null;
|
|
63
|
+
state?: string | null;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
): ListingCardModel {
|
|
67
|
+
const isPrivate = listing.priceVisibility === "private";
|
|
68
|
+
const area = listing.property?.usableArea ?? listing.property?.totalArea;
|
|
69
|
+
return {
|
|
70
|
+
href: listingPublicPath(listing),
|
|
71
|
+
title: listing.title,
|
|
72
|
+
businessType: listing.businessType,
|
|
73
|
+
businessLabel: listingBusinessLabel(listing.businessType),
|
|
74
|
+
priceVisibility: listing.priceVisibility,
|
|
75
|
+
price: listing.price,
|
|
76
|
+
priceLabel: isPrivate ? "Sob consulta" : formatListingPrice(listing.price),
|
|
77
|
+
pricePeriod:
|
|
78
|
+
listing.businessType === "rental" && !isPrivate && listing.price != null
|
|
79
|
+
? "/mês"
|
|
80
|
+
: null,
|
|
81
|
+
locationLabel: listingLocationLabel(listing.location || {}),
|
|
82
|
+
propertyType: listing.property?.type ?? null,
|
|
83
|
+
coverSrc: listing.coverImage?.src ?? null,
|
|
84
|
+
coverAlt: listing.coverImage?.alt ?? listing.title,
|
|
85
|
+
bedrooms: listing.property?.bedrooms ?? null,
|
|
86
|
+
bathrooms: listing.property?.bathrooms ?? null,
|
|
87
|
+
parkingSpaces: listing.property?.parkingSpaces ?? null,
|
|
88
|
+
areaM2: area ?? null,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presentation helpers with no UI framework.
|
|
3
|
+
* React / React Native / Flutter adapters consume these formatters and
|
|
4
|
+
* CSS custom-property names; they must not live inside JSX.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const SEARCH_CSS_VARS = {
|
|
8
|
+
cardRadius: "--garagem-listing-card-radius",
|
|
9
|
+
cardGap: "--garagem-listing-card-gap",
|
|
10
|
+
priceSize: "--garagem-listing-price-size",
|
|
11
|
+
mediaRatio: "--garagem-listing-media-ratio",
|
|
12
|
+
controlHeight: "--garagem-search-control-height",
|
|
13
|
+
iconSize: "--garagem-search-icon-size",
|
|
14
|
+
skeleton: "--garagem-skeleton",
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
/** Paste into generated `globals.css` to override tokens. Layout lives in the chrome artifact. */
|
|
18
|
+
export const SEARCH_CSS_RECIPE = `:root {
|
|
19
|
+
${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
|
|
20
|
+
${SEARCH_CSS_VARS.cardGap}: 1.5rem;
|
|
21
|
+
${SEARCH_CSS_VARS.priceSize}: 1.125rem;
|
|
22
|
+
${SEARCH_CSS_VARS.mediaRatio}: 4 / 3;
|
|
23
|
+
${SEARCH_CSS_VARS.controlHeight}: 2.75rem;
|
|
24
|
+
${SEARCH_CSS_VARS.iconSize}: 1.25rem;
|
|
25
|
+
${SEARCH_CSS_VARS.skeleton}: var(--muted, #e7e5e4);
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
export function formatListingPrice(
|
|
30
|
+
amount: number | null | undefined,
|
|
31
|
+
locale = "pt-BR",
|
|
32
|
+
currency = "BRL"
|
|
33
|
+
): string {
|
|
34
|
+
if (amount == null) return "Sob consulta";
|
|
35
|
+
try {
|
|
36
|
+
return new Intl.NumberFormat(locale, {
|
|
37
|
+
style: "currency",
|
|
38
|
+
currency,
|
|
39
|
+
minimumFractionDigits: 0,
|
|
40
|
+
maximumFractionDigits: 0,
|
|
41
|
+
}).format(amount);
|
|
42
|
+
} catch {
|
|
43
|
+
return `${currency} ${amount}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Input mask: `499000` → `"499.000"` (no currency symbol). */
|
|
48
|
+
export function formatGroupedInteger(
|
|
49
|
+
value: string | number | null | undefined,
|
|
50
|
+
locale = "pt-BR"
|
|
51
|
+
): string {
|
|
52
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
53
|
+
if (!digits) return "";
|
|
54
|
+
const amount = Number.parseInt(digits, 10);
|
|
55
|
+
if (!Number.isFinite(amount)) return "";
|
|
56
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(
|
|
57
|
+
amount
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Inverse of `formatGroupedInteger`: `"499.000"` / `"499000"` → `499000`. */
|
|
62
|
+
export function parseGroupedInteger(value: unknown): number | undefined {
|
|
63
|
+
if (typeof value === "number") {
|
|
64
|
+
return Number.isFinite(value) ? Math.trunc(value) : undefined;
|
|
65
|
+
}
|
|
66
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
67
|
+
if (!digits) return undefined;
|
|
68
|
+
const amount = Number.parseInt(digits, 10);
|
|
69
|
+
return Number.isFinite(amount) ? amount : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function formatAreaM2(area: number | null | undefined): string | null {
|
|
73
|
+
if (area == null || !Number.isFinite(area)) return null;
|
|
74
|
+
return `${area} m²`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function listingBusinessLabel(businessType: string | undefined): string {
|
|
78
|
+
return businessType === "rental" ? "Aluguel" : "Venda";
|
|
79
|
+
}
|
package/src/react/cn.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ReactElement } from "react";
|
|
4
|
+
|
|
5
|
+
import { formatGroupedInteger } from "../presentation";
|
|
6
|
+
import {
|
|
7
|
+
countFacetChoices,
|
|
8
|
+
pathFilterHasOption,
|
|
9
|
+
pathFilterValue,
|
|
10
|
+
} from "../search-engine";
|
|
11
|
+
import type { SearchPathFilters, SearchUiFilter } from "../types";
|
|
12
|
+
|
|
13
|
+
export type RangeCommitSource = "blur" | "enter" | "apply";
|
|
14
|
+
|
|
15
|
+
export type FilterPanelProps = {
|
|
16
|
+
filters: SearchUiFilter[];
|
|
17
|
+
pathFilters: SearchPathFilters;
|
|
18
|
+
onChange: (filterId: string, value: unknown) => void;
|
|
19
|
+
rangeDraft: Record<string, { min: string; max: string }>;
|
|
20
|
+
onRangePatch: (filterId: string, side: "min" | "max", value: string) => void;
|
|
21
|
+
onRangeCommit: (filterId: string, source?: RangeCommitSource) => void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function RangeFields({
|
|
25
|
+
filter,
|
|
26
|
+
rangeDraft,
|
|
27
|
+
onRangePatch,
|
|
28
|
+
onRangeCommit,
|
|
29
|
+
}: {
|
|
30
|
+
filter: SearchUiFilter;
|
|
31
|
+
rangeDraft: FilterPanelProps["rangeDraft"];
|
|
32
|
+
onRangePatch: FilterPanelProps["onRangePatch"];
|
|
33
|
+
onRangeCommit: FilterPanelProps["onRangeCommit"];
|
|
34
|
+
}): ReactElement {
|
|
35
|
+
const draft = rangeDraft[filter.id] || { min: "", max: "" };
|
|
36
|
+
const isPrice = filter.id === "price";
|
|
37
|
+
const patch = (side: "min" | "max", raw: string) => {
|
|
38
|
+
onRangePatch(filter.id, side, isPrice ? formatGroupedInteger(raw) : raw);
|
|
39
|
+
};
|
|
40
|
+
return (
|
|
41
|
+
<fieldset data-slot="search-filter">
|
|
42
|
+
<legend>{filter.label}</legend>
|
|
43
|
+
<div data-slot="search-range-row">
|
|
44
|
+
<RangeSide
|
|
45
|
+
id={`${filter.id}-min`}
|
|
46
|
+
label="Mín"
|
|
47
|
+
isPrice={isPrice}
|
|
48
|
+
value={draft.min}
|
|
49
|
+
onPatch={(raw) => patch("min", raw)}
|
|
50
|
+
onCommit={() => onRangeCommit(filter.id, "blur")}
|
|
51
|
+
onEnter={() => onRangeCommit(filter.id, "enter")}
|
|
52
|
+
/>
|
|
53
|
+
<RangeSide
|
|
54
|
+
id={`${filter.id}-max`}
|
|
55
|
+
label="Máx"
|
|
56
|
+
isPrice={isPrice}
|
|
57
|
+
value={draft.max}
|
|
58
|
+
onPatch={(raw) => patch("max", raw)}
|
|
59
|
+
onCommit={() => onRangeCommit(filter.id, "blur")}
|
|
60
|
+
onEnter={() => onRangeCommit(filter.id, "enter")}
|
|
61
|
+
/>
|
|
62
|
+
<button
|
|
63
|
+
type="button"
|
|
64
|
+
data-slot="search-range-apply"
|
|
65
|
+
onClick={() => onRangeCommit(filter.id, "apply")}
|
|
66
|
+
>
|
|
67
|
+
Atualizar
|
|
68
|
+
</button>
|
|
69
|
+
</div>
|
|
70
|
+
</fieldset>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function RangeSide({
|
|
75
|
+
id,
|
|
76
|
+
label,
|
|
77
|
+
isPrice,
|
|
78
|
+
value,
|
|
79
|
+
onPatch,
|
|
80
|
+
onCommit,
|
|
81
|
+
onEnter,
|
|
82
|
+
}: {
|
|
83
|
+
id: string;
|
|
84
|
+
label: string;
|
|
85
|
+
isPrice: boolean;
|
|
86
|
+
value: string;
|
|
87
|
+
onPatch: (raw: string) => void;
|
|
88
|
+
onCommit: () => void;
|
|
89
|
+
onEnter: () => void;
|
|
90
|
+
}): ReactElement {
|
|
91
|
+
const input = (
|
|
92
|
+
<input
|
|
93
|
+
id={id}
|
|
94
|
+
type={isPrice ? "text" : "number"}
|
|
95
|
+
inputMode={isPrice ? "numeric" : "decimal"}
|
|
96
|
+
min={isPrice ? undefined : 0}
|
|
97
|
+
step={isPrice ? undefined : 0.01}
|
|
98
|
+
value={value}
|
|
99
|
+
placeholder={isPrice ? "0" : undefined}
|
|
100
|
+
onChange={(event) => onPatch(event.target.value)}
|
|
101
|
+
onBlur={onCommit}
|
|
102
|
+
onKeyDown={(event) => {
|
|
103
|
+
if (event.key === "Enter") {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
onEnter();
|
|
106
|
+
}
|
|
107
|
+
}}
|
|
108
|
+
data-slot="search-range-input"
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
return (
|
|
112
|
+
<label data-slot="search-range-side" htmlFor={id}>
|
|
113
|
+
<span>{label}</span>
|
|
114
|
+
{isPrice ? (
|
|
115
|
+
<span data-slot="search-range-affix">
|
|
116
|
+
<span data-slot="search-range-prefix">R$</span>
|
|
117
|
+
{input}
|
|
118
|
+
</span>
|
|
119
|
+
) : (
|
|
120
|
+
input
|
|
121
|
+
)}
|
|
122
|
+
</label>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function CountFields({
|
|
127
|
+
filter,
|
|
128
|
+
pathFilters,
|
|
129
|
+
onChange,
|
|
130
|
+
}: {
|
|
131
|
+
filter: SearchUiFilter;
|
|
132
|
+
pathFilters: SearchPathFilters;
|
|
133
|
+
onChange: FilterPanelProps["onChange"];
|
|
134
|
+
}): ReactElement {
|
|
135
|
+
const selected = pathFilterValue(pathFilters, filter.id);
|
|
136
|
+
const choices = countFacetChoices(filter.options);
|
|
137
|
+
return (
|
|
138
|
+
<fieldset data-slot="search-filter">
|
|
139
|
+
<legend>{filter.label}</legend>
|
|
140
|
+
<div data-slot="search-count-group" role="group">
|
|
141
|
+
{choices.map((choice) => (
|
|
142
|
+
<button
|
|
143
|
+
key={choice.id}
|
|
144
|
+
type="button"
|
|
145
|
+
data-slot="search-count-choice"
|
|
146
|
+
data-selected={selected === choice.id ? "true" : undefined}
|
|
147
|
+
onClick={() => onChange(filter.id, Number(choice.id))}
|
|
148
|
+
>
|
|
149
|
+
{choice.label}
|
|
150
|
+
</button>
|
|
151
|
+
))}
|
|
152
|
+
</div>
|
|
153
|
+
</fieldset>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function EnumFields({
|
|
158
|
+
filter,
|
|
159
|
+
pathFilters,
|
|
160
|
+
onChange,
|
|
161
|
+
}: {
|
|
162
|
+
filter: SearchUiFilter;
|
|
163
|
+
pathFilters: SearchPathFilters;
|
|
164
|
+
onChange: FilterPanelProps["onChange"];
|
|
165
|
+
}): ReactElement {
|
|
166
|
+
const options = filter.options || [];
|
|
167
|
+
const scroll = options.length > 8;
|
|
168
|
+
return (
|
|
169
|
+
<fieldset data-slot="search-filter">
|
|
170
|
+
<legend>{filter.label}</legend>
|
|
171
|
+
<div data-slot={scroll ? "search-scroll" : "search-enum-list"}>
|
|
172
|
+
{options.map((option) => (
|
|
173
|
+
<label key={option.id} data-slot="search-enum-option">
|
|
174
|
+
<input
|
|
175
|
+
type="checkbox"
|
|
176
|
+
data-slot="search-checkbox"
|
|
177
|
+
checked={pathFilterHasOption(pathFilters, filter.id, option.id)}
|
|
178
|
+
onChange={() => onChange(filter.id, option.id)}
|
|
179
|
+
/>
|
|
180
|
+
<span>{option.label}</span>
|
|
181
|
+
</label>
|
|
182
|
+
))}
|
|
183
|
+
</div>
|
|
184
|
+
</fieldset>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function FilterPanel({
|
|
189
|
+
filters,
|
|
190
|
+
pathFilters,
|
|
191
|
+
onChange,
|
|
192
|
+
rangeDraft,
|
|
193
|
+
onRangePatch,
|
|
194
|
+
onRangeCommit,
|
|
195
|
+
}: FilterPanelProps): ReactElement {
|
|
196
|
+
return (
|
|
197
|
+
<div data-slot="search-filters">
|
|
198
|
+
{filters.map((filter) => {
|
|
199
|
+
if (filter.type === "range") {
|
|
200
|
+
return (
|
|
201
|
+
<RangeFields
|
|
202
|
+
key={filter.id}
|
|
203
|
+
filter={filter}
|
|
204
|
+
rangeDraft={rangeDraft}
|
|
205
|
+
onRangePatch={onRangePatch}
|
|
206
|
+
onRangeCommit={onRangeCommit}
|
|
207
|
+
/>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
if (filter.type === "count") {
|
|
211
|
+
return (
|
|
212
|
+
<CountFields
|
|
213
|
+
key={filter.id}
|
|
214
|
+
filter={filter}
|
|
215
|
+
pathFilters={pathFilters}
|
|
216
|
+
onChange={onChange}
|
|
217
|
+
/>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
return (
|
|
221
|
+
<EnumFields
|
|
222
|
+
key={filter.id}
|
|
223
|
+
filter={filter}
|
|
224
|
+
pathFilters={pathFilters}
|
|
225
|
+
onChange={onChange}
|
|
226
|
+
/>
|
|
227
|
+
);
|
|
228
|
+
})}
|
|
229
|
+
</div>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function rangeDraftFromPath(
|
|
234
|
+
pathFilters: SearchPathFilters
|
|
235
|
+
): Record<string, { min: string; max: string }> {
|
|
236
|
+
const price = pathFilters.price || {};
|
|
237
|
+
const area = pathFilters.area || {};
|
|
238
|
+
return {
|
|
239
|
+
price: {
|
|
240
|
+
min: price.min != null ? formatGroupedInteger(price.min) : "",
|
|
241
|
+
max: price.max != null ? formatGroupedInteger(price.max) : "",
|
|
242
|
+
},
|
|
243
|
+
property_area_total: {
|
|
244
|
+
min: area.min != null ? String(area.min) : "",
|
|
245
|
+
max: area.max != null ? String(area.max) : "",
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ReactElement, SVGProps } from "react";
|
|
2
|
+
|
|
3
|
+
type IconProps = SVGProps<SVGSVGElement>;
|
|
4
|
+
|
|
5
|
+
function Icon({ children, ...props }: IconProps): ReactElement {
|
|
6
|
+
return (
|
|
7
|
+
<svg
|
|
8
|
+
viewBox="0 0 24 24"
|
|
9
|
+
fill="none"
|
|
10
|
+
stroke="currentColor"
|
|
11
|
+
strokeWidth={2}
|
|
12
|
+
strokeLinecap="round"
|
|
13
|
+
strokeLinejoin="round"
|
|
14
|
+
aria-hidden
|
|
15
|
+
data-slot="search-icon"
|
|
16
|
+
{...props}
|
|
17
|
+
>
|
|
18
|
+
{children}
|
|
19
|
+
</svg>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function SearchLensIcon(props: IconProps): ReactElement {
|
|
24
|
+
return (
|
|
25
|
+
<Icon {...props}>
|
|
26
|
+
<circle cx="11" cy="11" r="7" />
|
|
27
|
+
<path d="M20 20l-3.5-3.5" />
|
|
28
|
+
</Icon>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function SearchClearIcon(props: IconProps): ReactElement {
|
|
33
|
+
return (
|
|
34
|
+
<Icon {...props}>
|
|
35
|
+
<path d="M6 6l12 12M18 6L6 18" />
|
|
36
|
+
</Icon>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function SearchCheckIcon(props: IconProps): ReactElement {
|
|
41
|
+
return (
|
|
42
|
+
<Icon {...props}>
|
|
43
|
+
<path d="M5 12l5 5L20 7" />
|
|
44
|
+
</Icon>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
export { ListingCard } from "./listing-card";
|
|
4
|
+
export { SearchPage } from "./search-page";
|
|
5
|
+
export { SearchChromeStyles } from "./styles";
|
|
6
|
+
export { SearchPagination } from "./search-pagination";
|
|
7
|
+
export { SearchQueryForm } from "./search-query-form";
|
|
8
|
+
export { FilterPanel, rangeDraftFromPath } from "./filter-panel";
|
|
9
|
+
export {
|
|
10
|
+
ResultsSkeleton,
|
|
11
|
+
SearchPageFallback,
|
|
12
|
+
SearchSortSelect,
|
|
13
|
+
} from "./search-chrome";
|
|
14
|
+
export { usePublicSearch } from "./use-public-search";
|
|
15
|
+
export type {
|
|
16
|
+
ListingCardClassNames,
|
|
17
|
+
ListingCardProps,
|
|
18
|
+
ListingCardSlots,
|
|
19
|
+
PublicSearchState,
|
|
20
|
+
SearchPageClassNames,
|
|
21
|
+
SearchPageIcons,
|
|
22
|
+
SearchPageVariant,
|
|
23
|
+
SiteIdInput,
|
|
24
|
+
UsePublicSearchOptions,
|
|
25
|
+
} from "./types";
|
|
26
|
+
export type { SearchPageProps } from "./search-page";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ReactElement } from "react";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
|
|
6
|
+
import { formatAreaM2 } from "../presentation";
|
|
7
|
+
import { toListingCardModel } from "../listing-card-model";
|
|
8
|
+
import type { Listing } from "../types";
|
|
9
|
+
import { cn } from "./cn";
|
|
10
|
+
import type { ListingCardProps } from "./types";
|
|
11
|
+
|
|
12
|
+
function isListing(value: ListingCardProps["listing"]): value is Listing {
|
|
13
|
+
return (
|
|
14
|
+
"priceVisibility" in value && "businessType" in value && "title" in value
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function ListingCard({
|
|
19
|
+
listing,
|
|
20
|
+
href,
|
|
21
|
+
className,
|
|
22
|
+
classNames,
|
|
23
|
+
slots,
|
|
24
|
+
style,
|
|
25
|
+
}: ListingCardProps): ReactElement {
|
|
26
|
+
const model = isListing(listing) ? toListingCardModel(listing) : listing;
|
|
27
|
+
const target = href ?? model.href;
|
|
28
|
+
const areaLabel = formatAreaM2(model.areaM2);
|
|
29
|
+
return (
|
|
30
|
+
<article
|
|
31
|
+
data-slot="listing-card"
|
|
32
|
+
className={cn(className, classNames?.root)}
|
|
33
|
+
style={style}
|
|
34
|
+
>
|
|
35
|
+
<Link href={target} data-slot="listing-card-link">
|
|
36
|
+
<div data-slot="listing-card-media" className={classNames?.media}>
|
|
37
|
+
{slots?.media ??
|
|
38
|
+
(model.coverSrc ? (
|
|
39
|
+
<img src={model.coverSrc} alt={model.coverAlt} />
|
|
40
|
+
) : (
|
|
41
|
+
<div data-slot="listing-card-empty">Sem foto</div>
|
|
42
|
+
))}
|
|
43
|
+
{slots?.badge ?? (
|
|
44
|
+
<span data-slot="listing-card-badge" className={classNames?.badge}>
|
|
45
|
+
{model.businessLabel}
|
|
46
|
+
</span>
|
|
47
|
+
)}
|
|
48
|
+
</div>
|
|
49
|
+
<div data-slot="listing-card-body" className={classNames?.body}>
|
|
50
|
+
<div data-slot="listing-card-price-row">
|
|
51
|
+
<p data-slot="listing-card-price" className={classNames?.price}>
|
|
52
|
+
{model.priceLabel}
|
|
53
|
+
</p>
|
|
54
|
+
{model.pricePeriod ? (
|
|
55
|
+
<span data-slot="listing-card-period">{model.pricePeriod}</span>
|
|
56
|
+
) : null}
|
|
57
|
+
</div>
|
|
58
|
+
<h3 data-slot="listing-card-title" className={classNames?.title}>
|
|
59
|
+
{model.title}
|
|
60
|
+
</h3>
|
|
61
|
+
<p data-slot="listing-card-location" className={classNames?.location}>
|
|
62
|
+
{model.locationLabel || model.propertyType || ""}
|
|
63
|
+
</p>
|
|
64
|
+
<ul
|
|
65
|
+
data-slot="listing-card-features"
|
|
66
|
+
className={classNames?.features}
|
|
67
|
+
>
|
|
68
|
+
{model.bedrooms != null ? <li>{model.bedrooms} quartos</li> : null}
|
|
69
|
+
{model.bathrooms != null ? (
|
|
70
|
+
<li>{model.bathrooms} banheiros</li>
|
|
71
|
+
) : null}
|
|
72
|
+
{model.parkingSpaces != null ? (
|
|
73
|
+
<li>{model.parkingSpaces} vagas</li>
|
|
74
|
+
) : null}
|
|
75
|
+
{areaLabel ? <li>{areaLabel}</li> : null}
|
|
76
|
+
</ul>
|
|
77
|
+
{slots?.cta ? (
|
|
78
|
+
<div data-slot="listing-card-cta" className={classNames?.cta}>
|
|
79
|
+
{slots.cta}
|
|
80
|
+
</div>
|
|
81
|
+
) : null}
|
|
82
|
+
</div>
|
|
83
|
+
</Link>
|
|
84
|
+
</article>
|
|
85
|
+
);
|
|
86
|
+
}
|