Skip to content

Commit

Permalink
feat: color select use MuiColorInput
Browse files Browse the repository at this point in the history
  • Loading branch information
keiko233 committed Feb 23, 2024
1 parent 9c65dde commit 6ade58c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 30 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 21 additions & 7 deletions src/components/setting/mods/theme-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<DialogRef>((props, ref) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -78,16 +80,28 @@ export const ThemeViewer = forwardRef<DialogRef>((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 (
<Item>
<ListItemText primary={label} />
<Round sx={{ background: theme[key] || dt[key] }} />
<TextField

<MuiColorInput
{...textProps}
value={theme[key] ?? ""}
placeholder={dt[key]}
onChange={handleChange(key)}
onKeyDown={(e) => e.key === "Enter" && onSave()}
value={color}
fallbackValue={dt[key]}
isAlphaHidden
format="hex"
onChange={onChange}
/>
</Item>
);
Expand All @@ -99,7 +113,7 @@ export const ThemeViewer = forwardRef<DialogRef>((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}
Expand Down

0 comments on commit 6ade58c

Please sign in to comment.