Component CSS (.css)

When styling your component, you should leverage the designs and CSS provided by the SLDS, as shown in the mycomponent example earlier. This will ensure that your UI continues to stay in line with the Salesforce containers it resides in, as well as any further advances with respect to supporting new devices and layout types.

Using Salesforce base components from the lightning namespace, such as lightning-button, lightning-input, and lightning-tabSet, automatically ensures that you are using the SLDS.

However, if you do need to define your own styles, do so via custom CSS classes added to the components .css file. The framework will ensure that these will be encapsulated within the component and will not affect other components on the page.

You should not attempt to modify the HTML style attribute of the element. Utilize the HTML class attribute to apply your own styles.

Any CSS you define is automatically scoped to your component. The following example is used in the Race Calendar component to highlight a race when the user clicks on it:

lightning-tile.active {
background: rgb(255, 236, 149);
}

The corresponding component markup uses a binding to apply the class attribute value:

<lightning-tile label={name} href="/" type="media" 
class={raceStyle} onclick={raceClicked}>

The controller property calculates the correct value based on the value of the selected property (defined elsewhere in the controller):

get raceStyle() {
return this.selected===true ?
'slds-tile_board active' : 'slds-tile_board'
}
The token is a feature of the Lightning framework that allows you to reuse colors and font values expressed by Salesforce in your own styles. The preceding example reuses a token from the SLDS that defines what color a selected item is. To include the standard SLDS tokens for use in your components, you must create an aura:tokens Lightning bundle, called defaultTokens. This has already been included in the sample code for this chapter. In this, you can also define your own tokens via the aura:token element. There is no direct support for tokens in Lightning Web Components. However, if you have an outer Lightning Aura component that imports them, the tokens are available to child Lightning Web Components.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.67.251