2022-03-02 10:18:45 +01:00
|
|
|
# Icons
|
|
|
|
|
2023-01-09 08:11:32 +01:00
|
|
|
Icons are loaded using [@svgr/webpack](https://www.npmjs.com/package/@svgr/webpack).
|
|
|
|
This is configured in [element-web](https://github.com/vector-im/element-web/blob/develop/webpack.config.js#L458).
|
2022-03-02 10:18:45 +01:00
|
|
|
|
2023-01-09 08:11:32 +01:00
|
|
|
Each `.svg` exports a `ReactComponent` at the named export `Icon`.
|
2022-03-02 10:18:45 +01:00
|
|
|
Icons have `role="presentation"` and `aria-hidden` automatically applied. These can be overriden by passing props to the icon component.
|
|
|
|
|
2023-01-09 08:11:32 +01:00
|
|
|
SVG file recommendations:
|
|
|
|
|
2024-12-02 10:39:36 +01:00
|
|
|
- Colours should not be defined absolutely. Use `currentColor` instead.
|
|
|
|
- SVG files should be taken from the design compound as they are. Some icons contain special padding.
|
|
|
|
This means that there should be icons for each size, e.g. warning-16px and warning-32px.
|
2023-01-09 08:11:32 +01:00
|
|
|
|
|
|
|
Example usage:
|
2022-12-12 12:24:14 +01:00
|
|
|
|
2022-03-02 10:18:45 +01:00
|
|
|
```
|
|
|
|
import { Icon as FavoriteIcon } from 'res/img/element-icons/favorite.svg';
|
|
|
|
|
|
|
|
const MyComponent = () => {
|
|
|
|
return <>
|
2023-01-09 08:11:32 +01:00
|
|
|
<FavoriteIcon className="mx_Icon mx_Icon_16">
|
2022-03-02 10:18:45 +01:00
|
|
|
</>;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2023-01-09 08:11:32 +01:00
|
|
|
If possible, use the icon classes from [here](../res/css/compound/_Icon.pcss).
|
2022-03-02 10:18:45 +01:00
|
|
|
|
2023-01-09 08:11:32 +01:00
|
|
|
## Custom styling
|
2022-03-02 10:18:45 +01:00
|
|
|
|
2023-01-09 08:11:32 +01:00
|
|
|
Icon components are svg elements and may be custom styled as usual.
|
|
|
|
|
|
|
|
`_MyComponents.pcss`:
|
|
|
|
|
|
|
|
```css
|
2022-03-02 10:18:45 +01:00
|
|
|
.mx_MyComponent-icon {
|
|
|
|
height: 20px;
|
|
|
|
width: 20px;
|
|
|
|
|
|
|
|
* {
|
|
|
|
fill: $accent;
|
|
|
|
}
|
|
|
|
}
|
2023-01-09 08:11:32 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
`MyComponent.tsx`:
|
2022-03-02 10:18:45 +01:00
|
|
|
|
2023-01-09 08:11:32 +01:00
|
|
|
```typescript
|
2022-03-02 10:18:45 +01:00
|
|
|
import { Icon as FavoriteIcon } from 'res/img/element-icons/favorite.svg';
|
|
|
|
|
|
|
|
const MyComponent = () => {
|
|
|
|
return <>
|
|
|
|
<FavoriteIcon className="mx_MyComponent-icon" role="img" aria-hidden="false">
|
|
|
|
</>;
|
|
|
|
}
|
2022-07-15 15:53:23 +02:00
|
|
|
```
|