Added Html utility for creating Tabs (Like on Performance tab) easily.

This commit is contained in:
Rsl1122 2018-01-30 10:22:24 +02:00
parent bd96978917
commit 099f68be3c
2 changed files with 75 additions and 0 deletions

View File

@ -51,6 +51,11 @@ public enum Html {
DIV_W_CLASS_STYLE("<div class=\"${0}\" style=\"${1}\">${2}</div>"),
//
ROW("<div class=\"row\">${0}</div>"),
CARD("<div class=\"card\">${0}</div>"),
BODY("<div class=\"body\">${0}</div>"),
PANEL("<div class=\"panel panel-default\">${0}</div>"),
PANEL_BODY("<div class=\"panel-body\">${0}</div>"),
//
TABLE_END("</tbody></table>"),
TABLE("<table class=\"table table-striped\">"),

View File

@ -0,0 +1,70 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.utilities.html.structure;
import com.djrapitops.plugin.utilities.Format;
/**
* Represents a structural HTML element that has Tabs on the top.
*
* @author Rsl1122
*/
public class TabsElement {
private final Tab[] tabs;
public TabsElement(Tab... tabs) {
this.tabs = tabs;
}
public String toHtml() {
StringBuilder nav = new StringBuilder();
StringBuilder content = new StringBuilder();
nav.append("<ul class=\"nav nav-tabs tab-nav-right\" role=\"tablist\">");
content.append("<div class=\"tab-content\">");
boolean first = true;
for (Tab tab : tabs) {
String id = tab.getId();
String navText = tab.getNavText();
String contentHtml = tab.getContentHtml();
nav.append("<li role=\"presentation\"").append(first ? " class=\"active\"" : "")
.append("><a href=\"#").append(id).append("\" data-toggle=\"tab\">")
.append(navText).append("</a></li>");
content.append("<div role=\"tabpanel\" class=\"tab-pane fade").append(first ? " in active" : "")
.append("\" id=\"").append(id).append("\">")
.append(contentHtml).append("</div>");
first = false;
}
content.append("</div>");
nav.append("</ul>");
return nav.toString() + content.toString();
}
public static class Tab {
private final String navText;
private final String contentHtml;
public Tab(String navText, String contentHtml) {
this.navText = navText;
this.contentHtml = contentHtml;
}
public String getNavText() {
return navText;
}
public String getContentHtml() {
return contentHtml;
}
public String getId() {
return "tab_" + new Format(navText).removeSymbols().removeWhitespace().lowerCase().toString();
}
}
}