Skip to content

Commit aff1777

Browse files
committed
refactor: update Logo component to allow deeper customizations + switch to lit-html for rendering
1 parent 2ed70e7 commit aff1777

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

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

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { define, props } from 'skatejs';
2-
import { h } from 'preact';
32
import { store } from '../../store.js'; // connect to redux
43

54
const classNames = require('classnames');
6-
import { BaseComponent } from '../base-component.js';
5+
import { html } from 'lit-html';
6+
import { BaseLitComponent } from '../base-component.js';
77

88
@define
9-
class Logo extends BaseComponent {
9+
class Logo extends BaseLitComponent {
1010
static is = 'pl-logo';
1111

1212
constructor(self) {
@@ -16,28 +16,39 @@ class Logo extends BaseComponent {
1616

1717
connected() {
1818
const state = store.getState();
19-
this.themeMode = state.app.themeMode || 'dark';
20-
}
21-
22-
shouldUpdate(prevProps, prevState) {
23-
return true;
19+
this.theme = this.theme || state.app.themeMode || 'dark';
2420
}
2521

2622
static props = {
23+
ratio: props.string,
24+
theme: props.string,
2725
url: props.string,
2826
text: props.string,
29-
src: props.string,
27+
altText: props.string,
28+
srcLight: props.string,
29+
srcDark: props.string,
3030
};
3131

32-
render({ themeMode }) {
33-
return (
34-
<a href={this.props.url} className="pl-c-logo">
35-
<img src={this.props.src} className="pl-c-logo__img" />
36-
{this.props.text && (
37-
<span className="pl-c-logo__text">{this.props.text}</span>
38-
)}
32+
render() {
33+
const imageSrc = this.theme === 'dark' ? this.srcDark : this.srcLight;
34+
35+
return html`
36+
<a
37+
href="${this.props.url === '' ? undefined : this.props.url}"
38+
class="pl-c-logo"
39+
>
40+
<img
41+
alt=${this.props.altText || 'Pattern Lab Logo'}
42+
src=${imageSrc}
43+
class="pl-c-logo__img"
44+
/>
45+
${this.props.text && this.props.text !== ''
46+
? html`
47+
<span class="pl-c-logo__text">{this.props.text}</span>
48+
`
49+
: ''}
3950
</a>
40-
);
51+
`;
4152
}
4253
}
4354

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,24 @@
33
\*------------------------------------*/
44

55
pl-logo {
6-
max-width: 12rem;
76
align-self: center;
87
display: flex;
9-
flex-direction: column;
8+
flex-direction: row;
109
align-items: center;
1110
justify-content: center;
1211
flex-shrink: 0;
1312
position: relative;
1413
z-index: 100;
14+
padding: 0;
15+
min-height: 44px;
16+
min-width: 44px;
1517

16-
@media all and (min-width: $pl-bp-med) {
17-
.pl-c-body--theme-sidebar & {
18-
max-width: none;
19-
width: 7rem;
20-
padding: 0.5rem;
21-
}
22-
}
2318
}
2419

2520
.pl-c-logo {
2621
width: auto;
27-
padding: 0.5rem;
22+
flex-grow: 1;
23+
padding: 0.5rem 12px;
2824
display: flex;
2925
align-items: center;
3026
justify-content: center;
@@ -33,22 +29,23 @@ pl-logo {
3329

3430
outline: 0;
3531
text-transform: lowercase;
36-
font-size: 1.4rem;
32+
font-size: 1.2rem;
3733
font-weight: bold;
3834
line-height: 1;
3935
margin: 0;
4036
transition: color .2s ease;
4137

4238
&:focus {
43-
outline: 1px dotted $pl-color-gray-50;
39+
outline: 1px dotted;
4440
outline-offset: -1px;
4541
}
4642
}
4743

4844
.pl-c-logo__img {
4945
display: block;
5046
height: auto;
51-
max-height: 2.5rem;
47+
max-width: 100%;
48+
max-height: 23px;
5249

5350
&:not(:last-child){
5451
margin-right: 0.25rem;

0 commit comments

Comments
 (0)