Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tokenizer-experimental-bottom-sheet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[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, announcements made while the sheet is open reach assistive technology through a live region inside the sheet, with `experimental` passed the component also accepts a `Ref<HTMLInputElement | HTMLButtonElement>` because `ref` reaches the trigger in the sheet presentation (the exported `TokenizerProps` interface is unchanged), 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.

@imdreamrunner
140 changes: 140 additions & 0 deletions apps/storybook/stories/Tokenizer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,143 @@ export const CaretPlacement: Story = {
}
},
};
// A long, searchable dataset for the sheet presentation: enough entries to
// see the 50-row batches of progressive rendering.
const sheetTags: SearchableItem[] = Array.from({length: 1000}, (_, index) => {
const number = index + 1;
return {
id: `tag-${number}`,
label:
number === 1
? 'Design'
: number === 2
? 'Eng'
: `Tag ${String(number).padStart(2, '0')}`,
};
});

const sheetTagSource: SearchSource = {
search: (query: string) =>
sheetTags.filter(tag =>
tag.label.toLowerCase().includes(query.toLowerCase()),
),
bootstrap: () => sheetTags,
};

/**
* The experimental touch surface, forced on every device so it is reviewable
* on a laptop: `experimental.presentation="bottom-sheet"`. The trigger shows
* the selected tokens; tapping it opens one tall sheet with the search row on
* top, checkbox rows that keep their place while the sheet is open, a Create
* row for typed text, and a confirmed Clear all beside Done.
*/
export const ExperimentalBottomSheet: Story = {
render: args => {
const [value, setValue] = useState<SearchableItem[]>([
sheetTags[0],
sheetTags[1],
]);
return (
<Tokenizer
{...args}
searchSource={sheetTagSource}
value={value}
onChange={items => setValue(items)}
hasCreate
maxMenuItems={1000}
debounceMs={0}
experimental={{presentation: 'bottom-sheet'}}
/>
);
},
args: {
label: 'Tags',
placeholder: 'Add tags',
},
name: 'Experimental: bottom sheet',
};

/**
* `experimental.presentation="adaptive"`: the sheet on a compact
* coarse-pointer screen (narrow the viewport and emulate touch), otherwise the
* inline combobox — the same resolution Selector uses.
*/
export const ExperimentalAdaptive: Story = {
render: args => {
// Enough tokens to wrap the inline field's row on a phone, so the box
// the trigger keeps at the swap is the wrapped one (FR16, FR17).
const [value, setValue] = useState<SearchableItem[]>([
sheetTags[0],
sheetTags[1],
sheetTags[2],
sheetTags[3],
sheetTags[4],
]);
return (
<Tokenizer
{...args}
searchSource={sheetTagSource}
value={value}
onChange={items => setValue(items)}
maxMenuItems={1000}
debounceMs={0}
experimental={{presentation: 'adaptive'}}
/>
);
},
args: {
label: 'Tags',
placeholder: 'Add tags',
},
name: 'Experimental: adaptive',
};

