-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (30 loc) · 836 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import {component, html, useEffect, useState} from 'haunted';
import styles from 'bundle-text:./index.css';
const SendDataToParent = (el, value) => {
const event = new CustomEvent('my-counter-add', {
bubbles: true,
detail: {
counter: value
}
});
el.dispatchEvent(event);
};
function Counter({start = 0, dsType = 'primary'}) {
const [count, setCount] = useState(Number(start));
useEffect(() => {
setCount(Number(start));
}, [start]);
useEffect(() => {
SendDataToParent(this, count);
}, [count]);
return html`
<style>${styles}</style>
<div>
<button type="button" class="button button-${dsType}" @click=${() => setCount(count + 1)}>
Increment : ${count}
</button>
</div>
`;
}
Counter.observedAttributes = ['start', 'ds-type'];
customElements.define('my-counter', component(Counter));