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

            
              <my-app></my-app>
            
          
!

CSS

            
              body {
    font-family: verdana; padding: 0px;
}
my-modal {
   position: fixed;
   top: 0px;
   left: 0px;
   right: 0px;
   bottom: 0px;
   z-index: 100;
}

.background {
    position: fixed;
	top: 0px;
    left: 0px;
    right: 0px;
    bottom: 0px;
	background-color: #000000;
	opacity: 0.2;
}

.modal-container {
	left: 50%;
	top: 50%;
	width: 300px;
	height: 300px;
	margin-top: -150px;
	margin-left: -150px;
	position: absolute;
	border: 1px solid #e1e1e8;
	background-color: white;
}
my-modals h3{
	border-bottom: 1px solid #e1e1e8;
	padding-left: 20px;
	padding-bottom: 5px;
    margin-top: 5px;
}

.content {
    padding-left: 20px;
}
my-app > occupation-questions, my-app > income-questions, my-app > diva-questions, my-app > programmer-questions {
    display: block;
    border: solid 1px black;
}
            
          
!

JS

            
              import { Component, value, stacheConverters, stache } from "//unpkg.com/can@5/ecosystem.mjs";
stache.addConverter(stacheConverters);

const OccupationQuestions = Component.extend({
	tag: "occupation-questions",
	view: `
		<h3>Occupation</h3>
		<div class='content'>
			<p>Are you a diva?
				<input type="radio" checked:bind="equal(isDiva, true)"/> yes
				<input type="radio"  checked:bind="equal(isDiva, false)"/> no
			</p>
			<p>Do you program?
				<input type="radio" checked:bind="equal(isProgrammer, true)"/> yes
				<input type="radio" checked:bind="equal(isProgrammer, false)"/> no
			</p>
			<p><button on:click="next()">Next</button></p>
		</div>
	`,
	ViewModel: {
		isDiva: "boolean",
		isProgrammer: "boolean"
	}
});

const DivaQuestions = Component.extend({
	tag: "diva-questions",
	view: `
		<h3>Diva Questions</h3>
		<div class='content'>
			<p>Check all expenses that apply:</p>
			<p><input type="checkbox"
					checked:bind="boolean-to-inList('Swagger', divaExpenses)"> Swagger
			</p>
			<p><input type="checkbox"
					checked:bind="boolean-to-inList('Fame', divaExpenses)"> Fame
			</p>
			<p><button on:click="next()">Next</button></p>
		</div>
    `,
    ViewModel: {
        divaExpenses: "any"
    }
});

const ProgrammerQuestions = Component.extend({
	tag: "programmer-questions",
	view: `
		<h3>Programmer Questions</h3>
		<div class='content'>
			<p>What is your favorite language?</p>
			<p>
				<select value:to="programmingLanguage">
					<option>C</option>
					<option>C++</option>
					<option>Java</option>
					<option>JavaScript</option>
				</select>
			</p>
			<p><button on:click="next()">Next</button></p>
		</div>
   `,
	ViewModel: {
		programmingLanguage: "string"
	}
});

const IncomeQuestions = Component.extend({
	tag: "income-questions",
	view: `
		<h3>Income</h3>
		<div class='content'>
			<p>What do you get paid in?</p>
			<p>
				<select value:bind="string-to-any(paymentType)">
					<option value="undefined">Select a type</option>
					<option>Peanuts</option>
					<option>Bread</option>
					<option>Tamales</option>
					<option>Cheddar</option>
					<option>Dough</option>
				</select>
			</p>
			<p><button on:click="next()">Finish</button></p>
		</div>
   `,
	ViewModel: {
		paymentType: "string"
	}
});

Component.extend({
	tag: "my-modals",
	view: `
		{{# each(componentsToShow)}}
            {{# if(last)}}
                <div class='background'></div>
            {{/ if}}
			<div class='modal-container'
                style="margin-top: {{position}}px; margin-left: {{position}}px">
                {{component}}
            </div>
		{{/ each}}
	`,
	ViewModel: {
		get componentToShow() {
			return this.components[0];
		},
		get componentsToShow() {
			var distance = 20;
			var count = this.components.length;
			var start = -150 - (distance / 2) * (count - 1);

			return this.components.map(function(component, i) {
				return {
					position: start + i * distance,
					component: component,
					last: i === count - 1
				}
			});
		}

	}
});

Component.extend({
	tag: "my-app",
	view: `
		<my-modals components:from="visibleQuestions"></my-modals>

		<p>isDiva: {{isDiva}}</p>
		<p>isProgrammer: {{isProgrammer}}</p>
		<p>diva expenses: {{divaExpenses.join(', ')}}</p>
		<p>programmingLanguage: {{programmingLanguage}}</p>
		<p>paymentType: {{paymentType}}</p>
   `,
	ViewModel: {
		// Stateful properties
		isDiva: { type: "boolean", default: false },
		divaExpenses: { Default: Array },
		isProgrammer: { type: "boolean", default: false },
		programmingLanguage: "string",
		paymentType: "string",

		occupationQuestions: {
			default () {
				return new OccupationQuestions({
					viewModel: {
						isDiva: value.bind(this, "isDiva"),
						isProgrammer: value.bind(this, "isProgrammer"),
						next: this.next.bind(this)
					}
				});
			}
		},
		divaQuestions: {
			default () {
				return new DivaQuestions({
					viewModel: {
						divaExpenses: value.bind(this, "divaExpenses"),
						next: this.next.bind(this)
					}
				});
			}
		},
		programmerQuestions: {
			default () {
				return new ProgrammerQuestions({
					viewModel: {
						programmingLanguage: value.bind(this, "programmingLanguage"),
						next: this.next.bind(this)
					}
				});
			}
		},
		incomeQuestions: {
			default () {
				return new IncomeQuestions({
					viewModel: {
						paymentType: value.bind(this, "paymentType"),
						next: this.next.bind(this)
					}
				});
			}
		},
		
		questionIndex: { default: 0 },
		
		// Derived properties
		get allQuestions() {
			var forms = [this.occupationQuestions];
			if (this.isDiva) {
				forms.push(this.divaQuestions)
			}
			if (this.isProgrammer) {
				forms.push(this.programmerQuestions)
			}
			forms.push(this.incomeQuestions);

			return forms;
		},
		get visibleQuestions() {
			return this.allQuestions.slice(this.questionIndex).reverse();
		},
		
		// Methods
		next() {
			this.questionIndex++;
		}
	}
});
            
          
!
999px

Console