Skip to content

Commit e6372c3

Browse files
committed
Added custom alert button
1 parent 98040ae commit e6372c3

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

src/components/button-alert.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Component, Prop } from '@stencil/core';
2+
3+
@Component({
4+
tag: 'button-alert'
5+
})
6+
7+
export class Button {
8+
9+
@Prop() buttonText: string;
10+
@Prop() alertMessage: string;
11+
12+
handleClick(event: UIEvent) {
13+
console.log(event);
14+
if (this.alertMessage) {
15+
alert(this.alertMessage);
16+
}
17+
}
18+
19+
render() {
20+
if(this.buttonText) {
21+
return (
22+
<button onClick={(event: UIEvent) => this.handleClick(event)}>{this.buttonText}</button>
23+
);
24+
}
25+
}
26+
}

src/components/my-first-component.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Component, Prop } from '@stencil/core';
44
tag: 'my-first-component'
55
})
66

7-
export class MyComponent {
7+
export class MyFirstComponent {
88
// Indicate that name should be a public property on the component
99
@Prop() firstName: string;
1010

src/components/todos-component.tsx renamed to src/components/todo-list.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Component } from '@stencil/core';
44
tag: 'todo-list'
55
})
66

7-
export class TodosComponent {
7+
export class TodoList {
88
// Indicate that name should be a public property on the component
99
todos = [
1010
{taskName:"Task 1", isCompleted:true},

src/index.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<script src="build/app.js"></script>
88
</head>
99
<body>
10-
11-
<my-name first="Stencil" last="JS"></my-name>
12-
<my-first-component first-name="Max"></my-first-component>
13-
<my-name></my-name>
14-
<todo-list></todo-list>
10+
<my-name first="Stencil" last="JS"></my-name>
11+
<my-first-component first-name="Max"></my-first-component>
12+
<my-name></my-name>
13+
<todo-list></todo-list>
14+
<button-alert button-text="Show me the money!" alert-message="The money!"></button-alert>
1515
</body>
1616
</html>

stencil.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
exports.config = {
22
bundles: [
3-
{ components: ['my-name', 'my-first-component', 'todo-list'] }
3+
{ components: ['my-name', 'my-first-component', 'todo-list', 'button-alert'] }
44
],
55
collections: [
66
{ name: '@stencil/router' }

0 commit comments

Comments
 (0)