Skip to content

Commit

Permalink
chore: updates documentation for MatchMediaStylesheetBehavior changes (
Browse files Browse the repository at this point in the history
…microsoft#3493)

* updates documentation for MatchMediaStylesheetBehavior changes

* fixing comments
  • Loading branch information
nicholasrice authored Jul 10, 2020
1 parent d939f5d commit e8d98f7
Showing 1 changed file with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,41 @@ FAST exposes a mechanism to attach stylesheets conditionally based on a [MatchMe

### MatchMedia stylesheets

`matchMediaStylesheetBehaviorFactory` can be used to construct a Behavior that will conditionally attach stylesheets based on the `matches` property of a [MediaQueryList](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList).
`MatchMediaStylesheetBehavior` can be used to attach a stylesheet when a [MediaQueryList](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList) matches and detach it when the query un-matches.

__Example: Using the `matchMediaStylesheetBehaviorFactory`__
```js
import { matchMediaStylesheetBehaviorFactory } from "@microsoft/fast-foundation";
const query = Window.matchMedia('(max-width: 600px)');
const maxWidthStylesheetBehavior = matchMediaStylesheetBehaviorFactory(query)
__Example: Constructing the `MatchMediaStyleSheetBehavior`__
```ts
import { MatchMediaStyleSheetBehavior } from "@microsoft/fast-foundation";

const mobileStylesheetBehavior = new MatchMediaStyleSheetBehavior(
Window.matchMedia('(max-width: 600px)'),
css`
body {
color: red;
}
`
));

const styles = css`
/* ... */
`.withBehaviors(
mobileStylesheetBehavior
)
```

`MatchMediaStyleSheetBehavior` can also be used to curry the [MediaQueryList](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList). This can be useful for defining commonly-used `MatchMediaStyleSheetBehavior`:

__Example: Re-using a commonly used query__
```ts
import { MatchMediaStyleSheetBehavior } from "@microsoft/fast-foundation";

const mobileStylesheetBehavior = MatchMediaStyleSheetBehavior.with(
Window.matchMedia('(max-width: 600px)')
);
const styles = css`
/* ... */
`.withBehaviors(
maxWidthStylesheetBehavior(css`
mobileStylesheetBehavior(css`
body {
color: red;
}
Expand All @@ -31,7 +55,7 @@ const styles = css`
FAST has a commitment to facilitating accessible web experiences and [forced-colors](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors) support is a core tenant of that commitment. `@microsoft/fast-components` exports the `forcedColorsStylesheetBehavior` utility to provide a simple mechanism to apply forced-color stylesheets without bloating the component stylesheet in non-forced-color environments. This Behavior is built using [MatchMedia Stylesheets](#matchmedia-stylesheets).

__Example: Forced-colors stylesheets__
```js
```ts
import { forcedColorsStylesheetBehavior } from "@microsoft/fast-foundation";
import { SystemColors } from "@microsoft/fast-web-utilities";
const styles = css`
Expand All @@ -45,6 +69,4 @@ const styles = css`
/* ... */
`)
)
```


```

0 comments on commit e8d98f7

Please sign in to comment.