torch-glare 2.2.1 → 2.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/apps/lib/components/Badge.tsx +6 -0
- package/apps/lib/components/ContextMenu.tsx +14 -11
- package/apps/lib/components/DataViews/DataViewRadio.tsx +9 -2
- package/apps/lib/components/DataViews/DataViewsConfigPanel.tsx +8 -8
- package/apps/lib/components/DataViews/DataViewsHeader.tsx +13 -32
- package/apps/lib/components/DataViews/FilterPanel.tsx +26 -9
- package/apps/lib/components/DataViews/filters/DatePickerRangeFilter.tsx +80 -0
- package/apps/lib/components/DataViews/types.ts +8 -0
- package/apps/lib/components/DatePicker.tsx +6 -1
- package/apps/lib/components/DropdownMenu.tsx +14 -11
- package/apps/lib/components/HeaderBar.tsx +127 -0
- package/apps/lib/components/SearchableSelect.tsx +42 -42
- package/apps/lib/components/SearchableTable.tsx +167 -177
- package/apps/lib/components/TabSwitch.tsx +181 -0
- package/docs/components/context-menu.md +30 -0
- package/docs/components/data-views-config-panel.md +3 -3
- package/docs/components/data-views-layout.md +9 -2
- package/docs/components/dropdown-menu.md +28 -0
- package/docs/components/header-bar.md +181 -0
- package/docs/components/searchable-table.md +44 -30
- package/docs/components/section-block.md +118 -0
- package/docs/components/tab-switch.md +163 -0
- package/docs/how-to/data-views-from-backend-response.md +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, type ReactNode } from "react";
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
5
|
+
import { cn } from "../utils/cn";
|
|
6
|
+
import { Themes } from "../utils/types";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* TabSwitch — a segmented control for picking one option from a small set.
|
|
10
|
+
*
|
|
11
|
+
* The classic "List / Cards"-style pill switcher: a rounded track holding one
|
|
12
|
+
* button per option, with the active option rendered as a raised pill. Thin
|
|
13
|
+
* dividers sit between adjacent inactive options (never flanking the active
|
|
14
|
+
* pill). Generic over the option value, controlled via `value`/`onValueChange`,
|
|
15
|
+
* theme-aware, and built on semantic presentation tokens so it adapts to
|
|
16
|
+
* light/dark/default themes.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export interface TabSwitchOption<T extends string = string> {
|
|
20
|
+
value: T;
|
|
21
|
+
label?: ReactNode;
|
|
22
|
+
/** Optional leading icon (Remix `<i>`, lucide svg, etc.). */
|
|
23
|
+
icon?: ReactNode;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The track (outer container) holds the segmented buttons.
|
|
28
|
+
const trackStyles = cva(
|
|
29
|
+
[
|
|
30
|
+
"inline-flex items-center w-fit",
|
|
31
|
+
"rounded-[10px]",
|
|
32
|
+
"bg-background-presentation-body-primary",
|
|
33
|
+
"shadow-[inset_0_0_4px_0_rgba(0,0,0,0.08)]",
|
|
34
|
+
],
|
|
35
|
+
{
|
|
36
|
+
variants: {
|
|
37
|
+
size: {
|
|
38
|
+
S: ["gap-[2px] p-[2px]"],
|
|
39
|
+
M: ["gap-[2px] p-[2px]"],
|
|
40
|
+
L: ["gap-[3px] p-[3px]"],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
defaultVariants: { size: "M" },
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Each option button. The active pill is raised; inactive options are
|
|
48
|
+
// transparent and lighten on hover.
|
|
49
|
+
const optionStyles = cva(
|
|
50
|
+
[
|
|
51
|
+
"flex items-center justify-center gap-[6px]",
|
|
52
|
+
"rounded-[8px]",
|
|
53
|
+
"font-[510] leading-none",
|
|
54
|
+
"transition-all duration-200 ease-in-out",
|
|
55
|
+
"outline-none",
|
|
56
|
+
"focus-visible:ring-2 focus-visible:ring-border-presentation-state-focus",
|
|
57
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
58
|
+
],
|
|
59
|
+
{
|
|
60
|
+
variants: {
|
|
61
|
+
size: {
|
|
62
|
+
S: [
|
|
63
|
+
"h-5 px-2 text-[12px]",
|
|
64
|
+
"[&_svg]:h-3 [&_svg]:w-3",
|
|
65
|
+
"[&_i]:text-[12px]",
|
|
66
|
+
],
|
|
67
|
+
M: [
|
|
68
|
+
"h-6 px-3 text-[14px]",
|
|
69
|
+
"[&_svg]:h-[14px] [&_svg]:w-[14px]",
|
|
70
|
+
"[&_i]:text-[14px]",
|
|
71
|
+
],
|
|
72
|
+
L: [
|
|
73
|
+
"h-8 px-4 text-[16px]",
|
|
74
|
+
"[&_svg]:h-4 [&_svg]:w-4",
|
|
75
|
+
"[&_i]:text-[16px]",
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
active: {
|
|
79
|
+
// Active option = a solid raised WHITE pill with dark text, in every
|
|
80
|
+
// theme. The selected-tab design tokens encode a different look per
|
|
81
|
+
// theme (black pill on light, translucent-white on dark), but the
|
|
82
|
+
// intended switcher is always a white pill — and it must stay visible
|
|
83
|
+
// on the always-dark DataViews header bar — so the active pill is
|
|
84
|
+
// theme-independent here. The track + inactive options remain
|
|
85
|
+
// theme-aware.
|
|
86
|
+
true: [
|
|
87
|
+
"bg-white",
|
|
88
|
+
"text-[#1C1D1F]",
|
|
89
|
+
"border border-black/5",
|
|
90
|
+
"shadow-[0_1px_3px_0_rgba(0,0,0,0.18)]",
|
|
91
|
+
],
|
|
92
|
+
false: [
|
|
93
|
+
"border border-transparent",
|
|
94
|
+
"bg-transparent",
|
|
95
|
+
"text-content-presentation-global-primary",
|
|
96
|
+
"hover:bg-background-presentation-tab-hover",
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
defaultVariants: { size: "M", active: false },
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
interface Props<T extends string = string>
|
|
105
|
+
extends
|
|
106
|
+
Omit<React.HTMLAttributes<HTMLDivElement>, "onChange">,
|
|
107
|
+
VariantProps<typeof trackStyles> {
|
|
108
|
+
options: TabSwitchOption<T>[];
|
|
109
|
+
/** Controlled selected value. */
|
|
110
|
+
value: T;
|
|
111
|
+
onValueChange: (value: T) => void;
|
|
112
|
+
theme?: Themes;
|
|
113
|
+
disabled?: boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function TabSwitchInner<T extends string = string>(
|
|
117
|
+
{
|
|
118
|
+
options,
|
|
119
|
+
value,
|
|
120
|
+
onValueChange,
|
|
121
|
+
size,
|
|
122
|
+
theme,
|
|
123
|
+
disabled,
|
|
124
|
+
className,
|
|
125
|
+
...props
|
|
126
|
+
}: Props<T>,
|
|
127
|
+
ref: React.ForwardedRef<HTMLDivElement>,
|
|
128
|
+
) {
|
|
129
|
+
return (
|
|
130
|
+
<div
|
|
131
|
+
ref={ref}
|
|
132
|
+
role="tablist"
|
|
133
|
+
data-theme={theme}
|
|
134
|
+
className={cn(trackStyles({ size }), className)}
|
|
135
|
+
{...props}
|
|
136
|
+
>
|
|
137
|
+
{options.map((option, idx) => {
|
|
138
|
+
const active = option.value === value;
|
|
139
|
+
const prevActive = idx > 0 && options[idx - 1].value === value;
|
|
140
|
+
// A divider sits between two inactive options only — the active pill is
|
|
141
|
+
// never flanked by one.
|
|
142
|
+
const showDivider = idx > 0 && !active && !prevActive;
|
|
143
|
+
const isDisabled = disabled || option.disabled;
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<div key={option.value} className="flex items-center">
|
|
147
|
+
{showDivider && (
|
|
148
|
+
<div className="mx-[3px] h-3 w-px bg-border-presentation-action-disabled" />
|
|
149
|
+
)}
|
|
150
|
+
<button
|
|
151
|
+
type="button"
|
|
152
|
+
role="tab"
|
|
153
|
+
aria-selected={active}
|
|
154
|
+
aria-pressed={active}
|
|
155
|
+
disabled={isDisabled}
|
|
156
|
+
onClick={() => onValueChange(option.value)}
|
|
157
|
+
className={cn(optionStyles({ size, active }))}
|
|
158
|
+
>
|
|
159
|
+
{option.icon && (
|
|
160
|
+
<span className="flex items-center justify-center">
|
|
161
|
+
{option.icon}
|
|
162
|
+
</span>
|
|
163
|
+
)}
|
|
164
|
+
{option.label}
|
|
165
|
+
</button>
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
})}
|
|
169
|
+
</div>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// forwardRef loses the generic, so we cast to preserve `<TabSwitch<T> />` typing.
|
|
174
|
+
export const TabSwitch = forwardRef(TabSwitchInner) as <
|
|
175
|
+
T extends string = string,
|
|
176
|
+
>(
|
|
177
|
+
props: Props<T> & { ref?: React.ForwardedRef<HTMLDivElement> },
|
|
178
|
+
) => ReturnType<typeof TabSwitchInner>;
|
|
179
|
+
|
|
180
|
+
// @ts-expect-error — attach displayName to the cast function for devtools.
|
|
181
|
+
TabSwitch.displayName = "TabSwitch";
|
|
@@ -233,6 +233,33 @@ function RtlMenu() {
|
|
|
233
233
|
}
|
|
234
234
|
```
|
|
235
235
|
|
|
236
|
+
### Long Menu (max height + scroll)
|
|
237
|
+
|
|
238
|
+
Tall menus scroll instead of overflowing off-screen. The surface caps at `maxHeight` (default `320`px) and never exceeds the space available after collision handling. Pass `maxHeight` to change the cap.
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import { ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuItem, ContextMenuLabel } from '@torch-ui/components'
|
|
242
|
+
|
|
243
|
+
function LongMenu() {
|
|
244
|
+
return (
|
|
245
|
+
<ContextMenu>
|
|
246
|
+
<ContextMenuTrigger asChild>
|
|
247
|
+
<div className="flex h-40 w-72 items-center justify-center rounded-md border border-dashed">
|
|
248
|
+
Right-click here
|
|
249
|
+
</div>
|
|
250
|
+
</ContextMenuTrigger>
|
|
251
|
+
{/* Cap the surface at 220px — the rest scrolls. */}
|
|
252
|
+
<ContextMenuContent maxHeight={220}>
|
|
253
|
+
<ContextMenuLabel>Jump to section</ContextMenuLabel>
|
|
254
|
+
{Array.from({ length: 20 }, (_, i) => (
|
|
255
|
+
<ContextMenuItem key={i}>Section {i + 1}</ContextMenuItem>
|
|
256
|
+
))}
|
|
257
|
+
</ContextMenuContent>
|
|
258
|
+
</ContextMenu>
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
236
263
|
## API Reference
|
|
237
264
|
|
|
238
265
|
### ContextMenu (Root)
|
|
@@ -264,6 +291,7 @@ The right-click zone. Wrap it around the element the menu should open from.
|
|
|
264
291
|
| `theme` | `'dark' \| 'light' \| 'default'` | - | Theme variant (applied as `data-theme`) |
|
|
265
292
|
| `className` | `string` | - | Additional CSS classes |
|
|
266
293
|
| `collisionPadding` | `number` | `8` | Min distance kept from the viewport edge |
|
|
294
|
+
| `maxHeight` | `number` | `320` | Max height (px) of the surface before it scrolls. Capped at `min(maxHeight, available-height)` so the menu never overflows off-screen |
|
|
267
295
|
| `autoGroup` | `boolean` | `true` | Auto-wrap loose items in a Boxed group (see Behavior notes) |
|
|
268
296
|
|
|
269
297
|
### ContextMenuItem
|
|
@@ -353,6 +381,7 @@ interface ContextMenuContentProps {
|
|
|
353
381
|
theme?: 'dark' | 'light' | 'default'
|
|
354
382
|
className?: string
|
|
355
383
|
collisionPadding?: number // default 8
|
|
384
|
+
maxHeight?: number // default 320 — surface scrolls past this
|
|
356
385
|
autoGroup?: boolean // default true
|
|
357
386
|
}
|
|
358
387
|
|
|
@@ -403,6 +432,7 @@ export const ContextMenuRadioItem: React.ForwardRefExoticComponent<ContextMenuRa
|
|
|
403
432
|
- **Opens at the pointer**: the menu opens on right-click (`contextmenu`) at the exact cursor position, not anchored to a fixed trigger button.
|
|
404
433
|
- **Second right-click closes it**: the Root is made controlled and tracks `open` in context. The Trigger listens in the capture phase, and when the menu is already open it `preventDefault()` / `stopPropagation()` and closes — so a second right-click dismisses instead of re-anchoring (which Radix handles unreliably).
|
|
405
434
|
- **Auto-grouping**: by default (`autoGroup` on `ContextMenuContent`, default `true`) consecutive loose items (`ContextMenuItem`, `ContextMenuCheckboxItem`, `ContextMenuRadioItem`, and `ContextMenuSub`) are automatically wrapped in a `Boxed` `ContextMenuGroup`, so they render inside a boxed container like DropdownMenu even when you do not write a group. Labels and explicit groups act as boundaries and pass through unchanged. Set `autoGroup={false}` to render children verbatim.
|
|
435
|
+
- **Max height & scrolling**: the surface caps its height at `min(maxHeight, available-height)` (where `maxHeight` defaults to `320`px and `available-height` is the space Radix has after collision handling). A taller menu scrolls vertically instead of overflowing off-screen — items and groups keep their full height rather than squishing. Pass `maxHeight={N}` to change the cap.
|
|
406
436
|
- **Checkbox / radio keep the menu open**: `ContextMenuCheckboxItem` and `ContextMenuRadioItem` call `event.preventDefault()` inside `onSelect`, stopping Radix's default auto-close so users can toggle multiple options in one pass.
|
|
407
437
|
- **Open-only animation**: only the open (enter) state animates (`fade-in`). There is intentionally no exit animation — holding the old DOM node during close breaks close/reposition on a second right-click, so it is omitted to keep repositioning reliable.
|
|
408
438
|
- **Submenus and RTL**: nested `ContextMenuSub` / `ContextMenuSubTrigger` / `ContextMenuSubContent` are supported, and `dir="rtl"` on the Root mirrors the layout (including the submenu chevron).
|
|
@@ -148,7 +148,7 @@ render `DataViewsConfigPanel` yourself (example above) or extend the layout
|
|
|
148
148
|
| Saved View | `savedViews` / `activeSavedView` | Radio list + "Save a New View" button. |
|
|
149
149
|
| Table Columns | `config.tableColumns` | Green `Switch` per column toggles `visible`; rows are drag-reorderable (HTML5 DnD) and patch `order`. |
|
|
150
150
|
| Default Sort | `config.sortBy` | Single-choice radio; selecting sets `sortBy`. Direction stays on `config.sortOrder`. |
|
|
151
|
-
| Filters tab | `filterState` + `fields` | Renders `FilterPanel` restyled full-width/transparent. |
|
|
151
|
+
| Filters tab | `filterState` + `fields` | Renders `FilterPanel` restyled full-width/transparent. Categorical fields render as checkbox/radio lists, or a `SearchableSelect` dropdown when a field sets `filterVariant: "searchable-select"`. |
|
|
152
152
|
|
|
153
153
|
## Internal: PanelControls
|
|
154
154
|
|
|
@@ -173,8 +173,8 @@ Common changes and where to make them:
|
|
|
173
173
|
|---|---|
|
|
174
174
|
| Make Saved View work through `DataViewsLayout` | Add `savedViews` / `activeSavedView` / `onSavedViewChange` / `onSaveNewView` to `DataViewsLayoutProps`, hold them in layout state (or accept from the host), and forward them to `<DataViewsConfigPanel>` at its render site in `DataViewsLayout.tsx`. |
|
|
175
175
|
| Add a new Config section | Add a new block inside the Config. tab in `DataViewsConfigPanel.tsx`, backed by a `config.*` field so `onConfigChange` persists it. |
|
|
176
|
-
| Restyle a radio/toggle | Edit `PanelControls.tsx`. Keep
|
|
177
|
-
| Change the dark chrome | The root forces `data-theme="dark"` and uses hardcoded hex (`#1C1D1F`, `#252729`, `#005ECC`, `#626467`, `#0AC713`). These are intentional Figma values, not tokens. |
|
|
176
|
+
| Restyle a radio/toggle | Edit the radio ring in `DataViewRadio.tsx` (the `RadioRow` in `PanelControls.tsx` just wraps it) or the switch in `PanelControls.tsx`. Keep the hardcoded hex matching the Figma spec; do not swap in the shared `Radio`/`Label` (they impose theming/layout that fights the dark panel — this was deliberate). |
|
|
177
|
+
| Change the dark chrome | The root forces `data-theme="dark"` and uses hardcoded hex (`#1C1D1F`, `#252729`, `#005ECC`, `#0075FF`, `#626467`, `#0AC713`). These are intentional Figma values, not tokens — the radio/checkbox rings hardcode them (`#626467` border, `rgba(255,255,255,0.05)` fill, `#0075FF` selected) so the panel always renders dark regardless of host `data-theme`. |
|
|
178
178
|
|
|
179
179
|
After any change to the panel docs or component, update this file and rebuild
|
|
180
180
|
the MCP server (`cd mcp && pnpm build`) so the docs the server serves stay in
|
|
@@ -176,7 +176,11 @@ Inbox auto-detects `isRead`, `isStarred`, `hasAttachment`, `priority`. Override
|
|
|
176
176
|
| `type` | `FieldType` | Renderer key (see below). Auto-inferred if omitted. |
|
|
177
177
|
| `visible` | `boolean` | Show in cells. Default `true`. |
|
|
178
178
|
| `order` | `number` | Display order. |
|
|
179
|
-
| `filterable` | `boolean` | Surface this field in the filter panel. |
|
|
179
|
+
| `filterable` | `boolean` | Surface this field in the filter panel. The control adapts to the field `type`: categorical fields render checkboxes/radios (or a searchable dropdown via `filterVariant`), numeric fields a range slider, and **date / date-format fields a From + To pair of Glare `DatePicker`s** (two single-date pickers bounding the range). Set `false` to explicitly exclude a field the panel would otherwise auto-detect (e.g. an `id` or `name` with few unique values). |
|
|
180
|
+
| `filterLabel` | `string` | Override the label shown above this field's filter (defaults to `label`). |
|
|
181
|
+
| `filterMode` | `"single" \| "multi"` | Categorical selection mode. `"multi"` (default) renders checkboxes; `"single"` renders radios. |
|
|
182
|
+
| `filterVariant` | `"checkbox" \| "searchable-select"` | Categorical control style. `"checkbox"` (default) is the inline checkbox/radio list; `"searchable-select"` renders a single-select `SearchableSelect` dropdown — useful when a field has many options. Implies single-select. |
|
|
183
|
+
| `filterOptions` | `string[] \| { label: string; value: string }[]` | Explicit option list for the categorical filter (otherwise options are collected from the data). |
|
|
180
184
|
| `variants` | `Record<string, BadgeVariant>` | For `enum-badge`: per-value color map. |
|
|
181
185
|
| `currency` | `string \| CurrencyOptions` | For `currency`: ISO code or `{ symbol, locale, decimals, code }`. |
|
|
182
186
|
| `thresholds` | `[number, number]` | For `progress-bar`: warning/ok thresholds. |
|
|
@@ -188,6 +192,8 @@ Inbox auto-detects `isRead`, `isStarred`, `hasAttachment`, `priority`. Override
|
|
|
188
192
|
|
|
189
193
|
`text` · `number` · `date` · `date-format` · `boolean` · `currency` · `number-format` · `enum-badge` · `badge-array` · `progress-bar` · `star-rating` · `icon-text` · `two-line` · `avatar` · `link` · `image` · `hidden`
|
|
190
194
|
|
|
195
|
+
> **`hidden` vs `filterable: false`** — use `type: "hidden"` to drop a field from the UI **entirely** (no column, no column-toggle in the config panel, no filter) while it stays in the data for row identity — e.g. an `id` you key rows by but never want shown. Use `filterable: false` to keep a field as a **column** but remove only its **filter**.
|
|
196
|
+
|
|
191
197
|
### `BadgeVariant`
|
|
192
198
|
|
|
193
199
|
`green` · `greenLight` · `cocktailGreen` · `yellow` · `redOrange` · `redLight` · `rose` · `purple` · `bluePurple` · `blue` · `navy` · `gray` · `highlight`
|
|
@@ -268,7 +274,7 @@ function CustomScreen({ data, fields }: Props) {
|
|
|
268
274
|
|
|
269
275
|
## Accessibility
|
|
270
276
|
|
|
271
|
-
- The view-switcher uses `
|
|
277
|
+
- The view-switcher uses [`TabSwitch`](./tab-switch.md) — a segmented `role="tablist"` control (each view a `role="tab"` button, full keyboard support via Tab/Enter/Space). Installing DataViews pulls in `TabSwitch` automatically.
|
|
272
278
|
- Tree rows expose `role="treeitem"` with `aria-expanded` and `aria-selected`.
|
|
273
279
|
- Filter checkboxes carry labels and `htmlFor` linkage.
|
|
274
280
|
- Settings panel buttons have `aria-pressed` for sort direction.
|
|
@@ -284,4 +290,5 @@ The component uses only `*-presentation-*` design tokens. Wrap with `ThemeProvid
|
|
|
284
290
|
- [`KanbanView`](./kanban-view.md) — standalone kanban
|
|
285
291
|
- [`InboxView`](./inbox-view.md) — standalone inbox
|
|
286
292
|
- [`TreeView`](./tree-view.md) — standalone tree
|
|
293
|
+
- [`TabSwitch`](./tab-switch.md) — the segmented view-switcher in the header (reusable on its own)
|
|
287
294
|
- [How-to: Render a backend response with DataViews](../how-to/data-views-from-backend-response.md) — recipes by data shape.
|
|
@@ -299,6 +299,32 @@ function Example() {
|
|
|
299
299
|
}
|
|
300
300
|
```
|
|
301
301
|
|
|
302
|
+
### Long Menu (max height + scroll)
|
|
303
|
+
|
|
304
|
+
Tall menus scroll instead of overflowing off-screen. The surface caps at `maxHeight` (default `320`px) and never exceeds the space available after collision handling. Pass `maxHeight` to change the cap.
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel } from '@torch-ui/components'
|
|
308
|
+
import { Button } from '@torch-ui/components'
|
|
309
|
+
|
|
310
|
+
function LongMenu() {
|
|
311
|
+
return (
|
|
312
|
+
<DropdownMenu>
|
|
313
|
+
<DropdownMenuTrigger asChild>
|
|
314
|
+
<Button variant="BorderStyle">Jump to section</Button>
|
|
315
|
+
</DropdownMenuTrigger>
|
|
316
|
+
{/* Cap the surface at 240px — the rest scrolls. */}
|
|
317
|
+
<DropdownMenuContent align="start" maxHeight={240}>
|
|
318
|
+
<DropdownMenuLabel>Sections</DropdownMenuLabel>
|
|
319
|
+
{Array.from({ length: 20 }, (_, i) => (
|
|
320
|
+
<DropdownMenuItem key={i}>Section {i + 1}</DropdownMenuItem>
|
|
321
|
+
))}
|
|
322
|
+
</DropdownMenuContent>
|
|
323
|
+
</DropdownMenu>
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
302
328
|
## API Reference
|
|
303
329
|
|
|
304
330
|
### DropdownMenu (Root)
|
|
@@ -326,6 +352,7 @@ function Example() {
|
|
|
326
352
|
| `sideOffset` | `number` | `4` | Distance from trigger |
|
|
327
353
|
| `collisionPadding` | `number` | `8` | Gap kept from viewport edges when flipping/shifting |
|
|
328
354
|
| `align` | `'start' \| 'center' \| 'end'` | `'center'` | Alignment (inherited from Radix) |
|
|
355
|
+
| `maxHeight` | `number` | `320` | Max height (px) of the surface before it scrolls. Capped at `min(maxHeight, available-height)` so the menu never overflows off-screen |
|
|
329
356
|
| `autoGroup` | `boolean` | `true` | Auto-wrap loose items in boxed groups |
|
|
330
357
|
|
|
331
358
|
### DropdownMenuItem
|
|
@@ -426,6 +453,7 @@ interface DropdownMenuContentProps {
|
|
|
426
453
|
sideOffset?: number
|
|
427
454
|
collisionPadding?: number
|
|
428
455
|
align?: 'start' | 'center' | 'end'
|
|
456
|
+
maxHeight?: number // default 320 — surface scrolls past this
|
|
429
457
|
autoGroup?: boolean
|
|
430
458
|
}
|
|
431
459
|
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: HeaderBar
|
|
3
|
+
description: Variant-driven page/form header chip pairing a colored emphasis pill with a plain title.
|
|
4
|
+
component: true
|
|
5
|
+
group: Layout
|
|
6
|
+
keywords: [header, headerbar, page-header, form-header, title, badge, label, layout]
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# HeaderBar
|
|
10
|
+
|
|
11
|
+
A presentational header chip used at the top of a form, page, or drawer to communicate the current record context — for example "NEW sales invoice", "EDIT sales invoice", or "ORDER de-344". It pairs a colored emphasis pill (the `label`) with a plain `title`, and the `variant` controls both the pill color and which side the pill sits on. The surface is always a fixed dark container, and the component is non-interactive.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx torch-glare@latest add HeaderBar
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Imports
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import HeaderBar from '@/components/HeaderBar'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { HeaderBar } from '@/components/HeaderBar'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Both the default export and the named export resolve to the same component. The website convention is the default import.
|
|
30
|
+
|
|
31
|
+
## Basic Usage
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import HeaderBar from '@/components/HeaderBar'
|
|
35
|
+
|
|
36
|
+
export function BasicHeaderBar() {
|
|
37
|
+
return (
|
|
38
|
+
<HeaderBar
|
|
39
|
+
variant="new"
|
|
40
|
+
label="New"
|
|
41
|
+
title="sales iNVOICE"
|
|
42
|
+
/>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Examples
|
|
48
|
+
|
|
49
|
+
### New Invoice Header
|
|
50
|
+
|
|
51
|
+
The `new` variant renders a blue emphasis pill on the left followed by the plain title on the right. Use it on create screens.
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import HeaderBar from '@/components/HeaderBar'
|
|
55
|
+
|
|
56
|
+
export function NewInvoiceHeader() {
|
|
57
|
+
return (
|
|
58
|
+
<HeaderBar
|
|
59
|
+
variant="new"
|
|
60
|
+
label="New"
|
|
61
|
+
title="sales iNVOICE"
|
|
62
|
+
/>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Edit Header
|
|
68
|
+
|
|
69
|
+
The `edit` variant shares the exact same layout as `new` (pill left, title right) but uses an orange emphasis pill. Use it on edit screens.
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import HeaderBar from '@/components/HeaderBar'
|
|
73
|
+
|
|
74
|
+
export function EditInvoiceHeader() {
|
|
75
|
+
return (
|
|
76
|
+
<HeaderBar
|
|
77
|
+
variant="edit"
|
|
78
|
+
label="edit"
|
|
79
|
+
title="sales iNVOICE"
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Detail Header
|
|
86
|
+
|
|
87
|
+
The `detail` variant swaps the positions: the plain title renders on the left and the colored (white-alpha) pill renders on the right. Use it for read-only record context such as an order reference.
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import HeaderBar from '@/components/HeaderBar'
|
|
91
|
+
|
|
92
|
+
export function OrderDetailHeader() {
|
|
93
|
+
// Renders as: SALES INVOICE [ de-344 ]
|
|
94
|
+
// plain title on the LEFT, badge on the RIGHT
|
|
95
|
+
return (
|
|
96
|
+
<HeaderBar
|
|
97
|
+
variant="detail"
|
|
98
|
+
label="de-344"
|
|
99
|
+
title="sales iNVOICE"
|
|
100
|
+
/>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Themed
|
|
106
|
+
|
|
107
|
+
HeaderBar accepts a `theme` prop applied via `data-theme`. The surface is always a dark chip, so theming is most useful for keeping the component consistent with the surrounding `data-theme` scope.
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
import HeaderBar from '@/components/HeaderBar'
|
|
111
|
+
|
|
112
|
+
export function ThemedHeaderBars() {
|
|
113
|
+
return (
|
|
114
|
+
<div className="flex flex-col gap-4">
|
|
115
|
+
<HeaderBar variant="new" label="New" title="sales iNVOICE" theme="dark" />
|
|
116
|
+
<HeaderBar variant="edit" label="edit" title="sales iNVOICE" theme="light" />
|
|
117
|
+
<HeaderBar variant="detail" label="de-344" title="sales iNVOICE" theme="default" />
|
|
118
|
+
</div>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## API Reference
|
|
124
|
+
|
|
125
|
+
### HeaderBar Props
|
|
126
|
+
|
|
127
|
+
| Prop | Type | Default | Description |
|
|
128
|
+
|------|------|---------|-------------|
|
|
129
|
+
| variant | `'new' \| 'edit' \| 'detail'` | `'new'` | Controls both the pill color and which side the pill sits on |
|
|
130
|
+
| label | `string` | — (required) | Text rendered inside the colored emphasis pill |
|
|
131
|
+
| title | `string` | — (required) | Plain text rendered alongside the pill |
|
|
132
|
+
| theme | `Themes` | — | Theme variant applied via `data-theme` (`'dark' \| 'light' \| 'default'`) |
|
|
133
|
+
| className | `string` | — | Additional CSS classes merged onto the root element |
|
|
134
|
+
|
|
135
|
+
All standard `HTMLAttributes<HTMLDivElement>` (for example `id`, `aria-*`, `data-*`, `style`, `onClick`) pass through to the root `div`.
|
|
136
|
+
|
|
137
|
+
## Variants
|
|
138
|
+
|
|
139
|
+
| Variant | Pill color | Pill text | Layout (left → right) |
|
|
140
|
+
|---------|-----------|-----------|------------------------|
|
|
141
|
+
| `new` | `bg-blue-sparkle-alpha-50` | `text-blue-sparkle-200` | pill (`label`) → title |
|
|
142
|
+
| `edit` | `bg-orange-alpha-50` | `text-orange-200` | pill (`label`) → title |
|
|
143
|
+
| `detail` | `bg-white-alpha-30` | `text-white-00` | title → pill (`label`) — positions swapped |
|
|
144
|
+
|
|
145
|
+
## Styling
|
|
146
|
+
|
|
147
|
+
- **Fixed dark container**: `rounded-[14px]`, `border-black-600`, `bg-black-1000`, `p-1.5`, with a double soft shadow. The surface is always dark regardless of theme.
|
|
148
|
+
- **Layout**: the root is `inline-flex`, so the chip hugs its content rather than stretching to fill its parent.
|
|
149
|
+
- **Typography**: 28px, weight 510, uppercase, SF Pro with the `cv05` stylistic set. Both `label` and `title` render uppercase.
|
|
150
|
+
- **Emphasis pill**: the colored badge background and text color are driven entirely by `variant` (see the Variants table). For `detail`, the pill also moves to the right side.
|
|
151
|
+
|
|
152
|
+
## TypeScript Types
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { HTMLAttributes } from 'react'
|
|
156
|
+
import { Themes } from '@/utils/types'
|
|
157
|
+
|
|
158
|
+
interface HeaderBarProps extends HTMLAttributes<HTMLDivElement> {
|
|
159
|
+
variant?: 'new' | 'edit' | 'detail'
|
|
160
|
+
label: string
|
|
161
|
+
title: string
|
|
162
|
+
theme?: Themes
|
|
163
|
+
className?: string
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Accessibility
|
|
168
|
+
|
|
169
|
+
- HeaderBar is purely presentational — it has no interactive behavior and is intended to label the surrounding content visually.
|
|
170
|
+
- Because the text is rendered uppercase via styling (not the source string), screen readers receive the original casing of `label` and `title`.
|
|
171
|
+
- Pass any `aria-*` attributes through the standard prop spread when the chip needs an explicit accessible role or label in its context.
|
|
172
|
+
- HeaderBar does not render an HTML heading element. When this chip represents the page or section heading, ensure proper heading semantics exist in the surrounding layout (for example an `<h1>` / `<h2>` for the page) so document structure remains navigable.
|
|
173
|
+
|
|
174
|
+
## Best Practices
|
|
175
|
+
|
|
176
|
+
1. **Match the variant to the screen mode**: use `new` for create screens, `edit` for edit screens, and `detail` for read-only record context.
|
|
177
|
+
2. **Keep `label` short**: it is the emphasis pill, so a concise token (a mode word like "New" / "edit" or a record reference like "de-344") reads best — text renders UPPERCASE automatically.
|
|
178
|
+
3. **Use `title` for the record type**: the plain side should name the entity (for example "sales invoice", "Order"), not duplicate the label.
|
|
179
|
+
4. **Expect the detail swap**: for `variant="detail"` the pill moves to the right and the title to the left — author content with that ordering in mind.
|
|
180
|
+
5. **Don't rely on it for interactivity**: HeaderBar is a label, not a control; place buttons or actions in a separate toolbar.
|
|
181
|
+
6. **Let it hug its content**: the chip is `inline-flex`; avoid forcing it to full width and keep it at the top of the form, page, or drawer it describes.
|