feat(templating): support for non on-event props
- use class or className - only on-event props are tolowercase'd
This commit is contained in:
parent
b4f3b98ee4
commit
27a5fb3024
3 changed files with 9 additions and 4 deletions
|
@ -6,7 +6,7 @@ export class Counter extends WebComponent {
|
|||
};
|
||||
get template() {
|
||||
return html`
|
||||
<button onClick=${() => ++this.props.count} style="background-color: black; color: white;">
|
||||
<button class="hey" id="btn" onclick=${() => ++this.props.count} style="background-color: black; color: white;">
|
||||
<span>${this.props.count}</span>
|
||||
</button>
|
||||
`;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "web-component-base",
|
||||
"version": "2.0.0-beta.14",
|
||||
"version": "2.0.0-beta.15",
|
||||
"description": "A zero-dependency, ~600 Bytes (minified & gzipped), JS base class for creating reactive custom elements easily",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
|
|
|
@ -7,8 +7,13 @@ export function createElement(tree) {
|
|||
return document.createTextNode(tree);
|
||||
} else {
|
||||
const el = document.createElement(tree.type);
|
||||
if (tree.props)
|
||||
Object.keys(tree.props).forEach(prop => el[prop.toLowerCase()] = tree.props[prop])
|
||||
if (tree.props) {
|
||||
Object.keys(tree.props).forEach(prop => {
|
||||
let domProp = prop.startsWith('on') ? prop.toLowerCase() : prop;
|
||||
if (domProp === 'class') domProp = 'className';
|
||||
el[domProp] = tree.props[prop]
|
||||
})
|
||||
}
|
||||
tree.children?.forEach((child) => {
|
||||
const childEl = createElement(child);
|
||||
if (childEl) {
|
||||
|
|
Loading…
Reference in a new issue