Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
ajs_22_shop_api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
Нұрасыл Қайратұлы
ajs_22_shop_api
Commits
dd77e9f7
Commit
dd77e9f7
authored
Aug 27, 2025
by
Нұрасыл Қайратұлы
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drag and drop
parent
1beb2338
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
15 deletions
+64
-15
ProductForm.tsx
client/src/components/ProductForm/ProductForm.tsx
+6
-1
FileInput.tsx
client/src/components/UI/Input/FileInput.tsx
+58
-14
No files found.
client/src/components/ProductForm/ProductForm.tsx
View file @
dd77e9f7
...
...
@@ -110,7 +110,12 @@ const ProductForm = () => {
</
Grid2
>
<
Grid2
>
<
FileInput
name=
'image'
label=
'Image'
onChange=
{
onFileChange
}
/>
<
FileInput
name=
'image'
label=
'Image'
onChange=
{
onFileChange
}
accept=
{
'image/*'
}
/>
</
Grid2
>
<
Grid2
>
...
...
client/src/components/UI/Input/FileInput.tsx
View file @
dd77e9f7
'use client'
import
{
Button
,
Grid2
,
styled
,
TextField
}
from
'@mui/material'
import
{
B
ox
,
B
utton
,
Grid2
,
styled
,
TextField
}
from
'@mui/material'
import
{
ChangeEvent
,
useRef
,
useState
}
from
'react'
interface
IProps
{
name
:
string
label
:
string
onChange
:
(
e
:
ChangeEvent
<
HTMLInputElement
>
)
=>
void
accept
?:
string
}
const
HiddenFileInput
=
styled
(
'input'
)({
display
:
'none'
})
const
FileInput
=
({
name
,
label
,
onChange
}:
IProps
)
=>
{
const
dragZoneStyles
=
{
border
:
'2px dashed #a7a7a7'
,
borderRadius
:
'8px'
,
cursor
:
'pointer'
,
}
const
FileInput
=
({
name
,
label
,
onChange
,
accept
}:
IProps
)
=>
{
const
inputRef
=
useRef
<
HTMLInputElement
>
(
null
)
const
[
fileName
,
setFileName
]
=
useState
(
''
)
const
[
isDragging
,
setIsDragging
]
=
useState
(
false
)
const
activeInput
=
()
=>
{
const
openDialog
=
()
=>
{
if
(
inputRef
?.
current
)
{
inputRef
.
current
.
click
()
}
...
...
@@ -23,14 +31,37 @@ const FileInput = ({ name, label, onChange }: IProps) => {
const
onFileChange
=
(
e
:
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
file
=
e
.
target
.
files
[
0
].
name
console
.
log
(
e
.
target
.
files
)
if
(
file
)
{
setFileName
(
file
)
onChange
(
e
)
}
}
const
prevent
=
(
e
:
DragEvent
)
=>
{
e
.
preventDefault
()
e
.
stopPropagation
()
}
const
onDragOver
=
(
e
:
any
)
=>
{
prevent
(
e
)
if
(
!
isDragging
)
setIsDragging
(
true
)
}
const
onDragLeave
=
(
e
:
any
)
=>
{
prevent
(
e
)
setIsDragging
(
false
)
}
const
onDrop
=
(
e
:
any
)
=>
{
prevent
(
e
)
setIsDragging
(
false
)
const
file
=
e
.
dataTransfer
?.
files
?.[
0
]
if
(
!
file
)
return
setFileName
(
file
.
name
)
}
return
(
<>
<
HiddenFileInput
...
...
@@ -38,22 +69,35 @@ const FileInput = ({ name, label, onChange }: IProps) => {
name=
{
name
}
onChange=
{
onFileChange
}
ref=
{
inputRef
}
accept=
{
accept
}
/>
<
Grid2
container
direction=
'row'
spacing=
{
2
}
alignItems=
{
'center'
}
>
<
Grid2
>
<
TextField
variant=
'outlined'
fullWidth
label=
{
label
}
value=
{
fileName
}
disabled
onClick=
{
activeInput
}
/>
<
Box
sx=
{
{
...
dragZoneStyles
,
background
:
isDragging
?
'gray'
:
'transparent'
,
borderColor
:
isDragging
?
'gray'
:
'transparent'
,
}
}
role=
'button'
onDragOver=
{
onDragOver
}
onDragLeave=
{
onDragLeave
}
onDrop=
{
onDrop
}
>
<
TextField
variant=
'outlined'
fullWidth
label=
{
label
}
value=
{
fileName
}
disabled
placeholder=
'Перетащите файл сюда или нажмите на выбор'
/>
</
Box
>
</
Grid2
>
<
Grid2
>
<
Button
variant=
'contained'
onClick=
{
activeInput
}
>
<
Button
variant=
'contained'
onClick=
{
openDialog
}
>
Browse
</
Button
>
</
Grid2
>
...
...
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