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

Support for multiple custom actions in snacks #110

Closed
wants to merge 2 commits into from
Closed

Support for multiple custom actions in snacks #110

wants to merge 2 commits into from

Conversation

YBogomolov
Copy link
Contributor

@YBogomolov YBogomolov commented Apr 5, 2019

See #107 for details.

My design decisions:

  1. The only reliable way to ensure user is able to close the snack – to provide user's action with our internal onClose handler. This could be done via abstracting action into a generator function.
  2. I also updated Redux example so you can see implementation from the user's perspective.
  3. The old behavior is preserved, so no regression is introduced by this PR.

Notes: I had to create src folder in redux-example and move corresponding files into it so the example could actually work.

@YBogomolov YBogomolov changed the title Implementation of FR#107 Support for multiple custom actions in snacks Apr 5, 2019
@YBogomolov
Copy link
Contributor Author

@iamhosseindhv any thoughts on this? Does my design suit overall architecture of Notistack well?

@iamhosseindhv
Copy link
Owner

iamhosseindhv commented Apr 19, 2019

@YBogomolov Thanks for the PR. like idea of passing an action function in options parameter. (i.e. getAction in your implementation). But we need notistack to be as close as possible to material-ui snackbars, in terms of the API. So I try to not add any new getAction or onClickAction prop/options.

Anyhow, this feature is now in master and will be published within the next week.

We now have access to the key for a given snackbar which can be used to dismiss the snackbar:

props.enqueueSnackbar('I love snacks!', {
    action: (key) => (
        <Fragment>
            <Button onClick={() => alert(`I belong to snackbar with key ${key}`)}>MyAction</Button>
            <Button onClick={() => props.closeSnackbar(key)}>Dismiss</Button>
        </Fragment>
    ),
    // OR: 
    action: (
         <Button onClick={() => alert('I don\'t care which snackbar I belong to')}>MyAction</Button>
    ),
 });

@YBogomolov
Copy link
Contributor Author

@iamhosseindhv Sorry, but I have to reopen this issue. Due to incorrect typings it's impossible to use this feature in TypeScript. I'll try to come with a PR as soon as possible.

@YBogomolov
Copy link
Contributor Author

@iamhosseindhv Please see #113. I would be grateful if this issue is addressed ASAP.

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.

2 participants