-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: auto resize text area 아이콘 추가 기능 구현 #196 * design : input 기본 컴포넌트 rounded 및 아이콘 반응형 추가 #196 * design : textarea 기본 컴포넌트 rounded 2x로 변경 #196 * design : iconBox 높이 40px로 변경 - chakra ui 기본 input박스와 맞추기 위해 40px로 수정 #196
- Loading branch information
1 parent
4bd9f1a
commit 28889b5
Showing
5 changed files
with
49 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,45 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import { Textarea, forwardRef } from '@chakra-ui/react'; | ||
import React from 'react'; | ||
import { Box, Flex, Textarea, forwardRef } from '@chakra-ui/react'; | ||
import ResizeTextarea from 'react-textarea-autosize'; | ||
|
||
import { AutoResizeTextareaProps } from './type'; | ||
|
||
const AutoResizeTextarea = forwardRef(({ ref, ...props }: AutoResizeTextareaProps) => ( | ||
<Textarea ref={ref} as={ResizeTextarea} overflow="hidden" w="100%" minH="unset" resize="none" {...props} /> | ||
)); | ||
const AutoResizeTextarea = forwardRef( | ||
( | ||
{ value, onChange, LeftIconButton, RightIconButton, ...props }: AutoResizeTextareaProps, | ||
ref: React.Ref<HTMLTextAreaElement>, | ||
) => { | ||
const rightChildCount = RightIconButton?.props.children?.length ?? 1; | ||
const leftChildCount = LeftIconButton?.props.children?.length ?? 1; | ||
|
||
const rightPadding = RightIconButton ? `${38 * rightChildCount}px` : '16px'; | ||
const leftPadding = LeftIconButton ? `${38 * leftChildCount}px` : '16px'; | ||
|
||
return ( | ||
<Flex pos="relative" w="100%"> | ||
<Box pos="absolute" zIndex="1" left="0" alignContent="center" h="40px"> | ||
{LeftIconButton} | ||
</Box> | ||
<Box w="100%"> | ||
<Textarea | ||
ref={ref} | ||
as={ResizeTextarea} | ||
w="100%" | ||
minH="40px" | ||
py="2" | ||
pr={rightPadding} | ||
pl={leftPadding} | ||
resize="none" | ||
onChange={onChange} | ||
value={value} | ||
{...props} | ||
/> | ||
</Box> | ||
<Box pos="absolute" zIndex="1" right="0" alignContent="center" h="40px"> | ||
{RightIconButton} | ||
</Box> | ||
</Flex> | ||
); | ||
}, | ||
); | ||
export default AutoResizeTextarea; |
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,3 +1,6 @@ | ||
export interface AutoResizeTextareaProps { | ||
ref?: React.Ref<HTMLTextAreaElement>; | ||
value: string; | ||
onChange: React.ChangeEventHandler<HTMLTextAreaElement>; | ||
LeftIconButton?: React.ReactElement; | ||
RightIconButton?: React.ReactElement; | ||
} |
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
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