/* * Copyright (C) Contributors to the Suwayomi project * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { useTranslation } from 'react-i18next'; import { useContext, useMemo } from 'react'; import Box from '@mui/material/Box'; import Typography from '@mui/material/Typography'; import Stack from '@mui/material/Stack'; import { styled, ThemeProvider } from '@mui/material/styles'; import CheckCircleIcon from '@mui/icons-material/CheckCircle'; import Card from '@mui/material/Card'; import CardActionArea from '@mui/material/CardActionArea'; import DeleteIcon from '@mui/icons-material/Delete'; import IconButton from '@mui/material/IconButton'; import Tooltip from '@mui/material/Tooltip'; import EditIcon from '@mui/icons-material/Edit'; import { bindDialog, usePopupState } from 'material-ui-popup-state/hooks'; import { ThemeModeContext } from '@/components/context/ThemeModeContext.tsx'; import { AppTheme } from '@/lib/ui/AppThemes.ts'; import { createTheme } from '@/theme.ts'; import { ThemeCreationDialog } from '@/screens/settings/appearance/theme/CreateThemeDialog.tsx'; const ThemePreviewBadge = styled(Box)(({ theme }) => ({ width: '15px', height: '20px', borderRadius: theme.shape.borderRadius, })); export const ThemePreview = ({ theme, onDelete }: { theme: AppTheme; onDelete: () => void }) => { const { getName } = theme; const { t } = useTranslation(); const { themeMode, setAppTheme, appTheme, pureBlackMode } = useContext(ThemeModeContext); const popupState = usePopupState({ variant: 'popover', popupId: `theme-edit-dialog-${theme.id}` }); const isSelected = theme.id === appTheme; const muiTheme = useMemo(() => createTheme(themeMode, theme, pureBlackMode), [theme, themeMode, pureBlackMode]); return ( <> setAppTheme(theme.id)} > {isSelected && ( )} {!isSelected && theme.isCustom && ( { e.preventDefault(); e.stopPropagation(); onDelete(); }} component="div" size="small" > )} {theme.isCustom && ( { e.preventDefault(); e.stopPropagation(); popupState.open(); }} component="div" size="small" > )} {getName()} ); };