-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Avoid inline css and js in dev #5315
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
mohe2015
wants to merge
1
commit into
DioxusLabs:main
Choose a base branch
from
mohe2015:csp-avoid-inline-js-and-css
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.
+174
−164
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* Inter Font */ | ||
| @import url('https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap') layer; | ||
|
|
||
| #dx-toast-template { | ||
| display: none; | ||
| visibility: hidden; | ||
| } | ||
|
|
||
| .dx-toast { | ||
| position: absolute; | ||
| top: 10px; | ||
| right: 0; | ||
| padding-right: 10px; | ||
| user-select: none; | ||
| /* transition: transform 0.2s ease; */ | ||
| z-index: 2147483647; | ||
| } | ||
|
|
||
| .dx-toast .dx-toast-inner { | ||
| /* transition: right 0.2s ease-out; */ | ||
| position: fixed; | ||
|
|
||
| background-color: #181B20; | ||
| color: #ffffff; | ||
| font-family: "Inter", sans-serif; | ||
|
|
||
| display: grid; | ||
| grid-template-columns: auto auto; | ||
| max-width: 400px; | ||
| min-height: 56px; | ||
| border-radius: 5px; | ||
| } | ||
|
|
||
| .dx-toast .dx-toast-inner { | ||
| cursor: pointer; | ||
| margin-right: 10px; | ||
| } | ||
|
|
||
| .dx-toast .dx-toast-level-bar-container { | ||
| height: 100%; | ||
| width: 6px; | ||
| } | ||
|
|
||
| .dx-toast .dx-toast-level-bar-container .dx-toast-level-bar { | ||
| width: 100%; | ||
| height: 100%; | ||
| border-radius: 5px 0px 0px 5px; | ||
| } | ||
|
|
||
| .dx-toast .dx-toast-content { | ||
| padding: 8px; | ||
| } | ||
|
|
||
| .dx-toast .dx-toast-header { | ||
| display: flex; | ||
| flex-direction: row; | ||
| justify-content: start; | ||
| align-items: end; | ||
| margin-bottom: 10px; | ||
| } | ||
|
|
||
| .dx-toast .dx-toast-header>svg { | ||
| height: 18px; | ||
| margin-right: 5px; | ||
| } | ||
|
|
||
| .dx-toast .dx-toast-header .dx-toast-header-text { | ||
| font-size: 14px; | ||
| font-weight: 700; | ||
| padding: 0; | ||
| margin: 0; | ||
| } | ||
|
|
||
| .dx-toast .dx-toast-msg { | ||
| font-size: 11px; | ||
| font-weight: 400; | ||
| padding: 0; | ||
| margin: 0; | ||
| } | ||
|
|
||
| .dx-toast-level-bar.info { | ||
| background-color: #428EFF; | ||
| } | ||
|
|
||
| .dx-toast-level-bar.success { | ||
| background-color: #42FF65; | ||
| } | ||
|
|
||
| .dx-toast-level-bar.error { | ||
| background-color: #FF4242; | ||
| } |
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,68 @@ | ||
| const STORAGE_KEY = "SCHEDULED-DX-TOAST"; | ||
| let currentTimeout = null; | ||
| let currentToastId = 0; | ||
|
|
||
| // Show a toast, removing the previous one. | ||
| function showDXToast(headerText, message, progressLevel, durationMs) { | ||
| const decor = document.getElementById("__dx-toast-decor"); | ||
| const text = document.getElementById("__dx-toast-text"); | ||
| const msg = document.getElementById("__dx-toast-msg"); | ||
| const inner = document.getElementById("__dx-toast-inner"); | ||
| const toast = document.getElementById("__dx-toast"); | ||
|
|
||
| if (decor) decor.className = `dx-toast-level-bar ${progressLevel}`; | ||
| if (text) text.innerText = headerText; | ||
| if (msg) msg.innerText = message; | ||
| if (inner) inner.style.right = "0"; | ||
| if (toast) { | ||
| toast.removeAttribute("aria-hidden"); | ||
| toast.addEventListener("click", closeDXToast); | ||
| } | ||
|
|
||
| // Wait a bit of time so animation plays correctly. | ||
| setTimeout( | ||
| () => { | ||
| let ourToastId = currentToastId; | ||
| currentTimeout = setTimeout(() => { | ||
| if (ourToastId == currentToastId) { | ||
| closeDXToast(); | ||
| } | ||
| }, durationMs); | ||
| }, | ||
| 100 | ||
| ); | ||
|
|
||
| currentToastId += 1; | ||
| } | ||
|
|
||
| // Schedule a toast to be displayed after reload. | ||
| function scheduleDXToast(headerText, message, level, durationMs) { | ||
| let data = { | ||
| headerText, | ||
| message, | ||
| level, | ||
| durationMs, | ||
| }; | ||
|
|
||
| let jsonData = JSON.stringify(data); | ||
| sessionStorage.setItem(STORAGE_KEY, jsonData); | ||
| } | ||
|
|
||
| // Close the current toast. | ||
| function closeDXToast() { | ||
| document.getElementById("__dx-toast-inner").style.right = "-1000px"; | ||
| document.getElementById("__dx-toast").setAttribute("aria-hidden", "true"); | ||
| clearTimeout(currentTimeout); | ||
| } | ||
|
|
||
| // Handle any scheduled toasts after reload. | ||
| let potentialData = sessionStorage.getItem(STORAGE_KEY); | ||
| if (potentialData) { | ||
| sessionStorage.removeItem(STORAGE_KEY); | ||
| let data = JSON.parse(potentialData); | ||
| showDXToast(data.headerText, data.message, data.level, data.durationMs); | ||
| } | ||
|
|
||
| window.scheduleDXToast = scheduleDXToast; | ||
| window.showDXToast = showDXToast; | ||
| window.closeDXToast = closeDXToast; |
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
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.
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'm aware that this is technically a breaking change but I think we should do it as it avoids bugs where these imports only work depending on from where you import. This way they either work all the time or not at all.