Skip to content
Snippets Groups Projects
Example1Generic.vue 2.06 KiB
Newer Older
<script setup>
import DragGrid from "../../src/DragGrid.vue";
</script>

<template>
  <DragGrid
    :rows="8"
    :cols="5"
    :pos-validation="blockField"
    v-model="items"
    class="bordered"
  >
    <div id="blocker">
Julian's avatar
Julian committed
      This field and the next one are blocked.
      <div></div>
    </div>
    <template #item="item">
      <div class="container">{{ item }}</div>
    </template>
  </DragGrid>
</template>

<script>
export default {
  name: "Example1Generic",
  methods: {
    blockField(x, y, key) {
      // We won't move fields with ID 'obj8' and nothing into (3, 3) and (4, 3)
      if (x === 3 && y === 3) return false;
      if (x === 4 && y === 3) return false;
      return key !== "obj8";
    },
  },
  data() {
    return {
      items: [
        { x: 1, y: 3, w: 1, h: 1, key: "obj1", data: {} },
        { x: 2, y: 1, w: 1, h: 1, key: "obj2", data: {} },
        { x: 3, y: 1, w: 2, h: 2, key: "obj3", data: {} },
        { x: 5, y: 2, w: 1, h: 1, key: "obj4", data: {} },
        { x: 1, y: 1, w: 1, h: 2, key: "obj5", data: {} },
        { x: 5, y: 1, w: 1, h: 1, key: "obj6", data: {} },
        { x: 2, y: 2, w: 1, h: 3, key: "obj7", data: {} },
        {
          x: 1,
          y: 4,
          w: 1,
          h: 1,
          key: "obj8",
          data: { title: "I'm blocked from moving!" },
        },
        { x: 5, y: 3, w: 1, h: 1, key: "obj9", data: {} },
      ],
    };
  },
};
</script>

<style scoped>
#blocker {
  grid-row: 3 / span 1;
  grid-column: 3 / span 1;
  background-image: linear-gradient(
    45deg,
    #edd85f 25%,
    #0f2b3d 25%,
    #0f2b3d 50%,
    #edd85f 50%,
    #edd85f 75%,
    #0f2b3d 75%,
    #0f2b3d 100%
  );
  background-size: 56.57px 56.57px;
  color: white;
  font-size: large;
  font-weight: bold;
  text-shadow: 4px 4px 4px #2c3e50;
Julian's avatar
Julian committed
  position: relative;
  padding: 1em;
}

#blocker > div {
  position: absolute;
  right: 0.5rem;
  color: red;
  font-size: 5em;
  top: 50%;
  transform: translate(0, -50%);
}

.container {
  background: lightcoral;
  width: 100%;
  height: 100%;
}

.bordered {
  border: 2px solid grey;
}
</style>