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
247bc80d
Commit
247bc80d
authored
Jan 04, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input fields
parent
dca2f104
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
3 deletions
+93
-3
Input.ts
theme/components/Input.ts
+2
-2
ContractReadItemInput.tsx
ui/address/contract/ContractReadItemInput.tsx
+47
-1
ContractReadItemInputField.tsx
ui/address/contract/ContractReadItemInputField.tsx
+43
-0
types.ts
ui/address/contract/types.ts
+1
-0
No files found.
theme/components/Input.ts
View file @
247bc80d
...
...
@@ -16,8 +16,8 @@ const size = {
xs
:
defineStyle
({
fontSize
:
'
md
'
,
lineHeight
:
'
24px
'
,
px
:
'
4
px
'
,
py
:
'
12
px
'
,
px
:
'
8
px
'
,
py
:
'
4
px
'
,
h
:
'
32px
'
,
borderRadius
:
'
base
'
,
}),
...
...
ui/address/contract/ContractReadItemInput.tsx
View file @
247bc80d
import
{
Button
,
chakra
}
from
'
@chakra-ui/react
'
;
import
_fromPairs
from
'
lodash/fromPairs
'
;
import
React
from
'
react
'
;
import
type
{
SubmitHandler
}
from
'
react-hook-form
'
;
import
{
useForm
}
from
'
react-hook-form
'
;
import
type
{
MethodInputFields
}
from
'
./types
'
;
import
type
{
SmartContractMethodInput
}
from
'
types/api/contract
'
;
import
ContractReadItemInputField
from
'
./ContractReadItemInputField
'
;
interface
Props
{
data
:
Array
<
SmartContractMethodInput
>
;
}
const
ContractReadItemInput
=
({
data
}:
Props
)
=>
{
return
<
span
>
{
data
.
map
(({
type
})
=>
type
).
join
(
'
,
'
)
}
</
span
>;
const
{
control
,
handleSubmit
}
=
useForm
<
MethodInputFields
>
({
defaultValues
:
_fromPairs
(
data
.
map
(({
name
},
index
)
=>
[
name
||
index
,
''
])),
});
const
onSubmit
:
SubmitHandler
<
MethodInputFields
>
=
React
.
useCallback
((
data
)
=>
{
// eslint-disable-next-line no-console
console
.
log
(
'
__>__
'
,
data
);
},
[
]);
return
(
<
chakra
.
form
noValidate
display=
"flex"
columnGap=
{
3
}
flexDir=
{
{
base
:
'
column
'
,
lg
:
'
row
'
}
}
rowGap=
{
2
}
alignItems=
{
{
base
:
'
flex-start
'
,
lg
:
'
center
'
}
}
onSubmit=
{
handleSubmit
(
onSubmit
)
}
>
{
data
.
map
(({
type
,
name
},
index
)
=>
{
return
(
<
ContractReadItemInputField
key=
{
name
||
index
}
name=
{
name
}
index=
{
index
}
control=
{
control
}
type=
{
type
}
/>
);
})
}
<
Button
variant=
"outline"
size=
"sm"
flexShrink=
{
0
}
type=
"submit"
>
Query
</
Button
>
</
chakra
.
form
>
);
};
export
default
ContractReadItemInput
;
ui/address/contract/ContractReadItemInputField.tsx
0 → 100644
View file @
247bc80d
import
{
Button
,
FormControl
,
Input
,
InputGroup
,
InputRightElement
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
type
{
Control
,
ControllerRenderProps
}
from
'
react-hook-form
'
;
import
{
Controller
}
from
'
react-hook-form
'
;
import
type
{
MethodInputFields
}
from
'
./types
'
;
interface
Props
{
control
:
Control
<
MethodInputFields
>
;
type
:
string
;
name
:
string
;
index
:
number
;
}
const
ContractReadItemInputField
=
({
control
,
name
,
type
,
index
}:
Props
)
=>
{
const
fieldName
=
name
||
String
(
index
);
const
renderInput
=
React
.
useCallback
(({
field
}:
{
field
:
ControllerRenderProps
<
MethodInputFields
>
})
=>
{
return
(
<
FormControl
id=
{
fieldName
}
>
<
InputGroup
key=
{
fieldName
}
size=
"xs"
>
<
Input
{
...
field
}
placeholder=
{
`${ name }(${ type })`
}
/>
<
InputRightElement
>
<
Button
size=
"xs"
>
clear
</
Button
>
</
InputRightElement
>
</
InputGroup
>
</
FormControl
>
);
},
[
fieldName
,
name
,
type
]);
return
(
<
Controller
name=
{
fieldName
}
control=
{
control
}
render=
{
renderInput
}
/>
);
};
export
default
ContractReadItemInputField
;
ui/address/contract/types.ts
0 → 100644
View file @
247bc80d
export
type
MethodInputFields
=
Record
<
string
,
string
>
;
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