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

웹 접근성 개선과 토스트 문서 추가 #86

Merged
merged 9 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
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
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ const Parent = () => {

return (
<>
<Button type="button" onClick={handleOpenBottomSheet}>
<button type="button" onClick={handleOpenBottomSheet}>
바텀시트 열기
</Button>
</button>
<BottomSheet ref={ref} isClosing={isClosing} close={handleCloseBottomSheet}>
<div>바텀시트 컴포넌트</div>
</BottomSheet>
Expand Down Expand Up @@ -133,7 +133,7 @@ const carouselList = [0, 1, 2].map((index) => ({

<br />

## **Checkbox**
## Checkbox

체크박스 컴포넌트입니다.

Expand Down Expand Up @@ -338,13 +338,27 @@ import {Link as RouterLink, NavLink} from 'react-router-dom'

### Props

| props | value | description |
| ------- | ------------------------------------------------------ | ------------------------------------------------ |
| resize? | both, horizontal, vertical, none<br /> (default: both) | Textarea 컴포넌트의 크기 재조정 방향 설정입니다. |
| props | value | description |
| ------------- | ------------------------------------------------------ | ------------------------------------------------ |
| resize? | both, horizontal, vertical, none<br /> (default: both) | Textarea 컴포넌트의 크기 재조정 방향 설정입니다. |
| errorMessage? | string | Textarea 컴포넌트의 에러 메시지입니다. |

### Example

```jsx
<Textarea />
<Textarea resize="vertical" rows={10} placeholder="값을 입력해주세요."/>
```

## Toast

알람을 띄우는 토스트 컴포넌트입니다.

### Example

```jsx
const { toast } = useToastActionContext();

toast.success('성공');
toast.error('실패');
```
16 changes: 15 additions & 1 deletion src/BottomSheet/useBottomSheet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useRef, useState } from 'react';
import type { KeyboardEventHandler } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';

export const useBottomSheet = () => {
const [isOpen, setIsOpen] = useState(false);
Expand All @@ -24,5 +25,18 @@ export const useBottomSheet = () => {
closeAnimated();
};

const handleKeydown = (e: KeyboardEvent) => {
if (e.keyCode === 27) {
e.preventDefault();
handleCloseBottomSheet();
}
};

useEffect(() => {
document.addEventListener('keydown', handleKeydown);

return () => document.removeEventListener('keydown', handleKeydown);
}, [handleKeydown]);

return { ref, isOpen, isClosing, handleOpenBottomSheet, handleCloseBottomSheet };
};
30 changes: 26 additions & 4 deletions src/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,44 @@ import { forwardRef } from 'react';
import type { CSSProperties, ComponentPropsWithRef } from 'react';
import styled from 'styled-components';

import theme from '../styles/theme';
import Text from '../Text/Text';

export interface TextareaProps extends ComponentPropsWithRef<'textarea'> {
/**
* Textarea 컴포넌트 사이즈 재조정 방향 설정입니다.
*/
resize?: CSSProperties['resize'];
/**
* Textarea 컴포넌트의 에러 메시지입니다.
*/
errorMessage?: string;
}

const Textarea = ({ resize = 'both', ref, ...props }: TextareaProps) => {
const Textarea = ({ resize = 'both', errorMessage, ref, ...props }: TextareaProps) => {
return (
<TextareaContainer ref={ref} resize={resize} autoCapitalize="off" autoCorrect="off" spellCheck="false" {...props} />
<>
<TextareaContainer
ref={ref}
resize={resize}
errorMessage={errorMessage}
autoCapitalize="off"
autoCorrect="off"
spellCheck="false"
{...props}
/>
<Text size="xs" color={theme.colors.error} aria-live="assertive">
{errorMessage}
</Text>
</>
);
};

export default forwardRef(Textarea);

type TextareaStyleProps = Pick<TextareaProps, 'resize'>;
type TextareaStyleProps = Pick<TextareaProps, 'resize'> & {
errorMessage?: string;
};

const TextareaContainer = styled.textarea<TextareaStyleProps>`
width: 100%;
Expand All @@ -27,7 +49,7 @@ const TextareaContainer = styled.textarea<TextareaStyleProps>`
border-radius: 0;
line-height: 1.5;
resize: ${({ resize }) => resize};
outline-color: ${({ theme }) => theme.colors.primary};
outline-color: ${({ errorMessage, theme }) => (errorMessage ? theme.colors.error : theme.colors.primary)};

&::placeholder {
color: ${({ theme }) => theme.textColors.disabled};
Expand Down
4 changes: 3 additions & 1 deletion src/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const Toast = ({ id, message, isError = false }: ToastProps) => {

return (
<ToastWrapper isError={isError} isAnimating={isShown}>
<Message color={theme.colors.white}>{message}</Message>
<Message color={theme.colors.white} aria-live="assertive">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{message}
</Message>
</ToastWrapper>
);
};
Expand Down