- Notifications
You must be signed in to change notification settings - Fork277
[Feat]: #1720 Add DropSpace / DragArea for fileUpload#1998
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
2c05e4d
[Feat]: #1720 add upload dragger
iamfaran5407edc
#1720 fix type error
iamfaran5464c85
#1720 add adjustable height in fixed mode
iamfaran85e9cf5
#1720 fix UI
iamfaranedbd09d
#1720 add drag area hint
iamfaran5db3f5a
#1720 remove unnecessary styled wrapper
iamfaran43c7fa3
#1720 add dragger image capture modal + custom dragger styling
iamfaran1e09cba
#1976 fix switch camera functionality
iamfaranaf83e43
#1720 fix modes height
iamfaranFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
202 changes: 202 additions & 0 deletionsclient/packages/lowcoder/src/comps/comps/fileComp/ImageCaptureModal.tsx
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,202 @@ | ||
import React, { Suspense, useCallback, useEffect, useRef, useState } from "react"; | ||
import { default as Button } from "antd/es/button"; | ||
import Dropdown from "antd/es/dropdown"; | ||
import type { ItemType } from "antd/es/menu/interface"; | ||
import Skeleton from "antd/es/skeleton"; | ||
import Menu from "antd/es/menu"; | ||
import Flex from "antd/es/flex"; | ||
import styled from "styled-components"; | ||
import { trans } from "i18n"; | ||
import { CustomModal } from "lowcoder-design"; | ||
const CustomModalStyled = styled(CustomModal)` | ||
top: 10vh; | ||
.react-draggable { | ||
max-width: 100%; | ||
width: 500px; | ||
video { | ||
width: 100%; | ||
} | ||
} | ||
`; | ||
const Error = styled.div` | ||
color: #f5222d; | ||
height: 100px; | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
`; | ||
const Wrapper = styled.div` | ||
img, | ||
video, | ||
.ant-skeleton { | ||
width: 100%; | ||
height: 400px; | ||
max-height: 70vh; | ||
position: relative; | ||
object-fit: cover; | ||
background-color: #000; | ||
} | ||
.ant-skeleton { | ||
h3, | ||
li { | ||
background-color: transparent; | ||
} | ||
} | ||
`; | ||
const ReactWebcam = React.lazy(() => import("react-webcam")); | ||
export const ImageCaptureModal = (props: { | ||
showModal: boolean; | ||
onModalClose: () => void; | ||
onImageCapture: (image: string) => void; | ||
}) => { | ||
const [errMessage, setErrMessage] = useState(""); | ||
const [videoConstraints, setVideoConstraints] = useState<MediaTrackConstraints>({ | ||
facingMode: "environment", | ||
}); | ||
const [modeList, setModeList] = useState<ItemType[]>([]); | ||
const [dropdownShow, setDropdownShow] = useState(false); | ||
const [imgSrc, setImgSrc] = useState<string>(); | ||
const webcamRef = useRef<any>(null); | ||
useEffect(() => { | ||
if (props.showModal) { | ||
setImgSrc(""); | ||
setErrMessage(""); | ||
setVideoConstraints({ facingMode: "environment" }); | ||
setDropdownShow(false); | ||
} | ||
}, [props.showModal]); | ||
const handleMediaErr = (err: any) => { | ||
if (typeof err === "string") { | ||
setErrMessage(err); | ||
} else { | ||
if (err.message === "getUserMedia is not implemented in this browser") { | ||
setErrMessage(trans("scanner.errTip")); | ||
} else { | ||
setErrMessage(err.message); | ||
} | ||
} | ||
}; | ||
const handleCapture = useCallback(() => { | ||
const imageSrc = webcamRef.current?.getScreenshot?.(); | ||
setImgSrc(imageSrc); | ||
}, [webcamRef]); | ||
const getModeList = () => { | ||
navigator.mediaDevices.enumerateDevices().then((data) => { | ||
const videoData = data.filter((item) => item.kind === "videoinput"); | ||
const faceModeList = videoData.map((item, index) => ({ | ||
label: item.label || trans("scanner.camera", { index: index + 1 }), | ||
key: item.deviceId, | ||
})); | ||
setModeList(faceModeList); | ||
}); | ||
}; | ||
return ( | ||
<CustomModalStyled | ||
showOkButton={false} | ||
showCancelButton={false} | ||
open={props.showModal} | ||
maskClosable={true} | ||
destroyOnHidden | ||
onCancel={props.onModalClose} | ||
> | ||
{!!errMessage ? ( | ||
<Error>{errMessage}</Error> | ||
) : ( | ||
props.showModal && ( | ||
<Wrapper> | ||
{imgSrc ? ( | ||
<img src={imgSrc} alt="webcam" /> | ||
) : ( | ||
<Suspense fallback={<Skeleton />}> | ||
<ReactWebcam | ||
key={JSON.stringify(videoConstraints)} | ||
ref={webcamRef} | ||
onUserMediaError={handleMediaErr} | ||
screenshotFormat="image/jpeg" | ||
videoConstraints={videoConstraints} | ||
/> | ||
</Suspense> | ||
)} | ||
{imgSrc ? ( | ||
<Flex justify="center" gap={10}> | ||
<Button | ||
type="primary" | ||
style={{ float: "right", marginTop: "10px" }} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
if (imgSrc) props.onImageCapture(imgSrc); | ||
}} | ||
> | ||
{trans("file.usePhoto")} | ||
</Button> | ||
<Button | ||
style={{ float: "right", marginTop: "10px" }} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
setImgSrc(""); | ||
}} | ||
> | ||
{trans("file.retakePhoto")} | ||
</Button> | ||
</Flex> | ||
) : ( | ||
<Flex justify="center" gap={10}> | ||
<Button | ||
type="primary" | ||
style={{ float: "right", marginTop: "10px" }} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
handleCapture(); | ||
}} | ||
> | ||
{trans("file.capture")} | ||
</Button> | ||
<Dropdown | ||
placement="bottomRight" | ||
trigger={["click"]} | ||
open={dropdownShow} | ||
onOpenChange={(value) => setDropdownShow(value)} | ||
popupRender={() => ( | ||
<Menu | ||
items={modeList} | ||
onClick={(value) => { | ||
setVideoConstraints({ deviceId: { exact: value.key } }); | ||
setDropdownShow(false); | ||
}} | ||
/> | ||
)} | ||
> | ||
<Button | ||
style={{ float: "right", marginTop: "10px" }} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
getModeList(); | ||
}} | ||
> | ||
{trans("scanner.changeCamera")} | ||
</Button> | ||
</Dropdown> | ||
</Flex> | ||
)} | ||
</Wrapper> | ||
) | ||
)} | ||
</CustomModalStyled> | ||
); | ||
}; | ||
export default ImageCaptureModal; | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.