-
-
Notifications
You must be signed in to change notification settings - Fork 175
Add toast notification component with JS init, template, examples, migration, and tests #1360
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
Open
lovasoa
wants to merge
5
commits into
main
Choose a base branch
from
ajouter-un-composant-toast-olb490
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f551bc
Support hash-triggered toasts
lovasoa 5743665
Address toast review feedback
lovasoa 500e2f3
Render toast positioning in template
lovasoa 93c9f08
Avoid reopening initialized toasts
lovasoa 276b968
Fix white toast foreground color
lovasoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| INSERT INTO component(name, icon, description, introduced_in_version) VALUES | ||
| ('toast', 'notification', ' | ||
| Displays a brief notification above the page. Each top-level `toast` row creates one notification, and consecutive toasts at the same position are queued in a shared stack. | ||
|
|
||
| Ordinary notifications use `role="status"` and `aria-live="polite"`. Colored variants retain a readable contrasting foreground. Automatic dismissal and the manual close control are configured independently.', '0.46.0'); | ||
|
|
||
| INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'toast', * FROM (VALUES | ||
| ('title', 'Optional notification heading.', 'TEXT', TRUE, TRUE), | ||
| ('description', 'Escaped plain-text body. This is used only when `description_md` is not supplied.', 'TEXT', TRUE, TRUE), | ||
| ('description_md', 'Rich-text alternative to `description`, rendered as Markdown. When both properties are supplied, `description_md` takes precedence.', 'TEXT', TRUE, TRUE), | ||
| ('icon', 'Optional [Tabler icon](https://tabler.io/icons) name.', 'ICON', TRUE, TRUE), | ||
| ('color', 'Optional Tabler color. The default is the neutral toast appearance; colored variants use the matching contrasting foreground utility.', 'COLOR', TRUE, TRUE), | ||
| ('dismissible', 'Whether to render an accessible manual close button. Defaults to true and is independent of automatic dismissal.', 'BOOLEAN', TRUE, TRUE), | ||
| ('duration', 'Automatic dismissal delay in milliseconds. Defaults to 5000. Set to 0 to keep the toast visible until manually dismissed (when `dismissible` is true) or the page is left.', 'INTEGER', TRUE, TRUE), | ||
| ('position', 'Screen placement: `top-start`, `top-center`, `top-end`, `bottom-start`, `bottom-center`, or `bottom-end`. Defaults to `top-end`; invalid values safely fall back to that default.', 'TEXT', TRUE, TRUE), | ||
| ('trigger', 'Optional URL fragment that opens the toast without reloading the page, with or without the leading `#`. When set, the toast does not open on page load and can be opened repeatedly by a link or button whose target is that fragment. Multiple toasts can share a trigger to open as a stack.', 'TEXT', TRUE, TRUE), | ||
| ('id', 'Optional stable HTML ID for the toast.', 'TEXT', TRUE, TRUE), | ||
| ('class', 'Optional custom CSS class appended to the toast.', 'TEXT', TRUE, TRUE) | ||
| ) x; | ||
|
|
||
| INSERT INTO example(component, description, properties) VALUES | ||
| ('toast', 'A toast that opens when the page loads and disappears automatically after the default 5000 milliseconds.', json('[ | ||
| {"component":"toast","id":"toast-auto","title":"This is a SQLPage toast","description":"This toast will open automatically when the page loads.","icon":"check","color":"green"} | ||
| ]')), | ||
| ('toast', 'A persistent error notification that disables automatic dismissal and requires the user to activate its close button.', json('[ | ||
| {"component":"toast","id":"toast-dismissible","trigger":"persistent-error","title":"Could not save","description":"Review the highlighted fields and try again.","icon":"alert-triangle","color":"black","duration":0,"dismissible":true}, | ||
| {"component":"toast","id":"toast-nondismissible","trigger":"persistent-status","title":"Connection unavailable","description":"This persistent notification has no manual close control.","duration":0,"dismissible":false}, | ||
| {"component":"button"}, | ||
| {"title":"Show dismissible error","link":"#persistent-error","color":"red"}, | ||
| {"title":"Show non-dismissible status","link":"#persistent-status"} | ||
| ]')), | ||
| ('toast', 'A persistent rich Markdown notification. Markdown takes precedence over plain text and renders emphasis and a link as HTML, while plain-text content remains escaped.', json('[ | ||
| {"component":"toast","id":"toast-markdown","trigger":"rich-notifications","title":"Release available","description":"<strong>This fallback stays escaped</strong>","description_md":"Version **2.0** is ready. [Read the notes](https://example.com/releases).","color":"blue","duration":0}, | ||
| {"component":"toast","id":"toast-plain","trigger":"rich-notifications","description":"<strong>Plain text stays escaped</strong>","color":"white","duration":0}, | ||
| {"component":"button"}, | ||
| {"title":"Show rich notifications","link":"#rich-notifications"} | ||
| ]')), | ||
| ('toast', 'Several persistent queued notifications. Toasts with the same position share a container and stack instead of overlapping.', json('[ | ||
| {"component":"toast","id":"toast-stack-one","trigger":"queued notifications","title":"Import started","description":"Preparing records.","duration":0}, | ||
| {"component":"toast","id":"toast-stack-two","trigger":"queued notifications","title":"Import running","description":"Processing records.","duration":0}, | ||
| {"component":"toast","id":"toast-short","trigger":"queued notifications","title":"Temporary update","description":"This message closes shortly.","duration":2000}, | ||
| {"component":"button"}, | ||
| {"title":"Show queued notifications","link":"#queued notifications"} | ||
| ]')), | ||
| ('toast', 'A notification placed at the bottom center of the screen instead of the default top end.', json('[ | ||
| {"component":"toast","id":"toast-bottom-center","trigger":"bottom-notification","title":"Download ready","description":"Your export is ready.","position":"bottom-center","duration":0}, | ||
| {"component":"button"}, | ||
| {"title":"Show bottom notification","link":"#bottom-notification"} | ||
| ]')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <div data-pre-init="toast-container" | ||
| {{~#if (eq position 'top-start')}} class="toast-container position-fixed p-3 top-0 start-0" data-sqlpage-toast-position="top-start" | ||
| {{~else}}{{#if (eq position 'top-center')}} class="toast-container position-fixed p-3 top-0 start-50 translate-middle-x" data-sqlpage-toast-position="top-center" | ||
| {{~else}}{{#if (eq position 'bottom-start')}} class="toast-container position-fixed p-3 bottom-0 start-0" data-sqlpage-toast-position="bottom-start" | ||
| {{~else}}{{#if (eq position 'bottom-center')}} class="toast-container position-fixed p-3 bottom-0 start-50 translate-middle-x" data-sqlpage-toast-position="bottom-center" | ||
| {{~else}}{{#if (eq position 'bottom-end')}} class="toast-container position-fixed p-3 bottom-0 end-0" data-sqlpage-toast-position="bottom-end" | ||
| {{~else}} class="toast-container position-fixed p-3 top-0 end-0" data-sqlpage-toast-position="top-end"{{/if}}{{/if}}{{/if}}{{/if}}{{/if}}> | ||
| <div{{#if id}} id="{{id}}"{{/if}} class="toast{{#if color}} toast-colored bg-{{color}} text-{{color}}-fg{{/if}}{{#if class}} {{class}}{{/if}}" role="status" aria-live="polite" aria-atomic="true" data-pre-init="toast" data-duration="{{default duration 5000}}"{{#if trigger}} data-toast-trigger="{{trigger}}"{{/if}}> | ||
|
lovasoa marked this conversation as resolved.
|
||
| <div class="toast-body d-flex align-items-start gap-2"> | ||
| {{~#if icon~}} | ||
| <span class="flex-shrink-0" aria-hidden="true">{{~icon_img icon~}}</span> | ||
| {{~/if~}} | ||
| <div class="flex-fill overflow-auto"> | ||
| {{~#if title~}}<div class="fw-bold mb-1">{{title}}</div>{{~/if~}} | ||
| {{~#if description_md~}} | ||
| <div class="toast-description toast-description-markdown">{{{markdown description_md}}}</div> | ||
|
lovasoa marked this conversation as resolved.
|
||
| {{~else~}} | ||
| {{~#if description~}}<div class="toast-description">{{description}}</div>{{~/if~}} | ||
| {{~/if~}} | ||
| </div> | ||
| {{~#if (default dismissible true)~}} | ||
| <button type="button" class="btn-close flex-shrink-0" data-bs-dismiss="toast" aria-label="Close notification"></button> | ||
| {{~/if~}} | ||
| </div> | ||
| </div> | ||
| </div> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.