Skip to content

Commit

Permalink
Merge pull request #2595 from AlchemyCMS/shoelaces
Browse files Browse the repository at this point in the history
Use Shoelace Tab for tabs
  • Loading branch information
tvdeyen authored Oct 12, 2023
2 parents 214ed21 + 1a9adc9 commit 30b7570
Show file tree
Hide file tree
Showing 25 changed files with 165 additions and 557 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/alchemy/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//= require jquery-ui/effects/effect-fade
//= require jquery-ui/widgets/draggable
//= require jquery-ui/widgets/sortable
//= require jquery-ui/widgets/tabs
//= require tinymce/tinymce.min
//= require_tree ../../../../vendor/assets/javascripts/jquery_plugins/
//= require clipboard.min
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/alchemy/alchemy.dialog.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class window.Alchemy.Dialog
# Initializes the Dialog body
init: ->
Alchemy.GUI.init(@dialog_body)
$('#overlay_tabs', @dialog_body).tabs()
@watch_remote_forms()

# Watches ajax requests inside of dialog body and replaces the content accordingly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ Alchemy.ElementEditors =

# Selects tab for given element
selectTabForElement: ($element) ->
$tabs = $("#fixed-elements .sortable-elements")
if $tabs.size() > 0
$tab = $element.closest(".sortable-elements")
$("#fixed-elements").tabs("option", "active", $tabs.index($tab))
tabs = document.querySelector("#fixed-elements")
if tabs
panel = $element.closest("sl-tab-panel").attr("name")
tabs.show(panel)
return

# Marks an element as selected in the element window and scrolls to it.
#
Expand Down
57 changes: 32 additions & 25 deletions app/assets/javascripts/alchemy/alchemy.fixed_elements.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
window.Alchemy = Alchemy || {};
window.Alchemy = Alchemy || {}

