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

Toast component #148

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

Toast component #148

wants to merge 24 commits into from

Conversation

vonwao
Copy link
Collaborator

@vonwao vonwao commented Jun 20, 2024

No description provided.

@vonwao vonwao added the WIP Work In Progress label Jun 20, 2024
Comment on lines 1 to 10
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accessible Toast Notifications</title>
<link rel="stylesheet" href="toast.css">
<link rel="stylesheet" href="app.css">
</head>
<body>
Copy link
Collaborator

Choose a reason for hiding this comment

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

These elements shouldn't be included in this /content/body/toast.php file. They would either already be automatically included when the page is initially compiled, or should be included in the /content/head/toast.php file.

{
"label": "Create markup",
"highlight": "data-tooltip",
"notes": "Our script uses the <code>data-tooltip</code> attribute instead of the <code>title</code> attribute, since <strong>title</strong> is rendered by user agents by default and cannot be styled."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't the data-tooltip just a attribute that the Enable custom tooltip component uses? I don't think that sites that are missing the Enable custom tooltip will know what to do with this attribute.

Comment on lines 2 to 4
@margin: 20px;
@gap: 10px;
@font-size: 16px;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of pixels, you should be using rem or em units in order to make text resizing be possible. This is especially important for font sizes.

Suggested change
@margin: 20px;
@gap: 10px;
@font-size: 16px;
@margin: 1.25rem;
@gap: 0.625rem;
@font-size: 1rem;

Comment on lines +4 to +14
@toast-padding: 10px;
@toast-border-radius: 5px;
@toast-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
@toast-transition: all 0.5s ease-in-out;
@toast-close-color: @toast-color;
@toast-close-hover-color: #ff0000;
@rack-background: rgba(241, 241, 241, 0.9);
@rack-border: 1px solid #ddd;
@rack-padding: 10px;
@rack-width: 300px;
@rack-max-height: 400px;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, consider using rem or em units instead of pixels whenever you can in this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For this and above, I am okay with just font-sizing and anything needed for that done in rems. For margins, padding, etc, it is okay to use px as long as it doesn't affect legibility (although it is not wrong to do so if it is more aesthetically pleasing).

less/toast.less Outdated

&.bottom-right,
&.bottom-left,
&.bottom-center {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Most of Enable is written using BEM. The structure should be like:

.toast {

&__container {

 &--bottom-right {
 
 }

}

&__rack {

}

(This is not exhaustive .. it's just an example)

concat.py Outdated Show resolved Hide resolved
concat.txt Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this for?

<li>Toasts should support different levels of severity (normal, error, warning, success), each with a unique color for visual distinction.</li>
</ol>
<p>
Our implementation ensures that toasts are fully accessible and follow best practices for ARIA and keyboard interaction. When a toast appears, it is announced to screen readers. Toasts can be configured to stay visible for a set amount of time or until manually dismissed by the user. Additionally, all toasts are stored in a toast rack for future reference.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may want to remove the set amount of time part. Let's discuss on your demo.

css/app.css Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. This is not a LESS file. All CSS must be in LESS.
  2. The name app.css is not specific. It should describe what it's used for. Is this for the demo, or the component?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is an old issue, both less and css files are in repository, which I think is the correct pattern

import toastModule from '../modules/toast.js';

const app = new (function () {
console.log('toast demo!!!');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove. I am surprised this wasn't caught by unit testing.


// Initialize the toast rack
this.rackContent = document.getElementById('rackContent');
this.toggleRackButton = document.getElementById('toggleRackButton');
Copy link
Collaborator

Choose a reason for hiding this comment

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

All CSS classes and IDs should be namespaced.

Use something like #enable-toast__rack-content and #enable-toast__rack-back-button.


// Update the visible toasts according to the max visible limit
updateVisibleToasts() {
console.log("Updating visible toasts");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoid keeping console.log() statements in your code. If they are absolutely necessary, use console.info(). I don't think this is, though.

this.visibleQueue.forEach((toast, index) => {
const toastElement = this.container.querySelector(`[data-id="${toast.id}"]`);
if (index < this.maxVisible) {
toastElement.classList.add('toast-visible');
Copy link
Collaborator

Choose a reason for hiding this comment

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

CSS classes should enforce BEM:

enable-toast--visible

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry -- all the comments for the ES4 code was meant for this file.

@font-size: 1rem; // 16px converted to rem

// Controls styles
.controls {
Copy link
Collaborator

Choose a reason for hiding this comment

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

BEM should be used here. Let's fix this and the toast.less file. Discuss with me if you need guidance.

less/toast.less Outdated

&.enable-toast__container--bottom-right,
&.enable-toast__container--bottom-left,
&.enable-toast__container--bottom-center {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should just use

    &__container--bottom-right,
    &__container--bottom-left,
    &__container--bottom-center {
    
    ...
    
    }

The point of BEM is ensure the components DOM structure can be changed completely and things will be styled the same. While this may not be a concern here, it is a concern for the selectors below.

What is relevant here is that BEM also flattens CSS specificity.

Let's talk when you have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work In Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants