Skip to content

Commit

Permalink
refactor: Input 컴포넌트 ref, onchange 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
from1to2 committed Nov 3, 2023
1 parent 3bb3694 commit f6cc37e
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 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 (
<>
const Input = React.forwardRef(
(
{
placeholder,
placeholderSize,
placeholderColor,
width,
height,
borderColor,
borderWidth,
borderRadius,
inputTextColor,
inputTextSize,
inputBackgroundColor,
onChange,
}: InputProps,
ref: ForwardedRef<HTMLInputElement>,
) => {
return (
<InputWrapper>
<StyleInput
ref={ref}
onChange={onChange}
placeholder={placeholder}
placeholderSize={placeholderSize}
placeholderColor={placeholderColor}
Expand All @@ -42,11 +50,12 @@ const Input = ({
inputTextSize={inputTextSize}
inputBackgroundColor={inputBackgroundColor}
borderRadius={borderRadius}
></StyleInput>
/>
</InputWrapper>
</>
)
}
)
},
)
Input.displayName = 'Input'

const InputWrapper = styled.div`
position: relative;
Expand All @@ -57,8 +66,6 @@ const StyleInput = styled.input<InputProps>`
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; // This should be adjusted if needed.
`

export default Input

0 comments on commit f6cc37e

Please sign in to comment.