@garagem-ai/site-sdk 0.3.0 → 0.4.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.
- package/README.md +26 -3
- package/dist/index.d.mts +78 -361
- package/dist/index.d.ts +78 -361
- package/dist/index.js +472 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +437 -46
- package/dist/index.mjs.map +1 -1
- package/dist/listing-card-model-D7iR4asd.d.mts +402 -0
- package/dist/listing-card-model-D7iR4asd.d.ts +402 -0
- package/dist/react.d.mts +136 -0
- package/dist/react.d.ts +136 -0
- package/dist/react.js +2070 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +2030 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +34 -1
- package/src/fetchers.ts +27 -18
- package/src/index.ts +42 -0
- package/src/internal/url.ts +14 -0
- package/src/listing-card-model.ts +90 -0
- package/src/presentation.ts +72 -0
- package/src/react/cn.ts +3 -0
- package/src/react/filter-panel.tsx +251 -0
- package/src/react/index.ts +20 -0
- package/src/react/listing-card.tsx +143 -0
- package/src/react/search-chrome.tsx +72 -0
- package/src/react/search-page.tsx +366 -0
- package/src/react/search-pagination.tsx +110 -0
- package/src/react/search-query-form.tsx +76 -0
- package/src/react/types.ts +88 -0
- package/src/react/use-public-search.ts +297 -0
- package/src/search-engine.ts +404 -0
|
@@ -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,72 @@
|
|
|
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
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
export const SEARCH_CSS_RECIPE = `:root {
|
|
15
|
+
${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
|
|
16
|
+
${SEARCH_CSS_VARS.cardGap}: 1.5rem;
|
|
17
|
+
${SEARCH_CSS_VARS.priceSize}: 1.125rem;
|
|
18
|
+
${SEARCH_CSS_VARS.mediaRatio}: 4 / 3;
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export function formatListingPrice(
|
|
23
|
+
amount: number | null | undefined,
|
|
24
|
+
locale = "pt-BR",
|
|
25
|
+
currency = "BRL"
|
|
26
|
+
): string {
|
|
27
|
+
if (amount == null) return "Sob consulta";
|
|
28
|
+
try {
|
|
29
|
+
return new Intl.NumberFormat(locale, {
|
|
30
|
+
style: "currency",
|
|
31
|
+
currency,
|
|
32
|
+
minimumFractionDigits: 0,
|
|
33
|
+
maximumFractionDigits: 0,
|
|
34
|
+
}).format(amount);
|
|
35
|
+
} catch {
|
|
36
|
+
return `${currency} ${amount}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Input mask: `499000` → `"499.000"` (no currency symbol). */
|
|
41
|
+
export function formatGroupedInteger(
|
|
42
|
+
value: string | number | null | undefined,
|
|
43
|
+
locale = "pt-BR"
|
|
44
|
+
): string {
|
|
45
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
46
|
+
if (!digits) return "";
|
|
47
|
+
const amount = Number.parseInt(digits, 10);
|
|
48
|
+
if (!Number.isFinite(amount)) return "";
|
|
49
|
+
return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(
|
|
50
|
+
amount
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Inverse of `formatGroupedInteger`: `"499.000"` / `"499000"` → `499000`. */
|
|
55
|
+
export function parseGroupedInteger(value: unknown): number | undefined {
|
|
56
|
+
if (typeof value === "number") {
|
|
57
|
+
return Number.isFinite(value) ? Math.trunc(value) : undefined;
|
|
58
|
+
}
|
|
59
|
+
const digits = String(value ?? "").replace(/\D/g, "");
|
|
60
|
+
if (!digits) return undefined;
|
|
61
|
+
const amount = Number.parseInt(digits, 10);
|
|
62
|
+
return Number.isFinite(amount) ? amount : undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function formatAreaM2(area: number | null | undefined): string | null {
|
|
66
|
+
if (area == null || !Number.isFinite(area)) return null;
|
|
67
|
+
return `${area} m²`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function listingBusinessLabel(businessType: string | undefined): string {
|
|
71
|
+
return businessType === "rental" ? "Aluguel" : "Venda";
|
|
72
|
+
}
|
package/src/react/cn.ts
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
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
|
+
import { cn } from "./cn";
|
|
13
|
+
|
|
14
|
+
export type FilterPanelProps = {
|
|
15
|
+
filters: SearchUiFilter[];
|
|
16
|
+
pathFilters: SearchPathFilters;
|
|
17
|
+
onChange: (filterId: string, value: unknown) => void;
|
|
18
|
+
rangeDraft: Record<string, { min: string; max: string }>;
|
|
19
|
+
onRangePatch: (filterId: string, side: "min" | "max", value: string) => void;
|
|
20
|
+
onRangeCommit: (filterId: string) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function RangeFields({
|
|
24
|
+
filter,
|
|
25
|
+
rangeDraft,
|
|
26
|
+
onRangePatch,
|
|
27
|
+
onRangeCommit,
|
|
28
|
+
}: {
|
|
29
|
+
filter: SearchUiFilter;
|
|
30
|
+
rangeDraft: FilterPanelProps["rangeDraft"];
|
|
31
|
+
onRangePatch: FilterPanelProps["onRangePatch"];
|
|
32
|
+
onRangeCommit: FilterPanelProps["onRangeCommit"];
|
|
33
|
+
}): ReactElement {
|
|
34
|
+
const draft = rangeDraft[filter.id] || { min: "", max: "" };
|
|
35
|
+
const isPrice = filter.id === "price";
|
|
36
|
+
const patch = (side: "min" | "max", raw: string) => {
|
|
37
|
+
onRangePatch(filter.id, side, isPrice ? formatGroupedInteger(raw) : raw);
|
|
38
|
+
};
|
|
39
|
+
const inputClass =
|
|
40
|
+
"min-h-10 w-full rounded-lg border border-border bg-background px-3";
|
|
41
|
+
return (
|
|
42
|
+
<fieldset className="text-sm">
|
|
43
|
+
<legend className="mb-1 text-muted-foreground">{filter.label}</legend>
|
|
44
|
+
<div className="flex gap-2">
|
|
45
|
+
<RangeSide
|
|
46
|
+
id={`${filter.id}-min`}
|
|
47
|
+
label="Mín"
|
|
48
|
+
isPrice={isPrice}
|
|
49
|
+
value={draft.min}
|
|
50
|
+
inputClass={inputClass}
|
|
51
|
+
onPatch={(raw) => patch("min", raw)}
|
|
52
|
+
onCommit={() => onRangeCommit(filter.id)}
|
|
53
|
+
/>
|
|
54
|
+
<RangeSide
|
|
55
|
+
id={`${filter.id}-max`}
|
|
56
|
+
label="Máx"
|
|
57
|
+
isPrice={isPrice}
|
|
58
|
+
value={draft.max}
|
|
59
|
+
inputClass={inputClass}
|
|
60
|
+
onPatch={(raw) => patch("max", raw)}
|
|
61
|
+
onCommit={() => onRangeCommit(filter.id)}
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
</fieldset>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function RangeSide({
|
|
69
|
+
id,
|
|
70
|
+
label,
|
|
71
|
+
isPrice,
|
|
72
|
+
value,
|
|
73
|
+
inputClass,
|
|
74
|
+
onPatch,
|
|
75
|
+
onCommit,
|
|
76
|
+
}: {
|
|
77
|
+
id: string;
|
|
78
|
+
label: string;
|
|
79
|
+
isPrice: boolean;
|
|
80
|
+
value: string;
|
|
81
|
+
inputClass: string;
|
|
82
|
+
onPatch: (raw: string) => void;
|
|
83
|
+
onCommit: () => void;
|
|
84
|
+
}): ReactElement {
|
|
85
|
+
const input = (
|
|
86
|
+
<input
|
|
87
|
+
id={id}
|
|
88
|
+
type={isPrice ? "text" : "number"}
|
|
89
|
+
inputMode={isPrice ? "numeric" : "decimal"}
|
|
90
|
+
min={isPrice ? undefined : 0}
|
|
91
|
+
step={isPrice ? undefined : 0.01}
|
|
92
|
+
value={value}
|
|
93
|
+
placeholder={isPrice ? "0" : undefined}
|
|
94
|
+
onChange={(event) => onPatch(event.target.value)}
|
|
95
|
+
onBlur={onCommit}
|
|
96
|
+
onKeyDown={(event) => {
|
|
97
|
+
if (event.key === "Enter") onCommit();
|
|
98
|
+
}}
|
|
99
|
+
className={isPrice ? `${inputClass} pl-10` : inputClass}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
return (
|
|
103
|
+
<label className="min-w-0 flex-1" htmlFor={id}>
|
|
104
|
+
<span className="mb-1 block text-xs text-muted-foreground">{label}</span>
|
|
105
|
+
{isPrice ? (
|
|
106
|
+
<span className="relative block">
|
|
107
|
+
<span className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3 text-muted-foreground">
|
|
108
|
+
R$
|
|
109
|
+
</span>
|
|
110
|
+
{input}
|
|
111
|
+
</span>
|
|
112
|
+
) : (
|
|
113
|
+
input
|
|
114
|
+
)}
|
|
115
|
+
</label>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function CountFields({
|
|
120
|
+
filter,
|
|
121
|
+
pathFilters,
|
|
122
|
+
onChange,
|
|
123
|
+
}: {
|
|
124
|
+
filter: SearchUiFilter;
|
|
125
|
+
pathFilters: SearchPathFilters;
|
|
126
|
+
onChange: FilterPanelProps["onChange"];
|
|
127
|
+
}): ReactElement {
|
|
128
|
+
const selected = pathFilterValue(pathFilters, filter.id);
|
|
129
|
+
const choices = countFacetChoices(filter.options);
|
|
130
|
+
return (
|
|
131
|
+
<fieldset className="text-sm">
|
|
132
|
+
<legend className="mb-2 text-muted-foreground">{filter.label}</legend>
|
|
133
|
+
<div className="flex flex-wrap gap-1.5" role="group">
|
|
134
|
+
{choices.map((choice) => (
|
|
135
|
+
<button
|
|
136
|
+
key={choice.id}
|
|
137
|
+
type="button"
|
|
138
|
+
onClick={() => onChange(filter.id, Number(choice.id))}
|
|
139
|
+
className={cn(
|
|
140
|
+
"min-h-10 cursor-pointer rounded-lg border px-3 text-sm hover:bg-muted",
|
|
141
|
+
selected === choice.id && "border-primary bg-primary/10"
|
|
142
|
+
)}
|
|
143
|
+
>
|
|
144
|
+
{choice.label}
|
|
145
|
+
</button>
|
|
146
|
+
))}
|
|
147
|
+
</div>
|
|
148
|
+
</fieldset>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function EnumFields({
|
|
153
|
+
filter,
|
|
154
|
+
pathFilters,
|
|
155
|
+
onChange,
|
|
156
|
+
}: {
|
|
157
|
+
filter: SearchUiFilter;
|
|
158
|
+
pathFilters: SearchPathFilters;
|
|
159
|
+
onChange: FilterPanelProps["onChange"];
|
|
160
|
+
}): ReactElement {
|
|
161
|
+
const options = filter.options || [];
|
|
162
|
+
const scroll = options.length > 8;
|
|
163
|
+
return (
|
|
164
|
+
<fieldset className="text-sm">
|
|
165
|
+
<legend className="mb-2 text-muted-foreground">{filter.label}</legend>
|
|
166
|
+
<div
|
|
167
|
+
className={cn(
|
|
168
|
+
"flex flex-col gap-1.5",
|
|
169
|
+
scroll && "max-h-48 overflow-y-auto"
|
|
170
|
+
)}
|
|
171
|
+
>
|
|
172
|
+
{options.map((option) => (
|
|
173
|
+
<label
|
|
174
|
+
key={option.id}
|
|
175
|
+
className="flex cursor-pointer items-center gap-2"
|
|
176
|
+
>
|
|
177
|
+
<input
|
|
178
|
+
type="checkbox"
|
|
179
|
+
checked={pathFilterHasOption(pathFilters, filter.id, option.id)}
|
|
180
|
+
onChange={() => onChange(filter.id, option.id)}
|
|
181
|
+
className="cursor-pointer"
|
|
182
|
+
/>
|
|
183
|
+
<span>{option.label}</span>
|
|
184
|
+
</label>
|
|
185
|
+
))}
|
|
186
|
+
</div>
|
|
187
|
+
</fieldset>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function FilterPanel({
|
|
192
|
+
filters,
|
|
193
|
+
pathFilters,
|
|
194
|
+
onChange,
|
|
195
|
+
rangeDraft,
|
|
196
|
+
onRangePatch,
|
|
197
|
+
onRangeCommit,
|
|
198
|
+
}: FilterPanelProps): ReactElement {
|
|
199
|
+
return (
|
|
200
|
+
<div className="flex flex-col gap-5" data-slot="search-filters">
|
|
201
|
+
{filters.map((filter) => {
|
|
202
|
+
if (filter.type === "range") {
|
|
203
|
+
return (
|
|
204
|
+
<RangeFields
|
|
205
|
+
key={filter.id}
|
|
206
|
+
filter={filter}
|
|
207
|
+
rangeDraft={rangeDraft}
|
|
208
|
+
onRangePatch={onRangePatch}
|
|
209
|
+
onRangeCommit={onRangeCommit}
|
|
210
|
+
/>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (filter.type === "count") {
|
|
214
|
+
return (
|
|
215
|
+
<CountFields
|
|
216
|
+
key={filter.id}
|
|
217
|
+
filter={filter}
|
|
218
|
+
pathFilters={pathFilters}
|
|
219
|
+
onChange={onChange}
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
return (
|
|
224
|
+
<EnumFields
|
|
225
|
+
key={filter.id}
|
|
226
|
+
filter={filter}
|
|
227
|
+
pathFilters={pathFilters}
|
|
228
|
+
onChange={onChange}
|
|
229
|
+
/>
|
|
230
|
+
);
|
|
231
|
+
})}
|
|
232
|
+
</div>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function rangeDraftFromPath(
|
|
237
|
+
pathFilters: SearchPathFilters
|
|
238
|
+
): Record<string, { min: string; max: string }> {
|
|
239
|
+
const price = pathFilters.price || {};
|
|
240
|
+
const area = pathFilters.area || {};
|
|
241
|
+
return {
|
|
242
|
+
price: {
|
|
243
|
+
min: price.min != null ? formatGroupedInteger(price.min) : "",
|
|
244
|
+
max: price.max != null ? formatGroupedInteger(price.max) : "",
|
|
245
|
+
},
|
|
246
|
+
property_area_total: {
|
|
247
|
+
min: area.min != null ? String(area.min) : "",
|
|
248
|
+
max: area.max != null ? String(area.max) : "",
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
export { ListingCard } from "./listing-card";
|
|
4
|
+
export { SearchPage } from "./search-page";
|
|
5
|
+
export { SearchPagination } from "./search-pagination";
|
|
6
|
+
export { SearchQueryForm } from "./search-query-form";
|
|
7
|
+
export { FilterPanel, rangeDraftFromPath } from "./filter-panel";
|
|
8
|
+
export { ResultsSkeleton, SearchSortSelect } from "./search-chrome";
|
|
9
|
+
export { usePublicSearch } from "./use-public-search";
|
|
10
|
+
export type {
|
|
11
|
+
ListingCardClassNames,
|
|
12
|
+
ListingCardProps,
|
|
13
|
+
ListingCardSlots,
|
|
14
|
+
PublicSearchState,
|
|
15
|
+
SearchPageClassNames,
|
|
16
|
+
SearchPageVariant,
|
|
17
|
+
SiteIdInput,
|
|
18
|
+
UsePublicSearchOptions,
|
|
19
|
+
} from "./types";
|
|
20
|
+
export type { SearchPageProps } from "./search-page";
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
|
|
30
|
+
return (
|
|
31
|
+
<article
|
|
32
|
+
data-slot="listing-card"
|
|
33
|
+
className={cn(
|
|
34
|
+
"group overflow-hidden rounded-[var(--garagem-listing-card-radius,0.75rem)] border border-border bg-background",
|
|
35
|
+
className,
|
|
36
|
+
classNames?.root
|
|
37
|
+
)}
|
|
38
|
+
style={style}
|
|
39
|
+
>
|
|
40
|
+
<Link
|
|
41
|
+
href={target}
|
|
42
|
+
className="block cursor-pointer"
|
|
43
|
+
data-slot="listing-card-link"
|
|
44
|
+
>
|
|
45
|
+
<div
|
|
46
|
+
data-slot="listing-card-media"
|
|
47
|
+
className={cn(
|
|
48
|
+
"relative w-full overflow-hidden bg-muted",
|
|
49
|
+
classNames?.media
|
|
50
|
+
)}
|
|
51
|
+
style={{ aspectRatio: "var(--garagem-listing-media-ratio, 4 / 3)" }}
|
|
52
|
+
>
|
|
53
|
+
{slots?.media ??
|
|
54
|
+
(model.coverSrc ? (
|
|
55
|
+
<img
|
|
56
|
+
src={model.coverSrc}
|
|
57
|
+
alt={model.coverAlt}
|
|
58
|
+
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
|
|
59
|
+
/>
|
|
60
|
+
) : (
|
|
61
|
+
<div className="flex h-full w-full items-center justify-center text-xs text-muted-foreground">
|
|
62
|
+
Sem foto
|
|
63
|
+
</div>
|
|
64
|
+
))}
|
|
65
|
+
{slots?.badge ?? (
|
|
66
|
+
<span
|
|
67
|
+
data-slot="listing-card-badge"
|
|
68
|
+
className={cn(
|
|
69
|
+
"absolute left-3 top-3 rounded-full bg-background/90 px-2 py-1 text-xs font-medium",
|
|
70
|
+
classNames?.badge
|
|
71
|
+
)}
|
|
72
|
+
>
|
|
73
|
+
{model.businessLabel}
|
|
74
|
+
</span>
|
|
75
|
+
)}
|
|
76
|
+
</div>
|
|
77
|
+
<div
|
|
78
|
+
data-slot="listing-card-body"
|
|
79
|
+
className={cn("p-4", classNames?.body)}
|
|
80
|
+
>
|
|
81
|
+
<div className="flex items-baseline justify-between gap-2">
|
|
82
|
+
<p
|
|
83
|
+
data-slot="listing-card-price"
|
|
84
|
+
className={cn("font-semibold tracking-tight", classNames?.price)}
|
|
85
|
+
style={{
|
|
86
|
+
fontSize: "var(--garagem-listing-price-size, 1.125rem)",
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
{model.priceLabel}
|
|
90
|
+
</p>
|
|
91
|
+
{model.pricePeriod ? (
|
|
92
|
+
<span className="text-xs text-muted-foreground">
|
|
93
|
+
{model.pricePeriod}
|
|
94
|
+
</span>
|
|
95
|
+
) : null}
|
|
96
|
+
</div>
|
|
97
|
+
<h3
|
|
98
|
+
data-slot="listing-card-title"
|
|
99
|
+
className={cn(
|
|
100
|
+
"mt-1 line-clamp-1 text-sm font-medium",
|
|
101
|
+
classNames?.title
|
|
102
|
+
)}
|
|
103
|
+
>
|
|
104
|
+
{model.title}
|
|
105
|
+
</h3>
|
|
106
|
+
<p
|
|
107
|
+
data-slot="listing-card-location"
|
|
108
|
+
className={cn(
|
|
109
|
+
"mt-0.5 line-clamp-1 text-xs text-muted-foreground",
|
|
110
|
+
classNames?.location
|
|
111
|
+
)}
|
|
112
|
+
>
|
|
113
|
+
{model.locationLabel || model.propertyType || ""}
|
|
114
|
+
</p>
|
|
115
|
+
<ul
|
|
116
|
+
data-slot="listing-card-features"
|
|
117
|
+
className={cn(
|
|
118
|
+
"mt-3 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground",
|
|
119
|
+
classNames?.features
|
|
120
|
+
)}
|
|
121
|
+
>
|
|
122
|
+
{model.bedrooms != null ? <li>{model.bedrooms} quartos</li> : null}
|
|
123
|
+
{model.bathrooms != null ? (
|
|
124
|
+
<li>{model.bathrooms} banheiros</li>
|
|
125
|
+
) : null}
|
|
126
|
+
{model.parkingSpaces != null ? (
|
|
127
|
+
<li>{model.parkingSpaces} vagas</li>
|
|
128
|
+
) : null}
|
|
129
|
+
{areaLabel ? <li>{areaLabel}</li> : null}
|
|
130
|
+
</ul>
|
|
131
|
+
{slots?.cta ? (
|
|
132
|
+
<div
|
|
133
|
+
data-slot="listing-card-cta"
|
|
134
|
+
className={cn("mt-3", classNames?.cta)}
|
|
135
|
+
>
|
|
136
|
+
{slots.cta}
|
|
137
|
+
</div>
|
|
138
|
+
) : null}
|
|
139
|
+
</div>
|
|
140
|
+
</Link>
|
|
141
|
+
</article>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ReactElement } from "react";
|
|
4
|
+
|
|
5
|
+
import { searchSortOptions } from "../search-engine";
|
|
6
|
+
import { cn } from "./cn";
|
|
7
|
+
|
|
8
|
+
export type SearchSortSelectProps = {
|
|
9
|
+
value: string;
|
|
10
|
+
onChange: (sort: string | null) => void;
|
|
11
|
+
sorts?: Array<{ id: string; label: string }>;
|
|
12
|
+
className?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function SearchSortSelect({
|
|
16
|
+
value,
|
|
17
|
+
onChange,
|
|
18
|
+
sorts,
|
|
19
|
+
className,
|
|
20
|
+
}: SearchSortSelectProps): ReactElement {
|
|
21
|
+
const options = searchSortOptions(sorts);
|
|
22
|
+
return (
|
|
23
|
+
<label className={cn("text-sm", className)}>
|
|
24
|
+
<span className="mb-1 block text-muted-foreground">Ordenar</span>
|
|
25
|
+
<select
|
|
26
|
+
id="garagem-search-sort"
|
|
27
|
+
value={value}
|
|
28
|
+
onChange={(event) => onChange(event.target.value || null)}
|
|
29
|
+
className="min-h-10 cursor-pointer rounded-lg border border-border bg-background px-3"
|
|
30
|
+
>
|
|
31
|
+
{options.map((sort) => (
|
|
32
|
+
<option key={sort.id || "relevance"} value={sort.id}>
|
|
33
|
+
{sort.label}
|
|
34
|
+
</option>
|
|
35
|
+
))}
|
|
36
|
+
</select>
|
|
37
|
+
</label>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function ResultsSkeleton({
|
|
42
|
+
className,
|
|
43
|
+
}: {
|
|
44
|
+
className?: string;
|
|
45
|
+
}): ReactElement {
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
data-slot="search-skeleton"
|
|
49
|
+
className={cn(
|
|
50
|
+
"grid grid-cols-1 gap-[var(--garagem-listing-card-gap,1.5rem)] sm:grid-cols-2 lg:grid-cols-3",
|
|
51
|
+
className
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
{Array.from({ length: 6 }, (_, i) => (
|
|
55
|
+
<div
|
|
56
|
+
key={i}
|
|
57
|
+
className="overflow-hidden rounded-[var(--garagem-listing-card-radius,0.75rem)] border border-border"
|
|
58
|
+
>
|
|
59
|
+
<div
|
|
60
|
+
className="animate-pulse bg-muted"
|
|
61
|
+
style={{ aspectRatio: "4 / 3" }}
|
|
62
|
+
/>
|
|
63
|
+
<div className="space-y-2 p-4">
|
|
64
|
+
<div className="h-5 w-1/2 animate-pulse rounded bg-muted" />
|
|
65
|
+
<div className="h-4 w-3/4 animate-pulse rounded bg-muted" />
|
|
66
|
+
<div className="h-3 w-2/3 animate-pulse rounded bg-muted" />
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
))}
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
}
|