diff --git a/COMPONENT_INDEX.md b/COMPONENT_INDEX.md index 2a39b52f..81510a5d 100644 --- a/COMPONENT_INDEX.md +++ b/COMPONENT_INDEX.md @@ -1,6 +1,6 @@ # Component Index -> 170 components exported from carbon-components-svelte@0.39.0. +> 171 components exported from carbon-components-svelte@0.39.0. ## Components @@ -11,6 +11,7 @@ - [`Breadcrumb`](#breadcrumb) - [`BreadcrumbItem`](#breadcrumbitem) - [`BreadcrumbSkeleton`](#breadcrumbskeleton) +- [`Breakpoint`](#breakpoint) - [`Button`](#button) - [`ButtonSet`](#buttonset) - [`ButtonSkeleton`](#buttonskeleton) @@ -344,6 +345,36 @@ None. | mouseenter | forwarded | -- | | mouseleave | forwarded | -- | +## `Breakpoint` + +### Types + +```ts +export type BreakpointSize = "sm" | "md" | "lg" | "xlg" | "max"; + +export type BreakpointValue = 320 | 672 | 1056 | 1312 | 1584; +``` + +### Props + +| Prop name | Kind | Reactive | Type | Default value | Description | +| :---------- | :----------------- | :------- | :--------------------------------------------------- | ------------------------------------------------------------------------- | ------------------------------------------------- | +| sizes | let | Yes | Record | { sm: false, md: false, lg: false, xlg: false, max: false, } | Carbon grid sizes as an object | +| size | let | Yes | BreakpointSize | -- | Determine the current Carbon grid breakpoint size | +| breakpoints | const | No | Record | { sm: 320, md: 672, lg: 1056, xlg: 1312, max: 1584, } | Reference the Carbon grid breakpoints | + +### Slots + +| Slot name | Default | Props | Fallback | +| :-------- | :------ | :------------------------------------------------------------------------------ | :------- | +| -- | Yes | { size: BreakpointSize; sizes: Record; } | -- | + +### Events + +| Event name | Type | Detail | +| :--------- | :--------- | :----------------------------------------------------------------------- | +| match | dispatched | { size: BreakpointSize; breakpointValue: BreakpointValue; } | + ## `Button` ### Props diff --git a/docs/src/COMPONENT_API.json b/docs/src/COMPONENT_API.json index 2f90e454..b94c4636 100644 --- a/docs/src/COMPONENT_API.json +++ b/docs/src/COMPONENT_API.json @@ -1,5 +1,5 @@ { - "total": 170, + "total": 171, "components": [ { "moduleName": "Accordion", @@ -344,6 +344,67 @@ "typedefs": [], "rest_props": { "type": "Element", "name": "div" } }, + { + "moduleName": "Breakpoint", + "filePath": "src/Breakpoint/Breakpoint.svelte", + "props": [ + { + "name": "size", + "kind": "let", + "description": "Determine the current Carbon grid breakpoint size", + "type": "BreakpointSize", + "isFunction": false, + "constant": false, + "reactive": true + }, + { + "name": "sizes", + "kind": "let", + "description": "Carbon grid sizes as an object", + "type": "Record", + "value": "{ sm: false, md: false, lg: false, xlg: false, max: false, }", + "isFunction": false, + "constant": false, + "reactive": true + }, + { + "name": "breakpoints", + "kind": "const", + "description": "Reference the Carbon grid breakpoints", + "type": "Record", + "value": "{ sm: 320, md: 672, lg: 1056, xlg: 1312, max: 1584, }", + "isFunction": false, + "constant": true, + "reactive": false + } + ], + "slots": [ + { + "name": "__default__", + "default": true, + "slot_props": "{ size: BreakpointSize; sizes: Record; }" + } + ], + "events": [ + { + "type": "dispatched", + "name": "match", + "detail": "{ size: BreakpointSize; breakpointValue: BreakpointValue; }" + } + ], + "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", "filePath": "src/Button/Button.svelte", diff --git a/docs/src/components/ComponentApi.svelte b/docs/src/components/ComponentApi.svelte index 820a45ed..91d24fc0 100644 --- a/docs/src/components/ComponentApi.svelte +++ b/docs/src/components/ComponentApi.svelte @@ -141,7 +141,7 @@ style="margin-top: var(--cds-spacing-08)" class="my-layout-01-03" type="multi" - code="{component.typedefs.map((t) => t.ts).join(';\n\n')}" + code="{component.typedefs.map((t) => t.ts).join(';\n\n')};" /> {:else}

No typedefs.

