@stapel/search-react 0.4.0 → 0.8.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/CHANGELOG.md +191 -0
- package/README.md +1 -1
- package/dist/default/DegradationNotice.d.ts +7 -0
- package/dist/default/DegradationNotice.d.ts.map +1 -1
- package/dist/default/DegradationNotice.js +17 -6
- package/dist/default/DegradationNotice.js.map +1 -1
- package/dist/default/FacetGroupControl.d.ts +40 -0
- package/dist/default/FacetGroupControl.d.ts.map +1 -0
- package/dist/default/FacetGroupControl.js +176 -0
- package/dist/default/FacetGroupControl.js.map +1 -0
- package/dist/default/FacetPanelPane.d.ts +54 -3
- package/dist/default/FacetPanelPane.d.ts.map +1 -1
- package/dist/default/FacetPanelPane.js +116 -22
- package/dist/default/FacetPanelPane.js.map +1 -1
- package/dist/default/FilterChips.d.ts +28 -0
- package/dist/default/FilterChips.d.ts.map +1 -0
- package/dist/default/FilterChips.js +204 -0
- package/dist/default/FilterChips.js.map +1 -0
- package/dist/default/LanguageSelect.d.ts +9 -0
- package/dist/default/LanguageSelect.d.ts.map +1 -0
- package/dist/default/LanguageSelect.js +72 -0
- package/dist/default/LanguageSelect.js.map +1 -0
- package/dist/default/PageSizeSelect.d.ts +29 -0
- package/dist/default/PageSizeSelect.d.ts.map +1 -0
- package/dist/default/PageSizeSelect.js +25 -0
- package/dist/default/PageSizeSelect.js.map +1 -0
- package/dist/default/RangeFilterRow.d.ts +12 -0
- package/dist/default/RangeFilterRow.d.ts.map +1 -0
- package/dist/default/RangeFilterRow.js +75 -0
- package/dist/default/RangeFilterRow.js.map +1 -0
- package/dist/default/RankingDisclosurePane.d.ts +5 -0
- package/dist/default/RankingDisclosurePane.d.ts.map +1 -1
- package/dist/default/RankingDisclosurePane.js +15 -15
- package/dist/default/RankingDisclosurePane.js.map +1 -1
- package/dist/default/SearchBox.d.ts +13 -0
- package/dist/default/SearchBox.d.ts.map +1 -0
- package/dist/default/SearchBox.js +67 -0
- package/dist/default/SearchBox.js.map +1 -0
- package/dist/default/SearchPage.d.ts +94 -16
- package/dist/default/SearchPage.d.ts.map +1 -1
- package/dist/default/SearchPage.js +191 -8
- package/dist/default/SearchPage.js.map +1 -1
- package/dist/default/SearchResultCard.d.ts +19 -18
- package/dist/default/SearchResultCard.d.ts.map +1 -1
- package/dist/default/SearchResultCard.js +178 -5
- package/dist/default/SearchResultCard.js.map +1 -1
- package/dist/default/SearchResultsPane.d.ts +61 -3
- package/dist/default/SearchResultsPane.d.ts.map +1 -1
- package/dist/default/SearchResultsPane.js +51 -21
- package/dist/default/SearchResultsPane.js.map +1 -1
- package/dist/default/SortSelect.d.ts +10 -2
- package/dist/default/SortSelect.d.ts.map +1 -1
- package/dist/default/SortSelect.js +27 -24
- package/dist/default/SortSelect.js.map +1 -1
- package/dist/default/UrlIssueNotice.d.ts.map +1 -1
- package/dist/default/UrlIssueNotice.js +19 -1
- package/dist/default/UrlIssueNotice.js.map +1 -1
- package/dist/default/ViewSwitch.d.ts +66 -0
- package/dist/default/ViewSwitch.d.ts.map +1 -0
- package/dist/default/ViewSwitch.js +49 -0
- package/dist/default/ViewSwitch.js.map +1 -0
- package/dist/default/index.d.ts +38 -15
- package/dist/default/index.d.ts.map +1 -1
- package/dist/default/index.js +29 -12
- package/dist/default/index.js.map +1 -1
- package/dist/default/sortLabels.d.ts +5 -0
- package/dist/default/sortLabels.d.ts.map +1 -0
- package/dist/default/sortLabels.js +32 -0
- package/dist/default/sortLabels.js.map +1 -0
- package/dist/headless/FacetPanel.d.ts +17 -0
- package/dist/headless/FacetPanel.d.ts.map +1 -1
- package/dist/headless/FacetPanel.js +23 -2
- package/dist/headless/FacetPanel.js.map +1 -1
- package/dist/headless/useAppliedCount.d.ts +8 -0
- package/dist/headless/useAppliedCount.d.ts.map +1 -0
- package/dist/headless/useAppliedCount.js +30 -0
- package/dist/headless/useAppliedCount.js.map +1 -0
- package/dist/headless/useScorerNames.d.ts +4 -0
- package/dist/headless/useScorerNames.d.ts.map +1 -0
- package/dist/headless/useScorerNames.js +34 -0
- package/dist/headless/useScorerNames.js.map +1 -0
- package/dist/headless/useSearchBox.d.ts +44 -0
- package/dist/headless/useSearchBox.d.ts.map +1 -0
- package/dist/headless/useSearchBox.js +116 -0
- package/dist/headless/useSearchBox.js.map +1 -0
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +38 -4
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/keys.d.ts +55 -0
- package/dist/i18n/keys.d.ts.map +1 -1
- package/dist/i18n/keys.js +101 -4
- package/dist/i18n/keys.js.map +1 -1
- package/dist/i18n/ru.d.ts.map +1 -1
- package/dist/i18n/ru.js +42 -4
- package/dist/i18n/ru.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/model/queries.d.ts +26 -2
- package/dist/model/queries.d.ts.map +1 -1
- package/dist/model/queries.js +38 -1
- package/dist/model/queries.js.map +1 -1
- package/dist/state/limits.d.ts +44 -0
- package/dist/state/limits.d.ts.map +1 -0
- package/dist/state/limits.js +44 -0
- package/dist/state/limits.js.map +1 -0
- package/dist/state/ranges.d.ts +52 -0
- package/dist/state/ranges.d.ts.map +1 -0
- package/dist/state/ranges.js +108 -0
- package/dist/state/ranges.js.map +1 -0
- package/llms.txt +16 -4
- package/manifest.json +268 -22
- package/nav-manifest.json +1 -1
- package/package.json +15 -10
- package/src/analytics/generated/events.json +1 -1
- package/src/default/DegradationNotice.tsx +34 -12
- package/src/default/FacetGroupControl.tsx +312 -0
- package/src/default/FacetPanelPane.tsx +320 -87
- package/src/default/FilterChips.tsx +415 -0
- package/src/default/LanguageSelect.tsx +93 -0
- package/src/default/PageSizeSelect.tsx +80 -0
- package/src/default/RangeFilterRow.tsx +148 -0
- package/src/default/RankingDisclosurePane.tsx +67 -35
- package/src/default/SearchBox.tsx +130 -0
- package/src/default/SearchPage.tsx +454 -44
- package/src/default/SearchResultCard.tsx +231 -24
- package/src/default/SearchResultsPane.tsx +158 -71
- package/src/default/SortSelect.tsx +50 -37
- package/src/default/UrlIssueNotice.tsx +21 -3
- package/src/default/ViewSwitch.tsx +147 -0
- package/src/default/index.ts +55 -15
- package/src/default/sortLabels.ts +34 -0
- package/src/headless/FacetPanel.tsx +30 -2
- package/src/headless/useAppliedCount.ts +41 -0
- package/src/headless/useScorerNames.ts +36 -0
- package/src/headless/useSearchBox.ts +189 -0
- package/src/i18n/es.ts +46 -4
- package/src/i18n/keys.ts +114 -4
- package/src/i18n/ru.ts +50 -4
- package/src/index.ts +22 -2
- package/src/model/queries.ts +51 -1
- package/src/state/limits.ts +50 -0
- package/src/state/ranges.ts +144 -0
- package/dist/default/ErrorAlert.d.ts +0 -9
- package/dist/default/ErrorAlert.d.ts.map +0 -1
- package/dist/default/ErrorAlert.js +0 -27
- package/dist/default/ErrorAlert.js.map +0 -1
- package/dist/default/theme.d.ts +0 -24
- package/dist/default/theme.d.ts.map +0 -1
- package/dist/default/theme.js +0 -39
- package/dist/default/theme.js.map +0 -1
- package/src/default/ErrorAlert.tsx +0 -46
- package/src/default/theme.tsx +0 -66
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<FilterChips>` — the phone's filter row: one horizontally scrolling line of
|
|
3
|
+
* chips, each of which opens its OWN picker.
|
|
4
|
+
*
|
|
5
|
+
* ## What it replaces, and why the replacement is not cosmetic
|
|
6
|
+
*
|
|
7
|
+
* The phone filter path was a single full-width "Filters (3)" button that
|
|
8
|
+
* opened the whole panel. Everything about a search — the category, the price,
|
|
9
|
+
* the brand, where — was behind one tap onto a sheet you then had to scroll,
|
|
10
|
+
* and NOTHING about what was already applied was visible on the results page
|
|
11
|
+
* itself except a number in brackets. The chips row states the filters ON the
|
|
12
|
+
* page: the ones you have set read as set, the ones you have not are one tap
|
|
13
|
+
* from their own small picker, and the whole panel is still there behind the
|
|
14
|
+
* leading chip for the person who wants all of it at once.
|
|
15
|
+
*
|
|
16
|
+
* ## The row scrolls; the PAGE does not
|
|
17
|
+
*
|
|
18
|
+
* A row of chips wider than a 390px phone is the point — it is how the row
|
|
19
|
+
* holds eight filters. What must not happen is the page's own body growing a
|
|
20
|
+
* horizontal scrollbar, which is what a `flex-wrap: nowrap` row without an
|
|
21
|
+
* `overflow-x` owner does: the chips push the document wider, every other
|
|
22
|
+
* element on the page slides, and the visitor is left rubber-banding the whole
|
|
23
|
+
* screen sideways to read a price. So the row owns its overflow
|
|
24
|
+
* (`overflow-x: auto`), contains its overscroll so a flick past the last chip
|
|
25
|
+
* does not start scrolling the page behind it, and hides the scrollbar itself
|
|
26
|
+
* (a 15px grey trough under a 32px chip is chrome nobody asked for) — through
|
|
27
|
+
* a hoisted stylesheet, because `::-webkit-scrollbar` and `scrollbar-width`
|
|
28
|
+
* cannot be written as inline style.
|
|
29
|
+
*
|
|
30
|
+
* Hiding a scrollbar is only safe because nothing here is reachable ONLY by
|
|
31
|
+
* dragging it: every chip is a real `<button>`, so Tab walks the row and the
|
|
32
|
+
* browser scrolls the focused chip into view on its own.
|
|
33
|
+
*
|
|
34
|
+
* ## Every picker is a `SkinDialog`
|
|
35
|
+
*
|
|
36
|
+
* Which means every picker is a BOTTOM SHEET on a phone and a modal above it
|
|
37
|
+
* (owner ruling 2026-08-24, enforced by `stapel/no-bare-dialog`). The chips
|
|
38
|
+
* row is a phone surface, so in practice it is always the sheet — but the
|
|
39
|
+
* component does not decide that, the substrate does, and a tablet rendering
|
|
40
|
+
* the row gets the tablet answer without this file knowing.
|
|
41
|
+
*
|
|
42
|
+
* ## The library is not inventing a classified's filters
|
|
43
|
+
*
|
|
44
|
+
* A chip exists for each facet group the SERVER returned, each numeric range
|
|
45
|
+
* the CATEGORY SCHEMA declares, and the location — plus the leading
|
|
46
|
+
* "all filters" chip. Nothing here knows what a "brand" or a "mileage" is;
|
|
47
|
+
* a deployment with three facets gets three chips and a deployment with none
|
|
48
|
+
* gets the leading chip alone.
|
|
49
|
+
*/
|
|
50
|
+
import { useState } from "react";
|
|
51
|
+
import type { CSSProperties, ReactElement, ReactNode } from "react";
|
|
52
|
+
import { Button, Flex, Typography } from "antd";
|
|
53
|
+
import { SkinDialog, useDialogSurface } from "@stapel/tokens-antd/skin";
|
|
54
|
+
import { SlotPlaceholder, useT, useTPlural } from "@stapel/core";
|
|
55
|
+
import { radii, spacing } from "@stapel/tokens";
|
|
56
|
+
import type { FeatureDef } from "@stapel/attributes-react";
|
|
57
|
+
import { useFacetPanel } from "../headless/FacetPanel.js";
|
|
58
|
+
import { useAppliedCount } from "../headless/useAppliedCount.js";
|
|
59
|
+
import { useSearchState } from "../headless/SearchStateProvider.js";
|
|
60
|
+
import { buildRangeGroups } from "../state/ranges.js";
|
|
61
|
+
import type { FacetGroup } from "../state/facets.js";
|
|
62
|
+
import { SEARCH_I18N_KEYS } from "../i18n/keys.js";
|
|
63
|
+
import { FacetGroupControl } from "./FacetGroupControl.js";
|
|
64
|
+
import { RangeFilterRow } from "./RangeFilterRow.js";
|
|
65
|
+
import type { GeoFilterSlotProps } from "./FacetPanelPane.js";
|
|
66
|
+
|
|
67
|
+
/** The class the scroller carries, for {@link chipRowCss}. */
|
|
68
|
+
export const CHIP_ROW_CLASS = "stapel-filter-chips";
|
|
69
|
+
|
|
70
|
+
/** The `href` the hoisted chip-row stylesheet is deduplicated by. */
|
|
71
|
+
export const CHIP_ROW_STYLE_HREF = "stapel-search-filter-chips";
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The two rules an inline style cannot express: Firefox's `scrollbar-width`
|
|
75
|
+
* and WebKit's `::-webkit-scrollbar`. Static (no theme values), so one hoisted
|
|
76
|
+
* copy serves the document.
|
|
77
|
+
*/
|
|
78
|
+
export function chipRowCss(): string {
|
|
79
|
+
return [
|
|
80
|
+
`.${CHIP_ROW_CLASS}{scrollbar-width:none;-ms-overflow-style:none}`,
|
|
81
|
+
`.${CHIP_ROW_CLASS}::-webkit-scrollbar{display:none}`,
|
|
82
|
+
].join("");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The scroller: one line, its own overflow, nobody else's. */
|
|
86
|
+
const ROW: CSSProperties = {
|
|
87
|
+
display: "flex",
|
|
88
|
+
alignItems: "center",
|
|
89
|
+
gap: spacing[2],
|
|
90
|
+
flexWrap: "nowrap",
|
|
91
|
+
overflowX: "auto",
|
|
92
|
+
// A flick past the last chip must not hand the gesture to the page.
|
|
93
|
+
overscrollBehaviorInline: "contain",
|
|
94
|
+
// Room for the focus ring of the first and last chip, which a flush edge
|
|
95
|
+
// clips into invisibility.
|
|
96
|
+
paddingBlock: spacing[1],
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const CHIP: CSSProperties = { flex: "0 0 auto", borderRadius: radii.full };
|
|
100
|
+
|
|
101
|
+
/** Which picker is open, if any. `null` closes everything. */
|
|
102
|
+
type OpenChip = string | null;
|
|
103
|
+
|
|
104
|
+
export interface FilterChipsProps {
|
|
105
|
+
/** The category's feature schema — the source of option labels, of which
|
|
106
|
+
* slugs get a range chip, and of how each group is drawn. */
|
|
107
|
+
readonly categoryFeatures?: readonly FeatureDef[];
|
|
108
|
+
readonly locale?: string;
|
|
109
|
+
/** The location control (`geo-react`), same slot the panel takes. Without
|
|
110
|
+
* it the location chip appears only when the URL already carries a point,
|
|
111
|
+
* so a shared link can still be widened. */
|
|
112
|
+
readonly renderGeoFilter?: (slot: GeoFilterSlotProps) => ReactNode;
|
|
113
|
+
/** Open the whole panel — the leading chip's action. The page owns that
|
|
114
|
+
* sheet, because the page is the surface it covers. */
|
|
115
|
+
readonly onOpenAll: () => void;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The label a chip carries: the group's name alone when nothing is chosen,
|
|
120
|
+
* and the CHOICE when something is — "Brand" becomes "Bosch", "Brand, +2".
|
|
121
|
+
* A chip that reads "Brand" while filtering to Bosch is a lie the person can
|
|
122
|
+
* only catch by opening it.
|
|
123
|
+
*/
|
|
124
|
+
function chipLabel(group: FacetGroup, t: (key: string, p?: Record<string, unknown>) => string): string {
|
|
125
|
+
const chosen = group.options.filter((option) => option.selected);
|
|
126
|
+
const first = chosen[0];
|
|
127
|
+
if (first === undefined) return group.label;
|
|
128
|
+
return chosen.length === 1
|
|
129
|
+
? first.label
|
|
130
|
+
: `${first.label}${t(SEARCH_I18N_KEYS.filtersChipMore, { count: chosen.length - 1 })}`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function FilterChips(props: FilterChipsProps): ReactElement {
|
|
134
|
+
const t = useT();
|
|
135
|
+
const tPlural = useTPlural();
|
|
136
|
+
const { state, setGeo } = useSearchState();
|
|
137
|
+
const bag = useFacetPanel({
|
|
138
|
+
...(props.categoryFeatures !== undefined
|
|
139
|
+
? { categoryFeatures: props.categoryFeatures }
|
|
140
|
+
: {}),
|
|
141
|
+
...(props.locale !== undefined ? { locale: props.locale } : {}),
|
|
142
|
+
});
|
|
143
|
+
const applied = useAppliedCount();
|
|
144
|
+
const surface = useDialogSurface();
|
|
145
|
+
const [open, setOpen] = useState<OpenChip>(null);
|
|
146
|
+
|
|
147
|
+
const ranges = buildRangeGroups({
|
|
148
|
+
state,
|
|
149
|
+
...(props.categoryFeatures !== undefined
|
|
150
|
+
? { categoryFeatures: props.categoryFeatures }
|
|
151
|
+
: {}),
|
|
152
|
+
t,
|
|
153
|
+
});
|
|
154
|
+
const groups =
|
|
155
|
+
bag.state.status === "ready"
|
|
156
|
+
? bag.state.data.filter((group) => group.options.length > 0)
|
|
157
|
+
: [];
|
|
158
|
+
|
|
159
|
+
// The same sentence the panel's own commit button says, for the same reason:
|
|
160
|
+
// the results are BEHIND this sheet, so the button that closes it is the
|
|
161
|
+
// only place a person learns what their choice did.
|
|
162
|
+
const applyLabel =
|
|
163
|
+
applied.count === null || applied.kind === "unknown"
|
|
164
|
+
? t(SEARCH_I18N_KEYS.filtersApply)
|
|
165
|
+
: tPlural(
|
|
166
|
+
applied.kind === "at_least"
|
|
167
|
+
? SEARCH_I18N_KEYS.filtersShowCountAtLeast
|
|
168
|
+
: SEARCH_I18N_KEYS.filtersShowCount,
|
|
169
|
+
{ count: applied.count }
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const close = (): void => {
|
|
173
|
+
setOpen(null);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const sheetFor = (
|
|
177
|
+
id: string,
|
|
178
|
+
title: string,
|
|
179
|
+
body: ReactNode
|
|
180
|
+
): ReactElement => (
|
|
181
|
+
<SkinDialog
|
|
182
|
+
open={open === id}
|
|
183
|
+
onClose={close}
|
|
184
|
+
title={title}
|
|
185
|
+
dismissLabel={t(SEARCH_I18N_KEYS.filtersDismiss)}
|
|
186
|
+
data-testid={`filter-chip-sheet-${id}`}
|
|
187
|
+
footer={
|
|
188
|
+
<Button
|
|
189
|
+
block
|
|
190
|
+
type="primary"
|
|
191
|
+
data-testid={`filter-chip-apply-${id}`}
|
|
192
|
+
data-analytics="none"
|
|
193
|
+
data-analytics-reason="the filter is already applied; this closes the sheet"
|
|
194
|
+
onClick={close}
|
|
195
|
+
>
|
|
196
|
+
{applyLabel}
|
|
197
|
+
</Button>
|
|
198
|
+
}
|
|
199
|
+
>
|
|
200
|
+
{body}
|
|
201
|
+
</SkinDialog>
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const geo = state.geo;
|
|
205
|
+
const showGeoChip = props.renderGeoFilter !== undefined || geo !== undefined;
|
|
206
|
+
const geoLabel =
|
|
207
|
+
geo === undefined
|
|
208
|
+
? t(SEARCH_I18N_KEYS.geoTitle)
|
|
209
|
+
: geo.kind === "bbox"
|
|
210
|
+
? t(SEARCH_I18N_KEYS.geoBox)
|
|
211
|
+
: t(SEARCH_I18N_KEYS.geoCenter, {
|
|
212
|
+
lat: geo.lat.toFixed(3),
|
|
213
|
+
lon: geo.lon.toFixed(3),
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<>
|
|
218
|
+
<style href={CHIP_ROW_STYLE_HREF} precedence="default">
|
|
219
|
+
{chipRowCss()}
|
|
220
|
+
</style>
|
|
221
|
+
<div
|
|
222
|
+
className={CHIP_ROW_CLASS}
|
|
223
|
+
style={ROW}
|
|
224
|
+
role="group"
|
|
225
|
+
aria-label={t(SEARCH_I18N_KEYS.filtersChipsLabel)}
|
|
226
|
+
data-testid="search-filter-chips"
|
|
227
|
+
data-surface={surface}
|
|
228
|
+
>
|
|
229
|
+
{/* The leading chip: the whole panel, in one icon-sized target. It is
|
|
230
|
+
icon-only because it is the one chip whose meaning does not change
|
|
231
|
+
— and it carries a DOT, not a count, because the counts are already
|
|
232
|
+
written on the chips beside it. */}
|
|
233
|
+
<Button
|
|
234
|
+
shape="circle"
|
|
235
|
+
aria-label={t(SEARCH_I18N_KEYS.filtersAll)}
|
|
236
|
+
icon={<SlidersGlyph />}
|
|
237
|
+
style={CHIP}
|
|
238
|
+
data-testid="search-filters-open"
|
|
239
|
+
data-active={bag.activeFilters > 0 ? "true" : "false"}
|
|
240
|
+
data-analytics="none"
|
|
241
|
+
data-analytics-reason="opening the filter sheet is a read, not a flow step"
|
|
242
|
+
onClick={props.onOpenAll}
|
|
243
|
+
>
|
|
244
|
+
{bag.activeFilters > 0 && <ActiveDot />}
|
|
245
|
+
</Button>
|
|
246
|
+
|
|
247
|
+
{showGeoChip && (
|
|
248
|
+
<Button
|
|
249
|
+
style={CHIP}
|
|
250
|
+
shape="round"
|
|
251
|
+
type={geo !== undefined ? "primary" : "default"}
|
|
252
|
+
data-testid="search-chip-geo"
|
|
253
|
+
data-analytics="none"
|
|
254
|
+
data-analytics-reason="a filter is a read, not a flow step"
|
|
255
|
+
onClick={() => {
|
|
256
|
+
setOpen("geo");
|
|
257
|
+
}}
|
|
258
|
+
>
|
|
259
|
+
{geoLabel}
|
|
260
|
+
</Button>
|
|
261
|
+
)}
|
|
262
|
+
|
|
263
|
+
{ranges.map((group) => (
|
|
264
|
+
<Button
|
|
265
|
+
key={group.slug}
|
|
266
|
+
style={CHIP}
|
|
267
|
+
shape="round"
|
|
268
|
+
type={group.active ? "primary" : "default"}
|
|
269
|
+
data-testid={`search-chip-range-${group.slug}`}
|
|
270
|
+
data-analytics="none"
|
|
271
|
+
data-analytics-reason="a filter is a read, not a flow step"
|
|
272
|
+
onClick={() => {
|
|
273
|
+
setOpen(`range:${group.slug}`);
|
|
274
|
+
}}
|
|
275
|
+
>
|
|
276
|
+
{group.label}
|
|
277
|
+
</Button>
|
|
278
|
+
))}
|
|
279
|
+
|
|
280
|
+
{groups.map((group) => (
|
|
281
|
+
<Button
|
|
282
|
+
key={group.slug}
|
|
283
|
+
style={CHIP}
|
|
284
|
+
shape="round"
|
|
285
|
+
type={group.selected.length > 0 ? "primary" : "default"}
|
|
286
|
+
data-testid={`search-chip-${group.slug}`}
|
|
287
|
+
data-analytics="none"
|
|
288
|
+
data-analytics-reason="a filter is a read, not a flow step"
|
|
289
|
+
onClick={() => {
|
|
290
|
+
setOpen(`facet:${group.slug}`);
|
|
291
|
+
}}
|
|
292
|
+
>
|
|
293
|
+
{chipLabel(group, t)}
|
|
294
|
+
</Button>
|
|
295
|
+
))}
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
{/* One sheet per chip, rendered only for the open one: a dozen mounted
|
|
299
|
+
dialogs is a dozen focus traps waiting for a stray `open`. */}
|
|
300
|
+
{open?.startsWith("facet:") === true &&
|
|
301
|
+
(() => {
|
|
302
|
+
const slug = open.slice("facet:".length);
|
|
303
|
+
const group = groups.find((candidate) => candidate.slug === slug);
|
|
304
|
+
return group === undefined
|
|
305
|
+
? null
|
|
306
|
+
: sheetFor(
|
|
307
|
+
open,
|
|
308
|
+
group.label,
|
|
309
|
+
<FacetGroupControl
|
|
310
|
+
group={group}
|
|
311
|
+
onToggle={bag.toggle}
|
|
312
|
+
heading={false}
|
|
313
|
+
// A sheet devoted to ONE group has the room for all of it;
|
|
314
|
+
// "Show all" inside it would be a fold inside a fold.
|
|
315
|
+
visibleOptions={null}
|
|
316
|
+
/>
|
|
317
|
+
);
|
|
318
|
+
})()}
|
|
319
|
+
|
|
320
|
+
{open?.startsWith("range:") === true &&
|
|
321
|
+
(() => {
|
|
322
|
+
const slug = open.slice("range:".length);
|
|
323
|
+
const group = ranges.find((candidate) => candidate.slug === slug);
|
|
324
|
+
return group === undefined
|
|
325
|
+
? null
|
|
326
|
+
: sheetFor(
|
|
327
|
+
open,
|
|
328
|
+
group.label,
|
|
329
|
+
<RangeFilterRow group={group} onApply={bag.setRange} />
|
|
330
|
+
);
|
|
331
|
+
})()}
|
|
332
|
+
|
|
333
|
+
{open === "geo" &&
|
|
334
|
+
sheetFor(
|
|
335
|
+
"geo",
|
|
336
|
+
t(SEARCH_I18N_KEYS.geoTitle),
|
|
337
|
+
<Flex vertical gap={spacing[3]}>
|
|
338
|
+
{/* SETTING a centre needs a geocoder, which is `geo-react`'s and
|
|
339
|
+
the deployment's. ADJUSTING or CLEARING one the URL already
|
|
340
|
+
carries does not — which is why the chip still opens on a
|
|
341
|
+
shared link with no slot filled, and why the absence of the
|
|
342
|
+
slot is NAMED in development rather than left as a gap under
|
|
343
|
+
the sheet's title. */}
|
|
344
|
+
{props.renderGeoFilter?.({
|
|
345
|
+
value: geo,
|
|
346
|
+
onChange: (next) => {
|
|
347
|
+
setGeo(next);
|
|
348
|
+
},
|
|
349
|
+
}) ?? <SlotPlaceholder name="renderGeoFilter" data-testid="search-chip-geo-slot" />}
|
|
350
|
+
{geo !== undefined && (
|
|
351
|
+
<>
|
|
352
|
+
<Typography.Text type="secondary" data-testid="search-chip-geo-summary">
|
|
353
|
+
{geoLabel}
|
|
354
|
+
</Typography.Text>
|
|
355
|
+
<Button
|
|
356
|
+
style={{ alignSelf: "flex-start" }}
|
|
357
|
+
data-testid="search-chip-geo-clear"
|
|
358
|
+
data-analytics="none"
|
|
359
|
+
data-analytics-reason="a filter is a read, not a flow step"
|
|
360
|
+
onClick={() => {
|
|
361
|
+
setGeo(null);
|
|
362
|
+
}}
|
|
363
|
+
>
|
|
364
|
+
{t(SEARCH_I18N_KEYS.geoClear)}
|
|
365
|
+
</Button>
|
|
366
|
+
</>
|
|
367
|
+
)}
|
|
368
|
+
</Flex>
|
|
369
|
+
)}
|
|
370
|
+
</>
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** The mark on the "all filters" chip: something is applied. Not a count —
|
|
375
|
+
* the counts are on the chips beside it, and a number inside a 32px circle is
|
|
376
|
+
* a number nobody reads. */
|
|
377
|
+
function ActiveDot(): ReactElement {
|
|
378
|
+
return (
|
|
379
|
+
<span
|
|
380
|
+
aria-hidden="true"
|
|
381
|
+
data-testid="search-filters-dot"
|
|
382
|
+
style={{
|
|
383
|
+
position: "absolute",
|
|
384
|
+
insetInlineEnd: spacing[1],
|
|
385
|
+
insetBlockStart: spacing[1],
|
|
386
|
+
width: spacing[2],
|
|
387
|
+
height: spacing[2],
|
|
388
|
+
borderRadius: radii.full,
|
|
389
|
+
background: "currentColor",
|
|
390
|
+
}}
|
|
391
|
+
/>
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** Sliders — the one glyph a filter control is universally drawn with. Inline
|
|
396
|
+
* SVG, like every other glyph in the fleet's skins: no icon-font dependency. */
|
|
397
|
+
function SlidersGlyph(): ReactElement {
|
|
398
|
+
return (
|
|
399
|
+
<svg
|
|
400
|
+
width="18"
|
|
401
|
+
height="18"
|
|
402
|
+
viewBox="0 0 24 24"
|
|
403
|
+
fill="none"
|
|
404
|
+
stroke="currentColor"
|
|
405
|
+
strokeWidth="1.75"
|
|
406
|
+
strokeLinecap="round"
|
|
407
|
+
role="img"
|
|
408
|
+
aria-hidden="true"
|
|
409
|
+
>
|
|
410
|
+
<path d="M4 7h10M18 7h2M4 17h4M12 17h8" />
|
|
411
|
+
<circle cx="16" cy="7" r="2.2" />
|
|
412
|
+
<circle cx="10" cy="17" r="2.2" />
|
|
413
|
+
</svg>
|
|
414
|
+
);
|
|
415
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The query's LANGUAGE — `lang`, and the reason it is a filter rather than a
|
|
3
|
+
* display preference.
|
|
4
|
+
*
|
|
5
|
+
* `lang` does two things server-side (`query.py`): it picks the ANALYZER (so a
|
|
6
|
+
* Russian word stems as Russian rather than as an unknown token) and it
|
|
7
|
+
* NARROWS the corpus to documents indexed in that language. Getting it wrong therefore changes
|
|
8
|
+
* which results exist, not how they are written — which is why the control
|
|
9
|
+
* lives in the filter panel beside the facets and not in a settings menu.
|
|
10
|
+
*
|
|
11
|
+
* ── Which languages a deployment has is not this pair's fact ───────────────
|
|
12
|
+
*
|
|
13
|
+
* The index's languages come from what has been indexed; there is no endpoint
|
|
14
|
+
* that lists them. So the host names them (`languages`), and the labels come
|
|
15
|
+
* from `Intl.DisplayNames` in the reader's own locale — each language named
|
|
16
|
+
* the way THIS reader would name it — rather than from a translation table this
|
|
17
|
+
* pair would have to carry for every language a deployment might index.
|
|
18
|
+
*
|
|
19
|
+
* With no `languages` prop the control renders only when the URL already
|
|
20
|
+
* carries one, and then only to REMOVE it: a constraint that arrived in a
|
|
21
|
+
* shared link must always have a control that widens it again.
|
|
22
|
+
*/
|
|
23
|
+
import { useMemo } from "react";
|
|
24
|
+
import type { ReactElement } from "react";
|
|
25
|
+
import { Flex, Select, Typography } from "antd";
|
|
26
|
+
import { useOptionalI18n, useT } from "@stapel/core";
|
|
27
|
+
import { spacing } from "@stapel/tokens";
|
|
28
|
+
import { useSearchState } from "../headless/SearchStateProvider.js";
|
|
29
|
+
import { SEARCH_I18N_KEYS } from "../i18n/keys.js";
|
|
30
|
+
|
|
31
|
+
/** Width of the language select — a language name plus room for a long one. */
|
|
32
|
+
export const LANGUAGE_SELECT_MIN_WIDTH = 176;
|
|
33
|
+
|
|
34
|
+
export interface LanguageSelectProps {
|
|
35
|
+
/** BCP-47 tags the deployment indexes (e.g. `["ru", "en"]`). */
|
|
36
|
+
readonly languages?: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A language tag as a person reads it, in THEIR locale. Falls back to the tag
|
|
41
|
+
* itself where the runtime has no name for it — a tag is at least honest,
|
|
42
|
+
* where a blank option is unclickable.
|
|
43
|
+
*/
|
|
44
|
+
function languageName(tag: string, locale: string): string {
|
|
45
|
+
try {
|
|
46
|
+
const names = new Intl.DisplayNames([locale], { type: "language" });
|
|
47
|
+
return names.of(tag) ?? tag;
|
|
48
|
+
} catch {
|
|
49
|
+
return tag;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function LanguageSelect(props: LanguageSelectProps): ReactElement | null {
|
|
54
|
+
const t = useT();
|
|
55
|
+
// The reader's locale names the languages. Optional on purpose: every other
|
|
56
|
+
// control in this skin renders outside a provider (English floor) rather
|
|
57
|
+
// than throwing, and a language list is not the place to break that.
|
|
58
|
+
const locale = useOptionalI18n()?.locale ?? "en";
|
|
59
|
+
const { state, setLanguage } = useSearchState();
|
|
60
|
+
const active = state.lang;
|
|
61
|
+
const languages = props.languages;
|
|
62
|
+
|
|
63
|
+
const options = useMemo(() => {
|
|
64
|
+
const tags = [...(languages ?? [])];
|
|
65
|
+
if (active !== undefined && !tags.includes(active)) tags.push(active);
|
|
66
|
+
return [
|
|
67
|
+
{ value: "", label: t(SEARCH_I18N_KEYS.languageAny) },
|
|
68
|
+
...tags.map((tag) => ({ value: tag, label: languageName(tag, locale) })),
|
|
69
|
+
];
|
|
70
|
+
}, [languages, active, locale, t]);
|
|
71
|
+
|
|
72
|
+
// Nothing offered and nothing applied: a select with one option ("any") is a
|
|
73
|
+
// control that cannot do anything, which §83 calls a dead control.
|
|
74
|
+
if ((languages ?? []).length === 0 && active === undefined) return null;
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Flex gap={spacing[2]} align="center" wrap>
|
|
78
|
+
<Typography.Text type="secondary" aria-hidden="true">
|
|
79
|
+
{t(SEARCH_I18N_KEYS.languageLabel)}
|
|
80
|
+
</Typography.Text>
|
|
81
|
+
<Select<string>
|
|
82
|
+
data-testid="search-language"
|
|
83
|
+
aria-label={t(SEARCH_I18N_KEYS.languageLabel)}
|
|
84
|
+
style={{ minWidth: LANGUAGE_SELECT_MIN_WIDTH }}
|
|
85
|
+
value={active ?? ""}
|
|
86
|
+
onChange={(next) => {
|
|
87
|
+
setLanguage(next === "" ? null : next);
|
|
88
|
+
}}
|
|
89
|
+
options={options}
|
|
90
|
+
/>
|
|
91
|
+
</Flex>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many results a page carries — `limit`, the fifth of the nine state
|
|
3
|
+
* setters that had no control.
|
|
4
|
+
*
|
|
5
|
+
* The offered sizes are the pair's, not the schema's: `docs/schema.json`
|
|
6
|
+
* declares `limit` as a bare integer, and the backend clamps it to
|
|
7
|
+
* `1..MAX_PAGE_SIZE` (100) with `DEFAULT_PAGE_SIZE` 24 when it is absent. So
|
|
8
|
+
* the select offers a short ladder around that default and never sends
|
|
9
|
+
* something the server would have to clamp — a person who lands on a link
|
|
10
|
+
* carrying `limit=37` keeps it (it is offered as its own option) rather than
|
|
11
|
+
* being silently moved to 24, which would change what a shared link shows.
|
|
12
|
+
*
|
|
13
|
+
* A page size is a PREFERENCE, not a step through the results: `setLimit`
|
|
14
|
+
* replaces the history entry rather than pushing one, so Back still undoes the
|
|
15
|
+
* last filter and not the last time somebody widened the page.
|
|
16
|
+
*/
|
|
17
|
+
import type { ReactElement } from "react";
|
|
18
|
+
import { Flex, Select, Typography } from "antd";
|
|
19
|
+
import { useT } from "@stapel/core";
|
|
20
|
+
import { fontSize, spacing } from "@stapel/tokens";
|
|
21
|
+
import { useSearchState } from "../headless/SearchStateProvider.js";
|
|
22
|
+
import { SEARCH_I18N_KEYS } from "../i18n/keys.js";
|
|
23
|
+
|
|
24
|
+
/** The shipped ladder, around stapel-search's own `DEFAULT_PAGE_SIZE` (24). */
|
|
25
|
+
export const SEARCH_PAGE_SIZES: readonly number[] = [12, 24, 48, 96];
|
|
26
|
+
|
|
27
|
+
/** Width of the size select — the widest option plus its caption. */
|
|
28
|
+
export const PAGE_SIZE_SELECT_MIN_WIDTH = 148;
|
|
29
|
+
|
|
30
|
+
export interface PageSizeSelectProps {
|
|
31
|
+
/** Override the offered ladder (a deployment with its own `MAX_PAGE_SIZE`). */
|
|
32
|
+
readonly sizes?: readonly number[];
|
|
33
|
+
/** What the server uses when the URL names none. Default 24. */
|
|
34
|
+
readonly defaultSize?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function PageSizeSelect(props: PageSizeSelectProps): ReactElement {
|
|
38
|
+
const t = useT();
|
|
39
|
+
const { state, setLimit } = useSearchState();
|
|
40
|
+
const ladder = props.sizes ?? SEARCH_PAGE_SIZES;
|
|
41
|
+
const active = state.limit ?? props.defaultSize ?? 24;
|
|
42
|
+
const offLadder = !ladder.includes(active);
|
|
43
|
+
const values = offLadder ? [...ladder, active].sort((a, b) => a - b) : ladder;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Flex vertical gap={spacing[1]} data-off-ladder={offLadder ? "true" : "false"}>
|
|
47
|
+
<Flex gap={spacing[2]} align="center">
|
|
48
|
+
<Typography.Text type="secondary" aria-hidden="true">
|
|
49
|
+
{t(SEARCH_I18N_KEYS.limitLabel)}
|
|
50
|
+
</Typography.Text>
|
|
51
|
+
<Select<number>
|
|
52
|
+
data-testid="search-limit"
|
|
53
|
+
aria-label={t(SEARCH_I18N_KEYS.limitLabel)}
|
|
54
|
+
style={{ minWidth: PAGE_SIZE_SELECT_MIN_WIDTH }}
|
|
55
|
+
value={active}
|
|
56
|
+
onChange={(next) => {
|
|
57
|
+
setLimit(next);
|
|
58
|
+
}}
|
|
59
|
+
options={values.map((size) => ({
|
|
60
|
+
value: size,
|
|
61
|
+
label: t(SEARCH_I18N_KEYS.limitOption, { count: size }),
|
|
62
|
+
}))}
|
|
63
|
+
/>
|
|
64
|
+
</Flex>
|
|
65
|
+
{/* Keeping a link's own page size is a DECISION, and a decision nobody
|
|
66
|
+
is told about is indistinguishable from a default. "37 per page" in
|
|
67
|
+
the box looks like the deployment's ladder until this line says
|
|
68
|
+
where it came from. */}
|
|
69
|
+
{offLadder && (
|
|
70
|
+
<Typography.Text
|
|
71
|
+
type="secondary"
|
|
72
|
+
style={{ fontSize: fontSize.xs.fontSize }}
|
|
73
|
+
data-testid="search-limit-from-link"
|
|
74
|
+
>
|
|
75
|
+
{t(SEARCH_I18N_KEYS.limitFromLink)}
|
|
76
|
+
</Typography.Text>
|
|
77
|
+
)}
|
|
78
|
+
</Flex>
|
|
79
|
+
);
|
|
80
|
+
}
|