Alchemy.FixedElements = {
WRAPPER: '<div id="fixed-elements"></div>',
TABS: '<ul><li><a href="#main-content-elements">{{label}}</a></li></ul>',
WRAPPER: '<sl-tab-group id="fixed-elements" />',
TABS: '<sl-tab slot="nav" panel="main-content-elements">{{label}}</sl-tab>',

// Builds fixed elements tabs
buildTabs: function(label) {
buildTabs: function (label) {
var $wrapper = $(this.WRAPPER),
$tabs = $(this.TABS.replace(/{{label}}/, label));
$tabs = $(this.TABS.replace(/{{label}}/, label))

$('#main-content-elements').wrap($wrapper);
$('#fixed-elements').prepend($tabs).tabs().tabs('paging', {
follow: true,
followOnSelect: true
});
$("#main-content-elements").wrap($wrapper)
$("#fixed-elements").prepend($tabs)
},

// Creates a fixed element tab.
createTab: function(element_id, label) {
var $fixed_elements = $('#fixed-elements'),
$tab;

$('> ul', $fixed_elements).append('<li><a href="#fixed-element-' + element_id + '">' + label + '</a></li>');
$tab = $('<div id="fixed-element-' + element_id + '" class="sortable-elements" />');
$fixed_elements.append($tab);
$fixed_elements.tabs().tabs('refresh');
$fixed_elements.tabs('option', 'active', $('#fixed-elements > div').index($tab));
createTab: function (element_id, label) {
var $fixed_elements = $("#fixed-elements")
var panel_name = "fixed-element-" + element_id

var $tab =
'<sl-tab slot="nav" panel="' + panel_name + '">' + label + "</sl-tab>"
$fixed_elements.append($tab)

var $panel = $(
'<sl-tab-panel name="' + panel_name + '" class="sortable-elements" />'
)
$fixed_elements.append($panel)
window.requestAnimationFrame(function () {
$fixed_elements.get(0).show(panel_name)
})
},

removeTab: function(element_id) {
var $fixed_elements = $('#fixed-elements');
removeTab: function (element_id) {
var $fixed_elements = $("#fixed-elements")

$fixed_elements.find('a[href="#fixed-element-' + element_id + '"]').parent().remove();
$fixed_elements.find('div#fixed-element-' + element_id).remove();
$fixed_elements.tabs().tabs('refresh');
$fixed_elements
.find('sl-tab[panel="fixed-element-' + element_id + '"]')
.remove()
$fixed_elements
.find('sl-tab-panel[name="fixed-element-' + element_id + '"]')
.remove()
$fixed_elements.get(0).show("main-content-elements")
}
};
}
12 changes: 6 additions & 6 deletions app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -183,27 +183,27 @@ class window.Alchemy.LinkDialog extends Alchemy.Dialog
# Checking of what kind the link is (internal, external or file).
if @$link.hasClass('external')
# Handles an external link.
tab = $('#overlay_tab_external_link')
tab = 'overlay_tab_external_link'
@$external_link.val(@$link.attr('href'))
else if @$link.hasClass('file')
# Handles a file link.
tab = $('#overlay_tab_file_link')
tab = 'overlay_tab_file_link'
@$file_link.select2('val', @$link[0].pathname + @$link[0].search)
else if @$link.attr('href').match(/^#/)
# Handles an anchor link.
tab = $('#overlay_tab_anchor_link')
tab = 'overlay_tab_anchor_link'
@$anchor_link.select2('val', @$link.attr('href'))
else if @$link.hasClass('internal')
# Handles an internal link.
tab = $('#overlay_tab_internal_link')
tab = 'overlay_tab_internal_link'
@initInternalLinkTab()
else
# Emit an event to allow extensions hook into the link overlay.
@$overlay_tabs.trigger 'SelectLinkTab.Alchemy',
link: @$link
if tab
# activate the tab jquery ui 1.10 style o.O
@$overlay_tabs.tabs('option', 'active', $('#overlay_tabs > div').index(tab))
window.requestAnimationFrame =>
@$overlay_tabs.get(0).show(tab)
return

# Handles actions for internal link tab.
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/alchemy/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@import "alchemy/resource_info";
@import "alchemy/search";
@import "alchemy/selects";
@import "alchemy/shoelace";
@import "alchemy/sitemap";
@import "alchemy/spinner";
@import "alchemy/tables";
Expand Down
10 changes: 1 addition & 9 deletions app/assets/stylesheets/alchemy/dialogs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,5 @@ $dialog-transition-duration: 150ms;
}

#overlay_tabs {
margin: -4*$default-padding;

.ui-tabs-panel {
padding: 4*$default-padding;
}

.ui-tabs.ui-corner-all {
border-radius: 0;
}
margin: -4 * $default-padding;
}
12 changes: 8 additions & 4 deletions app/assets/stylesheets/alchemy/elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@
}

&.selected:not(.is-fixed),
&:hover {
&:hover:not(.is-fixed) {
&:not(.hidden) {
box-shadow: 0 2px 8px rgba(#9b9b9b, 0.75);
}
}

&.selected:not(.is-fixed):not(.folded):not(.dirty):not(.hidden):not(.deprecated) {
&.selected:not(.is-fixed):not(.folded):not(.dirty):not(.hidden):not(
.deprecated
) {
> .element-header {
background-color: $element-header-active-bg-color;
color: $element-header-active-color;
Expand Down Expand Up @@ -963,8 +965,10 @@ textarea.has_tinymce {
position: relative;
}

.element-header {
background-color: transparent;
.element-editor:not(.is-fixed) & {
.element-header {
background-color: transparent;
}
}

.element-toolbar {
Expand Down
117 changes: 0 additions & 117 deletions app/assets/stylesheets/alchemy/jquery-ui.scss
Original file line number Diff line number Diff line change
Expand Up @@ -326,123 +326,6 @@
border-radius: 3px;
}

/*
* jQuery UI Tabs 1.8.7
*
* Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* http://docs.jquery.com/UI/Tabs#theming
*/

.ui-tabs {
position: relative;
padding: 0;
margin: 0;
border-style: none;
border-width: 0;
}

/* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed') */

.ui-tabs .ui-tabs-nav {
padding: 4px 8px 0;
background: $toolbar-bg-color;
border-radius: 0;
border-bottom: $default-border;
margin: 0;
padding: 0;
height: $tabs-height;
}

.ui-tabs .ui-tabs-nav li {
list-style: none;
float: left;
position: relative;
height: $tabs-height - $default-border-width;
margin: 0;
border-color: $default-border-color;
border-width: 0;
border-right-width: $default-border-width;
border-radius: 0;
padding: 0;
white-space: nowrap;
background-color: transparent;
font-weight: normal;

&.ui-tabs-active {
background-color: $light-gray;
height: $tabs-height;

a {
cursor: default;
}
}
}

.ui-tabs .ui-tabs-nav li a {
display: block;
text-decoration: none;
padding: 8px 12px 7px;
}

.ui-tabs .ui-tabs-nav li.ui-tabs-selected {
margin-bottom: 0;
padding-bottom: 1px;
background: $light-gray;
}

.ui-tabs .ui-tabs-nav li.ui-tabs-selected a,
.ui-tabs .ui-tabs-nav li.ui-state-disabled a,
.ui-tabs .ui-tabs-nav li.ui-state-processing a {
cursor: default;
}

.ui-tabs .ui-tabs-nav li a,
.ui-tabs.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-selected a {
cursor: pointer;
}

/* first selector in group seems obsolete, but required to overcome bug in Opera applying cursor: text overall if defined elsewhere... */

.ui-tabs .ui-tabs-panel {
display: block;
border-width: 0;
background: none;
}

.ui-tabs .ui-tabs-hide {
display: none !important;
}

/* UI Tabs Paging */

.ui-tabs li.ui-tabs-paging-prev {
border-right-width: 1px;
}

.ui-tabs li.ui-tabs-paging-next {
float: right !important;
padding: 0 !important;
border-right-width: 0;
}

.ui-tabs .ui-tabs-nav .ui-tabs-paging-prev a,
.ui-tabs .ui-tabs-nav .ui-tabs-paging-next a {
display: block;
border: 0;
z-index: 2;
padding: 8px;
color: $icon-color;
text-decoration: none;
cursor: pointer;
}

.ui-tabs .ui-tabs-nav .ui-tabs-paging-disabled {
display: none;
}

/*
* jQuery UI Progressbar 1.8.7
*
Expand Down
22 changes: 22 additions & 0 deletions app/assets/stylesheets/alchemy/shoelace.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
:root,
:host,
.sl-theme-light {
--sl-font-size-small: #{$base-font-size};
--sl-color-primary-600: #{$dark-blue};
--sl-color-neutral-600: #{$text-color};
--sl-focus-ring-color: #{$focus-color};
--sl-focus-ring-width: 2px;
}

sl-tab-group {
--indicator-color: #{$dark-orange};
--track-color: #{$medium-gray};

&::part(base) {
background-color: #{$light-gray};
}
}

sl-tab-panel {
--padding: #{4 * $default-padding};
}
3 changes: 3 additions & 0 deletions app/javascript/alchemy_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import "alchemy_admin/components/page_select"
import "alchemy_admin/components/spinner"
import "alchemy_admin/components/tinymce"
import "alchemy_admin/components/tooltip"
import "@shoelace/tab"
import "@shoelace/tab-group"
import "@shoelace/tab-panel"

// Global Alchemy object
if (typeof window.Alchemy === "undefined") {
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/elements/create.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Alchemy.FixedElements.buildTabs('<%= Alchemy.t(:main_content) %>');
}
Alchemy.FixedElements.createTab('<%= @element.id %>', '<%= @element.display_name %>');
$element_area = $('#fixed-element-<%= @element.id %>');
$element_area = $('[name="fixed-element-<%= @element.id %>"]');
<% elsif @element.parent_element %>
$element_area = $('#element_<%= @element.parent_element_id %> > .nestable-elements > .nested-elements');
Alchemy.Buttons.enable('.nestable-elements');
Expand Down
Loading

0 comments on commit 30b7570

Please sign in to comment.