Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(lab): MobileTokenizer — touch Tokenizer prototype (#6640)

Xinzi Zhoue983e37f13ee
diff --git a/apps/storybook/stories/MobileTokenizer.stories.tsx b/apps/storybook/stories/MobileTokenizer.stories.tsx
new file mode 100644
index 0000000000..684c27bb14
--- /dev/null
+++ b/apps/storybook/stories/MobileTokenizer.stories.tsx
@@ -0,0 +1,41 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+/**
+ * @file MobileTokenizer.stories.tsx
+ * @input Uses MobileTokenizer (Lab) with the sketch's Design/Eng data
+ * @output Storybook try-it story at 390px: field -> manage -> add sheets
+ * @position Lab story; stack layer 1 try-it surface
+ */
+import {useState} from 'react';
+import type {Meta, StoryObj} from '@storybook/react';
+import type {SearchableItem, SearchSource} from '@astryxdesign/core/Typeahead';
+import {MobileTokenizer} from '@astryxdesign/lab';
+
+const tags: SearchableItem[] = [
+ {id: 'design', label: 'Design'},
+ {id: 'eng', label: 'Eng'},
+ {id: 'engineer', label: 'Engineer'},
+ {id: 'energizer', label: 'Energizer'},
+];
+const source: SearchSource = {
+ search: (q: string) => tags.filter(t => t.label.toLowerCase().includes(q.toLowerCase())),
+ bootstrap: () => tags,
+};
+
+const meta: Meta<typeof MobileTokenizer> = {
+ title: 'Lab/MobileTokenizer',
+ component: MobileTokenizer,
+};
+export default meta;
+type Story = StoryObj<typeof MobileTokenizer>;
+
+export const TouchFlow: Story = {
+ render: () => {
+ const [value, setValue] = useState<SearchableItem[]>([tags[0], tags[1]]);
+ return (
+ <div style={{width: 350}}>
+ <MobileTokenizer label="Tags" searchSource={source} value={value} onChange={items => setValue(items)} placeholder="Add tags" debounceMs={0} />
+ </div>
+ );
+ },
+ name: 'Touch flow (sketch: manage + stacked add, bottom filter)',
+};
diff --git a/internal/shadcn-registry/routes.lock.json b/internal/shadcn-registry/routes.lock.json
index a067a343ad..a847e190a3 100644
--- a/internal/shadcn-registry/routes.lock.json
+++ b/internal/shadcn-registry/routes.lock.json
@@ -571,6 +571,11 @@
"path": "components/lab/log-stream",
"aliases": []
},
+ {
+ "name": "component-lab-mobile-tokenizer",
+ "path": "components/lab/mobile-tokenizer",
+ "aliases": []
+ },
{
"name": "component-lab-radial-chart",
"path": "components/lab/radial-chart",
diff --git a/packages/lab/src/MobileTokenizer/MobileTokenizer.doc.mjs b/packages/lab/src/MobileTokenizer/MobileTokenizer.doc.mjs
new file mode 100644
index 0000000000..37fcb09fd9
--- /dev/null
+++ b/packages/lab/src/MobileTokenizer/MobileTokenizer.doc.mjs
@@ -0,0 +1,32 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
+export const docs = {
+ name: 'MobileTokenizer',
+ displayName: 'Mobile Tokenizer',
+ group: 'MobileTokenizer',
+ category: 'Form Controls',
+ keywords: ['tokenizer', 'mobile', 'touch', 'bottom sheet', 'tags', 'chips'],
+ props: [
+ {name: 'label', type: 'string', description: 'Field label and sheet heading.', required: true},
+ {name: 'searchSource', type: 'SearchSource<T>', description: 'Core Typeahead search source (search + bootstrap).', required: true},
+ {name: 'value', type: 'T[]', description: 'Selected items (Core SearchableItem).', required: true},
+ {name: 'onChange', type: '(items: T[], change: MobileTokenizerChange<T>) => void', description: 'Mirrors Core Tokenizer: single-item add/create/remove, or reorder.', required: true},
+ {name: 'placeholder', type: 'string', description: 'Trigger text when nothing is selected.'},
+ {name: 'hasCreate', type: 'boolean', description: 'Offer Create "<query>" for unmatched free text.', default: 'false'},
+ {name: 'maxEntries', type: 'number', description: 'Cap selections; add rows disable at the cap.'},
+ {name: 'renderItem', type: '(item: T) => ReactNode', description: 'Custom add-sheet row content.'},
+ ],
+ usage: {
+ description:
+ 'Lab prototype for trying the touch Tokenizer flow: tap the field to open the manage sheet (review, remove, Clear all, Add item), tap Add item for the stacked search sheet (results above, filter + Done in the bottom row above the keyboard, tap +/check to toggle immediately).',
+ bestPractices: [
+ {guidance: true, description: 'Try this in Lab/canary to validate the flow; graduate via Core Tokenizer presentation="adaptive" when it ships.'},
+ {guidance: false, description: 'Do not ship stable product on this Lab API; it has no theming, i18n, or spec contract yet.'},
+ ],
+ anatomy: [
+ {name: 'Trigger field', required: true, description: 'Button showing tokens as a summary, with chevron.'},
+ {name: 'Manage sheet', required: true, description: 'Selected rows with remove, Clear all footer, Add item.'},
+ {name: 'Add sheet', required: true, description: 'Stacked sheet: result rows with +/check toggles, bottom filter + Done row.'},
+ ],
+ },
+};
diff --git a/packages/lab/src/MobileTokenizer/MobileTokenizer.test.tsx b/packages/lab/src/MobileTokenizer/MobileTokenizer.test.tsx
new file mode 100644
index 0000000000..381865f7eb
--- /dev/null
+++ b/packages/lab/src/MobileTokenizer/MobileTokenizer.test.tsx
@@ -0,0 +1,72 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+/**
+ * @file MobileTokenizer.test.tsx
+ * @input Uses vitest, @testing-library/react, MobileTokenizer
+ * @output Lab tests for the sketch flow: field -> manage -> add (bottom
+ * filter) -> Done -> manage
+ * @position Lab tests; validates MobileTokenizer.tsx
+ */
+import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';
+import {render, screen, fireEvent, waitFor} from '@testing-library/react';
+import {useState} from 'react';
+import {MobileTokenizer, type MobileTokenizerChange} from './MobileTokenizer';
+import type {SearchSource, SearchableItem} from '@astryxdesign/core/Typeahead';
+
+const ITEMS: SearchableItem[] = [
+ {id: 'design', label: 'Design'},
+ {id: 'eng', label: 'Eng'},
+ {id: 'engineer', label: 'Engineer'},
+ {id: 'energizer', label: 'Energizer'},
+];
+const source: SearchSource<SearchableItem> = {
+ search: q => ITEMS.filter(i => i.label.toLowerCase().includes(q.toLowerCase())),
+ bootstrap: () => ITEMS,
+};
+
+function Harness({spy}: {spy?: (i: SearchableItem[], c: MobileTokenizerChange<SearchableItem>) => void}) {
+ const [value, setValue] = useState<SearchableItem[]>([ITEMS[0], ITEMS[1]]);
+ return (
+ <MobileTokenizer label="Tags" searchSource={source} value={value} debounceMs={0} placeholder="Add tags"
+ onChange={(items, change) => { setValue(items); spy?.(items, change); }} />
+ );
+}
+
+beforeEach(() => {
+ HTMLDialogElement.prototype.showModal = vi.fn(function (this: HTMLDialogElement) { this.setAttribute('open', ''); });
+ HTMLDialogElement.prototype.show = vi.fn(function (this: HTMLDialogElement) { this.setAttribute('open', ''); });
+ HTMLDialogElement.prototype.close = vi.fn(function (this: HTMLDialogElement) { this.removeAttribute('open'); });
+ if (!Element.prototype.setPointerCapture) { Element.prototype.setPointerCapture = vi.fn(); Element.prototype.releasePointerCapture = vi.fn(); }
+ vi.stubGlobal('matchMedia', vi.fn().mockReturnValue({matches: false, media: '', onchange: null, addEventListener: vi.fn(), removeEventListener: vi.fn(), addListener: vi.fn(), removeListener: vi.fn(), dispatchEvent: vi.fn()}));
+ vi.stubGlobal('requestAnimationFrame', vi.fn((cb: FrameRequestCallback) => { cb(0); return 1; }));
+});
+afterEach(() => vi.unstubAllGlobals());
+
+describe('MobileTokenizer (Lab, sketch flow)', () => {
+ it('field -> manage -> add: filter at bottom, tap + adds, Done returns', async () => {
+ const spy = vi.fn();
+ render(<Harness spy={spy} />);
+ const trigger = screen.getByRole('button', {name: /Tags/});
+ expect(trigger.getAttribute('aria-haspopup')).toBe('dialog');
+ fireEvent.click(trigger);
+ expect((await screen.findByTestId('mobile-tokenizer-manage-list')).textContent).toContain('Design');
+ fireEvent.click(screen.getByRole('button', {name: 'Add item'}));
+ const search = await screen.findByLabelText('Search Tags');
+ fireEvent.change(search, {target: {value: 'E'}});
+ const engineer = await screen.findByRole('option', {name: /Engineer/});
+ fireEvent.click(engineer);
+ expect(spy).toHaveBeenCalledWith([ITEMS[0], ITEMS[1], ITEMS[2]], expect.objectContaining({type: 'add'}));
+ await waitFor(() => expect(screen.getByRole('option', {name: /Engineer/}).getAttribute('aria-selected')).toBe('true'));
+ fireEvent.click(screen.getByRole('button', {name: 'Done'}));
+ expect((await screen.findByTestId('mobile-tokenizer-manage-list')).textContent).toContain('Engineer');
+ });
+ it('manage sheet removes and clears', async () => {
+ const spy = vi.fn();
+ render(<Harness spy={spy} />);
+ fireEvent.click(screen.getByRole('button', {name: /Tags/}));
+ await screen.findByTestId('mobile-tokenizer-manage-list');
+ fireEvent.click(screen.getByRole('button', {name: 'Remove Eng'}));
+ expect(spy).toHaveBeenCalledWith([ITEMS[0]], expect.objectContaining({type: 'remove'}));
+ fireEvent.click(screen.getByRole('button', {name: 'Clear all'}));
+ expect(spy).toHaveBeenLastCalledWith([], expect.objectContaining({type: 'remove'}));
+ });
+});
diff --git a/packages/lab/src/MobileTokenizer/MobileTokenizer.tsx b/packages/lab/src/MobileTokenizer/MobileTokenizer.tsx
new file mode 100644
index 0000000000..cfec4323e1
--- /dev/null
+++ b/packages/lab/src/MobileTokenizer/MobileTokenizer.tsx
@@ -0,0 +1,474 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @file MobileTokenizer.tsx
+ * @input Uses public @astryxdesign/core components only (BottomSheet,
+ * BottomSheetSwitcher, Button, Field, Heading, Icon, IconButton, Text,
+ * TextInput, Token)
+ * @output Exports MobileTokenizer — Lab prototype of the touch Tokenizer
+ * flow (stacked manage + add sheets)
+ * @position Lab (canary) stack layer 1: validates the design before the
+ * Core promotion (Tokenizer presentation="bottom-sheet") stacked after it.
+ *
+ * API mirrors Core Tokenizer (label/searchSource/value/onChange/change,
+ * hasCreate, maxEntries) so graduation is an import swap. Differences from
+ * Core are the Lab deltas: the filter is a bordered TextInput (Core's
+ * PanelSearchInput is not exported), strings are literals (no i18n keys),
+ * and there is no theming/spec contract yet.
+ */
+
+import {
+ useEffect,
+ useId,
+ useMemo,
+ useRef,
+ useState,
+ type ReactNode,
+} from 'react';
+import * as stylex from '@stylexjs/stylex';
+import type {BaseProps} from '@astryxdesign/core';
+import {BottomSheet} from '@astryxdesign/core/BottomSheet';
+import {BottomSheetSwitcher} from '@astryxdesign/core/BottomSheet';
+import {Button} from '@astryxdesign/core/Button';
+import {Divider} from '@astryxdesign/core/Divider';
+import {Field} from '@astryxdesign/core/Field';
+import {Icon} from '@astryxdesign/core/Icon';
+import {IconButton} from '@astryxdesign/core/IconButton';
+import {Text} from '@astryxdesign/core/Text';
+import {TextInput} from '@astryxdesign/core/TextInput';
+import {Token} from '@astryxdesign/core/Token';
+import type {
+ SearchableItem,
+ SearchSource,
+} from '@astryxdesign/core/Typeahead';
+import {
+ colorVars,
+ radiusVars,
+ spacingVars,
+} from '@astryxdesign/core/theme/tokens.stylex';
+
+export type MobileTokenizerChange<T extends SearchableItem> =
+ | {item: T; type: 'add'}
+ | {item: T; type: 'create'}
+ | {item: T; type: 'remove'}
+ | {type: 'reorder'};
+
+export interface MobileTokenizerProps<T extends SearchableItem> extends Omit<
+ BaseProps<HTMLDivElement>,
+ 'onChange'
+> {
+ label: string;
+ searchSource: SearchSource<T>;
+ value: T[];
+ onChange: (items: T[], change: MobileTokenizerChange<T>) => void;
+ renderItem?: (item: T) => ReactNode;
+ placeholder?: string;
+ description?: string;
+ isOptional?: boolean;
+ isDisabled?: boolean;
+ hasCreate?: boolean;
+ maxEntries?: number;
+ maxMenuItems?: number;
+ minQueryLength?: number;
+ debounceMs?: number;
+ emptySearchResultsText?: string;
+ onChangeQuery?: (query: string) => void;
+}
+
+type SheetId = 'manage' | 'add';
+const CREATABLE_ID_PREFIX = '__xds_create__';
+
+const styles = stylex.create({
+ trigger: {
+ display: 'flex',
+ flexWrap: 'wrap',
+ alignItems: 'center',
+ gap: spacingVars['--spacing-1'],
+ width: '100%',
+ minHeight: 44,
+ paddingBlock: spacingVars['--spacing-1'],
+ paddingInline: spacingVars['--spacing-2'],
+ borderWidth: 1,
+ borderStyle: 'solid',
+ borderColor: colorVars['--color-border'],
+ borderRadius: radiusVars['--radius-element'],
+ backgroundColor: 'transparent',
+ textAlign: 'start',
+ cursor: {
+ default: 'pointer',
+ ':is(:disabled,[aria-disabled="true"])': 'default',
+ },
+ },
+ triggerPlaceholder: {
+ color: colorVars['--color-text-secondary'],
+ },
+ chevron: {
+ marginInlineStart: 'auto',
+ display: 'flex',
+ flexShrink: 0,
+ },
+ sheetBody: {
+ display: 'flex',
+ flexDirection: 'column',
+ height: '100%',
+ minHeight: 0,
+ paddingInline: spacingVars['--spacing-3'],
+ paddingBlockStart: spacingVars['--spacing-3'],
+ paddingBlockEnd: spacingVars['--spacing-3'],
+ },
+ // Sketch has no visible sheet headings — manage is rows + a top-end
+ // close affordance only. The sheet's accessible name still comes from
+ // BottomSheet's `label`, not a rendered heading.
+ closeRow: {
+ display: 'flex',
+ justifyContent: 'flex-end',
+ marginBlockEnd: spacingVars['--spacing-2'],
+ },
+ list: {
+ display: 'flex',
+ flexDirection: 'column',
+ overflowY: 'auto',
+ minHeight: 0,
+ },
+ row: {
+ display: 'flex',
+ alignItems: 'center',
+ gap: spacingVars['--spacing-2'],
+ width: '100%',
+ minHeight: 44,
+ paddingBlock: spacingVars['--spacing-2'],
+ paddingInline: spacingVars['--spacing-1'],
+ textAlign: 'start',
+ backgroundColor: 'transparent',
+ borderWidth: 0,
+ color: colorVars['--color-text-primary'],
+ cursor: {
+ default: 'pointer',
+ ':is(:disabled,[aria-disabled="true"])': 'default',
+ },
+ },
+ rowDisabled: {opacity: 0.5},
+ rowLabel: {flexGrow: 1, minWidth: 0},
+ toggleMark: {
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ width: 28,
+ height: 28,
+ flexShrink: 0,
+ borderRadius: radiusVars['--radius-full'],
+ borderWidth: 1,
+ borderStyle: 'solid',
+ borderColor: colorVars['--color-border'],
+ fontSize: 18,
+ lineHeight: 1,
+ },
+ footer: {
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ gap: spacingVars['--spacing-2'],
+ paddingBlockStart: spacingVars['--spacing-3'],
+ marginTop: 'auto',
+ },
+ filterRow: {
+ display: 'flex',
+ alignItems: 'flex-end',
+ gap: spacingVars['--spacing-2'],
+ paddingBlockStart: spacingVars['--spacing-2'],
+ marginTop: 'auto',
+ },
+ // TextInput renders Field (block, shrink-to-fit); xstyle lands on that
+ // root, so it must flex — the filter takes all row space minus Done+gap.
+ filterInput: {flexGrow: 1, flexShrink: 1, flexBasis: 0, minWidth: 0},
+ empty: {paddingBlock: spacingVars['--spacing-4']},
+});
+
+export function MobileTokenizer<T extends SearchableItem>({
+ label,
+ searchSource,
+ value,
+ onChange,
+ renderItem,
+ placeholder,
+ description,
+ isOptional,
+ isDisabled = false,
+ hasCreate = false,
+ maxEntries,
+ maxMenuItems = 10,
+ minQueryLength = 1,
+ debounceMs = 150,
+ emptySearchResultsText = 'No results found',
+ onChangeQuery,
+ xstyle,
+}: MobileTokenizerProps<T>) {
+ const triggerId = useId();
+ const [activeSheet, setActiveSheet] = useState<SheetId | null>(null);
+ const selectedIds = useMemo(() => new Set(value.map(v => v.id)), [value]);
+ const isAtMax = maxEntries != null && value.length >= maxEntries;
+
+ const handleAdd = (item: T) => {
+ if (isAtMax || selectedIds.has(item.id)) {
+ return;
+ }
+ if (
+ hasCreate &&
+ typeof item.id === 'string' &&
+ item.id.startsWith(CREATABLE_ID_PREFIX)
+ ) {
+ const created = item.id.slice(CREATABLE_ID_PREFIX.length);
+ if (selectedIds.has(created)) {
+ return;
+ }
+ const real = {id: created, label: created} as T;
+ onChange([...value, real], {item: real, type: 'create'});
+ return;
+ }
+ onChange([...value, item], {item, type: 'add'});
+ };
+ const handleRemove = (item: T) =>
+ onChange(
+ value.filter(v => v.id !== item.id),
+ {item, type: 'remove'},
+ );
+ const handleClearAll = () => {
+ if (value.length > 0) {
+ onChange([], {item: value[value.length - 1], type: 'remove'});
+ }
+ };
+
+ // ---- add-sheet search ----
+ const [query, setQuery] = useState('');
+ const [results, setResults] = useState<T[]>([]);
+ const [isSearching, setIsSearching] = useState(false);
+ const seqRef = useRef(0);
+ const isAddOpen = activeSheet === 'add';
+ useEffect(() => {
+ if (!isAddOpen) {
+ return;
+ }
+ const seq = ++seqRef.current;
+ const run = async () => {
+ setIsSearching(true);
+ try {
+ const trimmed = query.trim();
+ let items: T[];
+ if (trimmed === '') {
+ items = searchSource.bootstrap
+ ? await searchSource.bootstrap()
+ : await searchSource.search('');
+ } else if (trimmed.length < minQueryLength) {
+ items = [];
+ } else {
+ items = await searchSource.search(query);
+ }
+ if (seqRef.current === seq) {
+ setResults(items.slice(0, maxMenuItems));
+ }
+ } finally {
+ if (seqRef.current === seq) {
+ setIsSearching(false);
+ }
+ }
+ };
+ if (debounceMs > 0) {
+ const timer = setTimeout(() => {
+ void run();
+ }, debounceMs);
+ return () => clearTimeout(timer);
+ }
+ void run();
+ }, [isAddOpen, query, searchSource, minQueryLength, maxMenuItems, debounceMs]);
+
+ const createItem = useMemo<T | null>(() => {
+ const trimmed = query.trim();
+ if (!hasCreate || trimmed === '' || isAtMax) {
+ return null;
+ }
+ if (
+ selectedIds.has(trimmed) ||
+ results.some(r => r.label.toLowerCase() === trimmed.toLowerCase())
+ ) {
+ return null;
+ }
+ return {
+ id: `${CREATABLE_ID_PREFIX}${trimmed}`,
+ label: `Create "${trimmed}"`,
+ } as unknown as T;
+ }, [hasCreate, query, results, selectedIds, isAtMax]);
+
+ return (
+ <Field
+ label={label}
+ description={description}
+ isOptional={isOptional}
+ isDisabled={isDisabled}
+ inputID={triggerId}
+ xstyle={xstyle}>
+ <button
+ type="button"
+ id={triggerId}
+ aria-haspopup="dialog"
+ aria-expanded={activeSheet != null}
+ aria-label={label}
+ disabled={isDisabled}
+ onClick={() => setActiveSheet('manage')}
+ {...stylex.props(styles.trigger)}>
+ {value.length > 0 ? (
+ value.map(item => (
+ <Token key={item.id} label={item.label} isDisabled={isDisabled} />
+ ))
+ ) : (
+ <span {...stylex.props(styles.triggerPlaceholder)}>
+ {placeholder ?? ''}
+ </span>
+ )}
+ <span {...stylex.props(styles.chevron)} aria-hidden="true">
+ <Icon icon="chevronDown" size="sm" color="secondary" />
+ </span>
+ </button>
+
+ {!isDisabled && (
+ <BottomSheetSwitcher
+ activeSheet={activeSheet}
+ onActiveSheetChange={id => setActiveSheet(id as SheetId | null)}>
+ <BottomSheet sheetId="manage" label={label} height="hug">
+ <div {...stylex.props(styles.sheetBody)}>
+ <div {...stylex.props(styles.closeRow)}>
+ <IconButton
+ label="Close"
+ icon={<Icon icon="close" />}
+ variant="ghost"
+ size="sm"
+ onClick={() => setActiveSheet(null)}
+ />
+ </div>
+ <div {...stylex.props(styles.list)} data-testid="mobile-tokenizer-manage-list">
+ {value.length === 0 ? (
+ <Text type="supporting" color="secondary" xstyle={styles.empty}>
+ No items yet
+ </Text>
+ ) : (
+ value.map((item, i) => (
+ <div key={item.id}>
+ {i > 0 && <Divider />}
+ <div {...stylex.props(styles.row)}>
+ <span {...stylex.props(styles.rowLabel)}>
+ <Text type="body">{item.label}</Text>
+ </span>
+ <IconButton
+ label={`Remove ${item.label}`}
+ icon={<Icon icon="close" />}
+ variant="ghost"
+ size="sm"
+ onClick={() => handleRemove(item)}
+ />
+ </div>
+ </div>
+ ))
+ )}
+ </div>
+ <div {...stylex.props(styles.footer)}>
+ <Button
+ label="Clear all"
+ variant="ghost"
+ isDisabled={value.length === 0}
+ onClick={handleClearAll}
+ />
+ <Button
+ label="Add item"
+ variant="primary"
+ isDisabled={isAtMax}
+ onClick={() => setActiveSheet('add')}
+ />
+ </div>
+ </div>
+ </BottomSheet>
+
+ <BottomSheet sheetId="add" label="Add item" height="tall">
+ <div {...stylex.props(styles.sheetBody)}>
+ <div
+ {...stylex.props(styles.list)}
+ role="listbox"
+ aria-multiselectable="true"
+ aria-label={label}
+ data-testid="mobile-tokenizer-add-list">
+ {createItem != null && (
+ <button
+ type="button"
+ role="option"
+ aria-selected={false}
+ {...stylex.props(styles.row)}
+ onClick={() => {
+ handleAdd(createItem);
+ setQuery('');
+ }}>
+ <span {...stylex.props(styles.rowLabel)}>
+ <Text type="body">{createItem.label}</Text>
+ </span>
+ <span {...stylex.props(styles.toggleMark)} aria-hidden="true">+</span>
+ </button>
+ )}
+ {!isSearching && results.length === 0 && createItem == null ? (
+ <Text type="supporting" color="secondary" xstyle={styles.empty}>
+ {emptySearchResultsText}
+ </Text>
+ ) : (
+ results.map(item => {
+ const isSelected = selectedIds.has(item.id);
+ const rowDisabled = !isSelected && isAtMax;
+ return (
+ <button
+ key={item.id}
+ type="button"
+ role="option"
+ aria-selected={isSelected}
+ aria-disabled={rowDisabled || undefined}
+ {...stylex.props(styles.row, rowDisabled && styles.rowDisabled)}
+ onClick={() =>
+ isSelected ? handleRemove(item) : handleAdd(item)
+ }>
+ <span {...stylex.props(styles.rowLabel)}>
+ {renderItem ? renderItem(item) : <Text type="body">{item.label}</Text>}
+ </span>
+ <span {...stylex.props(styles.toggleMark)} aria-hidden="true">
+ {isSelected ? <Icon icon="check" size="sm" /> : '+'}
+ </span>
+ </button>
+ );
+ })
+ )}
+ </div>
+ <Divider />
+ <div {...stylex.props(styles.filterRow)}>
+ <TextInput
+ label={`Search ${label}`}
+ isLabelHidden
+ placeholder="Search..."
+ value={query}
+ width="100%"
+ hasClear
+ onChange={next => {
+ setQuery(next);
+ onChangeQuery?.(next);
+ }}
+ xstyle={styles.filterInput}
+ />
+ <Button
+ label="Done"
+ variant="primary"
+ onClick={() => setActiveSheet('manage')}
+ />
+ </div>
+ </div>
+ </BottomSheet>
+ </BottomSheetSwitcher>
+ )}
+ </Field>
+ );
+}
+
+MobileTokenizer.displayName = 'MobileTokenizer';
diff --git a/packages/lab/src/MobileTokenizer/index.ts b/packages/lab/src/MobileTokenizer/index.ts
new file mode 100644
index 0000000000..5fe4999040
--- /dev/null
+++ b/packages/lab/src/MobileTokenizer/index.ts
@@ -0,0 +1,16 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @file index.ts
+ * @input MobileTokenizer component
+ * @output Public MobileTokenizer entry point for @astryxdesign/lab
+ * @position Component barrel; re-exported by /packages/lab/src/index.ts
+ */
+
+export {MobileTokenizer} from './MobileTokenizer';
+export type {
+ MobileTokenizerProps,
+ MobileTokenizerChange,
+} from './MobileTokenizer';
diff --git a/packages/lab/src/index.ts b/packages/lab/src/index.ts
index 7c8e7cfbb1..0a0b58f47a 100644
--- a/packages/lab/src/index.ts
+++ b/packages/lab/src/index.ts
@@ -253,6 +253,15 @@ export {
type LogStreamLevel,
} from './LogStream';
+// MobileTokenizer — Lab prototype (stack layer 1) of the touch Tokenizer
+// flow: summary trigger + stacked manage/add BottomSheets. Graduates to
+// Core Tokenizer presentation="bottom-sheet" (stack layer 2).
+export {
+ MobileTokenizer,
+ type MobileTokenizerProps,
+ type MobileTokenizerChange,
+} from './MobileTokenizer';
+
// RichTextEditor (RFC facebook/astryx#3899) has graduated out of @astryxdesign/lab
// into its own canary-only package, @astryxdesign/richtext, so it can be canaried
// independently (e.g. into EPS/Nest). Import it from there: