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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                //- Just press the 'Run' button above to return
#app
	star-rating(
		v-bind:rating-title="ratingTitle"
		v-bind:rating-message="ratingMessage"
		v-bind:star-text="starText"
	)
//- Template VueJS component
script(type="text/x-template" id="tpl_star_rating")
	d.stars(v-bind:class="{ 'rating-selected': ratingSelected }")
		- for (var i = 5; i > 0; i--)
			input(
				type="radio"
				name="rating"
				id="rating_" + i
				v-on:change="changeRating(" + i + ")"
			)
			label(for="rating_" + i)
				//- Borrowed from https://materialdesignicons.com/ -> "star"
				svg(viewBox="0 0 24 24")
					path(d="M12,17.27L18.18,21L16.54,13.97L22,9.24L14.81,8.62L12,2L9.19,8.62L2,9.24L7.45,13.97L5.82,21L12,17.27Z")
		.rating-comment
			h3(v-if="ratingTitle != ''") {{ ratingTitle }}
			p(v-if="ratingMessage != ''") {{ ratingMessage }}
			h2 {{ rating }} {{ starText }}

              
            
!

CSS

              
                // Just press the 'Run' button above to return

$stars-default-background-color: #dfdfdf;
$stars-hover-background-color: #f4f680;
$stars-active-background-color: #f0f808;
$stars-transition: fill 200ms ease-out;
$stars-size: 72px;

$stars-selected-transition: transform 500ms cubic-bezier(0.6, -0.28, 0.74, 0.05) 64ms;
$stars-selected-svg-transition: width 350ms ease-out 650ms, height 350ms ease-out 650ms, transform 350ms linear 650ms;

$rating-comment-color: #884300;
$rating-comment-font-family: Montserrat, sans-serif;
$rating-comment-background-color: #e3d50d;
$rating-comment-width: 360px;
$rating-comment-height: 144px;
$rating-comment-border: thick double #03031b; // HACK: Must be same as 'background-color' (body)
$rating-comment-border-radius: 10px;
$rating-comment-transition: width 0ms linear 1250ms, height 0ms linear 1125ms, transform 680ms cubic-bezier(0.68, 0.55, 0.27, 1.55) 1125ms;

$rating-comment-ph2h3-margin: 10px;

@import url("https://fonts.googleapis.com/css?family=Montserrat:400,400i,700");

.stars {
	display: inline-flex;
	flex-direction: row-reverse;
	&.rating-selected {
		label {
			&:nth-child(10) {
				transform: translateX(200%);
			}
			&:nth-child(8) {
				transform: translateX(100%);
			}
			&:nth-child(4) {
				transform: translateX(-100%);
			}
			&:nth-child(2) {
				transform: translateX(-200%);
			}
			svg {
				width: 0;
				height: 0;
				transform: rotate(720deg);
			}
		}
		.rating-comment {
			width: $rating-comment-width;
			height: $rating-comment-height;
			transform: scale(1) rotate(0deg);
		}
	}
	input[type="radio"] {	
		display: none;
		&:checked ~ label svg path {
			fill: $stars-active-background-color;
		}
	}
	label {
		transition: $stars-selected-transition;
		svg {
			width: $stars-size;
			height: $stars-size;
			vertical-align: middle;
			transition: $stars-selected-svg-transition;
			path {
				fill: $stars-default-background-color;
				transition: $stars-transition;
			}
		}
		&:hover svg path, &:hover ~ label svg path {
			fill: $stars-hover-background-color;
		}
	}
	.rating-comment {
		color: $rating-comment-color;
		font-family: $rating-comment-font-family;
		background-color: $rating-comment-background-color;
		width: 0;
		height: 0;
		border: $rating-comment-border;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		box-sizing: border-box;
		border-radius: $rating-comment-border-radius;
		transform-origin: center;
		transform: scale(0) rotate(-90deg);
		transition: $rating-comment-transition;
		p, h2, h3 {
			padding: 0;
			margin: 0;
			margin-bottom: $rating-comment-ph2h3-margin;
			&:last-child {
				margin-bottom: 0;
			}
		}
	}
}

// ----------

html, body, #app {
	width: 100%;
	height: 100%;
	padding: 0;
	margin: 0;
}

#app {
	background-color: #03031b;
	display: flex;
	justify-content: center;
	align-items: center;
}

              
            
!

JS

              
                // Just press the 'Run' button above to return
// ----------
Vue.component('starRating', {
	props: ['ratingTitle', 'ratingMessage', 'starText'],
	data: () => {
		return {
			rating: 0,
			ratingSelected: false
		}
	},
	methods: {
		// HACK: Arrow function is not working well here,
		//       while trying to access the variable in 'data'.
		changeRating: function(val) {
			// If rating is already selected,
			// you can't change it anymore.
			if (this.rating === 0) {
				this.rating = val;
				this.ratingSelected = true;
			}
		}
	},
	template: '#tpl_star_rating'
});

// ---------- Usage of the component
var app = new Vue({
	el: '#app',
	data: {
		ratingTitle: 'Thank you!',
		ratingMessage: 'You rated this project:',
		starText: 'star/s'
	}
});

              
            
!
999px

Console