From c181d6e538f708a17aca9ec1e288268bc40524d0 Mon Sep 17 00:00:00 2001 From: Miki Date: Mon, 26 Sep 2022 12:17:02 +0300 Subject: [PATCH] Release 0.15.0 ready (#420) * #412 #414 #415 #416 done Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: vaadin-miki Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- README.md | 3 +- demo-v23/pom.xml | 6 +- .../builders/HasPositionableLabelBuilder.java | 25 ++++++ .../demo/builders/ObjectFieldBuilder.java | 2 +- .../demo/builders/VariantFieldBuilder.java | 2 +- .../providers/CollectionFieldProvider.java | 5 +- .../providers/GridMultiSelectProvider.java | 4 +- .../demo/providers/GridSelectProvider.java | 3 +- .../miki/demo/providers/MapFieldProvider.java | 4 +- .../demo/providers/ObjectFieldProvider.java | 5 +- .../demo/providers/SuperCheckboxProvider.java | 18 +++++ demo-v23/src/main/resources/SuperCheckbox.md | 1 + pom.xml | 2 +- superfields/README.md | 4 + superfields/pom.xml | 2 +- superfields/release-notes.md | 9 +++ .../miki/markers/HasLabelPositionable.java | 48 ++++++++++++ .../markers/WithLabelPositionableMixin.java | 23 ++++++ .../miki/shared/labels/LabelPosition.java | 77 +++++++++++++++++++ .../superfields/checkbox/SuperCheckbox.java | 45 +++++++++-- .../collections/CollectionField.java | 7 +- .../superfields/collections/MapField.java | 6 +- .../superfields/dates/SuperDatePicker.java | 5 +- .../dates/SuperDateTimePicker.java | 5 +- .../gridselect/AbstractGridSelect.java | 3 + .../gridselect/GridMultiSelect.java | 5 +- .../superfields/gridselect/GridSelect.java | 5 +- .../numbers/AbstractSuperNumberField.java | 15 +++- .../miki/superfields/object/ObjectField.java | 5 +- .../miki/superfields/text/LabelField.java | 5 ++ .../miki/superfields/text/SuperTextArea.java | 5 +- .../miki/superfields/text/SuperTextField.java | 6 +- .../superfields/variant/VariantField.java | 8 +- .../styles/label-positions-checkbox.css | 7 ++ .../frontend/styles/label-positions-grids.css | 7 ++ .../frontend/styles/label-positions.css | 58 ++++++++++++++ .../checkbox/SuperCheckboxTest.java | 25 ++++++ 37 files changed, 433 insertions(+), 32 deletions(-) create mode 100644 demo-v23/src/main/java/org/vaadin/miki/demo/builders/HasPositionableLabelBuilder.java create mode 100644 demo-v23/src/main/java/org/vaadin/miki/demo/providers/SuperCheckboxProvider.java create mode 100644 demo-v23/src/main/resources/SuperCheckbox.md create mode 100644 superfields/src/main/java/org/vaadin/miki/markers/HasLabelPositionable.java create mode 100644 superfields/src/main/java/org/vaadin/miki/markers/WithLabelPositionableMixin.java create mode 100644 superfields/src/main/java/org/vaadin/miki/shared/labels/LabelPosition.java create mode 100644 superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions-checkbox.css create mode 100644 superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions-grids.css create mode 100644 superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions.css diff --git a/README.md b/README.md index fdf38d6e..27304df4 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ This is the relevant dependency: org.vaadin.miki superfields - 0.14.1 + 0.15.0 ``` @@ -62,6 +62,7 @@ The author of the majority of the code is Miki, but this project would not be po * Jean-Christophe Gueriaud * Holger Hähnel * Matthias Hämmerle +* Jarmo Kemppainen * Gerald Koch * Sebastian Kühnau * Jean-François Lamy diff --git a/demo-v23/pom.xml b/demo-v23/pom.xml index 23b2bcbe..dbc1fbe6 100644 --- a/demo-v23/pom.xml +++ b/demo-v23/pom.xml @@ -4,11 +4,11 @@ superfields-parent org.vaadin.miki - 0.14.1 + 0.15.0 superfields-demo-v23 - 0.14.1 + 0.15.0 V23+ demo app for SuperFields Showcase application for V23+ and SuperFields. war @@ -23,7 +23,7 @@ org.vaadin.miki superfields - 0.14.1 + 0.15.0 javax.servlet diff --git a/demo-v23/src/main/java/org/vaadin/miki/demo/builders/HasPositionableLabelBuilder.java b/demo-v23/src/main/java/org/vaadin/miki/demo/builders/HasPositionableLabelBuilder.java new file mode 100644 index 00000000..6e972559 --- /dev/null +++ b/demo-v23/src/main/java/org/vaadin/miki/demo/builders/HasPositionableLabelBuilder.java @@ -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 { + @Override + public void buildContent(HasLabelPositionable component, Consumer callback) { + final ComboBox positions = new ComboBox<>("Pick label position:", LabelPosition.values()); + positions.setAllowCustomValue(false); + positions.addValueChangeListener(event -> component.setLabelPosition(event.getValue())); + callback.accept(new Component[]{positions}); + } +} diff --git a/demo-v23/src/main/java/org/vaadin/miki/demo/builders/ObjectFieldBuilder.java b/demo-v23/src/main/java/org/vaadin/miki/demo/builders/ObjectFieldBuilder.java index 293364b6..f43979ec 100644 --- a/demo-v23/src/main/java/org/vaadin/miki/demo/builders/ObjectFieldBuilder.java +++ b/demo-v23/src/main/java/org/vaadin/miki/demo/builders/ObjectFieldBuilder.java @@ -12,7 +12,7 @@ import java.time.LocalDate; import java.util.function.Consumer; -@Order(61) +@Order(1) public class ObjectFieldBuilder implements ContentBuilder> { @Override public void buildContent(ObjectField component, Consumer callback) { diff --git a/demo-v23/src/main/java/org/vaadin/miki/demo/builders/VariantFieldBuilder.java b/demo-v23/src/main/java/org/vaadin/miki/demo/builders/VariantFieldBuilder.java index cb33008b..a6dc02da 100644 --- a/demo-v23/src/main/java/org/vaadin/miki/demo/builders/VariantFieldBuilder.java +++ b/demo-v23/src/main/java/org/vaadin/miki/demo/builders/VariantFieldBuilder.java @@ -17,7 +17,7 @@ * @author miki * @since 2022-04-11 */ -@Order(80) +@Order(1) public class VariantFieldBuilder implements ContentBuilder { @Override diff --git a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/CollectionFieldProvider.java b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/CollectionFieldProvider.java index 9d355088..5dab04dc 100644 --- a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/CollectionFieldProvider.java +++ b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/CollectionFieldProvider.java @@ -32,7 +32,10 @@ public CollectionField> getComponent() { ), Collections.singletonList(CollectionComponentProviders.addLastButton("Add as last"))), CollectionComponentProviders.rowWithRemoveButtonFirst(CollectionComponentProviders.labelledField(SuperTextField::new, "Value"), "Remove") - ).withHelperText("(validator requires precisely three elements)"); + ) + .withHelperText("(validator requires precisely three elements)") + .withLabel("Enter some words:") + ; } @Override diff --git a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/GridMultiSelectProvider.java b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/GridMultiSelectProvider.java index aad3f05f..30da7b6f 100644 --- a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/GridMultiSelectProvider.java +++ b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/GridMultiSelectProvider.java @@ -15,7 +15,9 @@ public class GridMultiSelectProvider implements ComponentProvider getComponent() { final GridMultiSelect gridSelect = new GridMultiSelect<>(SuperFieldsGridItem.class, true, SuperFieldsGridItem.getAllRegisteredProviders()) - .withHelperText("(you can select multiple rows)"); + .withHelperText("(you can select multiple rows)") + .withLabel("Choose as many as you like:") + ; gridSelect.getGrid().getColumnByKey("nameLength").setAutoWidth(true); return gridSelect; } diff --git a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/GridSelectProvider.java b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/GridSelectProvider.java index adb6fdb3..18cd3468 100644 --- a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/GridSelectProvider.java +++ b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/GridSelectProvider.java @@ -15,7 +15,8 @@ public class GridSelectProvider implements ComponentProvider getComponent() { final GridSelect gridSelect = new GridSelect<>(SuperFieldsGridItem.class, true, SuperFieldsGridItem.getAllRegisteredProviders()) - .withHelperText("(at most one row can be selected)"); + .withHelperText("(at most one row can be selected)") + .withLabel("Please select your favourite component:"); gridSelect.getGrid().getColumnByKey("nameLength").setAutoWidth(true); return gridSelect; } diff --git a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/MapFieldProvider.java b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/MapFieldProvider.java index f036d80d..61b9b6fa 100644 --- a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/MapFieldProvider.java +++ b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/MapFieldProvider.java @@ -34,6 +34,8 @@ public MapField getComponent() { () -> new SuperTextField("Any text:"), () -> new SuperIntegerField("Any integer:") ), "Remove")) - .withHelperText("(this is a Map)"); + .withHelperText("(this is a Map)") + .withLabel("Please enter key-value data:") + ; } } diff --git a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/ObjectFieldProvider.java b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/ObjectFieldProvider.java index 68ea7d46..1a1296a3 100644 --- a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/ObjectFieldProvider.java +++ b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/ObjectFieldProvider.java @@ -36,7 +36,8 @@ public ObjectFieldProvider() { @Override public ObjectField getComponent() { return this.factory.buildAndConfigureObjectField(Book.class) - .withHelperText("(this field with all its components is automatically generated from a model class)") - .withHelperAbove(); + .withHelperText("(this entire form with all its components is automatically generated from a model class)") + .withLabel("Book details:") + ; } } diff --git a/demo-v23/src/main/java/org/vaadin/miki/demo/providers/SuperCheckboxProvider.java b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/SuperCheckboxProvider.java new file mode 100644 index 00000000..ecad6018 --- /dev/null +++ b/demo-v23/src/main/java/org/vaadin/miki/demo/providers/SuperCheckboxProvider.java @@ -0,0 +1,18 @@ +package org.vaadin.miki.demo.providers; + +import org.vaadin.miki.demo.ComponentProvider; +import org.vaadin.miki.demo.Order; +import org.vaadin.miki.superfields.checkbox.SuperCheckbox; + +/** + * Provides a fresh {@link SuperCheckbox}. + * @author miki + * @since 2022-09-15 + */ +@Order(99) +public class SuperCheckboxProvider implements ComponentProvider { + @Override + public SuperCheckbox getComponent() { + return new SuperCheckbox().withLabel("This component can be made read-only, contrary to the original Checkbox."); + } +} diff --git a/demo-v23/src/main/resources/SuperCheckbox.md b/demo-v23/src/main/resources/SuperCheckbox.md new file mode 100644 index 00000000..733d6de4 --- /dev/null +++ b/demo-v23/src/main/resources/SuperCheckbox.md @@ -0,0 +1 @@ +A fixed version of the regular `Checkbox` - can be set to read-only and can have a title. \ No newline at end of file diff --git a/pom.xml b/pom.xml index b481c6c1..59fb658d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.vaadin.miki superfields-parent - 0.14.1 + 0.15.0 superfields demo-v23 diff --git a/superfields/README.md b/superfields/README.md index d456a11a..2e374922 100644 --- a/superfields/README.md +++ b/superfields/README.md @@ -26,6 +26,10 @@ Some components contain server-side methods to control text selection in their w The web components listen to each key press and mouse click. If text selection changes as a result of that action, they send an event to the server-side component. This may happen quite often and increase server load, so the feature is turned off by default. To turn it on simply call `setReceivingSelectionEventsFromClient(true)` (or `withReceivingSelectionEventsFromClient(true)`). +#### Label position + +Most of the components that can have a label allow positioning said label through `setLabelPosition(...)` (or `withLabelPosition(...)`). This should work in most layouts, with `FormLayout` being an obvious exception. Not all components support all possible values of `LabelPosition` (`SuperCheckbox` ignores vertical alignment). In addition, things might work weird when using right-to-left languages - if that happens, please report the problem in GitHub. + #### Log messages Quite a few components log their state using [SLF4J](https://www.slf4j.org). Critical information is logged as error or warning, debugging messages are, well, debug or trace. Information about [how to configure which log messages get displayed can be found e.g. on Stack Overflow](https://stackoverflow.com/questions/45997759/how-to-change-slf4j-logging-level). diff --git a/superfields/pom.xml b/superfields/pom.xml index 2b08f9aa..c5af97f9 100644 --- a/superfields/pom.xml +++ b/superfields/pom.xml @@ -8,7 +8,7 @@ superfields SuperFields Code for various V14+ fields and other components. - 0.14.1 + 0.15.0 11 diff --git a/superfields/release-notes.md b/superfields/release-notes.md index 2984c935..f2371a4b 100644 --- a/superfields/release-notes.md +++ b/superfields/release-notes.md @@ -1,3 +1,12 @@ +# 0.15.0 - HasPositionableLabel +## New features and enhancements +* \#414 - [Positionable component labels](https://github.com/vaadin-miki/super-fields/issues/414) +## Changes to API +* \#412 - [SuperCheckbox should implement relevant marker interfaces](https://github.com/vaadin-miki/super-fields/issues/412) +* \#415 - [CollectionField and Grid(Multi)Select should implement HasLabel](https://github.com/vaadin-miki/super-fields/issues/415) +## Bug fixes +* \#415 - [CollectionField and Grid(Multi)Select should implement HasLabel](https://github.com/vaadin-miki/super-fields/issues/415) +* \#416 - [SuperCheckbox gets out of sync](https://github.com/vaadin-miki/super-fields/issues/416) # 0.14.1 - SuperCheckbox and bugfixes ## New features and enhancements * \#400 - [ObjectField should support enums and other values presentable with ComboBox](https://github.com/vaadin-miki/super-fields/issues/400) diff --git a/superfields/src/main/java/org/vaadin/miki/markers/HasLabelPositionable.java b/superfields/src/main/java/org/vaadin/miki/markers/HasLabelPositionable.java new file mode 100644 index 00000000..885040b8 --- /dev/null +++ b/superfields/src/main/java/org/vaadin/miki/markers/HasLabelPositionable.java @@ -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; + } + +} diff --git a/superfields/src/main/java/org/vaadin/miki/markers/WithLabelPositionableMixin.java b/superfields/src/main/java/org/vaadin/miki/markers/WithLabelPositionableMixin.java new file mode 100644 index 00000000..15b2d7d2 --- /dev/null +++ b/superfields/src/main/java/org/vaadin/miki/markers/WithLabelPositionableMixin.java @@ -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 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; + } +} diff --git a/superfields/src/main/java/org/vaadin/miki/shared/labels/LabelPosition.java b/superfields/src/main/java/org/vaadin/miki/shared/labels/LabelPosition.java new file mode 100644 index 00000000..15afacee --- /dev/null +++ b/superfields/src/main/java/org/vaadin/miki/shared/labels/LabelPosition.java @@ -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; + } +} diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/checkbox/SuperCheckbox.java b/superfields/src/main/java/org/vaadin/miki/superfields/checkbox/SuperCheckbox.java index b4194a20..bffd741e 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/checkbox/SuperCheckbox.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/checkbox/SuperCheckbox.java @@ -1,26 +1,59 @@ package org.vaadin.miki.superfields.checkbox; +import com.vaadin.flow.component.AbstractField; import com.vaadin.flow.component.checkbox.Checkbox; +import com.vaadin.flow.component.dependency.CssImport; +import org.vaadin.miki.markers.WithIdMixin; +import org.vaadin.miki.markers.WithLabelMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; +import org.vaadin.miki.markers.WithTitleMixin; +import org.vaadin.miki.markers.WithValueMixin; + +import java.util.Objects; /** - * A regular {@link Checkbox} that has its read-only state synchronised with enabledness. - * This exists purely as a workaround for a known issue of Vaadin. + * A regular {@link Checkbox} that can be made read-only (it becomes disabled when set to read-only). + * While this exists mostly as a workaround for a known issue of Vaadin, + * it also supports label position (though only {@link org.vaadin.miki.shared.labels.LabelPosition}{@code #BEFORE_*}, thus allowing + * the label to be positioned on the other side of the actual checkbox). * * @author miki * @since 2022-09-14 */ @SuppressWarnings("squid:S110") // no way around big number of parent classes -public class SuperCheckbox extends Checkbox { +@CssImport(value = "./styles/label-positions-checkbox.css", themeFor = "vaadin-checkbox") +public class SuperCheckbox extends Checkbox implements + WithLabelMixin, WithValueMixin, Boolean, SuperCheckbox>, + WithIdMixin, WithTitleMixin, WithLabelPositionableMixin { + + private boolean enabled = true; + private boolean readOnly = false; + + protected boolean isReallyEnabled() { + return this.enabled && !this.readOnly; + } @Override public void setReadOnly(boolean readOnly) { + this.readOnly = readOnly; super.setReadOnly(readOnly); - super.setEnabled(!readOnly); + super.setEnabled(this.isReallyEnabled()); } @Override public void setEnabled(boolean enabled) { - super.setReadOnly(!enabled); - super.setEnabled(enabled); + this.enabled = enabled; + super.setEnabled(this.isReallyEnabled()); } + + @Override + public void setTitle(String title) { + this.getElement().setProperty("title", Objects.requireNonNullElse(title, "")); + } + + @Override + public String getTitle() { + return Objects.requireNonNullElse(this.getElement().getProperty("title"), ""); + } + } diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/collections/CollectionField.java b/superfields/src/main/java/org/vaadin/miki/superfields/collections/CollectionField.java index bd25ee6a..8fc26dfe 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/collections/CollectionField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/collections/CollectionField.java @@ -7,6 +7,7 @@ import com.vaadin.flow.component.HasStyle; import com.vaadin.flow.component.HasValue; import com.vaadin.flow.component.customfield.CustomField; +import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.orderedlayout.FlexLayout; import com.vaadin.flow.function.SerializablePredicate; import com.vaadin.flow.function.SerializableSupplier; @@ -16,6 +17,8 @@ import org.vaadin.miki.markers.WithHelperMixin; import org.vaadin.miki.markers.WithHelperPositionableMixin; import org.vaadin.miki.markers.WithIdMixin; +import org.vaadin.miki.markers.WithLabelMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithValueMixin; import java.util.ArrayList; @@ -33,12 +36,14 @@ * @param Type of the element in the collection. * @param Type of the collection. */ +@CssImport(value = "./styles/label-positions.css", themeFor = "vaadin-custom-field") public class CollectionField> extends CustomField implements CollectionController, WithIdMixin>, HasStyle, WithCollectionValueComponentProviderMixin>, WithHelperMixin>, WithHelperPositionableMixin>, WithValueMixin, C>, C, CollectionField>, - WithCollectionElementFilterMixin> { + WithCollectionElementFilterMixin>, + WithLabelPositionableMixin>, WithLabelMixin> { /** * CSS class name that will be added to the main layout of this component. diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/collections/MapField.java b/superfields/src/main/java/org/vaadin/miki/superfields/collections/MapField.java index d5971532..bc6dd87f 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/collections/MapField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/collections/MapField.java @@ -6,12 +6,14 @@ import com.vaadin.flow.component.HasStyle; import com.vaadin.flow.component.HasValue; import com.vaadin.flow.component.customfield.CustomField; +import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.function.SerializablePredicate; import com.vaadin.flow.function.SerializableSupplier; import org.vaadin.miki.markers.WithHelperMixin; import org.vaadin.miki.markers.WithHelperPositionableMixin; import org.vaadin.miki.markers.WithIdMixin; import org.vaadin.miki.markers.WithLabelMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithValueMixin; import org.vaadin.miki.superfields.layouts.FlexLayoutHelpers; @@ -33,11 +35,13 @@ * @author miki * @since 2022-04-08 */ +@CssImport(value = "./styles/label-positions.css", themeFor = "vaadin-custom-field") public class MapField extends CustomField> implements HasStyle, WithIdMixin>, WithValueMixin>, Map>, Map, MapField>, WithHelperPositionableMixin>, WithHelperMixin>, WithLabelMixin>, WithCollectionValueComponentProviderMixin, MapField>, - WithCollectionElementFilterMixin, MapField> { + WithCollectionElementFilterMixin, MapField>, + WithLabelPositionableMixin> { /** * Produces a non-null entry filter (entry, its key and its value must be non-{@code null}). diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/dates/SuperDatePicker.java b/superfields/src/main/java/org/vaadin/miki/superfields/dates/SuperDatePicker.java index ee1f3260..1717f1b4 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/dates/SuperDatePicker.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/dates/SuperDatePicker.java @@ -6,6 +6,7 @@ import com.vaadin.flow.component.DetachEvent; import com.vaadin.flow.component.Tag; import com.vaadin.flow.component.datepicker.DatePicker; +import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.dependency.JsModule; import com.vaadin.flow.shared.Registration; import org.vaadin.miki.events.text.TextSelectionListener; @@ -19,6 +20,7 @@ import org.vaadin.miki.markers.WithLabelMixin; import org.vaadin.miki.markers.WithLocaleMixin; import org.vaadin.miki.markers.WithPlaceholderMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithReceivingSelectionEventsFromClientMixin; import org.vaadin.miki.markers.WithRequiredMixin; import org.vaadin.miki.markers.WithTitleMixin; @@ -39,10 +41,11 @@ */ @JsModule("./super-date-picker.js") @Tag("super-date-picker") +@CssImport(value = "./styles/label-positions.css", themeFor = "super-date-picker") @SuppressWarnings("squid:S110") // there is no way to reduce the number of parent classes public class SuperDatePicker extends DatePicker implements CanSelectText, CanReceiveSelectionEventsFromClient, WithReceivingSelectionEventsFromClientMixin, - TextSelectionNotifier, HasSuperDatePickerI18N, + TextSelectionNotifier, HasSuperDatePickerI18N, WithLabelPositionableMixin, WithLocaleMixin, WithLabelMixin, WithTitleMixin, WithPlaceholderMixin, WithDatePatternMixin, WithValueMixin, LocalDate, SuperDatePicker>, diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/dates/SuperDateTimePicker.java b/superfields/src/main/java/org/vaadin/miki/superfields/dates/SuperDateTimePicker.java index 46f672ef..7cc77572 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/dates/SuperDateTimePicker.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/dates/SuperDateTimePicker.java @@ -4,6 +4,7 @@ import com.vaadin.flow.component.Tag; import com.vaadin.flow.component.datepicker.DatePicker; import com.vaadin.flow.component.datetimepicker.DateTimePicker; +import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.dependency.JsModule; import com.vaadin.flow.component.timepicker.TimePicker; import org.vaadin.miki.markers.WithDatePatternMixin; @@ -12,6 +13,7 @@ import org.vaadin.miki.markers.WithIdMixin; import org.vaadin.miki.markers.WithLabelMixin; import org.vaadin.miki.markers.WithLocaleMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithValueMixin; import org.vaadin.miki.shared.dates.DatePattern; import org.vaadin.miki.util.ReflectTools; @@ -27,9 +29,10 @@ */ @JsModule("./super-date-time-picker.js") @Tag("super-date-time-picker") +@CssImport(value = "./styles/label-positions.css", themeFor = "super-date-time-picker") @SuppressWarnings("squid:S110") // there is no way to reduce the number of parent classes public class SuperDateTimePicker extends DateTimePicker - implements HasSuperDatePickerI18N, + implements HasSuperDatePickerI18N, WithLabelPositionableMixin, WithLocaleMixin, WithLabelMixin, WithDatePatternMixin, WithIdMixin, WithValueMixin, LocalDateTime, SuperDateTimePicker>, diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/AbstractGridSelect.java b/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/AbstractGridSelect.java index bea81635..14859b61 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/AbstractGridSelect.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/AbstractGridSelect.java @@ -1,6 +1,7 @@ package org.vaadin.miki.superfields.gridselect; import com.vaadin.flow.component.customfield.CustomField; +import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.data.selection.SelectionEvent; @@ -11,6 +12,8 @@ * @author miki * @since 2020-12-09 */ +@CssImport(value = "./styles/label-positions.css", themeFor = "vaadin-custom-field") +@CssImport(value = "./styles/label-positions-grids.css", themeFor = "vaadin-custom-field") public abstract class AbstractGridSelect extends CustomField { private final Grid grid; diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/GridMultiSelect.java b/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/GridMultiSelect.java index af8bd1a0..5381f2b4 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/GridMultiSelect.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/GridMultiSelect.java @@ -9,7 +9,9 @@ import org.vaadin.miki.markers.WithHelperPositionableMixin; import org.vaadin.miki.markers.WithIdMixin; import org.vaadin.miki.markers.WithItemsMixin; +import org.vaadin.miki.markers.WithLabelMixin; import org.vaadin.miki.markers.WithMaximumSelectionSizeMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithValueMixin; import java.util.Collection; @@ -25,7 +27,8 @@ public class GridMultiSelect extends AbstractGridSelect> implements WithIdMixin>, WithItemsMixin>, WithMaximumSelectionSizeMixin>, WithHelperMixin>, - WithHelperPositionableMixin>, + WithHelperPositionableMixin>, WithLabelPositionableMixin>, + WithLabelMixin>, WithValueMixin>, Set>, Set, GridMultiSelect> { private int maximumSelectionSize = UNLIMITED; diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/GridSelect.java b/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/GridSelect.java index 54f1c4ea..48ab035b 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/GridSelect.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/gridselect/GridSelect.java @@ -7,6 +7,8 @@ import org.vaadin.miki.markers.WithHelperPositionableMixin; import org.vaadin.miki.markers.WithIdMixin; import org.vaadin.miki.markers.WithItemsMixin; +import org.vaadin.miki.markers.WithLabelMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithValueMixin; import java.util.Collection; @@ -20,7 +22,8 @@ */ public class GridSelect extends AbstractGridSelect implements WithIdMixin>, WithItemsMixin>, WithHelperMixin>, - WithHelperPositionableMixin>, + WithHelperPositionableMixin>, WithLabelMixin>, + WithLabelPositionableMixin>, WithValueMixin, V>, V, GridSelect> { /** diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/numbers/AbstractSuperNumberField.java b/superfields/src/main/java/org/vaadin/miki/superfields/numbers/AbstractSuperNumberField.java index 34ed4be2..2bbcc5b8 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/numbers/AbstractSuperNumberField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/numbers/AbstractSuperNumberField.java @@ -27,6 +27,7 @@ import org.vaadin.miki.markers.WithHelperPositionableMixin; import org.vaadin.miki.markers.WithIdMixin; import org.vaadin.miki.markers.WithLabelMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithLocaleMixin; import org.vaadin.miki.markers.WithNullValueOptionallyAllowedMixin; import org.vaadin.miki.markers.WithPlaceholderMixin; @@ -34,6 +35,7 @@ import org.vaadin.miki.markers.WithRequiredMixin; import org.vaadin.miki.markers.WithTitleMixin; import org.vaadin.miki.markers.WithValueMixin; +import org.vaadin.miki.shared.labels.LabelPosition; import org.vaadin.miki.superfields.text.SuperTextField; import java.text.DecimalFormat; @@ -51,6 +53,7 @@ * @since 2020-04-07 */ @CssImport("./styles/form-layout-number-field-styles.css") +//@CssImport(value = "./styles/label-positions.css", themeFor = "super-text-field") @SuppressWarnings("squid:S119") // SELF is a perfectly fine generic name that indicates its purpose public abstract class AbstractSuperNumberField> extends CustomField @@ -60,7 +63,7 @@ public abstract class AbstractSuperNumberField, T>, T, SELF>, WithIdMixin, WithNullValueOptionallyAllowedMixin, T>, T>, WithHelperMixin, WithHelperPositionableMixin, WithClearButtonMixin, - WithRequiredMixin { + WithRequiredMixin, WithLabelPositionableMixin { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSuperNumberField.class); @@ -868,6 +871,16 @@ public boolean isRequired() { return this.field.isRequired(); } + @Override + public void setLabelPosition(LabelPosition position) { + this.field.setLabelPosition(position); + } + + @Override + public LabelPosition getLabelPosition() { + return this.field.getLabelPosition(); + } + /** * Explicitly invokes code that would otherwise be called when the component receives focus. * For testing purposes only. diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/object/ObjectField.java b/superfields/src/main/java/org/vaadin/miki/superfields/object/ObjectField.java index 995e714c..5d81621a 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/object/ObjectField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/object/ObjectField.java @@ -7,6 +7,7 @@ import com.vaadin.flow.component.HasStyle; import com.vaadin.flow.component.HasValue; import com.vaadin.flow.component.customfield.CustomField; +import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.orderedlayout.FlexLayout; import com.vaadin.flow.function.SerializableSupplier; import org.slf4j.Logger; @@ -16,6 +17,7 @@ import org.vaadin.miki.markers.WithHelperPositionableMixin; import org.vaadin.miki.markers.WithIdMixin; import org.vaadin.miki.markers.WithLabelMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithValueMixin; import org.vaadin.miki.superfields.layouts.FlexLayoutHelpers; import org.vaadin.miki.superfields.object.builder.SimplePropertyComponentBuilder; @@ -48,9 +50,10 @@ * @author miki * @since 2022-05-16 */ +@CssImport(value = "./styles/label-positions.css", themeFor = "vaadin-custom-field") public class ObjectField extends CustomField implements HasStyle, WithHelperMixin>, WithHelperPositionableMixin>, - WithIdMixin>, WithLabelMixin>, + WithIdMixin>, WithLabelMixin>, WithLabelPositionableMixin>, WithValueMixin, T>, T, ObjectField> { public static final SerializableSupplier DEFAULT_LAYOUT_PROVIDER = FlexLayoutHelpers::column; diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/text/LabelField.java b/superfields/src/main/java/org/vaadin/miki/superfields/text/LabelField.java index 1e7fe461..11741326 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/text/LabelField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/text/LabelField.java @@ -4,10 +4,13 @@ import com.vaadin.flow.component.HasStyle; import com.vaadin.flow.component.Text; import com.vaadin.flow.component.customfield.CustomField; +import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.function.SerializableFunction; import org.vaadin.miki.markers.WithHelperMixin; import org.vaadin.miki.markers.WithHelperPositionableMixin; +import org.vaadin.miki.markers.WithIdMixin; import org.vaadin.miki.markers.WithLabelMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithValueMixin; /** @@ -19,8 +22,10 @@ * @author miki * @since 2022-04-08 */ +@CssImport(value = "./styles/label-positions.css", themeFor = "vaadin-custom-field") public class LabelField extends CustomField implements HasStyle, WithLabelMixin>, WithHelperPositionableMixin>, WithHelperMixin>, + WithLabelPositionableMixin>, WithIdMixin>, WithValueMixin, V>, V, LabelField> { public static final String DEFAULT_NULL_REPRESENTATION = ""; diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextArea.java b/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextArea.java index 18442c02..b6390e0c 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextArea.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextArea.java @@ -5,6 +5,7 @@ import com.vaadin.flow.component.ClientCallable; import com.vaadin.flow.component.DetachEvent; import com.vaadin.flow.component.Tag; +import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.dependency.JsModule; import com.vaadin.flow.component.textfield.TextArea; import com.vaadin.flow.shared.Registration; @@ -18,6 +19,7 @@ import org.vaadin.miki.markers.WithIdMixin; import org.vaadin.miki.markers.WithLabelMixin; import org.vaadin.miki.markers.WithPlaceholderMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithReceivingSelectionEventsFromClientMixin; import org.vaadin.miki.markers.WithRequiredMixin; import org.vaadin.miki.markers.WithTitleMixin; @@ -33,9 +35,10 @@ */ @Tag("super-text-area") @JsModule("./super-text-area.js") +@CssImport(value = "./styles/label-positions.css", themeFor = "super-text-area") @SuppressWarnings("squid:S110") // there is no way to reduce the number of parent classes public class SuperTextArea extends TextArea implements CanSelectText, TextSelectionNotifier, - CanModifyText, WithRequiredMixin, + CanModifyText, WithRequiredMixin, WithLabelPositionableMixin, WithIdMixin, WithLabelMixin, WithPlaceholderMixin, WithReceivingSelectionEventsFromClientMixin, WithClearButtonMixin, WithHelperMixin, WithHelperPositionableMixin, WithTitleMixin, diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextField.java b/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextField.java index ae901f8d..b1e4b01a 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/text/SuperTextField.java @@ -5,6 +5,7 @@ import com.vaadin.flow.component.ClientCallable; import com.vaadin.flow.component.DetachEvent; import com.vaadin.flow.component.Tag; +import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.dependency.JsModule; import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.shared.Registration; @@ -18,6 +19,7 @@ import org.vaadin.miki.markers.WithIdMixin; import org.vaadin.miki.markers.WithLabelMixin; import org.vaadin.miki.markers.WithPlaceholderMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithReceivingSelectionEventsFromClientMixin; import org.vaadin.miki.markers.WithRequiredMixin; import org.vaadin.miki.markers.WithTitleMixin; @@ -31,9 +33,10 @@ */ @Tag("super-text-field") @JsModule("./super-text-field.js") +@CssImport(value = "./styles/label-positions.css", themeFor = "super-text-field") @SuppressWarnings("squid:S110") // there is no way to reduce the number of parent classes public class SuperTextField extends TextField implements CanSelectText, TextSelectionNotifier, - CanModifyText, WithRequiredMixin, + CanModifyText, WithRequiredMixin, WithLabelPositionableMixin, WithIdMixin, WithLabelMixin, WithPlaceholderMixin, WithValueMixin, String, SuperTextField>, WithHelperMixin, WithTitleMixin, WithHelperPositionableMixin, @@ -135,4 +138,5 @@ public void setClearButtonVisible(boolean clearButtonVisible) { public boolean isClearButtonVisible() { return super.isClearButtonVisible(); } + } diff --git a/superfields/src/main/java/org/vaadin/miki/superfields/variant/VariantField.java b/superfields/src/main/java/org/vaadin/miki/superfields/variant/VariantField.java index 14ddbcfb..a34d1954 100644 --- a/superfields/src/main/java/org/vaadin/miki/superfields/variant/VariantField.java +++ b/superfields/src/main/java/org/vaadin/miki/superfields/variant/VariantField.java @@ -5,11 +5,13 @@ import com.vaadin.flow.component.HasStyle; import com.vaadin.flow.component.HasValue; import com.vaadin.flow.component.customfield.CustomField; +import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.function.SerializableSupplier; import org.vaadin.miki.markers.WithHelperMixin; import org.vaadin.miki.markers.WithHelperPositionableMixin; import org.vaadin.miki.markers.WithIdMixin; import org.vaadin.miki.markers.WithLabelMixin; +import org.vaadin.miki.markers.WithLabelPositionableMixin; import org.vaadin.miki.markers.WithValueMixin; import org.vaadin.miki.superfields.text.LabelField; import org.vaadin.miki.util.ComponentTools; @@ -25,10 +27,12 @@ * @author miki * @since 2022-04-11 */ -public class VariantField extends CustomField implements HasStyle, WithLabelMixin, +@CssImport(value = "./styles/label-positions.css", themeFor = "vaadin-custom-field") +public class VariantField extends CustomField implements HasStyle, + WithLabelMixin, WithHelperMixin, WithHelperPositionableMixin, WithValueMixin, Object>, Object, VariantField>, - WithIdMixin { + WithIdMixin, WithLabelPositionableMixin { public static final SerializableSupplier DEFAULT_NULL_COMPONENT_PROVIDER = LabelField::new; diff --git a/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions-checkbox.css b/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions-checkbox.css new file mode 100644 index 00000000..a6937bdc --- /dev/null +++ b/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions-checkbox.css @@ -0,0 +1,7 @@ +:host([data-label-position-details~="before"]) [class|="vaadin"] [part="label"] { + order: 1; +} + +:host([data-label-position-details~="before"]) [class|="vaadin"] .vaadin-checkbox-wrapper { + order: 2; +} diff --git a/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions-grids.css b/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions-grids.css new file mode 100644 index 00000000..5f06c54e --- /dev/null +++ b/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions-grids.css @@ -0,0 +1,7 @@ +:host([data-label-position-details~="side"]) [class|="vaadin"] .inputs-wrapper { + flex: auto; +} + +:host([data-label-position-details~="after"]) [class|="vaadin"] .inputs-wrapper { + order: -1; +} diff --git a/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions.css b/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions.css new file mode 100644 index 00000000..cfada9a1 --- /dev/null +++ b/superfields/src/main/resources/META-INF/resources/frontend/styles/label-positions.css @@ -0,0 +1,58 @@ +/* css magic by Jarmo Kemppainen */ + +:host([data-label-position-details~="side"])::before { + height: 100%; +} + +:host([data-label-position-details~="side"]) [class|="vaadin"] { + width: 100%; + flex-wrap: wrap; + flex-direction: initial !important; + align-items: center; +} + +:host([data-label-position-details~="side"]) [class|="vaadin"] [part="label"] { + width: auto; + height: var(--lumo-text-field-size); +} + +:host([data-label-position-details~="middle"]) [class|="vaadin"] [part="label"] { + display: flex; + align-self: center; + align-items: center; + padding-bottom: 0; +} + +:host([data-label-position-details~="end"]) [class|="vaadin"] [part="label"] { + display: flex; + align-self: end; + align-items: end; + /* there must be default padding, otherwise the text renders incompletely */ +} + +:host([data-label-position-details~="side"]) [class|="vaadin"] [part="input-field"] { + /* flex: 1; */ +} + +:host([data-label-position-details~="side"]) [class|="vaadin"] [part="helper-text"], +:host([data-label-position-details~="side"]) [class|="vaadin"] [part="error-message"] { + width: 100%; +} + +:host([data-label-position-details~="after"]) [class|="vaadin"] [part="input-field"] { + order: -1; +} +:host([data-label-position-details~="after"][theme~="helper-above-field"]) [class|="vaadin"] [part="helper-text"] { + order: -2; +} + +:host([data-label-position-details~="before"][theme~="helper-above-field"]) [class|="vaadin"] [part="label"] { + order: 1; +} +:host([data-label-position-details~="before"][theme~="helper-above-field"]) [class|="vaadin"] [part="helper-text"] { + order: 0; +} + +:host([data-label-position-details~="last"]) [class|="vaadin"] [part="label"] { + order: 9; +} diff --git a/superfields/src/test/java/org/vaadin/miki/superfields/checkbox/SuperCheckboxTest.java b/superfields/src/test/java/org/vaadin/miki/superfields/checkbox/SuperCheckboxTest.java index ca592b62..8d2495a7 100644 --- a/superfields/src/test/java/org/vaadin/miki/superfields/checkbox/SuperCheckboxTest.java +++ b/superfields/src/test/java/org/vaadin/miki/superfields/checkbox/SuperCheckboxTest.java @@ -23,9 +23,34 @@ public void teardown() { @Test public void testReadOnlyAndEnabled() { + // on start, component is both enabled and not read-only + Assert.assertTrue(this.checkbox.isEnabled()); + Assert.assertFalse(this.checkbox.isReadOnly()); + // mark read-only, it should disable component + this.checkbox.setReadOnly(true); + Assert.assertFalse(this.checkbox.isEnabled()); + Assert.assertTrue(this.checkbox.isReadOnly()); + // this must fail, as the component must be both enabled AND not read-only + this.checkbox.setEnabled(true); + Assert.assertFalse(this.checkbox.isEnabled()); + Assert.assertTrue(this.checkbox.isReadOnly()); + // now it should be enabled + this.checkbox.setReadOnly(false); + Assert.assertTrue(this.checkbox.isEnabled()); + Assert.assertFalse(this.checkbox.isReadOnly()); + // disable + this.checkbox.setEnabled(false); + Assert.assertFalse(this.checkbox.isEnabled()); + Assert.assertFalse(this.checkbox.isReadOnly()); + // make read-only this.checkbox.setReadOnly(true); + Assert.assertFalse(this.checkbox.isEnabled()); Assert.assertTrue(this.checkbox.isReadOnly()); + // make not read-only, still disabled (because enabled was set to false) + this.checkbox.setReadOnly(false); Assert.assertFalse(this.checkbox.isEnabled()); + Assert.assertFalse(this.checkbox.isReadOnly()); + // finally, enable this.checkbox.setEnabled(true); Assert.assertTrue(this.checkbox.isEnabled()); Assert.assertFalse(this.checkbox.isReadOnly());