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/list-animated-layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[feat] `List` takes `animatedLayout`, the handle from `useAnimatedLayout({containerRef})`, and `ListItem` takes `itemKey`, the row's identity. With the handle, when rows are inserted, removed or reordered, an inserted row enters, a removed row (a swiped one with its action showing) collapses in place, and a row that crosses rows moving the other way rides above them with the surface color behind it, as an iOS table's opaque cell does. The rows after a change and the content after the list, up to the handle's container, glide to their new places. All of it runs on one shared motion and starts together, under every pointer; under Reduce Motion nothing travels. A row without an `itemKey` changes at once, and without the handle the whole list does.

@vjeux
152 changes: 152 additions & 0 deletions apps/storybook/stories/List.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {Icon} from '@astryxdesign/core/Icon';
import {Switch} from '@astryxdesign/core/Switch';
import {Heading, Text} from '@astryxdesign/core/Text';
import {VStack} from '@astryxdesign/core/Layout';
import {useAnimatedLayout} from '@astryxdesign/core/hooks';
import {rtlStyles} from '@astryxdesign/core/utils';
import {
Cog6ToothIcon,
Expand Down Expand Up @@ -762,3 +763,154 @@ export const HeaderInFlexParent: Story = {
},
},
};

function AnimatedChangesDemo() {
const [rows, setRows] = useState([
'Inbox',
'Sent',
'Drafts',
'Archive',
'Spam',
]);
const [next, setNext] = useState(1);
const containerRef = useRef<HTMLDivElement>(null);
const animatedLayout = useAnimatedLayout({containerRef});
return (
<div ref={containerRef}>
<VStack gap={4}>
<List animatedLayout={animatedLayout} hasDividers>
{rows.map(label => (
<ListItem
key={label}
itemKey={label}
label={label}
onClick={() => {}}
/>
))}
</List>
<Text data-testid="after-list">{`${rows.length} folders`}</Text>
<Button
label="Insert a row second"
onClick={() => {
setRows(current => [
current[0],
`Folder ${next}`,
...current.slice(1),
]);
setNext(n => n + 1);
}}
/>
<Button
label="Remove the second row"
onClick={() =>
setRows(current => current.filter((_, index) => index !== 1))
}
/>
<Button
label="Move the last row first"
onClick={() =>
setRows(current => [
current[current.length - 1],
...current.slice(0, -1),
])
}
/>
</VStack>
</div>
);
}

export const AnimatedChanges: Story = {
render: () => <AnimatedChangesDemo />,
parameters: {
docs: {
description: {
story:
'With `animatedLayout` (the handle from `useAnimatedLayout`) and ' +
'an `itemKey` on each row, an inserted row enters, a removed row ' +
'collapses in place, a row crossing rows that move the other way ' +
'rides above them with the surface color behind it, and the rows ' +
'after a change and the buttons below the list glide to their new ' +
'places, all on one shared motion, under every pointer.',
},
},
},
};

/** The swipe story's row with no swipe actions. */
const PLAIN_ROW = 'Notes';

function AnimatedChangesSwipeDemo() {
const [rows, setRows] = useState([
'Inbox',
'Sent',
'Drafts',
'Archive',
PLAIN_ROW,
]);
const containerRef = useRef<HTMLDivElement>(null);
const animatedLayout = useAnimatedLayout({containerRef});
const moveFirst = (label: string) =>
setRows(current =>
current.includes(label)
? [label, ...current.filter(row => row !== label)]
: current,
);
return (
<div ref={containerRef}>
<List animatedLayout={animatedLayout} hasDividers>
{rows.map(label => (
<ListItem
key={label}
itemKey={label}
label={label}
onClick={() => {}}
swipeActions={
label === PLAIN_ROW
? undefined
: {
trailing: [
{
label: 'Delete',
variant: 'destructive',
hasRemoval: true,
onActivate: () =>
setRows(current =>
current.filter(row => row !== label),
),
},
],
}
}
/>
))}
</List>
<Button
label="Move Archive first"
variant="secondary"
onClick={() => moveFirst('Archive')}
/>
<Button
label="Move Notes first"
variant="secondary"
onClick={() => moveFirst(PLAIN_ROW)}
/>
</div>
);
}

export const AnimatedChangesSwipe: Story = {
render: () => <AnimatedChangesSwipeDemo />,
parameters: {
docs: {
description: {
story:
'With `animatedLayout`, a row swiped away with a removal action ' +
'collapses in place, its action showing, while the rows below ' +
'glide up into its gap on the shared motion. A row moved up ' +
'across the swipeable rows, with swipe actions (Archive) or ' +
'without (Notes), rides above the rows it crosses.',
},
},
},
};
4 changes: 2 additions & 2 deletions docs/specs/AST-105-animated-layout/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ Rejected: the measured spring as the glide; a platform-measured opt-in, such as

The glide plays over `--duration-medium`, the middle of the theme's medium
durations: 300 ms in the Neutral theme and 410 ms with no theme, both scaled
by `tempo`. Collapsible, TreeList, Table's row expansion and AppShell's
content area share it, as one motion.
by `tempo`. Collapsible, TreeList, Table's row expansion, AppShell's content
area and List share it, as one motion.

