Icon API
Icon API (아이콘 API)
Icon은 아이콘 폰트(예: Material Icons)를 렌더링하는 컴포넌트예요. 이 페이지에서는 이 컴포넌트의 props, CSS 클래스, 그리고 기타 API를 하나씩 설명해 드릴게요.
출처: 문서
본문
데모 (Demos)
이 React 컴포넌트의 사용법과 세부 사항은 컴포넌트 데모 페이지에서 확인할 수 있어요.
- Icons
- Material Icons
Import
import Icon from '@mui/material/Icon';
// 또는
import { Icon } from '@mui/material';
번들 크기를 줄이는 방법이 궁금하시다면, 이 차이에 대한 가이드 문서를 읽어 보시면 좋아요.
Props
네이티브 컴포넌트의 props도 그대로 사용할 수 있어요.
| Name | Type | Default | Description |
|---|---|---|---|
| baseClassName | string | 'material-icons' | The base class applied to the icon. Defaults to 'material-icons', but can be changed to any other base class that suits the icon font you're using (for example material-icons-rounded, fas, etc). |
| children | node | - | The name of the icon font ligature. |
| classes | object | - | Override or extend the styles applied to the component. See CSS classes API below for more details. |
| color | 'inherit'| 'action'| 'disabled'| 'primary'| 'secondary'| 'error'| 'info'| 'success'| 'warning'| string | 'inherit' | The color of the component. It supports both default and custom theme colors, which can be added as shown in the palette customization guide. |
| component | elementType | - | The component used for the root node. Either a string to use a HTML element or a component. |
| fontSize | 'inherit'| 'large'| 'medium'| 'small'| string | 'medium' | The fontSize applied to the icon. Defaults to 24px, but can be configure to inherit font size. |
| sx | Array<func| object| bool>| func| object | - | The system prop that allows defining system overrides as well as additional CSS styles. See the sx page for more details. |
ref는 루트 요소로 전달돼요.
테마 기본 props (Theme default props)
MuiIcon을 사용하면 테마를 통해 이 컴포넌트의 기본 props를 바꿀 수 있어요.
CSS 클래스 (CSS classes)
이 클래스들은 CSS로 스타일을 지정할 때 유용해요. 특정 상태가 트리거되면 컴포넌트의 슬롯에 적용돼요.
| Class name | Rule name | Description |
|---|---|---|
| .MuiIcon-colorAction | colorAction | Styles applied to the root element if color="action". |
| .MuiIcon-colorDisabled | colorDisabled | Styles applied to the root element if color="disabled". |
| .MuiIcon-colorError | colorError | Styles applied to the root element if color="error". |
| .MuiIcon-colorPrimary | colorPrimary | Styles applied to the root element if color="primary". |
| .MuiIcon-colorSecondary | colorSecondary | Styles applied to the root element if color="secondary". |
| .MuiIcon-fontSizeInherit | fontSizeInherit | Styles applied to the root element if fontSize="inherit". |
| .MuiIcon-fontSizeLarge | fontSizeLarge | Styles applied to the root element if fontSize="large". |
| .MuiIcon-fontSizeSmall | fontSizeSmall | Styles applied to the root element if fontSize="small". |
| .MuiIcon-root | root | Styles applied to the root element. |
컴포넌트의 스타일을 다음 방법 중 하나로 재정의할 수 있어요.
- 전역 클래스 이름으로 재정의하기
- 커스텀 테마의 컴포넌트
styleOverrides속성에 규칙 이름(rule name)으로 재정의하기
소스 코드 (Source code)
이 페이지에서 원하는 정보를 찾지 못했다면, 컴포넌트의 구현 코드를 살펴보시면 더 자세한 내용을 확인할 수 있어요.