Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class ToggleButtonGroup<T> extends CustomField<T> {

public enum Orientation {
HORIZONTAL, VERTICAL
HORIZONTAL, VERTICAL, STACKED
}

private List<T> items;
Expand Down Expand Up @@ -95,6 +95,10 @@ private void init() {
}

addButtonsToLayout(buttons);

if(orientation == Orientation.STACKED) {
setValue(items.get(0), false);
}
}

protected void addButtonsToLayout(Button[] buttons) {
Expand Down Expand Up @@ -159,7 +163,15 @@ protected Optional<String> getLastButtonClass() {
}

private String getOrientationStylePostfix() {
return orientation == Orientation.HORIZONTAL ? "h" : "v";
switch(orientation) {
case HORIZONTAL:
return "h";
case STACKED:
return "s";
case VERTICAL:
return "v";
default: throw new IllegalArgumentException();
}
}

private Comparator<T> getDefaultComparator() {
Expand All @@ -186,7 +198,13 @@ protected void buttonsActionListener(ClickEvent<Button> event) {
Serializable selectedValueId = itemIdGenerator.apply(selectedValue);
Serializable previousValueId = itemIdGenerator.apply(getValue());
if (Objects.equals(selectedValueId, previousValueId)) {
setValue(null, event.isFromClient());
if(orientation == Orientation.STACKED) {
int itemIndex = items.indexOf(selectedValue)+1;
T nextItem = items.get(itemIndex == items.size() ? 0 : itemIndex);
setValue(nextItem, event.isFromClient());
}
else setValue(null, event.isFromClient());

return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

}

.toggle-button-group-button-s:not([theme~=primary]) {
display:none;
}

.toggle-button-group-button-s[theme~=primary] {
display: unset;
}

.toggle-button-group-button-h {
border-style: solid;
border-color: var(--_lumo-button-primary-background-color, var(--lumo-primary-color));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public ToggleButtonGroupView() {
);
group100.setId("group100");
group100.setOrientation(ToggleButtonGroup.Orientation.VERTICAL);



ToggleButtonGroup<TextAlignment> group110 = new ToggleButtonGroup<>("Alignment:");
group110.setItems(TextAlignment.values());
Expand All @@ -226,9 +228,17 @@ public ToggleButtonGroupView() {
case RIGHT -> VaadinIcon.ALIGN_RIGHT.create();
});
group110.setItemLabelGenerator(textAlignment -> "");

ToggleButtonGroup<Status> group120 = new ToggleButtonGroup<>(
"Status: [orientation = Stacked]",
Status.values()
);
group120.setId("group120");
group120.setOrientation(ToggleButtonGroup.Orientation.STACKED);
group120.setValue(Status.APPROVED);



VerticalLayout halfLayout = new VerticalLayout(line10, line15, group20, group30, line40, line50, group60, group70, group80, line90, group100, group110);
VerticalLayout halfLayout = new VerticalLayout(line10, line15, group20, group30, line40, line50, group60, group70, group80, line90, group100, group110,group120);
halfLayout.setId("parent-layout");
halfLayout.getStyle().set("width", "50%");
halfLayout.getStyle().set("border", "solid red 1px");
Expand Down