Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
23787bf1
Commit
23787bf1
authored
Feb 15, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
disabled state for drag-and-drop area
parent
39b7f189
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
7 deletions
+23
-7
ContractVerificationFieldSources.tsx
...tVerification/fields/ContractVerificationFieldSources.tsx
+2
-2
DragAndDropArea.tsx
ui/shared/forms/DragAndDropArea.tsx
+21
-5
No files found.
ui/contractVerification/fields/ContractVerificationFieldSources.tsx
View file @
23787bf1
...
@@ -91,7 +91,7 @@ const ContractVerificationFieldSources = ({ fileTypes, multiple, title, hint }:
...
@@ -91,7 +91,7 @@ const ContractVerificationFieldSources = ({ fileTypes, multiple, title, hint }:
rowGap=
{
2
}
rowGap=
{
2
}
w=
"100%"
w=
"100%"
>
>
<
DragAndDropArea
onDrop=
{
onChange
}
p=
{
{
base
:
3
,
lg
:
6
}
}
>
<
DragAndDropArea
onDrop=
{
onChange
}
p=
{
{
base
:
3
,
lg
:
6
}
}
isDisabled=
{
formState
.
isSubmitting
}
>
{
hasValue
?
renderFiles
(
field
.
value
)
:
renderUploadButton
()
}
{
hasValue
?
renderFiles
(
field
.
value
)
:
renderUploadButton
()
}
</
DragAndDropArea
>
</
DragAndDropArea
>
</
Flex
>
</
Flex
>
...
@@ -100,7 +100,7 @@ const ContractVerificationFieldSources = ({ fileTypes, multiple, title, hint }:
...
@@ -100,7 +100,7 @@ const ContractVerificationFieldSources = ({ fileTypes, multiple, title, hint }:
{
commonError
?.
message
&&
<
FieldError
message=
{
commonError
.
type
===
'
required
'
?
'
Field is required
'
:
commonError
.
message
}
/>
}
{
commonError
?.
message
&&
<
FieldError
message=
{
commonError
.
type
===
'
required
'
?
'
Field is required
'
:
commonError
.
message
}
/>
}
</>
</>
);
);
},
[
fileTypes
,
multiple
,
renderFiles
,
commonError
,
renderUploadButton
]);
},
[
fileTypes
,
multiple
,
commonError
,
formState
.
isSubmitting
,
renderFiles
,
renderUploadButton
]);
const
validateFileType
=
React
.
useCallback
(
async
(
value
:
FieldPathValue
<
FormFields
,
'
sources
'
>
):
Promise
<
ValidateResult
>
=>
{
const
validateFileType
=
React
.
useCallback
(
async
(
value
:
FieldPathValue
<
FormFields
,
'
sources
'
>
):
Promise
<
ValidateResult
>
=>
{
if
(
Array
.
isArray
(
value
))
{
if
(
Array
.
isArray
(
value
))
{
...
...
ui/shared/forms/DragAndDropArea.tsx
View file @
23787bf1
import
{
chakra
,
Center
}
from
'
@chakra-ui/react
'
;
import
{
chakra
,
Center
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
type
{
DragEvent
}
from
'
react
'
;
import
type
{
DragEvent
}
from
'
react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
...
@@ -8,20 +8,25 @@ interface Props {
...
@@ -8,20 +8,25 @@ interface Props {
children
:
React
.
ReactNode
;
children
:
React
.
ReactNode
;
onDrop
:
(
files
:
Array
<
File
>
)
=>
void
;
onDrop
:
(
files
:
Array
<
File
>
)
=>
void
;
className
?:
string
;
className
?:
string
;
isDisabled
?:
boolean
;
}
}
const
DragAndDropArea
=
({
onDrop
,
children
,
className
}:
Props
)
=>
{
const
DragAndDropArea
=
({
onDrop
,
children
,
className
,
isDisabled
}:
Props
)
=>
{
const
[
isDragOver
,
setIsDragOver
]
=
React
.
useState
(
false
);
const
[
isDragOver
,
setIsDragOver
]
=
React
.
useState
(
false
);
const
handleDrop
=
React
.
useCallback
(
async
(
event
:
DragEvent
<
HTMLDivElement
>
)
=>
{
const
handleDrop
=
React
.
useCallback
(
async
(
event
:
DragEvent
<
HTMLDivElement
>
)
=>
{
event
.
preventDefault
();
event
.
preventDefault
();
if
(
isDisabled
)
{
return
;
}
const
fileEntries
=
await
getAllFileEntries
(
event
.
dataTransfer
.
items
);
const
fileEntries
=
await
getAllFileEntries
(
event
.
dataTransfer
.
items
);
const
files
=
await
Promise
.
all
(
fileEntries
.
map
(
convertFileEntryToFile
));
const
files
=
await
Promise
.
all
(
fileEntries
.
map
(
convertFileEntryToFile
));
onDrop
(
files
);
onDrop
(
files
);
setIsDragOver
(
false
);
setIsDragOver
(
false
);
},
[
onDrop
]);
},
[
isDisabled
,
onDrop
]);
const
handleDragOver
=
React
.
useCallback
((
event
:
DragEvent
<
HTMLDivElement
>
)
=>
{
const
handleDragOver
=
React
.
useCallback
((
event
:
DragEvent
<
HTMLDivElement
>
)
=>
{
event
.
preventDefault
();
event
.
preventDefault
();
...
@@ -37,20 +42,31 @@ const DragAndDropArea = ({ onDrop, children, className }: Props) => {
...
@@ -37,20 +42,31 @@ const DragAndDropArea = ({ onDrop, children, className }: Props) => {
setIsDragOver
(
false
);
setIsDragOver
(
false
);
},
[]);
},
[]);
const
handleClick
=
React
.
useCallback
((
event
:
React
.
MouseEvent
)
=>
{
if
(
isDisabled
)
{
event
.
preventDefault
();
event
.
stopPropagation
();
}
},
[
isDisabled
]);
const
disabledBorderColor
=
useColorModeValue
(
'
blackAlpha.200
'
,
'
whiteAlpha.200
'
);
const
borderColor
=
isDragOver
?
'
link_hovered
'
:
'
link
'
;
return
(
return
(
<
Center
<
Center
className=
{
className
}
className=
{
className
}
w=
"100%"
w=
"100%"
minH=
"120px"
minH=
"120px"
borderWidth=
"2px"
borderWidth=
"2px"
borderColor=
{
isD
ragOver
?
'
link_hovered
'
:
'
link
'
}
borderColor=
{
isD
isabled
?
disabledBorderColor
:
borderColor
}
_hover=
{
{
_hover=
{
{
borderColor
:
'
link_hovered
'
,
borderColor
:
isDisabled
?
disabledBorderColor
:
'
link_hovered
'
,
}
}
}
}
borderRadius=
"base"
borderRadius=
"base"
borderStyle=
"dashed"
borderStyle=
"dashed"
cursor=
"pointer"
cursor=
"pointer"
textAlign=
"center"
textAlign=
"center"
onClick=
{
handleClick
}
onDrop=
{
handleDrop
}
onDrop=
{
handleDrop
}
onDragOver=
{
handleDragOver
}
onDragOver=
{
handleDragOver
}
onDragEnter=
{
handleDragEnter
}
onDragEnter=
{
handleDragEnter
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment