Skip to content

Commit 7821123

Browse files
sghoweribmuenzenmeyerJosefBredereck
authored
UIKit Nav Cleanup (pattern-lab#1102)
* feat: upgrade to Preact v10 * refactor: break apart Nav into smaller more maintainable pieces; significantly reduce UI logic required under the hood * refactor: minor tweaks to Pattern State UI * fix: fix the drag offset of the drawer resizer * chore: update yarn.lock * refactor: rename root Nav component files * pattern-lab#1102 After merge fixes * fix: yarn lock after merge * fix: review findings in css and js * fix: remove unused code and reimplement utility func Co-authored-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com> Co-authored-by: Josef Bredreck <slime.games@outlook.de> Co-authored-by: Josef Bredreck <13408112+JosefBredereck@users.noreply.github.com>
1 parent 13e28c2 commit 7821123

26 files changed

+717
-966
lines changed

packages/uikit-workshop/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@
7474
"mousetrap": "^1.6.5",
7575
"portfinder": "^1.0.28",
7676
"postcss-loader": "^3.0.0",
77-
"preact": "8.3.1",
78-
"preact-compat": "3.18.4",
79-
"preact-context": "1.1.2",
80-
"preact-render-to-string": "^4.1.0",
77+
"preact-render-to-string": "^5.1.1",
78+
"preact": "^10.0.5",
8179
"preload-webpack-plugin": "^3.0.0-beta.3",
8280
"pretty": "^2.0.0",
8381
"prismjs": "^1.25.0",

packages/uikit-workshop/src/sass/pattern-lab.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
/*------------------------------------*\
4444
#COMPONENTS
4545
\*------------------------------------*/
46-
@import '../scripts/components/pl-nav/pl-nav.scss';
46+
@import '../scripts/components/pl-nav/index.scss';
4747
@import '../scripts/components/pl-search/pl-search.scss';
4848
@import 'scss/04-components/annotations';
4949
@import 'scss/04-components/annotations-inside-modal';

packages/uikit-workshop/src/sass/scss/04-components/_pattern-states.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
.pl-c-pattern-state {
1010
width: 0.5em;
1111
height: 0.5em;
12-
margin-bottom: 0.25em;
1312
margin-left: 0.5em;
1413
border-radius: 50%;
14+
display: inline-block;
1515
background-color: $pl-color-state-info;
1616

1717
&--complete {

packages/uikit-workshop/src/sass/scss/05-themes/_sidebar-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
flex-direction: column; /* 3 */
2323
border-bottom: 0; /* 4 */
2424
justify-content: space-between;
25+
--nav-item-height: 2.5rem;
2526
}
2627

2728
/**

packages/uikit-workshop/src/scripts/components/base-skate-preact-element.js

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,7 @@ import { SkateElement } from './base-skate-element';
1616

1717
/** @jsx h */
1818

19-
import preact, { h, render } from 'preact';
20-
21-
// TODO make this a Symbol() when it's supported.
22-
const preactNodeName = '__preactNodeName';
23-
24-
let oldVnode;
25-
26-
function newVnode(vnode) {
27-
const fn = vnode.nodeName;
28-
if (fn && fn.prototype instanceof HTMLElement) {
29-
if (!fn[preactNodeName]) {
30-
const prefix = fn.name;
31-
customElements.define(
32-
(fn[preactNodeName] = name(prefix)),
33-
class extends fn {}
34-
);
35-
}
36-
vnode.nodeName = fn[preactNodeName];
37-
}
38-
return vnode;
39-
}
40-
41-
function setupPreact() {
42-
oldVnode = preact.options.vnode;
43-
preact.options.vnode = newVnode;
44-
}
45-
46-
function teardownPreact() {
47-
preact.options.vnode = oldVnode;
48-
}
19+
import { h, render } from 'preact';
4920

5021
export class SkatePreactElement extends SkateElement {
5122
get props() {
@@ -55,23 +26,16 @@ export class SkatePreactElement extends SkateElement {
5526
}
5627

5728
renderer(root, call) {
58-
setupPreact();
5929
this._renderRoot = root;
60-
this._preactDom = render(
61-
call(),
62-
root,
63-
this._preactDom || root.childNodes[0]
64-
);
65-
teardownPreact();
30+
render(call(), root);
6631
}
6732

6833
disconnectedCallback() {
6934
this.disconnecting && this.disconnecting();
7035
super.disconnectedCallback && super.disconnectedCallback();
7136
this.disconnected && this.disconnected();
7237
// Render null to unmount. See https://github.com/skatejs/skatejs/pull/1432#discussion_r183381359
73-
this._preactDom = render(null, this._renderRoot, this._preactDom);
74-
this._renderRoot = null;
38+
render(null, this._renderRoot);
7539

7640
this.__storeUnsubscribe && this.__storeUnsubscribe();
7741

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*------------------------------------*\
2+
#NAVIGATION
3+
\*------------------------------------*/
4+
5+
@import './nav.scss';
6+
@import './nav-link.scss';
7+
@import './nav-list.scss';
8+
@import './nav-dropdown.scss';
9+
@import './nav-accordion.scss';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@import '../../../sass/scss/core.scss';
2+
3+
.pl-c-nav__accordion {
4+
background-color: inherit; // allows the nav's children inherit from the parent header
5+
@include listReset();
6+
@include accordionPanel();
7+
display: flex;
8+
flex-flow: row wrap;
9+
opacity: 0;
10+
visibility: hidden;
11+
}
12+
13+
.is-open ~ .pl-c-nav__accordion {
14+
visibility: visible;
15+
max-height: none;
16+
transform: translateY(0);
17+
opacity: 1;
18+
19+
.pl-c-body--theme-horizontal & {
20+
overflow: auto;
21+
}
22+
23+
@media all and (min-width: $pl-bp-med) {
24+
height: auto;
25+
max-height: calc(100vh - #{$offset-top} - 2rem); /* 1 */
26+
}
27+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@import '../../../sass/scss/core.scss';
2+
3+
/**
4+
* Nav Dropdown
5+
* 1) On larger screens, display as dropdowns that
6+
* hangs over the header
7+
*/
8+
.pl-c-nav__dropdown {
9+
@media all and (min-width: $pl-bp-med) {
10+
position: absolute;
11+
top: 100%; /* 1 */
12+
left: 0;
13+
min-width: 14rem;
14+
border-radius: $pl-border-radius-med;
15+
border-style: solid;
16+
border-width: 1px;
17+
box-shadow: 0 2px 5px rgba($pl-color-black, 0.1);
18+
transition: all 0.2s ease;
19+
transform: translateY(-12px);
20+
z-index: 1;
21+
transition: all $pl-animate-quick ease-out;
22+
23+
.pl-c-body--theme-sidebar & {
24+
position: relative;
25+
}
26+
}
27+
28+
.pl-c-body--theme-light & {
29+
border-color: rgba($pl-color-black, 0.2);
30+
}
31+
32+
.pl-c-body--theme-dark & {
33+
border-color: rgba($pl-color-white, 0.2);
34+
}
35+
36+
.pl-c-body--theme-sidebar & {
37+
border-width: 0;
38+
transform: none;
39+
box-shadow: none;
40+
border-radius: 0;
41+
}
42+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// this line is required for rendering even if it is note used in the code
2+
import { h, Fragment } from 'preact';
3+
const classNames = require('classnames');
4+
5+
export const NavLink = (props) => {
6+
const classes = classNames('pl-c-nav__link', {
7+
[`pl-c-nav__link--level-${props.level}`]: props.level !== undefined,
8+
'pl-c-nav__link--icon-only': props.iconOnly,
9+
'pl-c-nav__link--title': props.isTitle,
10+
});
11+
12+
const Tag = props.href ? 'a' : 'button';
13+
14+
return (
15+
<Tag className={`${classes}`} role="tab" {...props}>
16+
{props.iconPos === 'before' && props.iconName && (
17+
<span
18+
class="pl-c-nav__link-icon"
19+
dangerouslySetInnerHTML={{
20+
__html: `<pl-icon name="${props.iconName}"></pl-icon>`,
21+
}}
22+
/>
23+
)}
24+
<span
25+
className={`pl-c-nav__link-text ${
26+
props.iconOnly ? 'is-vishidden' : ''
27+
}`}
28+
>
29+
{props.children}
30+
{props.status && (
31+
<span
32+
class={`pl-c-pattern-state pl-c-pattern-state--${props.status}`}
33+
title={props.status}
34+
/>
35+
)}
36+
</span>
37+
{props.iconPos !== 'before' && props.iconName && (
38+
<span
39+
class="pl-c-nav__link-icon"
40+
dangerouslySetInnerHTML={{
41+
__html: `<pl-icon name="${props.iconName}"></pl-icon>`,
42+
}}
43+
/>
44+
)}
45+
</Tag>
46+
);
47+
};

0 commit comments

Comments
 (0)