|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 7 | + <title>Shadow DOM dragging</title> |
| 8 | + <script src="../../../dist/gridstack-all.js"></script> |
| 9 | + </head> |
| 10 | + <body> |
| 11 | + <h2>Inside Custom Element with Shadow DOM</h2> |
| 12 | + <demo-gridstack></demo-gridstack> |
| 13 | + <script type="text/javascript"> |
| 14 | + class HTMLDemoGridStack extends HTMLElement { |
| 15 | + constructor() { |
| 16 | + super(); |
| 17 | + this.attachShadow({ |
| 18 | + mode: "open", |
| 19 | + }); |
| 20 | + } |
| 21 | + |
| 22 | + connectedCallback() { |
| 23 | + const styleBlocks = ` |
| 24 | +<link href="https://unpkg.com/gridstack@11.3.0/dist/gridstack.min.css" rel="stylesheet" /> |
| 25 | +<style type="text/css"> |
| 26 | +*, *::before, *::after { |
| 27 | +box-sizing: border-box; |
| 28 | +} |
| 29 | +:host { display: block; } |
| 30 | +
|
| 31 | +.grid-stack { |
| 32 | +background-color: #fafad2; |
| 33 | +} |
| 34 | +.grid-stack-item-content { |
| 35 | +background-color: #18bc9c; |
| 36 | +} |
| 37 | +</style> |
| 38 | +`; |
| 39 | + |
| 40 | + this.shadowRoot.innerHTML = `${styleBlocks}<div class="grid-stack"></div>`; |
| 41 | + const gridEl = this.shadowRoot.querySelector("div"); |
| 42 | + const items = [ |
| 43 | + { |
| 44 | + content: "my first widget", |
| 45 | + }, // will default to location (0,0) and 1x1 |
| 46 | + { |
| 47 | + w: 2, |
| 48 | + content: "another longer widget!", |
| 49 | + }, // will be placed next at (1,0) and 2x1 |
| 50 | + { |
| 51 | + content: "3rd Widget", |
| 52 | + }, |
| 53 | + ]; |
| 54 | + const grid = GridStack.init( |
| 55 | + { |
| 56 | + disableOneColumnMode: true, |
| 57 | + draggable: { |
| 58 | + appendTo: "parent", |
| 59 | + }, |
| 60 | + cellHeight: 100, |
| 61 | + }, |
| 62 | + gridEl |
| 63 | + ); |
| 64 | + grid.load(items); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + customElements.define("demo-gridstack", HTMLDemoGridStack); |
| 69 | + </script> |
| 70 | + </body> |
| 71 | +</html> |
0 commit comments