Menu Sheet Guide to using Swipeable Menu Sheet with Stackflow.
@seed-design/stackflow@2.0.0, @seed-design/react@2.0.0, @seed-design/css@2.0.0
Learn more about the Swipeable Menu Sheet component.
In typical cases, it is recommended to create a Swipeable Menu Sheet as an Activity and use it.
Since it is managed as an Activity, it is easy to manage with z-index higher than lower Activities and lower than upper Activities.
Deep linking is possible. (You can open the Swipeable Menu Sheet by accessing a URL.)
Migration from @stackflow/plugin-basic-ui BottomSheet is easy.
ActivityMenuSheetActivity.tsx
import { VStack } from "@seed-design/react" ;
import { useFlow, type StaticActivityComponentType } from "@stackflow/react/future" ;
import { IconHouseLine } from "@karrotmarket/react-monochrome-icon" ;
import {
AppBar,
AppBarBackButton,
AppBarIconButton,
AppBarLeft,
AppBarMain,
AppBarRight,
} from "seed-design/ui/app-bar" ;
import { AppScreen, AppScreenContent } from "seed-design/ui/app-screen" ;
import { ActionButton } from "seed-design/ui/action-button" ;
declare module "@stackflow/config" {
interface Register {
ActivityMenuSheetActivity : {};
}
}
const ActivityMenuSheetActivity : StaticActivityComponentType < "ActivityMenuSheetActivity" > = () => {
const { push } = useFlow ();
return (
< AppScreen >
< AppBar >
< AppBarLeft >
< AppBarBackButton />
</ AppBarLeft >
< AppBarMain title = "Activity" />
< AppBarRight >
< AppBarIconButton aria-label = "Home" onClick = {() => push ( "ActivityHome" , {})}>
< IconHouseLine />
</ AppBarIconButton >
</ AppBarRight >
</ AppBar >
< AppScreenContent >
< VStack p = "x5" justify = "center" gap = "x4" >
< ActionButton
variant = "neutralSolid"
flexGrow
onClick = {() => push ( "ActivityMenuSheetSimple" , {})}
>
ActivityMenuSheetSimple을 Push
</ ActionButton >
< ActionButton
variant = "neutralWeak"
flexGrow
onClick = {() => push ( "ActivityMenuSheetActivity" , {})}
>
지금 열린 이 Activity를 Push
</ ActionButton >
</ VStack >
</ AppScreenContent >
</ AppScreen >
);
};
export default ActivityMenuSheetActivity; ActivityMenuSheetSimple.tsx
import { useActivityZIndexBase } from "@seed-design/stackflow" ;
import { useActivity, useFlow, type StaticActivityComponentType } from "@stackflow/react/future" ;
import {
IconPencilLine,
IconPlusLine,
IconTrashcanLine,
} from "@karrotmarket/react-monochrome-icon" ;
import {
SwipeableMenuSheetContent,
SwipeableMenuSheetGroup,
SwipeableMenuSheetItem,
SwipeableMenuSheetRoot,
} from "seed-design/ui/swipeable-menu-sheet" ;
import { Snackbar, useSnackbarAdapter } from "seed-design/ui/snackbar" ;
declare module "@stackflow/config" {
interface Register {
ActivityMenuSheetSimple : {};
}
}
const ActivityMenuSheetSimple : StaticActivityComponentType < "ActivityMenuSheetSimple" > = () => {
const { pop } = useFlow ();
const activity = useActivity ();
const snackbar = useSnackbarAdapter ();
const handleAction = ( action : string ) => {
snackbar. create ({
render : () => < Snackbar variant = "positive" message = { `선택한 액션: ${ action }` } />,
});
pop ();
};
return (
< SwipeableMenuSheetRoot open = {activity.isActive} onOpenChange = {( open ) => ! open && pop ()}>
< SwipeableMenuSheetContent title = "Actions" layerIndex = { useActivityZIndexBase ()}>
< SwipeableMenuSheetGroup >
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "add" )}
label = "추가"
prefixIcon = {< IconPlusLine />}
/>
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "edit" )}
label = "수정"
prefixIcon = {< IconPencilLine />}
/>
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "delete" )}
tone = "critical"
label = "삭제"
prefixIcon = {< IconTrashcanLine />}
/>
</ SwipeableMenuSheetGroup >
</ SwipeableMenuSheetContent >
</ SwipeableMenuSheetRoot >
);
};
export default ActivityMenuSheetSimple;
import { useActivityZIndexBase } from "@seed-design/stackflow" ;
import { useActivity, useFlow, type ActivityComponentType } from "@stackflow/react/future" ;
// ... more imports
const ActivitySwipeableMenuSheet : ActivityComponentType < "ActivitySwipeableMenuSheet" > = () => {
const { pop } = useFlow ();
const handleAction = ( action : string ) => {
console. log ( "Selected action:" , action);
pop ();
};
return (
< SwipeableMenuSheetRoot open = { useActivity ().isActive} onOpenChange = {( open ) => ! open && pop ()}>
< SwipeableMenuSheetContent
title = "Actions"
layerIndex = { useActivityZIndexBase ()}
>
< SwipeableMenuSheetGroup >
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "add" )}
label = "Add"
prefixIcon = {< IconPlusLine />}
/>
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "edit" )}
label = "Edit"
prefixIcon = {< IconPencilLine />}
/>
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "delete" )}
tone = "critical"
label = "Delete"
prefixIcon = {< IconTrashcanLine />}
/>
</ SwipeableMenuSheetGroup >
</ SwipeableMenuSheetContent >
</ SwipeableMenuSheetRoot >
);
};
Pass useActivity().isActive to the open prop so that the Swipeable Menu Sheet opens when the Activity is activated.
When the Swipeable Menu Sheet closes, run pop() through onOpenChange to terminate the Activity. Since onOpenChange is also called when closing by swipe gesture, the Activity is also terminated.
Pass the z-index base point of the Swipeable Menu Sheet Activity with layerIndex={useActivityZIndexBase()}.
If you cannot create a Swipeable Menu Sheet as an Activity, you can create the state where the Swipeable Menu Sheet is displayed as a Step .
You can close the Swipeable Menu Sheet with a back button, etc., while maintaining the current Activity.
You can open and close the Swipeable Menu Sheet using SwipeableMenuSheetTrigger.
Constraints When pushing another Activity from a Swipeable Menu Sheet not created as an Activity, close the Swipeable Menu Sheet before pushing.
If you cannot close the Swipeable Menu Sheet, or if you need to maintain the Swipeable Menu Sheet in an open state when returning to the Activity that opened it, it is recommended to create the Swipeable Menu Sheet as an Activity .
To provide smooth transitions between Activities, some lower AppScreen elements are positioned above upper AppScreen elements. Due to this constraint, an open Swipeable Menu Sheet cannot be positioned between lower and upper Activities unless it is created as an independent Activity.
ActivityMenuSheetStep.tsx
import { Portal, VStack } from "@seed-design/react" ;
import { useActivityZIndexBase } from "@seed-design/stackflow" ;
import {
useActivityParams,
useFlow,
useStepFlow,
type StaticActivityComponentType,
} from "@stackflow/react/future" ;
import { useEffect, useState } from "react" ;
import { ActionButton } from "seed-design/ui/action-button" ;
import { AppBar, AppBarIconButton, AppBarMain, AppBarRight } from "seed-design/ui/app-bar" ;
import { AppScreen, AppScreenContent } from "seed-design/ui/app-screen" ;
import {
SwipeableMenuSheetContent,
SwipeableMenuSheetGroup,
SwipeableMenuSheetItem,
SwipeableMenuSheetRoot,
SwipeableMenuSheetTrigger,
} from "seed-design/ui/swipeable-menu-sheet" ;
import {
IconHouseLine,
IconPencilLine,
IconPlusLine,
IconTrashcanLine,
} from "@karrotmarket/react-monochrome-icon" ;
import { Snackbar, useSnackbarAdapter } from "seed-design/ui/snackbar" ;
declare module "@stackflow/config" {
interface Register {
ActivityMenuSheetStep : {
"menu-sheet" ?: "open" ;
};
}
}
const ActivityMenuSheetStep : StaticActivityComponentType < "ActivityMenuSheetStep" > = () => {
const [ open , setOpen ] = useState ( false );
const { push } = useFlow ();
const { pushStep , popStep } = useStepFlow ( "ActivityMenuSheetStep" );
const params = useActivityParams < "ActivityMenuSheetStep" >();
const isOverlayOpen = params[ "menu-sheet" ] === "open" ;
const snackbar = useSnackbarAdapter ();
useEffect (() => setOpen (isOverlayOpen), [isOverlayOpen]);
const onOpenChange = ( newOpen : boolean ) => {
setOpen (newOpen);
if (newOpen && ! isOverlayOpen) {
pushStep (( params ) => ({ ... params, "menu-sheet" : "open" }));
return ;
}
if ( ! newOpen && isOverlayOpen) {
popStep ();
return ;
}
};
const handleAction = ( action : string ) => {
snackbar. create ({
render : () => < Snackbar variant = "positive" message = { `선택한 액션: ${ action }` } />,
});
setOpen ( false );
};
return (
< AppScreen >
< AppBar >
< AppBarMain title = "Step" />
< AppBarRight >
< AppBarIconButton aria-label = "Home" onClick = {() => push ( "ActivityHome" , {})}>
< IconHouseLine />
</ AppBarIconButton >
</ AppBarRight >
</ AppBar >
< AppScreenContent >
< SwipeableMenuSheetRoot open = {open} onOpenChange = {onOpenChange}>
< SwipeableMenuSheetTrigger asChild >
< VStack p = "x5" justify = "center" gap = "x4" >
< ActionButton variant = "neutralSolid" flexGrow >
Menu Sheet 열기
</ ActionButton >
</ VStack >
</ SwipeableMenuSheetTrigger >
< Portal >
< SwipeableMenuSheetContent
title = "Step"
layerIndex = { useActivityZIndexBase ({ activityOffset: 1 })}
>
< SwipeableMenuSheetGroup >
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "add" )}
label = "추가"
prefixIcon = {< IconPlusLine />}
/>
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "edit" )}
label = "수정"
prefixIcon = {< IconPencilLine />}
/>
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "delete" )}
tone = "critical"
label = "삭제"
prefixIcon = {< IconTrashcanLine />}
/>
</ SwipeableMenuSheetGroup >
< SwipeableMenuSheetGroup labelAlign = "center" >
< SwipeableMenuSheetItem
onClick = {() => {
// 이 Menu Sheet는 Activity로 만들어지지 않았기 때문에, z-index 정리를 위해
// Menu Sheet를 먼저 닫고 다음 Activity를 push해야 합니다.
setOpen ( false );
push ( "ActivityDetail" , {
title: "Menu Sheet에서 이동한 화면" ,
body: "Menu Sheet를 닫고 이동했습니다." ,
});
}}
label = "Push"
/>
</ SwipeableMenuSheetGroup >
</ SwipeableMenuSheetContent >
</ Portal >
</ SwipeableMenuSheetRoot >
</ AppScreenContent >
</ AppScreen >
);
};
export default ActivityMenuSheetStep;
import { useActivityZIndexBase } from "@seed-design/stackflow" ;
import { Portal } from "@seed-design/react" ;
import {
useActivity,
useActivityParams,
useFlow,
useStepFlow,
type ActivityComponentType,
} from "@stackflow/react/future" ;
import { useEffect, useState } from "react" ;
// ... more imports
declare module "@stackflow/config" {
interface Register {
ActivityHome : {
"menu-sheet" ?: "open" ;
};
}
}
const ActivityHome : ActivityComponentType < "ActivityHome" > = () => {
const [ open , setOpen ] = useState ( false );
const { push } = useFlow ();
const { pushStep , popStep } = useStepFlow ( "ActivityHome" );
const params = useActivityParams < "ActivityHome" >();
const isOverlayOpen = params[ "menu-sheet" ] === "open" ;
useEffect (() => {
if ( ! isOverlayOpen) {
setOpen ( false );
}
}, [isOverlayOpen]);
const onOpenChange = ( newOpen : boolean ) => {
setOpen (newOpen);
if (newOpen && ! isOverlayOpen) {
pushStep (( params ) => ({ ... params, "menu-sheet" : "open" }));
return ;
}
if ( ! newOpen && isOverlayOpen) {
popStep ();
return ;
}
};
const handleAction = ( action : string ) => {
console. log ( "Selected action:" , action);
setOpen ( false );
};
return (
< AppScreen >
< SwipeableMenuSheetRoot open = {open} onOpenChange = {onOpenChange}>
< SwipeableMenuSheetTrigger asChild >
< ActionButton >Open</ ActionButton >
</ SwipeableMenuSheetTrigger >
< Portal >
< SwipeableMenuSheetContent
title = "Actions"
layerIndex = { useActivityZIndexBase ({ activityOffset: 1 })}
>
< SwipeableMenuSheetGroup >
< SwipeableMenuSheetItem onClick = {() => handleAction ( "add" )} label = "Add" />
< SwipeableMenuSheetItem onClick = {() => handleAction ( "edit" )} label = "Edit" />
< SwipeableMenuSheetItem
onClick = {() => {
setOpen ( false ); // Close the Swipeable Menu Sheet before moving to another Activity.
push ( "ActivityNext" );
}}
label = "Push"
/>
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "delete" )}
tone = "critical"
label = "Delete"
/>
</ SwipeableMenuSheetGroup >
</ SwipeableMenuSheetContent >
</ Portal >
</ SwipeableMenuSheetRoot >
</ AppScreen >
);
};
Use Portal to render the Swipeable Menu Sheet outside the current Activity in the DOM.
Manage the open prop and synchronize the Step state through the onOpenChange handler.
Synchronize the open state of the Swipeable Menu Sheet when Activity parameters change through back button, etc.
Pass a z-index base point one level higher than the current Activity with layerIndex={useActivityZIndexBase({ activityOffset: 1 })}.
It is convenient to use useStepOverlay to generalize #2 and #3. For implementation examples of useStepOverlay, see the code .
import { useActivityZIndexBase } from "@seed-design/stackflow" ;
import { Portal } from "@seed-design/react" ;
import { useStepOverlay } from "./use-step-overlay" ;
// ... more imports
const MyActivity : ActivityComponentType = () => {
const { overlayProps , setOpen } = useStepOverlay ();
const { popStep } = useStepFlow ( "MyActivity" );
const { push } = useFlow ();
const handleAction = ( action : string ) => {
console. log ( "Selected action:" , action);
popStep ();
};
return (
< AppScreen >
< SwipeableMenuSheetRoot { ... overlayProps}>
< SwipeableMenuSheetTrigger asChild >
< ActionButton >Open</ ActionButton >
</ SwipeableMenuSheetTrigger >
< Portal >
< SwipeableMenuSheetContent
title = "Actions"
layerIndex = { useActivityZIndexBase ({ activityOffset: 1 })}
>
< SwipeableMenuSheetGroup >
< SwipeableMenuSheetItem onClick = {() => handleAction ( "add" )} label = "Add" />
< SwipeableMenuSheetItem onClick = {() => handleAction ( "edit" )} label = "Edit" />
< SwipeableMenuSheetItem
onClick = {() => {
setOpen ( false ); // Close the Swipeable Menu Sheet before moving to another Activity.
push ( "ActivityNext" );
}}
label = "Push"
/>
< SwipeableMenuSheetItem
onClick = {() => handleAction ( "delete" )}
tone = "critical"
label = "Delete"
/>
</ SwipeableMenuSheetGroup >
</ SwipeableMenuSheetContent >
</ Portal >
</ SwipeableMenuSheetRoot >
</ AppScreen >
);
};
useActivityZIndexBase is a hook that returns the z-index base point for each Activity.
It returns useActivity().zIndex * 5. useActivity().zIndex is a value indicating which Activity the current Activity is among the entered Activities.
Elements that make up AppScreen (layer, appbar, dim, edge) have z-index calculated based on the useActivityZIndexBase() value.
┌─ 2nd BottomSheet Activity
│ └─ BottomSheet: 12 (2 × 5 + 2)
├─ 1st AppScreen Activity
│ ├─ appbar: 12 (1 × 5 + 7)
│ ├─ edge: 9 (1 × 5 + 4)
│ ├─ layer: 7 (1 × 5 + 2)
│ └─ dim: 5 (1 × 5 + 0)
└─ 0th AppScreen Activity
├─ appbar: 7 (0 × 5 + 7)
├─ edge: 4 (0 × 5 + 4)
├─ layer: 2 (0 × 5 + 2)
└─ dim: 0 (0 × 5 + 0)
The activityOffset option is used when you want to use the z-index base point of the next Activity instead of the current Activity.
For example, useActivityZIndexBase({ activityOffset: 1 }) returns the z-index base point of the next Activity.
This is useful when displaying a BottomSheet on top of the current Activity in the Step pattern.
┌─ BottomSheet displayed with activityOffset: 1 from 1st AppScreen Activity (e.g., Step pattern)
│ └─ BottomSheet: 12 ((1 + 1) × 5 + 2)
├─ 1st AppScreen Activity
│ ├─ appbar: 12 (1 × 5 + 7)
│ ├─ edge: 9 (1 × 5 + 4)
│ ├─ layer: 7 (1 × 5 + 2)
│ └─ dim: 5 (1 × 5 + 0)
└─ 0th AppScreen Activity
├─ appbar: 7 (0 × 5 + 7)
├─ edge: 4 (0 × 5 + 4)
├─ layer: 2 (0 × 5 + 2)
└─ dim: 0 (0 × 5 + 0)
Both hooks return values needed for z-index styling based on which Activity the current Activity is among the entered Activities.
While the values returned by both hooks are the same, when using Crispy components instead of @stackflow/plugin-basic-ui , it is recommended to use the useActivityZIndexBase hook from the @seed-design/stackflow package managed by Crispy.
The useActivityZIndexBase hook in the @stackflow/react-ui-core package does not provide the activityOffset option.
The useActivityZIndexBase hook is provided starting from @seed-design/stackflow@1.1.1.
If you were specifying layerIndex in the form useActivity().zIndex * 5 + n, you can change it to useActivityZIndexBase() + n. As you make the change, also review whether + n is necessary.