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

              
                <div id="app">
  <v-app :dark="darkMode" id="inspire">
    <v-container grid-list-xl>
      <v-layout
        align-center
        column
        wrap
      >
        <v-flex>
          <v-card
            v-if="avatars && avatars.length > 0"
            width="320"
          >
            <v-card-title class="title">
              Team
              <span class="grey--text ml-1">
                Stacked
              </span>
            </v-card-title>
            <v-divider></v-divider>
            <v-card-text>
              <div>
                The main objective of the stacked avatar group:
              </div>
              <ul>
                <li>To display a list of avatars, overlapped (left to right) with the avatars laid over each other</li>
                <li>The avatars should be overlaid on top of each other, so that the first avatar is fully visible</li>
                <li>The stacked avatars container should be scrollable (horizontally) on both desktop and mobile when needed</li>
              </ul>
            </v-card-text>
            <v-divider></v-divider>
            <section class="avatars-group pa-3 stacked">
              <div v-for="avatar in avatarsSorted" :key="`avatar-id-${avatar.id}`" class="avatars-group__item">
                <v-tooltip bottom>
                  <profile-avatar :avatar="avatar" slot="activator">
                    <profile-presence v-if="presence" :presence="avatar.presence"></profile-presence>
                  </profile-avatar>
                  <profile-tooltip :avatar="avatar" :presence="presence"></profile-tooltip>
                </v-tooltip>
              </div>
            </section>
          </v-card>
        </v-flex>
        <v-flex>
          <v-card
            v-if="avatarsStackedLimited && avatarsStackedLimited.length > 0"
            width="320"
          >
            <v-card-title class="title">
              Team
              <span class="grey--text ml-1">
                Stacked &amp; Limited
              </span>
            </v-card-title>
            <v-divider></v-divider>
            <section class="avatars-group pa-3 stacked">
              <div v-for="avatar in avatarsStackedLimited" :key="`avatar-id-${avatar.id}`" class="avatars-group__item">
                <v-tooltip bottom>
                  <profile-avatar :avatar="avatar" slot="activator">
                    <profile-presence v-if="presence" :presence="avatar.presence"></profile-presence>
                  </profile-avatar>
                  <profile-tooltip :avatar="avatar" :presence="presence"></profile-tooltip>
                </v-tooltip>
              </div>
              <div class="avatars-group__item more">
                <v-avatar color="primary" size="40px">
                  <v-menu
                    v-model="stackedMenu"
                    lazy
                    left
                    :max-height="menuMaxHeight"
                    nudge-bottom="8"
                    offset-y
                  >
                    <template v-slot:activator="{ on }">
                      <v-btn icon v-on="on">
                        <v-icon :color="$vuetify.theme.dark ? 'grey darken-2' : 'white'">more_horiz</v-icon>
                      </v-btn>
                    </template>
                    <v-list dense two-line>
                      <v-list-tile
                        v-for="avatar in avatarsSorted"
                        :key="`avatar-menu-id-${avatar.id}`"
                        avatar
                      >
                        <v-list-tile-avatar>
                          <profile-avatar :avatar="avatar" custom-class="bordered small" size="32px">
                            <profile-presence v-if="presence" :presence="avatar.presence"></profile-presence>
                          </profile-avatar>
                        </v-list-tile-avatar>
                        <v-list-tile-content>
                          <v-list-tile-title>{{ avatar.alt }}</v-list-tile-title>
                          <v-list-tile-sub-title>{{ avatar.role }}</v-list-tile-sub-title>
                        </v-list-tile-content>
                      </v-list-tile>
                    </v-list>
                  </v-menu>
                </v-avatar>
              </div>
            </section>
          </v-card>
        </v-flex>
        <v-flex>
          <v-card
            v-if="avatarsSorted && avatarsSorted.length > 0"
            width="320"
          >
            <v-card-title class="title">
              Team
              <span class="grey--text ml-1">
                Grid
              </span>
            </v-card-title>
            <v-divider></v-divider>
            <section class="avatars-group grid pa-3">
              <div v-for="avatar in avatarsSorted" :key="`avatar-id-${avatar.id}`" class="avatars-group__item">
                <v-tooltip bottom>
                  <profile-avatar :avatar="avatar" slot="activator">
                    <profile-presence v-if="presence" :presence="avatar.presence"></profile-presence>
                  </profile-avatar>
                  <profile-tooltip :avatar="avatar" :presence="presence"></profile-tooltip>
                </v-tooltip>
              </div>
            </section>
          </v-card>
        </v-flex>
        <v-flex>
          <v-switch label="Dark mode" v-model="darkMode"></v-switch>
          <v-switch label="Display presence" v-model="presence"></v-switch>
        </v-flex>
        <v-flex>
          <v-card width="320">
            <v-card-title class="title">
              Inspiration
            </v-card-title>
            <v-divider></v-divider>
            <v-card-text>
              <ul>
                <li><a href="https://leap.mediumra.re/documentation/css-avatars.html" target="_blank">Leap - CSS avatars</a></li>
                <li><a href="https://csslayout.io/patterns/avatar-list" target="_blank">CSS Layout - Avatar List</a></li>
              </ul>
            </v-card-text>
          </v-card>
        </v-flex>
      </v-layout>
    </v-container>
  </v-app>
