Skip to content

Commit a017ec1

Browse files
committed
feat(core): Tokenizer touch sheet behind experimental.presentation
Ports the Lab MobileTokenizer touch flow into Tokenizer as the `bottom-sheet` value of the experimental `presentation` option (`experimental={{presentation: 'popover' | 'bottom-sheet' | 'adaptive'}}`, spec:AST-017 FR21). `adaptive` resolves through useAdaptivePresentation, the policy Selector, MultiSelector and DropdownMenu share. Omitting `experimental` keeps the inline combobox unchanged. The sheet is one standalone BottomSheet driven by `isOpen`: the shared PanelSearchInput on top (grown to the 44px rows through a new internal fieldXstyle), checkbox rows that keep their place while the sheet is open and regroup selected-first on the next open, 50-row progressive rendering, a Create row with a trailing Add action under hasCreate, and a footer with a confirmed Clear all and Done. The list is busy from open and from each query change until the search settles. Selection stays in Tokenizer so the add, remove and create paths and their announcements are the inline field's own. The trigger is the control: base props and `ref` reach it, its accessible description lists the selected tokens, and a field that becomes disabled while the sheet is open closes it and takes focus back. Props with no sheet surface warn once in development. The surface loads with React.lazy and renders nothing during hydration, so a Tokenizer that does not opt in does not carry it. The sheet's parts expose no theming targets while the option is experimental. Also: @astryx.tokenizer.* catalog keys for the sheet's strings, doc.mjs prop and examples, a `Tokenizer — Adaptive presentation` block template (and its ShadCN route), three Core/Tokenizer stories, tests for the resolution and the ported flow, an [experimental] core changeset and a [docs] cli changeset, and the deletion of the spec's implementation-gap notes.
1 parent 0beb6ba commit a017ec1

14 files changed