diff --git a/docs/src/components/InlineSnippet.svelte b/docs/src/components/InlineSnippet.svelte index 48a02642..136fe90b 100644 --- a/docs/src/components/InlineSnippet.svelte +++ b/docs/src/components/InlineSnippet.svelte @@ -11,6 +11,6 @@ diff --git a/docs/src/pages/_layout.svelte b/docs/src/pages/_layout.svelte index 7f97d8e2..0946cf77 100644 --- a/docs/src/pages/_layout.svelte +++ b/docs/src/pages/_layout.svelte @@ -20,7 +20,7 @@ import Footer from "../components/Footer.svelte"; const deprecated = ["ToggleSmall", "Icon"]; - const new_components = ["ProgressBar", "RecursiveList", "TreeView"]; + const new_components = ["Breakpoint", "RecursiveList", "TreeView"]; let isOpen = false; let isSideNavOpen = true; diff --git a/docs/src/pages/components/Breakpoint.svx b/docs/src/pages/components/Breakpoint.svx new file mode 100644 index 00000000..082f57bc --- /dev/null +++ b/docs/src/pages/components/Breakpoint.svx @@ -0,0 +1,27 @@ + + + +The [Carbon Design System grid implementation](https://carbondesignsystem.com/guidelines/2x-grid/implementation#responsive-options) defines five responsive breakpoints: + + + Small: less than 672px + Medium: 672 - 1056px + Large: 1056 - 1312px + X-Large: 1312 - 1584px + Max: greater than 1584px + + +This utility component uses the [Window.matchMedia API](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia) to declaratively determine the current Carbon breakpoint size. + +### Default + +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). + + \ No newline at end of file diff --git a/docs/src/pages/framed/Breakpoint/Breakpoint.svelte b/docs/src/pages/framed/Breakpoint/Breakpoint.svelte new file mode 100644 index 00000000..d47affd2 --- /dev/null +++ b/docs/src/pages/framed/Breakpoint/Breakpoint.svelte @@ -0,0 +1,28 @@ + + + + +

Resize the width of your browser.

+
Breakpoint size
+

{size}

+ +
on:match
+
+  {JSON.stringify(events,null, 2)}
+
+ + diff --git a/docs/svelte.config.js b/docs/svelte.config.js index 035a51dd..8f27725b 100644 --- a/docs/svelte.config.js +++ b/docs/svelte.config.js @@ -68,6 +68,7 @@ function plugin() { const formattedCode = format(scriptBlock + node.value, { parser: "svelte", svelteBracketNewLine: true, + svelteSortOrder: "scripts-markup-styles", }); const highlightedCode = Prism.highlight( formattedCode, diff --git a/src/Breakpoint/Breakpoint.svelte b/src/Breakpoint/Breakpoint.svelte new file mode 100644 index 00000000..19ef305f --- /dev/null +++ b/src/Breakpoint/Breakpoint.svelte @@ -0,0 +1,100 @@ + + + diff --git a/src/Breakpoint/index.js b/src/Breakpoint/index.js new file mode 100644 index 00000000..a84d174b --- /dev/null +++ b/src/Breakpoint/index.js @@ -0,0 +1 @@ +export { default as Breakpoint } from "./Breakpoint.svelte"; diff --git a/src/index.js b/src/index.js index 5dc44324..c73f55f6 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ export { Accordion, AccordionItem, AccordionSkeleton } from "./Accordion"; export { AspectRatio } from "./AspectRatio"; export { Breadcrumb, BreadcrumbItem, BreadcrumbSkeleton } from "./Breadcrumb"; +export { Breakpoint } from "./Breakpoint"; export { Button, ButtonSkeleton, ButtonSet } from "./Button"; export { Checkbox, CheckboxSkeleton } from "./Checkbox"; export { ContentSwitcher, Switch } from "./ContentSwitcher"; diff --git a/tests/Breakpoint.test.svelte b/tests/Breakpoint.test.svelte new file mode 100644 index 00000000..9f71554f --- /dev/null +++ b/tests/Breakpoint.test.svelte @@ -0,0 +1,15 @@ + + + + {currentSize} + diff --git a/types/Breakpoint/Breakpoint.d.ts b/types/Breakpoint/Breakpoint.d.ts new file mode 100644 index 00000000..cb5d1cab --- /dev/null +++ b/types/Breakpoint/Breakpoint.d.ts @@ -0,0 +1,37 @@ +/// +import { SvelteComponentTyped } from "svelte"; + +export type BreakpointSize = "sm" | "md" | "lg" | "xlg" | "max"; + +export type BreakpointValue = 320 | 672 | 1056 | 1312 | 1584; + +export interface BreakpointProps { + /** + * Determine the current Carbon grid breakpoint size + */ + size?: BreakpointSize; + + /** + * Carbon grid sizes as an object + * @default { sm: false, md: false, lg: false, xlg: false, max: false, } + */ + sizes?: Record; + + /** + * Reference the Carbon grid breakpoints + * @constant + * @default { sm: 320, md: 672, lg: 1056, xlg: 1312, max: 1584, } + */ + breakpoints?: { sm: 320; md: 672; lg: 1056; xlg: 1312; max: 1584 }; +} + +export default class Breakpoint extends SvelteComponentTyped< + BreakpointProps, + { + match: CustomEvent<{ + size: BreakpointSize; + breakpointValue: BreakpointValue; + }>; + }, + { default: { size: BreakpointSize; sizes: Record } } +> {} diff --git a/types/index.d.ts b/types/index.d.ts index 02714fef..4dff84bd 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -5,6 +5,7 @@ export { default as AspectRatio } from "./AspectRatio/AspectRatio"; export { default as Breadcrumb } from "./Breadcrumb/Breadcrumb"; export { default as BreadcrumbItem } from "./Breadcrumb/BreadcrumbItem"; export { default as BreadcrumbSkeleton } from "./Breadcrumb/BreadcrumbSkeleton"; +export { default as Breakpoint } from "./Breakpoint/Breakpoint"; export { default as Button } from "./Button/Button"; export { default as ButtonSkeleton } from "./Button/ButtonSkeleton"; export { default as ButtonSet } from "./Button/ButtonSet";