Skip to content

Commit

Permalink
Merge pull request #14321 from craftcms/feature/cms-14313-sidebar-links
Browse files Browse the repository at this point in the history
Global nav subnav
  • Loading branch information
brandonkelly authored Feb 7, 2024
2 parents 073a0ac + f62a47f commit 7a7c917
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 206 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Content Management
- Improved global sidebar styling. ([#14281](https://github.com/craftcms/cms/pull/14281))
- The global sidebar is now collapsible. ([#14281](https://github.com/craftcms/cms/pull/14281))
- It’s now possible to expand and collapse global sidebar items without navigating to them. ([#14313](https://github.com/craftcms/cms/issues/14313), [#14321](https://github.com/craftcms/cms/pull/14321))
- Redesigned the global breadcrumb bar to include quick links to other areas of the control panel, page context menus, and action menus. ([#13902](https://github.com/craftcms/cms/pull/13902))
- All elements can now have thumbnails, provided by Assets fields. ([#12484](https://github.com/craftcms/cms/discussions/12484), [#12706](https://github.com/craftcms/cms/discussions/12706))
- Element indexes and relational fields now have the option to use card views. ([#6024](https://github.com/craftcms/cms/pull/6024))
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- It’s now possible to expand and collapse global sidebar items without navigating to them. ([#14313](https://github.com/craftcms/cms/issues/14313), [#14321](https://github.com/craftcms/cms/pull/14321))
- Removed the maximum content area width. ([#14281](https://github.com/craftcms/cms/pull/14281))
- Fixed a bug where querying elements with `eagerly()` wasn’t working across element types.
- Fixed a SQL error that could occur when querying relations with `eagerly()`.
- Fixed a bug where element actions weren’t working for elements that were added to a relational field.
Expand Down
2 changes: 2 additions & 0 deletions packages/craftcms-sass/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,11 @@ $menuBorderRadius: $mediumBorderRadius;
border: solid $color;
border-width: 0 $width $width 0;
opacity: 0.8;
position: relative;

@if $dir == up {
transform: rotate(225deg);
top: 2px;
} @else if $dir == down {
transform: rotate(45deg);
} @else if $dir == left {
Expand Down
11 changes: 6 additions & 5 deletions src/templates/_layouts/components/global-sidebar.twig
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@
{{ _self.action(item) }}

{% if item.subnav %}
{% set icon = item.sel ? 'angle-down' : 'angle-right' %}
<div type="button" class="nav-item__indicator">
<span class="cp-icon">{{ iconSvg(icon) }}</span>
</div>
<ul class="nav-item__subnav">
<craft-disclosure class="nav-item__trigger">
<button type="button" class="btn menubtn hairline" aria-controls="{{ item.id }}-subnav" aria-expanded="{{ item.sel ? 'true' : 'false' }}">
<span class="visually-hidden">{{ 'Open subnavigation' |t('app') }}</span>
</button>
</craft-disclosure>
<ul class="nav-item__subnav {{ item.sel ? 'is-open' : '' -}}" id="{{ item.id }}-subnav">
{% for itemId, item in item.subnav %}
{% set itemIsSelected = (
(selectedSubnavItem is defined and selectedSubnavItem == itemId) or
Expand Down
304 changes: 150 additions & 154 deletions src/templates/_layouts/cp.twig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/web/assets/cp/src/Craft.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ import './js/UserIndex.js';

// Custom elements
import './js/CraftGlobalSidebar.js';
import './js/CraftDisclosure.js';
11 changes: 0 additions & 11 deletions src/web/assets/cp/src/css/_cp.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ $badgeColor: var(--gray-800);
--neg-padding: calc(var(--padding) * -1);
--sidebar-width: #{$sidebarWidth};
--global-sidebar-width: #{$sidebarWidth};
--max-width: 1920px;
}

html {
Expand Down Expand Up @@ -274,10 +273,6 @@ $systemInfoHoverBgColor: darken($grey800, 10%);
display: flex;
flex-direction: column;
flex-grow: 1;

& > .container {
flex: 1;
}
}

#alerts {
Expand Down Expand Up @@ -1697,9 +1692,3 @@ li.breadcrumb-toggle-wrapper {
}
}
}

.container {
width: 100%;
max-width: var(--max-width);
margin: 0 auto;
}
112 changes: 81 additions & 31 deletions src/web/assets/cp/src/css/_global-sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@
.global-nav > ul {
display: flex;
flex-direction: column;
gap: var(--xs);
gap: var(--s);
}

.global-nav > ul > li {
position: relative;
padding: 0 10px; // match padding of #system-info
}

.global-nav > ul > li.sel {
Expand All @@ -74,11 +73,63 @@
}
}

.nav-item {
display: grid;
grid-template-columns: 10px 1fr var(--prefix-size) 10px;
grid-template-areas: '. action trigger .' 'subnav subnav subnav subnav';
align-items: center;
width: 100%;

> .sidebar-action {
grid-area: action;
}

[data-sidebar='collapsed'] & {
grid-template-areas: '. action .' '. trigger .' 'subnav subnav subnav';
grid-template-columns: 10px var(--prefix-size) 10px;
}
}

.nav-item__trigger {
--icon-size: 10px;
--trigger-size: var(--touch-target-size);
grid-area: trigger;
display: flex;
z-index: 1;

.menubtn {
padding: 0;
flex-direction: column;
justify-content: center;
align-items: center;
width: var(--trigger-size);
height: var(--trigger-size);
border: transparent;

&:hover {
background-color: var(--ui-control-bg-color);
}

&[aria-expanded='true']:not(:hover) {
background-color: transparent;
}

&[aria-expanded='true']:after {
@include angle(up);
}

&:after {
margin-left: 0 !important;
}
}
}

.nav-item__subnav {
--prefix-ratio: 4/3;
@include visually-hidden;
grid-area: subnav;

.sel & {
&.is-open {
@include not-visually-hidden;
}
}
Expand Down Expand Up @@ -137,27 +188,6 @@
}
}

.nav-item__indicator {
--icon-size: 10px;
position: absolute;
flex-direction: column;
justify-content: center;
align-items: center;
display: flex;
z-index: 1;
width: 1rem;
height: 1rem;
border-radius: 100%;
top: 15px;
transform: translateY(-50%);
right: calc(var(--m) + var(--xs));

.cp-icon {
position: relative;
top: 0.5px;
}
}

.sidebar-action--sub {
--indicator-size: 4px;
font-size: 0.9em;
Expand Down Expand Up @@ -245,10 +275,6 @@
justify-content: center;
padding: 0 var(--s);
margin-left: auto;

[data-sidebar='expanded'] .has-subnav & {
margin-right: var(--l);
}
}

/**
Expand Down Expand Up @@ -277,9 +303,18 @@ States
}
}

.nav-item__trigger {
.menubtn {
width: 100%;
height: auto;
padding-block: 2px var(--xs);
}
}

.sidebar-action__label {
position: absolute;
left: calc(100% + (var(--s) * 2));
z-index: 10;
left: calc(100% + (var(--xs) * 2));
top: 50%;
transform: translateY(-50%) translateX(-5px);
opacity: 0;
Expand All @@ -299,8 +334,8 @@ States
.sidebar-action__badge {
z-index: 100;
position: absolute;
right: 0;
bottom: 0;
right: calc(var(--xs) * -1);
bottom: var(--xs);
transform: translateY(25%);
padding: 0;
}
Expand All @@ -314,6 +349,21 @@ States
transform: translateX(-50%) translateY(-50%);
}
}

.global-nav > ul > li + li {
--separator-width: 28px;

&:before {
position: absolute;
top: calc(var(--s) / -2);
left: calc((var(--global-sidebar-width) - var(--separator-width)) / 2);
content: '';
width: var(--separator-width);
height: 1px;
margin: 0 auto;
background-color: var(--hairline-color);
}
}
}

[data-sidebar='expanded'] {
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/src/css/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ a.iconlink {
}

a.sel,
li.sel a {
li.sel > a {
cursor: default !important;
text-decoration: none;
}
Expand Down
55 changes: 55 additions & 0 deletions src/web/assets/cp/src/js/CraftDisclosure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Very simple disclosure trigger.
*
* Allows you to wrap a button[type="button"] and target an element to toggle the `is-open` class on.
* Set `aria-expanded` on the button
*/
class CraftDisclosure extends HTMLElement {
connectedCallback() {
this.trigger = this.querySelector('button[type="button"]');
if (!this.trigger) {
console.error(`craft-disclosure elements must include a button`, this);
return;
}

this.target = document.getElementById(
this.trigger.getAttribute('aria-controls')
);
if (!this.target) {
console.error(`No target found for disclosure`, this.trigger);
return;
}

if (!this.trigger.getAttribute('aria-expanded')) {
this.trigger.setAttribute('aria-expanded', 'false');
}

this.trigger.addEventListener('click', this.toggle.bind(this));

this.expanded = this.trigger.getAttribute('aria-expanded') === 'true';
}

toggle() {
if (this.expanded) {
this.close();
} else {
this.open();
}
}

open() {
this.trigger.setAttribute('aria-expanded', 'true');
this.expanded = true;
this.target.classList.add('is-open');
console.log('opening');
}

close() {
this.trigger.setAttribute('aria-expanded', 'false');
this.expanded = false;
this.target.classList.remove('is-open');
console.log('closing');
}
}

customElements.define('craft-disclosure', CraftDisclosure);

0 comments on commit 7a7c917

Please sign in to comment.