mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-04 23:32:54 +01:00
sticky search
This commit is contained in:
6 files changed
+86
-41
No files matched your search
@@ -31,6 +31,7 @@ Pages that are not migrated yet are named `_index.astro` so Astro skips them. Mi
|
|||||||
- No return type annotations. Put `satisfies Type` on the returned expression instead.
|
- No return type annotations. Put `satisfies Type` on the returned expression instead.
|
||||||
- Wrap functions defined inside React components in `useCallback`.
|
- Wrap functions defined inside React components in `useCallback`.
|
||||||
- Never inline a complex type (a union of object shapes, etc.) in a signature; name it as an interface or type.
|
- Never inline a complex type (a union of object shapes, etc.) in a signature; name it as an interface or type.
|
||||||
|
- Use a string `enum` (`Page = "page"`) instead of a union of string literals (`"page" | "dialog"`) whenever the values can be enumerated.
|
||||||
- In object literals, `...spread` entries come first, each on its own line, followed by a blank line, then the custom entries. A single-line object with a spread becomes multi-line.
|
- In object literals, `...spread` entries come first, each on its own line, followed by a blank line, then the custom entries. A single-line object with a spread becomes multi-line.
|
||||||
- When an object literal's values are long expressions, compute them first into `const`s named after their keys, then build the object with shorthand (`{ name, color, tanks: [] }`). Short values stay inline.
|
- When an object literal's values are long expressions, compute them first into `const`s named after their keys, then build the object with shorthand (`{ name, color, tanks: [] }`). Short values stay inline.
|
||||||
- Always hoist values that take work to compute (a function call, math, a lookup, like `"A".charCodeAt(0)` or `1 - SCROLL_ZONE`) and don't change between iterations or calls out of loops and repeatedly called functions into a `const` above them. No exceptions. Plain literals (strings, numbers, selectors like `"[data-row]"`) cost nothing and stay inline.
|
- Always hoist values that take work to compute (a function call, math, a lookup, like `"A".charCodeAt(0)` or `1 - SCROLL_ZONE`) and don't change between iterations or calls out of loops and repeatedly called functions into a `const` above them. No exceptions. Plain literals (strings, numbers, selectors like `"[data-row]"`) cost nothing and stay inline.
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
.controls {
|
||||||
|
position: sticky;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--space-4);
|
||||||
|
|
||||||
|
margin-block: calc(-1 * var(--space-4));
|
||||||
|
padding-block: var(--space-4);
|
||||||
|
|
||||||
|
/* Bleeds across the page gutters so results don't peek out beside it */
|
||||||
|
&[data-surface="page"] {
|
||||||
|
top: var(--navbar-big-height, 0);
|
||||||
|
|
||||||
|
margin-inline: calc(-1 * var(--page-padding));
|
||||||
|
padding-inline: var(--page-padding);
|
||||||
|
|
||||||
|
background-color: var(--gray-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cancels the overlay's padding, which sticky offsets are measured inside of */
|
||||||
|
&[data-surface="dialog"] {
|
||||||
|
top: calc(-1 * var(--space-4));
|
||||||
|
|
||||||
|
background-color: var(--gray-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.filters {
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import type { TankDefinition } from "@blitzkit/protos";
|
||||||
|
import type { LocaleAcceptorProps } from "../../hooks/useLocale";
|
||||||
|
import { ScrollerCurtains } from "../ScrollerCurtains";
|
||||||
|
import { TankSearchBar } from "../TankSearchBar";
|
||||||
|
import { TankSearchFilters } from "../TankSearchFilters";
|
||||||
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
|
export enum TankSearchControlsSurface {
|
||||||
|
Page = "page",
|
||||||
|
Dialog = "dialog",
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TankSearchControlsProps extends LocaleAcceptorProps {
|
||||||
|
// Which surface it sticks within, deciding its offset and background
|
||||||
|
surface: TankSearchControlsSurface;
|
||||||
|
onSelect?: (tank: TankDefinition) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The search bar and filters, stuck flush to the top while the results scroll
|
||||||
|
export function TankSearchControls({
|
||||||
|
locale,
|
||||||
|
surface,
|
||||||
|
onSelect,
|
||||||
|
}: TankSearchControlsProps) {
|
||||||
|
return (
|
||||||
|
<div className={styles.controls} data-surface={surface}>
|
||||||
|
<TankSearchBar locale={locale} onSelect={onSelect} />
|
||||||
|
|
||||||
|
<div className={styles.filters}>
|
||||||
|
<ScrollerCurtains />
|
||||||
|
<TankSearchFilters locale={locale} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
.controls {
|
|
||||||
position: sticky;
|
|
||||||
top: calc(-1 * var(--space-4));
|
|
||||||
z-index: 1;
|
|
||||||
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: var(--space-4);
|
|
||||||
|
|
||||||
margin-block: calc(-1 * var(--space-4));
|
|
||||||
padding-block: var(--space-4);
|
|
||||||
|
|
||||||
background-color: var(--gray-2);
|
|
||||||
|
|
||||||
.filters {
|
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,11 +3,11 @@ import { useCallback, useState, type ReactNode } from "react";
|
|||||||
import { useLocale } from "../../hooks/useLocale";
|
import { useLocale } from "../../hooks/useLocale";
|
||||||
import { useStrings } from "../../hooks/useStrings";
|
import { useStrings } from "../../hooks/useStrings";
|
||||||
import { Dialog } from "../Dialog";
|
import { Dialog } from "../Dialog";
|
||||||
import { ScrollerCurtains } from "../ScrollerCurtains";
|
import {
|
||||||
import { TankSearchBar } from "../TankSearchBar";
|
TankSearchControls,
|
||||||
import { TankSearchFilters } from "../TankSearchFilters";
|
TankSearchControlsSurface,
|
||||||
|
} from "../TankSearchControls";
|
||||||
import { TankSearchResults } from "../TankSearchResults";
|
import { TankSearchResults } from "../TankSearchResults";
|
||||||
import styles from "./index.module.css";
|
|
||||||
|
|
||||||
interface TankSearchDialogProps {
|
interface TankSearchDialogProps {
|
||||||
// the trigger, passed to Dialog.Trigger with asChild
|
// the trigger, passed to Dialog.Trigger with asChild
|
||||||
@@ -64,14 +64,11 @@ export function TankSearchDialog({
|
|||||||
</Dialog.Header>
|
</Dialog.Header>
|
||||||
|
|
||||||
<Dialog.Body>
|
<Dialog.Body>
|
||||||
<div className={styles.controls}>
|
<TankSearchControls
|
||||||
<TankSearchBar locale={locale} onSelect={handleSelect} />
|
locale={locale}
|
||||||
|
surface={TankSearchControlsSurface.Dialog}
|
||||||
<div className={styles.filters}>
|
onSelect={handleSelect}
|
||||||
<ScrollerCurtains />
|
/>
|
||||||
<TankSearchFilters locale={locale} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<TankSearchResults
|
<TankSearchResults
|
||||||
locale={locale}
|
locale={locale}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
---
|
---
|
||||||
import ColorScale from "../../../../components/ColorScale.astro";
|
import ColorScale from "../../../../components/ColorScale.astro";
|
||||||
import { RecentlyViewedTanks } from "../../../../components/RecentlyViewedTanks";
|
import { RecentlyViewedTanks } from "../../../../components/RecentlyViewedTanks";
|
||||||
import { ScrollerCurtains } from "../../../../components/ScrollerCurtains";
|
|
||||||
import { Section } from "../../../../components/Section";
|
import { Section } from "../../../../components/Section";
|
||||||
import Sections from "../../../../components/Sections.astro";
|
import Sections from "../../../../components/Sections.astro";
|
||||||
import { TankSearchBar } from "../../../../components/TankSearchBar";
|
import {
|
||||||
import { TankSearchFilters } from "../../../../components/TankSearchFilters";
|
TankSearchControls,
|
||||||
|
TankSearchControlsSurface,
|
||||||
|
} from "../../../../components/TankSearchControls";
|
||||||
import { TankSearchResults } from "../../../../components/TankSearchResults";
|
import { TankSearchResults } from "../../../../components/TankSearchResults";
|
||||||
import ToolBanner from "../../../../components/ToolBanner.astro";
|
import ToolBanner from "../../../../components/ToolBanner.astro";
|
||||||
import { tools } from "../../../../config/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
@@ -24,14 +25,11 @@ const { locale } = Astro.props;
|
|||||||
<ToolBanner {locale} tool={tools.tanks} />
|
<ToolBanner {locale} tool={tools.tanks} />
|
||||||
|
|
||||||
<Sections>
|
<Sections>
|
||||||
<Section>
|
<TankSearchControls
|
||||||
<TankSearchBar {locale} client:load />
|
{locale}
|
||||||
</Section>
|
surface={TankSearchControlsSurface.Page}
|
||||||
|
client:load
|
||||||
<Section overflow>
|
/>
|
||||||
<ScrollerCurtains client:load />
|
|
||||||
<TankSearchFilters {locale} client:load />
|
|
||||||
</Section>
|
|
||||||
|
|
||||||
<RecentlyViewedTanks {locale} client:load />
|
<RecentlyViewedTanks {locale} client:load />
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user