Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
e5d7891
refactor setTheme() for setting theme on elements
marchbox Jul 8, 2024
3bff695
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 8, 2024
7ecf93d
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 9, 2024
1bcd739
reorg the code
marchbox Jul 9, 2024
964b29d
set local themes
marchbox Jul 9, 2024
41ca177
fix firefox bug
marchbox Jul 9, 2024
c20be72
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 10, 2024
cbc6471
improve set theme story
marchbox Jul 10, 2024
694d794
fix story
marchbox Jul 10, 2024
1af991d
fix safari scope bug
marchbox Jul 10, 2024
1f3afa9
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 10, 2024
66a3a60
update api report
marchbox Jul 10, 2024
d22c5b4
check themeable element
marchbox Jul 11, 2024
24a1a6a
add change file
marchbox Jul 11, 2024
4b6b1a6
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 11, 2024
b9f3770
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 11, 2024
42a880b
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 15, 2024
3b2f458
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 16, 2024
8761294
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 18, 2024
ded57a8
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 19, 2024
092400c
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 20, 2024
54d056f
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 23, 2024
2aa86bd
Merge branch 'master' of github.com:marchbox/fluentui into users/mach…
marchbox Jul 24, 2024
0cc1a90
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 24, 2024
c25f436
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 26, 2024
651b7e7
update Theme type in story
marchbox Jul 26, 2024
110e03e
wip: add test
marchbox Jul 28, 2024
bdbb26e
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 29, 2024
a37ed82
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 29, 2024
cd2e084
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 30, 2024
c0f0348
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 30, 2024
8e064b3
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Jul 31, 2024
35e358f
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Aug 1, 2024
318eb26
fix formatting
marchbox Aug 1, 2024
3cc0a90
Merge branch 'users/machi/setthemefor' of github.com:marchbox/fluentu…
marchbox Aug 1, 2024
f3fa397
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Aug 2, 2024
9284219
Merge branch 'master' of github.com:marchbox/fluentui into users/mach…
marchbox Aug 5, 2024
3933664
clean up set theme in storybook and playwright
marchbox Aug 5, 2024
2f090a2
fix formatting
marchbox Aug 5, 2024
c915770
unset theme when css scope is not supported
marchbox Aug 6, 2024
97cb258
Merge branch 'microsoft:master' into users/machi/setthemefor
marchbox Aug 6, 2024
64ff7ba
use removeProperty instead
marchbox Aug 6, 2024
f0b2565
Merge branch 'master' of github.com:marchbox/fluentui into users/mach…
marchbox Aug 13, 2024
1b9c5d0
revert unwanted change
marchbox Aug 13, 2024
be32c93
improve the stories
marchbox Aug 13, 2024
2ec4205
add tests
marchbox Aug 13, 2024
8a6eb15
fix formatting
marchbox Aug 13, 2024
5cd9fa2
enable tests in other engines and fix issues
marchbox Aug 14, 2024
587923b
Merge branch 'master' into users/machi/setthemefor
marchbox Aug 14, 2024
dac52c8
fix formatting
marchbox Aug 14, 2024
f1802ac
remove use of CSS.registerProperty()
marchbox Aug 14, 2024
d461235
allow unset global theme in story
marchbox Aug 14, 2024
28b6bed
Merge branch 'master' into users/machi/setthemefor
marchbox Aug 14, 2024
d9b6f83
trim margins
marchbox Aug 14, 2024
b133052
fix formatting
marchbox Aug 14, 2024
84fe643
add argument doc
marchbox Aug 14, 2024
2a92a62
add more test
marchbox Aug 15, 2024
d82f6a9
update api report
marchbox Aug 15, 2024
c679aa5
Merge branch 'master' into users/machi/setthemefor
marchbox Aug 15, 2024
aeb64b4
add perf tests for setting themes on light and shadow DOM
marchbox Aug 15, 2024
963ad6c
fix formatting
marchbox Aug 15, 2024
b1fefdd
Merge branch 'master' into users/machi/setthemefor
marchbox Aug 15, 2024
a6848cb
update change file as per feedback
marchbox Aug 16, 2024
5d6e374
Merge branch 'master' into users/machi/setthemefor
marchbox Aug 16, 2024
f148920
revert accidental changes
marchbox Aug 16, 2024
f4e65e8
Merge branch 'master' into users/machi/setthemefor
marchbox Aug 16, 2024
94fc7b4
Merge branch 'master' into users/machi/setthemefor
marchbox Aug 19, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "feat: enabling setting theme on an individual element and unsetting themes",
"packageName": "@fluentui/web-components",
"email": "machi@microsoft.com",
"dependentChangeType": "patch"
}
17 changes: 14 additions & 3 deletions packages/web-components/.storybook/preview.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { switchTheme } from '../public/theme-switch.js';
import { teamsDarkTheme, teamsLightTheme, webDarkTheme, webLightTheme } from '@fluentui/tokens';
import webcomponentsTheme from './theme.mjs';
import { setTheme } from '../src/theme/set-theme.js';

import '../src/index-rollup.js';
import './docs-root.css';

const themes = {
'web-light': webLightTheme,
'web-dark': webDarkTheme,
'teams-light': teamsLightTheme,
'teams-dark': teamsDarkTheme,
};

function changeTheme(/** @type {Event} */ e) {
switchTheme(/** @type {Parameters<typeof switchTheme>[number]} */ (/** @type {HTMLInputElement}*/ (e.target).value));
setTheme(themes[/** @type {keyof themes} */ (/** @type {HTMLInputElement}*/ (e.target).value)]);
}

// This is needed in Playwright.
Object.defineProperty(window, 'setTheme', { value: setTheme });

document.getElementById('theme-switch')?.addEventListener('change', changeTheme, false);
switchTheme('web-light');
setTheme(themes['web-light']);

export const parameters = {
layout: 'fullscreen',
Expand Down
79 changes: 71 additions & 8 deletions packages/web-components/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,62 @@ export class BaseButton extends FASTElement {
value?: string;
}

// @public
export class BaseCheckbox extends FASTElement {
autofocus: boolean;
get checked(): boolean;
set checked(next: boolean);
checkValidity(): boolean;
// @internal
clickHandler(e: MouseEvent): boolean | void;
// (undocumented)
connectedCallback(): void;
disabled?: boolean;
disabledAttribute?: boolean;
// @internal
protected disabledAttributeChanged(prev: boolean | undefined, next: boolean | undefined): void;
// @internal
protected disabledChanged(prev: boolean | undefined, next: boolean | undefined): void;
// @internal
elementInternals: ElementInternals;
get form(): HTMLFormElement | null;
static formAssociated: boolean;
formAttribute?: string;
// @internal
formResetCallback(): void;
initialChecked?: boolean;
// @internal
protected initialCheckedChanged(prev: boolean | undefined, next: boolean | undefined): void;
initialValue: string;
// @internal
protected initialValueChanged(prev: string, next: string): void;
// @internal
inputHandler(e: InputEvent): boolean | void;
// @internal
keydownHandler(e: KeyboardEvent): boolean | void;
// @internal
keyupHandler(e: KeyboardEvent): boolean | void;
get labels(): ReadonlyArray<HTMLLabelElement>;
name: string;
reportValidity(): boolean;
required: boolean;
// @internal
protected requiredChanged(prev: boolean, next: boolean): void;
// @internal
protected setAriaChecked(value?: boolean): void;
setCustomValidity(message: string): void;
// @internal
setFormValue(value: File | string | FormData | null, state?: File | string | FormData | null): void;
// @internal
setValidity(flags?: Partial<ValidityState>, message?: string, anchor?: HTMLElement): void;
toggleChecked(force?: boolean): void;
get validationMessage(): string;
get validity(): ValidityState;
get value(): string;
set value(value: string);
get willValidate(): boolean;
}

// @public
export class BaseDivider extends FASTElement {
// (undocumented)
Expand Down Expand Up @@ -883,8 +939,6 @@ export const ButtonType: {
// @public
export type ButtonType = ValuesOf<typeof ButtonType>;

// Warning: (ae-forgotten-export) The symbol "BaseCheckbox" needs to be exported by the entry point index.d.ts
//
// @public
export class Checkbox extends BaseCheckbox {
constructor();
Expand Down Expand Up @@ -2234,7 +2288,10 @@ export const DividerDefinition: FASTElementDefinition<typeof Divider>;

// @public
export const DividerOrientation: {
readonly horizontal: "horizontal";
readonly horizontal: "horizontal"; /**
* Divider roles
* @public
*/
readonly vertical: "vertical";
};

Expand Down Expand Up @@ -2971,7 +3028,10 @@ export const RadioGroupDefinition: FASTElementDefinition<typeof RadioGroup>;

// @public
export const RadioGroupOrientation: {
readonly horizontal: "horizontal";
readonly horizontal: "horizontal"; /**
* Radio Group orientation
* @public
*/
readonly vertical: "vertical";
};

Expand Down Expand Up @@ -3049,12 +3109,12 @@ export const roleForMenuItem: {
// Warning: (ae-internal-missing-underscore) The name "setTheme" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
export const setTheme: (theme: Theme) => void;
export function setTheme(theme: Theme | null, node?: Document | HTMLElement): void;

// Warning: (ae-internal-missing-underscore) The name "setThemeFor" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export const setThemeFor: (element: HTMLElement, theme: Theme) => void;
// @internal @deprecated (undocumented)
export function setThemeFor(element: HTMLElement, theme: Theme | null): void;

// @public
export const shadow16 = "var(--shadow16)";
Expand Down Expand Up @@ -3475,7 +3535,10 @@ export const TablistDefinition: FASTElementDefinition<typeof Tablist>;

// @public
export const TablistOrientation: {
readonly horizontal: "horizontal";
readonly horizontal: "horizontal"; /**
* The appearance of the component
* @public
*/
readonly vertical: "vertical";
};

Expand Down
19 changes: 18 additions & 1 deletion packages/web-components/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

const config: PlaywrightTestConfig = {
reporter: 'list',
testMatch: /.*\.spec\.ts$/,
retries: 3,
fullyParallel: process.env.CI ? false : true,
timeout: process.env.CI ? 10000 : 30000,
Expand All @@ -13,6 +13,23 @@ const config: PlaywrightTestConfig = {
width: 1280,
},
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
testMatch: /.*\.spec\.ts$/,
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
testMatch: [/set-theme\.spec\.ts$/],
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
testMatch: [/set-theme\.spec\.ts$/],
},
],
webServer: {
// double-quotes are required for Windows
command: `node -e "import('express').then(({ default: e }) => e().use(e.static('./dist/storybook')).listen(6006))"`,
Expand Down
13 changes: 0 additions & 13 deletions packages/web-components/public/theme-switch.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const tests: Record<string, TestRenderFunction> = {
setTheme(teamsDarkTheme);
setTheme(teamsLightTheme);

// Unset themes
setTheme(null);

endMeasure();

onComplete();
Expand Down
36 changes: 36 additions & 0 deletions packages/web-components/src/theme/set-theme.local.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { measurePerformance, type TestRenderFunction } from '@tensile-perf/web-components';
import { teamsDarkTheme, teamsLightTheme, webDarkTheme, webLightTheme } from '@fluentui/tokens';

import { setTheme } from './set-theme.js';

const tests: Record<string, TestRenderFunction> = {
mount: ({ onComplete }) => {
const { startMeasure, endMeasure } = measurePerformance();

const el = document.createElement('div');
document.body.append(el);

startMeasure();

// Newly set themes
setTheme(webLightTheme, el);
setTheme(webDarkTheme, el);
setTheme(teamsDarkTheme, el);
setTheme(teamsLightTheme, el);

// Cached themes
setTheme(webLightTheme, el);
setTheme(webDarkTheme, el);
setTheme(teamsDarkTheme, el);
setTheme(teamsLightTheme, el);

// Unset themes
setTheme(null, el);

endMeasure();

onComplete();
},
};

export { tests };
38 changes: 38 additions & 0 deletions packages/web-components/src/theme/set-theme.shadow.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { measurePerformance, type TestRenderFunction } from '@tensile-perf/web-components';
import { teamsDarkTheme, teamsLightTheme, webDarkTheme, webLightTheme } from '@fluentui/tokens';

import { setTheme } from './set-theme.js';

const tests: Record<string, TestRenderFunction> = {
mount: ({ onComplete }) => {
const { startMeasure, endMeasure } = measurePerformance();

const el = document.createElement('div');
el.attachShadow({ mode: 'open' });
el.shadowRoot!.append(document.createElement('span'));
document.body.append(el);

startMeasure();

// Newly set themes
setTheme(webLightTheme, el);
setTheme(webDarkTheme, el);
setTheme(teamsDarkTheme, el);
setTheme(teamsLightTheme, el);

// Cached themes
setTheme(webLightTheme, el);
setTheme(webDarkTheme, el);
setTheme(teamsDarkTheme, el);
setTheme(teamsLightTheme, el);

// Unset themes
setTheme(null, el);

endMeasure();

onComplete();
},
};

export { tests };
Loading