1 module uim.bootstrap.bs4.obj; 2 3 import uim.bootstrap; 4 5 class DBS4Obj : DH5Obj { 6 mixin(H5This!("DIV")); 7 8 // Adding a margin 9 O margin(this O)(int size) { return margin("-"~to!string(size)); } 10 O margin(this O)(string side, int size) { return margin(side~"-"~to!string(size)); } 11 O margin(this O)(string value) { 12 if (value.length > 0) this.classes("m"~value); 13 return cast(O) this; 14 } 15 unittest { 16 assert(Assert(BS4Obj.margin("t-2"), `<div class="mt-2"></div>`)); 17 } 18 19 /// Adding padding 20 O padding(this O)(int size) { return padding("-"~to!string(size)); } 21 O padding(this O)(string side, int size) { return padding(side~"-"~to!string(size)); } 22 O padding(this O)(string value) { 23 if (value.length > 0) this.classes("p"~value); 24 return cast(O) this; 25 } 26 unittest { 27 assert(Assert(BS4Obj.padding("t-2"), `<div class="pt-2"></div>`)); 28 } 29 30 /// Clear border 31 O noPadding(this O)(string side = null) { 32 this.classes("p-0"); 33 return cast(O) this; 34 } 35 36 /// Adding border 37 O border(this O)(int value) { 38 if (value > 0) this.classes("border-"~to!string(value)); 39 else this.classes("border"); 40 return cast(O) this; 41 } 42 O border(this O)(string side, int value) { return border(side~"-"~to!string(value)); } 43 O border(this O)(string value = null) { 44 if (value.length > 0) this.classes("border-"~value); 45 else this.classes("border"); 46 return cast(O) this; 47 } 48 unittest { 49 assert(Assert(BS4Obj.border, `<div class="border"></div>`)); 50 assert(Assert(BS4Obj.border(1), `<div class="border-1"></div>`)); 51 assert(Assert(BS4Obj.border("top"), `<div class="border-top"></div>`)); 52 } 53 54 /// Clear border 55 O noBorder(this O)(string side = null) { 56 if (side.length > 0) this.classes("border-"~side~"-0"); 57 else this.classes("border-0"); 58 return cast(O) this; 59 } 60 unittest { 61 assert(Assert(BS4Obj.noBorder, `<div class="border-0"></div>`)); 62 } 63 64 /// Set border color 65 O borderColor(this O)(string color) { 66 if (color.length > 0) this.classes("border-"~color); 67 return cast(O) this; 68 } 69 unittest { 70 assert(Assert(BS4Obj.borderColor("primary"), `<div class="border-primary"></div>`)); 71 assert(Assert(BS4Obj.border.borderColor("primary"), `<div class="border border-primary"></div>`)); 72 } 73 74 /// Change rounded of corners 75 O rounded(this O)(string value = "") { 76 if (value.length > 0) this.classes("rounded-"~value); 77 else this.classes("rounded"); 78 return cast(O) this; 79 } 80 unittest { 81 assert(Assert(BS4Obj.rounded, `<div class="rounded"></div>`)); 82 assert(Assert(BS4Obj.rounded("top"), `<div class="rounded-top"></div>`)); 83 } 84 85 /// Clear rounded 86 O noRounded(this O)() { 87 this.classes("rounded-0"); 88 return cast(O) this; 89 } 90 unittest { 91 assert(Assert(BS4Obj.noRounded, `<div class="rounded-0"></div>`)); 92 } 93 94 /// Set size of rounded 95 O roundedSize(this O)(string value) { 96 if (value.length > 0) this.classes("rounded-"~value); 97 return cast(O) this; 98 } 99 unittest { 100 assert(Assert(BS4Obj.roundedSize("lg"), `<div class="rounded-lg"></div>`)); 101 } 102 103 O clearfix(this O)() { 104 this.classes("clearfix"); 105 return cast(O) this; 106 } 107 unittest { 108 assert(Assert(BS4Obj.clearfix, `<div class="clearfix"></div>`)); 109 } 110 111 O closeButton(this O)(string icon = "×") { 112 this.content(BS4Button(["close"], ["aria-label":"Close"], H5Span(["aria-label":"true"], icon))); 113 return cast(O) this; 114 } 115 unittest { 116 assert(Assert(BS4Obj.closeButton, `<div><button class="btn close" aria-label="Close" type="button"><span aria-label="true">×</span></button></div>`)); 117 } 118 119 /// Setting text color 120 O textColor(this O)(string color, int value) { return textColor(color, to!string(value)); } 121 O textColor(this O)(string color, string value = null) { 122 if (value.length > 0) this.classes("text-"~color~"-"~value); 123 else this.classes("text-"~color); 124 return cast(O) this; 125 } 126 unittest { 127 assert(Assert(BS4Obj.textColor("primary"), `<div class="text-primary"></div>`)); 128 assert(Assert(BS4Obj.textColor("black", "50"), `<div class="text-black-50"></div>`)); 129 } 130 131 /// Setting background color 132 O background(this O)(string color, int value) { return background(color, to!string(value)); } 133 O background(this O)(string color, string value = null) { 134 if (value.length > 0) this.classes("bg-"~color~"-"~value); 135 else this.classes("bg-"~color); 136 return cast(O) this; 137 } 138 unittest { 139 assert(Assert(BS4Obj.background("primary"), `<div class="bg-primary"></div>`)); 140 } 141 142 /// Setting display 143 O display(this O)(string value) { return this.display(null, value); } 144 O display(this O)(string breakpoint, string value) { 145 if (breakpoint.length > 0) this.classes("d-"~breakpoint~"-"~value); 146 else this.classes("d-"~value); 147 return cast(O) this; 148 } 149 unittest { 150 assert(Assert(BS4Obj.display("none"), `<div class="d-none"></div>`)); 151 assert(Assert(BS4Obj.display("sm", "block"), `<div class="d-sm-block"></div>`)); 152 } 153 154 /// Setting print display 155 O print(this O)(string value) { 156 if (value.length > 0) this.classes("d-print-"~value); 157 return cast(O) this; 158 } 159 unittest { 160 assert(Assert(BS4Obj.print("none"), `<div class="d-print-none"></div>`)); 161 } 162 } 163 164 mixin(H5Calls!"BS4Obj"); 165 166 unittest { 167 assert(Assert(BS4Obj, "<div></div>")); 168 }