import React, {
type FC,
type PropsWithChildren,
useRef,
useMemo,
useState,
useCallback
} from 'react';
import { SettingsIcon, CheckIcon } from '@chakra-ui/icons';
import {
Button,
Drawer,
DrawerBody,
DrawerContent,
DrawerCloseButton,
DrawerHeader,
DrawerFooter,
DrawerOverlay,
useDisclosure,
ButtonGroup,
Heading,
Stack,
Center,
Wrap,
WrapItem,
Text,
type Colors,
HStack
} from '@chakra-ui/react';
import { FormattedMessage } from 'dumi';
import useTheme from '../../hooks/useTheme';
import { isObject } from '../../factory/tools';
// not colors scheme variable
const blackList = ['blackAlpha', 'whiteAlpha', 'brand'];
export type ColorItem = [string, Colors];
const ColorPanel: FC<{ color: ColorItem; hideChooseButton?: boolean }> = ({
color: [colorKey, colorMap]
}) => (
{Object.entries(colorMap).map(([alpha, color]) => {
const text = `${colorKey}.${alpha}`;
return (
{color as string}
);
})}
);
const SettingPanel: FC = ({ children }) => {
const { isOpen, onOpen, onClose } = useDisclosure();
const closeButtonRef = useRef(null);
const { brand, changeBrand, config } = useTheme();
const [currentChoose, setCurrentChoose] = useState();
const choicesThemeColors = useMemo>(() => {
return Object.entries(config!.colors!).filter(
([colorKey, colorObject]) =>
isObject(colorObject) && !blackList.includes(colorKey)
) as Array;
}, [config]);
const brandColors = useMemo(() => {
return choicesThemeColors.filter(([brandKey, brandColorMap]) => {
if (typeof brand === 'string') {
return brandKey === brand;
}
if (isObject(brand)) {
return Object.keys(brandColorMap).every(
(key) => brand[key] === brandColorMap[key]
);
}
return brandKey === 'purple';
})[0];
}, [choicesThemeColors, brand]);
const storeAndChangeTheme = useCallback(() => {
if (currentChoose) {
const choicesTheme = choicesThemeColors.find(
(v) => v[0] === currentChoose
)![1];
changeBrand!(choicesTheme);
}
onClose();
}, [currentChoose, changeBrand, choicesThemeColors]);
return (
<>
brand: {brandColors[0]}
{choicesThemeColors.map(([colorKey], index) => (
{colorKey}
))}
>
);
};
export default SettingPanel;