can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
69 lines (59 loc) • 1.44 kB
JavaScript
import { StacheElement, type } from "can";
import "./percent-slider";
class TaskEditor extends StacheElement {
static get view() {
return `
{{
<h1><code><task-editor></code></h1>
<p>
This content is provided by the <code><task-editor></code> component.
Click <a href="{{ routeUrl(page='home') }}">Home</a> to return to the homepage, or
<button on:click="this.logout()">Logout</button> to log out. Edit the task below:
</p>
{{ else }}
<h2>Task Editor</h2>
{{/ if }}
<form on:submit="this.save(scope.event)">
Name: {{ this.name }}
<p>
<input value:bind="this.name">
</p>
Progress: {{ this.progress }}
<p>
<percent-slider value:bind="this.progress" />
</p>
<button disabled:from="this.isSaving">
{{
</button>
</form>
`;
}
static get props() {
return {
id: type.convert(Number),
name: {
get default() {
return "Task " + this.id;
}
},
progress: {
// makes progress an integer
type(num) {
return parseInt(num, 10);
},
default: 0
},
isSaving: { default: false }
};
}
save(event) {
event.preventDefault();
this.isSaving = true;
// fake ajax request
setTimeout(() => {
this.isSaving = false;
}, 2000);
}
}
customElements.define("task-editor", TaskEditor);
export default TaskEditor;