Rejected: `--duration-medium-min`.

Expand Down
4 changes: 3 additions & 1 deletion docs/specs/components/List/List.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ verified_by:
packages/core/src/List/ListItem.hitArea.test.tsx,
packages/core/src/List/__tests__/ListTouchHitArea.interaction.browser.spec.ts,
packages/core/src/List/__tests__/ListDividers.interaction.browser.spec.ts,
packages/core/src/List/listLayoutUpdates.test.tsx,
packages/core/src/List/__tests__/ListUpdates.interaction.browser.spec.ts,
packages/core/src/theme/derivedVarRegistry.test.ts,
packages/core/src/theme/generateThemeRules.test.ts,
apps/storybook/stories/List.stories.tsx,
Expand Down Expand Up @@ -52,7 +54,7 @@ system_specs:
| Behavior | One edge treatment applies to every ListItem row and decides where row content and row paint sit relative to the list's edges and the host's padding. With `reorderable`, rows reorder by dragging a handle or through reorder mode (`spec:AST-103` FR3, FR4). Under a coarse pointer a row's press follows the cell profile (`spec:AST-094` FR11); with `animatedLayout`, row updates animate (`spec:AST-105`). A row menu opens from the row's own `<li>` on the context request (FR13). |
| End-user impact | Row text can share the line of the list header and a heading above, with row paint stopping at the text, reaching into the host padding, or reaching the host edges. Touch users get a 44 px row target (FR10) and the cell press (FR11), and every pointer keeps a highlighted row's dividers visible (FR11); with `animatedLayout`, row updates animate for every pointer (FR12). A row with a menu opens it by a long press, a right click, or Shift+F10, or through its More actions button (FR13). |
| Builder impact | One `edge` choice per list. `flush` works anywhere; `outset` and `bleed` act only inside a host that publishes container padding. Passing an `animatedLayout` handle is one new choice, and a row menu is the other: the caller passes a ListItem's ref to `useContextMenu` (FR13), and who draws a plain row's More actions button is open (OQ2); and rows animate only with an `itemKey`; the touch target and press need none. |
| Compatibility/readiness | Additive; omission keeps current geometry; `edgeCompensation` keeps working with a codemod to `edge`. `reorderable` and `itemKey` are additive and stable, specified and not implemented yet; without them nothing changes. `animatedLayout` is additive and specified, not implemented yet. The touch target (FR10) and the press's compositor release (FR11) are implemented under coarse primary pointers. Neither changes anything under a fine pointer. Row menus (FR13) are additive and specified, not implemented yet. |
| Compatibility/readiness | Additive; omission keeps current geometry; `edgeCompensation` keeps working with a codemod to `edge`. `reorderable` is additive and stable, specified and not implemented yet. `itemKey` and `animatedLayout`'s row updates (FR12) are implemented; its start and end content motion is not. The touch target (FR10) and the press's compositor release (FR11) are implemented under coarse primary pointers. Neither changes anything under a fine pointer. Row menus (FR13) are additive and specified, not implemented yet. |
| Review checks | Reject header movement, row paint past the host's padding edge, duplicated padding values, physical-edge logic, automatic opt-in, a ListItem-level edge prop, or a second prop that can contradict `edge`. |
| Governing rules | `architecture:container-padding/INV3`, `INV9–INV11`; `spec:AST-002/DEC-1–DEC-2`; `spec:AST-017/FR4`; `spec:AST-057/FR9`. `spec:AST-103`. `spec:AST-094` FR4, FR5, FR11, FR13; `spec:AST-105` FR1–FR5, FR8. `spec:AST-107` FR8 (row menus). |

