![]() |
VOOZH | about |
We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.
Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.
Follow TNS on your favorite social media networks.
Become a TNS follower on LinkedIn.
Check out the latest featured and trending stories while you wait for your first TNS newsletter.
rating-element. The span defined in style doesn’t affect the component because of the isolation of the shadow DOM.
Let’s extract the interesting bits from the code:
👁 ImagecustomElements.define('rating-element', RatingElement);
There is a render method that basically builds the basic element:
render() {
return html`
<button
class="thumb_down"
@click=${() => {this.vote = 'down'}}>
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewbox="0 0 24 24" width="24"><path d="..."/></svg>
</button>
<span class="rating">${this.rating}</span>
<button
class="thumb_up"
@click=${() => {this.vote = 'up'}}>
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewbox="0 0 24 24" width="24"><path d="..."/></svg>
</button>`;
}
npm update too.
👁 Imageimport '@shoelace-style/shoelace/dist/themes/light.css';
import '@shoelace-style/shoelace/dist/themes/dark.css';
import SlButton from '@shoelace-style/shoelace/dist/components/button/button.js';
import SlIcon from '@shoelace-style/shoelace/dist/components/icon/icon.js';
import SlInput from '@shoelace-style/shoelace/dist/components/input/input.js';
import SlRating from '@shoelace-style/shoelace/dist/components/rating/rating.js';
import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path.js';
// Set the base path to the folder you copied Shoelace's assets to
setBasePath('/dist/shoelace');
// <sl-button>, <sl-icon>, <sl-input>, and <sl-rating> are ready to use!%
<!doctype html> <html> <head> <title>Shoelace Rollup Example</title> <link rel="stylesheet" href="dist/bundle.css"> </head> <body> <h1>Shoelace Rollup Example</h1> <sl-button type="primary">Click me</sl-button> <br><br> <sl-input placeholder="Enter some text" style="max-width: 300px;"></sl-input> <br><br> <sl-rating></sl-rating> <script src="dist/index.js"></script> </body> </html>
<html class="sl-theme-dark">
...
import SlIcon from '@shoelace-style/shoelace/dist/components/icon/icon.js';
import SlInput from '@shoelace-style/shoelace/dist/components/input/input.js';
import SlRating from '@shoelace-style/shoelace/dist/components/rating/rating.js';
import SlAlert from '@shoelace-style/shoelace/dist/components/alert/alert.js';
...
We place the component in our index.html, replacing the button code:
<div class="alert-duration"> <sl-button variant="primary">Show Alert</sl-button> <sl-alert variant="primary" duration="3000" countdown="rtl" closable> <sl-icon slot="icon" name="info-circle"></sl-icon> This alert will automatically hide itself after three seconds, unless you interact with it. </sl-alert> </div>
const container = document.querySelector('.alert-duration');
const button = container.querySelector('sl-button');
const alert = container.querySelector('sl-alert');
button.addEventListener('click', () => alert.toast());