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
fcf8ced4
Commit
fcf8ced4
authored
Jun 14, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
floating label basic implementation + colors for error
parent
46dc6e28
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
161 additions
and
2 deletions
+161
-2
index.tsx
pages/index.tsx
+7
-2
Form.ts
theme/components/Form.ts
+69
-0
Input.ts
theme/components/Input.ts
+71
-0
index.ts
theme/components/index.ts
+4
-0
getDefaultFormColors.ts
theme/utils/getDefaultFormColors.ts
+10
-0
No files found.
pages/index.tsx
View file @
fcf8ced4
import
React
from
'
react
'
;
import
type
{
NextPage
}
from
'
next
'
;
import
{
Center
}
from
'
@chakra-ui/react
'
;
import
{
Center
,
FormControl
,
Input
,
FormLabel
}
from
'
@chakra-ui/react
'
;
import
Page
from
'
../components/Page/Page
'
;
const
Home
:
NextPage
=
()
=>
{
return
(
<
Page
>
<
Center
h=
"100%"
>
Home Page
<
FormControl
variant=
"floating"
id=
"address"
isRequired
>
{
/* Placeholder should be present */
}
<
Input
placeholder=
" "
/>
{
/* It is important that the Label comes after the Control due to css selectors */
}
<
FormLabel
>
Address
</
FormLabel
>
</
FormControl
>
</
Center
>
</
Page
>
);
...
...
theme/components/Form.ts
0 → 100644
View file @
fcf8ced4
import
type
{
formAnatomy
as
parts
}
from
'
@chakra-ui/anatomy
'
;
import
type
{
ComponentStyleConfig
}
from
'
@chakra-ui/theme
'
;
import
{
getColor
}
from
'
@chakra-ui/theme-tools
'
;
import
type
{
StyleFunctionProps
,
PartsStyleFunction
}
from
'
@chakra-ui/theme-tools
'
;
import
getDefaultFormColors
from
'
../utils/getDefaultFormColors
'
;
const
activeLabelStyles
=
{
fontSize
:
'
12px
'
,
lineHeight
:
'
15px
'
,
top
:
'
10px
'
,
};
const
activeInputStyles
=
{
paddingTop
:
'
30px
'
,
paddingBottom
:
'
10px
'
,
};
const
variantFloating
:
PartsStyleFunction
<
typeof
parts
>
=
(
props
:
StyleFunctionProps
)
=>
{
const
{
theme
}
=
props
;
const
{
focusBorderColor
:
fc
,
errorBorderColor
:
ec
}
=
getDefaultFormColors
(
props
);
return
{
container
:
{
_focusWithin
:
{
label
:
{
...
activeLabelStyles
,
},
input
:
{
...
activeInputStyles
,
},
},
'
input:not(:placeholder-shown) + label
'
:
{
...
activeLabelStyles
,
},
'
input[aria-invalid=true] + label
'
:
{
color
:
getColor
(
theme
,
ec
),
},
label
:
{
top
:
'
20px
'
,
left
:
0
,
zIndex
:
2
,
position
:
'
absolute
'
,
color
:
getColor
(
theme
,
fc
),
backgroundColor
:
'
transparent
'
,
pointerEvents
:
'
none
'
,
padding
:
'
0 20px
'
,
margin
:
0
,
transformOrigin
:
'
left top
'
,
fontSize
:
'
16px
'
,
lineHeight
:
'
20px
'
,
transitionProperty
:
'
top, font-size, line-height
'
,
},
input
:
{
padding
:
'
20px
'
,
},
'
input:not(:placeholder-shown)
'
:
{
...
activeInputStyles
,
},
},
}
}
const
Form
:
ComponentStyleConfig
=
{
variants
:
{
floating
:
variantFloating
,
},
}
export
default
Form
;
theme/components/Input.ts
0 → 100644
View file @
fcf8ced4
import
type
{
inputAnatomy
as
parts
}
from
'
@chakra-ui/anatomy
'
;
import
type
{
ComponentStyleConfig
}
from
'
@chakra-ui/theme
'
;
import
type
{
PartsStyleFunction
,
SystemStyleObject
}
from
'
@chakra-ui/theme-tools
'
;
import
{
getColor
,
mode
}
from
'
@chakra-ui/theme-tools
'
;
import
getDefaultFormColors
from
'
../utils/getDefaultFormColors
'
;
const
sizes
:
Record
<
string
,
SystemStyleObject
>
=
{
md
:
{
fontSize
:
'
16px
'
,
lineHeight
:
'
20px
'
,
px
:
'
20px
'
,
py
:
'
20px
'
,
h
:
'
60px
'
,
borderRadius
:
'
base
'
,
},
}
const
variantOutline
:
PartsStyleFunction
<
typeof
parts
>
=
(
props
)
=>
{
const
{
theme
}
=
props
const
{
focusBorderColor
:
fc
,
errorBorderColor
:
ec
}
=
getDefaultFormColors
(
props
)
return
{
field
:
{
border
:
'
1px solid
'
,
borderColor
:
'
inherit
'
,
bg
:
'
inherit
'
,
_hover
:
{
borderColor
:
mode
(
'
gray.300
'
,
'
whiteAlpha.400
'
)(
props
),
},
_readOnly
:
{
boxShadow
:
'
none !important
'
,
userSelect
:
'
all
'
,
},
_disabled
:
{
opacity
:
0.4
,
cursor
:
'
not-allowed
'
,
},
_invalid
:
{
borderColor
:
getColor
(
theme
,
ec
),
boxShadow
:
`none`
,
},
_focusVisible
:
{
zIndex
:
1
,
borderColor
:
getColor
(
theme
,
fc
),
boxShadow
:
`none`
,
},
},
addon
:
{
border
:
'
1px solid
'
,
borderColor
:
mode
(
'
inherit
'
,
'
whiteAlpha.50
'
)(
props
),
bg
:
mode
(
'
gray.100
'
,
'
whiteAlpha.300
'
)(
props
),
},
}
}
const
Input
:
ComponentStyleConfig
=
{
sizes
:
{
md
:
{
field
:
sizes
.
md
,
addon
:
sizes
.
md
,
},
},
defaultProps
:
{
size
:
'
md
'
,
},
variants
:
{
outline
:
variantOutline
,
},
}
export
default
Input
;
theme/components/index.ts
View file @
fcf8ced4
...
...
@@ -2,12 +2,16 @@ import Switch from './Switch';
import
Button
from
'
./Button
'
;
import
Modal
from
'
./Modal
'
;
import
Table
from
'
./Table
'
;
import
Form
from
'
./Form
'
;
import
Input
from
'
./Input
'
;
const
components
=
{
Switch
,
Button
,
Modal
,
Table
,
Input
,
Form
,
}
export
default
components
;
theme/utils/getDefaultFormColors.ts
0 → 100644
View file @
fcf8ced4
import
type
{
StyleFunctionProps
}
from
'
@chakra-ui/theme-tools
'
;
import
{
mode
}
from
'
@chakra-ui/theme-tools
'
;
export
default
function
getDefaultFormColors
(
props
:
StyleFunctionProps
)
{
const
{
focusBorderColor
:
fc
,
errorBorderColor
:
ec
}
=
props
return
{
focusBorderColor
:
fc
||
mode
(
'
brand.700
'
,
'
brand.300
'
)(
props
),
errorBorderColor
:
ec
||
mode
(
'
red.400
'
,
'
red.300
'
)(
props
),
}
}
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