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
f350b105
Commit
f350b105
authored
Jan 24, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
empty, filled, disabled and error styles
parent
138c1689
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
52 deletions
+71
-52
Form.ts
theme/components/Form.ts
+16
-3
FormLabel.ts
theme/components/FormLabel.ts
+13
-22
FancySelect.tsx
ui/shared/FancySelect/FancySelect.tsx
+13
-4
utils.ts
ui/shared/FancySelect/utils.ts
+28
-20
InputPlaceholder.tsx
ui/shared/InputPlaceholder.tsx
+1
-3
No files found.
theme/components/Form.ts
View file @
f350b105
...
...
@@ -58,11 +58,16 @@ function getFloatingVariantStylesForSize(size: 'md' | 'lg', props: StyleFunction
label
:
activeLabelStyles
,
'
input, textarea
'
:
activeInputStyles
,
},
'
&[aria-active=true] label
'
:
activeLabelStyles
,
// label styles
label
:
FormLabel
.
sizes
?.[
size
](
props
)
||
{},
'
input:not(:placeholder-shown) + label, textarea:not(:placeholder-shown) + label
'
:
activeLabelStyles
,
'
input[aria-invalid=true] + label, textarea[aria-invalid=true] + label
'
:
{
[
`
input[aria-invalid=true] + label,
textarea[aria-invalid=true] + label,
&[aria-invalid=true] label
`
]:
{
color
:
getColor
(
theme
,
errorColor
),
},
...
...
@@ -74,7 +79,11 @@ function getFloatingVariantStylesForSize(size: 'md' | 'lg', props: StyleFunction
padding
:
inputPx
,
},
'
input:not(:placeholder-shown), textarea:not(:placeholder-shown)
'
:
activeInputStyles
,
'
input[disabled] + label, textarea[disabled] + label
'
:
{
[
`
input[disabled] + label,
textarea[disabled] + label,
&[aria-disabled=true] label
`
]:
{
backgroundColor
:
'
transparent
'
,
},
...
...
@@ -82,7 +91,11 @@ function getFloatingVariantStylesForSize(size: 'md' | 'lg', props: StyleFunction
'
input:not(:placeholder-shown) + label .chakra-form__required-indicator, textarea:not(:placeholder-shown) + label .chakra-form__required-indicator
'
:
{
color
:
getColor
(
theme
,
focusPlaceholderColor
),
},
'
input[aria-invalid=true] + label .chakra-form__required-indicator, textarea[aria-invalid=true] + label .chakra-form__required-indicator
'
:
{
[
`
input[aria-invalid=true] + label .chakra-form__required-indicator,
textarea[aria-invalid=true] + label .chakra-form__required-indicator,
&[aria-invalid=true] .chakra-form__required-indicator
`
]:
{
color
:
getColor
(
theme
,
errorColor
),
},
},
...
...
theme/components/FormLabel.ts
View file @
f350b105
...
...
@@ -22,14 +22,6 @@ const variantFloating = defineStyle((props) => {
const
{
focusPlaceholderColor
}
=
getDefaultFormColors
(
props
);
const
bc
=
backgroundColor
||
mode
(
'
white
'
,
'
black
'
)(
props
);
const
activeStyles
=
{
backgroundColor
:
bc
,
color
:
getColor
(
theme
,
focusPlaceholderColor
),
fontSize
:
'
xs
'
,
lineHeight
:
'
16px
'
,
borderTopRightRadius
:
'
none
'
,
};
return
{
left
:
'
2px
'
,
top
:
'
2px
'
,
...
...
@@ -46,8 +38,13 @@ const variantFloating = defineStyle((props) => {
overflow
:
'
hidden
'
,
whiteSpace
:
'
nowrap
'
,
textOverflow
:
'
ellipsis
'
,
_focusWithin
:
activeStyles
,
'
&[data-active=true]
'
:
activeStyles
,
_focusWithin
:
{
backgroundColor
:
bc
,
color
:
getColor
(
theme
,
focusPlaceholderColor
),
fontSize
:
'
xs
'
,
lineHeight
:
'
16px
'
,
borderTopRightRadius
:
'
none
'
,
},
};
});
...
...
@@ -58,17 +55,14 @@ const variants = {
const
sizes
=
{
lg
:
defineStyle
((
props
)
=>
{
if
(
props
.
variant
===
'
floating
'
)
{
const
activeStyles
=
{
padding
:
'
16px 24px 2px 24px
'
,
};
return
{
fontSize
:
'
md
'
,
lineHeight
:
'
24px
'
,
padding
:
'
28px 24px
'
,
right
:
'
26px
'
,
_focusWithin
:
activeStyles
,
'
&[data-active=true]
'
:
activeStyles
,
_focusWithin
:
{
padding
:
'
16px 24px 2px 24px
'
,
},
'
&[data-fancy=true]
'
:
{
right
:
'
36px
'
,
},
...
...
@@ -79,17 +73,14 @@ const sizes = {
}),
md
:
defineStyle
((
props
)
=>
{
if
(
props
.
variant
===
'
floating
'
)
{
const
activeStyles
=
{
padding
:
'
10px 16px 2px 16px
'
,
};
return
{
fontSize
:
'
md
'
,
lineHeight
:
'
20px
'
,
padding
:
'
18px 16px
'
,
right
:
'
18px
'
,
_focusWithin
:
activeStyles
,
'
&[data-active=true]
'
:
activeStyles
,
_focusWithin
:
{
padding
:
'
10px 16px 2px 16px
'
,
},
'
&[data-fancy=true]
'
:
{
right
:
'
36px
'
,
},
...
...
ui/shared/FancySelect/FancySelect.tsx
View file @
f350b105
import
{
FormControl
,
useBoolean
,
useToken
}
from
'
@chakra-ui/react
'
;
import
{
FormControl
,
useBoolean
,
useToken
,
useColorMode
}
from
'
@chakra-ui/react
'
;
import
type
{
Size
,
CSSObjectWithLabel
,
OptionsOrGroups
,
GroupBase
,
SingleValue
,
MultiValue
}
from
'
chakra-react-select
'
;
import
{
Select
}
from
'
chakra-react-select
'
;
import
React
from
'
react
'
;
...
...
@@ -6,7 +6,7 @@ import type { FieldError } from 'react-hook-form';
import
type
{
Option
}
from
'
./types
'
;
import
{
c
hakraStyles
}
from
'
ui/shared/FancySelect/utils
'
;
import
{
getC
hakraStyles
}
from
'
ui/shared/FancySelect/utils
'
;
import
InputPlaceholder
from
'
ui/shared/InputPlaceholder
'
;
interface
Props
{
...
...
@@ -25,6 +25,7 @@ const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur
const
[
hasValue
,
setHasValue
]
=
useBoolean
(
false
);
const
menuZIndex
=
useToken
(
'
zIndices
'
,
'
dropdown
'
);
const
{
colorMode
}
=
useColorMode
();
const
handleChange
=
React
.
useCallback
((
newValue
:
SingleValue
<
Option
>
|
MultiValue
<
Option
>
)
=>
{
if
(
Array
.
isArray
(
newValue
))
{
...
...
@@ -48,8 +49,17 @@ const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur
menuPortal
:
(
provided
:
CSSObjectWithLabel
)
=>
({
...
provided
,
zIndex
:
menuZIndex
}),
}),
[
menuZIndex
]);
const
chakraStyles
=
React
.
useMemo
(()
=>
getChakraStyles
(
colorMode
),
[
colorMode
]);
return
(
<
FormControl
variant=
"floating"
size=
{
size
}
isRequired=
{
isRequired
}
>
<
FormControl
variant=
"floating"
size=
{
size
}
isRequired=
{
isRequired
}
{
...
(
error
?
{
'
aria
-
invalid
':
true
}
:
{})
}
{
...
(
isDisabled
?
{
'
aria
-
disabled
':
true
}
:
{})
}
{
...
(
hasValue
?
{
'
aria
-
active
':
true
}
:
{})
}
>
<
Select
menuPortalTarget=
{
window
.
document
.
body
}
placeholder=
""
...
...
@@ -67,7 +77,6 @@ const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur
/>
<
InputPlaceholder
text=
{
placeholder
}
isActive=
{
hasValue
}
error=
{
error
}
isFancy
/>
...
...
ui/shared/FancySelect/utils.ts
View file @
f350b105
import
type
{
ColorMode
}
from
'
@chakra-ui/react
'
;
import
type
{
Size
,
ChakraStylesConfig
}
from
'
chakra-react-select
'
;
import
type
{
Option
}
from
'
./types
'
;
...
...
@@ -40,25 +41,32 @@ function getSingleValueStyles(size?: Size) {
}
}
const
chakraStyles
:
ChakraStylesConfig
<
Option
>
=
{
// control: (provided) => ({
// ...provided,
// }),
inputContainer
:
(
provided
)
=>
({
...
provided
,
py
:
0
,
mx
:
0
,
}),
valueContainer
:
(
provided
,
state
)
=>
({
...
provided
,
...
getValueContainerStyles
(
state
.
selectProps
.
size
),
}),
singleValue
:
(
provided
,
state
)
=>
({
...
provided
,
mx
:
0
,
transform
:
'
none
'
,
...
getSingleValueStyles
(
state
.
selectProps
.
size
),
}),
const
getChakraStyles
:
(
colorMode
:
ColorMode
)
=>
ChakraStylesConfig
<
Option
>
=
(
colorMode
)
=>
{
const
emptyInputBorderColor
=
colorMode
===
'
dark
'
?
'
gray.700
'
:
'
gray.100
'
;
const
filledInputBorderColor
=
colorMode
===
'
dark
'
?
'
gray.600
'
:
'
gray.300
'
;
return
{
control
:
(
provided
,
state
)
=>
({
...
provided
,
borderColor
:
state
.
hasValue
?
filledInputBorderColor
:
emptyInputBorderColor
,
}),
inputContainer
:
(
provided
)
=>
({
...
provided
,
py
:
0
,
mx
:
0
,
}),
valueContainer
:
(
provided
,
state
)
=>
({
...
provided
,
...
getValueContainerStyles
(
state
.
selectProps
.
size
),
py
:
0
,
}),
singleValue
:
(
provided
,
state
)
=>
({
...
provided
,
mx
:
0
,
transform
:
'
none
'
,
...
getSingleValueStyles
(
state
.
selectProps
.
size
),
}),
};
};
export
{
c
hakraStyles
};
export
{
getC
hakraStyles
};
ui/shared/InputPlaceholder.tsx
View file @
f350b105
...
...
@@ -6,11 +6,10 @@ interface Props {
text
:
string
;
error
?:
Partial
<
FieldError
>
;
className
?:
string
;
isActive
?:
boolean
;
isFancy
?:
boolean
;
}
const
InputPlaceholder
=
({
text
,
error
,
className
,
is
Active
,
is
Fancy
}:
Props
)
=>
{
const
InputPlaceholder
=
({
text
,
error
,
className
,
isFancy
}:
Props
)
=>
{
let
errorMessage
=
error
?.
message
;
if
(
!
errorMessage
&&
error
?.
type
===
'
pattern
'
)
{
...
...
@@ -20,7 +19,6 @@ const InputPlaceholder = ({ text, error, className, isActive, isFancy }: Props)
return
(
<
FormLabel
className=
{
className
}
{
...
(
isActive
?
{
'
data
-
active
':
true
}
:
{})
}
{
...
(
isFancy
?
{
'
data
-
fancy
':
true
}
:
{})
}
>
<
chakra
.
span
>
{
text
}
</
chakra
.
span
>
...
...
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