-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheader.ts
More file actions
73 lines (64 loc) · 1.98 KB
/
header.ts
File metadata and controls
73 lines (64 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Element } from '@core/element'
import { html, css } from 'lit'
import { customElement } from 'lit/decorators.js'
import '~icons/custom/logo.svg'
import '~icons/mdi/white-balance-sunny.js'
import '~icons/mdi/moon-waning-crescent.js'
import '~icons/mdi/file-upload-outline.js'
import './inputs/traceLoader.js'
import { DARK_MODE_KEY } from '../controller/constants.js'
const darkModeInitValue = localStorage.getItem(DARK_MODE_KEY)
@customElement('wdio-devtools-header')
export class DevtoolsHeader extends Element {
#darkMode =
typeof darkModeInitValue === 'string'
? darkModeInitValue === 'true'
: window.matchMedia('(prefers-color-scheme: dark)').matches
constructor() {
super()
if (this.#darkMode) {
document.querySelector('body')?.classList.add('dark')
}
}
static styles = [
...Element.styles,
css`
:host {
display: flex;
align-items: center;
background: black;
height: 40px;
width: 100%;
}
`
]
render() {
return html`
<icon-custom-logo class="p-2 dark:p-2 h-full"></icon-custom-logo>
<h1 class="font-bold text-white">WebdriverIO Devtools</h1>
<nav class="ml-auto mr-2">
<wdio-devtools-trace-loader as="button"></wdio-devtools-trace-loader>
<button class="p-2" @click="${this.#switchMode}">
<icon-mdi-moon-waning-crescent
class="${this.#darkMode ? 'hidden' : 'show'}"
></icon-mdi-moon-waning-crescent>
<icon-mdi-white-balance-sunny
class="${this.#darkMode ? 'show' : 'hidden'}"
></icon-mdi-white-balance-sunny>
</button>
</nav>
`
}
#switchMode() {
const body = document.querySelector('body')
body?.classList.toggle('dark')
this.#darkMode = !this.#darkMode
localStorage.setItem(DARK_MODE_KEY, this.#darkMode ? 'true' : 'false')
this.requestUpdate()
}
}
declare global {
interface HTMLElementTagNameMap {
'wdio-devtools-header': DevtoolsHeader
}
}