From 9089589d3623bb7bf7299005bbdcd67a4db4fe3a Mon Sep 17 00:00:00 2001 From: BordedDev <> Date: Sun, 9 Mar 2025 00:21:50 +0100 Subject: [PATCH] Made input styling shared --- src/snek/static/base.css | 3 +- src/snek/static/generic-form.js | 33 ++++++++------ src/snek/static/shared.css | 15 +++++++ src/snek/static/style.css | 76 +++++++++++++++++---------------- src/snek/templates/base.html | 1 + 5 files changed, 78 insertions(+), 50 deletions(-) create mode 100644 src/snek/static/shared.css diff --git a/src/snek/static/base.css b/src/snek/static/base.css index 3d154a9..70dd7ad 100644 --- a/src/snek/static/base.css +++ b/src/snek/static/base.css @@ -1,3 +1,5 @@ +@import "shared.css"; + * { margin: 0; box-sizing: border-box; @@ -342,4 +344,3 @@ a { .sidebar ul li a:hover { color: #fff; } - diff --git a/src/snek/static/generic-form.js b/src/snek/static/generic-form.js index 319d7d3..3a702d5 100644 --- a/src/snek/static/generic-form.js +++ b/src/snek/static/generic-form.js @@ -21,6 +21,24 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +const getAdoptionStyles = () => { + return Array.from(document.styleSheets) + .filter((styleSheet) => styleSheet.href?.endsWith("shared.css")) + .map(x => { + const sheet = new CSSStyleSheet(); + + sheet.replaceSync(Array.from(x.cssRules).flatMap(rule => { + if (rule instanceof CSSImportRule) { + return Array.from(rule.styleSheet.cssRules).map(rule => rule.cssText); + } else { + return rule.cssText; + } + }).join(' ')); + + return sheet; + }); +} + class GenericField extends HTMLElement { form = null; field = null; @@ -83,18 +101,6 @@ class GenericField extends HTMLElement { background-color: #1a1a1a; color: #e6e6e6; font-size: 1em; - - &:focus { - outline: 2px solid #f05a28 !important; - } - - &::placeholder { - transition: opacity 0.3s; - } - - &:focus::placeholder { - opacity: 0.4; - } } button { @@ -155,6 +161,9 @@ class GenericField extends HTMLElement { this.container.appendChild(this.styleElement); this.shadowRoot.appendChild(this.container); + + + this.shadowRoot.adoptedStyleSheets = getAdoptionStyles(); } connectedCallback() { diff --git a/src/snek/static/shared.css b/src/snek/static/shared.css new file mode 100644 index 0000000..d7a652b --- /dev/null +++ b/src/snek/static/shared.css @@ -0,0 +1,15 @@ + + +input, textarea { + &:focus { + outline: 2px solid #f05a28 !important; + } + + &::placeholder { + transition: opacity 0.3s; + } + + &:focus::placeholder { + opacity: 0.4; + } +} diff --git a/src/snek/static/style.css b/src/snek/static/style.css index 63a28ed..705aea7 100644 --- a/src/snek/static/style.css +++ b/src/snek/static/style.css @@ -1,55 +1,57 @@ +@import "shared.css"; * { - - box-sizing: border-box; + box-sizing: border-box; +} + +.dialog { + background-color: #0f0f0f; + border-radius: 10px; + padding: 30px; + width: 800px; + margin: 30px; + box-shadow: 0 0 15px rgba(0, 0, 0, 0.5); +} + +@media screen and (max-width: 500px) { + .center { + width: 100%; + left: 0px; } .dialog { - - background-color: #0f0f0f; - border-radius: 10px; - padding: 30px; - width: 800px; - margin: 30px; - box-shadow: 0 0 15px rgba(0, 0, 0, 0.5); -} - - @media screen and (max-width: 500px) { - .center { - width: 100%; - left: 0px; - } - .dialog { - width: 100%; - left: 0px; - } - + width: 100%; + left: 0px; } +} + h1 { - font-size: 2em; - color: #f05a28; - margin-bottom: 20px; + font-size: 2em; + color: #f05a28; + margin-bottom: 20px; } h2 { - font-size: 1.4em; - color: #f05a28; - margin-bottom: 20px; + font-size: 1.4em; + color: #f05a28; + margin-bottom: 20px; } + body { - font-family: Arial, sans-serif; - background-color: #1a1a1a; - color: #e6e6e6; - line-height: 1.5; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - min-height: 100vh; + font-family: Arial, sans-serif; + background-color: #1a1a1a; + color: #e6e6e6; + line-height: 1.5; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + min-height: 100vh; } + div { - text-align: left; + text-align: left; } \ No newline at end of file diff --git a/src/snek/templates/base.html b/src/snek/templates/base.html index d93b568..7d10aab 100644 --- a/src/snek/templates/base.html +++ b/src/snek/templates/base.html @@ -20,6 +20,7 @@ + {% block head %} {% endblock %}