Expand Down
8 changes: 3 additions & 5 deletions docs/specs/components/List/ListItem.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ review_triggers: [public-api, behavior, layout, theming]
verified_by:
[
packages/core/src/List/List.test.tsx,
packages/core/src/List/listLayoutUpdates.test.tsx,
packages/core/src/theme/themingTargets.test.ts,
scripts/check-knowledge.mjs,
apps/storybook/rtl-audit/targets.json,
Expand All @@ -36,11 +37,11 @@ system_specs: [spec:AST-057, spec:AST-103]

| Area | Contract |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Public contract | `ListItem` with `label`, `description`, `startContent`, `endContent`, `onClick`, `interactiveRef`, `href`, `target`, `rel`, `align`, `isDisabled`, `isSelected`, `swipe`, `xstyle`, `className`, `style`, and `ref`, with the deprecated `swipeActions` and `swipeBehavior` until `spec:AST-057` CLN-0025; the row carries `component:List`'s `list-item` target. `itemKey` (`spec:AST-103` DEC-4) is specified but not shipped. |
| Public contract | `ListItem` with `label`, `description`, `startContent`, `endContent`, `onClick`, `interactiveRef`, `href`, `target`, `rel`, `align`, `isDisabled`, `isSelected`, `itemKey`, `swipe`, `xstyle`, `className`, `style`, and `ref`, with the deprecated `swipeActions` and `swipeBehavior` until `spec:AST-057` CLN-0025; the row carries `component:List`'s `list-item` target. `itemKey` is the item's key (`spec:AST-103` DEC-4). |
| Behavior | One `<li>` row rendered by `component:Item`, which receives every row prop. Inside a List the row takes the list's density, dividers, edge treatment, and marker; outside a List it uses Item's defaults and draws no marker. |
| End-user impact | Each list entry reads as one list item, with the list's bullet, number, or task checkbox before it and the same interaction Item gives any row. |
| Builder impact | The deprecated `swipeActions` and `swipeBehavior` move to `swipe={createSwipe(…)}` under `spec:AST-057` DEP-0017; its `astryx upgrade` codemod is an opt-in early migration from the deprecating release and runs again in 0.8.0's upgrade with CLN-0025's removal. |
| Compatibility/readiness | Records shipped behavior; no public change. Three implementation gaps, listed under Current-state impact. |
| Compatibility/readiness | Records shipped behavior; `itemKey` is additive. Two implementation gaps, listed under Current-state impact. |
| Review checks | Reject a row that is not an `<li>`, a ListItem-level edge, density, or divider prop, a marker drawn outside a marked List, or a dropped Item prop. |
| Governing rules | `component:Item` (`align` for start and end content); `component:List`; `family:navigation-destinations`; `spec:AST-057`; `spec:AST-103`; `architecture:component-theming-surface`; `architecture:component-style-authoring` INV7. |

Expand Down Expand Up @@ -73,9 +74,6 @@ Consumer migration instructions belong in consumer docs and release notes.
pseudo-element, beside the row's content. `architecture:component-style-authoring`
INV7 carries decoration with no semantic role on a pseudo-element rather than
an added element.
- **ListItem has no `itemKey` yet.** `spec:AST-103` DEC-4 and `component:List`
FR12 have each reorderable row name its item through an `itemKey` prop;
ListItem does not accept one yet.
- **ListItem has no `swipe` yet.** `spec:AST-057` FR1 has ListItem pass
`swipe` through to `Item`, which replaces the deprecated `swipeActions`
and `swipeBehavior` (`spec:AST-057` DEP-0017); `swipe` is not built, so
Expand Down
2 changes: 2 additions & 0 deletions packages/core/api-report.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/core/src/List/List.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export const docs = {
description: 'Show dividers between items.',
default: 'false',
},
{
name: 'animatedLayout',
type: 'AnimatedLayout',
description: 'The handle from useAnimatedLayout({containerRef}). With it, when rows are inserted, removed or reordered, an inserted row enters, a removed row collapses in place, a row that crosses rows moving the other way rides above them with the surface color behind it, and the rows after a change and the content after the list, up to that container, glide to their new places, all on one shared motion, under every pointer. Under Reduce Motion nothing travels. A row is identified by its itemKey: a row without one changes at once. Without a handle the list changes at once.',
},
{
name: 'edge',
type: "'padded' | 'flush' | 'outset' | 'bleed'",
Expand Down
27 changes: 25 additions & 2 deletions packages/core/src/List/List.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {List} from './List';
import {ListItem} from './ListItem';
import {ListMarkerScope} from './ListContext';
import {HIT_INSET_PROPERTIES} from '../utils/hitArea';
import {useAnimatedLayout} from '../hooks/useAnimatedLayout';

describe('List', () => {
it('forwards ListItem align to its Item row unchanged', () => {
Expand Down Expand Up @@ -1159,6 +1160,23 @@ describe('List and swipe actions', () => {
expect(other.filter(rule => rule.includes('isolation'))).toEqual([]);
});

it('isolates for every pointer under an animatedLayout handle, since a sliding row rides above its neighbors with a mouse too', () => {
function Animated() {
const containerRef = useRef<HTMLDivElement | null>(null);
const animatedLayout = useAnimatedLayout({containerRef});
return (
<div ref={containerRef}>
<List animatedLayout={animatedLayout}>
<ListItem label="A" itemKey="a" onClick={() => {}} />
</List>
</div>
);
}
render(<Animated />);
const {other} = touchGatedRules(screen.getByRole('list'));
expect(other.join('\n')).toMatch(/isolation: isolate/);
});

it('under a finger, raises a swipeable interactive row above the rows after it: it is a stacking context, so its touch band’s own z-index orders only inside it', () => {
render(
<List>
Expand Down Expand Up @@ -1193,8 +1211,13 @@ describe('List and swipe actions', () => {
};
const swipeable = rowZ(row('Swipeable'));
expect(swipeable.touch.join('\n')).toMatch(/z-index: 1/);
// With a mouse there is no band, and nothing changes.
expect(swipeable.other).toEqual([]);
// With a mouse there is no band: the row's only z-index is an update's
// travelling raise, while it slides across other rows.
for (const rule of swipeable.other) {
expect(rule.slice(0, rule.indexOf('{'))).toContain(
'[data-astryx-travelling]',
);
}
// A row that is no stacking context needs no raise (its band's own
// z-index orders it), and a swipeable row with no band gets none.
expect(rowZ(row('Pressable')).touch).toEqual([]);
Expand Down
Loading
Loading