-
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
30 changed files
with
342 additions
and
22 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
25 changes: 25 additions & 0 deletions
25
demo-v23/src/main/java/org/vaadin/miki/demo/builders/HasPositionableLabelBuilder.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,25 @@ | ||
package org.vaadin.miki.demo.builders; | ||
|
||
import com.vaadin.flow.component.Component; | ||
import com.vaadin.flow.component.combobox.ComboBox; | ||
import org.vaadin.miki.demo.ContentBuilder; | ||
import org.vaadin.miki.demo.Order; | ||
import org.vaadin.miki.markers.HasLabelPositionable; | ||
import org.vaadin.miki.shared.labels.LabelPosition; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* @author miki | ||
* @since 2022-09-23 | ||
*/ | ||
@Order(33) | ||
public class HasPositionableLabelBuilder implements ContentBuilder<HasLabelPositionable> { | ||
@Override | ||
public void buildContent(HasLabelPositionable component, Consumer<Component[]> callback) { | ||
final ComboBox<LabelPosition> positions = new ComboBox<>("Pick label position:", LabelPosition.values()); | ||
positions.setAllowCustomValue(false); | ||
positions.addValueChangeListener(event -> component.setLabelPosition(event.getValue())); | ||
callback.accept(new Component[]{positions}); | ||
} | ||
} |
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
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
48 changes: 48 additions & 0 deletions
48
superfields/src/main/java/org/vaadin/miki/markers/HasLabelPositionable.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,48 @@ | ||
package org.vaadin.miki.markers; | ||
|
||
import com.vaadin.flow.component.HasElement; | ||
import org.vaadin.miki.shared.labels.LabelPosition; | ||
|
||
/** | ||
* Marker interface for components that have a positionable label. | ||
* | ||
* @author miki | ||
* @since 2022-09-23 | ||
*/ | ||
public interface HasLabelPositionable extends HasElement { | ||
|
||
/** | ||
* Attribute name that contains the selected label position value. | ||
*/ | ||
String LABEL_POSITION_ATTRIBUTE = "data-label-position"; | ||
/** | ||
* Attribute name that contains details of the label for easy styling. | ||
*/ | ||
String LABEL_POSITION_DETAILS_ATTRIBUTE = "data-label-position-details"; | ||
|
||
/** | ||
* Sets the label position to a new one. | ||
* @param position A position to use. Setting {@code null} will reset it to the default setting. | ||
*/ | ||
default void setLabelPosition(LabelPosition position) { | ||
if(position == null || position == LabelPosition.DEFAULT) { | ||
this.getElement().removeAttribute(LABEL_POSITION_ATTRIBUTE); | ||
this.getElement().removeAttribute(LABEL_POSITION_DETAILS_ATTRIBUTE); | ||
} | ||
else { | ||
this.getElement().setAttribute(LABEL_POSITION_ATTRIBUTE, position.name()); | ||
this.getElement().setAttribute(LABEL_POSITION_DETAILS_ATTRIBUTE, position.getPositionData()); | ||
} | ||
} | ||
|
||
/** | ||
* Returns current label position, if it has been set. | ||
* @return A {@link LabelPosition}. | ||
*/ | ||
default LabelPosition getLabelPosition() { | ||
if(this.getElement().hasAttribute(LABEL_POSITION_ATTRIBUTE)) | ||
return LabelPosition.valueOf(this.getElement().getAttribute(LABEL_POSITION_ATTRIBUTE)); | ||
else return LabelPosition.DEFAULT; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
superfields/src/main/java/org/vaadin/miki/markers/WithLabelPositionableMixin.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,23 @@ | ||
package org.vaadin.miki.markers; | ||
|
||
import org.vaadin.miki.shared.labels.LabelPosition; | ||
|
||
/** | ||
* A mixin for {@link HasLabelPositionable}. | ||
* | ||
* @author miki | ||
* @since 2022-09-23 | ||
*/ | ||
public interface WithLabelPositionableMixin<SELF extends HasLabelPositionable> extends HasLabelPositionable { | ||
|
||
/** | ||
* Chains {@link #setLabelPosition(LabelPosition)} and returns itself. | ||
* @param position Position. | ||
* @return This. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
default SELF withLabelPosition(LabelPosition position) { | ||
this.setLabelPosition(position); | ||
return (SELF) this; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
superfields/src/main/java/org/vaadin/miki/shared/labels/LabelPosition.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,77 @@ | ||
package org.vaadin.miki.shared.labels; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Available label positions. | ||
* | ||
* @author miki | ||
* @since 2022-09-23 | ||
*/ | ||
public enum LabelPosition { | ||
|
||
/** | ||
* Default label position, without any changes. | ||
*/ | ||
DEFAULT(false), | ||
|
||
/** | ||
* Label is placed to the side of the component, before it, and aligned to the start of the column. | ||
* In left-to-right, top-to-bottom layouts, this means: label on the left, aligned to the top. | ||
*/ | ||
BEFORE_START, | ||
/** | ||
* Label is placed to the side of the component, before it, and aligned to the middle of the column. | ||
* In left-to-right, top-to-bottom layouts, this means: label on the left, in the vertical middle of column. | ||
*/ | ||
BEFORE_MIDDLE, | ||
/** | ||
* Label is placed to the side of the component, before it, and aligned to the end of the column. | ||
* In left-to-right, top-to-bottom layouts, this means: label on the left, aligned to the bottom. | ||
*/ | ||
BEFORE_END, | ||
/** | ||
* Label is placed to the side of the component, after it, and aligned to the start of the column. | ||
* In left-to-right, top-to-bottom layouts, this means: label on the right, aligned to the top. | ||
*/ | ||
AFTER_START, | ||
/** | ||
* Label is placed to the side of the component, after it, and aligned to the middle of the column. | ||
* In left-to-right, top-to-bottom layouts, this means: label on the right, in the vertical middle of column. | ||
*/ | ||
AFTER_MIDDLE, | ||
/** | ||
* Label is placed to the side of the component, after it, and aligned to the end of the column. | ||
* In left-to-right, top-to-bottom layouts, this means: label on the right, aligned to the bottom. | ||
*/ | ||
AFTER_END, | ||
/** | ||
* Label is placed as the last thing of the entire component. | ||
* In left-to-right, top-to-bottom layouts, this means: label on the bottom. | ||
*/ | ||
LAST(false); | ||
|
||
private final String positionData; | ||
|
||
LabelPosition() { | ||
this(true); | ||
} | ||
|
||
/** | ||
* Creates the enum. | ||
* @param side Whether the label is on the side of the component. | ||
*/ | ||
LabelPosition(boolean side) { | ||
this.positionData = String.join(" ", ((side ? "side_" : "") + this.name()).toLowerCase(Locale.ROOT).split("_")); | ||
} | ||
|
||
/** | ||
* The attribute value that corresponds to the given label position. Used by CSS selectors. | ||
* This is a space-separated list of styles. Never {@code null}. | ||
* | ||
* @return A non-{@code null} array. | ||
*/ | ||
public String getPositionData() { | ||
return positionData; | ||
} | ||
} |
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
Oops, something went wrong.