rare-sapphire
rare-sapphire6mo ago

How can i change sidebar icons ?

Hello, how can i easly change sidebar icons ?
3 Replies
kapa.ai
kapa.ai6mo ago
Hi @!!DETLIXX. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To change the sidebar icons in a Refine application, you can customize the Sider component. Here are the steps to achieve this: 1. Use a Custom Sider Component: You can create a custom Sider component and use the render prop to customize the sidebar content, including the icons. 2. Example Code: Below is an example of how to create a custom Sider component and use it in your layout:
import { Layout, Sider } from "@refinedev/antd";
import { useMenu } from "@refinedev/core";
import { HomeOutlined, UserOutlined } from "@ant-design/icons"; // Example icons from Ant Design

const CustomSider = () => {
const { menuItems } = useMenu();

return (
<Sider
render={({ items, logout }) => {
return (
<>
{menuItems.map((item) => (
<a key={item.key} href={item.route}>
{item.icon === "home" ? <HomeOutlined /> : <UserOutlined />}
{item.label}
</a>
))}
{logout}
</>
);
}}
/>
);
};

const CustomLayout = () => {
return <Layout Sider={CustomSider}>...</Layout>;
};

import { Layout, Sider } from "@refinedev/antd";
import { useMenu } from "@refinedev/core";
import { HomeOutlined, UserOutlined } from "@ant-design/icons"; // Example icons from Ant Design

const CustomSider = () => {
const { menuItems } = useMenu();

return (
<Sider
render={({ items, logout }) => {
return (
<>
{menuItems.map((item) => (
<a key={item.key} href={item.route}>
{item.icon === "home" ? <HomeOutlined /> : <UserOutlined />}
{item.label}
</a>
))}
{logout}
</>
);
}}
/>
);
};

const CustomLayout = () => {
return <Layout Sider={CustomSider}>...</Layout>;
};

3. Using the useMenu Hook: The useMenu hook can be used to get the menu items and customize their icons based on your requirements. For more information on the useMenu hook, refer to the useMenu hook documentation (https://refine.dev/docs/core/hooks/utilities/use-menu/). 4. Swizzle the Default Sider Component: If you need more extensive customization, you can use the swizzle command to copy the default Sider component to your project and modify it as needed. For more information, refer to the swizzle documentation (https://refine.dev/docs/packages/documentation/cli/#swizzle). By following these steps, you can easily change the sidebar icons in your Refine application. For more detailed information, you can refer to the Refine Sider documentation (https://refine.dev/docs/core/refine-component/#sider-). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai6mo ago
<@410826510841151498> kapa.ai is still learning and improving, please let us know how it did by reacting below
flat-fuchsia
flat-fuchsia6mo ago
Hello @!!DETLIXX, you can give meta.icon to resource array https://refine.dev/docs/core/refine-component/#icon to change icons

Did you find this page helpful?