Lines changed: 2139 additions & 48 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/cli': patch
3+
---
4+
5+
[docs] A new Tokenizer block, `Tokenizer — Adaptive presentation`, shows the experimental `experimental={{presentation: 'adaptive'}}` option: a searchable bottom sheet of checkbox rows on compact touch screens, the inline field with its popover everywhere else. (#7977)
6+
7+
@imdreamrunner
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[experimental] Tokenizer gains a touch surface behind `experimental={{presentation: 'bottom-sheet' | 'adaptive'}}`. `bottom-sheet` replaces the inline combobox with a trigger that shows the selected tokens and opens one tall modal sheet: a search row on top, full-width checkbox rows that keep their place while the sheet is open and regroup selected-first on the next open, 50-row progressive rendering for long lists, a `Create "…"` row with a trailing Add action under `hasCreate`, and a footer with a confirmed Clear all and Done. `adaptive` uses the sheet on compact coarse-pointer screens and the popover otherwise, resolved the same way Selector resolves it. The sheet surface loads on demand, so a Tokenizer that does not opt in does not carry it. The trigger describes its selected tokens to assistive technology, and in development the field warns once about props that have no surface in the sheet presentation (`renderItem`, `renderToken`, `endContent`, `hasClear`, `hasEntriesOnFocus`, `menuWidth`, `tokenOverflowBehavior`, `hasAutoFocus`). New `@astryx.tokenizer.*` catalog keys for the sheet's strings; the sheet's parts expose no theming targets while the option is experimental. Anything inside Tokenizer's `experimental` prop may change or be removed in a patch release; omitting it keeps the stable behavior.
6+
7+
@imdreamrunner

‎apps/sandbox/scripts/next-export-routes.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@
667667
"/templates/TokenIcon/",
668668
"/templates/TokenRemovable/",
669669
"/templates/TokenShowcase/",
670+
"/templates/TokenizerAdaptive/",
670671
"/templates/TokenizerClear/",
671672
"/templates/TokenizerCreatable/",
672673
"/templates/TokenizerEndContent/",

‎apps/storybook/stories/Tokenizer.stories.tsx‎

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ const meta: Meta<typeof Tokenizer> = {
7070
},
7171
},
7272
decorators: [
73+
// A 400px column where there is room that shrinks with the viewport, so
74+
// the stories read the same on a phone-sized canvas.
7375
Story => (
74-
<div style={{width: 400}}>
76+
<div style={{display: 'grid', gridTemplateColumns: 'minmax(0, 400px)'}}>
7577
<Story />
7678
</div>
7779
),
@@ -549,3 +551,136 @@ export const RtlEndLane: Story = {
549551
},
550552
name: 'RTL end lane (token + clear)',
551553
};
554+
555+
// A long, searchable dataset for the sheet presentation: enough entries to
556+
// see the 50-row batches of progressive rendering.
557+
const sheetTags: SearchableItem[] = Array.from({length: 1000}, (_, index) => {
558+
const number = index + 1;
559+
return {
560+
id: `tag-${number}`,
561+
label:
562+
number === 1
563+
? 'Design'
564+
: number === 2
565+
? 'Eng'
566+
: `Tag ${String(number).padStart(2, '0')}`,
567+
};
568+
});
569+
570+
const sheetTagSource: SearchSource = {
571+
search: (query: string) =>
572+
sheetTags.filter(tag =>
573+
tag.label.toLowerCase().includes(query.toLowerCase()),
574+
),
575+
bootstrap: () => sheetTags,
576+
};
577+
578+
/**
579+
* The experimental touch surface, forced on every device so it is reviewable
580+
* on a laptop: `experimental.presentation="bottom-sheet"`. The trigger shows
581+
* the selected tokens; tapping it opens one tall sheet with the search row on
582+
* top, checkbox rows that keep their place while the sheet is open, a Create
583+
* row for typed text, and a confirmed Clear all beside Done.
584+
*/
585+
export const ExperimentalBottomSheet: Story = {
586+
render: args => {
587+
const [value, setValue] = useState<SearchableItem[]>([
588+
sheetTags[0],
589+
sheetTags[1],
590+
]);
591+
return (
592+
<Tokenizer
593+
{...args}
594+
searchSource={sheetTagSource}
595+
value={value}
596+
onChange={items => setValue(items)}
597+
hasCreate
598+
maxMenuItems={1000}
599+
debounceMs={0}
600+
experimental={{presentation: 'bottom-sheet'}}
601+
/>
602+
);
603+
},
604+
args: {
605+
label: 'Tags',
606+
placeholder: 'Add tags',
607+
},
608+
name: 'Experimental: bottom sheet',
609+
};
610+
611+
/**
612+
* `experimental.presentation="adaptive"`: the sheet on a compact
613+
* coarse-pointer screen (narrow the viewport and emulate touch), otherwise the
614+
* inline combobox — the same resolution Selector uses.
615+
*/
616+
export const ExperimentalAdaptive: Story = {
617+
render: args => {
618+
const [value, setValue] = useState<SearchableItem[]>([sheetTags[0]]);
619+
return (
620+
<Tokenizer
621+
{...args}
622+
searchSource={sheetTagSource}
623+
value={value}
624+
onChange={items => setValue(items)}
625+
maxMenuItems={1000}
626+
debounceMs={0}
627+
experimental={{presentation: 'adaptive'}}
628+
/>
629+
);
630+
},
631+
args: {
632+
label: 'Tags',
633+
placeholder: 'Add tags',
634+
},
635+
name: 'Experimental: adaptive',
636+
};
637+
638+
/**
639+
* Disabled and at-limit states of the sheet presentation: the disabled
640+
* trigger stays focusable and does not open; at `maxEntries` the sheet's
641+
* unchecked rows are inert while checked rows still toggle.
642+
*/
643+
export const ExperimentalBottomSheetStates: Story = {
644+
render: args => {
645+
const [value, setValue] = useState<SearchableItem[]>([
646+
sheetTags[0],
647+
sheetTags[1],
648+
]);
649+
return (
650+
<div style={{display: 'grid', gap: 16}}>
651+
<Tokenizer
652+
{...args}
653+
label="Disabled"
654+
searchSource={sheetTagSource}
655+
value={[sheetTags[0], sheetTags[1]]}
656+
onChange={() => {}}
657+
isDisabled
658+
experimental={{presentation: 'bottom-sheet'}}
659+
/>
660+
<Tokenizer
661+
{...args}
662+
label="Disabled and empty"
663+
searchSource={sheetTagSource}
664+
value={[]}
665+
onChange={() => {}}
666+
isDisabled
667+
experimental={{presentation: 'bottom-sheet'}}
668+
/>
669+
<Tokenizer
670+
{...args}
671+
label="At the limit"
672+
searchSource={sheetTagSource}
673+
value={value}
674+
onChange={items => setValue(items)}
675+
maxEntries={2}
676+
debounceMs={0}
677+
experimental={{presentation: 'bottom-sheet'}}
678+
/>
679+
</div>
680+
);
681+
},
682+
args: {
683+
placeholder: 'Add tags',
684+
},
685+
name: 'Experimental: bottom sheet states',
686+
};

