Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add float labels #775

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions src/components/elements/Input/Input.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useState } from 'react'
import { Box, Flex } from 'components/elements'
import { transition, colors } from 'theme'
import { transition, colors, space, fontSizes } from 'theme'
import styled from 'styled-components'
import { lighten } from 'polished'
import noop from 'lodash/noop'
Expand All @@ -18,11 +18,14 @@ const InputBase = styled(Text)(
border: 0,
appearance: 'none',
'&:focus': {
outline: '0',
boxShadow: `inset 0 0 0 1px ${colors.blue500}`
outline: '0'
// boxShadow: `inset 0 0 0 1px ${colors.blue500}`, Te lo comento por
},
'&:disabled': {
opacity: 1 / 4
},
'&::placeholder': {
opacity: 0
}
})
)
Expand All @@ -41,20 +44,34 @@ InputBase.defaultProps = {

const InputWrapper = styled(Flex)`
border: 1px solid;
border-color: ${({ isDark }) => (isDark ? colors.white20 : colors.black20)};
position: relative;
border-color: ${({ isFocusStyle }) =>
isFocusStyle ? colors.primary : colors.black20};
transition: border-color ${transition.medium}, stroke ${transition.medium},
color ${transition.medium};

${props =>
props.focus &&
`
outline: 0;
border-color: ${lighten(0.15, colors.link)}
outline: 0;
border-color: ${lighten(0.15, colors.link)}

svg {
stroke: ${lighten(0.15, colors.link)}
color: ${lighten(0.15, colors.link)}
}
`}
`

svg {
stroke: ${lighten(0.15, colors.link)}
color: ${lighten(0.15, colors.link)}
}
`}
const Label = styled(Text)`
font-size: ${fontSizes[1]} !important; /* de donde viene esta mierda */
position: absolute;
background-color: red;
transition: 0.15s ease-in-out;
background-color: white;
pointer-events: none;
left: ${space[2]};
top: ${props => (props.isFocusStyle ? '-14px' : space[2])};
`

const Input = ({
Expand All @@ -68,6 +85,8 @@ const Input = ({
...props
}) => {
const [isFocus, setFocus] = useState(props.autoFocus)
const [isFocusStyle, setFocusStyle] = useState(false)
const checkInput = event => event.target.value.length > 0

const list = useMemo(() => {
if (!suggestions) return undefined
Expand All @@ -86,16 +105,20 @@ const Input = ({
borderRadius={2}
focus={isFocus}
isDark={theme === 'dark'}
isFocusStyle={isFocusStyle}
>
<Label isFocusStyle={isFocusStyle}> {props.placeholder}</Label>
{Icon && <Box pl={2} pt={1} children={Icon} />}
<InputBase
list={list}
ref={innerRef}
onFocus={event => {
setFocusStyle(true)
setFocus(true)
return onFocus(event)
}}
onBlur={event => {
setFocusStyle(checkInput(event))
setFocus(false)
return onBlur(event)
}}
Expand Down