56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
import {
|
|
initRouter,
|
|
Route,
|
|
ViewChild,
|
|
Component,
|
|
ComponentInput,
|
|
ComponentDefinition,
|
|
} from "./pwa.js";
|
|
|
|
class TestComponent extends Component {
|
|
static get definition() {
|
|
return new ComponentDefinition({
|
|
name: "test-component",
|
|
template: `<div>
|
|
<h1>Test Component</h1>
|
|
<p>This is a test component.</p>
|
|
<button
|
|
id="test-button"
|
|
(click)="incrementCount()"
|
|
[class.green-button]="count % 2 !== 0"
|
|
[class.red-button]="count % 2 === 0"
|
|
>Count: {{count}}</button>
|
|
</div>`,
|
|
style: `
|
|
.red-button {
|
|
background-color: red;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
font-size: 16px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.green-button {
|
|
background-color: green;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
font-size: 16px;
|
|
cursor: pointer;
|
|
}
|
|
`
|
|
});
|
|
}
|
|
|
|
count = new ComponentInput(0);
|
|
|
|
incrementCount() {
|
|
this.count++;
|
|
}
|
|
}
|
|
|
|
const route1 = new Route("/counter", TestComponent);
|
|
const route2 = new Route("/counter/:count", TestComponent);
|
|
initRouter("routerOutlet", "styleOutlet", [route1, route2]);
|