-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
712 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
demo-v24/src/main/java/org/vaadin/miki/demo/providers/ComponentSelectProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.vaadin.miki.demo.providers; | ||
|
||
import com.vaadin.flow.component.button.Button; | ||
import com.vaadin.flow.component.button.ButtonVariant; | ||
import org.vaadin.miki.demo.ComponentProvider; | ||
import org.vaadin.miki.demo.Order; | ||
import org.vaadin.miki.demo.data.Format; | ||
import org.vaadin.miki.superfields.componentselect.ComponentSelect; | ||
import org.vaadin.miki.superfields.componentselect.ComponentSelectHelpers; | ||
import org.vaadin.miki.superfields.layouts.FlexLayoutHelpers; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Provides a {@link ComponentSelect} that uses themed buttons and {@link Format}. | ||
* | ||
* @author miki | ||
* @since 2023-11-17 | ||
*/ | ||
@Order(96) | ||
public class ComponentSelectProvider implements ComponentProvider<ComponentSelect<Button, Format>> { | ||
@Override | ||
public ComponentSelect<Button, Format> getComponent() { | ||
return new ComponentSelect<>(FlexLayoutHelpers::row, | ||
(integer, format) -> new Button("%d. %s".formatted(integer + 1, format.name().toLowerCase(Locale.ROOT).replace('_', ' '))), | ||
Format.values() | ||
) | ||
.withHelperText("(click a button to select the corresponding option)") | ||
.withComponentSelectedAction(ComponentSelectHelpers.addVariant(ButtonVariant.LUMO_PRIMARY)) | ||
.withComponentDeselectedAction(ComponentSelectHelpers.removeVariant(ButtonVariant.LUMO_PRIMARY)) | ||
.withLabel("Select your favourite book format:"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A `CustomField` that allows shows options as `ClickNotifer`s (e.g. `Button`s) and allows custom selection/deselection actions (e.g. style or theme changes). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
superfields/src/main/java/org/vaadin/miki/superfields/buttons/ButtonSelect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.vaadin.miki.superfields.buttons; | ||
|
||
import com.vaadin.flow.component.Component; | ||
import com.vaadin.flow.component.HasComponents; | ||
import com.vaadin.flow.component.button.Button; | ||
import com.vaadin.flow.component.button.ButtonVariant; | ||
import com.vaadin.flow.function.SerializableBiConsumer; | ||
import com.vaadin.flow.function.SerializableBiFunction; | ||
import org.vaadin.miki.superfields.componentselect.ComponentSelect; | ||
import org.vaadin.miki.superfields.componentselect.ComponentSelectHelpers; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* The simplest possible extension of {@link ComponentSelect} that uses {@link Button}s. | ||
* | ||
* @author miki | ||
* @since 2023-11-17 | ||
*/ | ||
public class ButtonSelect<T> extends ComponentSelect<Button, T> { | ||
|
||
/** | ||
* Creates a {@link ButtonSelect} that uses style names to visually distinguish the selected button. | ||
* @param layoutProvider Provides the root layout of the component. | ||
* @param selectedClassName Style name used when a button is selected. | ||
* @param deselectedClassName Style name used when a button is deselected. | ||
* @param items Items. | ||
* @param <L> Layout type. | ||
*/ | ||
@SafeVarargs | ||
public <L extends Component & HasComponents> ButtonSelect(Supplier<L> layoutProvider, String selectedClassName, String deselectedClassName, T... items) { | ||
this(layoutProvider, ComponentSelectHelpers.simpleComponentFactory(Button::new), | ||
ComponentSelectHelpers.changeStyle(deselectedClassName, selectedClassName), | ||
ComponentSelectHelpers.changeStyle(selectedClassName, deselectedClassName), | ||
items); | ||
} | ||
|
||
/** | ||
* Creates a {@link ButtonSelect} that uses {@link ButtonVariant} to visually distinguish the selected button. | ||
* @param layoutProvider Provides the root layout of the component. | ||
* @param selectedVariant Variant to use for the selected button. The lack of this variant indicates a non-selected button. | ||
* @param items Items. | ||
* @param <L> Layout type. | ||
*/ | ||
@SafeVarargs | ||
public <L extends Component & HasComponents> ButtonSelect(Supplier<L> layoutProvider, ButtonVariant selectedVariant, T... items) { | ||
this(layoutProvider, ComponentSelectHelpers.simpleComponentFactory(Button::new, Object::toString), | ||
ComponentSelectHelpers.addVariant(selectedVariant), | ||
ComponentSelectHelpers.removeVariant(selectedVariant), | ||
items); | ||
} | ||
|
||
/** | ||
* Creates a {@link ButtonSelect}. | ||
* @param layoutSupplier Provides the root layout of the component. | ||
* @param componentFactory A factory to create {@link Button}s for each option. | ||
* @param selectionModifier Action to perform when a button is selected. | ||
* @param deselectionModifier Action to perform when a button is deselected. | ||
* @param options Items. | ||
* @param <L> Layout type. | ||
*/ | ||
@SafeVarargs | ||
public <L extends Component & HasComponents> ButtonSelect(Supplier<L> layoutSupplier, SerializableBiFunction<Integer, T, Button> componentFactory, SerializableBiConsumer<Integer, Button> selectionModifier, SerializableBiConsumer<Integer, Button> deselectionModifier, T... options) { | ||
super(layoutSupplier, componentFactory, selectionModifier, deselectionModifier, options); | ||
} | ||
} |
Oops, something went wrong.