Components
Snackbar
Snackbar displays informative text
Status component contains a list of checks and completeness that has been tested and owned by each component
Snackbars notify users of processes that have been or will be performed by the app. They appear temporarily, towards the bottom of the screen. They must not interfere with the user experience, and they do not require user input to disappear.
Variants & Themes
Legion has 4 variants for snackbar :
- Title
- Description
- Action Text
- Icon / Avatar
Legion has 5 themes for snackbar :
- Basic / Normal Theme
- Error Theme
- Warning Theme
- Success Theme
- Info Theme
Usage
To implement a snackbar, you can create SnackbarHost, which includes a LgnSnackbarHostState property. LgnSnackbarHostState provides access to the showSnackbar() function which you can use to display LgnSnackbar.
This suspending function requires a CoroutineScope such as with using rememberCoroutineScope — and can be called in response to UI events to show a LgnSnackBar within Scaffold.
Normal Snackbar
val scope = rememberCourotineScope()val snackbarHostState = remember { LgnSnackbarHostState() }Scaffold(snackbarHost = {LgnSnackbarHost(hostState = snackbarHostStatesnackbar = {LgnSnackBar(it)}
Success Snackbar
...val snackbarHostState = remember { LgnSnackbarHostSate() }Scaffold(...){Button(onClick = {scope.launch{snackbarHostState.showSnackbarSuccess(...)
Info Snackbar
...val snackbarHostState = remember { LgnSnackbarHostSate() }Scaffold(...){Button(onClick = {scope.launch{snackbarHostState.showSnackbarInfo(...)
Error Snackbar
...val snackbarHostState = remember { LgnSnackbarHostSate() }Scaffold(...){Button(onClick = {scope.launch{snackbarHostState.showSnackbarError(...)
Warning Snackbar
...val snackbarHostState = remember { LgnSnackbarHostSate() }Scaffold(...){Button(onClick = {scope.launch{snackbarHostState.showSnackbarWarning(...)
Custom Snackbar
LgnSnackbar also provide customization in LgnSnackbarHostState.showSnackbar (can be showSnackbarError, etc) have parameters to customize like adjust duration of the snackbar, action button, icon.
Here is the markdown for the parameters of the LgnAccordion
function:
...val snackbarHostState = remember { LgnSnackbarHostSate() }Scaffold(...){Button(onClick = {scope.launch{snackbarHostState.showSnackbar(
Attributes
Parameters | Type | Description |
---|---|---|
title | String | Text to be shown in the Snackbar |
message | String | Optional message text to be shown in the Snackbar |
icon | ImageVector | Optional icon to be shown in the Snackbar |
actionLabel | String | Optional action label to show as button in the Snackbar |
withDismissAction | Boolean | a Boolean to show a dismiss action in the Snackbar. |
duration | LgnSnackbarDuration | Duration to control how long snackbar will be shown in [SnackbarHost], either [LgnSnackbarDuration.Short], [LgnSnackbarDuration.Long] or [LgnSnackbarDuration.Indefinite] |