mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
feat(breakpoint): integrate Breakpoint
with v11 (#1957)
This commit is contained in:
parent
1600308614
commit
b4930910bc
7 changed files with 14 additions and 8 deletions
|
@ -335,7 +335,7 @@ export type BreakpointValue = 320 | 672 | 1056 | 1312 | 1584;
|
||||||
|
|
||||||
| Prop name | Required | Kind | Reactive | Type | Default value | Description |
|
| Prop name | Required | Kind | Reactive | Type | Default value | Description |
|
||||||
| :-------- | :------- | :--------------- | :------- | -------------------------------------------- | ------------------------------------------------------------------------- | ------------------------------------------------- |
|
| :-------- | :------- | :--------------- | :------- | -------------------------------------------- | ------------------------------------------------------------------------- | ------------------------------------------------- |
|
||||||
| sizes | No | <code>let</code> | Yes | <code>Record<BreakpointSize, boolean></code> | <code>{ sm: false, md: false, lg: false, xlg: false, max: false, }</code> | Carbon grid sizes as an object |
|
| sizes | No | <code>let</code> | Yes | <code>Record<BreakpointSize, boolean></code> | <code>{ sm: false, md: false, lg: false, xlg: false, max: false, }</code> | Bind to all Carbon grid breakpoints. |
|
||||||
| size | No | <code>let</code> | Yes | <code>BreakpointSize</code> | <code>undefined</code> | Determine the current Carbon grid breakpoint size |
|
| size | No | <code>let</code> | Yes | <code>BreakpointSize</code> | <code>undefined</code> | Determine the current Carbon grid breakpoint size |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
|
@ -358,7 +358,7 @@
|
||||||
{
|
{
|
||||||
"name": "sizes",
|
"name": "sizes",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
"description": "Carbon grid sizes as an object",
|
"description": "Bind to all Carbon grid breakpoints.",
|
||||||
"type": "Record<BreakpointSize, boolean>",
|
"type": "Record<BreakpointSize, boolean>",
|
||||||
"value": "{ sm: false, md: false, lg: false, xlg: false, max: false, }",
|
"value": "{ sm: false, md: false, lg: false, xlg: false, max: false, }",
|
||||||
"isFunction": false,
|
"isFunction": false,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import Preview from "../../components/Preview.svelte";
|
import Preview from "../../components/Preview.svelte";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
The [Carbon Design System grid implementation](https://carbondesignsystem.com/guidelines/2x-grid/implementation#responsive-options) defines five responsive breakpoints:
|
The [Carbon Design System grid implementation](https://carbondesignsystem.com/elements/2x-grid/overview/#breakpoints) defines five responsive breakpoints:
|
||||||
|
|
||||||
<UnorderedList svx-ignore style="margin-bottom: var(--bx-spacing-08)">
|
<UnorderedList svx-ignore style="margin-bottom: var(--bx-spacing-08)">
|
||||||
<ListItem><strong>Small</strong>: less than 672px</ListItem>
|
<ListItem><strong>Small</strong>: less than 672px</ListItem>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {"sm" | "md" | "lg" | "xlg" | "max"} BreakpointSize
|
* @typedef {"sm" | "md" | "lg" | "xlg" | "max"} BreakpointSize
|
||||||
* @typedef {320 | 672 | 1056 | 1312 | 1584} BreakpointValue
|
* @typedef {320 | 672 | 1056 | 1312 | 1584} BreakpointValue
|
||||||
|
@ -13,7 +15,7 @@
|
||||||
export let size = undefined;
|
export let size = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Carbon grid sizes as an object
|
* Bind to all Carbon grid breakpoints.
|
||||||
* @type {Record<BreakpointSize, boolean>}
|
* @type {Record<BreakpointSize, boolean>}
|
||||||
*/
|
*/
|
||||||
export let sizes = {
|
export let sizes = {
|
||||||
|
@ -28,6 +30,7 @@
|
||||||
import { breakpointObserver } from "./breakpointObserver";
|
import { breakpointObserver } from "./breakpointObserver";
|
||||||
import { breakpoints } from "./breakpoints";
|
import { breakpoints } from "./breakpoints";
|
||||||
|
|
||||||
|
/** @type {import("svelte").EventDispatcher<{ change: { size: BreakpointSize; breakpointValue: BreakpointValue; } }>} */
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
const observer = breakpointObserver();
|
const observer = breakpointObserver();
|
||||||
|
|
||||||
|
@ -39,8 +42,9 @@
|
||||||
xlg: size == "xlg",
|
xlg: size == "xlg",
|
||||||
max: size == "max",
|
max: size == "max",
|
||||||
};
|
};
|
||||||
$: if (size != undefined)
|
$: if (size != undefined) {
|
||||||
dispatch("change", { size, breakpointValue: breakpoints[size] });
|
dispatch("change", { size, breakpointValue: breakpoints[size] });
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<slot size="{size}" sizes="{sizes}" />
|
<slot size="{size}" sizes="{sizes}" />
|
||||||
|
|
|
@ -75,8 +75,9 @@ export function breakpointObserver() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkSizeValid(size) {
|
function checkSizeValid(size) {
|
||||||
if (size in breakpoints == false)
|
if (size in breakpoints == false) {
|
||||||
throw new Error(`"${size}" is not a valid breakpoint size.`);
|
throw new Error(`"${size}" is not a valid breakpoint size.`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default breakpointObserver;
|
export default breakpointObserver;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Pixel sizes of Carbon grid breakpoints.
|
* Carbon grid breakpoints in px.
|
||||||
|
* @see https://carbondesignsystem.com/elements/2x-grid/overview/#breakpoints
|
||||||
* @type {Record<import("./breakpoints").BreakpointSize, BreakpointValue>}
|
* @type {Record<import("./breakpoints").BreakpointSize, BreakpointValue>}
|
||||||
*/
|
*/
|
||||||
export const breakpoints = Object.freeze({
|
export const breakpoints = Object.freeze({
|
||||||
|
|
2
types/Breakpoint/Breakpoint.svelte.d.ts
vendored
2
types/Breakpoint/Breakpoint.svelte.d.ts
vendored
|
@ -12,7 +12,7 @@ export interface BreakpointProps {
|
||||||
size?: BreakpointSize;
|
size?: BreakpointSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Carbon grid sizes as an object
|
* Bind to all Carbon grid breakpoints.
|
||||||
* @default { sm: false, md: false, lg: false, xlg: false, max: false, }
|
* @default { sm: false, md: false, lg: false, xlg: false, max: false, }
|
||||||
*/
|
*/
|
||||||
sizes?: Record<BreakpointSize, boolean>;
|
sizes?: Record<BreakpointSize, boolean>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue