Skip to content

Commit

Permalink
feat: Add dark mode support (#110)
Browse files Browse the repository at this point in the history
Adds theme attribute that can be either light (default), dark or auto.
That should allow adding dark mode to plugin site before we add it to
the others and allow adding a color theme toggle to the page in the
future.
  • Loading branch information
halkeye authored Dec 6, 2023
2 parents 21d01b4 + 1971f93 commit 7f253cd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 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
10 changes: 10 additions & 0 deletions src/jio-navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ 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 @@ -188,7 +196,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 7f253cd

Please sign in to comment.