@garagem-ai/site-sdk 0.4.0 → 0.4.2
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 +29 -9
- package/dist/index.d.mts +57 -58
- package/dist/index.d.ts +57 -58
- package/dist/index.js +187 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -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 +573 -486
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +542 -456
- 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 +15 -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 +61 -106
- package/src/react/search-chrome.tsx +30 -27
- 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 +31 -0
- package/src/react/types.ts +18 -0
- package/src/react/use-public-search.ts +7 -0
- package/src/search-engine.ts +79 -0
- package/src/studio-contract.ts +138 -0
|
@@ -399,4 +399,70 @@ declare function toListingCardModel(listing: Pick<Listing, "id" | "listingCode"
|
|
|
399
399
|
};
|
|
400
400
|
}): ListingCardModel;
|
|
401
401
|
|
|
402
|
-
|
|
402
|
+
/** Query keys that must never encode filters (Editor/Studio path contract). */
|
|
403
|
+
declare const FORBIDDEN_SEARCH_QUERY_KEYS: readonly ["tipo", "quartos", "tipo-imovel", "banheiros", "vagas"];
|
|
404
|
+
/** Default option: omit `ordenar` (API has no relevance token). */
|
|
405
|
+
declare const SEARCH_SORT_RELEVANCE: {
|
|
406
|
+
readonly id: "";
|
|
407
|
+
readonly label: "Mais relevantes";
|
|
408
|
+
};
|
|
409
|
+
declare function searchSortOptions(sorts: Array<{
|
|
410
|
+
id: string;
|
|
411
|
+
label: string;
|
|
412
|
+
}> | undefined): Array<{
|
|
413
|
+
id: string;
|
|
414
|
+
label: string;
|
|
415
|
+
}>;
|
|
416
|
+
/** Toolbar: price + bedrooms first and required when the schema has them. */
|
|
417
|
+
declare const TOOLBAR_PRIMARY_FILTER_IDS: readonly ["price", "property_bedrooms"];
|
|
418
|
+
declare function isListingDetailPath(pathname: string): boolean;
|
|
419
|
+
declare function readPublicSearch(pathname: string, search: string, dictionary?: SearchUiDictionary): {
|
|
420
|
+
pathFilters: SearchPathFilters;
|
|
421
|
+
applied: AppliedSearchQuery;
|
|
422
|
+
};
|
|
423
|
+
type LocationNameTables = {
|
|
424
|
+
states?: Record<string, string>;
|
|
425
|
+
cities?: Record<string, string>;
|
|
426
|
+
neighborhoods?: Record<string, string>;
|
|
427
|
+
streets?: Record<string, string>;
|
|
428
|
+
};
|
|
429
|
+
declare function displayPathLocation(location: SearchPathFilters["location"], values?: LocationNameTables | null): SearchPathFilters["location"] | null;
|
|
430
|
+
declare function buildQueryListingsParams(pathFilters: SearchPathFilters, applied: AppliedSearchQuery, schema: Pick<SearchUi, "defaultLimit"> | {
|
|
431
|
+
defaultLimit?: number;
|
|
432
|
+
} | null, locationValues?: LocationNameTables | null): QueryListingsParams;
|
|
433
|
+
declare function applyPathFilter(pathFilters: SearchPathFilters, filterId: string, value: unknown): SearchPathFilters;
|
|
434
|
+
declare function pathFilterValue(pathFilters: SearchPathFilters | undefined, filterId: string): string;
|
|
435
|
+
declare function pathFilterHasOption(pathFilters: SearchPathFilters | undefined, filterId: string, optionId: string): boolean;
|
|
436
|
+
declare function publicSearchHref(pathFilters: SearchPathFilters, applied: AppliedSearchQuery, dictionary?: SearchUiDictionary, existingSearch?: string): string;
|
|
437
|
+
declare function hrefForPathFilters(pathname: string, search: string, dictionary: SearchUiDictionary | undefined, nextPathFilters: SearchPathFilters): string;
|
|
438
|
+
declare function hrefForAppliedChange(pathname: string, search: string, dictionary: SearchUiDictionary | undefined, change: AppliedSearchChange): string;
|
|
439
|
+
/** Canonical href if the current URL is out of generation order; otherwise null. */
|
|
440
|
+
declare function canonicalizeSearchHref(pathname: string, search: string, dictionary?: SearchUiDictionary): string | null;
|
|
441
|
+
declare function searchHrefUsesLegacyFilterQuery(href: string): boolean;
|
|
442
|
+
/**
|
|
443
|
+
* Drop staged filters. Location always stays until apply.
|
|
444
|
+
* `keepFilterIds` keeps toolbar-primary filters (price, bedrooms) so Limpar
|
|
445
|
+
* in the extra-filters dialog does not wipe values already on the toolbar.
|
|
446
|
+
*/
|
|
447
|
+
declare function clearStagedPathFilters(current: SearchPathFilters, keepFilterIds?: readonly string[]): SearchPathFilters;
|
|
448
|
+
declare function visibleSearchFilters(schema: SearchUi | null): SearchUiFilter[];
|
|
449
|
+
declare function toolbarFilterIds(schema: SearchUi | null): string[];
|
|
450
|
+
declare function countOptionLabel(option: Pick<SearchUiOption, "label">): string;
|
|
451
|
+
declare function countFacetChoices(options: SearchUiOption[] | undefined): Array<{
|
|
452
|
+
id: string;
|
|
453
|
+
label: string;
|
|
454
|
+
}>;
|
|
455
|
+
/**
|
|
456
|
+
* SEO H1 for a search URL. Must stay stable for the same path — never
|
|
457
|
+
* include the hit count (Google treats a changing H1 on one URL as
|
|
458
|
+
* volatile). Count is rendered in a sibling `<span>`.
|
|
459
|
+
*/
|
|
460
|
+
declare function searchResultsHeading(pathFilters: SearchPathFilters, dictionary?: SearchUiDictionary | null, locationNames?: LocationNameTables | null): string;
|
|
461
|
+
/**
|
|
462
|
+
* Next App Router does not navigate when the href is unchanged. Canonical
|
|
463
|
+
* URLs omit `page=1`, so pagination must still emit `?page=1` on the link.
|
|
464
|
+
*/
|
|
465
|
+
declare function hrefWithExplicitPage(href: string, page: number): string;
|
|
466
|
+
declare function paginationPages(currentPage: number, totalPages: number, padding: number): number[];
|
|
467
|
+
|
|
468
|
+
export { publicSearchHref as $, type AppliedSearchQuery as A, SEARCH_SORT_RELEVANCE as B, type CmsCollection as C, type SearchPathLocation as D, type SearchUiFilter as E, FORBIDDEN_SEARCH_QUERY_KEYS as F, type SearchUiOption as G, applyPathFilter as H, buildQueryListingsParams as I, canonicalizeSearchHref as J, clearStagedPathFilters as K, type ListingFilters as L, countFacetChoices as M, countOptionLabel as N, displayPathLocation as O, hrefForAppliedChange as P, type QueryListingsParams as Q, type RequestNextOptions as R, type SearchListingsParams as S, TOOLBAR_PRIMARY_FILTER_IDS as T, hrefForPathFilters as U, hrefWithExplicitPage as V, isListingDetailPath as W, listingLocationLabel as X, paginationPages as Y, pathFilterHasOption as Z, pathFilterValue as _, type CmsEntriesResult as a, readPublicSearch as a0, searchHrefUsesLegacyFilterQuery as a1, searchResultsHeading as a2, searchSortOptions as a3, toListingCardModel as a4, toolbarFilterIds as a5, visibleSearchFilters as a6, type CmsEntry as b, type ListingDetail as c, type ListingsResult as d, type SearchUi as e, type SimilarListingsResult as f, type Site as g, type QueryListingsResult as h, type SearchListingsResult as i, type SearchPathFilters as j, type SearchUiDictionary as k, type QueryListingsFilters as l, type AppliedSearchChange as m, type CmsEntryStatus as n, type CmsFieldDefinition as o, type CmsFieldType as p, type CmsSeoData as q, type Listing as r, type ListingBusinessType as s, type ListingCardModel as t, type ListingLocation as u, type ListingMedia as v, type ListingPriceVisibility as w, type ListingPropertySummary as x, type LocationNameTables as y, type QueryListingsLocation as z };
|
|
@@ -399,4 +399,70 @@ declare function toListingCardModel(listing: Pick<Listing, "id" | "listingCode"
|
|
|
399
399
|
};
|
|
400
400
|
}): ListingCardModel;
|
|
401
401
|
|
|
402
|
-
|
|
402
|
+
/** Query keys that must never encode filters (Editor/Studio path contract). */
|
|
403
|
+
declare const FORBIDDEN_SEARCH_QUERY_KEYS: readonly ["tipo", "quartos", "tipo-imovel", "banheiros", "vagas"];
|
|
404
|
+
/** Default option: omit `ordenar` (API has no relevance token). */
|
|
405
|
+
declare const SEARCH_SORT_RELEVANCE: {
|
|
406
|
+
readonly id: "";
|
|
407
|
+
readonly label: "Mais relevantes";
|
|
408
|
+
};
|
|
409
|
+
declare function searchSortOptions(sorts: Array<{
|
|
410
|
+
id: string;
|
|
411
|
+
label: string;
|
|
412
|
+
}> | undefined): Array<{
|
|
413
|
+
id: string;
|
|
414
|
+
label: string;
|
|
415
|
+
}>;
|
|
416
|
+
/** Toolbar: price + bedrooms first and required when the schema has them. */
|
|
417
|
+
declare const TOOLBAR_PRIMARY_FILTER_IDS: readonly ["price", "property_bedrooms"];
|
|
418
|
+
declare function isListingDetailPath(pathname: string): boolean;
|
|
419
|
+
declare function readPublicSearch(pathname: string, search: string, dictionary?: SearchUiDictionary): {
|
|
420
|
+
pathFilters: SearchPathFilters;
|
|
421
|
+
applied: AppliedSearchQuery;
|
|
422
|
+
};
|
|
423
|
+
type LocationNameTables = {
|
|
424
|
+
states?: Record<string, string>;
|
|
425
|
+
cities?: Record<string, string>;
|
|
426
|
+
neighborhoods?: Record<string, string>;
|
|
427
|
+
streets?: Record<string, string>;
|
|
428
|
+
};
|
|
429
|
+
declare function displayPathLocation(location: SearchPathFilters["location"], values?: LocationNameTables | null): SearchPathFilters["location"] | null;
|
|
430
|
+
declare function buildQueryListingsParams(pathFilters: SearchPathFilters, applied: AppliedSearchQuery, schema: Pick<SearchUi, "defaultLimit"> | {
|
|
431
|
+
defaultLimit?: number;
|
|
432
|
+
} | null, locationValues?: LocationNameTables | null): QueryListingsParams;
|
|
433
|
+
declare function applyPathFilter(pathFilters: SearchPathFilters, filterId: string, value: unknown): SearchPathFilters;
|
|
434
|
+
declare function pathFilterValue(pathFilters: SearchPathFilters | undefined, filterId: string): string;
|
|
435
|
+
declare function pathFilterHasOption(pathFilters: SearchPathFilters | undefined, filterId: string, optionId: string): boolean;
|
|
436
|
+
declare function publicSearchHref(pathFilters: SearchPathFilters, applied: AppliedSearchQuery, dictionary?: SearchUiDictionary, existingSearch?: string): string;
|
|
437
|
+
declare function hrefForPathFilters(pathname: string, search: string, dictionary: SearchUiDictionary | undefined, nextPathFilters: SearchPathFilters): string;
|
|
438
|
+
declare function hrefForAppliedChange(pathname: string, search: string, dictionary: SearchUiDictionary | undefined, change: AppliedSearchChange): string;
|
|
439
|
+
/** Canonical href if the current URL is out of generation order; otherwise null. */
|
|
440
|
+
declare function canonicalizeSearchHref(pathname: string, search: string, dictionary?: SearchUiDictionary): string | null;
|
|
441
|
+
declare function searchHrefUsesLegacyFilterQuery(href: string): boolean;
|
|
442
|
+
/**
|
|
443
|
+
* Drop staged filters. Location always stays until apply.
|
|
444
|
+
* `keepFilterIds` keeps toolbar-primary filters (price, bedrooms) so Limpar
|
|
445
|
+
* in the extra-filters dialog does not wipe values already on the toolbar.
|
|
446
|
+
*/
|
|
447
|
+
declare function clearStagedPathFilters(current: SearchPathFilters, keepFilterIds?: readonly string[]): SearchPathFilters;
|
|
448
|
+
declare function visibleSearchFilters(schema: SearchUi | null): SearchUiFilter[];
|
|
449
|
+
declare function toolbarFilterIds(schema: SearchUi | null): string[];
|
|
450
|
+
declare function countOptionLabel(option: Pick<SearchUiOption, "label">): string;
|
|
451
|
+
declare function countFacetChoices(options: SearchUiOption[] | undefined): Array<{
|
|
452
|
+
id: string;
|
|
453
|
+
label: string;
|
|
454
|
+
}>;
|
|
455
|
+
/**
|
|
456
|
+
* SEO H1 for a search URL. Must stay stable for the same path — never
|
|
457
|
+
* include the hit count (Google treats a changing H1 on one URL as
|
|
458
|
+
* volatile). Count is rendered in a sibling `<span>`.
|
|
459
|
+
*/
|
|
460
|
+
declare function searchResultsHeading(pathFilters: SearchPathFilters, dictionary?: SearchUiDictionary | null, locationNames?: LocationNameTables | null): string;
|
|
461
|
+
/**
|
|
462
|
+
* Next App Router does not navigate when the href is unchanged. Canonical
|
|
463
|
+
* URLs omit `page=1`, so pagination must still emit `?page=1` on the link.
|
|
464
|
+
*/
|
|
465
|
+
declare function hrefWithExplicitPage(href: string, page: number): string;
|
|
466
|
+
declare function paginationPages(currentPage: number, totalPages: number, padding: number): number[];
|
|
467
|
+
|
|
468
|
+
export { publicSearchHref as $, type AppliedSearchQuery as A, SEARCH_SORT_RELEVANCE as B, type CmsCollection as C, type SearchPathLocation as D, type SearchUiFilter as E, FORBIDDEN_SEARCH_QUERY_KEYS as F, type SearchUiOption as G, applyPathFilter as H, buildQueryListingsParams as I, canonicalizeSearchHref as J, clearStagedPathFilters as K, type ListingFilters as L, countFacetChoices as M, countOptionLabel as N, displayPathLocation as O, hrefForAppliedChange as P, type QueryListingsParams as Q, type RequestNextOptions as R, type SearchListingsParams as S, TOOLBAR_PRIMARY_FILTER_IDS as T, hrefForPathFilters as U, hrefWithExplicitPage as V, isListingDetailPath as W, listingLocationLabel as X, paginationPages as Y, pathFilterHasOption as Z, pathFilterValue as _, type CmsEntriesResult as a, readPublicSearch as a0, searchHrefUsesLegacyFilterQuery as a1, searchResultsHeading as a2, searchSortOptions as a3, toListingCardModel as a4, toolbarFilterIds as a5, visibleSearchFilters as a6, type CmsEntry as b, type ListingDetail as c, type ListingsResult as d, type SearchUi as e, type SimilarListingsResult as f, type Site as g, type QueryListingsResult as h, type SearchListingsResult as i, type SearchPathFilters as j, type SearchUiDictionary as k, type QueryListingsFilters as l, type AppliedSearchChange as m, type CmsEntryStatus as n, type CmsFieldDefinition as o, type CmsFieldType as p, type CmsSeoData as q, type Listing as r, type ListingBusinessType as s, type ListingCardModel as t, type ListingLocation as u, type ListingMedia as v, type ListingPriceVisibility as w, type ListingPropertySummary as x, type LocationNameTables as y, type QueryListingsLocation as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@garagem-ai/site-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Typed, runtime-agnostic SDK for building custom real estate sites against the Garagem platform. Drop into any Next.js (or other JS) project to fetch listings, sites and CMS data.",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"import": "./dist/react.mjs",
|
|
19
19
|
"require": "./dist/react.js",
|
|
20
20
|
"default": "./dist/react.js"
|
|
21
|
-
}
|
|
21
|
+
},
|
|
22
|
+
"./react/search.css": "./src/react/search.css"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"dist",
|
|
@@ -40,10 +41,12 @@
|
|
|
40
41
|
"import": "./dist/react.mjs",
|
|
41
42
|
"require": "./dist/react.js",
|
|
42
43
|
"default": "./dist/react.js"
|
|
43
|
-
}
|
|
44
|
+
},
|
|
45
|
+
"./react/search.css": "./src/react/search.css"
|
|
44
46
|
}
|
|
45
47
|
},
|
|
46
48
|
"scripts": {
|
|
49
|
+
"prebuild": "node scripts/build-search-chrome-css.mjs",
|
|
47
50
|
"build": "tsup",
|
|
48
51
|
"dev": "tsup --watch",
|
|
49
52
|
"test": "vitest run",
|
|
@@ -80,7 +83,9 @@
|
|
|
80
83
|
"optional": true
|
|
81
84
|
}
|
|
82
85
|
},
|
|
83
|
-
"sideEffects":
|
|
86
|
+
"sideEffects": [
|
|
87
|
+
"**/*.css"
|
|
88
|
+
],
|
|
84
89
|
"keywords": [
|
|
85
90
|
"garagem",
|
|
86
91
|
"real-estate",
|
package/src/index.ts
CHANGED
|
@@ -113,6 +113,7 @@ export {
|
|
|
113
113
|
displayPathLocation,
|
|
114
114
|
hrefForAppliedChange,
|
|
115
115
|
hrefForPathFilters,
|
|
116
|
+
hrefWithExplicitPage,
|
|
116
117
|
isListingDetailPath,
|
|
117
118
|
paginationPages,
|
|
118
119
|
pathFilterHasOption,
|
|
@@ -123,6 +124,7 @@ export {
|
|
|
123
124
|
searchSortOptions,
|
|
124
125
|
toolbarFilterIds,
|
|
125
126
|
visibleSearchFilters,
|
|
127
|
+
searchResultsHeading,
|
|
126
128
|
type LocationNameTables,
|
|
127
129
|
} from "./search-engine";
|
|
128
130
|
|
|
@@ -151,6 +153,19 @@ export {
|
|
|
151
153
|
type ResolvePublicSiteIdOptions,
|
|
152
154
|
} from "./resolve-site-id";
|
|
153
155
|
|
|
156
|
+
export {
|
|
157
|
+
STUDIO_SDK_CONTRACT,
|
|
158
|
+
STUDIO_SDK_PACKAGE,
|
|
159
|
+
coerceNpmVersion,
|
|
160
|
+
compareSemver,
|
|
161
|
+
parseReactSdkNamedImports,
|
|
162
|
+
studioChromeInstruction,
|
|
163
|
+
studioCodegenContractViolations,
|
|
164
|
+
studioSdkPinInstruction,
|
|
165
|
+
unavailableReactImports,
|
|
166
|
+
type StudioSdkContract,
|
|
167
|
+
} from "./studio-contract";
|
|
168
|
+
|
|
154
169
|
export {
|
|
155
170
|
createGaragemClient,
|
|
156
171
|
type CreateGaragemClientOptions,
|
package/src/presentation.ts
CHANGED
|
@@ -9,13 +9,20 @@ export const SEARCH_CSS_VARS = {
|
|
|
9
9
|
cardGap: "--garagem-listing-card-gap",
|
|
10
10
|
priceSize: "--garagem-listing-price-size",
|
|
11
11
|
mediaRatio: "--garagem-listing-media-ratio",
|
|
12
|
+
controlHeight: "--garagem-search-control-height",
|
|
13
|
+
iconSize: "--garagem-search-icon-size",
|
|
14
|
+
skeleton: "--garagem-skeleton",
|
|
12
15
|
} as const;
|
|
13
16
|
|
|
17
|
+
/** Paste into generated `globals.css` to override tokens. Layout lives in the chrome artifact. */
|
|
14
18
|
export const SEARCH_CSS_RECIPE = `:root {
|
|
15
19
|
${SEARCH_CSS_VARS.cardRadius}: 0.75rem;
|
|
16
20
|
${SEARCH_CSS_VARS.cardGap}: 1.5rem;
|
|
17
21
|
${SEARCH_CSS_VARS.priceSize}: 1.125rem;
|
|
18
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);
|
|
19
26
|
}
|
|
20
27
|
`;
|
|
21
28
|
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
pathFilterValue,
|
|
10
10
|
} from "../search-engine";
|
|
11
11
|
import type { SearchPathFilters, SearchUiFilter } from "../types";
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
export type RangeCommitSource = "blur" | "enter" | "apply";
|
|
13
14
|
|
|
14
15
|
export type FilterPanelProps = {
|
|
15
16
|
filters: SearchUiFilter[];
|
|
@@ -17,7 +18,7 @@ export type FilterPanelProps = {
|
|
|
17
18
|
onChange: (filterId: string, value: unknown) => void;
|
|
18
19
|
rangeDraft: Record<string, { min: string; max: string }>;
|
|
19
20
|
onRangePatch: (filterId: string, side: "min" | "max", value: string) => void;
|
|
20
|
-
onRangeCommit: (filterId: string) => void;
|
|
21
|
+
onRangeCommit: (filterId: string, source?: RangeCommitSource) => void;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
function RangeFields({
|
|
@@ -36,30 +37,35 @@ function RangeFields({
|
|
|
36
37
|
const patch = (side: "min" | "max", raw: string) => {
|
|
37
38
|
onRangePatch(filter.id, side, isPrice ? formatGroupedInteger(raw) : raw);
|
|
38
39
|
};
|
|
39
|
-
const inputClass =
|
|
40
|
-
"min-h-10 w-full rounded-lg border border-border bg-background px-3";
|
|
41
40
|
return (
|
|
42
|
-
<fieldset
|
|
43
|
-
<legend
|
|
44
|
-
<div
|
|
41
|
+
<fieldset data-slot="search-filter">
|
|
42
|
+
<legend>{filter.label}</legend>
|
|
43
|
+
<div data-slot="search-range-row">
|
|
45
44
|
<RangeSide
|
|
46
45
|
id={`${filter.id}-min`}
|
|
47
46
|
label="Mín"
|
|
48
47
|
isPrice={isPrice}
|
|
49
48
|
value={draft.min}
|
|
50
|
-
inputClass={inputClass}
|
|
51
49
|
onPatch={(raw) => patch("min", raw)}
|
|
52
|
-
onCommit={() => onRangeCommit(filter.id)}
|
|
50
|
+
onCommit={() => onRangeCommit(filter.id, "blur")}
|
|
51
|
+
onEnter={() => onRangeCommit(filter.id, "enter")}
|
|
53
52
|
/>
|
|
54
53
|
<RangeSide
|
|
55
54
|
id={`${filter.id}-max`}
|
|
56
55
|
label="Máx"
|
|
57
56
|
isPrice={isPrice}
|
|
58
57
|
value={draft.max}
|
|
59
|
-
inputClass={inputClass}
|
|
60
58
|
onPatch={(raw) => patch("max", raw)}
|
|
61
|
-
onCommit={() => onRangeCommit(filter.id)}
|
|
59
|
+
onCommit={() => onRangeCommit(filter.id, "blur")}
|
|
60
|
+
onEnter={() => onRangeCommit(filter.id, "enter")}
|
|
62
61
|
/>
|
|
62
|
+
<button
|
|
63
|
+
type="button"
|
|
64
|
+
data-slot="search-range-apply"
|
|
65
|
+
onClick={() => onRangeCommit(filter.id, "apply")}
|
|
66
|
+
>
|
|
67
|
+
Atualizar
|
|
68
|
+
</button>
|
|
63
69
|
</div>
|
|
64
70
|
</fieldset>
|
|
65
71
|
);
|
|
@@ -70,17 +76,17 @@ function RangeSide({
|
|
|
70
76
|
label,
|
|
71
77
|
isPrice,
|
|
72
78
|
value,
|
|
73
|
-
inputClass,
|
|
74
79
|
onPatch,
|
|
75
80
|
onCommit,
|
|
81
|
+
onEnter,
|
|
76
82
|
}: {
|
|
77
83
|
id: string;
|
|
78
84
|
label: string;
|
|
79
85
|
isPrice: boolean;
|
|
80
86
|
value: string;
|
|
81
|
-
inputClass: string;
|
|
82
87
|
onPatch: (raw: string) => void;
|
|
83
88
|
onCommit: () => void;
|
|
89
|
+
onEnter: () => void;
|
|
84
90
|
}): ReactElement {
|
|
85
91
|
const input = (
|
|
86
92
|
<input
|
|
@@ -94,19 +100,20 @@ function RangeSide({
|
|
|
94
100
|
onChange={(event) => onPatch(event.target.value)}
|
|
95
101
|
onBlur={onCommit}
|
|
96
102
|
onKeyDown={(event) => {
|
|
97
|
-
if (event.key === "Enter")
|
|
103
|
+
if (event.key === "Enter") {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
onEnter();
|
|
106
|
+
}
|
|
98
107
|
}}
|
|
99
|
-
|
|
108
|
+
data-slot="search-range-input"
|
|
100
109
|
/>
|
|
101
110
|
);
|
|
102
111
|
return (
|
|
103
|
-
<label
|
|
104
|
-
<span
|
|
112
|
+
<label data-slot="search-range-side" htmlFor={id}>
|
|
113
|
+
<span>{label}</span>
|
|
105
114
|
{isPrice ? (
|
|
106
|
-
<span
|
|
107
|
-
<span
|
|
108
|
-
R$
|
|
109
|
-
</span>
|
|
115
|
+
<span data-slot="search-range-affix">
|
|
116
|
+
<span data-slot="search-range-prefix">R$</span>
|
|
110
117
|
{input}
|
|
111
118
|
</span>
|
|
112
119
|
) : (
|
|
@@ -128,18 +135,16 @@ function CountFields({
|
|
|
128
135
|
const selected = pathFilterValue(pathFilters, filter.id);
|
|
129
136
|
const choices = countFacetChoices(filter.options);
|
|
130
137
|
return (
|
|
131
|
-
<fieldset
|
|
132
|
-
<legend
|
|
133
|
-
<div
|
|
138
|
+
<fieldset data-slot="search-filter">
|
|
139
|
+
<legend>{filter.label}</legend>
|
|
140
|
+
<div data-slot="search-count-group" role="group">
|
|
134
141
|
{choices.map((choice) => (
|
|
135
142
|
<button
|
|
136
143
|
key={choice.id}
|
|
137
144
|
type="button"
|
|
145
|
+
data-slot="search-count-choice"
|
|
146
|
+
data-selected={selected === choice.id ? "true" : undefined}
|
|
138
147
|
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
148
|
>
|
|
144
149
|
{choice.label}
|
|
145
150
|
</button>
|
|
@@ -161,24 +166,16 @@ function EnumFields({
|
|
|
161
166
|
const options = filter.options || [];
|
|
162
167
|
const scroll = options.length > 8;
|
|
163
168
|
return (
|
|
164
|
-
<fieldset
|
|
165
|
-
<legend
|
|
166
|
-
<div
|
|
167
|
-
className={cn(
|
|
168
|
-
"flex flex-col gap-1.5",
|
|
169
|
-
scroll && "max-h-48 overflow-y-auto"
|
|
170
|
-
)}
|
|
171
|
-
>
|
|
169
|
+
<fieldset data-slot="search-filter">
|
|
170
|
+
<legend>{filter.label}</legend>
|
|
171
|
+
<div data-slot={scroll ? "search-scroll" : "search-enum-list"}>
|
|
172
172
|
{options.map((option) => (
|
|
173
|
-
<label
|
|
174
|
-
key={option.id}
|
|
175
|
-
className="flex cursor-pointer items-center gap-2"
|
|
176
|
-
>
|
|
173
|
+
<label key={option.id} data-slot="search-enum-option">
|
|
177
174
|
<input
|
|
178
175
|
type="checkbox"
|
|
176
|
+
data-slot="search-checkbox"
|
|
179
177
|
checked={pathFilterHasOption(pathFilters, filter.id, option.id)}
|
|
180
178
|
onChange={() => onChange(filter.id, option.id)}
|
|
181
|
-
className="cursor-pointer"
|
|
182
179
|
/>
|
|
183
180
|
<span>{option.label}</span>
|
|
184
181
|
</label>
|
|
@@ -197,7 +194,7 @@ export function FilterPanel({
|
|
|
197
194
|
onRangeCommit,
|
|
198
195
|
}: FilterPanelProps): ReactElement {
|
|
199
196
|
return (
|
|
200
|
-
<div
|
|
197
|
+
<div data-slot="search-filters">
|
|
201
198
|
{filters.map((filter) => {
|
|
202
199
|
if (filter.type === "range") {
|
|
203
200
|
return (
|
|
@@ -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
|
+
}
|
package/src/react/index.ts
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
export { ListingCard } from "./listing-card";
|
|
4
4
|
export { SearchPage } from "./search-page";
|
|
5
|
+
export { SearchChromeStyles } from "./styles";
|
|
5
6
|
export { SearchPagination } from "./search-pagination";
|
|
6
7
|
export { SearchQueryForm } from "./search-query-form";
|
|
7
8
|
export { FilterPanel, rangeDraftFromPath } from "./filter-panel";
|
|
8
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
ResultsSkeleton,
|
|
11
|
+
SearchPageFallback,
|
|
12
|
+
SearchSortSelect,
|
|
13
|
+
} from "./search-chrome";
|
|
9
14
|
export { usePublicSearch } from "./use-public-search";
|
|
10
15
|
export type {
|
|
11
16
|
ListingCardClassNames,
|
|
@@ -13,6 +18,7 @@ export type {
|
|
|
13
18
|
ListingCardSlots,
|
|
14
19
|
PublicSearchState,
|
|
15
20
|
SearchPageClassNames,
|
|
21
|
+
SearchPageIcons,
|
|
16
22
|
SearchPageVariant,
|
|
17
23
|
SiteIdInput,
|
|
18
24
|
UsePublicSearchOptions,
|