forked from PrestaShop/autoupgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refacto to use native html dialog + js
- Loading branch information
Showing
27 changed files
with
332 additions
and
203 deletions.
There are no files selected for viewing
This file contains 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,128 @@ | ||
@use "../variables" as *; | ||
|
||
$e: ".dialog"; | ||
|
||
@at-root { | ||
::backdrop { | ||
background-color: rgba(0, 0, 0, 0.5); | ||
} | ||
} | ||
|
||
#{$ua-id} { | ||
#{$e} { | ||
border: none; | ||
border: none; | ||
box-shadow: var(--#{$ua-prefix}box-shadow-modal); | ||
width: 508px; | ||
max-width: calc(100% - 2rem); | ||
|
||
&__content { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1.5rem; | ||
} | ||
|
||
&__header { | ||
display: flex; | ||
gap: 1rem; | ||
align-items: center; | ||
width: 100%; | ||
padding: 1.5rem; | ||
padding-block-end: 0; | ||
border: none; | ||
|
||
.close { | ||
flex-shrink: 0; | ||
float: none; | ||
margin: 0; | ||
margin-inline-start: auto; | ||
opacity: 1; | ||
color: var(--#{$ua-prefix}base-text-color); | ||
cursor: pointer; | ||
|
||
&:hover { | ||
color: var(--#{$ua-prefix}base-text-color-hover); | ||
} | ||
|
||
.material-icons { | ||
font-size: 1.5rem; | ||
} | ||
} | ||
} | ||
|
||
&__body { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1.5rem; | ||
padding-block: 0; | ||
padding-inline: 1.5rem; | ||
font-size: 1rem; | ||
line-height: 1.375; | ||
} | ||
|
||
&__footer { | ||
padding: 1.5rem; | ||
padding-block-start: 0; | ||
border: none; | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: flex-end; | ||
gap: 1rem; | ||
} | ||
|
||
// Custom modals | ||
&__spacer { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1.5rem; | ||
} | ||
|
||
&__no-backup { | ||
margin-block: 0; | ||
|
||
label { | ||
font-weight: 400; | ||
} | ||
} | ||
|
||
&__rocket-icon { | ||
width: 1.425em; | ||
height: 1.425em; | ||
} | ||
|
||
&__error-report-form { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.5rem; | ||
} | ||
|
||
&--md { | ||
width: 904px; | ||
max-width: calc(100% - 2rem); | ||
} | ||
|
||
&--lg { | ||
width: 1127px; | ||
max-width: calc(100% - 2rem); | ||
} | ||
|
||
&--danger { | ||
#{$e}__header { | ||
&::before { | ||
content: "\e872"; | ||
display: flex; | ||
flex-shrink: 0; | ||
align-items: center; | ||
justify-content: center; | ||
width: 2.5rem; | ||
height: 2.5rem; | ||
background-color: var(--#{$ua-prefix}red-50); | ||
border-radius: 999px; | ||
font-family: var(--#{$ua-prefix}font-family-material-icons); | ||
font-size: 1.5rem; | ||
font-weight: 400; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import ModalContainer from './components/ModalContainer'; | ||
import DialogContainer from './components/DialogContainer'; | ||
import RouteHandler from './routing/RouteHandler'; | ||
import ScriptHandler from './routing/ScriptHandler'; | ||
|
||
export const routeHandler = new RouteHandler(); | ||
|
||
export const modalContainer = new ModalContainer(); | ||
export const dialogContainer = new DialogContainer(); | ||
export const scriptHandler = new ScriptHandler(); | ||
|
||
export default { routeHandler, scriptHandler, modalContainer }; | ||
export default { routeHandler, scriptHandler, dialogContainer }; |
This file contains 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,61 @@ | ||
import DomLifecycle from '../types/DomLifecycle'; | ||
import Hydration from '../utils/Hydration'; | ||
|
||
export default class DialogContainer implements DomLifecycle { | ||
public static readonly cancelEvent = 'cancel'; | ||
public static readonly okEvent = 'ok'; | ||
|
||
public static readonly containerId = 'ua_dialog'; | ||
|
||
public mount(): void { | ||
this.DialogContainer.addEventListener(Hydration.hydrationEventName, this.#displayDialog); | ||
this.DialogContainer.addEventListener('click', this.#onClick); | ||
this.DialogContainer.addEventListener(DialogContainer.cancelEvent, this.#closeDialog); | ||
this.DialogContainer.addEventListener(DialogContainer.okEvent, this.#closeDialog); | ||
} | ||
|
||
public beforeDestroy(): void { | ||
this.DialogContainer.removeEventListener(Hydration.hydrationEventName, this.#displayDialog); | ||
this.DialogContainer.removeEventListener('click', this.#onClick); | ||
this.DialogContainer.removeEventListener(DialogContainer.cancelEvent, this.#closeDialog); | ||
this.DialogContainer.removeEventListener(DialogContainer.okEvent, this.#closeDialog); | ||
} | ||
|
||
public get DialogContainer(): HTMLElement { | ||
const container = document.getElementById(DialogContainer.containerId); | ||
|
||
if (!container) { | ||
throw new Error('Cannot find dialog container to initialize.'); | ||
} | ||
return container; | ||
} | ||
|
||
#displayDialog(): void { | ||
const dialog = document.getElementById(DialogContainer.containerId)?.getElementsByClassName('dialog')[0] as HTMLDialogElement; | ||
if (dialog) { | ||
dialog.showModal(); | ||
} | ||
} | ||
|
||
#onClick(ev: Event): void { | ||
const target = ev.target ? (ev.target as HTMLElement) : null; | ||
const dialog = target?.closest('.dialog'); | ||
|
||
if (dialog) { | ||
if (target?.closest("[data-dismiss='dialog']")) { | ||
dialog.dispatchEvent(new Event(DialogContainer.cancelEvent, { bubbles: true })); | ||
} else if (!dialog.contains(target) || target === dialog) { | ||
dialog.dispatchEvent(new Event(DialogContainer.cancelEvent, { bubbles: true })); | ||
} else if (target?.closest(".dialog__footer button:not([data-dismiss='dialog'])")) { | ||
dialog.dispatchEvent(new Event(DialogContainer.okEvent, { bubbles: true })); | ||
} | ||
} | ||
} | ||
|
||
#closeDialog(ev: Event): void { | ||
const dialog = ev.target as HTMLDialogElement; | ||
if (dialog) { | ||
dialog.close(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
_dev/src/ts/modals/StartUpdateModal.ts → _dev/src/ts/dialogs/StartUpdateDialog.ts
This file contains 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 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 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 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
Oops, something went wrong.