-
-
Notifications
You must be signed in to change notification settings - Fork 20
feat: Add support for dialogs #680
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
base: main
Are you sure you want to change the base?
Changes from all commits
8639720
4dfaab2
ef23d16
146546c
c0046e3
79e1d3c
0014b52
c9f9a0c
ea75e56
6e968d3
7fcbbc1
930dc73
46069eb
aea2d39
9234929
c04e69e
52ece10
6a19bf9
1cda054
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { | ||
| openOverlay, | ||
| closeOverlay, | ||
| addOverlayClickListener, | ||
| } from "./overlay.js"; | ||
|
|
||
| function getCloseButton(dialog) { | ||
| return dialog.querySelector(".o-dialog__header > .a-button"); | ||
| } | ||
|
|
||
| function openDialog(dialogId) { | ||
| const dialog = document.getElementById(dialogId); | ||
| if (!dialog) return; | ||
|
|
||
| dialog.show(); | ||
| openOverlay("dialog"); | ||
|
|
||
| const closeButton = getCloseButton(dialog); | ||
| if (closeButton) { | ||
| closeButton.addEventListener("click", () => closeDialog(dialog)); | ||
| } | ||
| } | ||
|
|
||
| function closeDialog(dialog) { | ||
MoritzWeber0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const closeButton = getCloseButton(dialog); | ||
| if (closeButton) { | ||
| closeButton.replaceWith(closeButton.cloneNode(true)); | ||
| } | ||
| dialog.close(); | ||
| closeOverlay(); | ||
| } | ||
|
|
||
| function closeAllDialogs() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could there be more than one open dialog? do you think of a dialog in a dialog? 😅
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say that we shouldn't do that. And if we do so, we can still update the implementation, but it makes it a bit more complex if we need to track which dialog is the one with the highest z-index. |
||
| document.querySelectorAll("dialog[open]").forEach((dialog) => { | ||
| closeDialog(dialog); | ||
| }); | ||
| } | ||
|
|
||
| function initDialogs() { | ||
| document.querySelectorAll("[data-dialog-trigger]").forEach((trigger) => { | ||
| const handler = (e) => { | ||
| if (e.type === "click" || (e.type === "keydown" && e.key === "Enter")) { | ||
| e.preventDefault(); | ||
| const dialogId = trigger.getAttribute("data-dialog-trigger"); | ||
| openDialog(dialogId); | ||
| } | ||
| }; | ||
|
|
||
| trigger.addEventListener("click", handler); | ||
| trigger.addEventListener("keydown", handler); | ||
| }); | ||
|
|
||
| addOverlayClickListener(() => { | ||
| closeAllDialogs(); | ||
| }); | ||
|
|
||
| document.addEventListener("keydown", (e) => { | ||
| if (e.key === "Escape") { | ||
| closeAllDialogs(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| if (document.readyState === "loading") { | ||
| document.addEventListener("DOMContentLoaded", initDialogs); | ||
| } else { | ||
| initDialogs(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| .o-dialog { | ||
| max-height: calc(100dvh - 14rem); | ||
| overflow: auto; | ||
| display: flex; | ||
| flex-direction: column; | ||
|
|
||
| .a-anchorlink { | ||
| margin-bottom: 0; | ||
|
|
||
| &__link { | ||
| display: none; | ||
| } | ||
|
|
||
| > h2 { | ||
| margin-bottom: 1rem; | ||
| } | ||
| } | ||
|
|
||
| .o-divider { | ||
| display: none; | ||
| } | ||
|
|
||
| &__wrapper { | ||
| width: fit-content; | ||
| position: fixed; | ||
| top: 7rem; | ||
| border: none; | ||
| padding: 0; | ||
| background-color: var(--bg-default); | ||
| color: var(--color-body); | ||
| border-radius: var(--border-radius-m); | ||
| z-index: 12; | ||
| border: var(--border); | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| &__header { | ||
MoritzWeber0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| position: sticky; | ||
| top: 0; | ||
| background-color: var(--bg-default); | ||
| display: flex; | ||
| column-gap: 1rem; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| padding: 1rem 1rem 1rem 2rem; | ||
| border-bottom: var(--border); | ||
| border-color: var(--color-table-border); | ||
|
|
||
| .o-divider { | ||
| display: none; | ||
| } | ||
|
|
||
| > h1 { | ||
| margin: 0; | ||
| font-size: 2.2rem; | ||
| } | ||
| } | ||
|
|
||
| &__body { | ||
| padding: 2rem; | ||
| overflow: auto; | ||
|
|
||
| > *:last-child { | ||
| margin-bottom: 0; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,4 @@ | |
| @import "tag.scss"; | ||
| @import "floatImage.scss"; | ||
| @import "teamMember.scss"; | ||
| @import "dialog.scss"; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,17 @@ | ||
| <a | ||
| href="{{ .Destination }}" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| class="a-button o-link__external" | ||
| > | ||
| {{- .Text -}}{{- partial "icon" "arrow_outward" -}} | ||
| </a> | ||
| {{ if .Destination }} | ||
| <a | ||
| href="{{ .Destination }}" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| class="a-button a-button__external o-link__external" | ||
| > | ||
| {{- .Text -}}{{- partial "icon" "arrow_outward" -}} | ||
| </a> | ||
| {{ else }} | ||
| <button | ||
| class="a-button a-button__internal" | ||
| {{- with .Title }}title="{{ . }}"{{- end -}} | ||
| > | ||
| {{- .Text -}} | ||
| </button> | ||
| {{ end }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <dialog | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i’m wondering, why the dialog is
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I initially used the modal dialog implementation, opened via
There is a workaround, described here: https://stackoverflow.com/a/73988585. But it's not pretty and we wouldn't be able to use our overlay. So I went for a normal dialog with out own overlay, but then modal is not set. Maybe we can tune it manually via some attributes. Where do you see the modal setting in Edge? |
||
| id="{{ .ID }}" | ||
| class="o-dialog__wrapper" | ||
| aria-labelledby="{{ .ID }}-title" | ||
| > | ||
| <div class="o-dialog o-container"> | ||
| <header class="o-dialog__header"> | ||
| <h1 id="{{ .ID }}-title" class="o-dialog__title">{{ .Title }}</h1> | ||
| {{- partial "button" (dict "Text" (partial "icon" "close") "Title" (i18n "dialog.close")) -}} | ||
| </header> | ||
| <div class="o-dialog__body"> | ||
| {{- partial "increase-headings" (dict "content" .Content) | safeHTML -}} | ||
| </div> | ||
| </div> | ||
| </dialog> | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.