Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <div id="vueApp">
  <player></player>
  <credits></credits>
</div>

<script type="x-template/script" id="player">
  <div class="player">
    <current-song></current-song>
    <playlist :playlist-items="playlistItems"></playlist>
    <new-playlist-item
      :playlist-items="playlistItems"
    ></new-playlist-item>
  </div>
</script>


<script type="x-template/script" id="playlist">
  <div class="playlist u-mb">
    
    <div v-if="playlistItems.length > 0">
      <div v-for="playlistItem in playlistItems" :key="playlistItem.id" class="playlist__item">
        <div class="u-pull-l">
          <playlist-item :song="playlistItem"></playlist-item>
        </div>
        <div class="u-pull-r">
          <button-play :song="playlistItem"></button-play>
        </div>
        <br class="u-clear-both">
      </div>
    </div>
    <div v-if="playlistItems.length == 0" class="u-p u-text-center">
      <h2>Playlist</h2>
      <p>No songs! Go ahead, add one!</p>
    </div>
  </div>
</script>


<script type="x-template/script" id="playlist-item">
  <transition name="bounce">
    <div v-if="showSong">
        <span class="artist">
          {{song.artist}}
        </span>
        <span class="title">
          {{song.title}}
        </span>        
    </div>
  </transition>
</script>


<script type="x-template/script" id="new-playlist-item">
  <div class="new-item">
    <div class="u-bg-error" v-if="errorMsg">
      <p class="u-p u-color-white u-text-bold u-text-center" >{{errorMsg}}</p>
    </div>
  
    <form @submit.prevent="addSong()">
      <input autocomplete="off" type="text" v-model="artist" placeholder="Artist" name="artist">
      <input autocomplete="off" type="text" v-model="title" placeholder="Title of the song" name="title">
      <button type="submit">Add song to playlist</button>
    </form>
  </div>
</script>


<script type="x-template/script" id="current-song">
  <transition name="bounce">
    <div class="current-song u-mb" v-show="currentSong">
      <div class="player__icons u-pull-l u-text-center">
        <button-stop></button-stop>
      </div>
      <div class="playlist__item__wrapper u-pull-l u-text-center">
        <div class="playlist__item">
          <playlist-item type="current-song" :song="currentSong"></playlist-item>
        </div>
      </div>
      <span class="u-clear-both"></span>
      <player-status></player-status>
    </div>
  </transition>
</script>


<script type="x-template/script" id="button-stop">
  <div class="o-button">
    <a class="u-color-white" @click="stopSong">&#9608;</a>
  </div>
</script>


<script type="x-template/script" id="button-play">
  <div class="o-button">
    <a class="o-button--rounded o-button--primary" @click="playSong">&#9658;</a>
  </div>
</script>


<script type="x-template/script" id="player-status">
  <div class="player__status-bar" :style="barStyle">{{currentSong}}</div>
</script>

<script type="x-template/script" id="credits">
  <div class="credits u-p u-color--white u-text-center">
    Made for <a target="_blank" href="https://www.meetup.com/VueJSMeetupAmsterdam/events/242082860/">Vue Meetup Amsterdam</a> with &hearts; by 
    <a target="_blank" :href="twitter">{{name}}</a>
  </div>
</script>
              
            
!

CSS

              
                $color-primary: #43C6AC; //#ba0b38
$color-secondairy: #191654; //3841a3

