-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tl-provider and tl-context components (v5.1.0, #63)
- Loading branch information
Showing
13 changed files
with
336 additions
and
24 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
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
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,117 @@ | ||
<h2><code>tl-context</code></h2> | ||
<section> | ||
<p> | ||
<tag-code tag="tl-context"></tag-code> is a custom element that pulls the attributes from a | ||
<tag-code tag="tl-provider"></tag-code> parent, and maps it to attributes in your web-component. The main purpose is | ||
to share state across multiple components without depending on prop-drilling or sending state via events. | ||
</p> | ||
<p> | ||
<code-template-html> | ||
<template> | ||
<!-- component definition --> | ||
<template tl-definition> | ||
<text-preview> | ||
<tl-context tl-name="font-size"></tl-context> | ||
<div style="font-size: ${'size'}"> | ||
<slot></slot> | ||
</div> | ||
</text-preview> | ||
</template> | ||
|
||
<!-- main HTML --> | ||
<tl-provider tl-name="font-size" size="1em"> | ||
<text-preview>This is some text content</text-preview> | ||
</tl-provider> | ||
</template> | ||
</code-template-html> | ||
</p> | ||
</section> | ||
<section> | ||
<h2>Syntax</h2> | ||
<p> | ||
<code-template-html> | ||
<template> | ||
<tl-context tl-name="provider-name" tl-attrmap="provider-attribute:host-attribute"></tl-context> | ||
</template> | ||
</code-template-html> | ||
</p> | ||
<h3>Parameters</h3> | ||
<dl> | ||
<dt><code>tl-name</code></dt> | ||
<dd> | ||
<p>The name of the provider to pull context values from.</p> | ||
</dd> | ||
<dt><code>tl-attrmap</code> <optional-badge>optional</optional-badge></dt> | ||
<dd> | ||
<p> | ||
Mapping of provider element's state (<code>provider-attribute</code>) to an attribute name that will be on the | ||
host web-component (<code>host-attribute</code>), defaults to all the user-defined attributes on the provider | ||
mapped to their same name. Can be multiple values (space delimited). | ||
</p> | ||
</dd> | ||
</dl> | ||
</section> | ||
<section> | ||
<h2>Custom Web Components</h2> | ||
<p> | ||
If you'd like to use this api with components that aren't defined in Tram-Lite, you can use the Javascript API to | ||
apply it to a class using <code>TramLite.appendShadowRootProcessor</code> | ||
|
||
<code-template-html> | ||
<template> | ||
<script src="https://unpkg.com/tram-lite@5"></script> | ||
<script> | ||
TramLite.appendShadowRootProcessor('tl-context', ContextConsumer, MyWebComponentClass); | ||
</script> | ||
</template> | ||
</code-template-html> | ||
</p> | ||
</section> | ||
<section> | ||
<h2>Live Example</h2> | ||
<div | ||
class="codepen" | ||
data-height="300" | ||
data-theme-id="dark" | ||
data-default-tab="html,result" | ||
data-editable="true" | ||
data-prefill="{}" | ||
> | ||
<pre data-lang="html"> | ||
<script src="https://unpkg.com/tram-lite@5"></script> | ||
|
||
<!-- component definitions --> | ||
<template tl-definition> | ||
|
||
<!-- example component definition --> | ||
<font-toggle> | ||
<tl-context tl-name="font-size"></tl-context> | ||
<label> | ||
Font Size | ||
<select tl-controlled tl-attrmap="value:size"> | ||
<option value="0.8em">Small</option> | ||
<option value="1em">Medium</option> | ||
<option value="1.2em">Large</option> | ||
</select> | ||
</label> | ||
</font-toggle> | ||
|
||
<text-preview> | ||
<tl-context tl-name="font-size"></tl-context> | ||
<div style="font-size: ${'size'}"> | ||
<slot></slot> | ||
</div> | ||
</text-preview> | ||
|
||
</template> | ||
|
||
<!-- HTML Page --> | ||
<tl-provider tl-name="font-size" size="1em"> | ||
<font-toggle></font-toggle> | ||
<text-preview>This is a text preview</text-preview> | ||
</tl-provider></pre | ||
> | ||
</div> | ||
|
||
<script async src="https://cpwebassets.codepen.io/assets/embed/ei.js"></script> | ||
</section> |
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,32 @@ | ||
<h2><code>tl-provider</code></h2> | ||
<section> | ||
<p> | ||
<tag-code tag="tl-provider"></tag-code> is a custom Element that can provide state to multiple | ||
<tag-code tag="tl-context"></tag-code> elements. <tag-code tag="tl-provider"></tag-code> can live in the shadow or | ||
light DOM. | ||
</p> | ||
</section> | ||
<section> | ||
<h2>Syntax</h2> | ||
<p> | ||
<code-template-html> | ||
<template> | ||
<tl-provider tl-name="provider-name" custom-attributes></tl-provider> | ||
</template> | ||
</code-template-html> | ||
</p> | ||
<h3>Parameters</h3> | ||
<dl> | ||
<dt><code>tl-name</code></dt> | ||
<dd> | ||
<p>Name to match with <tag-code tag="tl-context"></tag-code> tag.</p> | ||
</dd> | ||
<dt><code>custom-attributes</code> <optional-badge>optional</optional-badge></dt> | ||
<dd> | ||
<p> | ||
User defined attributes to make available to components that use <tag-code tag="tl-context"></tag-code>. Can be | ||
boolean or string values. No specific prefix is required. | ||
</p> | ||
</dd> | ||
</dl> | ||
</section> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Oops, something went wrong.