From 5d6e5a7d552fd8af1dd5c04d65755e39dede3255 Mon Sep 17 00:00:00 2001 From: Paola De Bartolo Date: Mon, 4 Nov 2024 16:22:03 -0300 Subject: [PATCH] feat: add method to set full height to image Close #5 --- .../vaadin/addons/imagecrop/ImageCrop.java | 18 +++++++++++++++ .../frontend/styles/image-crop-styles.css | 23 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/main/resources/META-INF/frontend/styles/image-crop-styles.css diff --git a/src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java b/src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java index e990585..8ec08a4 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java +++ b/src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java @@ -46,7 +46,10 @@ @JsModule("./src/image-crop.tsx") @Tag("image-crop") @CssImport("react-image-crop/dist/ReactCrop.css") +@CssImport("./styles/image-crop-styles.css") public class ImageCrop extends ReactAdapterComponent { + + private static final String IMG_FULL_HEIGHT_CLASS_NAME = "img-full-height"; private String croppedImageDataUri; @@ -341,6 +344,21 @@ public String getCroppedImageDataUri() { return this.croppedImageDataUri; } + /** + * Sets the image to occupy the full viewport height when enabled. + * If {@code fullHeight} is {@code true}, applies a CSS class that + * sets the image height to 100vh. If {@code false}, removes the class + * to revert to the default height. + * + * @param fullHeight whether the image should fill the viewport height + */ + public void setImageFullHeight(Boolean fullHeight) { + if (fullHeight) + this.addClassName(IMG_FULL_HEIGHT_CLASS_NAME); + else + this.removeClassName(IMG_FULL_HEIGHT_CLASS_NAME); + } + /** * Decodes the cropped image data URI and returns it as a byte array. If the image data URI is not * in the format "data:image/*;base64,", it will be decoded assuming it is a Base64 encoded diff --git a/src/main/resources/META-INF/frontend/styles/image-crop-styles.css b/src/main/resources/META-INF/frontend/styles/image-crop-styles.css new file mode 100644 index 0000000..e455f43 --- /dev/null +++ b/src/main/resources/META-INF/frontend/styles/image-crop-styles.css @@ -0,0 +1,23 @@ +/*- + * #%L + * Image Crop Add-on + * %% + * Copyright (C) 2024 Flowing Code + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +.img-full-height img { + height: 100vh; +}; \ No newline at end of file