-
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(layer): first pass at
Layer
component (#1932)
Closes #1892
- Loading branch information
1 parent
e4670a1
commit 5031d0b
Showing
9 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Component Index | ||
|
||
> 165 components exported from [email protected]. | ||
> 166 components exported from [email protected]. | ||
## Components | ||
|
||
|
@@ -66,6 +66,7 @@ | |
- [`ImageLoader`](#imageloader) | ||
- [`InlineLoading`](#inlineloading) | ||
- [`InlineNotification`](#inlinenotification) | ||
- [`Layer`](#layer) | ||
- [`Link`](#link) | ||
- [`ListBox`](#listbox) | ||
- [`ListBoxField`](#listboxfield) | ||
|
@@ -1959,6 +1960,26 @@ None. | |
| mouseenter | forwarded | -- | | ||
| mouseleave | forwarded | -- | | ||
|
||
## `Layer` | ||
|
||
### Props | ||
|
||
| Prop name | Required | Kind | Reactive | Type | Default value | Description | | ||
| :--------- | :------- | :--------------- | :------- | ------------------------------------------------------------ | ---------------------- | --------------------------------------------------------------------------- | | ||
| level | No | <code>let</code> | Yes | <code>0 | 1 | 2 </code> | <code>undefined</code> | Specify the layer level to override any existing levels based on hierarchy. | | ||
| as | No | <code>let</code> | No | <code>string</code> | <code>"div"</code> | Specify the HTML element to render. | | ||
| layerProps | No | <code>let</code> | No | <code>import('svelte/elements').HTMLElementAttributes</code> | <code>{}</code> | Specify the Layer HTML element props | | ||
|
||
### Slots | ||
|
||
| Slot name | Default | Props | Fallback | | ||
| :-------- | :------ | :---- | :------- | | ||
| -- | Yes | -- | -- | | ||
|
||
### Events | ||
|
||
None. | ||
|
||
## `Link` | ||
|
||
### Props | ||
|
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,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,37 @@ | ||
<script> | ||
import { getContext, setContext } from "svelte"; | ||
/** | ||
* Specify the layer level to override any existing levels based on hierarchy. | ||
* @type {0 | 1 | 2 } | ||
*/ | ||
export let level = undefined; | ||
/** Specify the HTML element to render. */ | ||
export let as = "div"; | ||
/** | ||
* Specify the Layer HTML element props | ||
* @type {import('svelte/elements').HTMLElementAttributes} | ||
*/ | ||
export let layerProps = {}; | ||
// 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}" | ||
{...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,27 @@ | ||
import type { SvelteComponentTyped } from "svelte"; | ||
|
||
export interface LayerProps { | ||
/** | ||
* Specify the layer level to override any existing levels based on hierarchy. | ||
* @default undefined | ||
*/ | ||
level?: 0 | 1 | 2; | ||
|
||
/** | ||
* Specify the HTML element to render. | ||
* @default "div" | ||
*/ | ||
as?: string; | ||
|
||
/** | ||
* Specify the Layer HTML element props | ||
* @default {} | ||
*/ | ||
layerProps?: import("svelte/elements").HTMLElementAttributes; | ||
} | ||
|
||
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