# ModalDrawer

> ModalDrawer from Material Compose (`androidx.compose.material:material`) for Jetpack Compose, with a code sample.

- Library: [Material Compose](https://composables.com/material-components/material-compose.md)
- Category: [Modals](https://composables.com/material-components/modals.md)
- Category: [Drawers](https://composables.com/material-components/drawers.md)
- API reference and more examples: [ModalDrawer](https://composables.com/jetpack-compose/androidx.compose.material/material/components/ModalDrawer/api.md)

## Code

```kotlin
@Composable
fun ModalDrawerSample() {
    val drawerState = rememberDrawerState(DrawerValue.Closed)
    val scope = rememberCoroutineScope()
    ModalDrawer(
        drawerState = drawerState,
        drawerContent = {
            Button(
                modifier = Modifier.align(Alignment.CenterHorizontally).padding(top = 16.dp),
                onClick = { scope.launch { drawerState.close() } },
                content = { Text("Close Drawer") },
            )
        },
        content = {
            Column(
                modifier = Modifier.fillMaxSize().padding(16.dp),
                horizontalAlignment = Alignment.CenterHorizontally,
            ) {
                Text(text = if (drawerState.isClosed) ">>> Swipe >>>" else "<<< Swipe <<<")
                Spacer(Modifier.height(20.dp))
                Button(onClick = { scope.launch { drawerState.open() } }) { Text("Click to open") }
            }
        },
    )
}
```
