Skip to content

Commit

Permalink
Add dark mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
zbynek committed Nov 3, 2023
1 parent 7e3180c commit bf56f22
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
1 change: 0 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default {
input,
plugins: [
litcss({
include: '/**/*.css',
transform: (css, {filePath}) =>
processor.process(css, {from: filePath})
.css,
Expand Down
2 changes: 1 addition & 1 deletion src/jio-locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const setLocaleFromUrl = async () => {
const locale = url.searchParams.get('locale') || (new Intl.NumberFormat()).resolvedOptions().locale || sourceLocale;
await setLocale(locale);
};
setLocaleFromUrl().catch(e => console.error(`Error loading locale: ${(e as Error).message}`));
setLocaleFromUrl().catch(e => console.log(`Error loading locale: ${(e as Error).message}`));


window.addEventListener('jio-locale-changed', (e) => {
Expand Down
9 changes: 9 additions & 0 deletions src/jio-navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ button:not(:disabled) {
position: relative;
}

@media(prefers-color-scheme: dark) {
.navbar[data-theme="auto"] {
background-color: #000;
}
}
.navbar[data-theme="dark"] {
background-color: #000;
}

.navbar-brand a,
.navbar-brand ::slotted(a) {
color: #fff;
Expand Down
12 changes: 10 additions & 2 deletions src/jio-navbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export type NavbarItemLink = {
title?: string;
};

export type Theme = 'dark' | 'light' | 'auto';

@localized()
@customElement('jio-navbar')
export class Navbar extends LitElement {
Expand All @@ -31,14 +33,20 @@ export class Navbar extends LitElement {

/**
* Show search box
* (doesnt yet work)
*/
@property({type: Boolean})
showSearchBox: Boolean = false;

@property()
locationPathname: string = location.pathname;


/**
* Header theme (light/dark/auto)
*/
@property()
theme = 'light';

/**
* Keeps track of what menu is opened.
*
Expand Down Expand Up @@ -187,7 +195,7 @@ export class Navbar extends LitElement {
});
const searchboxHtml = !this.showSearchBox ? nothing : html`<jio-searchbox @click=${this._handleSearchboxClick}></jio-searchbox>`;
return html`
<nav class="navbar">
<nav class="navbar" data-theme="${this.theme}">
<span class="navbar-brand">
<slot name="brand">
<a href="/">Jenkins</a>
Expand Down
4 changes: 3 additions & 1 deletion src/stories/Navbar.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ export default {
showSearchBox: {control: {type: 'boolean'}, },
visibleMenu: {table: {disable: true}},
menuToggled: {table: {disable: true}},
theme: {control: 'select', options: ['light', 'dark', 'auto']},
}
} as Meta;

const render = ({property, showSearchBox, locationPathname}) => html`<jio-navbar
const render = ({property, showSearchBox, locationPathname, theme}) => html`<jio-navbar
property=${ifDefined(property)}
.locationPathname=${ifDefined(locationPathname)}
.theme=${ifDefined(theme)}
?showSearchBox=${showSearchBox}
></jio-navbar>`;

Expand Down

0 comments on commit bf56f22

Please sign in to comment.