Skip to content

Instantly share code, notes, and snippets.

@justin-lyon
Last active November 18, 2019 15:44
Show Gist options
  • Save justin-lyon/9046de7ead457829d829f6c988df1ee3 to your computer and use it in GitHub Desktop.
Save justin-lyon/9046de7ead457829d829f6c988df1ee3 to your computer and use it in GitHub Desktop.
<aura:tokens extends="force:base">
<aura:token
name="myYellow"
value="#fcba03" />
<aura:token
name="colorWarning"
value="{!colorBackgroundWarning}" />
<aura:token
name="colorBrand"
value="{!colorBrand}" />
</aura:tokens>
div.box {
width: 100%;
height: 5rem;
}
div.box.warning {
background-color: var(--lwc-colorWarning,#fc3000);
}
div.box.slds-warning {
}
div.box.brand {
background-color: var(--lwc-myColorBrand,#7eeba2);
}
div.box.slds-brand {
background-color: var(--lwc-colorBrand,#7eeba2);
}
<template>
<div class="slds-grid slds-gutters slds-wrap">
<div class="slds-col slds-size_1-of-3 slds-m-top_x-small">
<div class="box warning">
<div>lwc</div>
custom warning, fall back red
</div>
</div>
<div class="slds-col slds-size_1-of-3 slds-m-top_x-small">
<div class="box warning">
<div>lwc</div>
custom warning, fall back red
</div>
</div>
<div class="slds-col slds-size_1-of-3 slds-m-top_x-small">
<div class="box warning">
<div>lwc</div>
Cannot save .css with "--lwc-colorBackgroundWarning", Internal Token, not Global Access
</div>
</div>
<div class="slds-col slds-size_1-of-3 slds-m-top_x-small">
<div class="box brand">
<div>lwc</div>
custom brand, fall back green
</div>
</div>
<div class="slds-col slds-size_1-of-3 slds-m-top_x-small">
<div class="box brand">
<div>lwc</div>
custom brand, fall back green
</div>
</div>
<div class="slds-col slds-size_1-of-3 slds-m-top_x-small">
<div class="box slds-brand">
<div>lwc</div>
slds-brand, fall back green
</div>
</div>
</div>
</template>
<aura:component description="TokenContainer"
implements="flexipage:availableForAllPageTypes"
access="global">
<div class="aura-box">
Aura, colorBackgroundWarning
</div>
<div class="slds-box">
<div>Aura > LWC</div>
<c:designTokenDemo />
</div>
</aura:component>
.THIS.aura-box {
background-color: t(colorWarning);
width: 100%;
height: 5rem;
}
@justin-lyon
Copy link
Author

justin-lyon commented Nov 18, 2019

@justin-lyon
Copy link
Author

justin-lyon commented Nov 18, 2019

Experimenting with SLDS Design Tokens for LWC.

According to the docs, a single Aura component with Design Tokens must be in the page - does not need to be a parent of the LWC - in order for the LWC to use Design Tokens.

What I've found is that an Aura Component is not necessary to use Design Tokens in an LWC - however, custom design tokens are not supported, and ONLY Globally Accessible Tokens are available to LWC.

Design Tokens Docs:
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.interop_components_css_aura

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment