Skip to content

Commit

Permalink
feat: dark/Light mode option can be toggled via an option
Browse files Browse the repository at this point in the history
Theme mode can now be toggled and set via option, instead of always following the systeme

fix #314
  • Loading branch information
wa0x6e committed Feb 18, 2023
1 parent b5b2b69 commit 7e025fe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/cal-heatmap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
stroke-width: 1px;
}

@media (prefers-color-scheme: dark) {
&[data-theme='dark'] {
.graph-rect {
fill: #2d333b;
}
Expand Down Expand Up @@ -98,7 +98,7 @@
left: calc($arrow-size / -2);
}

@media (prefers-color-scheme: dark) {
&[data-theme='dark'] {
background: #636e7b;
color: #cdd9e5;
}
Expand Down
3 changes: 2 additions & 1 deletion src/calendar/CalendarPainter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ export default class CalendarPainter {
}

setup(): boolean {
const { itemSelector } = this.calendar.options.options;
const { itemSelector, theme } = this.calendar.options.options;

if (!this.root) {
this.root = select(itemSelector)
.append('svg')
.attr('data-theme', theme)
.attr('class', 'cal-heatmap-container');
this.root
.attr('x', 0)
Expand Down
4 changes: 4 additions & 0 deletions src/options/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export type OptionsType = {
scale?: ScaleOptions;
animationDuration: number;
verticalOrientation: boolean;
theme: 'light' | 'dark';
};

type InternalOptionsType = {
Expand Down Expand Up @@ -271,6 +272,9 @@ export default class Options {
// Animation duration, in ms
animationDuration: 200,

// Theme mode: dark/light
theme: 'light',

// Internally used options, do not edit not set
x: {
domainHorizontalLabelWidth: 0,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/Tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export default class Tooltip implements IPlugin {
this.root = document.body.appendChild(tooltipElem);
}

this.root.setAttribute('data-theme', this.calendar.options.options.theme);

this.popperInstance = createPopper<StrictModifiers>(
virtualElement,
this.root,
Expand Down

0 comments on commit 7e025fe

Please sign in to comment.