</div>
              
            
!

CSS

              
                $avatar-size = 40px
$base-unit = 8px
$border-width = $base-unit / 4

.avatars-group
  &.grid
    display grid
    grid-gap $base-unit
    grid-template-columns repeat(auto-fit, minmax(($avatar-size + $base-unit), 1fr))
  &.stacked
    display flex
    flex-direction row
    direction ltr
    max-width 100%
    overflow hidden
    overflow-x auto
    white-space nowrap
    > *
      margin-right -($base-unit)
      &:last-of-type
        padding-right ($base-unit * 2)
  &__item
    cursor default
    transition all .1s ease-out
    &.more
      align-items center
      display flex
      &:hover
        transform none
    &:hover
      transform translateY(-($base-unit / 2))
      z-index 1
  .v-avatar
    box-shadow 0px 0px 0px $border-width #fff inset
    img
      padding $border-width
    span
      align-items center
      display flex
      font-size 110%
      font-weight 700
      height 100%
      justify-content center
      letter-spacing 0.1rem
      text-shadow 0px 0px 2px rgba(0, 0, 0, 0.56)
      width inherit

.v-avatar.bordered
  box-shadow 0px 0px 0px $border-width #fff inset
  img
    padding $border-width
.v-avatar.bordered.small
    box-shadow 0px 0px 0px ($border-width - 1) #fff inset
    img
      padding ($border-width - 1)
 
.presence
  box-shadow 0px 0px 0px ($border-width) #fff inset
  border-radius 50%
  bottom 0px
  display block
  height ($base-unit * 1.75)
  position absolute
  width ($base-unit * 1.75)
.v-avatar.bordered.small
  .presence
    box-shadow 0px 0px 0px ($border-width - 1) #fff inset
    display block
    height ($base-unit * 1)
    position absolute
    width ($base-unit * 1)
              
            
!

JS

              
                // Locally Registered Component
const ProfileAvatar = {
  props: {
    avatar: {
      default: () => {},
      type: Object
    },
    customClass: {
      default: '',
      type: String
    },
    size: {
      default: '48px',
      type: String
    }
  },
  template: `
    <v-avatar :class="(customClass) ? customClass : ''" :color="(!avatar.src) ? GetColour(avatar.alt) : null" :size="size">
      <slot></slot>
      <img
        v-if="avatar.src"
        :src="avatar.src"
        :alt="avatar.alt"
      >
      <span
        v-else
        class="white--text"
      >
        {{ GetInitials(avatar.alt) }}
      </span>
    </v-avatar>
  `,
  methods: {
    GetColour (name) {
      var hash = 0;
      if (name.length === 0) return hash
      for (var i = 0; i < name.length; i++) {
        hash = name.charCodeAt(i) + ((hash << 5) - hash)
        hash = hash & hash
      }
      var color = '#'
      for (var i = 0; i < 3; i++) {
        var value = (hash >> (i * 8)) & 255
        color += ('00' + value.toString(16)).substr(-2)
      }
      return color
    },
    GetInitials (name) {
      const parts = name.split(' ')
      let initials = ''
      for (var i = 0; i < parts.length; i++) {
        if (parts[i].length > 0 && parts[i] !== '') {
          initials += parts[i][0]
        }
      }
      return initials
    }
  }
}

const ProfilePresence = {
  props: {
    presence: {
      default: 'away',
      type: String
    }
  },
  computed: {
    presenceColour () {
      switch (this.presence.toLowerCase()) {
        case 'away':
          return 'orange'
        case 'busy':
          return 'red'
        case 'holiday':
          return 'purple'
        case 'offline':
          return 'grey'
        case 'online':
          return 'success'
      }
    }
  },
  template: `
    <div class="presence" :class="presenceColour"></div>
  `
}

const ProfileTooltip = {
  props: {
    avatar: {
      default: () => {},
      type: Object
    },
    presence: {
      default: true,
      type: Boolean
    }
  },
  template: `
    <v-layout column>
      <span v-if="presence" class="font-weight-medium text-uppercase">
        <small>{{ avatar.presence }}</small>
      </span>
      <span class="font-weight-medium">{{ avatar.alt }}</span>
      <span>{{ avatar.role }}</span>
    </v-layout>
  `
}

