Adjust button to use the Builder
This commit is contained in:
parent
abd487523e
commit
e58efecbff
2 changed files with 46 additions and 30 deletions
|
@ -2,14 +2,12 @@ package dev.zontreck.ariaslib.html;
|
||||||
|
|
||||||
import dev.zontreck.ariaslib.html.bootstrap.Color;
|
import dev.zontreck.ariaslib.html.bootstrap.Color;
|
||||||
|
|
||||||
public class Button extends Element
|
public class Button {
|
||||||
{
|
|
||||||
public Color elementColor = Color.Primary;
|
public Color elementColor = Color.Primary;
|
||||||
public boolean isOutline=false;
|
public boolean isOutline = false;
|
||||||
public boolean isDisabled=false;
|
public boolean isDisabled = false;
|
||||||
|
|
||||||
public enum ButtonSize
|
public enum ButtonSize {
|
||||||
{
|
|
||||||
Normal,
|
Normal,
|
||||||
Large,
|
Large,
|
||||||
Small
|
Small
|
||||||
|
@ -20,15 +18,8 @@ public class Button extends Element
|
||||||
public String label = "Click me";
|
public String label = "Click me";
|
||||||
|
|
||||||
|
|
||||||
public Button (String label) {
|
private String getSizeText ( ) {
|
||||||
super("button");
|
switch ( size ) {
|
||||||
this.label=label;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getSizeText()
|
|
||||||
{
|
|
||||||
switch(size)
|
|
||||||
{
|
|
||||||
case Normal -> {
|
case Normal -> {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -44,9 +35,45 @@ public class Button extends Element
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public HTMLElementBuilder build ( ) {
|
||||||
public String toString()
|
return new HTMLElementBuilder ( "button" ).withAttribute ( "type" , "button" ).withAttribute ( "class" , "btn " + getSizeText ( ) + " " + ( isDisabled ? "disabled " : "" ) + "btn-" + ( isOutline ? "outline-" : "" ) + elementColor.name ( ).toLowerCase ( ) ).withText ( label );
|
||||||
{
|
|
||||||
return "<" + elementName + " type='button' class='btn " + getSizeText() + " " + (isDisabled?"disabled " : "") + "btn-" + (isOutline ? "outline-" : "") + elementColor.name ().toLowerCase ( )+ "'>" + label + "</" + elementName + ">";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Button withLabel ( String label ) {
|
||||||
|
this.label = label;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button hasOutline ( ) {
|
||||||
|
this.isOutline = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button withoutOutline ( ) {
|
||||||
|
this.isOutline = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button isDisabled ( ) {
|
||||||
|
this.isDisabled = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button isEnabled ( ) {
|
||||||
|
this.isDisabled = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button withButtonSize ( ButtonSize size ) {
|
||||||
|
this.size = size;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Button withColor ( Color color ) {
|
||||||
|
this.elementColor = color;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package dev.zontreck.ariaslib.html;
|
|
||||||
|
|
||||||
public class Element
|
|
||||||
{
|
|
||||||
public String elementName;
|
|
||||||
|
|
||||||
public Element(String name)
|
|
||||||
{
|
|
||||||
elementName=name;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue