-
Notifications
You must be signed in to change notification settings - Fork 69
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
[BD-46] feat: add new toast #2959
base: master
Are you sure you want to change the base?
Conversation
Thanks for the pull request, @khudym! When this pull request is ready, tag your edX technical lead. |
✅ Deploy Preview for paragon-openedx ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
src/Toast/README.md
Outdated
@@ -2,7 +2,8 @@ | |||
title: 'Toast' | |||
type: 'component' | |||
components: | |||
- Toast | |||
- ToastContainer | |||
- toast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Is toast
a React component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i`ll remove it, not a component
src/Toast/README.md
Outdated
</Toast> | ||
|
||
<Button variant="primary" onClick={() => setShow(true)}>Show Toast</Button> | ||
<div className="mt-3"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[important] Let's shorten the example of using the component and use a ready-made ExamplePropsForm
component, which we use to improve the user experience.
For example:
- We can display the number of milliseconds as a range
- Add position options as inputs with the radio type
- Use a checkbox to display the action
Example of using the ExamplePropsForm component:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
src/Toast/ToastContainer.jsx
Outdated
ToastContainer.propTypes = { | ||
/** Specifies contents of the component. */ | ||
children: PropTypes.node.isRequired, | ||
position: PropTypes.oneOf(['top-left', 'top-right', 'bottom-left', 'bottom-right']), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[important] let's put the PropTypes value into a constant
For example: const TOAST_POSITIONS = ['top-left', 'top-right', 'bottom-left', 'bottom-right'];
src/Toast/index.jsx
Outdated
export const TOAST_CLOSE_LABEL_TEXT = 'Close'; | ||
export const TOAST_DELAY = 5000; | ||
import Button from '../Button'; | ||
import { Close } from '../../icons'; | ||
|
||
function Toast({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[proposal] I propose renaming this component to BaseToast
. This will make it more obvious what it is used for.
> | ||
<div className="toast__header small"> | ||
<p className="toast__message">{message}</p> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Do we need this gap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i`ll remove it
src/index.js
Outdated
@@ -133,7 +133,8 @@ export { | |||
TabPane, | |||
} from './Tabs'; | |||
export { default as TextArea } from './TextArea'; | |||
export { default as Toast, TOAST_CLOSE_LABEL_TEXT, TOAST_DELAY } from './Toast'; | |||
export { default as ToastContainer } from './Toast/ToastContainer'; | |||
export { toast } from './Toast/toast'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[important] I suggest changing the file structure in the Toast folder.
Let's consider the option of moving the EventEmitter.js
and toast.js
files to the utils
folder (+ we will implement re-export for these files). Let's rename the index.jsx
file to BaseToast
, and ToastContainer.jsx
in index.jsx
.
For example:
- Toast
- tests
- ...
- utils
- EventEmitter.js
- index.js
- toast.js
- _variables.scss
- BaseToast.jsx
- index.scss
- README.MD
- index.jsx
- tests
The export from Paragon will look like this:
export { default as ToastContainer, toast } from './Toast';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, i`ll do it. Maybe we should think about the organization of files so that key files will be in the root (here, for example, the toast container and the toast function) that are exported or keep them in the "core" directory
src/Toast/toast.js
Outdated
import { toastEmitter } from './EventEmitter'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const toast = ({ message, duration, actions }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be great to add a little jsDocs documentation for this function
src/Toast/README.md
Outdated
## Features | ||
|
||
- **Customizable Appearance**: Choose the window position for toast. | ||
- **Interactive**: Includes a close button for manual dismissal. | ||
- **Auto-dismiss**: Disappears automatically after a set duration. | ||
- **Hover Interactivity**: Auto-dismiss timer pauses on hover or focus, allowing users to interact with the content. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[important] Let's place this description of the functionality of the Toast component in the Behaviors
. Now we're repeating ourselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good idea
src/Toast/ToastContainer.jsx
Outdated
}, []); | ||
|
||
return portalDivRef.current ? ReactDOM.createPortal( | ||
<div className="toast-container" style={{ ...positionStyle }}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<div className="toast-container" style={{ ...positionStyle }}> | |
<div className="pgn__toast-container" style={{ ...positionStyle }}> |
src/Toast/EventEmitter.js
Outdated
this.events[event].push(callback); | ||
} | ||
|
||
emit(event, data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[proposal] In the current implementation, when using several Toasts on a page, we observe their simultaneous calling. After clicking on any of the Toast triggers, we simultaneously call the emitter for all toasts on the page. We need to unify this process and make sure that the trigger executes the showToast
event only for the desired Toast.
On the component usage example pages we have Toast in the code example (copy button) and in the usage example itself.
9e1dc57
to
4bf88cf
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #2959 +/- ##
==========================================
+ Coverage 93.00% 93.05% +0.05%
==========================================
Files 236 239 +3
Lines 4273 4306 +33
Branches 1033 1036 +3
==========================================
+ Hits 3974 4007 +33
Misses 295 295
Partials 4 4 ☔ View full report in Codecov by Sentry. |
Description
Implemented new toast based on event emitter
Issue#1858
Deploy Preview
components/toast
Merge Checklist
example
app?wittjeff
andadamstankiewicz
as reviewers on this PR.Post-merge Checklist