Skip to content
Snippets Groups Projects
MessageInfo.vue 5.7 KiB
Newer Older
Timothee P's avatar
Timothee P committed
  <div
    v-if="messages && messages.length > 0"
    class="row over-content"
  >
    <div class="fourteen wide column">
Timothee P's avatar
Timothee P committed
      <ul
        class="message-list"
        aria-live="assertive"
      >
        <li
          v-for="message in messages"
          :key="'message-' + message.counter"
          :ref="'message-' + message.counter"
          :class="['list-container', { 'show': removedItem !== message.counter }]"
        >
          <div :class="['list-item', { 'show': removedItem !== message.counter }]">
            <div :class="['ui', message.level ? message.level : 'info', 'message']">
              <i
                class="close icon"
                aria-hidden="true"
                @click="removeListItem(message.counter)"
              />
              <div class="header">
                <i
                  class="info circle icon"
                  aria-hidden="true"
                />
                Informations
              </div>
              <ul class="list">
                {{
                  message.comment
                }}
              </ul>
            </div>
          </div>
        </li>
      </ul>

      <!-- <transition-group name="fadeDownUp">
        <div
          v-for="(message, index) in messages"
          :key="'message-' + index"
          :class="['ui', message.level ? message.level : 'info', 'message']"
        >
          <i
            class="close icon"
            aria-hidden="true"
            @click="DISCARD_MESSAGE(message)"
          />
          <div class="header">
            <i
              class="info circle icon"
              aria-hidden="true"
            />
            Informations
          </div>
          <ul class="list">
            {{
              message.comment
            }}
          </ul>
        </div>
Timothee P's avatar
Timothee P committed
      </transition-group> -->
Timothee P's avatar
Timothee P committed
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex';

export default {
  name: 'MessageInfo',

Timothee P's avatar
Timothee P committed
  data() {
    return {
      removedItem: null
    };
  },

  computed: {
    ...mapState(['messages']),
  },

Timothee P's avatar
Timothee P committed
  //mounted() {
  //  //this.animateList();
  //},

  methods: {
    ...mapMutations(['DISCARD_MESSAGE']),
Timothee P's avatar
Timothee P committed

    animateList() {
      const listItems = document.querySelectorAll('.list-item');
      function calculateHeightOfListContainer(){
        const firstListItem = listItems[0];
        let heightOfListItem = firstListItem.clientHeight;
        const styleTag = document.createElement('style');
        document.body.prepend(styleTag);
        styleTag.innerHTML = `.list-container.show {
            height: ${heightOfListItem}px;
        }`;
        //setTimeout(function(){
        //  styleTag.innerHTML += `.list-container {
        //      transition: all 0.6s ease-out;
        //  }`;
        //}, 0);
      }
      calculateHeightOfListContainer();
    },

    removeListItem(messageCount){
      const container = this.$refs['message-' + messageCount][0];
      console.log(container);
      container.ontransitionend = () => {
        console.log('container removed');
        this.DISCARD_MESSAGE(messageCount);
      };
      console.log(container.ontransitionend);
      this.removedItem = messageCount; // starts the transition by removing class show (with height)
    },

    /* addElement(e){
      const container = document.createElement('li'); container.classList.add('list-container'); container.setAttribute('role', 'listitem');
      const listItem = document.createElement('div'); listItem.classList.add('list-item'); listItem.innerHTML = 'List Item';
      container.append(listItem);
      addBtn.parentNode.insertBefore(container, addBtn);
      container.onclick = removeListItem;
      setTimeout(function(){
        container.classList.add('show'); listItem.classList.add('show');
      }, 15);
    } */
Timothee P's avatar
Timothee P committed
<style scoped>

.row.over-content {
  position: absolute; /* to display message info over page content */
  z-index: 99;
  opacity: 0.95;
  width: calc(100% - 4em); /* 4em is #content left + right paddings */
  top: calc(61px + 1em); /* 61px is #app-header height */
  right: 2em; /* 2em is #content left paddings */
}
Timothee P's avatar
Timothee P committed
.message-list{
    list-style: none;
}
.list-container{
    list-style: none;
    width: 100%;
    height: 0;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.6s ease-out;
}
.list-container.show{
  height: 95px;
}
.list-container.show:not(:first-child){
  margin-top: 10px;
}
.list-container .list-item{
    padding: .5rem 0;
    width: 100%;
    position: absolute;
    opacity: 0;
    top: 0;
    left: 0;
    transition: all 0.6s ease-out;
}
.list-container .list-item.show{
    opacity: 1;
}

ul.list{
  overflow: scroll;
  height: 2em;
  margin-bottom: .5em !important;
}

.ui.message {
  overflow: hidden;
  padding-bottom: 0 !important;
}
.ui.message::after {
  content: "";
  position: absolute;
  bottom: 1em;
  left: 1em;
  right: 0;
  width: calc(100% - 2em);
}
.ui.info.message::after {
  box-shadow: 0px 0px 7px 13px rgb(248, 255, 255);
}
.ui.positive.message::after {
  box-shadow: 0px 0px 7px 13px red;
}
.ui.negative.message::after {
  box-shadow: 0px 0px 7px 13px red;
}
Timothee P's avatar
Timothee P committed
/* .fadeDownUp-enter-active {
  animation: fadeInDown .5s;
}
.fadeDownUp-leave-active {
  animation: fadeOutUp .5s;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translate3d(0, -100%, 0);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}
Timothee P's avatar
Timothee P committed
@keyframes fadeOutUp {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate3d(0, -100%, 0);
  }
Timothee P's avatar
Timothee P committed
} */

.ui.message > .close.icon {
  cursor: pointer;
  position: absolute;
  margin: 0em;
  top: 0.78575em;
  right: 0.5em;
  opacity: 0.7;
  -webkit-transition: opacity 0.1s ease;
  transition: opacity 0.1s ease;
}
</style>