mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-21 04:39:19 +00:00
Remove additional exports of breakpoint symbols.
Restore typedef entries in `Breakpoint` component. Generate type definitions for `constants.js` and `breakpointObserver.js`. Validate size passed to `smallerThan`/`largerThan`. Document `breakpointObserver`/`breakpoints`. Fix `Breakpoint` component docs/example.
This commit is contained in:
parent
3c1e868165
commit
213d4debe7
13 changed files with 97 additions and 14 deletions
|
@ -403,7 +403,18 @@
|
|||
"detail": "{ size: BreakpointSize; breakpointValue: BreakpointValue; }"
|
||||
}
|
||||
],
|
||||
"typedefs": []
|
||||
"typedefs": [
|
||||
{
|
||||
"type": "\"sm\" | \"md\" | \"lg\" | \"xlg\" | \"max\"",
|
||||
"name": "BreakpointSize",
|
||||
"ts": "type BreakpointSize = \"sm\" | \"md\" | \"lg\" | \"xlg\" | \"max\""
|
||||
},
|
||||
{
|
||||
"type": "320 | 672 | 1056 | 1312 | 1584",
|
||||
"name": "BreakpointValue",
|
||||
"ts": "type BreakpointValue = 320 | 672 | 1056 | 1312 | 1584"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"moduleName": "Button",
|
||||
|
|
|
@ -22,6 +22,14 @@ This utility component uses the [Window.matchMedia API](https://developer.mozill
|
|||
|
||||
Bind to the `size` prop to determine the current breakpoint size. Possible values include: `"sm" | "md" | "lg" | "xlg" | "max"`.
|
||||
|
||||
The `"on:match"` event will fire only when a breakpoint change event occurs (e.g., the browser width is resized).
|
||||
The `"on:change"` event will fire when the size is initially determined and when a breakpoint change event occurs (e.g., the browser width is resized).
|
||||
|
||||
<FileSource src="/framed/Breakpoint/Breakpoint" />
|
||||
<FileSource src="/framed/Breakpoint/Breakpoint" />
|
||||
|
||||
### Store and Breakpoint Values
|
||||
|
||||
As an alternative to the component, `breakpointObserver` can be used to get the current size as a Svelte store. The store has two additional functions which create derived stores that return a `boolean` indicating whether the size is smaller/larger than a certain breakpoint.
|
||||
|
||||
There also exists a `breakpoints` dictionary mapping from `BreakpointSize` to `BreakpointValue`.
|
||||
|
||||
<FileSource src="/framed/Breakpoint/BreakpointObserver" />
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
let events = [];
|
||||
</script>
|
||||
|
||||
<Breakpoint bind:size on:match="{(e) => (events = [...events, e.detail])}" />
|
||||
<Breakpoint bind:size on:change="{(e) => (events = [...events, e.detail])}" />
|
||||
|
||||
<p>Resize the width of your browser.</p>
|
||||
<h6>Breakpoint size</h6>
|
||||
<h1>{size}</h1>
|
||||
|
||||
<h6>on:match</h6>
|
||||
<h6>on:change</h6>
|
||||
<pre>
|
||||
{JSON.stringify(events, null, 2)}
|
||||
</pre>
|
||||
|
|
15
docs/src/pages/framed/Breakpoint/BreakpointObserver.svelte
Normal file
15
docs/src/pages/framed/Breakpoint/BreakpointObserver.svelte
Normal file
|
@ -0,0 +1,15 @@
|
|||
<script>
|
||||
import {
|
||||
breakpointObserver,
|
||||
breakpoints,
|
||||
} from "carbon-components-svelte/src/Breakpoint";
|
||||
|
||||
const size = breakpointObserver();
|
||||
const smaller = size.smallerThan("md");
|
||||
const larger = size.largerThan("md");
|
||||
</script>
|
||||
|
||||
<p>Current breakpoint size: {$size}</p>
|
||||
<p>Current breakpoint value: {breakpoints[$size]}px</p>
|
||||
<p>Smaller than medium: {$smaller}</p>
|
||||
<p>Larger than medium: {$larger}</p>
|
Loading…
Add table
Add a link
Reference in a new issue