X 프로바이더
X 프로바이더 (XProvider)
@ant-design/x 컴포넌트에 전역 설정을 제공하는 프로바이더 컴포넌트예요.
출처: 문서
본문
사용법
XProvider는 antd의 ConfigProvider를 확장해서 @ant-design/x 컴포넌트에 전역 설정을 제공해요.
이미 antd의 ConfigProvider를 사용 중이라면 코드를 아래처럼 바꿔주세요:
- import { ConfigProvider } from 'antd';
+ import { XProvider } from '@ant-design/x';
const App = () => (
- <ConfigProvider>
+ <XProvider>
<YourApp />
- </ConfigProvider>
+ </XProvider>
);
예시
- 로케일 (Locale)
- 방향 (Direction)
- 테마 (Theme)
- 단축키 (Shortcut Key)
Locale
프로젝트에서 antd를 사용한다면 antd의 locale을 XProvider에 병합해야 해요
import { XProvider } from '@ant-design/x';
import zhCN from 'antd/locale/zh_CN';
import zhCN_X from '@ant-design/x/locale/zh_CN';
<XProvider locale={{...zhCN_X,...zhCN}}>
<App />
</XProvider>
API
XProvider는 antd의 ConfigProvider를 완전히 확장해요. props 참고: Antd ConfigProvider
컴포넌트 설정
| 속성 | 설명 | 타입 | 기본값 | 버전 |
|---|---|---|---|---|
| bubble | Bubble 컴포넌트의 전역 설정 | {style: React.CSSProperties; styles: Record<string, React.CSSProperties>;className: string; classNames: Record<string, string>;} | - | - |
| conversations | Conversations 컴포넌트의 전역 설정 | {style: React.CSSProperties; styles: Record<string, React.CSSProperties>;className: string; classNames: Record<string, string>;shortcutKeys: {items?: ShortcutKeys<'number'> | ShortcutKeys[]}} | - | - |
| prompts | Prompts 컴포넌트의 전역 설정 | {style: React.CSSProperties; styles: Record<string, React.CSSProperties>;className: string; classNames: Record<string, string>;} | - | - |
| sender | Sender 컴포넌트의 전역 설정 | {style: React.CSSProperties; styles: Record<string, React.CSSProperties>;className: string; classNames: Record<string, string>;} | - | - |
| suggestion | Suggestion 컴포넌트의 전역 설정 | {style: React.CSSProperties; className: string;} | - | |
| thoughtChain | ThoughtChain 컴포넌트의 전역 설정 | {style: React.CSSProperties; styles: Record<string, React.CSSProperties>;className: string; classNames: Record<string, string>;} | - | |
| actions | Actions 컴포넌트의 전역 설정 | {style: React.CSSProperties; className: string;} | - |
ShortcutKeys
type SignKeysType = {
Ctrl: keyof KeyboardEvent;
Alt: keyof KeyboardEvent;
Meta: keyof KeyboardEvent;
Shift: keyof KeyboardEvent;
};
type ShortcutKeys<CustomKey = number | 'number'> =
| [keyof SignKeysType, keyof SignKeysType, CustomKey]
| [keyof SignKeysType, CustomKey];
더 알아보기
테마 커스터마이징 방법은 'create-react-app과 함께 사용하기' 문서의 Custom Theme 절도 참고할 만해요. 컴포넌트들의 실제 활용은 'Ant Design X 소개' 문서를 함께 보면 좋아요.