Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ add another resource


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


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.


Auto Save

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.


                <div id="app">
  <header class="ml-4 mb-3 text-indigo-darker">
      Sunrise and Sunset
  <content class="flex flex-col w-1/2">
    <label for="search" class="ml-2 text-indigo-dark">Search for a city</label>
    <input type="text" id="search" v-model="search" class="p-2 m-2 bg-grey-lighter rounded border border-indigo-dark">
    <!-- A few things to note:
      * We're already making use of tailwind css, which 
        offers excellent utility classes
      * v-model makes our data reactive, meaning we can
        read in user input with ease
    <div v-for="datum in citiesToDisplay"
         class="bg-white m-3 p-4 rounded text-blue-darker">
        <!-- Here, instead of looping through the whole list,
             we can loop through a computed property, where 
             filter our original list based on our search term.
             These are a useful (and performant) feature in Vue
        <h3 class="mb-2">

<script type="text/x-template" id="sunrise-sunset-viz-template">
    <!-- We'll use <slider>, which is an open-source component
         called vue-slider component: 
        marginTop: '2.5em'
        backgroundColor: 'darkorange'
        backgroundColor: 'darkslateblue'   
        backgroundColor: 'darkorange', 
        boxShadow: 'none'
    <template slot="tooltip" scope="tooltip">
      <!-- Here we're using a scoped-slot. It's an
           advanced, but incredibly useful pattern.
           However, explaining it is outside the 
           scope of this example. 
           Here's a great explanation of them:
      <div v-if="tooltip.index === 0">
      </div >
      <div v-else>


                body {
  background: #bbfaff

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 40px;


                // [{ city, sunrise: {hour, minute}, sunset: {hour, minute} }, ...]
const DUMMY_DATA = [{
  city: 'Baltimore',
  sunrise: {hour: 4, minute: 50},
  sunset: {hour: 19, minute: 16}
}, {
  city: 'Havana',
  sunrise: {hour: 5, minute: 4},
  sunset: {hour: 19, minute: 1}
}, {
  city: 'Lima',
  sunrise: {hour: 6, minute: 19},
  sunset: {hour: 17, minute: 51}

// number of seconds in a day
const SECONDS_IN_DAY = 24 * 60 * 60

// function to turn a number into a string, prepending
// a 0 if it's single-digit
// formatDigit(9) yields '09'
// formatDigit(13) yields '13'
const formatDigit = digit => digit > 9 ? `${digit}` : `0${digit}`

Vue.component('sunrise-sunset-viz', {
  template: '#sunrise-sunset-viz-template',
  components: {
    slider: window['vue-slider-component']
  props: ["sunrise", "sunset"],
  data() {
    return {
      min: 0,
      max: SECONDS_IN_DAY,
  methods: {
    timeInSeconds({hour, minute}) {
      return (hour * 60 * 60) + (minute * 60)
    formatTime({hour, minute}) {
      const regularHour = hour % 12
      return `${formatDigit(regularHour)}:${formatDigit(minute)}`
  computed: {
    sliderValue() {
      const {sunrise, sunset} = this;
      // {hour, minute} --> time of day in seconds
      // we use this number to make it easier to use
      // with vue-slider-component
      return [ this.timeInSeconds(sunrise), this.timeInSeconds(sunset)  ]

const app = new Vue({
  el: "#app",
  data() {
    return {
      search: '',
      times: DUMMY_DATA
  computed: {
    citiesToDisplay() {
      return this.times.filter(d =>