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
cd328318
Commit
cd328318
authored
May 09, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change color previews only if hex is correct
parent
36b4be0b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
26 deletions
+35
-26
color.ts
lib/validations/color.ts
+17
-0
PublicTagsSubmitFieldTag.tsx
ui/publicTags/submit/fields/PublicTagsSubmitFieldTag.tsx
+5
-2
PublicTagsSubmitFieldTagColor.tsx
...ublicTags/submit/fields/PublicTagsSubmitFieldTagColor.tsx
+13
-24
No files found.
lib/validations/color.ts
0 → 100644
View file @
cd328318
export
const
COLOR_HEX_REGEXP
=
/^
[
A-Fa-f
\d]{3,6}
$/
;
export
const
validator
=
(
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
;
};
ui/publicTags/submit/fields/PublicTagsSubmitFieldTag.tsx
View file @
cd328318
...
@@ -6,6 +6,7 @@ import type { FormFields, FormFieldTag } from '../types';
...
@@ -6,6 +6,7 @@ import type { FormFields, FormFieldTag } from '../types';
import
type
{
PublicTagType
}
from
'
types/api/addressMetadata
'
;
import
type
{
PublicTagType
}
from
'
types/api/addressMetadata
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
{
validator
as
colorValidator
}
from
'
lib/validations/color
'
;
import
{
validator
as
urlValidator
}
from
'
lib/validations/url
'
;
import
{
validator
as
urlValidator
}
from
'
lib/validations/url
'
;
import
EntityTag
from
'
ui/shared/EntityTags/EntityTag
'
;
import
EntityTag
from
'
ui/shared/EntityTags/EntityTag
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
...
@@ -74,6 +75,7 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, register, errors, onAddCl
...
@@ -74,6 +75,7 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, register, errors, onAddCl
</
FormControl
>
</
FormControl
>
</
GridItem
>
</
GridItem
>
<
PublicTagsSubmitFieldTagColor
<
PublicTagsSubmitFieldTagColor
fieldType=
"bgColor"
fieldName=
{
`tags.${ index }.bgColor`
}
fieldName=
{
`tags.${ index }.bgColor`
}
placeholder=
"Background color"
placeholder=
"Background color"
index=
{
index
}
index=
{
index
}
...
@@ -82,6 +84,7 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, register, errors, onAddCl
...
@@ -82,6 +84,7 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, register, errors, onAddCl
isDisabled=
{
isDisabled
}
isDisabled=
{
isDisabled
}
/>
/>
<
PublicTagsSubmitFieldTagColor
<
PublicTagsSubmitFieldTagColor
fieldType=
"textColor"
fieldName=
{
`tags.${ index }.textColor`
}
fieldName=
{
`tags.${ index }.textColor`
}
placeholder=
"Text color"
placeholder=
"Text color"
index=
{
index
}
index=
{
index
}
...
@@ -141,8 +144,8 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, register, errors, onAddCl
...
@@ -141,8 +144,8 @@ const PublicTagsSubmitFieldTag = ({ index, isDisabled, register, errors, onAddCl
tagType
:
field
.
type
.
value
,
tagType
:
field
.
type
.
value
,
meta
:
{
meta
:
{
tagUrl
:
field
.
url
,
tagUrl
:
field
.
url
,
bgColor
:
field
.
bgColor
?
`#${ field.bgColor }`
:
undefined
,
bgColor
:
field
.
bgColor
&&
colorValidator
(
field
.
bgColor
)
===
true
?
`#${ field.bgColor }`
:
undefined
,
textColor
:
field
.
textColor
?
`#${ field.textColor }`
:
undefined
,
textColor
:
field
.
textColor
&&
colorValidator
(
field
.
textColor
)
===
true
?
`#${ field.textColor }`
:
undefined
,
tooltipDescription
:
field
.
tooltipDescription
,
tooltipDescription
:
field
.
tooltipDescription
,
},
},
slug
:
'
new
'
,
slug
:
'
new
'
,
...
...
ui/publicTags/submit/fields/PublicTagsSubmitFieldTagColor.tsx
View file @
cd328318
...
@@ -5,10 +5,14 @@ import { useFormContext, type FieldError, type UseFormRegister } from 'react-hoo
...
@@ -5,10 +5,14 @@ import { useFormContext, type FieldError, type UseFormRegister } from 'react-hoo
import
type
{
FormFields
}
from
'
../types
'
;
import
type
{
FormFields
}
from
'
../types
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
{
validator
as
colorValidator
}
from
'
lib/validations/color
'
;
import
InputPlaceholder
from
'
ui/shared/InputPlaceholder
'
;
import
InputPlaceholder
from
'
ui/shared/InputPlaceholder
'
;
interface
Props
{
type
ColorFieldTypes
=
'
bgColor
'
|
'
textColor
'
;
fieldName
:
`tags.
${
number
}
.
${
'
bgColor
'
|
'
textColor
'
}
`
;
interface
Props
<
Type
extends
ColorFieldTypes
>
{
fieldType
:
Type
;
fieldName
:
`tags.
${
number
}
.
${
Type
}
`
;
index
:
number
;
index
:
number
;
isDisabled
:
boolean
;
isDisabled
:
boolean
;
register
:
UseFormRegister
<
FormFields
>
;
register
:
UseFormRegister
<
FormFields
>
;
...
@@ -16,30 +20,15 @@ interface Props {
...
@@ -16,30 +20,15 @@ interface Props {
placeholder
:
string
;
placeholder
:
string
;
}
}
const
COLOR_HEX_REGEXP
=
/^
[
A-Fa-f
\d]{3,6}
$/
;
const
PublicTagsSubmitFieldTagColor
=
<
Type
extends
ColorFieldTypes
>
(
{
isDisabled
,
error
,
fieldName
,
placeholder
,
fieldType
}
: Props
<
Type
>
) =
>
{
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
{
getValues
,
register
}
=
useFormContext
<
FormFields
>
();
const
inputBgColor
=
useColorModeValue
(
'
white
'
,
'
black
'
);
const
inputBgColor
=
useColorModeValue
(
'
white
'
,
'
black
'
);
const
circleBgColorDefault
=
useColorModeValue
(
'
gray.100
'
,
'
gray.700
'
);
const
circleBgColorDefault
=
{
bgColor
:
useColorModeValue
(
'
gray.100
'
,
'
gray.700
'
),
textColor
:
useColorModeValue
(
'
blackAlpha.800
'
,
'
whiteAlpha.800
'
),
};
const
isMobile
=
useIsMobile
();
const
isMobile
=
useIsMobile
();
const
field
=
register
(
fieldName
,
{
validate
,
maxLength
:
6
});
const
field
=
register
(
fieldName
,
{
validate
:
colorValidator
,
maxLength
:
6
});
const
value
=
getValues
(
fieldName
);
const
value
=
getValues
(
fieldName
);
return
(
return
(
...
@@ -57,7 +46,7 @@ const PublicTagsSubmitFieldTagColor = ({ isDisabled, error, fieldName, placehold
...
@@ -57,7 +46,7 @@ const PublicTagsSubmitFieldTagColor = ({ isDisabled, error, fieldName, placehold
<
InputRightElement
w=
"30px"
right=
{
4
}
zIndex=
{
10
}
>
<
InputRightElement
w=
"30px"
right=
{
4
}
zIndex=
{
10
}
>
<
Circle
<
Circle
size=
"30px"
size=
"30px"
bgColor=
{
!
value
?
circleBgColorDefault
:
`#${ value }`
}
bgColor=
{
value
&&
colorValidator
(
value
)
===
true
?
`#${ value }`
:
circleBgColorDefault
[
fieldType
]
}
borderColor=
"gray.300"
borderColor=
"gray.300"
borderWidth=
"1px"
borderWidth=
"1px"
/>
/>
...
...
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