Skip to content

Commit 005c620

Browse files
committed
docs: Add Sortable Flex examples
Add a Flex examples section that mirrors the Grid examples, with interactive examples for: auto scroll, drop indicator (default, custom style and custom component), item snap, different item sizes, touchable, custom handle, fixed items, active item portal and custom shadow. The flex/examples.mdx pointer page (which just linked to the Grid examples) is replaced by a flex/examples/ folder, analogous to grid/examples/. The drop indicator examples use theme-aware colors and the custom handle disables pointer events on the handle icon, matching the equivalent Grid examples.
1 parent 92fe9da commit 005c620

22 files changed

Lines changed: 1090 additions & 9 deletions

packages/docs/docs/flex/examples.mdx

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"label": "Examples",
3+
"position": 3,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Flex Examples",
7+
"slug": "/flex/examples"
8+
}
9+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
sidebar_position: 8
3+
description: ''
4+
---
5+
6+
# Active Item Portal
7+
8+
## Description
9+
10+
This example demonstrates how to use the active item portal to render the active item on top of other components.
11+
12+
In this case, the `PortalProvider` is used to render the active item outside of the `ScrollView` content bounds. This is the only way to render only the active item without cropping it whilst keeping the rest of the flex container within the `ScrollView` content bounds.
13+
14+
## Example
15+
16+
import InteractiveExample from '@site/src/components/InteractiveExample';
17+
import FlexActiveItemPortalExample from '@site/src/examples/FlexActiveItemPortal';
18+
import FlexActiveItemPortalCode from '!!raw-loader!@site/src/examples/FlexActiveItemPortal';
19+
20+
<InteractiveExample
21+
component={FlexActiveItemPortalExample}
22+
code={FlexActiveItemPortalCode}
23+
/>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
sidebar_position: 1
3+
description: ''
4+
---
5+
6+
# Auto Scroll
7+
8+
## Description
9+
10+
This example demonstrates how to use the **auto scroll** feature of the **Sortable Flex** component. Pass a `scrollableRef` pointing to the scrollable container and it will scroll automatically while you drag an item near its edges.
11+
12+
## Example
13+
14+
import InteractiveExample from '@site/src/components/InteractiveExample';
15+
import FlexAutoScrollExample from '@site/src/examples/FlexAutoScroll';
16+
import FlexAutoScrollCode from '!!raw-loader!@site/src/examples/FlexAutoScroll';
17+
18+
<InteractiveExample
19+
component={FlexAutoScrollExample}
20+
code={FlexAutoScrollCode}
21+
/>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
sidebar_position: 6
3+
description: ''
4+
---
5+
6+
# Custom Handle
7+
8+
## Description
9+
10+
The **Custom Handle** example demonstrates how to use a custom item drag handle in the **Sortable Flex** component.
11+
12+
## Example
13+
14+
import InteractiveExample from '@site/src/components/InteractiveExample';
15+
import FlexCustomHandleExample from '@site/src/examples/FlexCustomHandle';
16+
import FlexCustomHandleCode from '!!raw-loader!@site/src/examples/FlexCustomHandle';
17+
18+
<InteractiveExample
19+
component={FlexCustomHandleExample}
20+
code={FlexCustomHandleCode}
21+
/>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
sidebar_position: 9
3+
description: ''
4+
---
5+
6+
# Custom Shadow
7+
8+
## Description
9+
10+
This example demonstrates how to create a **custom shadow** for the active item during drag. By disabling the default shadow with `activeItemShadowOpacity={0}` and using the [useItemContext](/hooks/useItemContext) hook, you can animate the `box-shadow` property of the item based on the activation animation progress.
11+
12+
This is particularly useful when you want to add shadows on **Android**, where shadows are not supported by default and must be implemented by the user.
13+
14+
## Example
15+
16+
import InteractiveExample from '@site/src/components/InteractiveExample';
17+
import FlexCustomShadowExample from '@site/src/examples/FlexCustomShadow';
18+
import FlexCustomShadowCode from '!!raw-loader!@site/src/examples/FlexCustomShadow';
19+
20+
<InteractiveExample
21+
component={FlexCustomShadowExample}
22+
code={FlexCustomShadowCode}
23+
/>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
sidebar_position: 4
3+
description: ''
4+
---
5+
6+
# Different Item Sizes
7+
8+
## Description
9+
10+
This example shows that the **Sortable Flex** component can handle **items of different sizes** without any issues. Items flow and wrap naturally based on their content.
11+
12+
## Example
13+
14+
import InteractiveExample from '@site/src/components/InteractiveExample';
15+
import FlexDifferentSizesExample from '@site/src/examples/FlexDifferentSizes';
16+
import FlexDifferentSizesCode from '!!raw-loader!@site/src/examples/FlexDifferentSizes';
17+
18+
<InteractiveExample
19+
component={FlexDifferentSizesExample}
20+
code={FlexDifferentSizesCode}
21+
/>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
sidebar_position: 2
3+
description: ''
4+
---
5+
6+
# Drop Indicator
7+
8+
## Description
9+
10+
The drop indicator is a **visual indicator** that shows the **position where the item will be dropped** when the user releases the item.
11+
12+
## Default
13+
14+
import InteractiveExample from '@site/src/components/InteractiveExample';
15+
import FlexDropIndicatorDefaultExample from '@site/src/examples/FlexDropIndicatorDefault';
16+
import FlexDropIndicatorDefaultCode from '!!raw-loader!@site/src/examples/FlexDropIndicatorDefault';
17+
18+
<InteractiveExample
19+
component={FlexDropIndicatorDefaultExample}
20+
code={FlexDropIndicatorDefaultCode}
21+
/>
22+
23+
## Custom Style
24+
25+
import FlexDropIndicatorCustomStyleExample from '@site/src/examples/FlexDropIndicatorCustomStyle';
26+
import FlexDropIndicatorCustomStyleCode from '!!raw-loader!@site/src/examples/FlexDropIndicatorCustomStyle';
27+
28+
<InteractiveExample
29+
component={FlexDropIndicatorCustomStyleExample}
30+
code={FlexDropIndicatorCustomStyleCode}
31+
/>
32+
33+
## Custom Component
34+
35+
import FlexDropIndicatorCustomComponentExample from '@site/src/examples/FlexDropIndicatorCustomComponent';
36+
import FlexDropIndicatorCustomComponentCode from '!!raw-loader!@site/src/examples/FlexDropIndicatorCustomComponent';
37+
38+
<InteractiveExample
39+
component={FlexDropIndicatorCustomComponentExample}
40+
code={FlexDropIndicatorCustomComponentCode}
41+
/>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
sidebar_position: 7
3+
description: ''
4+
---
5+
6+
# Fixed Items
7+
8+
## Description
9+
10+
The fixed items example demonstrates how to create a **Sortable Flex** with items which have a **fixed position**.
11+
12+
In the example below, the **first**, the **last** and an **item in the middle** are fixed (grayed out) and stay in the same ordinal position.
13+
14+
## Example
15+
16+
import InteractiveExample from '@site/src/components/InteractiveExample';
17+
import FlexFixedItemsExample from '@site/src/examples/FlexFixedItems';
18+
import FlexFixedItemsCode from '!!raw-loader!@site/src/examples/FlexFixedItems';
19+
20+
<InteractiveExample
21+
component={FlexFixedItemsExample}
22+
code={FlexFixedItemsCode}
23+
/>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
sidebar_position: 3
3+
description: ''
4+
---
5+
6+
# Item snap
7+
8+
## Description
9+
10+
The item snap is a **transformation of the item** that happens when the user **presses the item** (before the drag starts). It **transforms** the item **in relation to the touch position**.
11+
12+
## Example
13+
14+
import InteractiveExample from '@site/src/components/InteractiveExample';
15+
import FlexItemSnapExample from '@site/src/examples/FlexItemSnap';
16+
import FlexItemSnapCode from '!!raw-loader!@site/src/examples/FlexItemSnap';
17+
18+
<InteractiveExample component={FlexItemSnapExample} code={FlexItemSnapCode} />

0 commit comments

Comments
 (0)