$default-padding: 20px;
$default-margin: 20px;
$default-gradient: linear-gradient(211deg, $color-primary, $color-secondairy);
$error-gradient: linear-gradient(211deg, #EA384D, #D31027);
$default-border-color: #DEDEDE;


* {
  font-family: 'Roboto', 'Verdana', sans-serif;
  font-weight: 200;
  font-size: 14px;
}

body {
  background: #1b2b34;
}

h2 {
  padding: 0px;
  margin: 0px;
  font-size: 24px;
}

p {
  padding: 0px;
  margin: 0px;
}

button,
input {
  padding: 20px;
  outline: 0;
}

input {
  width: calc( 100% - 42px );
  border: 1px solid #FFF;
  margin-bottom: 20px;
  border-radius: 2px;
  margin: 0;
  border-bottom: 1px solid $default-border-color;
  -webkit-appearance: none;
}

button {
  width: 100%;
  background: $default-gradient;
  border: 0;
  color: #FFF;
  font-size: 16px;
  border-radius: 2px;
}

// ------ Utilities ------

.u-pull-l {
  float: left;
}

.u-pull-r {
  float: right;
}

.u-mb {
  margin-bottom: $default-margin;
}

.u-p {
 padding: $default-padding; 
}

.u-p-t {
  padding-top: $default-padding;
}

.u-p-b {
  padding-bottom: $default-padding;
}

.u-p-l {
  padding-left: $default-padding;
}

.u-p-r {
  padding-right: $default-padding;
}

.u-clear-both {
  display: block;
  content: '';
  clear: both;
}

.u-color-red {
  color: red;
}

.u-color-white {
  color: #FFF;
}

.u-text-bold {
  font-weight: 300;
}

.u-text-center {
  text-align: center;
}

.u-bg-error {
  background: $error-gradient;
}

.o-button--primary {
  display: block;
  background: $default-gradient;
  padding: 10px;
  color: #FFF;
  width: 25px;
  height: 25px;
  line-height: 25px;
  text-align: center;
}

.o-button--rounded {
  border-radius: 5px;
}


// ------ Components ------

// Player component

.player {
  position: relative;
  background: #EEE;
  width: calc( 100% - 40px );
  max-width: 400px;
  padding: 20px;
  border-radius: 5px;
  margin: 0 auto;
  
  .current-song {
    
    .playlist__item__wrapper {
      width: calc( 100% - 50px );
    
      .playlist__item {
        width: calc( 100% - 100px );
        height: 50px;
        padding: 50px;
        border-radius: 10px;
        background: transparent !important;
        border-bottom: 0 !important;

        > span {
          position: relative;
          display: block;
          top: 50%;
          transform: translateY(-50%);
        }
        span.artist {
          font-size: 16px;
        } 
        span.title {
          font-size: 20px;
        }
      }
    }
  }
  
}

//Playlist component
  
.playlist {
  border-radius: 4px;
  background: #FFF;
}

// Playlist item component

.playlist__item {
  background: #FFF;
  padding: 20px;
  border-top: 1px solid $default-border-color;

  span {
    display: block;
  }

  span.artist {
    font-size: 13px;
    color: #888;
  }

  span.title {
    font-size: 15px;
  }

  &:first-child {
    border-top: 0;
  }

  &:last-child {
    border-bottom: 1px solid $default-border-color;
  }

  &:nth-child(odd) {
    background: #f5f5f5;
  }
}

// New song component

.new-item {
  background: #DEDEDE;
  border-radius: 4px;
}

// Current song component

.current-song {
  background: #DDD;
  border-radius: 4px;
  overflow: hidden;

  .player__icons {
    width: 50px;
    height: 150px;
    background: $default-gradient;
    box-shadow: 29px 24px 96px 0px #929292;

    .o-button {
      position: relative;
      display: block;
      top: 50%;
      transform: translateY(-50%);
    }
  }
}

// Player status

.player__status-bar {
  width: 0;
  overflow: hidden;
  height: 3px;
  background: $default-gradient;
  transition-duration: 1s;
  transition-timing-function: ease;
  transition-property: width;
  margin: 0 auto;
}

// Credits 

.credits {
  color: #FFF;
  a {
    color: #FFF;
  }
}

/**
 * Vue Transition
 * @doc More information: https://vuejs.org/v2/guide/transitions.html
 */

.bounce-enter-active {
  animation: bounce-in .5s;
}
.bounce-leave-active {
  animation: bounce-in .5s reverse;
}
@keyframes bounce-in {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}
              
            
!

JS

              
                const state = {
  currentSong: null
}

const mutations = {
 SET_CURRENT_SONG( state, payload ) {
   state.currentSong = payload
 } 
}

const actions = {
 playSong( {commit}, song ) {
   commit('SET_CURRENT_SONG', song)
 },
 stopSong( {commit} ){
   commit('SET_CURRENT_SONG', null )
 }
}

const store = new Vuex.Store({
  state,
  actions,
  mutations
})


Vue.component('player', {
  template: '#player',
  data() {
    return {
      playlistItems: []
    }
  }
})

Vue.component('playlist', {
  template: '#playlist',
  props: {
    playlistItems: {
      required: true,
      type: Array
    }
  }
})

Vue.component('playlist-item', {
  template: '#playlist-item',
  props: {
    song: {
      required: false
    }
  },
  computed: {
    showSong() {
      return typeof this.song == 'object' && 
        this.song.artist !== undefined && 
        this.song.title !== undefined
    }
  }
})

Vue.component('new-playlist-item', {
  template: '#new-playlist-item',
  props: {
    playlistItems: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      artist: '',
      title: '',
      errorMsg: ''
    }
  },
  methods: {
    addSong() {
      
      let { artist, title } = this
      
      if ( this.artist.length > 0 && this.title.length > 0 ) {
        
        this.playlistItems.push({
          artist,
          title
        })

        this.clearForm()
        
      } else {
        this.errorMsg = 'You did not fill in all the required fields'
      }
    },
    clearForm() {
      this.artist = ''
      this.title = ''
      this.errorMsg = ''
    }
  }
})

Vue.component('current-song', {
  template: '#current-song'
})


Vue.component('credits', {
  template: '#credits',
  data() {
    return {
      name: 'Sybren Dotinga',
      twitter: 'https://twitter.com/sybrendotinga'
    }
  }
})


Vue.component('button-play', {
  template: '#button-play',
  props: {
    song: {
      required: true
    }
  },
  methods: {
    playSong(){
      this.$store.dispatch('playSong', this.song)
    }
  }
})


Vue.component('button-stop', {
  template: '#button-stop',
  methods: {
    stopSong() {      
      this.$store.dispatch('stopSong', '')
    }
  }
})


Vue.component('player-status', {
  template: '#player-status',
  data() {
    return {
      status: 0,
      intervalId: null
    }
  },
  computed: {
    barStyle() {
      return {
        width: this.status + '%'
      }
    },
    currentSong() {
      let song = this.$store.state.currentSong
      if ( song && this.intervalId === null ) {
        this.startPlaying()
      }
      if ( !song ) {
        this.stopPlaying()
      }
      return song
    },
    songPlaying() {
      return typeof this.currentSong === 'object'
    }
  },
  methods: {
    startPlaying() {
      let that = this;
      that.intervalId = setInterval( () => {
        if ( that.status < 100 ) {
          that.status++
        } else {
          that.stopPlaying()
        }
      }, 1000)
    },
    stopPlaying() {
      this.status = 0
      clearInterval( this.intervalId )
      this.intervalId = null
    }
  }
})


const vue = new Vue({
  el: '#vueApp', 
  store
})
              
            
!
999px

Console