@realadvisor-sites/kit-astro 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +38 -2
- package/astro.d.mts +4 -0
- package/astro.mjs +122 -0
- package/components/ConsentBanner.astro +35 -0
- package/components/EnquiryForm.astro +149 -0
- package/components/LegalContent.astro +32 -0
- package/components/ListingsMap.astro +153 -0
- package/components/ListingsPager.astro +45 -0
- package/components/ListingsSearch.astro +490 -0
- package/components/RaImage.astro +79 -0
- package/components/form/Button.astro +25 -0
- package/components/form/Combobox.astro +41 -0
- package/components/form/Input.astro +26 -0
- package/components/form/Select.astro +35 -0
- package/lib/ra.ts +145 -0
- package/middleware.ts +93 -0
- package/package.json +44 -4
- package/tools/keep-assets.mjs +79 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* THE listing search: filters, active-filter chips, count, sort, list / map
|
|
4
|
+
* views, pagination, empty states and the phone List/Map pill. Every agency
|
|
5
|
+
* site's /listings renders it; designs theme it, they never rewrite it.
|
|
6
|
+
*
|
|
7
|
+
* const params = parseSearch(Astro.url.searchParams);
|
|
8
|
+
* const result = runSearch(await allListings(), params, { locale: LOCALE });
|
|
9
|
+
* <h1 data-rs-sync="h1">{heading}</h1>
|
|
10
|
+
* <ListingsSearch result={result} contactHref="/contact" valuationHref="/contact#valuation">
|
|
11
|
+
* {(l, i) => <ListingCard listing={l} />}
|
|
12
|
+
* </ListingsSearch>
|
|
13
|
+
*
|
|
14
|
+
* The default slot is a callback rendering the design's own card (a plain
|
|
15
|
+
* card when there is none); the `empty` slot replaces the "no listings at
|
|
16
|
+
* all" block. Works without JS (GET form, links); with JS
|
|
17
|
+
* (@realadvisor/sites-kit-core/client/listings-search.ts) filters apply without a page load and the
|
|
18
|
+
* page's `data-rs-sync` elements and title follow.
|
|
19
|
+
*
|
|
20
|
+
* Theme with tokens (fallbacks included): --accent, --text, --paper,
|
|
21
|
+
* --surface, --line, --muted, --control-radius, --header-h (sticky offset),
|
|
22
|
+
* --rs-columns (max grid columns, 3), --rs-gap, --map-h; selected states
|
|
23
|
+
* --rs-active / --rs-on-active (default text / paper), --rs-pill-radius,
|
|
24
|
+
* --rs-sheet-radius, --rs-heading-weight, --rs-card-h (card height, map list).
|
|
25
|
+
* Class hooks: rs-*.
|
|
26
|
+
*/
|
|
27
|
+
import type { Listing } from '../lib/ra';
|
|
28
|
+
import { mapView, searchHref, type FilterKey, type SearchResult } from '@realadvisor/sites-kit-core/search';
|
|
29
|
+
import { formatAmount, formatPrice, formatSurface, listingUrl, LOCALE } from '@realadvisor/sites-kit-core/format';
|
|
30
|
+
import { count, lang, localePath, offerTypeLabel, propertyTypeLabel, t } from '@realadvisor/sites-kit-core/i18n';
|
|
31
|
+
import ListingsMap from './ListingsMap.astro';
|
|
32
|
+
import ListingsPager from './ListingsPager.astro';
|
|
33
|
+
import RaImage from './RaImage.astro';
|
|
34
|
+
import Select from './form/Select.astro';
|
|
35
|
+
import Combobox from './form/Combobox.astro';
|
|
36
|
+
import Button from './form/Button.astro';
|
|
37
|
+
|
|
38
|
+
type FilterName = 'offerType' | 'propertyType' | 'city' | 'price' | 'rooms';
|
|
39
|
+
interface Props {
|
|
40
|
+
result: SearchResult;
|
|
41
|
+
/** Path of the search page (renamed paths: `/proprietes`). */
|
|
42
|
+
base?: string;
|
|
43
|
+
/** Page locale on a multi-language site (e.g. 'en-CH'). */
|
|
44
|
+
locale?: string;
|
|
45
|
+
contactHref?: string;
|
|
46
|
+
valuationHref?: string;
|
|
47
|
+
/** "Tell us what you need" on no match (a search-profile page); default `contactHref`. */
|
|
48
|
+
tellUsHref?: string;
|
|
49
|
+
/** Listing URL for the plain card and the map (default `/listings/<slug>` in the page language). */
|
|
50
|
+
listingHref?: (l: Listing) => string;
|
|
51
|
+
/** Map popup price (default `formatPrice`), when the design's cards format prices their own way. */
|
|
52
|
+
price?: (l: Listing) => string;
|
|
53
|
+
/** Filters to show (default: all that the data supports). */
|
|
54
|
+
filters?: FilterName[];
|
|
55
|
+
/** Show the Available / Sold switch when the agency has sold listings. */
|
|
56
|
+
sold?: boolean;
|
|
57
|
+
class?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const {
|
|
61
|
+
result,
|
|
62
|
+
locale = LOCALE,
|
|
63
|
+
base = localePath('/listings', locale),
|
|
64
|
+
contactHref,
|
|
65
|
+
valuationHref,
|
|
66
|
+
tellUsHref = contactHref,
|
|
67
|
+
listingHref = (x: Listing) => localePath(listingUrl(x), locale),
|
|
68
|
+
price,
|
|
69
|
+
filters = ['offerType', 'propertyType', 'city', 'price', 'rooms'],
|
|
70
|
+
sold = true,
|
|
71
|
+
class: cls,
|
|
72
|
+
} = Astro.props;
|
|
73
|
+
const l = lang(locale);
|
|
74
|
+
const { params: p, facets, counts, total } = result;
|
|
75
|
+
const href = (over: Parameters<typeof searchHref>[2] = {}) => searchHref(base, p, over);
|
|
76
|
+
const show = (f: FilterName) => filters.includes(f);
|
|
77
|
+
const isMap = p.view === 'map';
|
|
78
|
+
const nothingAtAll = counts.available + counts.sold === 0;
|
|
79
|
+
|
|
80
|
+
// Current values stay selectable even when the facets no longer list them.
|
|
81
|
+
const withCurrent = <T extends { value: string }>(opts: T[], value: string | undefined, make: (v: string) => T) =>
|
|
82
|
+
value && !opts.some((o) => o.value === value) ? [make(value), ...opts] : opts;
|
|
83
|
+
const amount = (n: number) => formatAmount(n);
|
|
84
|
+
const typeOptions = withCurrent(
|
|
85
|
+
facets.propertyTypes.map((f) => ({ value: f.value, label: propertyTypeLabel(f.value, locale) })),
|
|
86
|
+
p.propertyType,
|
|
87
|
+
(v) => ({ value: v, label: propertyTypeLabel(v, locale) }),
|
|
88
|
+
);
|
|
89
|
+
const cityOptions = withCurrent(facets.cities.map((f) => ({ value: f.value, label: f.value })), p.city, (v) => ({ value: v, label: v }));
|
|
90
|
+
const priceOptions = withCurrent(
|
|
91
|
+
facets.prices.map((n) => ({ value: String(n), label: t('priceMax', { price: amount(n) }, l) })),
|
|
92
|
+
p.maxPrice ? String(p.maxPrice) : undefined,
|
|
93
|
+
(v) => ({ value: v, label: t('priceMax', { price: amount(Number(v)) }, l) }),
|
|
94
|
+
);
|
|
95
|
+
const roomOptions = withCurrent(
|
|
96
|
+
facets.rooms.map((n) => ({ value: String(n), label: t('roomsMin', { n: String(n) }, l) })),
|
|
97
|
+
p.minRooms ? String(p.minRooms) : undefined,
|
|
98
|
+
(v) => ({ value: v, label: t('roomsMin', { n: v }, l) }),
|
|
99
|
+
);
|
|
100
|
+
const sortOptions = (['newest', 'price-asc', 'price-desc', 'surface-desc'] as const).map((s) => ({ value: s, label: t(`sort_${s}`, {}, l) }));
|
|
101
|
+
const showOffer = show('offerType') && (facets.offerTypes.length > 1 || !!p.offerType);
|
|
102
|
+
const nFilters = result.chips.length;
|
|
103
|
+
|
|
104
|
+
const chipLabel = (k: FilterKey): string =>
|
|
105
|
+
k === 'offerType' ? offerTypeLabel(p.offerType!, locale)
|
|
106
|
+
: k === 'propertyType' ? propertyTypeLabel(p.propertyType, locale)
|
|
107
|
+
: k === 'city' ? p.city!
|
|
108
|
+
: k === 'minPrice' ? t('priceMin', { price: amount(p.minPrice!) }, l)
|
|
109
|
+
: k === 'maxPrice' ? t('priceMax', { price: amount(p.maxPrice!) }, l)
|
|
110
|
+
: k === 'bbox' ? t('mapArea', {}, l)
|
|
111
|
+
: t('roomsMin', { n: String(p.minRooms) }, l);
|
|
112
|
+
const resetHref = searchHref(base, { ...p, offerType: undefined, propertyType: undefined, city: undefined, minPrice: undefined, maxPrice: undefined, minRooms: undefined, bbox: undefined }, { page: undefined, map: undefined });
|
|
113
|
+
|
|
114
|
+
// Map view: the cards and the markers are the same listings.
|
|
115
|
+
// Map view with markers: cards of the map area | map (the server filters by `bbox`).
|
|
116
|
+
const mapMode = isMap && result.mapItems.length > 0;
|
|
117
|
+
|
|
118
|
+
// The design's card, or a plain one.
|
|
119
|
+
const hasCard = Astro.slots.has('default');
|
|
120
|
+
const cards = hasCard ? await Promise.all(result.items.map((x, i) => Astro.slots.render('default', [x, i]))) : [];
|
|
121
|
+
const facts = (x: Listing) =>
|
|
122
|
+
[x.rooms ? `${x.rooms} ${t('rooms', {}, l).toLowerCase()}` : '', x.living_surface ? formatSurface(x.living_surface) : ''].filter(Boolean).join(' · ');
|
|
123
|
+
const cardSizes = isMap ? '(min-width: 1280px) 300px, (min-width: 960px) 40vw, 100vw' : '(min-width: 1024px) 400px, (min-width: 640px) 50vw, 100vw';
|
|
124
|
+
---
|
|
125
|
+
<div class:list={['rs', { 'is-map': isMap }, cls]} data-rs-root data-rs-view={p.view}>
|
|
126
|
+
{!nothingAtAll && (
|
|
127
|
+
<form method="get" action={base} class="rs-form" data-rs-form role="search" aria-label={t('filters', {}, l)}>
|
|
128
|
+
{isMap && <input type="hidden" name="view" value="map" />}
|
|
129
|
+
{p.status === 'sold' && <input type="hidden" name="status" value="sold" />}
|
|
130
|
+
<div class="rs-top">
|
|
131
|
+
<button type="button" class="rs-filters-btn" popovertarget="rs-sheet">
|
|
132
|
+
<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round"><path d="M4 6h10M18 6h2M4 12h4M12 12h8M4 18h12M20 18h0" /><circle cx="16" cy="6" r="2" /><circle cx="10" cy="12" r="2" /><circle cx="18" cy="18" r="2" /></svg>
|
|
133
|
+
<span>{t('filters', {}, l)}</span>
|
|
134
|
+
<span class="rs-badge" data-rs-swap="badge" hidden={!nFilters}>{nFilters}</span>
|
|
135
|
+
</button>
|
|
136
|
+
<div id="rs-sheet" class="rs-sheet" popover>
|
|
137
|
+
<div class="rs-sheet-head">
|
|
138
|
+
<p class="rs-sheet-title">{t('filters', {}, l)}</p>
|
|
139
|
+
<button type="button" class="rs-sheet-close" popovertarget="rs-sheet" popovertargetaction="hide" aria-label={t('close', {}, l)}>
|
|
140
|
+
<svg aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18" /></svg>
|
|
141
|
+
</button>
|
|
142
|
+
</div>
|
|
143
|
+
{showOffer && (
|
|
144
|
+
<fieldset class="rs-offer field">
|
|
145
|
+
<legend class="field-label">{t('offer', {}, l)}</legend>
|
|
146
|
+
<div class="rs-seg">
|
|
147
|
+
<label><input type="radio" name="offerType" value="" checked={!p.offerType} /><span>{t('all', {}, l)}</span></label>
|
|
148
|
+
<label><input type="radio" name="offerType" value="buy" checked={p.offerType === 'buy'} /><span>{t('offerBuy', {}, l)}</span></label>
|
|
149
|
+
<label><input type="radio" name="offerType" value="rent" checked={p.offerType === 'rent'} /><span>{t('offerRent', {}, l)}</span></label>
|
|
150
|
+
</div>
|
|
151
|
+
</fieldset>
|
|
152
|
+
)}
|
|
153
|
+
{!showOffer && p.offerType && <input type="hidden" name="offerType" value={p.offerType} />}
|
|
154
|
+
{show('city') && cityOptions.length > 1 && (
|
|
155
|
+
<Combobox label={t('city', {}, l)} name="city" value={p.city} placeholder={t('allCities', {}, l)} options={cityOptions} class="rs-city" />
|
|
156
|
+
)}
|
|
157
|
+
{show('propertyType') && typeOptions.length > 1 && (
|
|
158
|
+
<Select label={t('propertyType', {}, l)} name="propertyType" value={p.propertyType} placeholder={t('all', {}, l)} options={typeOptions} class="rs-type" />
|
|
159
|
+
)}
|
|
160
|
+
{show('price') && priceOptions.length > 0 && (
|
|
161
|
+
<Select label={t('price', {}, l)} name="maxPrice" value={p.maxPrice ? String(p.maxPrice) : undefined} placeholder={t('any', {}, l)} options={priceOptions} class="rs-price" />
|
|
162
|
+
)}
|
|
163
|
+
{p.minPrice && <input type="hidden" name="minPrice" value={String(p.minPrice)} />}
|
|
164
|
+
{show('rooms') && roomOptions.length > 1 && (
|
|
165
|
+
<Select label={t('rooms', {}, l)} name="minRooms" value={p.minRooms ? String(p.minRooms) : undefined} placeholder={t('any', {}, l)} options={roomOptions} class="rs-rooms" />
|
|
166
|
+
)}
|
|
167
|
+
<Button type="submit" class="rs-apply"><span data-rs-swap="apply">{count('showListings', total, l)}</span></Button>
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<div class="rs-bar">
|
|
172
|
+
<p class="rs-count" data-rs-count data-rs-swap="count" aria-live="polite" tabindex="-1">{count('listingsFound', total, l)}</p>
|
|
173
|
+
<div class="rs-tools">
|
|
174
|
+
{sold && counts.sold > 0 && (
|
|
175
|
+
<nav class="rs-status" aria-label={t('status', {}, l)} data-rs-swap="status">
|
|
176
|
+
<a href={href({ status: undefined })} aria-current={p.status === 'available' ? 'page' : undefined}>{t('currentListings', {}, l)}</a>
|
|
177
|
+
<a href={href({ status: 'sold' })} aria-current={p.status === 'sold' ? 'page' : undefined}>{t('soldListings', {}, l)} <span class="rs-n">{counts.sold}</span></a>
|
|
178
|
+
</nav>
|
|
179
|
+
)}
|
|
180
|
+
<Select label={t('sort', {}, l)} hideLabel name="sort" value={p.sort} options={sortOptions} class="rs-sort" />
|
|
181
|
+
<nav class="rs-views" aria-label={`${t('viewList', {}, l)} / ${t('viewMap', {}, l)}`} data-rs-swap="views">
|
|
182
|
+
<a href={href({ view: undefined })} data-rs-nav data-rs-view="list" aria-current={!isMap ? 'page' : undefined}>
|
|
183
|
+
<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75"><rect x="4" y="4" width="7" height="7" /><rect x="13" y="4" width="7" height="7" /><rect x="4" y="13" width="7" height="7" /><rect x="13" y="13" width="7" height="7" /></svg>
|
|
184
|
+
{t('viewList', {}, l)}
|
|
185
|
+
</a>
|
|
186
|
+
<a href={href({ view: 'map' })} data-rs-nav data-rs-view="map" aria-current={isMap ? 'page' : undefined}>
|
|
187
|
+
<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linejoin="round"><path d="M9 4 3 6v14l6-2 6 2 6-2V4l-6 2-6-2zM9 4v14M15 6v14" /></svg>
|
|
188
|
+
{t('viewMap', {}, l)}
|
|
189
|
+
</a>
|
|
190
|
+
</nav>
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
</form>
|
|
194
|
+
)}
|
|
195
|
+
|
|
196
|
+
<div class="rs-chips" data-rs-chips data-rs-swap="chips" hidden={!nFilters} aria-label={t('activeFilters', {}, l)} role="group">
|
|
197
|
+
{result.chips.map((k) => (
|
|
198
|
+
<a class="rs-chip" href={href({ [k]: undefined })} data-rs-nav aria-label={t('removeFilter', { filter: chipLabel(k) }, l)}>
|
|
199
|
+
{chipLabel(k)}<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M7 7l10 10M17 7L7 17" /></svg>
|
|
200
|
+
</a>
|
|
201
|
+
))}
|
|
202
|
+
{nFilters > 1 && <a class="rs-reset" href={resetHref} data-rs-nav>{t('resetFilters', {}, l)}</a>}
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
<div class="rs-region" data-rs-swap="results">
|
|
206
|
+
{nothingAtAll ? (
|
|
207
|
+
Astro.slots.has('empty') ? <div data-rs-empty="none"><slot name="empty" /></div> : (
|
|
208
|
+
<div class="rs-empty" data-rs-empty="none">
|
|
209
|
+
<h2 class="rs-empty-title">{t('noListings', {}, l)}</h2>
|
|
210
|
+
<p class="rs-empty-text">{t('noListingsText', {}, l)}</p>
|
|
211
|
+
<p class="rs-empty-actions">
|
|
212
|
+
{valuationHref && <Button href={valuationHref}>{t('valuation', {}, l)}</Button>}
|
|
213
|
+
{contactHref && <Button href={contactHref} variant="secondary">{t('contactUs', {}, l)}</Button>}
|
|
214
|
+
</p>
|
|
215
|
+
</div>
|
|
216
|
+
)
|
|
217
|
+
) : mapMode ? (
|
|
218
|
+
<Fragment>
|
|
219
|
+
{result.truncated && <p class="rs-note">{t('mapTruncated', { n: String(result.mapItems.length) }, l)}</p>}
|
|
220
|
+
<div class="rs-results rs-split">
|
|
221
|
+
<div class="rs-col">
|
|
222
|
+
{total > 0 ? (
|
|
223
|
+
<ul id="rs-results" class="rs-grid rs-list" data-rs-results>
|
|
224
|
+
{result.items.map((x, i) => (
|
|
225
|
+
<li data-listing-id={x.id}>
|
|
226
|
+
{hasCard ? <Fragment set:html={cards[i]} /> : (
|
|
227
|
+
<a class="rs-card" href={listingHref(x)}>
|
|
228
|
+
{x.photos[0] ? (
|
|
229
|
+
<RaImage src={x.photos[0]} alt={x.photos[0].alt ?? `${propertyTypeLabel(x.property_type, locale)}, ${x.address.city ?? ''}`} width={600} height={400} sizes={cardSizes} />
|
|
230
|
+
) : (
|
|
231
|
+
<span class="rs-card-nophoto" aria-hidden="true">{propertyTypeLabel(x.property_type, locale)}</span>
|
|
232
|
+
)}
|
|
233
|
+
<span class="rs-card-type">{propertyTypeLabel(x.property_type, locale)}{x.address.city && ` · ${x.address.city}`}</span>
|
|
234
|
+
<span class="rs-card-title">{x.title}</span>
|
|
235
|
+
<span class="rs-card-price">{x.status === 'sold' ? t('sold', {}, l) : formatPrice(x)}</span>
|
|
236
|
+
{facts(x) && <span class="rs-card-facts">{facts(x)}</span>}
|
|
237
|
+
</a>
|
|
238
|
+
)}
|
|
239
|
+
</li>
|
|
240
|
+
))}
|
|
241
|
+
</ul>
|
|
242
|
+
) : (
|
|
243
|
+
// Nothing in the map area (the markers elsewhere stay): zoom out, or drop the area.
|
|
244
|
+
<div class="rs-empty rs-empty-area" data-rs-empty="area">
|
|
245
|
+
<h2 class="rs-empty-title">{t('noneInArea', {}, l)}</h2>
|
|
246
|
+
<p class="rs-empty-text">{t('noneInAreaText', {}, l)}</p>
|
|
247
|
+
{result.relax.length > 0 && (
|
|
248
|
+
<ul class="rs-relax">
|
|
249
|
+
{result.relax.map((r) => (
|
|
250
|
+
<li><a href={href({ [r.key]: undefined })} data-rs-nav>{t('removeFilter', { filter: chipLabel(r.key) }, l)}</a> <span class="rs-n">{count('listings', r.count, l)}</span></li>
|
|
251
|
+
))}
|
|
252
|
+
</ul>
|
|
253
|
+
)}
|
|
254
|
+
<p class="rs-empty-actions"><Button href={resetHref} data-rs-reset data-rs-nav>{t('resetFilters', {}, l)}</Button></p>
|
|
255
|
+
</div>
|
|
256
|
+
)}
|
|
257
|
+
<ListingsPager result={result} href={href} locale={locale} />
|
|
258
|
+
</div>
|
|
259
|
+
<div class="rs-map" data-rs-map>
|
|
260
|
+
<div class="rs-follow" data-rs-follow-bar>
|
|
261
|
+
<label class="rs-follow-toggle"><input type="checkbox" data-rs-follow checked /> <span>{t('searchAsMove', {}, l)}</span></label>
|
|
262
|
+
<button type="button" class="rs-search-area" data-rs-search-area hidden>{t('searchThisArea', {}, l)}</button>
|
|
263
|
+
</div>
|
|
264
|
+
<ListingsMap listings={result.mapItems} list="rs-results" locale={locale} view={mapView(p.map)} sync listMode="server" href={listingHref} price={price} />
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
</Fragment>
|
|
268
|
+
) : total === 0 ? (
|
|
269
|
+
<div class="rs-empty" data-rs-empty="nomatch">
|
|
270
|
+
<h2 class="rs-empty-title">{t('noMatch', {}, l)}</h2>
|
|
271
|
+
<p class="rs-empty-text">{t('noMatchText', {}, l)}</p>
|
|
272
|
+
{result.relax.length > 0 && (
|
|
273
|
+
<ul class="rs-relax">
|
|
274
|
+
{result.relax.map((r) => (
|
|
275
|
+
<li><a href={href({ [r.key]: undefined })} data-rs-nav>{t('removeFilter', { filter: chipLabel(r.key) }, l)}</a> <span class="rs-n">{count('listings', r.count, l)}</span></li>
|
|
276
|
+
))}
|
|
277
|
+
</ul>
|
|
278
|
+
)}
|
|
279
|
+
<p class="rs-empty-actions">
|
|
280
|
+
<Button href={resetHref} data-rs-reset data-rs-nav>{t('resetFilters', {}, l)}</Button>
|
|
281
|
+
{tellUsHref && <Button href={tellUsHref} variant="secondary">{t('tellUs', {}, l)}</Button>}
|
|
282
|
+
</p>
|
|
283
|
+
</div>
|
|
284
|
+
) : (
|
|
285
|
+
<Fragment>
|
|
286
|
+
{isMap && <p class="rs-note">{t('noCoords', {}, l)}</p>}
|
|
287
|
+
<div class="rs-results">
|
|
288
|
+
<ul id="rs-results" class="rs-grid" data-rs-results>
|
|
289
|
+
{result.items.map((x, i) => (
|
|
290
|
+
<li data-listing-id={x.id}>
|
|
291
|
+
{hasCard ? <Fragment set:html={cards[i]} /> : (
|
|
292
|
+
<a class="rs-card" href={listingHref(x)}>
|
|
293
|
+
{x.photos[0] ? (
|
|
294
|
+
<RaImage src={x.photos[0]} alt={x.photos[0].alt ?? `${propertyTypeLabel(x.property_type, locale)}, ${x.address.city ?? ''}`} width={600} height={400} sizes={cardSizes} />
|
|
295
|
+
) : (
|
|
296
|
+
<span class="rs-card-nophoto" aria-hidden="true">{propertyTypeLabel(x.property_type, locale)}</span>
|
|
297
|
+
)}
|
|
298
|
+
<span class="rs-card-type">{propertyTypeLabel(x.property_type, locale)}{x.address.city && ` · ${x.address.city}`}</span>
|
|
299
|
+
<span class="rs-card-title">{x.title}</span>
|
|
300
|
+
<span class="rs-card-price">{x.status === 'sold' ? t('sold', {}, l) : formatPrice(x)}</span>
|
|
301
|
+
{facts(x) && <span class="rs-card-facts">{facts(x)}</span>}
|
|
302
|
+
</a>
|
|
303
|
+
)}
|
|
304
|
+
</li>
|
|
305
|
+
))}
|
|
306
|
+
</ul>
|
|
307
|
+
</div>
|
|
308
|
+
<ListingsPager result={result} href={href} locale={locale} />
|
|
309
|
+
</Fragment>
|
|
310
|
+
)}
|
|
311
|
+
</div>
|
|
312
|
+
|
|
313
|
+
{!nothingAtAll && total > 0 && (
|
|
314
|
+
<a class="rs-pill" data-rs-pill data-rs-nav data-rs-swap="pill" href={href({ view: isMap ? undefined : 'map' })}>
|
|
315
|
+
{isMap ? (
|
|
316
|
+
<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75"><rect x="4" y="4" width="7" height="7" /><rect x="13" y="4" width="7" height="7" /><rect x="4" y="13" width="7" height="7" /><rect x="13" y="13" width="7" height="7" /></svg>
|
|
317
|
+
) : (
|
|
318
|
+
<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linejoin="round"><path d="M9 4 3 6v14l6-2 6 2 6-2V4l-6 2-6-2zM9 4v14M15 6v14" /></svg>
|
|
319
|
+
)}
|
|
320
|
+
{isMap ? t('viewList', {}, l) : t('viewMap', {}, l)}
|
|
321
|
+
</a>
|
|
322
|
+
)}
|
|
323
|
+
</div>
|
|
324
|
+
|
|
325
|
+
<script>
|
|
326
|
+
import '@realadvisor/sites-kit-core/client/listings-search';
|
|
327
|
+
</script>
|
|
328
|
+
|
|
329
|
+
<style>
|
|
330
|
+
.rs {
|
|
331
|
+
--rs-ink: var(--text, #1c1b19);
|
|
332
|
+
--rs-bg: var(--paper, var(--bg, #fff));
|
|
333
|
+
--rs-line: var(--line, #e2dfda);
|
|
334
|
+
--rs-muted: var(--muted, #6b6b6b);
|
|
335
|
+
--rs-accent: var(--accent, #134266);
|
|
336
|
+
--rs-gap-x: var(--rs-gap, 32px);
|
|
337
|
+
--rs-top: calc(var(--header-h, 0px) + 16px);
|
|
338
|
+
--rs-on: var(--rs-active, var(--rs-ink));
|
|
339
|
+
--rs-on-ink: var(--rs-on-active, var(--rs-bg));
|
|
340
|
+
position: relative;
|
|
341
|
+
}
|
|
342
|
+
.rs[aria-busy='true'] .rs-region { opacity: .55; transition: opacity .2s .1s; }
|
|
343
|
+
|
|
344
|
+
/* Filters: one inline row at >= 960px, a bottom sheet (popover) on phones. */
|
|
345
|
+
.rs-top { display: flex; gap: 12px; align-items: end; }
|
|
346
|
+
.rs-filters-btn {
|
|
347
|
+
display: inline-flex; align-items: center; gap: 8px; min-height: var(--control-h, 48px); padding: 0 18px;
|
|
348
|
+
border: 1px solid var(--rs-line); border-radius: var(--control-radius, 8px); background: var(--rs-bg); color: var(--rs-ink); font: inherit; font-weight: 600; cursor: pointer;
|
|
349
|
+
}
|
|
350
|
+
.rs-badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--rs-accent); color: #fff; font-size: 12px; }
|
|
351
|
+
.rs-badge[hidden] { display: none; }
|
|
352
|
+
.rs-sheet { color: var(--rs-ink); }
|
|
353
|
+
.rs-sheet-head { display: flex; justify-content: space-between; align-items: center; }
|
|
354
|
+
.rs-sheet-title { margin: 0; font-weight: 600; font-size: 1.125rem; }
|
|
355
|
+
.rs-sheet-close { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: inherit; cursor: pointer; }
|
|
356
|
+
.rs-sheet:popover-open {
|
|
357
|
+
position: fixed; inset: auto 0 0 0; width: 100%; max-width: none; max-height: 88svh; margin: 0; overflow: auto; box-sizing: border-box;
|
|
358
|
+
display: grid; gap: 20px; padding: 8px 20px max(20px, env(safe-area-inset-bottom)); border: 0; border-radius: var(--rs-sheet-radius, 16px) var(--rs-sheet-radius, 16px) 0 0;
|
|
359
|
+
background: var(--rs-bg); box-shadow: 0 -8px 32px rgb(0 0 0 / .18);
|
|
360
|
+
}
|
|
361
|
+
.rs-sheet::backdrop { background: rgb(0 0 0 / .4); }
|
|
362
|
+
.rs-sheet :global(.rs-apply) { width: 100%; position: sticky; bottom: 0; }
|
|
363
|
+
@supports not selector(:popover-open) {
|
|
364
|
+
.rs-filters-btn { display: none; }
|
|
365
|
+
.rs-sheet { display: grid; gap: 16px; }
|
|
366
|
+
.rs-sheet-head { display: none; }
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.rs-offer { border: 0; margin: 0; padding: 0; min-width: 0; }
|
|
370
|
+
.rs-offer legend { padding: 0; margin-bottom: 6px; }
|
|
371
|
+
.rs-seg { display: flex; border: 1px solid var(--rs-line); border-radius: var(--control-radius, 8px); overflow: hidden; height: var(--control-h, 48px); background: var(--rs-bg); }
|
|
372
|
+
.rs-seg label { position: relative; flex: 1; display: flex; }
|
|
373
|
+
.rs-seg label + label { border-left: 1px solid var(--rs-line); }
|
|
374
|
+
.rs-seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
|
|
375
|
+
.rs-seg span { flex: 1; display: grid; place-items: center; padding: 0 16px; white-space: nowrap; font-size: .9375rem; transition: background .15s, color .15s; }
|
|
376
|
+
.rs-seg input:checked + span { background: var(--rs-on); color: var(--rs-on-ink); }
|
|
377
|
+
.rs-seg input:focus-visible + span { outline: 2px solid var(--rs-accent); outline-offset: -4px; }
|
|
378
|
+
|
|
379
|
+
@media (min-width: 960px) {
|
|
380
|
+
.rs-filters-btn, .rs-sheet-head { display: none; }
|
|
381
|
+
.rs-top { display: block; }
|
|
382
|
+
/* The popover, shown inline: author styles beat the UA's [popover] display:none. */
|
|
383
|
+
.rs-sheet, .rs-sheet:popover-open {
|
|
384
|
+
position: static; inset: auto; width: auto; max-height: none; margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none; overflow: visible; background: none;
|
|
385
|
+
display: flex; flex-wrap: wrap; gap: 12px; align-items: end;
|
|
386
|
+
}
|
|
387
|
+
.rs-sheet > :global(.field) { flex: 1 1 160px; min-width: 0; }
|
|
388
|
+
.rs-sheet > .rs-offer { flex: 0 0 auto; }
|
|
389
|
+
.rs-sheet > :global(.rs-city) { flex: 1.4 1 200px; }
|
|
390
|
+
.rs-sheet :global(.rs-apply) { width: auto; position: static; }
|
|
391
|
+
.rs.is-js .rs-sheet :global(.rs-apply) { display: none; }
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
.rs-bar { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; margin: 24px 0 16px; }
|
|
395
|
+
.rs-count { margin: 0; font-weight: 600; outline: none; }
|
|
396
|
+
.rs-tools { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; }
|
|
397
|
+
.rs-tools :global(.rs-sort) { width: auto; }
|
|
398
|
+
.rs-status, .rs-views { display: flex; border: 1px solid var(--rs-line); border-radius: var(--control-radius, 8px); overflow: hidden; }
|
|
399
|
+
.rs-status a, .rs-views a {
|
|
400
|
+
display: inline-flex; gap: 8px; align-items: center; min-height: calc(var(--control-h, 48px) - 2px); padding: 0 16px;
|
|
401
|
+
color: var(--rs-ink); text-decoration: none; font-size: .9375rem; white-space: nowrap;
|
|
402
|
+
}
|
|
403
|
+
.rs-status a + a, .rs-views a + a { border-left: 1px solid var(--rs-line); }
|
|
404
|
+
.rs-status a[aria-current], .rs-views a[aria-current] { background: var(--rs-on); color: var(--rs-on-ink); }
|
|
405
|
+
.rs-n { opacity: .7; font-variant-numeric: tabular-nums; }
|
|
406
|
+
|
|
407
|
+
.rs-chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 24px; }
|
|
408
|
+
.rs-chips[hidden] { display: none; }
|
|
409
|
+
.rs-chip {
|
|
410
|
+
display: inline-flex; gap: 6px; align-items: center; min-height: 36px; padding: 0 10px 0 14px; border-radius: 999px;
|
|
411
|
+
background: color-mix(in srgb, var(--rs-accent) 10%, var(--rs-bg)); color: var(--rs-ink); text-decoration: none; font-size: .875rem;
|
|
412
|
+
}
|
|
413
|
+
.rs-chip:hover { background: color-mix(in srgb, var(--rs-accent) 18%, var(--rs-bg)); }
|
|
414
|
+
.rs-reset { color: var(--rs-accent); font-size: .875rem; padding: 8px 4px; }
|
|
415
|
+
|
|
416
|
+
/* Results: list view grid; map view split (cards | sticky map) at >= 960px. */
|
|
417
|
+
.rs-grid { --rs-cols: 1; list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(var(--rs-cols), minmax(0, 1fr)); gap: 40px var(--rs-gap-x); }
|
|
418
|
+
.rs-grid > li { min-width: 0; }
|
|
419
|
+
@media (min-width: 640px) { .rs-grid { --rs-cols: 2; } }
|
|
420
|
+
@media (min-width: 1024px) { .rs-grid { --rs-cols: var(--rs-columns, 3); } }
|
|
421
|
+
/* Map view renders up to 300 cards: skip the off-screen ones' layout. */
|
|
422
|
+
.rs-list > li { content-visibility: auto; contain-intrinsic-size: auto var(--rs-card-h, 420px); }
|
|
423
|
+
.rs-grid > :global(li.is-map-hover), .rs-grid > :global(li.is-selected) { outline: 2px solid var(--rs-accent); outline-offset: 6px; border-radius: 2px; }
|
|
424
|
+
|
|
425
|
+
.rs-map { --map-h: min(70svh, 560px); margin-bottom: 24px; }
|
|
426
|
+
.rs-split { display: flex; flex-direction: column; }
|
|
427
|
+
.rs-split .rs-map { order: -1; }
|
|
428
|
+
@media (min-width: 960px) {
|
|
429
|
+
.rs-split { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: var(--rs-gap-x); align-items: start; }
|
|
430
|
+
.rs-split .rs-map { order: 2; position: sticky; top: var(--rs-top); margin: 0; --map-h: calc(100svh - var(--rs-top) - 16px); }
|
|
431
|
+
.rs-list { --rs-cols: 1; }
|
|
432
|
+
}
|
|
433
|
+
@media (min-width: 1280px) { .rs-list { --rs-cols: 2; gap: 32px 20px; } }
|
|
434
|
+
/* Map view: "search as I move the map" over the map; with it off, a "search this area" button. */
|
|
435
|
+
.rs-map { position: relative; }
|
|
436
|
+
.rs-follow { position: absolute; z-index: 5; top: 12px; left: 50%; translate: -50% 0; max-width: calc(100% - 136px); display: flex; justify-content: center; pointer-events: none; }
|
|
437
|
+
.rs-follow > * { pointer-events: auto; }
|
|
438
|
+
.rs:not(.is-js) .rs-follow { display: none; }
|
|
439
|
+
/* An open popup owns the top of the map (its close button sits there on a phone). */
|
|
440
|
+
.rs-map:has(.ra-map-popup.is-open) .rs-follow { visibility: hidden; }
|
|
441
|
+
.rs-follow-toggle, .rs-search-area {
|
|
442
|
+
display: inline-flex; gap: 8px; align-items: center; min-height: 40px; padding: 0 14px; border: 0; border-radius: var(--rs-pill-radius, 999px);
|
|
443
|
+
background: var(--rs-bg); color: var(--rs-ink); box-shadow: 0 2px 8px rgb(0 0 0 / .2); font: inherit; font-size: .875rem; white-space: nowrap; cursor: pointer;
|
|
444
|
+
}
|
|
445
|
+
.rs-follow-toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--rs-on); }
|
|
446
|
+
.rs-follow-toggle span { overflow: hidden; text-overflow: ellipsis; }
|
|
447
|
+
.rs-search-area { background: var(--rs-on); color: var(--rs-on-ink); font-weight: 600; }
|
|
448
|
+
.rs-follow:has(.rs-search-area:not([hidden])) .rs-follow-toggle { display: none; }
|
|
449
|
+
.rs-empty-area { padding: 24px 0; }
|
|
450
|
+
.rs-note { margin: 0 0 16px; color: var(--rs-muted); font-size: .9375rem; }
|
|
451
|
+
|
|
452
|
+
/* Plain card: only when the page passes none. */
|
|
453
|
+
.rs-card { display: grid; gap: 4px; color: inherit; text-decoration: none; }
|
|
454
|
+
.rs-card :global(img), .rs-card-nophoto { width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; margin-bottom: 8px; border-radius: var(--radius-img, 0); }
|
|
455
|
+
.rs-card-nophoto { display: grid; place-items: center; background: var(--surface, #f2f0ec); color: var(--rs-muted); }
|
|
456
|
+
.rs-card-type { font-size: .8125rem; letter-spacing: .04em; text-transform: uppercase; color: var(--rs-muted); }
|
|
457
|
+
.rs-card-title { font-weight: 600; }
|
|
458
|
+
.rs-card-price { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
459
|
+
.rs-card-facts { color: var(--rs-muted); font-size: .9375rem; }
|
|
460
|
+
.rs-card:focus-visible { outline: 2px solid var(--rs-accent); outline-offset: 3px; }
|
|
461
|
+
|
|
462
|
+
.rs-empty { display: grid; gap: 12px; justify-items: start; max-width: 60ch; padding: 48px 0; }
|
|
463
|
+
.rs-empty-title { margin: 0; font-size: var(--rs-heading-size, clamp(1.25rem, 1rem + 1vw, 1.75rem)); font-weight: var(--rs-heading-weight, 600); line-height: 1.2; }
|
|
464
|
+
.rs-empty-text { margin: 0; color: var(--rs-muted); }
|
|
465
|
+
.rs-empty-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0 0; }
|
|
466
|
+
.rs-relax { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; }
|
|
467
|
+
.rs-relax a { display: inline-flex; align-items: center; min-height: 44px; color: var(--rs-accent); }
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
/* Phone: List / Map always in reach. */
|
|
471
|
+
.rs-pill {
|
|
472
|
+
position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 20; translate: -50% 0;
|
|
473
|
+
display: inline-flex; gap: 8px; align-items: center; min-height: 48px; padding: 0 22px; border-radius: var(--rs-pill-radius, 999px);
|
|
474
|
+
background: var(--rs-on); color: var(--rs-on-ink); font-weight: 600; text-decoration: none; box-shadow: 0 6px 20px rgb(0 0 0 / .25);
|
|
475
|
+
}
|
|
476
|
+
@media (min-width: 960px) { .rs-pill { display: none; } }
|
|
477
|
+
/* Phone: [Filters (n)] [Sort] on one row, then the status switch and the count. */
|
|
478
|
+
@media (max-width: 959px) {
|
|
479
|
+
.rs-form { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: 'f s' 'st st' 'c c'; gap: 12px; margin-bottom: 16px; }
|
|
480
|
+
.rs-top, .rs-bar, .rs-tools { display: contents; }
|
|
481
|
+
.rs-filters-btn { grid-area: f; }
|
|
482
|
+
.rs-tools :global(.rs-sort) { grid-area: s; }
|
|
483
|
+
.rs-status { grid-area: st; }
|
|
484
|
+
.rs-status a { flex: 1; justify-content: center; }
|
|
485
|
+
.rs-count { grid-area: c; }
|
|
486
|
+
.rs-views { display: none; }
|
|
487
|
+
.rs:has(.rs-pill) .rs-region { padding-bottom: 72px; }
|
|
488
|
+
}
|
|
489
|
+
@media (prefers-reduced-motion: reduce) { .rs * { transition: none !important; } }
|
|
490
|
+
</style>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* THE way to show a listing, agent, agency or development photo.
|
|
4
|
+
* Always served by img.realadvisor.ch (imgproxy) at the size you need, with
|
|
5
|
+
* a srcset (480/768/1200/1920), sizes, width and height. Lazy by default;
|
|
6
|
+
* `priority` for the one LCP image of the page (hero, first gallery photo):
|
|
7
|
+
* AVIF first, quality 70, at most 1600w, sizes capped at 1440px.
|
|
8
|
+
*
|
|
9
|
+
* <RaImage src={listing.photos[0]} alt="…" width={800} height={600}
|
|
10
|
+
* sizes="(min-width: 1024px) 33vw, 100vw" />
|
|
11
|
+
* <RaImage src={hero} alt="…" width={1600} height={900} priority
|
|
12
|
+
* mobile={{ width: 800, height: 1000 }} />
|
|
13
|
+
*
|
|
14
|
+
* `mobile`: a different crop under 768px (art direction, `<picture>`), e.g.
|
|
15
|
+
* 4:5 for a hero. Required whenever the mobile box is portrait and the photo
|
|
16
|
+
* landscape; `mobileSizes` defaults to 100vw.
|
|
17
|
+
*
|
|
18
|
+
* `width`/`height` are the box ratio and intrinsic size attributes; CSS sets
|
|
19
|
+
* the rendered size. The crop follows width/height (fit: fill). Pass
|
|
20
|
+
* `fit="fit"` to keep the photo's own ratio (logos, plans).
|
|
21
|
+
*/
|
|
22
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
23
|
+
import type { Photo } from '../lib/ra';
|
|
24
|
+
import { img, srcset } from '@realadvisor/sites-kit-core/image';
|
|
25
|
+
|
|
26
|
+
type Props = Omit<HTMLAttributes<'img'>, 'src' | 'srcset' | 'width' | 'height' | 'loading' | 'alt'> & {
|
|
27
|
+
src: Photo | string | null | undefined;
|
|
28
|
+
alt: string;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
/** Browser layout width per breakpoint. Default 100vw. */
|
|
32
|
+
sizes?: string;
|
|
33
|
+
/** LCP image: eager, fetchpriority high, and a preload hint. One per page. */
|
|
34
|
+
priority?: boolean;
|
|
35
|
+
fit?: 'fill' | 'fit';
|
|
36
|
+
widths?: number[];
|
|
37
|
+
quality?: number;
|
|
38
|
+
/** Crop for screens under 768px: box ratio width/height and sizes. */
|
|
39
|
+
mobile?: { width: number; height: number; sizes?: string };
|
|
40
|
+
};
|
|
41
|
+
const { src, alt, width, height, priority = false, fit = 'fill', mobile, sizes: sizesProp, widths: widthsProp, quality: qualityProp, ...rest } = Astro.props;
|
|
42
|
+
// LCP image: at most 1600w on desktop, quality 70, AVIF first (WebP fallback).
|
|
43
|
+
const widths = widthsProp ?? (priority ? [640, 960, 1280, 1600] : [480, 768, 1200, 1920]);
|
|
44
|
+
const quality = qualityProp ?? (priority ? 70 : undefined);
|
|
45
|
+
const sizes = sizesProp ?? (priority ? '(min-width: 1440px) 1440px, 100vw' : '100vw');
|
|
46
|
+
const url = typeof src === 'string' ? src : src?.url;
|
|
47
|
+
const ratio = fit === 'fill' ? width / height : undefined;
|
|
48
|
+
const set = url ? srcset(url, widths, ratio, { quality }) : '';
|
|
49
|
+
const avifSet = url && priority && set ? srcset(url, widths, ratio, { quality, format: 'avif' }) : '';
|
|
50
|
+
const fallbackW = Math.min(1200, Math.max(...widths.filter((w) => w <= 1200), widths[0] ?? 768));
|
|
51
|
+
const fallback = url ? img(url, { w: fallbackW, h: ratio ? Math.round(fallbackW / ratio) : 0, fit, quality }) : '';
|
|
52
|
+
const MOBILE = '(max-width: 767px)';
|
|
53
|
+
const DESKTOP = '(min-width: 768px)';
|
|
54
|
+
const mobileW = [480, 600, 800, 1200];
|
|
55
|
+
const mRatio = mobile ? mobile.width / mobile.height : 0;
|
|
56
|
+
const mobileSet = url && mobile ? srcset(url, mobileW, mRatio, { quality }) : '';
|
|
57
|
+
const mobileAvif = mobileSet && priority ? srcset(url, mobileW, mRatio, { quality, format: 'avif' }) : '';
|
|
58
|
+
const mobileSizes = mobile?.sizes ?? '100vw';
|
|
59
|
+
const imgTag = { width, height, alt, loading: priority ? 'eager' : 'lazy', fetchpriority: priority ? 'high' : undefined, decoding: 'async' } as const;
|
|
60
|
+
const usePicture = !!(mobileSet || avifSet);
|
|
61
|
+
---
|
|
62
|
+
{url && !usePicture && (
|
|
63
|
+
<>
|
|
64
|
+
{priority && set && <link rel="preload" as="image" imagesrcset={set} imagesizes={sizes} fetchpriority="high" />}
|
|
65
|
+
<img src={fallback} srcset={set || undefined} sizes={set ? sizes : undefined} {...imgTag} {...rest} />
|
|
66
|
+
</>
|
|
67
|
+
)}
|
|
68
|
+
{url && usePicture && (
|
|
69
|
+
<>
|
|
70
|
+
{priority && mobileSet && <link rel="preload" as="image" type="image/avif" media={MOBILE} imagesrcset={mobileAvif} imagesizes={mobileSizes} fetchpriority="high" />}
|
|
71
|
+
{priority && <link rel="preload" as="image" type="image/avif" media={mobileSet ? DESKTOP : undefined} imagesrcset={avifSet} imagesizes={sizes} fetchpriority="high" />}
|
|
72
|
+
<picture>
|
|
73
|
+
{mobileAvif && <source media={MOBILE} type="image/avif" srcset={mobileAvif} sizes={mobileSizes} width={mobile!.width} height={mobile!.height} />}
|
|
74
|
+
{mobileSet && <source media={MOBILE} srcset={mobileSet} sizes={mobileSizes} width={mobile!.width} height={mobile!.height} />}
|
|
75
|
+
{avifSet && <source type="image/avif" srcset={avifSet} sizes={sizes} />}
|
|
76
|
+
<img src={fallback} srcset={set || undefined} sizes={sizes} {...imgTag} {...rest} />
|
|
77
|
+
</picture>
|
|
78
|
+
</>
|
|
79
|
+
)}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Button or link styled as a button, same height as the form controls.
|
|
4
|
+
* <Button type="submit">Suchen</Button>
|
|
5
|
+
* <Button href="/listings" variant="secondary">Zurücksetzen</Button>
|
|
6
|
+
* <Button href="/estimation" variant="on-photo">Faire estimer mon bien</Button> (on a hero photo)
|
|
7
|
+
*/
|
|
8
|
+
import '@realadvisor/sites-kit-core/styles/form.css';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
href?: string;
|
|
12
|
+
type?: 'submit' | 'button' | 'reset';
|
|
13
|
+
/** `on-photo`: white text and border on a translucent dark fill, for buttons over a photo. */
|
|
14
|
+
variant?: 'primary' | 'secondary' | 'on-photo';
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
class?: string;
|
|
17
|
+
/** `data-*` hooks pass through (e.g. `data-rs-nav` in ListingsSearch). */
|
|
18
|
+
[data: `data-${string}`]: string | boolean | undefined;
|
|
19
|
+
}
|
|
20
|
+
const { href, type = 'submit', variant = 'primary', disabled, class: cls, ...data } = Astro.props;
|
|
21
|
+
const classes = ['btn', { 'btn--secondary': variant === 'secondary', 'btn--on-photo': variant === 'on-photo' }, cls];
|
|
22
|
+
---
|
|
23
|
+
{href
|
|
24
|
+
? <a href={href} class:list={classes} {...data}><slot /></a>
|
|
25
|
+
: <button type={type} class:list={classes} disabled={disabled} {...data}><slot /></button>}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Searchable select for long lists (cities/Ort, property types with many values).
|
|
4
|
+
* Renders a styled native <select> (works without JS, submits with the form), then a
|
|
5
|
+
* ~2 KB script upgrades it to an ARIA 1.2 combobox: type to filter (accent- and
|
|
6
|
+
* case-insensitive), Up/Down, Enter, Escape, click. No dependency.
|
|
7
|
+
* <Combobox label="Ort" name="city" value={city} placeholder="Alle Orte"
|
|
8
|
+
* options={cities.map((c) => ({ value: c, label: c }))} />
|
|
9
|
+
*/
|
|
10
|
+
import '@realadvisor/sites-kit-core/styles/form.css';
|
|
11
|
+
import type { Option } from './Select.astro';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
label: string;
|
|
15
|
+
name: string;
|
|
16
|
+
options: Option[];
|
|
17
|
+
value?: string | null;
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
hideLabel?: boolean;
|
|
20
|
+
noResults?: string;
|
|
21
|
+
id?: string;
|
|
22
|
+
class?: string;
|
|
23
|
+
}
|
|
24
|
+
const { label, name, options, value, placeholder = '', hideLabel, noResults = '–', id, class: cls } = Astro.props;
|
|
25
|
+
const fieldId = id ?? `f-${name}`;
|
|
26
|
+
---
|
|
27
|
+
<div class:list={['field', cls]}>
|
|
28
|
+
<label for={fieldId} class:list={['field-label', { 'sr-only': hideLabel }]}>{label}</label>
|
|
29
|
+
<div class="combobox" data-combobox data-no-results={noResults}>
|
|
30
|
+
<span class="select">
|
|
31
|
+
<select id={fieldId} name={name} class="control">
|
|
32
|
+
<option value="" selected={!value}>{placeholder}</option>
|
|
33
|
+
{options.map((o) => <option value={o.value} selected={o.value === value}>{o.label}</option>)}
|
|
34
|
+
</select>
|
|
35
|
+
</span>
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<script>
|
|
40
|
+
import '@realadvisor/sites-kit-core/client/combobox';
|
|
41
|
+
</script>
|