‎internal/shadcn-registry/routes.lock.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,6 +3444,11 @@
34443444
"path": "examples/token/removable",
34453445
"aliases": []
34463446
},
3447+
{
3448+
"name": "example-tokenizer-adaptive-presentation",
3449+
"path": "examples/tokenizer/adaptive-presentation",
3450+
"aliases": []
3451+
},
34473452
{
34483453
"name": "example-tokenizer-clear",
34493454
"path": "examples/tokenizer/clear",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4+
export const doc = {
5+
type: 'block',
6+
exampleFor: 'Tokenizer',
7+
name: 'Tokenizer \u2014 Adaptive presentation',
8+
displayName: 'Tokenizer \u2014 Adaptive presentation',
9+
description:
10+
'Tokenizer with the experimental presentation option set to adaptive: a searchable bottom sheet on compact touch screens, the inline field with its popover everywhere else. Experimental; it may change or be removed in a patch release.',
11+
isReady: true,
12+
aspectRatio: 16 / 9,
13+
componentsUsed: ['Tokenizer', 'Layout', 'Text'],
14+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
'use client';
4+
5+
import {useState} from 'react';
6+
import {Tokenizer} from '@astryxdesign/core/Tokenizer';
7+
import {Stack} from '@astryxdesign/core/Layout';
8+
import {Text} from '@astryxdesign/core/Text';
9+
import type {SearchableItem, SearchSource} from '@astryxdesign/core/Typeahead';
10+
11+
const tags: SearchableItem[] = [
12+
{id: 'design', label: 'Design'},
13+
{id: 'engineering', label: 'Engineering'},
14+
{id: 'research', label: 'Research'},
15+
{id: 'marketing', label: 'Marketing'},
16+
{id: 'sales', label: 'Sales'},
17+
{id: 'support', label: 'Support'},
18+
{id: 'legal', label: 'Legal'},
19+
{id: 'finance', label: 'Finance'},
20+
];
21+
22+
const tagSource: SearchSource = {
23+
search: (query: string) =>
24+
tags.filter(t => t.label.toLowerCase().includes(query.toLowerCase())),
25+
bootstrap: () => tags,
26+
};
27+
28+
export default function TokenizerAdaptive() {
29+
const [value, setValue] = useState<SearchableItem[]>([tags[0]]);
30+
31+
return (
32+
<div style={{display: 'grid', gridTemplateColumns: 'minmax(0, 400px)'}}>
33+
<Stack direction="vertical" gap={2}>
34+
<Text type="supporting" color="secondary">
35+
A sheet on compact touch screens, the inline popover otherwise
36+
</Text>
37+
<Tokenizer
38+
label="Tags"
39+
placeholder="Add tags..."
40+
searchSource={tagSource}
41+
value={value}
42+
onChange={items => setValue(items)}
43+
hasCreate
44+
experimental={{presentation: 'adaptive'}}
45+
/>
46+
</Stack>
47+
</div>
48+
);
49+
}

‎packages/core/locales/en.json‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,54 @@
15991599
"defaultMessage": "Removed {label}",
16001600
"description": "Polite screen-reader announcement after a token is removed from a Tokenizer, by its × button or by Backspace. Live-region text, never shown on screen; `{label}` is the token's visible text."
16011601
},
1602+
"@astryx.tokenizer.search": {
1603+
"defaultMessage": "Search {label}",
1604+
"description": "Accessible name of the search field at the top of a Tokenizer's bottom sheet (the touch presentation). `{label}` is the field's own label, e.g. `Search Tags`. Not shown on screen."
1605+
},
1606+
"@astryx.tokenizer.searchPlaceholder": {
1607+
"defaultMessage": "Search…",
1608+
"description": "Placeholder inside the search field at the top of a Tokenizer's bottom sheet, shown while the query is empty. Single word plus ellipsis."
1609+
},
1610+
"@astryx.tokenizer.noItems": {
1611+
"defaultMessage": "No items available",
1612+
"description": "Title of the empty state inside a Tokenizer's bottom sheet when the search source has nothing to choose from and no query is typed. Neutral tone (not error-y)."
1613+
},
1614+
"@astryx.tokenizer.noItemsDescription": {
1615+
"defaultMessage": "There are no items to choose from.",
1616+
"description": "Supporting sentence under the `No items available` empty-state title inside a Tokenizer's bottom sheet."
1617+
},
1618+
"@astryx.tokenizer.noResultsDescription": {
1619+
"defaultMessage": "Try a different search.",
1620+
"description": "Supporting sentence under the no-results empty-state title inside a Tokenizer's bottom sheet, suggesting the person change the query."
1621+
},
1622+
"@astryx.tokenizer.create": {
1623+
"defaultMessage": "Create \"{value}\"",
1624+
"description": "Label of the create row inside a Tokenizer's bottom sheet when `hasCreate` is set and the typed text matches no existing item. `{value}` is the typed text, e.g. `Create \"Marketing\"`."
1625+
},
1626+
"@astryx.tokenizer.add": {
1627+
"defaultMessage": "Add",
1628+
"description": "Visible label of the button at the end of the create row inside a Tokenizer's bottom sheet; pressing it adds the typed text as a new token. Imperative verb; short."
1629+
},
1630+
"@astryx.tokenizer.addValue": {
1631+
"defaultMessage": "Add {value}",
1632+
"description": "Screen-reader-only name of the create row's Add button inside a Tokenizer's bottom sheet. `{value}` is the typed text, e.g. `Add Marketing`."
1633+
},
1634+
"@astryx.tokenizer.done": {
1635+
"defaultMessage": "Done",
1636+
"description": "Label of the primary footer button inside a Tokenizer's bottom sheet; pressing it closes the sheet. Selections are already applied, so this is not a confirm."
1637+
},
1638+
"@astryx.tokenizer.clearAllTitle": {
1639+
"defaultMessage": "Clear all selected items?",
1640+
"description": "Title of the confirmation dialog shown when the person presses Clear all inside a Tokenizer's bottom sheet. A question."
1641+
},
1642+
"@astryx.tokenizer.clearAllDescription": {
1643+
"defaultMessage": "This removes all selected items from {label}.",
1644+
"description": "Body of the Clear all confirmation dialog inside a Tokenizer's bottom sheet. `{label}` is the field's own label, e.g. `This removes all selected items from Tags.`"
1645+
},
1646+
"@astryx.tokenizer.clearSelection": {
1647+
"defaultMessage": "Clear selection",
1648+
"description": "Label of the destructive action button in the Clear all confirmation dialog inside a Tokenizer's bottom sheet. Imperative verb phrase; confirms removing every token."
1649+
},
16021650
"@astryx.lightbox.imagePosition": {
16031651
"defaultMessage": "Image {index, number} of {total, number}",
16041652
"description": "Polite screen-reader announcement when a Lightbox moves to a media item that has no alt text. Live-region text, never shown on screen; `{index}` is 1-based, example: `Image 3 of 12`."

‎packages/core/src/Field/PanelSearchInput.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import {useCallback, useState, type Ref} from 'react';
4343
import * as stylex from '@stylexjs/stylex';
44+
import type {StyleXStyles} from '@stylexjs/stylex';
4445
import {Icon} from '../Icon';
4546
import {InputClearButton} from './InputClearButton';
4647
import {mergeProps} from '../utils';
@@ -177,6 +178,14 @@ export interface PanelSearchInputProps extends Omit<
177178
* handler of its own.
178179
*/
179180
onContainerKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
181+
182+
/**
183+
* Styles for the field box itself (the rounded row that draws the focus
184+
* ring), as opposed to `xstyle`, which lands on the outer gutter. A panel
185+
* whose rows are taller than a dropdown's — a touch sheet — uses it to grow
186+
* the field to the same height as its rows.
187+
*/
188+
fieldXstyle?: StyleXStyles;
180189
}
181190

182191
/**
@@ -199,6 +208,7 @@ export function PanelSearchInput({
199208
onFocus,
200209
onBlur,
201210
onContainerKeyDown,
211+
fieldXstyle,
202212
xstyle,
203213
className,
204214
style,
@@ -259,6 +269,7 @@ export function PanelSearchInput({
259269
{...stylex.props(
260270
styles.field,
261271
isKeyboardFocus && styles.fieldKeyboardFocus,
272+
fieldXstyle,
262273
)}>
263274
<Icon icon="search" size="sm" color="secondary" xstyle={styles.icon} />
264275
<input

0 commit comments

Comments
 (0)