-
Notifications
You must be signed in to change notification settings - Fork 31
Feat/image-upload-component #3654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 87 commits
Commits
Show all changes
103 commits
Select commit
Hold shift + click to select a range
fda2780
Image upload component wip
Magnusrm 6d64978
update cropping component
Magnusrm aefafc0
add circle config
Magnusrm 35af5c2
move eventlisteners to canvas
Magnusrm 7f3fe76
explicit use of constrainToArea
Magnusrm daf3f37
further refactor image upload component
Magnusrm 12e2bca
add common utils for draw and handlecrop functions + variable viewpor…
lassopicasso f78e84d
add common utils for draw and handlecrop functions + variable viewpor…
lassopicasso 530b1a1
extract functions to utils (#3663)
Magnusrm 7e6c115
implement cropAsConfig prop into viewport config (#3662)
lassopicasso 741579f
prevent scrolling (#3658)
lassopicasso d15cc89
Feat/refine image upload buttons according to design (#3660)
lassopicasso 211edd7
Move the image cropper into a card (#3665)
Magnusrm 6602e9c
clean up css and style closer to figma design (#3669)
Magnusrm a82fe47
added save and cancel buttons with functionality (some left for save …
lassopicasso c336050
Redesign slider + buttons in img controller (#3671)
lassopicasso 658e9fd
Extract canvas and effects into its own component (#3674)
Magnusrm bcaf56f
feat/ handle saved image and new display when image is saved (#3675)
lassopicasso 6b65f5c
add check at higher level for stored image (#3680)
lassopicasso 420fc34
zoom to the center of viewport (#3681)
lassopicasso 38a6ada
Feat/custom crop area config + renaming (#3682)
lassopicasso a115242
Feat/remove-dropzone-icon-and-change-background (#3679)
Magnusrm 1629e7f
fix zooming limits (#3684)
lassopicasso 0d8477f
fix: active pointer canvas and keyboard support on change image (#3683)
lassopicasso 7d33561
update icons
Magnusrm 821e4d1
Add validationmessages for imageupload size and types (#3687)
Magnusrm 805df2f
Feat/use-language-for-component-texts (#3689)
Magnusrm 24da4ac
Display uploaded image+more (#3690)
lassopicasso 5976437
refactor: calculations (#3697)
lassopicasso fbb9514
feat: Support config (#3700)
lassopicasso 38db36c
small adjustment
lassopicasso b57f83c
change config from one object to 3 props
lassopicasso acedcd9
Merge remote-tracking branch 'origin/main' into feat/image-upload-com…
Magnusrm 2484b05
New dropzone using the new figma design (#3708)
Magnusrm abb0710
clean up comment, fix text-alignment
Magnusrm 97d9977
remove redundant css class
Magnusrm ed86243
fix cropped preview
Magnusrm 26b53c9
feat: Handle canvas size based on grid or mobile viewport and use fil…
lassopicasso 1681b0a
add unit tests and fix validation (#3714)
lassopicasso c0c0cb8
Add displaydata expression test to ImageUpload (#3719)
Magnusrm 0e685d9
adjust to equal height and width if circle and they are uneven
lassopicasso cfd3a11
fix duplicate ids and use ref instead of getElementById
Magnusrm ee0aab3
clean up css
Magnusrm 76e1893
fix sizing
lassopicasso 1f948f4
Merge branch 'feat/image-upload-component' of https://github.com/Alti…
lassopicasso be47527
use unique id, remove preventDefault for dropzone
Magnusrm 753184f
remove a type-casting
Magnusrm e9aa62a
add accesible title to reset zoom button
Magnusrm f7958fe
remove redundant css
Magnusrm 0a02587
fix change image button
Magnusrm 6f79243
add cypress tests for image upload component (#3721)
Magnusrm ae76f44
make filetypes the same
Magnusrm 99a3dc6
make filetypes match
Magnusrm 0c15edf
support summary2 (#3725)
lassopicasso 825d32c
support validFileEndings config
lassopicasso edf4926
merge
lassopicasso 4065306
replace chess background when image is saved
lassopicasso 715a1b4
fix edge case where canvas gets too low between 1160-1200px when grid…
lassopicasso 4afbe86
simplify responsivness and keep fixed size of the canvas
lassopicasso dc21ba9
set min zoom as default
lassopicasso d57d892
remove error message when save
lassopicasso b6e0b1e
add tests for imageupload in summary2
lassopicasso e683284
reverse validfileendings config support
lassopicasso 8d6ac3d
add cypress test where replacing image
lassopicasso 3823a85
react recommendations
lassopicasso 0294604
add utility tests
lassopicasso 51d8654
Merge branch 'main' into feat/image-upload-component
lassopicasso 221082c
remove some comments
lassopicasso 20c479c
add specific image types to be allowed
lassopicasso 019ea8f
small adjustment
lassopicasso d0993c6
new summary of image upload, show image
lassopicasso 8e526e7
some text changes
lassopicasso 5be3187
update tests for new summary of image upload
lassopicasso 057189a
check for possible animation file type and inform user that only firs…
lassopicasso 5f0dbcf
support readOnly config
lassopicasso 1d068cd
fix test
lassopicasso 50f6b68
rabbit feedback
lassopicasso 089711e
rename config from square to rectangle
lassopicasso 1b4d5ee
make useFileUploaderDataBindingsValidation support ImageUpload as well
lassopicasso f391958
Better error message for imageUpload is not supported in summary comp…
lassopicasso 8812b14
check that allowedContentTypes in app meta data is valid when renderi…
lassopicasso f87e83b
remove emojis in css comments
lassopicasso bea697c
move logic out of jsx into a function
lassopicasso 21b54b6
rename css class
lassopicasso 6f05f4f
text resource to aria-label
lassopicasso 2ba154b
move existing canvas files into own folder
lassopicasso 07bce70
refactor image canvas
lassopicasso 8f8ea3d
move zoom calculation to a utility helper
lassopicasso acbff84
refactor imageCropper
lassopicasso 989605c
--ds-color-neutral-background-tinted
lassopicasso ef2d89f
adjust zoom behavior
lassopicasso 9b4d104
reverse change in fileTable, not needed anymore
lassopicasso 7abe4a3
update config to use oneOf and update code related to this
lassopicasso f6fbc62
rabbit feedback - ensure draw after image is completly uploaded to br…
lassopicasso fcc8025
rabbit feedback - !!readOnly is redudant - keep only readOnly
lassopicasso 7e76bb9
rabbit feedback - ensure better quality on saved image with imageSmoo…
lassopicasso 1815734
rabbit feedback - not necessary, but adding a fallback to imageType
lassopicasso 598e658
move useImageFile to hooks folder
lassopicasso f9f167c
move imageUploadSummary2 into a folder
lassopicasso 7dfb383
rabbit feedback - naming type
lassopicasso 89090a7
small adjustment
lassopicasso 2c4bca6
Merge branch 'main' into feat/image-upload-component
lassopicasso edd47c6
adjust the size of slider
lassopicasso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.mediaCard { | ||
padding: 0; | ||
margin-bottom: -7px; | ||
} | ||
.mediaCard img { | ||
object-fit: cover; | ||
|
This file contains hidden or 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 hidden or 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
42 changes: 42 additions & 0 deletions
42
src/features/expressions/shared-tests/functions/displayValue/type-ImageUpload.json
This file contains hidden or 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,42 @@ | ||
{ | ||
"name": "Display value of FileUpload component", | ||
"expression": [ | ||
"displayValue", | ||
"image" | ||
], | ||
"context": { | ||
"component": "image", | ||
"currentLayout": "Page" | ||
}, | ||
"expects": "my-image.jpg", | ||
"layouts": { | ||
"Page": { | ||
"$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", | ||
"data": { | ||
"layout": [ | ||
{ | ||
"id": "image", | ||
"type": "ImageUpload" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"instanceDataElements": [ | ||
{ | ||
"id": "bb2b2222-2b22-2b22-222b-222222222222", | ||
"instanceGuid": "aa1a1111-1a11-1a11-111a-111111111111", | ||
"dataType": "image", | ||
"filename": "my-image.jpg", | ||
"contentType": "image/jpeg", | ||
"blobStoragePath": "", | ||
"size": 100, | ||
"locked": false, | ||
"refs": [], | ||
"created": "2021-01-01T00:00:00.000Z", | ||
"createdBy": "testUser", | ||
"lastChanged": "2021-01-01T00:00:00.000Z", | ||
"lastChangedBy": "testUser" | ||
} | ||
] | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -11,3 +11,7 @@ video { | |
.cardMedia:last-of-type { | ||
margin-top: auto; | ||
} | ||
|
||
.mediaCard { | ||
margin-bottom: -7px; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
.canvas { | ||
display: block; | ||
position: relative; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
cursor: grab; | ||
touch-action: none; | ||
} | ||
|
||
.canvas:active { | ||
cursor: grabbing; | ||
} |
This file contains hidden or 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,65 @@ | ||
import React from 'react'; | ||
|
||
import { useLanguage } from 'src/features/language/useLanguage'; | ||
import { useCanvasDraw } from 'src/layout/ImageUpload/ImageCanvas/hooks/useCanvasDraw'; | ||
import { useDragInteraction } from 'src/layout/ImageUpload/ImageCanvas/hooks/useDragInteraction'; | ||
import { useKeyboardNavigation } from 'src/layout/ImageUpload/ImageCanvas/hooks/useKeyboardNavigation'; | ||
import { useZoomInteraction } from 'src/layout/ImageUpload/ImageCanvas/hooks/useZoomInteraction'; | ||
import classes from 'src/layout/ImageUpload/ImageCanvas/ImageCanvas.module.css'; | ||
import { ImagePreview } from 'src/layout/ImageUpload/ImageCanvas/ImagePreview'; | ||
import { useImageFile } from 'src/layout/ImageUpload/useImageFile'; | ||
import type { CropArea, Position } from 'src/layout/ImageUpload/imageUploadUtils'; | ||
interface ImageCanvasProps { | ||
imageRef: React.RefObject<HTMLImageElement | null>; | ||
zoom: number; | ||
position: Position; | ||
cropArea: CropArea; | ||
baseComponentId: string; | ||
onPositionChange: (newPosition: Position) => void; | ||
onZoomChange: (newZoom: number) => void; | ||
canvasRef: React.RefObject<HTMLCanvasElement | null>; | ||
} | ||
|
||
const CANVAS_HEIGHT = 320; | ||
const CANVAS_WIDTH = 1000; | ||
|
||
export function ImageCanvas({ | ||
imageRef, | ||
zoom, | ||
position, | ||
cropArea, | ||
baseComponentId, | ||
onPositionChange, | ||
onZoomChange, | ||
canvasRef, | ||
}: ImageCanvasProps) { | ||
const { storedImage, imageUrl } = useImageFile(baseComponentId); | ||
const { langAsString } = useLanguage(); | ||
|
||
useCanvasDraw({ canvasRef, imageRef, zoom, position, cropArea }); | ||
useZoomInteraction({ canvasRef, zoom, onZoomChange }); | ||
const { handlePointerDown } = useDragInteraction({ canvasRef, position, onPositionChange }); | ||
const { handleKeyDown } = useKeyboardNavigation({ position, onPositionChange }); | ||
|
||
if (storedImage) { | ||
return ( | ||
<ImagePreview | ||
storedImage={storedImage} | ||
imageUrl={imageUrl} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<canvas | ||
onPointerDown={handlePointerDown} | ||
onKeyDown={handleKeyDown} | ||
tabIndex={0} | ||
ref={canvasRef} | ||
height={CANVAS_HEIGHT} | ||
width={CANVAS_WIDTH} | ||
className={classes.canvas} | ||
aria-label={langAsString('image_upload_component.crop_area')} | ||
/> | ||
); | ||
} |
This file contains hidden or 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,9 @@ | ||
.previewWrapper { | ||
background-color: #f4f5f6; /* Following does not exist in v1: var(--ds-color-neutral-background-subtle); */ | ||
lassopicasso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
height: 320px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
padding: var(--ds-size-4); | ||
box-sizing: border-box; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.