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 7 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
19 changes: 16 additions & 3 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 @@ -348,3 +348,16 @@ import {Link as RouterLink, NavLink} from 'react-router-dom'
<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 };
};
29 changes: 26 additions & 3 deletions src/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { forwardRef } from 'react';
import type { CSSProperties, ComponentPropsWithRef } from 'react';
import styled from 'styled-components';

import useValidator from '../hooks/useSpaceValidator';
import theme from '../styles/theme';
import Text from '../Text/Text';

export interface TextareaProps extends ComponentPropsWithRef<'textarea'> {
/**
* Textarea 컴포넌트 사이즈 재조정 방향 설정입니다.
Expand All @@ -10,14 +14,33 @@ export interface TextareaProps extends ComponentPropsWithRef<'textarea'> {
}

const Textarea = ({ resize = 'both', ref, ...props }: TextareaProps) => {
const { value, error, handleChange } = useValidator();
Copy link
Collaborator

Choose a reason for hiding this comment

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

그럼 요거가 삭제되겠네요!


return (
<TextareaContainer ref={ref} resize={resize} autoCapitalize="off" autoCorrect="off" spellCheck="false" {...props} />
<>
<TextareaContainer
value={value}
ref={ref}
resize={resize}
error={error}
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 친구랑

autoCapitalize="off"
autoCorrect="off"
spellCheck="false"
onChange={handleChange}
{...props}
/>
<Text size="xs" color={theme.colors.error} aria-live="assertive">
{error}
</Text>
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 친구는 여기 남기고

</>
);
};

export default forwardRef(Textarea);

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

const TextareaContainer = styled.textarea<TextareaStyleProps>`
width: 100%;
Expand All @@ -27,7 +50,7 @@ const TextareaContainer = styled.textarea<TextareaStyleProps>`
border-radius: 0;
line-height: 1.5;
resize: ${({ resize }) => resize};
outline-color: ${({ theme }) => theme.colors.primary};
outline-color: ${({ error, theme }) => (error ? 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
24 changes: 24 additions & 0 deletions src/hooks/useSpaceValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { ChangeEventHandler } from 'react';
import { useState } from 'react';

const useSpaceValidator = (initialValue = '') => {
const [value, setValue] = useState(initialValue);
const [error, setError] = useState('');

const handleChange: ChangeEventHandler<HTMLTextAreaElement> = (e) => {
const newValue = e.target.value;
setValue(newValue);

const isWhitespaceOnly = !newValue.trim() && newValue.length > 2;
const isConsecutiveSpaces = /\s{10,}/.test(newValue);
const isConsecutiveNewlines = /\n{4,}/.test(newValue);

isWhitespaceOnly || isConsecutiveSpaces || isConsecutiveNewlines
? setError('의미 있는 리뷰를 작성해보는 건 어떨까요? 🫨')
: setError('');
};

return { value, error, handleChange };
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 훅은 사용처에서 작성해도 될거 같아요.
함수만 제공해도 될 거 같다고 했는데, 이건 사용처에서 처리하는 부분이라 common한 부분은 아닌거 같아서..! 아싸리 펀잇에서 작성하는건 어떤가요??


export default useSpaceValidator;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { default as FunEatProvider } from './FunEatProvider';

export { default as theme } from './styles/theme';
export { default as useTheme } from './hooks/useTheme';
export { default as useSpaceValidator } from './hooks/useSpaceValidator';

export { default as Badge } from './Badge';
export { default as BottomSheet } from './BottomSheet';
Expand Down