Fixed a bug relating to custom-elements's first vnode where render(){ return <div class="example" /> } would set the example-class on the custom-element itself.
Added support for className and style similar to react Cleaned up some comments Reworked how tests are built in order to add a new test "pdf" which was a small side-project where previous mentioned bug showed up, it's an example using HTML to create a PDF for printing
This commit is contained in:
58
tests/todos-mvc/components/my-todo.jsx
Normal file
58
tests/todos-mvc/components/my-todo.jsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import {defineElement, render, CustomElement, Host, State} from "../../../packages/csx";
|
||||
|
||||
import style from './my-todo.scss';
|
||||
import {TodoInput} from './todo-input';
|
||||
import {TodoItem} from './todo-item';
|
||||
|
||||
@defineElement('my-todo')
|
||||
export class MyTodo extends CustomElement{
|
||||
uid = 1;
|
||||
@State() todos = [
|
||||
{id: this.uid++, text: "my initial todo", checked: false },
|
||||
{id: this.uid++, text: "Learn about Web Components", checked: false },
|
||||
];
|
||||
|
||||
render(){
|
||||
return (
|
||||
<Host>
|
||||
<style>{ style }</style>
|
||||
<h1>CSX Todo</h1>
|
||||
<section>
|
||||
<TodoInput onSubmit={this.handleSubmit}/>
|
||||
<ul id="list-container"
|
||||
onCheck={this.handleCheck}
|
||||
onRemove={this.handleRemove}
|
||||
>
|
||||
{this.todos.map(item =>
|
||||
<TodoItem
|
||||
key={item.id}
|
||||
model={ item.id }
|
||||
checked={ item.checked }
|
||||
>
|
||||
{ item.text }
|
||||
</TodoItem>
|
||||
)}
|
||||
</ul>
|
||||
</section>
|
||||
</Host>
|
||||
);
|
||||
}
|
||||
|
||||
handleSubmit = ({ detail: text }) => {
|
||||
if(text) {
|
||||
console.log("Submit rcvd: " + text);
|
||||
this.todos = [...this.todos, { id: this.uid++, text, checked: false }];
|
||||
}
|
||||
};
|
||||
handleCheck = ({detail: {checked,id}}) => {
|
||||
let indexOf = this.todos.findIndex(t=>t.id===id);
|
||||
if(indexOf>=0) {
|
||||
let updated = { ...this.todos[ indexOf ], checked };
|
||||
this.todos = [...this.todos.slice(0, indexOf), updated, ...this.todos.slice(indexOf + 1)];
|
||||
}
|
||||
};
|
||||
handleRemove = ({detail: {id}})=>{
|
||||
let indexOf = this.todos.findIndex(t=>t.id===id);
|
||||
this.todos = [...this.todos.slice(0,indexOf), ...this.todos.slice(indexOf+1)];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user