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

feat(notificationstack): New hooks and components for NotificationStack #12572

Closed
wants to merge 2 commits into from

Conversation

cgirani
Copy link

@cgirani cgirani commented Nov 8, 2022

Reference: #8405

New hooks and components to render NotificationStack.

Components/hooks and their use/purpose:

NotificationStack - Component to be used in begin of the application, it's a wrapper of all notifications
notification-store - Function where we hold the state of notifications, along with functions that act like dispatch/reducer
notification - Export a function to trigger the notification, this function can be imported in any file in the application
useNotification - Hook with notifications info from the store and some handlers (actions/dispatch) to be used, this one is used in the component NotificationStack

Even files are aligned about Notifications hooks, trigger function and store are generic enough for future uses of any other component...

Changelog

New

  • New files to support notification stack headless
    • NotificationStack
    • notification-store
    • notification
    • useNotification
    • css file for NotificationStack

Changed

  • Index.css to add new css files

Removed

  • None

Testing / Reviewing

At the storybook test the NotificationStack component.

  • If opens multiple notifications
  • If closes correctly with the timeout
  • Animation worksas expected

@cgirani cgirani requested a review from a team as a code owner November 8, 2022 14:01
@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2022

DCO Assistant Lite bot All contributors have signed the DCO.

@tay1orjones tay1orjones self-requested a review November 8, 2022 14:02
@netlify
Copy link

netlify bot commented Nov 8, 2022

Deploy Preview for carbon-components-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit fdf0516
🔍 Latest deploy log https://app.netlify.com/sites/carbon-components-react/deploys/636a612f85427e000877df00
😎 Deploy Preview https://deploy-preview-12572--carbon-components-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Nov 8, 2022

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit fdf0516
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/636a612f423e9a0009f5050d
😎 Deploy Preview https://deploy-preview-12572--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@cgirani
Copy link
Author

cgirani commented Nov 8, 2022

DCO Assistant Lite bot: Thanks for your submission! We ask that you sign our Developer Certificate of Origin before we can accept your contribution. You can sign the DCO by adding a comment below using this text:

I have read the DCO document and I hereby sign the DCO.

You can retrigger this bot by commenting recheck in this Pull Request

I have read the DCO document and I hereby sign the DCO.

@tw15egan
Copy link
Member

tw15egan commented Nov 8, 2022

@cgirani could you just post the message without the quoted text in a new comment? Thanks!

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Thanks so much for submitting this! It's a great first step towards landing something like this in the project.

I'd love to schedule some time to review this with you further and see how we could nail down the experience and API a bit more.

Some high level thoughts from an initial glance:

NotificationStack - Component to be used in begin of the application, it's a wrapper of all notifications

Great approach here, I think it's a very common pattern to expect consumers to wrap part or all of their application tree with a context-provider-type of component like this.

notification-store - Function where we hold the state of notifications, along with functions that act like dispatch/reducer

I'd like to see this use useReducer instead of a vanilla reducer pattern. Also, have you ran into any issues storing these in state? I could forsee a situation where someone needs to persist the notification store across sessions - we might want to think about how to open up this to enable "saving" to an external store, if even just localstorage.

notification - Export a function to trigger the notification, this function can be imported in any file in the application

I'd like to see this provided by the hook, instead of it's own function to import. Also we should look into using useLayoutEffect instead of a setTimeout for being able to calculate the height.

useNotification - Hook with notifications info from the store and some handlers (actions/dispatch) to be used, this one is used in the component NotificationStack

I'd really like to refocus this on the experience of the consumer. I think in an ideal world we'd have the useNotification hook as a central entrypoint for all of this behavior. trigger would be destructured off the hook in consumer apps or in storybook examples.

Will a consumer ever need to dispatch manually? If we need a second hook for the internal dispatch, etc., that would be fine, but we should probably keep those concerns separate from useNotification if there's no need for a consumer to call dispatch.

Additional thoughts:

  • This only works with ToastNotification. Ideally, InlineNotification and ActionableNotification support would be included and provide the animation defined in the root issue.
  • I see you haven't added any of this to the root index.js exports yet. We'll want to really hone in on what we intend to expose to consumers and think about limiting that API surface area so the underlying implementation can shift without introducing breaking changes to consumers.
  • As this firms up we can first introduce it as experimental, prefixed as unstable__useNotification.
  • Respecting the user's prefers-reduced-motion setting will be important to provide support out of the gate

Again thank you for this initial drop! 🙏 🎉 I can reach out to schedule some time to discuss this.

@tay1orjones tay1orjones marked this pull request as draft November 16, 2022 15:37
@cgirani
Copy link
Author

cgirani commented Nov 16, 2022

I have read the DCO document and I hereby sign the DCO.

@tay1orjones
Copy link
Member

tay1orjones commented Mar 24, 2023

Sorry this has languished - our team has had other priorities and been unable to pick up this workstream and devote the time and attention it deserves. If anyone is willing to continue this work based on the suggestions and feedback provided above, we'd love to chat.

Going to close this for now to clean up our PR queue, but happy to reopen if work resumes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants