[KAPA-AI] Dark mode
How do I introduce dark mode / light mode functionality to my CRM Refine Example?
IconMoonStars and IconSun icons in your project, you need to ensure that you have the @tabler/icons-react package installed. This package provides a wide range of icons, including the ones you need.extendTheme function provided by Chakra UI or Mantine, depending on which UI framework you are using. Below are the steps for both Chakra UI and Mantine.``tsx
import React, { useState } from "react";
import { Form, Input, Button, Space } from "antd";
const DynamicForm = () => {
const [fields, setFields] = useState([
{ name: ["firstName"], value: "" },
{ name: ["lastName"], value: "" },
]);
const onFinish = (values) => {
console.log("Received values:", values);
};
const addField = () => {
setFields([...fields, { name: [field${fields.length}`], value: "" }]);Field ${index + 1}}DocumentTitleHandler component. This component generates the document title based on the current resource and action, with a default suffix of "Refine". If you want to customize this behavior, you can provide a custom handler function to the DocumentTitleHandler.``tsx
const App = () => {{
return (
<BrowserRouter>
<Refine
/* ... */
>
{/* ... */}
<DocumentTitleHandler
handler={({{ action, params, resource }}) => {{
const id = params?.id ?? "";
const actionPrefixMatcher = {{
create: "Create new ",
clone: #${{id}} Clone ${{resource?.meta?.label}},
edit: #${{id}} Edit ${{resource?.meta?.label}},
show: #${{id}} Show ${{resource?.meta?.label}},
list: ${{resource?.meta?.label}}`,IconMoonStarsIconSun@tabler/icons-reactextendTheme**Community Member 31**: You can find the schema design by going to <https://lucasconstantino.github.io/graphiql-online/>
change the end point to api.crm.refine/dev/graphql
add:
{
__schema {
types {
name
kind
fields {
name
type {
name
kind
}
}
}
}
}
click play**Community Member 31**: You can find the schema design by going to <https://lucasconstantino.github.io/graphiql-online/>
change the end point to api.crm.refine/dev/graphql
add:
{
__schema {
types {
name
kind
fields {
name
type {
name
kind
}
}
}
}
}
click play``tsx
import React, { useState } from "react";
import { Form, Input, Button, Space } from "antd";
const DynamicForm = () => {
const [fields, setFields] = useState([
{ name: ["firstName"], value: "" },
{ name: ["lastName"], value: "" },
]);
const onFinish = (values) => {
console.log("Received values:", values);
};
const addField = () => {
setFields([...fields, { name: [Field ${index + 1}3. **Integrate the Dynamic Form Component:**
You can integrate the `DynamicForm` component into your Refine CRM application by including it in the appropriate page or layout.DocumentTitleHandlerDocumentTitleHandler``tsx
const App = () => {{
return (
<BrowserRouter>
<Refine
/* ... */
>
{/* ... */}
<DocumentTitleHandler
handler={({{ action, params, resource }}) => {{
const id = params?.id ?? "";
const actionPrefixMatcher = {{
create: "Create new ",
clone: ,
edit: ,
show: ,
list: import { Space, Button } from "antd";
import { FC } from "react";
import { IconMoonStars, IconSun } from "@tabler/icons-react"; // Ensure you have these icons or replace them with your own
interface HeaderProps {
theme: "light" | "dark";
setTheme: (theme: "light" | "dark") => void;
}
const Header: FC<HeaderProps> = (props) => {
return (
<Space
direction="vertical"
align="end"
style={{
padding: "1rem",
}}
>
<Button
onClick={() => {
props.setTheme(props.theme === "light" ? "dark" : "light");
}}
icon={props.theme === "light" ? <IconMoonStars /> : <IconSun />}
/>
</Space>
);
};
export default Header; import { Space, Button } from "antd";
import { FC } from "react";
import { IconMoonStars, IconSun } from "@tabler/icons-react"; // Ensure you have these icons or replace them with your own
interface HeaderProps {
theme: "light" | "dark";
setTheme: (theme: "light" | "dark") => void;
}
const Header: FC<HeaderProps> = (props) => {
return (
<Space
direction="vertical"
align="end"
style={{
padding: "1rem",
}}
>
<Button
onClick={() => {
props.setTheme(props.theme === "light" ? "dark" : "light");
}}
icon={props.theme === "light" ? <IconMoonStars /> : <IconSun />}
/>
</Space>
);
};
export default Header; npm install @tabler/icons-react
# or
yarn add @tabler/icons-react import { Refine } from "@refinedev/core";
import { ThemedLayoutV2 } from "@refinedev/antd";
import { ConfigProvider, theme } from "antd";
import { useState } from "react";
import Header from "./Header"; // Adjust the import path as necessary
const App: React.FC = () => {
const [currentTheme, setCurrentTheme] = useState<"light" | "dark">("dark");
return (
<ConfigProvider
theme={{
algorithm:
currentTheme === "light"
? theme.defaultAlgorithm
: theme.darkAlgorithm,
}}
>
<Refine
/* ... */
>
<ThemedLayoutV2 Header={() => <Header theme={currentTheme} setTheme={setCurrentTheme} />}>
{/* ... */}
</ThemedLayoutV2>
</Refine>
</ConfigProvider>
);
};
export default App; import { ChakraProvider, extendTheme } from "@chakra-ui/react";
import { RefineThemes } from "@refinedev/chakra-ui"; const customTheme = extendTheme({
...RefineThemes.Blue, // Start with a base theme
colors: {
primary: {
50: "#e3f2f9",
100: "#c5e4f3",
200: "#a2d4ec",
300: "#7ac1e4",
400: "#47a9da",
500: "#0088cc", // Custom primary color
600: "#007ab8",
700: "#006ba1",
800: "#005885",
900: "#003f5e",
},
// Add other custom colors here
},
}); const App = () => {
return (
<ChakraProvider theme={customTheme}>
<BrowserRouter>
<Refine
/* ... */
>
<Routes>
<Route
element={
<ThemedLayoutV2>
<Outlet />
</ThemedLayoutV2>
}
>
<Route path="posts">
<Route index element={<PostList />} />
<Route path="create" element={<PostCreate />} />
<Route path="edit/:id" element={<PostEdit />} />
</Route>
<Route path="*" element={<ErrorComponent />} />
</Route>
</Routes>
</Refine>
</BrowserRouter>
</ChakraProvider>
);
};
export default App; import { MantineProvider, extendTheme } from "@mantine/core";
import { RefineThemes } from "@refinedev/mantine"; const customTheme = {
...RefineThemes.Blue, // Start with a base theme
colors: {
primary: [
"#e3f2f9",
"#c5e4f3",
"#a2d4ec",
"#7ac1e4",
"#47a9da",
"#0088cc", // Custom primary color
"#007ab8",
"#006ba1",
"#005885",
"#003f5e",
],
// Add other custom colors here
},
}; import { ConfigProvider } from "antd";
import { RefineThemes } from "@refinedev/antd"; const customTheme = {
token: {
colorPrimary: "#1DA57A", // Custom primary color
// Add other custom tokens here
},
}; import { Refine } from "@refinedev/core";
import { ThemedLayoutV2 } from "@refinedev/antd";
import { BrowserRouter, Route, Routes, Outlet } from "react-router-dom";
import { useState } from "react";
const App: React.FC = () => {
const [currentTheme, setCurrentTheme] = useState<"light" | "dark">("light");
return (
<ConfigProvider
theme={{
...customTheme,
algorithm:
currentTheme === "light"
? theme.defaultAlgorithm
: theme.darkAlgorithm,
}}
>
<Refine
/* ... */
>
<ThemedLayoutV2>
<BrowserRouter>
<Routes>
<Route path="/" element={<Outlet />}>
{/* Define your routes here */}
</Route>
</Routes>
</BrowserRouter>
</ThemedLayoutV2>
</Refine>
</ConfigProvider>
);
};
export default App; npm create refine-app@latest -- --example blog-refine-antd-dynamic-form import {{ BrowserRouter }} from "react-router-dom";
import {{ DocumentTitleHandler }} from "@refinedev/react-router-v6";
import {{ Refine }} from "@refinedev/core"; {
__schema {
types {
name
kind
fields {
name
type {
name
kind
}
}
}
}
} {
__schema {
types {
name
kind
fields {
name
type {
name
kind
}
}
}
}
}