-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ion input with styled components (#143)
- Loading branch information
1 parent
c99fa4b
commit 0e418b1
Showing
5 changed files
with
79 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
import { InputHTMLAttributes, useRef } from 'react'; | ||
import { InputType } from '../../core/types/input'; | ||
import { InputContainer, InputRow, InputStyles } from './styles'; | ||
import React from 'react'; | ||
import { Container, Input } from './styles'; | ||
|
||
export type InputProps = { | ||
placeholder?: string; | ||
type?: InputType; | ||
disabled?: boolean; | ||
}; | ||
} & InputHTMLAttributes<HTMLInputElement>; | ||
|
||
export const IonInput = ({ | ||
placeholder, | ||
type = 'text', | ||
disabled = false, | ||
...props | ||
}: InputProps) => { | ||
const ref = useRef<HTMLInputElement>(null); | ||
|
||
const handleContainerClick = () => { | ||
ref.current && ref.current.focus(); | ||
}; | ||
|
||
return ( | ||
<InputContainer> | ||
<InputRow disabled={disabled}> | ||
<InputStyles | ||
type={type} | ||
placeholder={placeholder} | ||
disabled={disabled} | ||
/> | ||
</InputRow> | ||
</InputContainer> | ||
<Container onClick={handleContainerClick} disabled={disabled}> | ||
<Input ref={ref} type={type} disabled={disabled} {...props} /> | ||
</Container> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,51 @@ | ||
import stitches from '../../stitches.config'; | ||
const { styled } = stitches; | ||
|
||
export const InputContainer = styled('div', { | ||
display: 'flex', | ||
lineHeight: '0', | ||
width: '100%', | ||
}); | ||
|
||
export const InputRow = styled('div', { | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: '8px', | ||
background: '$neutral1', | ||
border: '1px solid $neutral5', | ||
borderRadius: '8px', | ||
padding: '8px 12px', | ||
width: '100%', | ||
|
||
variants: { | ||
disabled: { | ||
true: { | ||
background: '$neutral2', | ||
border: '1px solid $neutral4', | ||
cursor: 'not-allowed', | ||
outline: 'none', | ||
color: '$neutral4', | ||
|
||
'&:hover': { | ||
borderColor: '$neutral4', | ||
}, | ||
|
||
'::placeholder': { | ||
color: '$neutral5', | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
'&:focus-within': { | ||
borderColor: '$primary5', | ||
outline: '2px solid', | ||
outlineColor: '$primary2', | ||
}, | ||
|
||
'&:hover': { | ||
borderColor: '$primary4', | ||
}, | ||
}); | ||
|
||
export const InputStyles = styled('input', { | ||
border: 'none', | ||
width: '100%', | ||
outline: 'none', | ||
color: '$neutral7', | ||
background: '$neutral1', | ||
fontSize: '14px', | ||
|
||
'&[disabled]': { | ||
background: '$neutral2', | ||
cursor: 'not-allowed', | ||
outline: 'none', | ||
}, | ||
}); | ||
import { css, styled } from 'styled-components'; | ||
|
||
export const Container = styled.div<{ disabled: boolean }>` | ||
${({ theme }) => css` | ||
${theme.utils.flex.start(8)}; | ||
width: 100%; | ||
background: ${theme.colors.neutral[1]}; | ||
border: 1px solid ${theme.colors.neutral[5]}; | ||
border-radius: 8px; | ||
padding: 0.8rem 1.2rem; | ||
cursor: text; | ||
${theme.utils.focus}; | ||
&:hover { | ||
border-color: ${theme.colors.primary[4]}; | ||
} | ||
&:focus-within { | ||
border-color: ${theme.colors.primary[5]}; | ||
} | ||
&[disabled] { | ||
cursor: not-allowed; | ||
outline: none; | ||
background: ${theme.colors.neutral[2]}; | ||
color: ${theme.colors.neutral[4]}; | ||
border-color: ${theme.colors.neutral[4]}; | ||
&::placeholder { | ||
color: ${theme.colors.neutral[4]}; | ||
} | ||
} | ||
`} | ||
`; | ||
|
||
export const Input = styled.input` | ||
${({ theme }) => css` | ||
${theme.font.size[14]} | ||
border: none; | ||
width: 100%; | ||
outline: none; | ||
color: ${theme.colors.neutral[7]}; | ||
background: ${theme.colors.neutral[1]}; | ||
&:disabled { | ||
background: ${theme.colors.neutral[2]}; | ||
cursor: not-allowed; | ||
outline: none; | ||
} | ||
`} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters