Skip to content

Commit 7cbc248

Browse files
authored
fix(web-components): add set theme export (#35778)
1 parent 019b0e7 commit 7cbc248

8 files changed

Lines changed: 79 additions & 45 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "fix: add setTheme export",
4+
"packageName": "@fluentui/web-components",
5+
"email": "rupertdavid@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/web-components/.storybook/docs-root.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,16 @@ body ul li {
438438

439439
h1.fluent {
440440
font-weight: 700;
441-
font-size: 40px;
441+
font-size: 40px !important;
442442
font-family: 'Segoe UI';
443443
line-height: 48px;
444444
letter-spacing: -0.16px;
445445
}
446446

447+
h1.fluent p {
448+
font-size: 40px !important;
449+
}
450+
447451
h1.fluent .fluent-version {
448452
display: block;
449453
font-size: 24px;

packages/web-components/docs/web-components.api.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,9 +3543,7 @@ export const roleForMenuItem: {
35433543
[value in keyof typeof MenuItemRole]: (typeof MenuItemRole)[value];
35443544
};
35453545

3546-
// Warning: (ae-internal-missing-underscore) The name "setTheme" should be prefixed with an underscore because the declaration is marked as @internal
3547-
//
3548-
// @internal
3546+
// @public
35493547
export function setTheme(theme: Theme | null, node?: Document | HTMLElement): void;
35503548

35513549
// Warning: (ae-internal-missing-underscore) The name "setThemeFor" should be prefixed with an underscore because the declaration is marked as @internal
@@ -4319,9 +4317,7 @@ export const TextWeight: {
43194317
// @public
43204318
export type TextWeight = ValuesOf<typeof TextWeight>;
43214319

4322-
// Warning: (ae-internal-missing-underscore) The name "Theme" should be prefixed with an underscore because the declaration is marked as @internal
4323-
//
4324-
// @internal
4320+
// @public
43254321
export type Theme = Record<string, string | number>;
43264322

43274323
// @public

packages/web-components/src/_docs/developer/polyfilling.mdx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,33 @@ Fluent UI Web Components takes a "bring your own polyfill" approach so that proj
1010

1111
Here's a list of features we're leveraging and their current [Baseline](https://web.dev/baseline) browser support.
1212

13-
| | Chrome | Edge | Firefox | Safari |
14-
| ---------------------- | ------ | ---- | ------- | ------ |
15-
| HTML Popover Attribute | 114 | 114 | 125 | 17 |
16-
| CSS Anchor Positioning | 125 | 125 |||
13+
<table>
14+
<thead>
15+
<tr>
16+
<th></th>
17+
<th>Chrome</th>
18+
<th>Edge</th>
19+
<th>Firefox</th>
20+
<th>Safari</th>
21+
</tr>
22+
</thead>
23+
<tbody>
24+
<tr>
25+
<td>HTML Popover Attribute</td>
26+
<td>114</td>
27+
<td>114</td>
28+
<td>125</td>
29+
<td>17</td>
30+
</tr>
31+
<tr>
32+
<td>CSS Anchor Positioning</td>
33+
<td>125</td>
34+
<td>125</td>
35+
<td>147</td>
36+
<td>26</td>
37+
</tr>
38+
</tbody>
39+
</table>
1740

1841
## HTML Popover
1942

packages/web-components/src/_docs/developer/quick-start.mdx

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,64 @@ import { Meta } from '@storybook/addon-docs/blocks';
22

33
<Meta title="Concepts/Developer/Quick Start" />
44

5-
## Install
5+
# Quick Start
66

7-
Fluent UI should be installed as a `dependency` of your app.
7+
## Install Fluent UI Web Components v3
88

9-
**Yarn**
9+
Fluent UI web components and Fluent tokens should be installed as a `dependency` of your app. Both packages are also [available on unpkg](https://unpkg.com/@fluentui/web-components).
1010

1111
```sh
12-
yarn add @fluentui/web-components
12+
npm install @fluentui/web-components @fluentui/tokens
1313
```
1414

15-
**NPM**
15+
## Basic Usage: Import entire component bundle
1616

17-
```sh
18-
npm i @fluentui/web-components
19-
```
17+
The easiest way to get up and running with Fluent Web Components is to use our entire component bundle. You will also need Fluent UI's design token CSS on the page in either by generating stylesheet yourself or using our `setTheme` utility.
2018

21-
**pnpm**
19+
```js
20+
// Import all components and the setTheme utility
21+
import '@fluentui/web-components/web-components.min.js';
2222

23-
```sh
24-
pnpm add @fluentui/web-components
23+
// Set theme
24+
import { webLightTheme } from '@fluentui/tokens';
25+
setTheme(webLightTheme);
2526
```
2627

27-
## Setup
28+
## Recommended Usage: Use our tree-shakable component exports
29+
30+
To reduce your production bundle size, we offer each component as a standalone ESM export. We recommend this pathway for maximum performance and tree-shaking. There are two options for importing individual components.
31+
32+
### Importing the defined component
2833

29-
Fluent UI Web Components are styled using tokens in the form of CSS variables. You can use the `setTheme` utility to provide a theme for your website or application.
34+
Our defined component exports will import single components _and_ define the custom element on the page.
3035

3136
```js
37+
// Import with side-effectful Custom Element definitions
38+
import '@fluentui/web-components/button.js';
39+
import '@fluentui/web-components/dialog.js';
40+
41+
// Set theme
3242
import { setTheme } from '@fluentui/web-components';
3343
import { webLightTheme } from '@fluentui/tokens';
34-
3544
setTheme(webLightTheme);
3645
```
3746

38-
## Usage
39-
40-
That's it. You can now use Fluent UI Web Components in your app.
41-
42-
**Importing the defined component:**
47+
Note: If a component has a child component dependency, you will need to import both components (e.g. Tablist and Tab).
4348

44-
```js
45-
import '@fluentui/web-components/button.js';
46-
```
49+
### Defining the element yourself using named imports
4750

48-
**Defining the element yourself using named imports:**
51+
If you want to control side-effects and need granular control of when your component definitions are defined, import the named imports for each component definition, and call the `define` method.
4952

5053
```js
51-
import { ButtonDefinition, FluentDesignSystem } from '@fluentui/web-components';
54+
// Import non-side-effectful component definitions
55+
import { ButtonDefinition, DialogDefinition, FluentDesignSystem } from '@fluentui/web-components';
5256

57+
// Manual component definition
5358
ButtonDefinition.define(FluentDesignSystem.registry);
59+
DialogDefinition.define(FluentDesignSystem.registry);
60+
61+
// Set theme
62+
import { setTheme } from '@fluentui/web-components';
63+
import { webLightTheme } from '@fluentui/tokens';
64+
setTheme(webLightTheme);
5465
```

packages/web-components/src/index-rollup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ import './toggle-button/define.js';
4242
import './tooltip/define.js';
4343
import './tree/define.js';
4444
import './tree-item/define.js';
45+
export { setTheme } from './theme/set-theme.js';

packages/web-components/src/theme/index.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ export {
44
borderRadiusMedium,
55
borderRadiusLarge,
66
borderRadiusXLarge,
7-
borderRadius2XLarge,
8-
borderRadius3XLarge,
9-
borderRadius4XLarge,
10-
borderRadius5XLarge,
11-
borderRadius6XLarge,
127
borderRadiusCircular,
138
fontSizeBase100,
149
fontSizeBase200,
@@ -154,9 +149,6 @@ export {
154149
colorNeutralBackground5Selected,
155150
colorNeutralBackground6,
156151
colorNeutralBackgroundInverted,
157-
colorNeutralBackgroundInvertedHover,
158-
colorNeutralBackgroundInvertedPressed,
159-
colorNeutralBackgroundInvertedSelected,
160152
colorNeutralBackgroundStatic,
161153
colorSubtleBackground,
162154
colorSubtleBackgroundHover,

packages/web-components/src/theme/set-theme.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { uniqueId } from '@microsoft/fast-web-utilities';
44
/**
55
* Not using the `Theme` type from `@fluentui/tokens` package to allow custom
66
* tokens to be added.
7-
* @internal
7+
* @public
88
*/
99
export type Theme = Record<string, string | number>;
1010

@@ -46,7 +46,7 @@ const globalThemeStyleSheet = new CSSStyleSheet();
4646
* as each entry’s value is either a string or a number.
4747
* @param node - The node to set the theme on, defaults to `document` for
4848
* setting global theme.
49-
* @internal
49+
* @public
5050
*/
5151
export function setTheme(theme: Theme | null, node: Document | HTMLElement = document) {
5252
if (!node || !isThemeableNode(node)) {

0 commit comments

Comments
 (0)