Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add dark mode support #110

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It matches css files by default, using regex. It seems that regex works cross-platform and glob is POSIX only.

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 @@ -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