Skip to content

Commit d4e546e

Browse files
thinkclayclaude
andcommitted
feat(list-toolbar): a tabs slot, so a screen's own partition attaches to its toolbar
The SCF prototype's list screens put the partition — Open / Closed, Recommended / All — as folder tabs on the top edge of the search row, so the tabs and the toolbar read as one panel. Ours drew the same folder tabs as a strip floating 20px above the toolbar on four screens. `tabs` / `activeTab` / `onTabChange` on ListToolbar render the partition on the toolbar's top edge; with tabs present the rows become the panel the tabs attach to — a hairline box whose top edge is the strip's own hairline, which the selected tab paints over in the panel colour. Labels take the prototype's "Label · n" form from `count`. Without tabs nothing changes for the eleven screens that use the toolbar today. The primary row is skipped when it would be empty, so a toolbar that is only tabs and a count still gets its panel. Section navigation stays the shell's strip (Scaffald/SaaS#968); this is for one list's own partition. Refs Scaffald/SaaS#984. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent bf5979e commit d4e546e

5 files changed

Lines changed: 163 additions & 50 deletions

File tree

‎src/__tests__/components/ScreenPrimitives.test.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ describe('ScreenHeader', () => {
5454
})
5555

5656
describe('ListToolbar', () => {
57+
it('renders a partition as tabs on its top edge and reports the choice', () => {
58+
const onTabChange = vi.fn()
59+
wrap(
60+
<ListToolbar
61+
tabs={[
62+
{ key: 'open', label: 'Open', count: 3 },
63+
{ key: 'closed', label: 'Closed', count: 12 },
64+
]}
65+
activeTab="open"
66+
onTabChange={onTabChange}
67+
resultCount={3}
68+
resultNoun="posting"
69+
/>,
70+
)
71+
expect(screen.getByText('Open · 3')).toBeTruthy()
72+
fireEvent.click(screen.getByText('Closed · 12'))
73+
expect(onTabChange).toHaveBeenCalledWith('closed')
74+
})
75+
5776
it('uses one "{n} {noun}" template, pluralising only when n is not 1', () => {
5877
const { unmount } = wrap(<ListToolbar resultCount={14} resultNoun="case" />)
5978
expect(screen.getByText('14 cases')).toBeTruthy()

‎src/components/ListToolbar/ListToolbar.tsx‎

Lines changed: 95 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ import { radius } from '../../tokens/borders'
3838
import { Text } from '../Typography/Text'
3939
import { Input } from '../Input'
4040
import { Popover, PopoverContent } from '../Popover'
41+
import { Tabs } from '../Tabs'
4142
import type { ListToolbarProps } from './ListToolbar.types'
4243

4344
export function ListToolbar({
45+
tabs,
46+
activeTab,
47+
onTabChange,
4448
searchValue,
4549
onSearchChange,
4650
searchPlaceholder = 'Search...',
@@ -121,57 +125,75 @@ export function ListToolbar({
121125
</Pressable>
122126
)
123127

124-
return (
125-
<View style={[styles.root, style]} testID={testID}>
126-
<View style={styles.primaryRow}>
127-
{showSearch ? (
128-
<View style={styles.searchCell}>
129-
{renderSearch ? (
130-
renderSearch()
131-
) : (
132-
<Input
133-
placeholder={searchPlaceholder}
134-
value={searchValue ?? ''}
135-
onChangeText={onSearchChange}
136-
iconStart={Search}
137-
iconEnd={hasSearch ? X : undefined}
138-
iconEndOnPress={hasSearch ? () => onSearchChange?.('') : undefined}
139-
iconEndAccessibilityLabel={hasSearch ? 'Clear search' : undefined}
140-
/>
141-
)}
142-
</View>
143-
) : null}
128+
const hasTabs = tabs != null && tabs.length > 0
129+
const showPrimaryRow =
130+
showSearch || filterContent != null || countLabel != null || actions != null
131+
132+
// With tabs, the rows become the panel the tabs attach to: a hairline box
133+
// whose top edge is the strip's own hairline (the selected tab paints over
134+
// it in the panel colour, so tab and panel read as one shape — the
135+
// prototype's list screens). Without tabs nothing changes.
136+
const body = (
137+
<View
138+
style={[
139+
styles.rows,
140+
hasTabs && [
141+
styles.panel,
142+
{ backgroundColor: colors.bg[theme].default, borderColor: colors.border[theme].default },
143+
],
144+
]}
145+
>
146+
{showPrimaryRow ? (
147+
<View style={styles.primaryRow}>
148+
{showSearch ? (
149+
<View style={styles.searchCell}>
150+
{renderSearch ? (
151+
renderSearch()
152+
) : (
153+
<Input
154+
placeholder={searchPlaceholder}
155+
value={searchValue ?? ''}
156+
onChangeText={onSearchChange}
157+
iconStart={Search}
158+
iconEnd={hasSearch ? X : undefined}
159+
iconEndOnPress={hasSearch ? () => onSearchChange?.('') : undefined}
160+
iconEndAccessibilityLabel={hasSearch ? 'Clear search' : undefined}
161+
/>
162+
)}
163+
</View>
164+
) : null}
144165

145-
{filterContent ? (
146-
<Popover
147-
placement="bottom"
148-
trigger="manual"
149-
open={open}
150-
onOpenChange={setOpen}
151-
offset={6}
152-
content={<PopoverContent>{filterContent}</PopoverContent>}
153-
>
154-
{trigger}
155-
</Popover>
156-
) : null}
166+
{filterContent ? (
167+
<Popover
168+
placement="bottom"
169+
trigger="manual"
170+
open={open}
171+
onOpenChange={setOpen}
172+
offset={6}
173+
content={<PopoverContent>{filterContent}</PopoverContent>}
174+
>
175+
{trigger}
176+
</Popover>
177+
) : null}
157178

158-
<View style={styles.spacer} />
179+
<View style={styles.spacer} />
159180

160-
{countLabel ? (
161-
<Text
162-
style={{
163-
fontSize: fontSize.md,
164-
color: colors.text[theme].tertiary,
165-
fontVariant: ['tabular-nums'],
166-
}}
167-
numberOfLines={1}
168-
>
169-
{countLabel}
170-
</Text>
171-
) : null}
181+
{countLabel ? (
182+
<Text
183+
style={{
184+
fontSize: fontSize.md,
185+
color: colors.text[theme].tertiary,
186+
fontVariant: ['tabular-nums'],
187+
}}
188+
numberOfLines={1}
189+
>
190+
{countLabel}
191+
</Text>
192+
) : null}
172193

173-
{actions ? <View style={styles.actions}>{actions}</View> : null}
174-
</View>
194+
{actions ? <View style={styles.actions}>{actions}</View> : null}
195+
</View>
196+
) : null}
175197

176198
{chips && chips.length > 0 ? (
177199
<View style={styles.chipStrip}>
@@ -240,13 +262,39 @@ export function ListToolbar({
240262
) : null}
241263
</View>
242264
)
265+
266+
return (
267+
<View style={[styles.root, style]} testID={testID}>
268+
{hasTabs ? (
269+
<Tabs type="folder" value={activeTab ?? ''} onValueChange={(key) => onTabChange?.(key)}>
270+
{tabs.map((tab) => (
271+
<Tabs.Item key={tab.key} value={tab.key}>
272+
<Tabs.Trigger>
273+
{tab.count == null ? tab.label : `${tab.label} · ${tab.count}`}
274+
</Tabs.Trigger>
275+
</Tabs.Item>
276+
))}
277+
</Tabs>
278+
) : null}
279+
{body}
280+
</View>
281+
)
243282
}
244283

245284
const styles = StyleSheet.create({
246285
root: {
247286
width: '100%',
287+
},
288+
rows: {
248289
gap: spacing[8],
249290
},
291+
panel: {
292+
borderWidth: 1,
293+
borderTopWidth: 0,
294+
borderBottomLeftRadius: radius.lg,
295+
borderBottomRightRadius: radius.lg,
296+
padding: spacing[12],
297+
},
250298
primaryRow: {
251299
flexDirection: 'row',
252300
alignItems: 'center',

‎src/components/ListToolbar/ListToolbar.types.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,26 @@ export interface ListToolbarFilterChip {
1212
onClear?: () => void
1313
}
1414

15+
/** One folder tab on the toolbar's top edge — a screen's own partition. */
16+
export interface ListToolbarTab {
17+
key: string
18+
label: string
19+
/** Rendered after the label as "Label · n", the prototype's form. */
20+
count?: number
21+
}
22+
1523
export interface ListToolbarProps {
24+
/**
25+
* The screen's own partition — Open / Closed, Recommended / All — as
26+
* folder tabs sitting on the toolbar's top edge, so the toolbar is the
27+
* panel the tabs attach to. Section navigation is the shell's strip, not
28+
* this; this is for a partition of one list.
29+
*/
30+
tabs?: ListToolbarTab[]
31+
/** Key of the active tab. */
32+
activeTab?: string
33+
onTabChange?: (key: string) => void
34+
1635
searchValue?: string
1736
onSearchChange?: (value: string) => void
1837
searchPlaceholder?: string
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { ListToolbar } from './ListToolbar'
2-
export type { ListToolbarProps, ListToolbarFilterChip } from './ListToolbar.types'
2+
export type { ListToolbarProps, ListToolbarFilterChip, ListToolbarTab } from './ListToolbar.types'

‎src/stories/components/ListToolbar/ListToolbar.stories.tsx‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ export const WithActiveFilterCount: Story = {
116116
filterContent={
117117
<View style={styles.flyout}>
118118
<Text style={{ color: colors.text[theme].secondary, fontSize: fontSize.sm }}>
119-
Stage, trade, distance, certifications, availability — one flyout per
120-
screen.
119+
Stage, trade, distance, certifications, availability — one flyout per screen.
121120
</Text>
122121
</View>
123122
}
@@ -240,3 +239,31 @@ const styles = StyleSheet.create({
240239
opacity: 0.7,
241240
},
242241
})
242+
243+
/**
244+
* A screen's own partition as folder tabs on the toolbar's top edge — the
245+
* toolbar is the panel the tabs attach to (#984). Section navigation is the
246+
* shell's strip; this is for one list's Open / Closed, Recommended / All.
247+
*/
248+
export const WithTabs: Story = {
249+
render: () => {
250+
const [tab, setTab] = useState('open')
251+
const [search, setSearch] = useState('')
252+
return (
253+
<ListToolbar
254+
tabs={[
255+
{ key: 'open', label: 'Open', count: 3 },
256+
{ key: 'paused', label: 'Paused', count: 1 },
257+
{ key: 'closed', label: 'Closed', count: 12 },
258+
]}
259+
activeTab={tab}
260+
onTabChange={setTab}
261+
searchValue={search}
262+
onSearchChange={setSearch}
263+
searchPlaceholder="Search your postings…"
264+
resultCount={tab === 'open' ? 3 : tab === 'paused' ? 1 : 12}
265+
resultNoun="posting"
266+
/>
267+
)
268+
},
269+
}

0 commit comments

Comments
 (0)