Skip to content

Commit

Permalink
refactor: Input 컴포넌트 ref, onchange 추가 (#90)
Browse files Browse the repository at this point in the history
* refactor: Input 컴포넌트 ref, onchange 추가

* refactor: pr 수정사항 반영
  • Loading branch information
from1to2 authored Nov 8, 2023
1 parent 4f9db62 commit 2ea0a9a
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions src/components/common/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from '@emotion/styled'
import React, { ForwardedRef } from 'react'

type InputProps = {
placeholder?: string
Expand All @@ -12,25 +13,32 @@ type InputProps = {
inputTextSize?: string
inputBackgroundColor?: string
borderRadius?: string
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
}

const Input = ({
placeholder,
placeholderSize,
placeholderColor,
width,
height,
borderColor,
borderWidth,
borderRadius,
inputTextColor,
inputTextSize,
inputBackgroundColor,
}: InputProps) => {
return (
<>
<InputWrapper>
<StyleInput
const Input = React.forwardRef(
(
{
placeholder,
placeholderSize,
placeholderColor,
width,
height,
borderColor,
borderWidth,
borderRadius,
inputTextColor,
inputTextSize,
inputBackgroundColor,
onChange,
}: InputProps,
ref: ForwardedRef<HTMLInputElement>,
) => {
return (
<StyledInputWrapper>
<StyledInput
ref={ref}
onChange={onChange}
placeholder={placeholder}
placeholderSize={placeholderSize}
placeholderColor={placeholderColor}
Expand All @@ -42,23 +50,22 @@ const Input = ({
inputTextSize={inputTextSize}
inputBackgroundColor={inputBackgroundColor}
borderRadius={borderRadius}
></StyleInput>
</InputWrapper>
</>
)
}
/>
</StyledInputWrapper>
)
},
)
Input.displayName = 'Input'

const InputWrapper = styled.div`
const StyledInputWrapper = styled.div`
position: relative;
`

const StyleInput = styled.input<InputProps>`
const StyledInput = styled.input<InputProps>`
::placeholder {
font-size: ${(props) => props.placeholderSize};
color: ${(props) => props.placeholderColor};
}
position: relative;
placeholder: ${(props) => props.placeholder};
width: ${(props) => props.width};
height: ${(props) => props.height};
border-color: ${(props) => props.borderColor};
Expand All @@ -67,6 +74,7 @@ const StyleInput = styled.input<InputProps>`
background-color: ${(props) => props.inputBackgroundColor};
border-radius: ${(props) => props.borderRadius};
font-size: ${(props) => props.inputTextSize};
position: relative;
`

export default Input

0 comments on commit 2ea0a9a

Please sign in to comment.