Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <h2>Create a Todo</h2>

<todo-create></todo-create>

<h2>Todos</h2>

<todo-list></todo-list>

<script type="module">
import {realtimeRestModel, ObservableObject, ObservableArray, StacheElement, fixture, stache, Reflect, type} from "//unpkg.com/can@pre/core.mjs";

class Todo extends ObservableObject {
	static props = {
		id: {
			type: Number,
			identity: true
		},
		complete: false,
		dueDate: {
			type: type.convert(Date),
			get default() {
				return new Date();
			}
		},
		name: String
	}

	preventSave(){
		return !this.name || this.isSaving() || this.isDestroying();
	}
}

class TodoList extends ObservableArray {
	static items = Todo;
}

const todoConnection = realtimeRestModel({
    Map: Todo,
    List: TodoList,
    url: "/api/todos/{id}"
});

var terms = ["can you","please","","","",""],
    verbs = ["clean","walk","do","vaccum","organize","fold","wash","dust","pay","cook","get","take out"],
    subjects = ["dog","laundry","diapers","clothes","car","windows","carpet","taxes","food","gas","trash"];

var dayInMS = 24*60*60*1000;
var lastWeek = new Date() - (7*dayInMS);
var fourWeeks = new Date().getTime() + (4*7*dayInMS);

var todoStore = fixture.store(100, function(){
    return {
        complete: fixture.rand([true, false],1)[0],
        dueDate: new Date( fixture.rand(lastWeek, fourWeeks) ).toString(),
        name: (fixture.rand(terms,1)[0]+" "+fixture.rand(verbs,1)[0]+" "+fixture.rand(subjects,1)[0]).trim()
    }
}, type.convertAll(Todo));

fixture("/api/todos/{id}", todoStore);
fixture.delay = 500;
	
class TodoListEl extends StacheElement {
	static view = `
    Sort By: <select value:bind="sort">
        <option value="">none</option>
        <option value="name">name</option>
        <option value="dueDate">dueDate</option>
    </select>

    Show: <select value:bind="completeFilter">
        <option value="">All</option>
        <option value="complete">Complete</option>
        <option value="incomplete">Incomplete</option>
    </select>

    Due: <select value:bind="dueFilter">
        <option value="">Anytime</option>
        <option value="today">Today</option>
        <option value="week">This Week</option>
    </select>

    Results <select value:bind="count">
        <option value="">All</option>
        <option value="10">10</option>
        <option value="20">20</option>
    </select>

    <ul>
        {{# if(todosPromise.isResolved) }}
            {{# each(todosPromise.value) }}
                <li>
                    <input type='checkbox'
                        checked:bind='complete'
                        on:change="save()"
                        disabled:from="preventSave()"/>
                    <label>{{name}}</label>
                    <input type='date'
                        valueAsDate:bind='dueDate'
                        on:change="save()"
                        disabled:from="preventSave()"/>
                    <button on:click="destroy()"
                        disabled:from="preventSave()">delete</button>
                </li>
            {{/ each }}
        {{/ if}}
        {{# if(todosPromise.isPending) }}
            <li>Loading</li>
        {{/ if}}
    </ul>
    `;
	
	static props = {
        sort: String,
        completeFilter: String,
        dueFilter: String,
        count: "10",
        todosPromise: {
            get(){
                var query = {filter: {}};
                if(this.sort) {
                    query.sort =  this.sort;
                }
                if(this.completeFilter) {
                    query.filter.complete = this.completeFilter === "complete";
                }
                if(this.dueFilter) {
                    var day = 24*60*60*1000;
                    var now = new Date();
                    var today = new Date(now.getFullYear(), now.getMonth(), now.getDate() );
                    if(this.dueFilter === "today") {

                        query.filter.dueDate = {
                            $gte: now.toString(),
                            $lt: new Date(now.getTime() + day).toString()
                        }
                    }
                    if(this.dueFilter === "week") {
                        var start = today.getTime() - (today.getDay() * day);
                        query.filter.dueDate = {
                            $gte: new Date(start).toString(),
                            $lt: new Date(start + 7*day).toString()
                        };
                    }
                }
                if(this.count) {
                    query.page = {
                        start: 0,
                        end: (+this.count)-1
                    };
                }
                return Todo.getList(query);
            }
        }
    }
}

customElements.define("todo-list", TodoListEl);

class TodoCreate extends StacheElement {
	static view = `
        <form on:submit="createTodo(scope.event)">
            <p>
                <label>Name</label>
                <input on:input:value:bind='todo.name'/>
            </p>
            <p>
                <label>Complete</label>
                <input type='checkbox' checked:bind='todo.complete'/>
            </p>
            <p>
                <label>Date</label>
                <input type='date' valueAsDate:bind='todo.dueDate'/>
            </p>
            <button disabled:from="todo.preventSave()">Create Todo</button>
            {{# if(todo.isSaving()) }}Creating ....{{/ if}}
        </form>
    `;
	
	static props = {
		todo: {
			get default() {
				return new Todo();
			}
		}
	};
	
	async createTodo(event) {
		event.preventDefault();
		let createdTodo = await this.todo.save();
		this.todo = new Todo();
	}
}
	
customElements.define("todo-create", TodoList);
</script>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console