Skip to content

Commit bc67e9c

Browse files
authored
Merge pull request #6 from FlowingCode/issue-5
Add method to set full height to image
2 parents c5446f9 + 4e10791 commit bc67e9c

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.flowingcode.vaadin.addons</groupId>
66
<artifactId>image-crop-addon</artifactId>
7-
<version>1.0.1-SNAPSHOT</version>
7+
<version>1.1.0-SNAPSHOT</version>
88
<name>Image Crop Add-on</name>
99
<description>Image Crop Add-on for Vaadin Flow</description>
1010
<url>https://www.flowingcode.com/en/open-source/</url>

src/main/java/com/flowingcode/vaadin/addons/imagecrop/ImageCrop.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
@JsModule("./src/image-crop.tsx")
4747
@Tag("image-crop")
4848
@CssImport("react-image-crop/dist/ReactCrop.css")
49+
@CssImport("./styles/image-crop-styles.css")
4950
public class ImageCrop extends ReactAdapterComponent {
51+
52+
private static final String IMG_FULL_HEIGHT_CLASS_NAME = "img-full-height";
5053

5154
private String croppedImageDataUri;
5255

@@ -341,6 +344,21 @@ public String getCroppedImageDataUri() {
341344
return this.croppedImageDataUri;
342345
}
343346

347+
/**
348+
* Sets the image to occupy the full viewport height when enabled.
349+
* If {@code fullHeight} is {@code true}, applies a CSS class that
350+
* sets the image height to 100vh. If {@code false}, removes the class
351+
* to revert to the default height.
352+
*
353+
* @param fullHeight whether the image should fill the viewport height
354+
*/
355+
public void setImageFullHeight(Boolean fullHeight) {
356+
if (fullHeight)
357+
this.addClassName(IMG_FULL_HEIGHT_CLASS_NAME);
358+
else
359+
this.removeClassName(IMG_FULL_HEIGHT_CLASS_NAME);
360+
}
361+
344362
/**
345363
* Decodes the cropped image data URI and returns it as a byte array. If the image data URI is not
346364
* in the format "data:image/*;base64,", it will be decoded assuming it is a Base64 encoded
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*-
2+
* #%L
3+
* Image Crop Add-on
4+
* %%
5+
* Copyright (C) 2024 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
21+
.img-full-height img {
22+
height: 100vh;
23+
};

0 commit comments

Comments
 (0)