Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Snackbar to be persistent #426

Merged
merged 12 commits into from
May 15, 2024
Merged

Conversation

jamal-khey
Copy link
Contributor

This pull request adds the ability to make Snackbar messages persistent. Previously, Snackbar messages would disappear after a certain amount of time, but now they can be set to stay on the screen until dismissed by the user.

Copy link
Contributor

@TheMaskedTurtle TheMaskedTurtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to just extend a bit the notistack API here with our snackInfo, snackWarn, etc.. methods, so it would be nice to not limit it. If so, it wouldn't require any dev to add the persist behavior as it is already in the notistack API.

src/hooks/useSnackMessage.ts Outdated Show resolved Hide resolved
src/hooks/useSnackMessage.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@TheMaskedTurtle TheMaskedTurtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really on your dev but the makeSnackbar method kind of mixes the logic of building the message and the one that just enqueue the message, maybe you could split them to make it more readable.
Something like that for the enqueue logic

const enqueue = useCallback(
        (variant: BaseVariant, snackInputs: SnackInputs) => {
            const message = makeMessage(intlRef, snackInputs);
            if (message !== undefined) {
                enqueueSnackbar(message, {
                    ...snackInputs,
                    variant,
                    style: { whiteSpace: 'pre-line' },
                });
            }
        },
        [enqueueSnackbar, intlRef]
    );

And then you keep the makeMessage with the current message logic.

src/hooks/useSnackMessage.ts Outdated Show resolved Hide resolved
src/hooks/useSnackMessage.ts Outdated Show resolved Hide resolved
src/hooks/useSnackMessage.ts Outdated Show resolved Hide resolved
src/hooks/useSnackMessage.ts Outdated Show resolved Hide resolved
src/hooks/useSnackMessage.ts Outdated Show resolved Hide resolved
src/hooks/useSnackMessage.ts Outdated Show resolved Hide resolved
src/hooks/useSnackMessage.ts Show resolved Hide resolved
src/hooks/useSnackMessage.ts Outdated Show resolved Hide resolved
demo/src/app.jsx Outdated
<Button
variant="contained"
color="info"
style={{ float: 'left', margin: '5px' }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make style button sx={style.button}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jamal-khey jamal-khey merged commit d975c09 into main May 15, 2024
3 checks passed
@jamal-khey jamal-khey deleted the allow-snack-bar-persistance branch May 15, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants