1 module uim.html.components.sidebar_dropdown; 2 3 import uim.html; 4 5 class DH5SidebarDropdown : DH5Component { 6 this() { 7 super(); 8 this 9 .css(`body { 10 font-family: "Lato", sans-serif; 11 } 12 13 /* Fixed sidenav, full height */ 14 .sidenav { 15 height: 100%; 16 width: 200px; 17 position: fixed; 18 z-index: 1; 19 top: 0; 20 left: 0; 21 background-color: #111; 22 overflow-x: hidden; 23 padding-top: 20px; 24 } 25 26 /* Style the sidenav links and the dropdown button */ 27 .sidenav a, .dropdown-btn { 28 padding: 6px 8px 6px 16px; 29 text-decoration: none; 30 font-size: 20px; 31 color: #818181; 32 display: block; 33 border: none; 34 background: none; 35 width: 100%; 36 text-align: left; 37 cursor: pointer; 38 outline: none; 39 } 40 41 /* On mouse-over */ 42 .sidenav a:hover, .dropdown-btn:hover { 43 color: #f1f1f1; 44 } 45 46 /* Main content */ 47 .main { 48 margin-left: 200px; /* Same as the width of the sidenav */ 49 font-size: 20px; /* Increased text to enable scrolling */ 50 padding: 0px 10px; 51 } 52 53 /* Add an active class to the active dropdown button */ 54 .active { 55 background-color: green; 56 color: white; 57 } 58 59 /* Dropdown container (hidden by default). Optional: add a lighter background color and some left padding to change the design of the dropdown content */ 60 .dropdown-container { 61 display: none; 62 background-color: #262626; 63 padding-left: 8px; 64 } 65 66 /* Optional: Style the caret down icon */ 67 .fa-caret-down { 68 float: right; 69 padding-right: 8px; 70 } 71 72 /* Some media queries for responsiveness */ 73 @media screen and (max-height: 450px) { 74 .sidenav {padding-top: 15px;} 75 .sidenav a {font-size: 18px;} 76 }`) 77 .html(`<dclassiv class="sidenav"> 78 <a href="#about">About</a> 79 <a href="#services">Services</a> 80 <a href="#clients">Clients</a> 81 <a href="#contact">Contact</a> 82 <button class="dropdown-btn">Dropdown 83 <i class="fa fa-caret-down"></i> 84 </button> 85 <div class="dropdown-container"> 86 <a href="#">Link 1</a> 87 <a href="#">Link 2</a> 88 <a href="#">Link 3</a> 89 </div> 90 <a href="#contact">Search</a> 91 </div> 92 93 <div class="main"> 94 <h2>Sidebar Dropdown</h2> 95 <p>Click on the dropdown button to open the dropdown menu inside the side navigation.</p> 96 <p>This sidebar is of full height (100%) and always shown.</p> 97 <p>Some random text..</p> 98 </div>`) 99 .js(`* Loop through all dropdown buttons to toggle between hiding and showing its dropdown content - This allows the user to have multiple dropdowns without any conflict */ 100 var dropdown = document.getElementsByClassName("dropdown-btn"); 101 var i; 102 103 for (i = 0; i < dropdown.length; i++) { 104 dropdown[i].addEventListener("click", function() { 105 this.classList.toggle("active"); 106 var dropdownContent = this.nextElementSibling; 107 if (dropdownContent.style.display === "block") { 108 dropdownContent.style.display = "none"; 109 } else { 110 dropdownContent.style.display = "block"; 111 } 112 }); 113 }`); 114 } 115 } 116 auto H5SidebarDropdown() { return new DH5SidebarDropdown(); }