src/app/app.module.ts
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { ShoelaceStyleAngularModule } from "shoelace-style-angular";
@NgModule({
imports: [
BrowserModule,
// provide angular outputs for shoelace events:
ShoelaceStyleAngularModule,
],
// required 'cause shoelace based on Web Components:
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}
For using shoelace
assets, add to config:
{
"glob": "**/*.*",
"input": "node_modules/@shoelace-style/shoelace/dist",
"output": "/assets/shoelace"
}
and to src/main.ts
:
import { setBasePath } from "@shoelace-style/shoelace";
setBasePath("/assets/shoelace");
Provide shoelace
components and styles to index.html
:
<link rel="stylesheet" href="/assets/shoelace/themes/light.css" />
<script type="module" src="/assets/shoelace/shoelace.js"></script>
Pay attention to use two-way bindings for sl-dialog open attribute!
import { Component } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms";
@Component({
selector: "app-greeter",
template: `
<sl-form [data]="form" (submit)="isDialogOpen = true">
<sl-input name="username" label="Enter your name"></sl-input>
<br />
<sl-button submit [disabled]="form.invalid">Say Hello</sl-button>
</sl-form>
<sl-dialog label="Greetings" [(open)]="isDialogOpen">
Hello,
{{ form.get("username").value }}!
</sl-dialog>
`,
})
export class GreeterComponent {
form = this.formBuilder.group({
username: ["World", Validators.required],
});
isDialogOpen = false;
constructor(private formBuilder: FormBuilder) {}
}
Shoelace event | Angular output | In template |
---|---|---|
sl-submit | submit | sl-form[data] |
sl-change | change |
sl-checkbox, sl-color-picker, sl-form, sl-input, sl-radio, sl-range, sl-rating, sl-select, sl-switch, sl-textarea |
sl-clear | clear | sl-tag[clearable] |
sl-close | close | sl-tab[closable] |
sl-load | load | sl-icon, sl-include |
sl-initial-focus, sl-request-close |
initialFocus, requestClose |
sl-dialog, sl-drawer |
sl-show, sl-hide, sl-after-show, sl-after-hide |
show, hide, afterShow, afterHide |
sl-alert, sl-color-picker, sl-details, sl-dialog, sl-drawer, sl-dropdown, sl-tooltip |
sl-start, sl-finish, sl-cancel |
start, finish, cancel |
sl-animation |
sl-resize | resize | sl-resize-observer |