Skip to content

Commit 447f054

Browse files
committed
refactor: clean up Nav styles + use new <pl-icon> component; keep using Preact under fully refactored
1 parent 9e1c3e7 commit 447f054

File tree

2 files changed

+49
-42
lines changed

2 files changed

+49
-42
lines changed

packages/uikit-workshop/src/scripts/components/pl-nav/pl-nav.js

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { h } from 'preact';
55
const classNames = require('classnames');
66

77
import { store } from '../../store.js'; // redux store
8-
import ArrowIcon from '../../../icons/arrow-down.svg';
98
import { BaseComponent } from '../base-component.js';
9+
import Mousetrap from 'mousetrap';
1010
import 'url-search-params-polyfill';
1111

1212
const SubSubList = props => {
@@ -125,14 +125,12 @@ const SpecialButton = props => {
125125
{...props}
126126
>
127127
{props.children}
128-
<span class="pl-c-nav__link-icon">
129-
<ArrowIcon
130-
height={24}
131-
width={24}
132-
viewBox="0 0 24 24"
133-
fill="currentColor"
134-
/>
135-
</span>
128+
<span
129+
class="pl-c-nav__link-icon"
130+
dangerouslySetInnerHTML={{
131+
__html: '<pl-icon name="arrow-down"></pl-icon>',
132+
}}
133+
/>
136134
</button>
137135
);
138136
};
@@ -147,14 +145,12 @@ const Button = props => {
147145
{...props}
148146
>
149147
<span className={`pl-c-nav__link-text`}>{props.children}</span>
150-
<span class="pl-c-nav__link-icon">
151-
<ArrowIcon
152-
height={24}
153-
width={24}
154-
viewBox="0 0 24 24"
155-
fill="currentColor"
156-
/>
157-
</span>
148+
<span
149+
class="pl-c-nav__link-icon"
150+
dangerouslySetInnerHTML={{
151+
__html: '<pl-icon name="arrow-down"></pl-icon>',
152+
}}
153+
/>
158154
</button>
159155
);
160156
};
@@ -168,14 +164,12 @@ const ButtonTitle = props => {
168164
role="tab"
169165
{...props}
170166
>
171-
<span class="pl-c-nav__link-icon">
172-
<ArrowIcon
173-
height={24}
174-
width={16}
175-
viewBox="0 0 24 24"
176-
fill="currentColor"
177-
/>
178-
</span>
167+
<span
168+
class="pl-c-nav__link-icon"
169+
dangerouslySetInnerHTML={{
170+
__html: '<pl-icon name="arrow-down"></pl-icon>',
171+
}}
172+
/>
179173
<span className={`pl-c-nav__link-text`}>{props.children}</span>
180174
</button>
181175
);
@@ -207,26 +201,38 @@ class Nav extends BaseComponent {
207201
this.elem = this;
208202
this.previousActiveLinks = [];
209203
this.iframeElem = document.querySelector('pl-iframe');
204+
205+
Mousetrap.bind('esc', function(e) {
206+
self.cleanupActiveNav();
207+
});
208+
210209
window.addEventListener('message', this.receiveIframeMessage, false);
211210

212211
document.body.addEventListener('click', function(e) {
213212
if (
214-
e.target.closest('pl-header') === null &&
213+
e.target.closest('.pl-c-nav') === null &&
214+
e.target.closest('.pl-js-nav-trigger') === null &&
215215
e.target.closest('svg') === null
216216
) {
217217
self.cleanupActiveNav();
218218
}
219219
});
220220
}
221221

222+
disconnected() {
223+
super.disconnected && super.disconnected();
224+
window.removeEventListener('message', this.receiveIframeMessage);
225+
}
226+
222227
_stateChanged(state) {
223-
this.layoutMode = state.app.layoutMode || '';
228+
if (this.layoutMode !== state.app.layoutMode) {
229+
this.layoutMode = state.app.layoutMode || '';
230+
}
224231

225232
if (this.currentPattern !== state.app.currentPattern) {
226233
this.currentPattern = state.app.currentPattern;
234+
this.handleURLChange(); // so the nav logic is always correct (ex. layout changes)
227235
}
228-
229-
this.handleURLChange(); // so the nav logic is always correct (ex. layout changes)
230236
}
231237

232238
receiveIframeMessage(event) {
@@ -251,9 +257,13 @@ class Nav extends BaseComponent {
251257
if (data.event !== undefined && data.event === 'patternLab.pageClick') {
252258
try {
253259
if (
254-
window.matchMedia('(min-width: calc(42em))').matches &&
255-
self.layoutMode !== 'vertical'
260+
window.innerWidth <= 670 ||
261+
(window.innerWidth >= 670 && self.layoutMode !== 'vertical')
256262
) {
263+
console.log(
264+
window.innerWidth <= 670 ||
265+
(window.innerWidth >= 670 && self.layoutMode !== 'vertical')
266+
);
257267
self.cleanupActiveNav();
258268
}
259269
} catch (error) {

packages/uikit-workshop/src/scripts/components/pl-nav/pl-nav.scss

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pl-nav {
4141

4242
@media all and (min-width: $pl-bp-med) {
4343
.pl-c-body--theme-sidebar & {
44-
padding-bottom: 0.5rem;
4544
display: block;
4645
display: flex;
4746
overflow: hidden;
@@ -140,6 +139,8 @@ pl-nav {
140139
*/
141140
.pl-c-nav__link {
142141
@include linkStyle;
142+
outline: 0;
143+
min-height: 40px;
143144
color: inherit;
144145
line-height: 1.5;
145146
display: flex;
@@ -232,6 +233,7 @@ pl-nav {
232233
transform: rotate(-90deg);
233234
flex-grow: 0;
234235
line-height: 0;
236+
font-size: 1.3rem; // temp solution till new pl-button used in Navigation
235237
}
236238

237239
.pl-c-nav__link--overview-wrapper.pl-is-active > .pl-c-nav__link--section-dropdown > .pl-c-nav__link-icon,
@@ -431,16 +433,6 @@ pl-nav {
431433
}
432434
}
433435

434-
.pl-c-nav__list > .pl-c-nav__item:not(:last-child) {
435-
@media all and (min-width: $pl-bp-med) {
436-
.pl-c-body--theme-sidebar & {
437-
margin-bottom: 0.5rem;
438-
margin-top: 0.5rem;
439-
440-
}
441-
}
442-
}
443-
444436
.pl-c-nav__link--section-dropdown {
445437
width: 2.5rem !important;
446438
height: 2.5rem !important;
@@ -493,6 +485,11 @@ pl-nav {
493485
}
494486
}
495487

488+
&:focus {
489+
outline-offset: -1px;
490+
outline: 1px dotted;
491+
}
492+
496493
&:active:not(:hover):after,
497494
&:focus:not(:hover):after {
498495
opacity: 0;

0 commit comments

Comments
 (0)