From 98ca8f89e6eb810cc4a0e41737da4b719b1d3f60 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 23 May 2024 09:29:26 +0200 Subject: [PATCH] Use inline styles for menubar component Since we use shadow dom anyway we can just inline the styles and remove the necessity to precompile it. --- app/assets/config/alchemy_manifest.js | 1 - app/assets/stylesheets/alchemy/menubar.scss | 81 ------------ app/javascript/menubar.js | 10 -- app/views/alchemy/_menubar.html.erb | 139 ++++++++++++++++++-- spec/features/page_feature_spec.rb | 10 +- 5 files changed, 131 insertions(+), 110 deletions(-) delete mode 100644 app/assets/stylesheets/alchemy/menubar.scss delete mode 100644 app/javascript/menubar.js diff --git a/app/assets/config/alchemy_manifest.js b/app/assets/config/alchemy_manifest.js index c8bc5c8167..55c683627b 100644 --- a/app/assets/config/alchemy_manifest.js +++ b/app/assets/config/alchemy_manifest.js @@ -1,7 +1,6 @@ //= link alchemy/admin/all.css //= link alchemy/admin/all.js //= link alchemy/preview.js -//= link alchemy/menubar.css //= link alchemy/print.css //= link alchemy/welcome.css //= link tinymce/plugins/alchemy_link/plugin.min.js diff --git a/app/assets/stylesheets/alchemy/menubar.scss b/app/assets/stylesheets/alchemy/menubar.scss deleted file mode 100644 index 0684eefb5a..0000000000 --- a/app/assets/stylesheets/alchemy/menubar.scss +++ /dev/null @@ -1,81 +0,0 @@ -/* - *= require_self - */ - -@import "alchemy/variables"; -@import "alchemy/mixins"; - -#alchemy_menubar { - position: fixed; - top: 0; - left: -358px; - width: 400px; - z-index: 10000; - background: $main-menu-bg-color; - transition: left 0.25s cubic-bezier(0.23, 1, 0.32, 1); - box-shadow: 0 0 0 1px $white; - box-sizing: border-box; - height: auto; - padding: 8px 40px 8px 8px; - overflow: hidden; - font-family: $default-font-family; - font-size: $base-font-size; - - * { - box-sizing: border-box; - margin: 0; - padding: 0; - } - - &:hover { - left: 0; - } - - &:after { - content: ""; - width: 24px; - height: 24px; - position: absolute; - right: 10px; - top: 50%; - background: image-url("alchemy/icon-white.svg") 1px 1px no-repeat; - background-size: 24px 24px; - transform: translateY(-50%); - } - - ul { - padding: 0; - margin: 0; - height: 100%; - - li { - width: 33.333%; - height: 100%; - margin: 0; - padding: 0 $default-padding; - float: left; - list-style-type: none; - text-align: center; - - a, - button { - @include button-defaults( - $background-color: $main-menu-bg-color, - $hover-color: $blue, - $hover-border-color: $white, - $border: 1px solid $white, - $box-shadow: none, - $padding: 0.5em 0, - $margin: 0, - $color: $white - ); - width: 100%; - text-decoration: none !important; - - &:after { - display: none; - } - } - } - } -} diff --git a/app/javascript/menubar.js b/app/javascript/menubar.js deleted file mode 100644 index 369ec38019..0000000000 --- a/app/javascript/menubar.js +++ /dev/null @@ -1,10 +0,0 @@ -class Menubar extends HTMLElement { - constructor() { - super() - const template = this.querySelector("template") - const attachedShadowRoot = this.attachShadow({ mode: "open" }) - attachedShadowRoot.appendChild(template.content.cloneNode(true)) - } -} - -customElements.define("alchemy-menubar", Menubar) diff --git a/app/views/alchemy/_menubar.html.erb b/app/views/alchemy/_menubar.html.erb index 60c2ed012b..2c525ae5d0 100644 --- a/app/views/alchemy/_menubar.html.erb +++ b/app/views/alchemy/_menubar.html.erb @@ -1,20 +1,133 @@ <% if !Alchemy::Current.preview_page? && @page && can?(:edit_content, @page) %> - - <%= javascript_include_tag('menubar', type: "module") %> + + <% end %> diff --git a/spec/features/page_feature_spec.rb b/spec/features/page_feature_spec.rb index 988403adbb..90f9672ba5 100644 --- a/spec/features/page_feature_spec.rb +++ b/spec/features/page_feature_spec.rb @@ -114,25 +114,25 @@ it "a link to the admin area" do within find("alchemy-menubar").shadow_root do - expect(page).to have_selector("li a[href='#{alchemy.admin_dashboard_url(host: host)}']") + expect(page).to have_selector("a[href='#{alchemy.admin_dashboard_url(host: host)}']") end end it "a link to edit the current page" do within find("alchemy-menubar").shadow_root do expect(page).to \ - have_selector("li a[href='#{alchemy.edit_admin_page_url(public_page, host: host)}']") + have_selector("a[href='#{alchemy.edit_admin_page_url(public_page, host: host)}']") end end it "a form and button to logout of alchemy" do within find("alchemy-menubar").shadow_root do expect(page).to \ - have_selector("li form[action='#{Alchemy.logout_path}'][method='post']") + have_selector("form[action='#{Alchemy.logout_path}'][method='post']") expect(page).to \ - have_selector("li form[action='#{Alchemy.logout_path}'] > button[type='submit']") + have_selector("form[action='#{Alchemy.logout_path}'] > button[type='submit']") expect(page).to \ - have_selector("li form[action='#{Alchemy.logout_path}'] > input[type='hidden'][name='_method'][value='#{Alchemy.logout_method}']") + have_selector("form[action='#{Alchemy.logout_path}'] > input[type='hidden'][name='_method'][value='#{Alchemy.logout_method}']") end end end