Skip to content

Commit b2d2817

Browse files
feat(elements): export theme-changed event type (#3372)
1 parent d705e32 commit b2d2817

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

packages/elements/src/components/app/app.component.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
22
import type { PropertyValues } from 'lit';
3-
import { html, unsafeCSS, nothing } from 'lit';
3+
import { html, nothing, unsafeCSS } from 'lit';
44
import { customElement, property } from 'lit/decorators.js';
5-
import type { MutantResult, MutationTestResult } from 'mutation-testing-report-schema/api';
65
import type {
7-
MetricsResult,
8-
MutantModel,
9-
TestModel,
106
FileUnderTestModel,
117
Metrics,
8+
MetricsResult,
9+
MutantModel,
1210
MutationTestMetricsResult,
1311
TestFileModel,
1412
TestMetrics,
13+
TestModel,
1514
} from 'mutation-testing-metrics';
1615
import { calculateMutationTestMetrics } from 'mutation-testing-metrics';
17-
import { tailwind, globals } from '../../style/index.js';
18-
import { locationChange$, View } from '../../lib/router.js';
16+
import type { MutantResult, MutationTestResult } from 'mutation-testing-report-schema/api';
1917
import type { Subscription } from 'rxjs';
2018
import { fromEvent, sampleTime } from 'rxjs';
21-
import theme from './theme.scss?inline';
19+
import { isLocalStorageAvailable } from '../../lib/browser.js';
20+
import type { MteCustomEvent } from '../../lib/custom-events.js';
2221
import { createCustomEvent } from '../../lib/custom-events.js';
2322
import { toAbsoluteUrl } from '../../lib/html-helpers.js';
24-
import { isLocalStorageAvailable } from '../../lib/browser.js';
2523
import { mutantChanges } from '../../lib/mutant-changes.js';
24+
import { locationChange$, View } from '../../lib/router.js';
25+
import type { Theme } from '../../lib/theme.js';
26+
import { globals, tailwind } from '../../style/index.js';
2627
import { RealTimeElement } from '../real-time-element.js';
28+
import theme from './theme.scss?inline';
2729

2830
interface BaseContext {
2931
path: string[];
@@ -70,14 +72,14 @@ export class MutationTestReportAppComponent extends RealTimeElement {
7072
@property({ attribute: false })
7173
public declare context: Context;
7274

73-
@property()
75+
@property({ type: Array })
7476
public declare path: readonly string[];
7577

7678
@property({ attribute: 'title-postfix' })
7779
public declare titlePostfix: string | undefined;
7880

7981
@property({ reflect: true })
80-
public declare theme?: string;
82+
public declare theme?: Theme;
8183

8284
@property({ attribute: false })
8385
public get themeBackgroundColor(): string {
@@ -155,11 +157,11 @@ export class MutationTestReportAppComponent extends RealTimeElement {
155157
}
156158
}
157159

158-
private getTheme(): string {
160+
private getTheme(): Theme {
159161
// 1. check local storage
160162
const theme = isLocalStorageAvailable() && localStorage.getItem('mutation-testing-elements-theme');
161163
if (theme) {
162-
return theme;
164+
return theme as Theme;
163165
// 2. check for user's OS preference
164166
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)')?.matches) {
165167
return 'dark';
@@ -225,7 +227,7 @@ export class MutationTestReportAppComponent extends RealTimeElement {
225227
document.title = this.title;
226228
}
227229

228-
public themeSwitch = (event: CustomEvent<string>) => {
230+
public themeSwitch = (event: MteCustomEvent<'theme-switch'>) => {
229231
this.theme = event.detail;
230232

231233
if (isLocalStorageAvailable()) {

packages/elements/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ import './components/drawer-test/drawer-test.component.js';
1313
import './components/file-icon/file-icon.component.js';
1414
import './components/tooltip/tooltip.component.js';
1515
import './components/result-status-bar/result-status-bar.js';
16+
17+
import type { MteCustomEvent } from './lib/custom-events.js';
18+
19+
export type ThemeChangedEvent = MteCustomEvent<'theme-changed'>;

packages/elements/src/lib/custom-events.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { MutantModel, TestModel } from 'mutation-testing-metrics';
2+
import type { Theme } from './theme.js';
23

34
export interface CustomEventMap {
45
'mutant-selected': { selected: boolean; mutant: MutantModel | undefined };
56
'test-selected': { selected: boolean; test: TestModel | undefined };
6-
'theme-changed': { theme: string; themeBackgroundColor: string };
7-
'theme-switch': 'dark' | 'light';
7+
'theme-changed': { theme: Theme; themeBackgroundColor: string };
8+
'theme-switch': Theme;
89
'filters-changed': string[];
910
next: void;
1011
previous: void;

packages/elements/src/lib/theme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Theme = 'light' | 'dark';

0 commit comments

Comments
 (0)