hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { Show } from "solid-js"; |
| 2 | import type { JSX } from "solid-js"; |
| 3 | import { DataTableSearch } from "@/components/ui/data-table-search"; |
| 4 | import { cn } from "@/lib/cn"; |
| 5 | |
| 6 | /** The card a list toolbar sits on — the same box DataTable draws. */ |
| 7 | export const TOOLBAR_CARD = "rounded-xl border border-border-line bg-surface-base p-3 shadow-xs"; |
| 8 | |
| 9 | /** |
| 10 | * One toolbar control: a pill, touch-sized (h-10) below `sm` and on touch |
| 11 | * screens, h-8 from `sm` up, at 13px. For controls a page places by hand |
| 12 | * (a stepper, a date jump) beside the slot-sized ones. |
| 13 | */ |
| 14 | export const TOOLBAR_CONTROL = "h-10 rounded-full text-[13px] sm:h-8 touch:h-10"; |
| 15 | |
| 16 | /** |
| 17 | * The same standard applied to every button and link inside a slot, so the |
| 18 | * page's plain `<Button size="sm">` (26px) lands at the toolbar height. |
| 19 | * Mirrors DataTable's actions/filters slots. |
| 20 | */ |
| 21 | export const TOOLBAR_SLOT = |
| 22 | "[&_button]:h-10 [&_button]:shrink-0 [&_button]:rounded-full [&_button]:px-3.5 [&_button]:text-[13px] sm:[&_button]:h-8 touch:[&_button]:h-10 [&_a]:h-10 [&_a]:rounded-full [&_a]:px-3.5 [&_a]:text-[13px] sm:[&_a]:h-8 touch:[&_a]:h-10 [&_[data-filter-active]]:border-primary [&_[data-filter-active]]:text-primary-text"; |
| 23 | |
| 24 | export function DataToolbar(props: { |
| 25 | searchValue?: string; |
| 26 | searchPlaceholder?: string; |
| 27 | /** On-focus hint under the search box naming the fields it matches. */ |
| 28 | searchHint?: string; |
| 29 | onSearchInput?: (value: string) => void; |
| 30 | filters?: JSX.Element; |
| 31 | actions?: JSX.Element; |
| 32 | /** Let the search box grow into the free width instead of stopping at `max-w-72`. */ |
| 33 | inline?: boolean; |
| 34 | class?: string; |
| 35 | }) { |
| 36 | const hasSearch = () => props.searchValue !== undefined || props.searchPlaceholder !== undefined || props.onSearchInput !== undefined; |
| 37 | return ( |
| 38 | // One wrapping row, ordered by width — the same shape as DataTable's |
| 39 | // toolbar. Phones: search and actions share the first line and the |
| 40 | // filters take the next one; nothing is squeezed into a fixed row, where |
| 41 | // the search box shrank to a sliver and a filter painted over its icon. |
| 42 | // From `sm`: search, filters, then actions pushed to the right edge. |
| 43 | <div class={cn("flex flex-wrap items-center gap-2 sm:gap-3", props.class)}> |
| 44 | <Show when={hasSearch()}> |
| 45 | <DataTableSearch |
| 46 | class={cn("order-1 w-auto min-w-40 flex-1 grow-[100]", !props.inline && "sm:max-w-72")} |
| 47 | value={props.searchValue ?? ""} |
| 48 | placeholder={props.searchPlaceholder} |
| 49 | hint={props.searchHint} |
| 50 | onChange={(value) => props.onSearchInput?.(value)} |
| 51 | /> |
| 52 | </Show> |
| 53 | <Show when={props.filters}> |
| 54 | <div class={cn("order-3 flex w-full flex-wrap items-center gap-2 sm:order-2 sm:w-auto", TOOLBAR_SLOT)}>{props.filters}</div> |
| 55 | </Show> |
| 56 | <Show when={props.actions}> |
| 57 | <div class={cn("order-2 ml-auto flex shrink-0 grow items-center justify-end gap-2 sm:order-3 sm:grow-0 max-sm:[&_button]:flex-1", TOOLBAR_SLOT)}>{props.actions}</div> |
| 58 | </Show> |
| 59 | </div> |
| 60 | ); |
| 61 | } |