/**
* Disabled and at-limit states of the sheet presentation: the disabled
* trigger stays focusable and does not open; at `maxEntries` the sheet's
* unchecked rows are inert while checked rows still toggle.
*/
export const ExperimentalBottomSheetStates: Story = {
render: args => {
const [value, setValue] = useState<SearchableItem[]>([
sheetTags[0],
sheetTags[1],
]);
return (
<div style={{display: 'grid', gap: 16}}>
<Tokenizer
{...args}
label="Disabled"
searchSource={sheetTagSource}
value={[sheetTags[0], sheetTags[1]]}
onChange={() => {}}
isDisabled
experimental={{presentation: 'bottom-sheet'}}
/>
<Tokenizer
{...args}
label="Disabled and empty"
searchSource={sheetTagSource}
value={[]}
onChange={() => {}}
isDisabled
experimental={{presentation: 'bottom-sheet'}}
/>
<Tokenizer
{...args}
label="At the limit"
searchSource={sheetTagSource}
value={value}
onChange={items => setValue(items)}
maxEntries={2}
debounceMs={0}
experimental={{presentation: 'bottom-sheet'}}
/>
</div>
);
},
args: {
placeholder: 'Add tags',
},
name: 'Experimental: bottom sheet states',
};
52 changes: 52 additions & 0 deletions packages/core/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,58 @@
"defaultMessage": "Removed {label}",
"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."
},
"@astryx.tokenizer.search": {
"defaultMessage": "Search {label}",
"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."
},
"@astryx.tokenizer.searchPlaceholder": {
"defaultMessage": "Search…",
"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."
},
"@astryx.tokenizer.noResultsDescription": {
"defaultMessage": "Try a different search.",
"description": "Supporting sentence under the no-results empty-state title inside a Tokenizer's bottom sheet, suggesting the person change the query."
},
"@astryx.tokenizer.create": {
"defaultMessage": "Create \"{value}\"",
"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\"`."
},
"@astryx.tokenizer.add": {
"defaultMessage": "Add",
"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."
},
"@astryx.tokenizer.addValue": {
"defaultMessage": "Add {value}",
"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`."
},
"@astryx.tokenizer.done": {
"defaultMessage": "Done",
"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."
},
"@astryx.tokenizer.clearAllTitle": {
"defaultMessage": "Clear all selected items?",
"description": "Title of the confirmation dialog shown when the person presses Clear all inside a Tokenizer's bottom sheet. A question."
},
"@astryx.tokenizer.clearAllDescription": {
"defaultMessage": "This removes all selected items from {label}.",
"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.`"
},
"@astryx.tokenizer.nothingToClear": {
"defaultMessage": "Nothing selected",
"description": "Tooltip on the disabled Clear all action in a Tokenizer's bottom sheet while no item is selected; keeps the action focusable and says why it does nothing."
},
"@astryx.tokenizer.allRemoved": {
"defaultMessage": "All items removed",
"description": "Polite screen-reader announcement after a confirmed Clear all in a Tokenizer's bottom sheet has removed every selected item. Live-region text, never shown on screen."
},
"@astryx.tokenizer.selectedCount": {
"defaultMessage": "{count, number} selected",
"description": "Screen-reader-only lead-in of the description on a Tokenizer's bottom-sheet trigger (the touch presentation), followed by the selected token labels. `{count}` is how many tokens are selected, e.g. `2 selected`. Not shown on screen."
},
"@astryx.tokenizer.clearSelection": {
"defaultMessage": "Clear selection",
"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."
},
"@astryx.lightbox.imagePosition": {
"defaultMessage": "Image {index, number} of {total, number}",
"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`."
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/AlertDialog/AlertDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {BaseProps} from '../BaseProps';
import {mergeProps} from '../utils';
import {themeProps} from '../utils/themeProps';
import {useTranslator} from '../i18n';
import {useMediaQuery} from '../hooks';
import {useMediaQuery} from '../hooks/useMediaQuery';

const SMALL_SCREEN_QUERY = '(max-width: 640px)';

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/BottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ import {
easeVars,
spacingVars,
} from '../theme/tokens.stylex';
import {useDevWarning, useScrollLock} from '../hooks';
import {useDevWarning} from '../hooks/useDevWarning';
import {useScrollLock} from '../hooks/useScrollLock';
import {mergeProps} from '../utils';
import {LayerDepthProvider} from '../Layer/LayerDepthContext';
import {ModalAnnounceProvider} from '../hooks/ModalAnnounceProvider';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/BottomSheet/BottomSheetPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {BaseProps} from '../BaseProps';
import {useDevWarning, useMediaQuery} from '../hooks';
import {useDevWarning} from '../hooks/useDevWarning';
import {useMediaQuery} from '../hooks/useMediaQuery';
import {useScrollableArea} from '../hooks/useScrollableArea';
import {
borderVars,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/BottomSheet/BottomSheetSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import {
import * as stylex from '@stylexjs/stylex';
import type {BaseProps} from '../BaseProps';
import type {DialogPurpose} from '../Dialog';
import {useScrollLock} from '../hooks';
import {useScrollLock} from '../hooks/useScrollLock';
import {useFocusTrapEscapeCompatibilitySignal} from '../hooks/useFocusTrap';
import {dispatchLayerEscapeKeyDown} from '../Layer/layerStack';
import {useLayerDismissal} from '../Layer/useLayerDismissal';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {IconType} from '../Icon';
import {mergeProps} from '../utils';
import {useDevWarning} from '../hooks/useDevWarning';
import {FormLayoutContext} from '../FormLayout/FormLayoutContext';
import {Text} from '../Text';
import {Text} from '../Text/Text';
import {VisuallyHidden} from '../VisuallyHidden';
import {themeProps} from '../utils/themeProps';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Field/FieldLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {Icon, renderIconSlot, type IconType} from '../Icon';
import {Tooltip} from '../Tooltip';
import {useTranslator} from '../i18n';
import {themeProps} from '../utils/themeProps';
import {useInputContainer} from '../hooks';
import {useInputContainer} from '../hooks/useInputContainer';
import {FormLayoutContext} from '../FormLayout/FormLayoutContext';

const styles = stylex.create({
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/Field/PanelSearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import {useCallback, useState, type Ref} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {StyleXStyles} from '@stylexjs/stylex';
import {Icon} from '../Icon';
import {InputClearButton} from './InputClearButton';
import {mergeProps} from '../utils';
Expand Down Expand Up @@ -177,6 +178,14 @@ export interface PanelSearchInputProps extends Omit<
* handler of its own.
*/
onContainerKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;

/**
* Styles for the field box itself (the rounded row that draws the focus
* ring), as opposed to `xstyle`, which lands on the outer gutter. A panel
* whose rows are taller than a dropdown's — a touch sheet — uses it to grow
* the field to the same height as its rows.
*/
fieldXstyle?: StyleXStyles;
}

/**
Expand All @@ -199,6 +208,7 @@ export function PanelSearchInput({
onFocus,
onBlur,
onContainerKeyDown,
fieldXstyle,
xstyle,
className,
style,
Expand Down Expand Up @@ -258,6 +268,7 @@ export function PanelSearchInput({
{...stylex.props(
styles.field,
isKeyboardFocus && styles.fieldKeyboardFocus,
fieldXstyle,
)}>
<Icon icon="search" size="sm" color="secondary" xstyle={styles.icon} />
<input
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/Tokenizer/Tokenizer.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ export const docs = {
type: 'CSSProperties',
description: 'Inline styles for the visual control box.',
},
{
name: 'experimental',
type: "{presentation?: 'popover' | 'bottom-sheet' | 'adaptive'}",
stability: 'experimental',
description:
"Experimental options: anything in this object may change or be removed in a patch release, and omitting it keeps the stable behavior. presentation (default 'popover') chooses how the field presents its choices. popover is the inline combobox with its anchored suggestion menu. bottom-sheet replaces it with a trigger showing the selected tokens that opens one tall modal sheet: a search row on top, full-width checkbox rows that keep their place while the sheet is open, a Create row with hasCreate, and a footer with a confirmed Clear all and Done. adaptive uses the bottom sheet on compact touch screens and the popover otherwise, resolved the same way Selector resolves it. In the sheet presentation the trigger is the control (ref, id, aria-* and data-* reach it; with experimental passed, ref also accepts a Ref<HTMLInputElement | HTMLButtonElement> — an input-only ref still type-checks against that wider type, but with adaptive or bottom-sheet it receives the trigger button at runtime, so type the ref for both elements; the exported TokenizerProps interface is unchanged), and renderItem, renderToken, endContent, hasClear, hasEntriesOnFocus, menuWidth, tokenOverflowBehavior and hasAutoFocus have no surface to act on; the field warns once in development when they are passed. For example: <Tokenizer label=\"Tags\" searchSource={tagSource} value={tags} onChange={setTags} hasCreate experimental={{presentation: 'adaptive'}} />.",
},
],
theming: {
targets: [
Expand Down Expand Up @@ -628,6 +635,13 @@ export const docsZh = {
type: 'CSSProperties',
description: '可视控件框的内联样式。',
},
{
name: 'experimental',
type: "{presentation?: 'popover' | 'bottom-sheet' | 'adaptive'}",
stability: 'experimental',
description:
"实验性选项:此对象中的任何内容都可能在补丁版本中更改或移除;省略它即保持稳定行为。presentation(默认 'popover')决定字段如何呈现选项:popover 为内联组合框及其锚定建议菜单;bottom-sheet 改为一个显示已选标记的触发按钮,点按后打开一个高的模态底部面板——顶部为搜索行,下方为整行复选框行(面板打开期间位置保持不变),hasCreate 时有「创建」行,底部为需确认的「全部清除」和「完成」;adaptive 在紧凑触摸屏上使用底部面板,其他情况使用 popover,解析方式与 Selector 相同。在底部面板呈现中,触发按钮即为控件(ref、id、aria-* 和 data-* 都作用于它;传入 experimental 后,ref 也接受 Ref<HTMLInputElement | HTMLButtonElement>——仅为输入框类型的 ref 在这个更宽的类型下仍能通过类型检查,但在 adaptive 或 bottom-sheet 下运行时收到的是触发按钮,因此请为两种元素声明 ref 的类型;导出的 TokenizerProps 接口不变);renderItem、renderToken、endContent、hasClear、hasEntriesOnFocus、menuWidth、tokenOverflowBehavior 和 hasAutoFocus 没有作用对象,传入时开发模式下会警告一次。例如:<Tokenizer label=\"标签\" searchSource={tagSource} value={tags} onChange={setTags} hasCreate experimental={{presentation: 'adaptive'}} />。",
},
],
theming: {
targets: [
Expand Down Expand Up @@ -825,5 +839,7 @@ export const docsDense = {
'Icon at input start, before tokens. Icon name, SVG component, or ReactNode.',
endContent: 'Content at input row end. For buttons, counts, controls.',
handleRef: 'Imperative handle for focus() and blur() control.',
experimental:
"Experimental; may change in a patch. presentation: 'popover' (default, inline combobox) | 'bottom-sheet' (trigger + one searchable modal sheet of checkbox rows) | 'adaptive' (sheet on compact touch, else popover).",
},
};
Loading
Loading