forked from carbon-design-system/carbon-components-svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial pass at Layer (new component) carbon-design-system#1892
- Loading branch information
Samuel Janda
committed
Mar 9, 2024
1 parent
559701e
commit f349b50
Showing
9 changed files
with
568 additions
and
241 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script> | ||
import { Layer } from "carbon-components-svelte"; | ||
import Preview from "../../components/Preview.svelte"; | ||
</script> | ||
|
||
## Default | ||
|
||
<Layer> | ||
<p>First layer</p> | ||
<Layer> | ||
<p>Second layer</p> | ||
<Layer> | ||
<p>Third layer</p> | ||
</Layer> | ||
</Layer> | ||
</Layer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script> | ||
import { getContext, setContext } from "svelte"; | ||
/** | ||
* Specify the layer level and override any existing levels based on hierarchy. | ||
* @type {0 | 1 | 2 } | ||
*/ | ||
export let level = undefined; | ||
/** | ||
* Specify the HTML element to render. If none is specified, a `div` is rendered. | ||
* @type {typeof import("svelte").SvelteComponent} | ||
*/ | ||
export let as = "div"; | ||
/** | ||
* Specify the Layer HTML element props | ||
* @type {import('svelte/elements').HTMLElementAttributes} | ||
*/ | ||
export let layerProps = {}; | ||
/** Set an id for the Layer component */ | ||
export let id = "ccs-" + Math.random().toString(36); | ||
let ref = null; | ||
// If there is no level override, determine the Level based on the hierarchy | ||
const parentLevel = getContext("LAYER_CONTEXT"); | ||
if (level === undefined) { | ||
level = typeof parentLevel === "number" ? parentLevel + 1 : 0; | ||
} | ||
setContext("LAYER_CONTEXT", level); | ||
</script> | ||
|
||
<svelte:element | ||
this="{as}" | ||
class:bx--layer-one="{level === 0}" | ||
class:bx--layer-two="{level === 1}" | ||
class:bx--layer-three="{level === 2}" | ||
id="{id}" | ||
bind:this="{ref}" | ||
{...layerProps} | ||
> | ||
<slot /> | ||
</svelte:element> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Layer } from "./Layer.svelte"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
import { Layer } from "carbon-components-svelte"; | ||
</script> | ||
|
||
<Layer> | ||
<p>First layer</p> | ||
<Layer> | ||
<p>Second layer</p> | ||
<Layer> | ||
<p>Third layer</p> | ||
</Layer> | ||
</Layer> | ||
</Layer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { SvelteComponentTyped } from "svelte"; | ||
|
||
export interface LayerProps { | ||
/** | ||
* Specify the layer level and override any existing levels based on hierarchy. | ||
* @default undefined | ||
*/ | ||
level?: 0 | 1 | 2; | ||
|
||
/** | ||
* Specify the HTML element to render. If none is specified, a `div` is rendered. | ||
* @default "div" | ||
*/ | ||
as?: typeof import("svelte").SvelteComponent; | ||
|
||
/** | ||
* Specify the Layer HTML element props | ||
* @default {} | ||
*/ | ||
layerProps?: import("svelte/elements").HTMLElementAttributes; | ||
|
||
/** | ||
* Set an id for the Layer component | ||
* @default "ccs-" + Math.random().toString(36) | ||
*/ | ||
id?: string; | ||
} | ||
|
||
export default class Layer extends SvelteComponentTyped< | ||
LayerProps, | ||
Record<string, any>, | ||
{ default: {} } | ||
> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters