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
26ef668d
Commit
26ef668d
authored
May 08, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
color preview
parent
a2263142
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
18 deletions
+53
-18
PublicTagsSubmitFieldTag.tsx
ui/publicTags/submit/fields/PublicTagsSubmitFieldTag.tsx
+4
-4
PublicTagsSubmitFieldTagColor.tsx
...ublicTags/submit/fields/PublicTagsSubmitFieldTagColor.tsx
+49
-14
No files found.
ui/publicTags/submit/fields/PublicTagsSubmitFieldTag.tsx
View file @
26ef668d
...
...
@@ -72,19 +72,19 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, register, errors, onAddCl
</
FormControl
>
</
GridItem
>
<
PublicTagsSubmitFieldTagColor
fieldName=
"bgColor"
fieldName=
{
`tags.${ index }.bgColor`
}
placeholder=
"Background color"
index=
{
index
}
register=
{
register
}
error
s=
{
errors
}
error
=
{
errors
?.
bgColor
}
isDisabled=
{
isDisabled
}
/>
<
PublicTagsSubmitFieldTagColor
fieldName=
"textColor"
fieldName=
{
`tags.${ index }.textColor`
}
placeholder=
"Text color"
index=
{
index
}
register=
{
register
}
error
s=
{
errors
}
error
=
{
errors
?.
textColor
}
isDisabled=
{
isDisabled
}
/>
<
GridItem
colSpan=
{
{
base
:
1
,
lg
:
4
}
}
>
...
...
ui/publicTags/submit/fields/PublicTagsSubmitFieldTagColor.tsx
View file @
26ef668d
import
{
FormControl
,
Inpu
t
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
{
Circle
,
FormControl
,
Input
,
InputGroup
,
InputRightElemen
t
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
type
{
FieldError
,
FieldErrorsImpl
,
Merge
,
UseFormRegister
}
from
'
react-hook-form
'
;
import
{
useFormContext
,
type
FieldError
,
type
UseFormRegister
}
from
'
react-hook-form
'
;
import
type
{
FormField
Tag
,
FormField
s
}
from
'
../types
'
;
import
type
{
FormFields
}
from
'
../types
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
InputPlaceholder
from
'
ui/shared/InputPlaceholder
'
;
interface
Props
{
fieldName
:
'
textColor
'
|
'
bgColor
'
;
fieldName
:
`tags.
${
number
}
.
${
'
bgColor
'
|
'
textColor
'
}
`
;
index
:
number
;
isDisabled
:
boolean
;
register
:
UseFormRegister
<
FormFields
>
;
error
s
:
Merge
<
FieldError
,
FieldErrorsImpl
<
FormFieldTag
>>
|
undefined
;
error
:
FieldError
|
undefined
;
placeholder
:
string
;
}
const
PublicTagsSubmitFieldTagColor
=
({
index
,
isDisabled
,
register
,
errors
,
fieldName
,
placeholder
}:
Props
)
=>
{
const
COLOR_HEX_REGEXP
=
/^
[
A-Fa-f
\d]{3,6}
$/
;
const
validate
=
(
value
:
string
|
undefined
)
=>
{
if
(
!
value
||
value
.
length
===
0
)
{
return
true
;
}
if
(
value
.
length
!==
3
&&
value
.
length
!==
6
)
{
return
'
Invalid length
'
;
}
if
(
!
COLOR_HEX_REGEXP
.
test
(
value
))
{
return
'
Invalid hex code
'
;
}
return
true
;
};
const
PublicTagsSubmitFieldTagColor
=
({
isDisabled
,
error
,
fieldName
,
placeholder
}:
Props
)
=>
{
const
{
getValues
,
register
}
=
useFormContext
<
FormFields
>
();
const
inputBgColor
=
useColorModeValue
(
'
white
'
,
'
black
'
);
const
circleBgColorDefault
=
useColorModeValue
(
'
gray.100
'
,
'
gray.700
'
);
const
isMobile
=
useIsMobile
();
const
field
=
register
(
fieldName
,
{
validate
,
maxLength
:
6
});
const
value
=
getValues
(
fieldName
);
return
(
<
FormControl
variant=
"floating"
size=
{
{
base
:
'
md
'
,
lg
:
'
lg
'
}
}
>
<
InputGroup
size=
{
isMobile
?
'
md
'
:
'
lg
'
}
>
<
Input
{
...
register
(`
tags
.
$
{
index
}
.
$
{
fieldName
}`)
}
isInvalid=
{
Boolean
(
errors
?.[
fieldName
]
)
}
{
...
field
}
isInvalid=
{
Boolean
(
error
)
}
isDisabled=
{
isDisabled
}
autoComplete=
"off"
bgColor=
{
inputBgColor
}
maxLength=
{
6
}
/>
<
InputPlaceholder
text=
{
placeholder
}
error=
{
error
}
/>
<
InputRightElement
w=
"30px"
right=
{
4
}
zIndex=
{
10
}
>
<
Circle
size=
"30px"
bgColor=
{
!
value
?
circleBgColorDefault
:
`#${ value }`
}
borderColor=
"gray.300"
borderWidth=
"1px"
/>
<
InputPlaceholder
text=
{
placeholder
}
error=
{
errors
?.[
fieldName
]
}
/>
</
InputRightElement
>
</
InputGroup
>
</
FormControl
>
);
};
...
...
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