diff --git a/package.json b/package.json index 9f3f904806..01bc3285a4 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "i18next": "23.9.0", "lodash-es": "4.17.21", "monaco-editor": "0.46.0", + "mui-color-input": "^2.0.3", "react": "18.2.0", "react-dom": "18.2.0", "react-error-boundary": "4.0.12", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 87f9558af8..6b81340993 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -62,6 +62,9 @@ dependencies: monaco-editor: specifier: 0.46.0 version: 0.46.0 + mui-color-input: + specifier: ^2.0.3 + version: 2.0.3(@emotion/react@11.11.3)(@emotion/styled@11.11.0)(@mui/material@5.15.10)(@types/react@18.2.57)(react-dom@18.2.0)(react@18.2.0) react: specifier: 18.2.0 version: 18.2.0 @@ -726,6 +729,11 @@ packages: postcss-selector-parser: 6.0.15 dev: true + /@ctrl/tinycolor@4.0.3: + resolution: {integrity: sha512-e9nEVehVJwkymQpkGhdSNzLT2Lr9UTTby+JePq4Z2SxBbOQjY7pLgSouAaXvfaGQVSAaY0U4eJdwfSDmCbItcw==} + engines: {node: '>=14'} + dev: false + /@dnd-kit/accessibility@3.1.0(react@18.2.0): resolution: {integrity: sha512-ea7IkhKvlJUv9iSHJOnxinBcoOI3ppGnnL+VDJ75O45Nss6HtZd8IdN8touXPDtASfeI2T2LImb8VOZcL47wjQ==} peerDependencies: @@ -4847,6 +4855,28 @@ packages: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true + /mui-color-input@2.0.3(@emotion/react@11.11.3)(@emotion/styled@11.11.0)(@mui/material@5.15.10)(@types/react@18.2.57)(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-rAd040qQ0Y+8dk4gE8kkCiJ/vCgA0j4vv1quJ43BfORTFE3uHarHj0xY1Vo9CPbojtx1f5vW+CjckYPRIZPIRg==} + peerDependencies: + '@emotion/react': ^11.5.0 + '@emotion/styled': ^11.3.0 + '@mui/material': ^5.0.0 + '@types/react': ^18.0.0 + react: ^18.0.0 + react-dom: ^18.0.0 + peerDependenciesMeta: + '@types/react': + optional: true + dependencies: + '@ctrl/tinycolor': 4.0.3 + '@emotion/react': 11.11.3(@types/react@18.2.57)(react@18.2.0) + '@emotion/styled': 11.11.0(@emotion/react@11.11.3)(@types/react@18.2.57)(react@18.2.0) + '@mui/material': 5.15.10(@emotion/react@11.11.3)(@emotion/styled@11.11.0)(@types/react@18.2.57)(react-dom@18.2.0)(react@18.2.0) + '@types/react': 18.2.57 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + dev: false + /nanoid@3.3.7: resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} diff --git a/src/components/setting/mods/theme-viewer.tsx b/src/components/setting/mods/theme-viewer.tsx index fb84c7e24f..7f86c5b09e 100644 --- a/src/components/setting/mods/theme-viewer.tsx +++ b/src/components/setting/mods/theme-viewer.tsx @@ -13,6 +13,8 @@ import { import { useLockFn } from "ahooks"; import { forwardRef, useImperativeHandle, useState } from "react"; import { useTranslation } from "react-i18next"; +import { MuiColorInput } from "mui-color-input"; +import React from "react"; export const ThemeViewer = forwardRef((props, ref) => { const { t } = useTranslation(); @@ -78,16 +80,28 @@ export const ThemeViewer = forwardRef((props, ref) => { type ThemeKey = keyof typeof theme & keyof typeof defaultTheme; const renderItem = (label: string, key: ThemeKey) => { + const [color, setColor] = React.useState(theme[key] || dt[key]); + + const onChange = (color: string) => { + if (!color) { + color = dt[key]; + } + + setColor(color); + setTheme((t) => ({ ...t, [key]: color })); + }; + return ( - - e.key === "Enter" && onSave()} + value={color} + fallbackValue={dt[key]} + isAlphaHidden + format="hex" + onChange={onChange} /> ); @@ -99,7 +113,7 @@ export const ThemeViewer = forwardRef((props, ref) => { title={t("Theme Setting")} okBtn={t("Save")} cancelBtn={t("Cancel")} - contentSx={{ width: 400, maxHeight: 300, overflow: "auto", pb: 0 }} + contentSx={{ width: 400, maxHeight: "80%", overflow: "auto", pb: 0 }} onClose={() => setOpen(false)} onCancel={() => setOpen(false)} onOk={onSave}