Begin to add HTML generation helpers

This commit is contained in:
Aria 2023-06-19 03:14:32 -07:00
parent b01bf6e129
commit 1980ff5fd8
9 changed files with 282 additions and 0 deletions

View file

@ -0,0 +1,39 @@
package dev.zontreck.ariaslib.html;
import dev.zontreck.ariaslib.html.bootstrap.Color;
public class Background extends Element
{
public Background ( Color color, boolean subtle, boolean gradient) {
super ( "" );
bgColor=color;
isSubtle=subtle;
hasGradient=gradient;
}
public Color bgColor;
public boolean isSubtle = false;
public boolean hasGradient = false;
/**
* Generate a background string to be inserted into the class of a existing element
*/
@Override
public String toString()
{
return "bg-" + bgColor.name ().toLowerCase ( ) + (isSubtle ? "-subtle" : "") + (hasGradient ? ".bg-gradient" : "");
}
/**
* Generate a background string to be inserted into the class of a existing element
*/
public static String getBackgroundClass(Color color, boolean isSubtle, boolean hasGradient)
{
return "bg-"+color.name ().toLowerCase ( ) + (isSubtle ? "-subtle" : "") + (hasGradient ? ".bg-gradient" : "");
}
}

View file

@ -0,0 +1,37 @@
package dev.zontreck.ariaslib.html;
import dev.zontreck.ariaslib.html.bootstrap.Color;
public class Border extends Element
{
public Border (Color color, boolean subtle) {
super ( "" );
borderColor=color;
isSubtle=subtle;
}
public Color borderColor;
public boolean isSubtle = false;
/**
* Generate a border string to be inserted into the class of a existing element
*/
@Override
public String toString()
{
return "border-" + borderColor.name ().toLowerCase ( ) + (isSubtle ? "-subtle" : "");
}
/**
* Generate a border string to be inserted into the class of a existing element
*/
public static String getBorderClass(Color color, boolean isSubtle)
{
return "border-"+color.name ().toLowerCase ( ) + (isSubtle ? "-subtle" : "");
}
}

View file

@ -0,0 +1,52 @@
package dev.zontreck.ariaslib.html;
import dev.zontreck.ariaslib.html.bootstrap.Color;
public class Button extends Element
{
public Color elementColor = Color.Primary;
public boolean isOutline=false;
public boolean isDisabled=false;
public enum ButtonSize
{
Normal,
Large,
Small
}
public ButtonSize size = ButtonSize.Normal;
public String label = "Click me";
public Button (String label) {
super("button");
this.label=label;
}
private String getSizeText()
{
switch(size)
{
case Normal -> {
return "";
}
case Large -> {
return "btn-lg ";
}
case Small -> {
return "btn-sm ";
}
default -> {
return "";
}
}
}
@Override
public String toString()
{
return "<" + elementName + " type='button' class='btn " + getSizeText() + " " + (isDisabled?"disabled " : "") + "btn-" + (isOutline ? "outline-" : "") + elementColor.name ().toLowerCase ( )+ "'>" + label + "</" + elementName + ">";
}
}

View file

@ -0,0 +1,39 @@
package dev.zontreck.ariaslib.html;
public class DOM
{
/**
* Generates a HTML Header that automatically includes dependencies
* @return HTML
*/
public static String getHTMLHeader(String pageTitle)
{
return "<!doctype html>\n" +
"<html lang=\"en\">\n" +
" <head>\n" +
" <!-- Required meta tags -->\n" +
" <meta charset=\"utf-8\">\n" +
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" +
"\n" +
" <!-- Bootstrap CSS -->\n" +
" \n" +
" <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM\" crossorigin=\"anonymous\">\n\n" +
"\n" +
" <title>"+pageTitle+"</title>\n" +
" </head>\n" +
" <body>\n" +
"\n" +
" <!-- Optional JavaScript; choose one of the two! -->\n" +
"\n" +
" <!-- Option 1: Bootstrap Bundle with Popper -->\n" +
" \n" +
" <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz\" crossorigin=\"anonymous\"></script>\n\n" +
"\n";
}
public static String closeHTML()
{
return "</body></html>";
}
}

View file

@ -0,0 +1,11 @@
package dev.zontreck.ariaslib.html;
public class Element
{
public String elementName;
public Element(String name)
{
elementName=name;
}
}

View file

@ -0,0 +1,20 @@
package dev.zontreck.ariaslib.html;
import dev.zontreck.ariaslib.util.Percent;
public class Opacity extends Element
{
public Opacity ( Percent val ) {
super ( "" );
value=val;
}
public Percent value;
@Override
public String toString()
{
return "bg-opacity-" + value.get();
}
}

View file

@ -0,0 +1,19 @@
package dev.zontreck.ariaslib.html;
import dev.zontreck.ariaslib.html.bootstrap.Color;
public class TextColor extends Element
{
public TextColor ( Color color ) {
super ( "" );
}
public Color color;
@Override
public String toString()
{
return "text-" + color.name ().toLowerCase ( );
}
}

View file

@ -0,0 +1,46 @@
package dev.zontreck.ariaslib.html.bootstrap;
public enum Color
{
/**
* Dark Blue
*/
Primary,
/**
* Dark Gray
*/
Secondary,
/**
* Dark Green
*/
Success,
/**
* Dark Red
*/
Danger,
/**
* Yellow
*/
Warning,
/**
* Light Blue
*/
Info,
/**
* Black
*/
Dark,
/**
* Semi-gray
*/
Light,
Black,
White
}

View file

@ -0,0 +1,19 @@
package dev.zontreck.ariaslib.util;
public class Percent
{
int current;
int maximum;
public Percent(int cur, int max)
{
current=cur;
maximum=max;
}
public int get()
{
return ((current * 100) / maximum);
}
}