draggable-cards.component.ts 6.43 KB
Newer Older
Ooh-Ao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
import {
  CdkDragDrop,
  moveItemInArray,
  transferArrayItem,
} from '@angular/cdk/drag-drop';
import { Component, OnInit } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Component({
  selector: 'app-draggable-cards',
  templateUrl: './draggable-cards.component.html',
  styleUrls: ['./draggable-cards.component.scss'],
})
export class DraggableCardsComponent implements OnInit {
  col1 = [
    `<div class="box mb-0">
                    <div class="box-body">
                      Some quick example text to build on the card title and make up the bulk of the card's content.
                    </div>
                  </div>`,
    `<div class="box mb-0 !bg-primary text-white">
                    <div class="box-body">
                      Some quick example text to build on the card title and make up the bulk of the card's content.
                    </div>
                  </div>`,
    `<div class="box mb-0">
                    <img class="w-full h-auto rounded-t-sm" src="./assets/img/gallery/3.jpg" alt="Image Description">
                    <div class="p-4 md:p-5">
                        <h3 class="text-lg font-bold text-gray-800 dark:text-white">
                            Card title
                        </h3>
                        <p class="mt-1 text-gray-800 dark:text-white/70">
                            Some quick example text to build on the card title and make up the bulk of the
                            card's content.
                        </p>
                        <a class="mt-3 py-2 px-3 inline-flex justify-center items-center gap-2 rounded-sm border border-transparent font-semibold bg-primary text-white hover:bg-primary focus:outline-none focus:ring-0 focus:ring-primary focus:ring-offset-0 transition-all text-sm dark:focus:ring-offset-white/10" href="javascript:void(0);">
                            Go somewhere
                        </a>
                    </div>
                  </div>`,
    `<div class="box mb-0 !bg-success text-white">
                    <div class="box-body">
                      Some quick example text to build on the card title and make up the bulk of the card's content.
                    </div>
                  </div>`,
  ];
  col2 = [
    `<div class="box mb-0 !bg-primary text-white">
                    <div class="box-body">
                      Some quick example text to build on the card title and make up the bulk of the card's content.
                    </div>
                  </div>`,
    `<div class="box mb-0">
                    <div class="box-body">
                      Some quick example text to build on the card title and make up the bulk of the card's content.
                    </div>
                  </div>`,
    `<div class="box mb-0 !bg-warning text-white">
                    <div class="box-body">
                      Some quick example text to build on the card title and make up the bulk of the card's content.
                    </div>
                  </div>`,
    `<div class="box mb-0">
                    <img class="w-full h-auto rounded-t-sm" src="./assets/img/gallery/3.jpg" alt="Image Description">
                    <div class="p-4 md:p-5">
                        <h3 class="text-lg font-bold text-gray-800 dark:text-white">
                            Card title
                        </h3>
                        <p class="mt-1 text-gray-800 dark:text-white/70">
                            Some quick example text to build on the card title and make up the bulk of the
                            card's content.
                        </p>
                        <a class="mt-3 py-2 px-3 inline-flex justify-center items-center gap-2 rounded-sm border border-transparent font-semibold bg-primary text-white hover:bg-primary focus:outline-none focus:ring-0 focus:ring-primary focus:ring-offset-0 transition-all text-sm dark:focus:ring-offset-white/10" href="javascript:void(0);">
                            Go somewhere
                        </a>
                    </div>
                  </div>`,
  ];
  col3 = [
    `<div class="box !bg-secondary text-white mb-0">
                    <div class="box-body">
                      Some quick example text to build on the card title and make up the bulk of the card's content.
                    </div>
                  </div>`,
    `<div class="box mb-0 !bg-info text-white">
                    <div class="box-body">
                      Some quick example text to build on the card title and make up the bulk of the card's content.
                    </div>
                  </div>`,
    `<div class="box mb-0 !bg-danger text-white">
                    <div class="box-body">
                      Some quick example text to build on the card title and make up the bulk of the card's content.
                    </div>
                  </div>`,
    `<div class="box mb-0">
                    <div class="p-4 md:p-5">
                        <h3 class="text-lg font-bold text-gray-800 dark:text-white">
                            Card title
                        </h3>
                        <p class="mt-1 text-gray-800 dark:text-white/70">
                            Some quick example text to build on the card title and make up the bulk of the
                            card's content.
                        </p>
                        <a class="mt-3 py-2 px-3 inline-flex justify-center items-center gap-2 rounded-sm border border-transparent font-semibold bg-primary text-white hover:bg-primary focus:outline-none focus:ring-0 focus:ring-primary focus:ring-offset-0 transition-all text-sm dark:focus:ring-offset-white/10" href="javascript:void(0);">
                            Go somewhere
                        </a>
                    </div>
                    <img class="w-full h-auto rounded-b-sm" src="./assets/img/gallery/3.jpg" alt="Image Description">
                  </div>`,
  ];

  drop(event: CdkDragDrop<string[]>) {
    if (event.previousContainer === event.container) {
      moveItemInArray(
        event.container.data,
        event.previousIndex,
        event.currentIndex
      );
    } else {
      transferArrayItem(
        event.previousContainer.data,
        event.container.data,
        event.previousIndex,
        event.currentIndex
      );
    }
  }

  getSanitizedSVG(svgContent: string): SafeHtml {
    return this.sanitizer.bypassSecurityTrustHtml(svgContent);
  }

  constructor(private sanitizer: DomSanitizer) {}

  ngOnInit(): void {}
}