Skip to content

Commit

Permalink
feat: add method to set full height to image
Browse files Browse the repository at this point in the history
Close #5
  • Loading branch information
paodb committed Nov 4, 2024
1 parent f88c893 commit 5d6e5a7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/main/resources/META-INF/frontend/styles/image-crop-styles.css
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 5d6e5a7

Please sign in to comment.