feat: Add clickable dashboard cards and theme color selector
Some checks failed
CI / style (push) Has been cancelled
CI / build-client (push) Has been cancelled
CI / build-amd64 (push) Has been cancelled
CI / build-tester (push) Has been cancelled
CI / test (cockroachdb) (push) Has been cancelled
CI / test (mariadb) (push) Has been cancelled
CI / test (postgres) (push) Has been cancelled
CI / test (sqlite) (push) Has been cancelled
CI / build-arm64 (push) Has been cancelled
CI / build-armv7 (push) Has been cancelled
CI / publish-images (push) Has been cancelled
CI / publish-release (push) Has been cancelled
Some checks failed
CI / style (push) Has been cancelled
CI / build-client (push) Has been cancelled
CI / build-amd64 (push) Has been cancelled
CI / build-tester (push) Has been cancelled
CI / test (cockroachdb) (push) Has been cancelled
CI / test (mariadb) (push) Has been cancelled
CI / test (postgres) (push) Has been cancelled
CI / test (sqlite) (push) Has been cancelled
CI / build-arm64 (push) Has been cancelled
CI / build-armv7 (push) Has been cancelled
CI / publish-images (push) Has been cancelled
CI / publish-release (push) Has been cancelled
- Dashboard cards now link to list page when clicked (except + button) - Added theme color selector in Settings (orange, teal, red, green, blue) - Theme persists in localStorage Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -348,6 +348,14 @@
|
|||||||
"round_prices": {
|
"round_prices": {
|
||||||
"label": "Round prices",
|
"label": "Round prices",
|
||||||
"tooltip": "Round prices to the nearest whole number."
|
"tooltip": "Round prices to the nearest whole number."
|
||||||
|
},
|
||||||
|
"theme_color": {
|
||||||
|
"label": "Theme Color",
|
||||||
|
"orange": "Orange",
|
||||||
|
"teal": "Teal",
|
||||||
|
"red": "Red",
|
||||||
|
"green": "Green",
|
||||||
|
"blue": "Blue"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"backup": {
|
"backup": {
|
||||||
|
|||||||
@@ -1,24 +1,43 @@
|
|||||||
import { ConfigProvider, theme } from "antd";
|
import { ConfigProvider, theme } from "antd";
|
||||||
import { createContext, PropsWithChildren, useEffect, useState } from "react";
|
import { createContext, PropsWithChildren, useEffect, useState } from "react";
|
||||||
|
|
||||||
|
// Theme color options
|
||||||
|
export const THEME_COLORS = {
|
||||||
|
orange: "#f97316",
|
||||||
|
teal: "#0891b2",
|
||||||
|
red: "#dc2626",
|
||||||
|
green: "#16a34a",
|
||||||
|
blue: "#2563eb",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type ThemeColorKey = keyof typeof THEME_COLORS;
|
||||||
|
|
||||||
type ColorModeContextType = {
|
type ColorModeContextType = {
|
||||||
mode: string;
|
mode: string;
|
||||||
setMode: (mode: string) => void;
|
setMode: (mode: string) => void;
|
||||||
|
themeColor: ThemeColorKey;
|
||||||
|
setThemeColor: (color: ThemeColorKey) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ColorModeContext = createContext<ColorModeContextType>({} as ColorModeContextType);
|
export const ColorModeContext = createContext<ColorModeContextType>({} as ColorModeContextType);
|
||||||
|
|
||||||
export const ColorModeContextProvider: React.FC<PropsWithChildren> = ({ children }) => {
|
export const ColorModeContextProvider: React.FC<PropsWithChildren> = ({ children }) => {
|
||||||
const colorModeFromLocalStorage = localStorage.getItem("colorMode");
|
const colorModeFromLocalStorage = localStorage.getItem("colorMode");
|
||||||
|
const themeColorFromLocalStorage = localStorage.getItem("themeColor") as ThemeColorKey | null;
|
||||||
const isSystemPreferenceDark = window?.matchMedia("(prefers-color-scheme: dark)").matches;
|
const isSystemPreferenceDark = window?.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||||
|
|
||||||
const systemPreference = isSystemPreferenceDark ? "dark" : "light";
|
const systemPreference = isSystemPreferenceDark ? "dark" : "light";
|
||||||
const [mode, setMode] = useState(colorModeFromLocalStorage || systemPreference);
|
const [mode, setMode] = useState(colorModeFromLocalStorage || systemPreference);
|
||||||
|
const [themeColor, setThemeColorState] = useState<ThemeColorKey>(themeColorFromLocalStorage || "teal");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.localStorage.setItem("colorMode", mode);
|
window.localStorage.setItem("colorMode", mode);
|
||||||
}, [mode]);
|
}, [mode]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.localStorage.setItem("themeColor", themeColor);
|
||||||
|
}, [themeColor]);
|
||||||
|
|
||||||
const setColorMode = () => {
|
const setColorMode = () => {
|
||||||
if (mode === "light") {
|
if (mode === "light") {
|
||||||
setMode("dark");
|
setMode("dark");
|
||||||
@@ -27,22 +46,28 @@ export const ColorModeContextProvider: React.FC<PropsWithChildren> = ({ children
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setThemeColor = (color: ThemeColorKey) => {
|
||||||
|
setThemeColorState(color);
|
||||||
|
};
|
||||||
|
|
||||||
const { darkAlgorithm, defaultAlgorithm } = theme;
|
const { darkAlgorithm, defaultAlgorithm } = theme;
|
||||||
|
const primaryColor = THEME_COLORS[themeColor];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ColorModeContext.Provider
|
<ColorModeContext.Provider
|
||||||
value={{
|
value={{
|
||||||
setMode: setColorMode,
|
setMode: setColorMode,
|
||||||
mode,
|
mode,
|
||||||
|
themeColor,
|
||||||
|
setThemeColor,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ConfigProvider
|
<ConfigProvider
|
||||||
// you can change the theme colors here. example: ...RefineThemes.Magenta,
|
|
||||||
theme={{
|
theme={{
|
||||||
algorithm: mode === "light" ? defaultAlgorithm : darkAlgorithm,
|
algorithm: mode === "light" ? defaultAlgorithm : darkAlgorithm,
|
||||||
token: {
|
token: {
|
||||||
colorPrimary: "#0891b2",
|
colorPrimary: primaryColor,
|
||||||
colorInfo: "#0891b2",
|
colorInfo: primaryColor,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -38,16 +38,21 @@ export const Home: React.FC<IResourceComponentsProps> = () => {
|
|||||||
<Col xs={12} md={6}>
|
<Col xs={12} md={6}>
|
||||||
<Card
|
<Card
|
||||||
loading={props.loading}
|
loading={props.loading}
|
||||||
|
hoverable
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
|
styles={{ body: { padding: 0 } }}
|
||||||
actions={[
|
actions={[
|
||||||
<Link to={`/${props.resource}`}>
|
<Link to={`/${props.resource}`} onClick={(e) => e.stopPropagation()}>
|
||||||
<UnorderedListOutlined />
|
<UnorderedListOutlined />
|
||||||
</Link>,
|
</Link>,
|
||||||
<Link to={`/${props.resource}/create`}>
|
<Link to={`/${props.resource}/create`} onClick={(e) => e.stopPropagation()}>
|
||||||
<PlusOutlined />
|
<PlusOutlined />
|
||||||
</Link>,
|
</Link>,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
|
<Link to={`/${props.resource}`} style={{ display: "block", padding: "24px", color: "inherit" }}>
|
||||||
<Statistic title={t(`${props.resource}.${props.resource}`)} value={props.value} prefix={props.icon} />
|
<Statistic title={t(`${props.resource}.${props.resource}`)} value={props.value} prefix={props.icon} />
|
||||||
|
</Link>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ import { DownloadOutlined, UploadOutlined } from "@ant-design/icons";
|
|||||||
import { useTranslate } from "@refinedev/core";
|
import { useTranslate } from "@refinedev/core";
|
||||||
import { Button, Checkbox, Divider, Form, Input, message, Popconfirm, Space, Upload } from "antd";
|
import { Button, Checkbox, Divider, Form, Input, message, Popconfirm, Space, Upload } from "antd";
|
||||||
import type { UploadFile } from "antd";
|
import type { UploadFile } from "antd";
|
||||||
import { useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import { getAPIURL } from "../../utils/url";
|
import { getAPIURL } from "../../utils/url";
|
||||||
import { useGetSettings, useSetSetting } from "../../utils/querySettings";
|
import { useGetSettings, useSetSetting } from "../../utils/querySettings";
|
||||||
|
import { ColorModeContext, THEME_COLORS, ThemeColorKey } from "../../contexts/color-mode";
|
||||||
|
|
||||||
export function GeneralSettings() {
|
export function GeneralSettings() {
|
||||||
const settings = useGetSettings();
|
const settings = useGetSettings();
|
||||||
@@ -14,6 +15,7 @@ export function GeneralSettings() {
|
|||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
|
const { themeColor, setThemeColor } = useContext(ColorModeContext);
|
||||||
|
|
||||||
// Set initial form values
|
// Set initial form values
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -107,6 +109,25 @@ export function GeneralSettings() {
|
|||||||
<Checkbox />
|
<Checkbox />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label={t("settings.general.theme_color.label")}>
|
||||||
|
<Space>
|
||||||
|
{(Object.keys(THEME_COLORS) as ThemeColorKey[]).map((colorKey) => (
|
||||||
|
<Button
|
||||||
|
key={colorKey}
|
||||||
|
type={themeColor === colorKey ? "primary" : "default"}
|
||||||
|
style={{
|
||||||
|
backgroundColor: themeColor === colorKey ? THEME_COLORS[colorKey] : undefined,
|
||||||
|
borderColor: THEME_COLORS[colorKey],
|
||||||
|
minWidth: 80,
|
||||||
|
}}
|
||||||
|
onClick={() => setThemeColor(colorKey)}
|
||||||
|
>
|
||||||
|
{t(`settings.general.theme_color.${colorKey}`)}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</Space>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
|
<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
|
||||||
<Button type="primary" htmlType="submit" loading={settings.isFetching || setCurrency.isPending}>
|
<Button type="primary" htmlType="submit" loading={settings.isFetching || setCurrency.isPending}>
|
||||||
{t("buttons.save")}
|
{t("buttons.save")}
|
||||||
|
|||||||
Reference in New Issue
Block a user