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
36b4be0b
Commit
36b4be0b
authored
May 09, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add icon to tag type control
parent
a33a8d54
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
3 deletions
+39
-3
PublicTagsSubmitFieldTagType.tsx
ui/publicTags/submit/fields/PublicTagsSubmitFieldTagType.tsx
+39
-3
No files found.
ui/publicTags/submit/fields/PublicTagsSubmitFieldTagType.tsx
View file @
36b4be0b
import
{
FormControl
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
{
chakra
,
Flex
,
FormControl
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
type
{
GroupBase
,
SelectComponentsConfig
,
SingleValueProps
}
from
'
chakra-react-select
'
;
import
{
chakraComponents
}
from
'
chakra-react-select
'
;
import
React
from
'
react
'
;
import
type
{
ControllerRenderProps
}
from
'
react-hook-form
'
;
import
{
Controller
,
useFormContext
}
from
'
react-hook-form
'
;
import
type
{
FormFields
}
from
'
../types
'
;
import
type
{
PublicTagType
}
from
'
types/api/addressMetadata
'
;
import
type
{
Option
}
from
'
ui/shared/FancySelect/types
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
FancySelect
from
'
ui/shared/FancySelect/FancySelect
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
interface
Props
{
index
:
number
;
...
...
@@ -17,7 +21,7 @@ interface Props {
const
PublicTagsSubmitFieldTagType
=
({
index
,
tagTypes
,
isDisabled
}:
Props
)
=>
{
const
isMobile
=
useIsMobile
();
const
{
control
}
=
useFormContext
<
FormFields
>
();
const
{
control
,
watch
}
=
useFormContext
<
FormFields
>
();
const
inputBgColor
=
useColorModeValue
(
'
white
'
,
'
black
'
);
const
typeOptions
=
React
.
useMemo
(()
=>
tagTypes
?.
map
((
type
)
=>
({
...
...
@@ -25,6 +29,36 @@ const PublicTagsSubmitFieldTagType = ({ index, tagTypes, isDisabled }: Props) =>
label
:
type
.
type
,
})),
[
tagTypes
]);
const
fieldValue
=
watch
(
`tags.
${
index
}
.type`
).
value
;
const
selectComponents
:
SelectComponentsConfig
<
Option
,
boolean
,
GroupBase
<
Option
>>
=
React
.
useMemo
(()
=>
{
type
SingleValueComponentProps
=
SingleValueProps
<
Option
,
boolean
,
GroupBase
<
Option
>>
&
{
children
:
React
.
ReactNode
}
const
SingleValue
=
({
children
,
...
props
}:
SingleValueComponentProps
)
=>
{
switch
(
fieldValue
)
{
case
'
name
'
:
{
return
(
<
chakraComponents
.
SingleValue
{
...
props
}
>
<
Flex
alignItems=
"center"
columnGap=
{
1
}
>
<
IconSvg
name=
"publictags_slim"
boxSize=
{
4
}
flexShrink=
{
0
}
color=
"gray.400"
/>
{
children
}
</
Flex
>
</
chakraComponents
.
SingleValue
>
);
}
case
'
protocol
'
:
case
'
generic
'
:
{
return
(<
chakraComponents
.
SingleValue
{
...
props
}
><
chakra
.
span
color=
"gray.400"
>
#
</
chakra
.
span
>
{
children
}
</
chakraComponents
.
SingleValue
>);
}
default
:
{
return
(<
chakraComponents
.
SingleValue
{
...
props
}
>
{
children
}
</
chakraComponents
.
SingleValue
>);
}
}
};
return
{
SingleValue
};
},
[
fieldValue
]);
const
renderControl
=
React
.
useCallback
(({
field
}:
{
field
:
ControllerRenderProps
<
FormFields
,
`tags.
${
number
}
.type`
>
})
=>
{
return
(
<
FormControl
variant=
"floating"
id=
{
field
.
name
}
isRequired
size=
{
{
base
:
'
md
'
,
lg
:
'
lg
'
}
}
>
...
...
@@ -36,6 +70,8 @@ const PublicTagsSubmitFieldTagType = ({ index, tagTypes, isDisabled }: Props) =>
isDisabled=
{
isDisabled
}
isRequired
isAsync=
{
false
}
isSearchable=
{
false
}
components=
{
selectComponents
}
formControlStyles=
{
{
bgColor
:
inputBgColor
,
borderRadius
:
'
base
'
,
...
...
@@ -43,7 +79,7 @@ const PublicTagsSubmitFieldTagType = ({ index, tagTypes, isDisabled }: Props) =>
/>
</
FormControl
>
);
},
[
inputBgColor
,
isDisabled
,
isMobile
,
typeOptions
]);
},
[
inputBgColor
,
isDisabled
,
isMobile
,
selectComponents
,
typeOptions
]);
return
(
<
Controller
...
...
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