new Vue({
  el: '#app',
  components: {
    ProfileAvatar,
    ProfilePresence,
    ProfileTooltip
  },
  data () {
    return {
      avatars: [
        {
          alt: 'John Smitt',
          id: 1,
          presence: 'Online',
          role: 'Frontend Engineer',
          src: null
        },
        {
          alt: 'Joanne Swizzlette',
          id: 2,
          presence: 'Away',
          role: 'Automation Engineer',
          src: 'https://randomuser.me/api/portraits/med/women/3.jpg'
        },
        {
          alt: 'Frankie Dowle',
          id: 4,
          presence: 'Online',
          role: 'Platform Architect',
          src: 'https://randomuser.me/api/portraits/med/men/8.jpg'
        },
        {
          alt: 'Annette Walker',
          id: 5,
          presence: 'Online',
          role: 'Head of UX',
          src: 'https://randomuser.me/api/portraits/med/women/5.jpg'
        },
        {
          alt: 'Danny Quaide',
          id: 6,
          presence: 'Offline',
          role: 'UI Designer',
          src: 'https://randomuser.me/api/portraits/med/men/10.jpg'
        },
        {
          alt: 'Paisley Arch',
          id: 7,
          presence: 'Holiday',
          role: 'Automation Engineer',
          src: 'https://randomuser.me/api/portraits/med/women/7.jpg'
        },
        {
          alt: 'Kenneth Boomstang',
          id: 8,
          presence: 'Online',
          role: 'Frontend Engineer',
          src: 'https://randomuser.me/api/portraits/med/men/1.jpg'
        },
        {
          alt: 'Donna Avery',
          id: 9,
          presence: 'Online',
          role: 'UX Researcher',
          src: 'https://randomuser.me/api/portraits/med/women/2.jpg'
        },
        {
          alt: 'Phillip Hargreaves',
          id: 10,
          presence: 'Online',
          role: 'Head of Quality',
          src: 'https://randomuser.me/api/portraits/med/men/11.jpg'
        },
        {
          alt: 'Melissa Tushoos',
          id: 11,
          presence: 'Online',
          role: 'Head of Platform Engineering',
          src: 'https://randomuser.me/api/portraits/med/women/4.jpg'
        },
        {
          alt: 'Justin Backbeard',
          id: 12,
          presence: 'Busy',
          role: 'Frontend Engineer',
          src: 'https://randomuser.me/api/portraits/med/men/13.jpg'
        },
        {
          alt: 'Amy Fullerton',
          id: 13,
          presence: 'Busy',
          role: 'UI Designer',
          src: 'https://randomuser.me/api/portraits/med/women/6.jpg'
        },
        {
          alt: 'Angus Dougherty',
          id: 14,
          presence: 'Online',
          role: 'Backend Engineer',
          src: null
        },
        {
          alt: 'Jess Cransley',
          id: 15,
          presence: 'Online',
          role: 'UX Advocate',
          src: 'https://randomuser.me/api/portraits/med/women/8.jpg'
        },
        {
          alt: 'Barry Morgan',
          id: 16,
          presence: 'Away',
          role: 'Frontend Architect',
          src: 'https://randomuser.me/api/portraits/med/men/17.jpg'
        },
        {
          alt: 'Warren Deekead',
          id: 17,
          presence: 'Online',
          role: 'Backend Engineer',
          src: 'https://randomuser.me/api/portraits/med/men/19.jpg'
        },
        {
          alt: 'Melissa Warmslent',
          id: 18,
          presence: 'Holiday',
          role: 'DevOps Engineer',
          src: 'https://randomuser.me/api/portraits/med/women/12.jpg'
        }
      ],
      darkMode: true,
      menuMaxHeight: `${(60 * 5) + 4}px`,
      presence: false,
      stackedLimit: 6,
      stackedMenu: false
    }
  },
  
  computed: {
    avatarsSorted () {
      return (this.avatars && this.avatars.length > 0)
        ? this.avatars.sort((a, b) => a.alt.localeCompare(b.alt))
        : null
    },
    avatarsStackedLimited () {
      return (this.avatarsSorted && this.avatarsSorted.length > 0)
        ? this.avatarsSorted.slice(0, this.stackedLimit)
        : null
    }
  },
  
  created () {
    window.matchMedia("(prefers-color-scheme: dark)").addListener(e => e.matches && this.DarkModeToggle())
    window.matchMedia("(prefers-color-scheme: light)").addListener(e => e.matches && this.DarkModeToggle())
  },
  
  beforeDestroy () {
    window.matchMedia("(prefers-color-scheme: dark)").removeListener()
    window.matchMedia("(prefers-color-scheme: light)").removeListener()
  },
  
  methods: {
    DarkModeToggle () {
      this.darkMode = !this.darkMode
    },
    GetColour (name) {
      var hash = 0;
      if (name.length === 0) return hash
      for (var i = 0; i < name.length; i++) {
        hash = name.charCodeAt(i) + ((hash << 5) - hash)
        hash = hash & hash
      }
      var color = '#'
      for (var i = 0; i < 3; i++) {
        var value = (hash >> (i * 8)) & 255
        color += ('00' + value.toString(16)).substr(-2)
      }
      return color
    }
  }
})
              
            
!
999px

Console