Skip to content

Commit 9e1c3e7

Browse files
committed
refactor: convert Header to render via lit-html
1 parent 3c5a9a7 commit 9e1c3e7

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

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

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ const classNames = require('classnames');
55

66
import { store } from '../../store.js'; // connect to redux
77
import { BaseComponent } from '../base-component.js';
8-
import MenuIcon from '../../../icons/menu.svg';
9-
import VisuallyHidden from '@reach/visually-hidden';
8+
9+
import { html } from 'lit-html';
10+
import { BaseLitComponent } from '../base-component.js';
1011

1112
@define
12-
class Header extends BaseComponent {
13+
class Header extends BaseLitComponent {
1314
static is = 'pl-header';
1415

1516
constructor(self) {
@@ -42,33 +43,55 @@ class Header extends BaseComponent {
4243
navTarget.classList.toggle('pl-is-active'); // @todo: refactor to have this add based on the component's state
4344
}
4445

45-
render({ themeMode }) {
46-
return (
46+
render() {
47+
return html`
4748
<header class="pl-c-header" role="banner">
4849
<button
4950
class="pl-c-header__nav-toggle pl-js-nav-trigger"
50-
onClick={this.toggleNav}
51+
@click="${this.toggleNav}"
5152
>
52-
<MenuIcon height={20} width={20} fill="currentColor" />
53-
<VisuallyHidden>Menu</VisuallyHidden>
53+
<pl-icon
54+
name="menu"
55+
height="20"
56+
width="20"
57+
fill="currentColor"
58+
></pl-icon>
59+
<span class="is-vishidden">Menu</span>
5460
</button>
5561
56-
<pl-logo
57-
src={`styleguide/images/pattern-lab-logo--on-${themeMode}.svg`}
58-
url="/"
59-
text="Pattern Lab"
60-
/>
62+
${window.config?.theme?.logo !== false
63+
? html`
64+
<pl-logo
65+
src-light="${window.config?.theme?.logo?.srcLight ||
66+
'styleguide/images/pattern-lab-logo--on-light.svg'}"
67+
src-dark="${window.config?.theme?.logo?.srcDark ||
68+
'styleguide/images/pattern-lab-logo--on-dark.svg'}"
69+
url="${window.config?.theme?.logo?.url === '' ||
70+
window.config?.theme?.logo?.url === 'none'
71+
? ''
72+
: window.config?.theme?.logo?.url || '/'}"
73+
alt-text="${window.config?.theme?.logo?.altText || ''}"
74+
theme="${this.themeMode}"
75+
ratio="${window.config?.theme?.logo?.ratio || ''}"
76+
text="${window.config?.theme?.logo?.text === '' ||
77+
window.config?.theme?.logo?.text === false ||
78+
window.config?.theme?.logo?.text === 'none'
79+
? ''
80+
: window.config?.theme?.logo?.text || 'Pattern Lab'}"
81+
></pl-logo>
82+
`
83+
: ''}
6184
6285
<nav
6386
class="pl-c-nav pl-js-nav-target pl-js-nav-container"
6487
role="navigation"
6588
>
66-
<pl-search max-results="10" placeholder="Find a Pattern" />
67-
<pl-nav />
89+
<pl-search max-results="10" placeholder="Find a Pattern"></pl-search>
90+
<pl-nav></pl-nav>
6891
</nav>
6992
<pl-controls></pl-controls>
7093
</header>
71-
);
94+
`;
7295
}
7396
}
7497

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,15 @@ pl-header {
8383
*/
8484
.pl-c-header__nav-toggle {
8585
@include linkStyle();
86+
padding: 11px 12px;
8687
border: 0;
8788

8889
@media all and (min-width: $pl-bp-med) {
8990
display: none;
9091
}
92+
93+
&:focus {
94+
outline: 1px dotted;
95+
outline-offset: -1px;
96+
}
9197
}

0 commit comments

Comments
 (0)