0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

chore(ui): typing for Theme (#4890)

This commit is contained in:
Marc Bernard 2024-10-08 01:51:02 -04:00 committed by GitHub
parent 124e5f2de7
commit 409494aeb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 129 additions and 106 deletions

View file

@ -0,0 +1,5 @@
---
'@verdaccio/ui-components': patch
---
chore(ui): typing for Theme

View file

@ -3,7 +3,7 @@ import React from 'react';
import { Theme } from './theme'; import { Theme } from './theme';
const resetStyles = makeStyles(({ theme }: { theme?: Theme }) => ({ const resetStyles = makeStyles((theme: Theme) => ({
'@global': { '@global': {
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
'html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video': 'html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video':
@ -11,7 +11,7 @@ const resetStyles = makeStyles(({ theme }: { theme?: Theme }) => ({
fontFamily: '"Roboto", Helvetica Neue, Arial, sans-serif', fontFamily: '"Roboto", Helvetica Neue, Arial, sans-serif',
}, },
strong: { strong: {
fontWeight: theme?.fontWeight.semiBold, fontWeight: theme.fontWeight.semiBold,
}, },
'html, body, #root': { 'html, body, #root': {
height: '100%', height: '100%',
@ -26,8 +26,8 @@ const resetStyles = makeStyles(({ theme }: { theme?: Theme }) => ({
flex: 1, flex: 1,
height: '100%', height: '100%',
[`@media screen and (min-width: ${theme?.breakPoints.container}px)`]: { [`@media screen and (min-width: ${theme.breakPoints.container}px)`]: {
maxWidth: theme?.breakPoints.container, maxWidth: theme.breakPoints.container,
width: '100%', width: '100%',
marginLeft: 'auto', marginLeft: 'auto',
marginRight: 'auto', marginRight: 'auto',

View file

@ -1,4 +1,4 @@
import { createTheme } from '@mui/material/styles'; import { Theme as MuiTheme, createTheme } from '@mui/material/styles';
import { PRIMARY_COLOR } from './colors'; import { PRIMARY_COLOR } from './colors';
@ -92,7 +92,15 @@ const customizedTheme = {
type CustomizedTheme = typeof customizedTheme; type CustomizedTheme = typeof customizedTheme;
export const getTheme = (themeMode: ThemeMode, primaryColor: string) => { export interface CustomTheme {
fontSize: typeof fontSize;
fontWeight: typeof fontWeight;
breakPoints: typeof breakPoints;
}
export type Theme = MuiTheme & CustomTheme;
export const getTheme = (themeMode: ThemeMode, primaryColor: string): Theme => {
const palette = applyPrimaryColor(themeMode, primaryColor); const palette = applyPrimaryColor(themeMode, primaryColor);
return createTheme({ return createTheme({
typography: { typography: {
@ -122,10 +130,13 @@ export const getTheme = (themeMode: ThemeMode, primaryColor: string) => {
}, },
}, },
...customizedTheme, ...customizedTheme,
}); }) as Theme;
}; };
export type Theme = ReturnType<typeof getTheme>; declare module '@mui/material/styles' {
interface Theme extends CustomTheme {}
interface ThemeOptions extends CustomTheme {}
}
declare module '@mui/material/styles/createTheme' { declare module '@mui/material/styles/createTheme' {
/* eslint-disable-next-line @typescript-eslint/no-empty-interface */ /* eslint-disable-next-line @typescript-eslint/no-empty-interface */

View file

@ -16,11 +16,11 @@ import LinkExternal from '../LinkExternal';
export const Fab = styled(FabMUI)<{ theme?: Theme }>(({ theme }) => ({ export const Fab = styled(FabMUI)<{ theme?: Theme }>(({ theme }) => ({
backgroundColor: backgroundColor:
theme?.palette.mode === 'light' ? theme?.palette.primary.main : theme?.palette.cyanBlue, theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.cyanBlue,
'&:hover': { '&:hover': {
color: theme?.palette.mode === 'light' ? theme?.palette.primary.main : theme?.palette.cyanBlue, color: theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.cyanBlue,
}, },
color: theme?.palette.white, color: theme.palette.white,
})); }));
type ActionType = 'VISIT_HOMEPAGE' | 'OPEN_AN_ISSUE' | 'DOWNLOAD_TARBALL' | 'RAW_DATA'; type ActionType = 'VISIT_HOMEPAGE' | 'OPEN_AN_ISSUE' | 'DOWNLOAD_TARBALL' | 'RAW_DATA';

View file

@ -5,7 +5,7 @@ import ListItem from '@mui/material/ListItem';
import { Theme } from '../../Theme'; import { Theme } from '../../Theme';
export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({ export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme?.fontWeight.bold, fontWeight: props.theme.fontWeight.bold,
})); }));
export const AuthorListItem = styled(ListItem)({ export const AuthorListItem = styled(ListItem)({

View file

@ -26,7 +26,7 @@ const Content = styled('span')<{ theme?: Theme }>(({ theme }) => ({
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
height: 'auto', height: 'auto',
whiteSpace: 'break-spaces', whiteSpace: 'break-spaces',
fontSize: theme?.fontSize.sm, fontSize: theme.fontSize.sm,
})); }));
function CopyToClipBoard({ text, children, dataTestId, title, ...props }: Props) { function CopyToClipBoard({ text, children, dataTestId, title, ...props }: Props) {

View file

@ -17,7 +17,7 @@ interface DependencyBlockProps {
} }
export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({ export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme && props.theme.fontWeight.bold, fontWeight: props.theme.fontWeight.bold,
textTransform: 'capitalize', textTransform: 'capitalize',
})); }));
@ -38,7 +38,7 @@ export const Tag = styled(Chip)<{ theme?: Theme }>((props) => ({
export const DependencyBlock: React.FC<DependencyBlockProps> = ({ title, dependencies }) => { export const DependencyBlock: React.FC<DependencyBlockProps> = ({ title, dependencies }) => {
const history = useHistory(); const history = useHistory();
const { t } = useTranslation(); const { t } = useTranslation();
const theme = useTheme(); const theme: Theme = useTheme();
const deps = Object.entries(dependencies); const deps = Object.entries(dependencies);
function handleClick(name: string): void { function handleClick(name: string): void {

View file

@ -2,12 +2,14 @@ import Alert from '@mui/material/Alert';
import { useTheme } from '@mui/styles'; import { useTheme } from '@mui/styles';
import React from 'react'; import React from 'react';
import { Theme } from '../../Theme';
export type Props = { export type Props = {
message: string; message: string;
}; };
const Deprecated: React.FC<Props> = ({ message }) => { const Deprecated: React.FC<Props> = ({ message }) => {
const theme = useTheme(); const theme: Theme = useTheme();
return ( return (
<Alert severity="warning" sx={{ marginTop: theme.spacing(1), marginBottom: theme.spacing(1) }}> <Alert severity="warning" sx={{ marginTop: theme.spacing(1), marginBottom: theme.spacing(1) }}>
{message} {message}

View file

@ -11,8 +11,8 @@ import Title from './Title';
import getUniqueDeveloperValues from './get-unique-developer-values'; import getUniqueDeveloperValues from './get-unique-developer-values';
export const Fab = styled(FabMUI)<{ theme?: Theme }>((props) => ({ export const Fab = styled(FabMUI)<{ theme?: Theme }>((props) => ({
backgroundColor: props.theme?.palette.primary.main, backgroundColor: props.theme.palette.primary.main,
color: props.theme?.palette.white, color: props.theme.palette.white,
})); }));
interface Props { interface Props {

View file

@ -23,6 +23,6 @@ const Title: React.FC<Props> = ({ type }) => {
export default Title; export default Title;
const StyledText = styled(Typography)<{ theme?: Theme }>(({ theme }) => ({ const StyledText = styled(Typography)<{ theme?: Theme }>(({ theme }) => ({
fontWeight: theme?.fontWeight.bold, fontWeight: theme.fontWeight.bold,
marginBottom: '10px', marginBottom: '10px',
})); }));

View file

@ -6,7 +6,7 @@ import Typography from '@mui/material/Typography';
import { Theme } from '../../Theme'; import { Theme } from '../../Theme';
export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({ export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme?.fontWeight.bold, fontWeight: props.theme.fontWeight.bold,
textTransform: 'capitalize', textTransform: 'capitalize',
})); }));

View file

@ -5,7 +5,7 @@ import Typography from '@mui/material/Typography';
import { Theme } from '../../Theme'; import { Theme } from '../../Theme';
export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({ export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme?.fontWeight.bold, fontWeight: props.theme.fontWeight.bold,
textTransform: 'capitalize', textTransform: 'capitalize',
})); }));

View file

@ -51,6 +51,6 @@ const Container = styled('div')({
}); });
const StyledHeading = styled(Heading)<{ theme?: Theme }>(({ theme }) => ({ const StyledHeading = styled(Heading)<{ theme?: Theme }>(({ theme }) => ({
color: theme?.palette.mode === 'light' ? theme?.palette.primary.main : theme?.palette.white, color: theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.white,
marginBottom: 16, marginBottom: 16,
})); }));

View file

@ -9,14 +9,14 @@ import { url } from '../../utils';
import LinkExternal from '../LinkExternal'; import LinkExternal from '../LinkExternal';
const StyledLink = styled(LinkExternal)<{ theme?: Theme }>(({ theme }) => ({ const StyledLink = styled(LinkExternal)<{ theme?: Theme }>(({ theme }) => ({
marginTop: theme?.spacing(2), marginTop: theme.spacing(2),
marginBottom: theme?.spacing(2), marginBottom: theme.spacing(2),
textDecoration: 'none', textDecoration: 'none',
display: 'block', display: 'block',
})); }));
const StyledFavoriteIcon = styled(Favorite)<{ theme?: Theme }>(({ theme }) => ({ const StyledFavoriteIcon = styled(Favorite)<{ theme?: Theme }>(({ theme }) => ({
color: theme?.palette.orange, color: theme.palette.orange,
})); }));
const StyledFundStrong = styled('strong')({ const StyledFundStrong = styled('strong')({

View file

@ -12,7 +12,7 @@ import { SettingsMenu } from '../SettingsMenu';
import InstallListItem, { DependencyManager } from './InstallListItem'; import InstallListItem, { DependencyManager } from './InstallListItem';
const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({ const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme?.fontWeight.bold, fontWeight: props.theme.fontWeight.bold,
textTransform: 'capitalize', textTransform: 'capitalize',
})); }));

View file

@ -5,6 +5,7 @@ import ListItemText from '@mui/material/ListItemText';
import { useTheme } from '@mui/styles'; import { useTheme } from '@mui/styles';
import React from 'react'; import React from 'react';
import { Theme } from '../../Theme';
import { useSettings } from '../../providers/PersistenceSettingProvider'; import { useSettings } from '../../providers/PersistenceSettingProvider';
import CopyToClipBoard from '../CopyClipboard'; import CopyToClipBoard from '../CopyClipboard';
import { Npm, Pnpm, Yarn } from '../Icons'; import { Npm, Pnpm, Yarn } from '../Icons';
@ -55,7 +56,7 @@ const InstallListItem: React.FC<Interface> = ({
packageVersion, packageVersion,
}) => { }) => {
const { localSettings } = useSettings(); const { localSettings } = useSettings();
const theme = useTheme(); const theme: Theme = useTheme();
const isLatest = localSettings[packageName]?.latest ?? false; const isLatest = localSettings[packageName]?.latest ?? false;
const isGlobal = localSettings[packageName]?.global ?? false; const isGlobal = localSettings[packageName]?.global ?? false;
switch (dependencyManager) { switch (dependencyManager) {

View file

@ -4,12 +4,13 @@ import { useTheme } from '@mui/styles';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Theme } from '../../Theme';
import { PackageMetaInterface } from '../../types/packageMeta'; import { PackageMetaInterface } from '../../types/packageMeta';
import KeywordListItems from './KeywordListItems'; import KeywordListItems from './KeywordListItems';
const Keywords: React.FC<{ packageMeta: PackageMetaInterface }> = ({ packageMeta }) => { const Keywords: React.FC<{ packageMeta: PackageMetaInterface }> = ({ packageMeta }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const theme = useTheme(); const theme: Theme = useTheme();
if (!packageMeta?.latest?.keywords) { if (!packageMeta?.latest?.keywords) {
return null; return null;

View file

@ -16,7 +16,7 @@ interface WrapperProps {
} }
const Wrapper = styled('div')<WrapperProps & { theme?: Theme }>((props) => ({ const Wrapper = styled('div')<WrapperProps & { theme?: Theme }>((props) => ({
fontWeight: props.theme?.fontWeight[props.weight], fontWeight: props.theme.fontWeight[props.weight],
textTransform: props.capitalize ? 'capitalize' : 'none', textTransform: props.capitalize ? 'capitalize' : 'none',
})); }));

View file

@ -30,5 +30,5 @@ const Wrapper = styled('div')<Pick<Props, 'centered'>>(({ centered }) => ({
})); }));
const Circular = styled(CircularProgress)<{ theme?: Theme }>(({ theme }) => ({ const Circular = styled(CircularProgress)<{ theme?: Theme }>(({ theme }) => ({
color: theme?.palette.mode === 'dark' ? theme?.palette.white : theme?.palette.primary.main, color: theme.palette.mode === 'dark' ? theme.palette.white : theme.palette.primary.main,
})); }));

View file

@ -14,5 +14,5 @@ export const Badge = styled('div')<{ theme?: Theme }>(({ theme }) => ({
padding: 5, padding: 5,
borderRadius: 25, borderRadius: 25,
boxShadow: '0 10px 20px 0 rgba(69, 58, 100, 0.2)', boxShadow: '0 10px 20px 0 rgba(69, 58, 100, 0.2)',
background: theme?.palette.mode === 'dark' ? theme?.palette.black : '#f7f8f6', background: theme.palette.mode === 'dark' ? theme.palette.black : '#f7f8f6',
})); }));

View file

@ -7,14 +7,14 @@ import React, { memo } from 'react';
import { LoginError, Theme } from '../../'; import { LoginError, Theme } from '../../';
const StyledSnackbarContent = styled(SnackbarContent)<{ theme?: Theme }>(({ theme }) => ({ const StyledSnackbarContent = styled(SnackbarContent)<{ theme?: Theme }>(({ theme }) => ({
backgroundColor: theme?.palette.error.dark, backgroundColor: theme.palette.error.dark,
color: theme?.palette.white, color: theme.palette.white,
})); }));
const StyledErrorIcon = styled(Error)<{ theme?: Theme }>(({ theme }) => ({ const StyledErrorIcon = styled(Error)<{ theme?: Theme }>(({ theme }) => ({
fontSize: 20, fontSize: 20,
opacity: 0.9, opacity: 0.9,
marginRight: theme?.spacing(1), marginRight: theme.spacing(1),
})); }));
export interface FormValues { export interface FormValues {

View file

@ -34,15 +34,15 @@ const LoginDialogHeader: React.FC<Props> = ({ onClose }) => {
export default LoginDialogHeader; export default LoginDialogHeader;
const StyledAvatar = styled(Avatar)<{ theme?: Theme }>(({ theme }) => ({ const StyledAvatar = styled(Avatar)<{ theme?: Theme }>(({ theme }) => ({
margin: theme?.spacing(1), margin: theme.spacing(1),
backgroundColor: backgroundColor:
theme?.palette.mode === 'light' ? theme?.palette.primary.main : theme?.palette.cyanBlue, theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.cyanBlue,
color: theme?.palette.white, color: theme.palette.white,
})); }));
const StyledIconButton = styled(IconButton)<{ theme?: Theme }>(({ theme }) => ({ const StyledIconButton = styled(IconButton)<{ theme?: Theme }>(({ theme }) => ({
position: 'absolute', position: 'absolute',
right: theme?.spacing() / 2, right: theme.spacing() / 2,
top: theme?.spacing() / 2, top: theme.spacing() / 2,
color: theme?.palette.grey[500], color: theme.palette.grey[500],
})); }));

View file

@ -28,10 +28,10 @@ interface Props {
const Logo: React.FC<Props> = ({ size, onClick, className, isDefault = false, title = '' }) => { const Logo: React.FC<Props> = ({ size, onClick, className, isDefault = false, title = '' }) => {
const { configOptions } = useConfig(); const { configOptions } = useConfig();
const theme = useTheme(); const theme: Theme = useTheme();
if (!isDefault && configOptions?.logo) { if (!isDefault && configOptions?.logo) {
const logoSrc = const logoSrc =
theme?.palette.mode === 'dark' && configOptions.logoDark theme.palette.mode === 'dark' && configOptions.logoDark
? configOptions.logoDark ? configOptions.logoDark
: configOptions.logo; : configOptions.logo;
return ( return (
@ -64,7 +64,7 @@ const StyledLogo = styled('div')<Props & { theme?: Theme }>(({ size = 'small', t
boxSizing: 'border-box', boxSizing: 'border-box',
backgroundPosition: 'center', backgroundPosition: 'center',
backgroundSize: 'contain', backgroundSize: 'contain',
backgroundImage: `url(${logos[theme?.palette.mode]})`, backgroundImage: `url(${logos[theme.palette.mode]})`,
backgroundRepeat: ' no-repeat', backgroundRepeat: ' no-repeat',
width: sizes[size], width: sizes[size],
height: sizes[size], height: sizes[size],

View file

@ -48,6 +48,6 @@ const Container = styled('div')({
}); });
const StyledHeading = styled(Heading)<{ theme?: Theme }>(({ theme }) => ({ const StyledHeading = styled(Heading)<{ theme?: Theme }>(({ theme }) => ({
color: theme?.palette.mode === 'light' ? theme?.palette.primary.main : theme?.palette.white, color: theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.white,
marginBottom: 16, marginBottom: 16,
})); }));

View file

@ -246,7 +246,7 @@ export default Package;
const iconStyle = ({ theme }: { theme: Theme }) => css` const iconStyle = ({ theme }: { theme: Theme }) => css`
margin: 0 10px 0 0; margin: 0 10px 0 0;
fill: ${theme?.palette.mode === 'light' ? theme?.palette.greyDark : theme?.palette.white}; fill: ${theme.palette.mode === 'light' ? theme.palette.greyDark : theme.palette.white};
`; `;
const StyledVersion = styled(Version)` const StyledVersion = styled(Version)`

View file

@ -12,14 +12,14 @@ export const OverviewItem = styled('span')<{ theme?: Theme }>(({ theme }) => ({
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
margin: '0 20px 0 0', margin: '0 20px 0 0',
color: theme?.palette.mode === 'light' ? theme?.palette.greyDark2 : theme?.palette.white, color: theme.palette.mode === 'light' ? theme.palette.greyDark2 : theme.palette.white,
fontSize: 12, fontSize: 12,
[`@media (max-width: ${theme?.breakPoints.medium}px)`]: { [`@media (max-width: ${theme.breakPoints.medium}px)`]: {
':nth-of-type(3)': { ':nth-of-type(3)': {
display: 'none', display: 'none',
}, },
}, },
[`@media (max-width: ${theme?.breakPoints.small}px)`]: { [`@media (max-width: ${theme.breakPoints.small}px)`]: {
':nth-of-type(4)': { ':nth-of-type(4)': {
display: 'none', display: 'none',
}, },
@ -52,14 +52,14 @@ export const WrapperLink = styled(Link)({
}); });
export const PackageTitle = styled('span')<{ theme?: Theme }>(({ theme }) => ({ export const PackageTitle = styled('span')<{ theme?: Theme }>(({ theme }) => ({
fontWeight: theme?.fontWeight.bold, fontWeight: theme.fontWeight.bold,
fontSize: 20, fontSize: 20,
display: 'block', display: 'block',
marginBottom: 12, marginBottom: 12,
color: theme?.palette.mode == 'dark' ? theme?.palette.dodgerBlue : theme?.palette.eclipse, color: theme.palette.mode == 'dark' ? theme.palette.dodgerBlue : theme.palette.eclipse,
cursor: 'pointer', cursor: 'pointer',
textDecoration: 'none', textDecoration: 'none',
[`@media (max-width: ${theme?.breakPoints.small}px)`]: { [`@media (max-width: ${theme.breakPoints.small}px)`]: {
fontSize: 14, fontSize: 14,
marginBottom: 8, marginBottom: 8,
}, },
@ -72,7 +72,7 @@ export const GridRightAligned = styled(Grid)({
export const Wrapper = styled(List)<{ theme?: Theme }>(({ theme }) => ({ export const Wrapper = styled(List)<{ theme?: Theme }>(({ theme }) => ({
'&:hover': { '&:hover': {
backgroundColor: backgroundColor:
theme?.palette?.type == 'dark' ? theme?.palette?.secondary.main : theme?.palette?.greyLight2, theme.palette.mode == 'dark' ? theme.palette.secondary.main : theme.palette.greyLight2,
}, },
})); }));
@ -88,7 +88,7 @@ export const PackageListItemText = styled(ListItemText)({
}); });
export const Description = styled('span')<{ theme?: Theme }>(({ theme }) => ({ export const Description = styled('span')<{ theme?: Theme }>(({ theme }) => ({
color: theme?.palette.mode === 'light' ? theme?.palette.greyDark2 : theme?.palette.white, color: theme.palette.mode === 'light' ? theme.palette.greyDark2 : theme.palette.white,
fontSize: '14px', fontSize: '14px',
paddingRight: 0, paddingRight: 0,
})); }));

View file

@ -8,6 +8,8 @@ import React from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import ReactJson from 'react-json-view'; import ReactJson from 'react-json-view';
import { Theme } from '../../Theme';
export interface ViewerTitleProps { export interface ViewerTitleProps {
id: string; id: string;
children?: React.ReactNode; children?: React.ReactNode;
@ -48,7 +50,7 @@ type Props = {
/* eslint-disable verdaccio/jsx-spread */ /* eslint-disable verdaccio/jsx-spread */
const RawViewer: React.FC<Props> = ({ isOpen = false, onClose, packageMeta }) => { const RawViewer: React.FC<Props> = ({ isOpen = false, onClose, packageMeta }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const theme = useTheme(); const theme: Theme = useTheme();
return ( return (
<Dialog data-testid={'rawViewer--dialog'} fullScreen={true} open={isOpen}> <Dialog data-testid={'rawViewer--dialog'} fullScreen={true} open={isOpen}>
<ViewerTitle id="viewer-title" onClose={onClose}> <ViewerTitle id="viewer-title" onClose={onClose}>
@ -61,7 +63,7 @@ const RawViewer: React.FC<Props> = ({ isOpen = false, onClose, packageMeta }) =>
enableClipboard={true} enableClipboard={true}
groupArraysAfterLength={10} groupArraysAfterLength={10}
src={packageMeta as any} src={packageMeta as any}
theme={theme?.palette.mode == 'light' ? 'bright:inverted' : 'bright'} theme={theme.palette.mode == 'light' ? 'bright:inverted' : 'bright'}
/> />
</DialogContent> </DialogContent>
</Dialog> </Dialog>

View file

@ -6,17 +6,17 @@ import { Theme } from '../../';
export const Title = styled(DialogTitle)<{ theme?: Theme }>(({ theme }) => ({ export const Title = styled(DialogTitle)<{ theme?: Theme }>(({ theme }) => ({
backgroundColor: backgroundColor:
theme?.palette.mode === 'light' ? theme?.palette.primary.main : theme?.palette.cyanBlue, theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.cyanBlue,
color: theme?.palette.white, color: theme.palette.white,
fontSize: theme?.fontSize.lg, fontSize: theme.fontSize.lg,
})); }));
export const Content = styled(DialogContent)<{ theme?: Theme }>(({ theme }) => ({ export const Content = styled(DialogContent)<{ theme?: Theme }>(({ theme }) => ({
padding: '0 24px', padding: '0 24px',
backgroundColor: theme?.palette.background.default, backgroundColor: theme.palette.background.default,
})); }));
export const TextContent = styled('div')<{ theme?: Theme }>(({ theme }) => ({ export const TextContent = styled('div')<{ theme?: Theme }>(({ theme }) => ({
padding: '10px 24px', padding: '10px 24px',
backgroundColor: theme?.palette.background.default, backgroundColor: theme.palette.background.default,
})); }));

View file

@ -15,7 +15,7 @@ import { Git } from '../Icons';
import LinkExternal from '../LinkExternal'; import LinkExternal from '../LinkExternal';
const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({ const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme?.fontWeight.bold, fontWeight: props.theme.fontWeight.bold,
textTransform: 'capitalize', textTransform: 'capitalize',
})); }));
@ -39,7 +39,7 @@ const RepositoryAvatar = styled(Avatar)({
const Repository: React.FC<{ packageMeta: any }> = ({ packageMeta }) => { const Repository: React.FC<{ packageMeta: any }> = ({ packageMeta }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const theme = useTheme(); const theme: Theme = useTheme();
const url = packageMeta?.latest?.repository?.url; const url = packageMeta?.latest?.repository?.url;
if (!url || !urlUtils.isURL(url)) { if (!url || !urlUtils.isURL(url)) {
return null; return null;

View file

@ -28,19 +28,19 @@ const Wrapper = styled.div({
export const Description = styled('div')<{ theme?: Theme }>(({ theme }) => ({ export const Description = styled('div')<{ theme?: Theme }>(({ theme }) => ({
display: 'none', display: 'none',
color: theme?.palette?.greyLight2, color: theme.palette.greyLight2,
lineHeight: '1.5rem', lineHeight: '1.5rem',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
alignItems: 'center', alignItems: 'center',
overflow: 'hidden', overflow: 'hidden',
paddingLeft: theme.spacing(), paddingLeft: theme.spacing(),
fontSize: theme?.fontSize.ssm, fontSize: theme.fontSize.ssm,
[`@media (min-width: ${theme?.breakPoints.medium}px)`]: { [`@media (min-width: ${theme.breakPoints.medium}px)`]: {
display: 'block', display: 'block',
width: '300px', width: '300px',
}, },
[`@media (min-width: ${theme?.breakPoints.large}px)`]: { [`@media (min-width: ${theme.breakPoints.large}px)`]: {
display: 'block', display: 'block',
width: '500px', width: '500px',
}, },
@ -57,11 +57,11 @@ const NameGroup = styled.span({
const Name = styled('span')<{ theme?: Theme }>(({ theme }) => ({ const Name = styled('span')<{ theme?: Theme }>(({ theme }) => ({
fontWeight: '700', fontWeight: '700',
fontSize: theme?.fontSize.sm, fontSize: theme.fontSize.sm,
})); }));
const Version = styled('span')<{ theme?: Theme }>(({ theme }) => ({ const Version = styled('span')<{ theme?: Theme }>(({ theme }) => ({
fontSize: theme?.fontSize.ssm, fontSize: theme.fontSize.ssm,
})); }));
const SearchItem: React.FC<SearchItemProps> = ({ const SearchItem: React.FC<SearchItemProps> = ({

View file

@ -14,7 +14,7 @@ export const StyledTextField = styled(TextField)<{ theme?: Theme }>((props) => (
border: 'none', border: 'none',
}, },
':after': { ':after': {
borderColor: props.theme?.palette.white, borderColor: props.theme.palette.white,
}, },
':hover:before': { ':hover:before': {
content: 'none', content: 'none',
@ -23,19 +23,19 @@ export const StyledTextField = styled(TextField)<{ theme?: Theme }>((props) => (
content: 'none', content: 'none',
transform: 'scaleX(1)', transform: 'scaleX(1)',
}, },
[`@media screen and (min-width: ${props.theme?.breakPoints.medium}px)`]: { [`@media screen and (min-width: ${props.theme.breakPoints.medium}px)`]: {
':hover:after': { ':hover:after': {
content: "''", content: "''",
}, },
}, },
}, },
'& .MuiInputBase-input': { '& .MuiInputBase-input': {
[`@media screen and (min-width: ${props.theme?.breakPoints.medium}px)`]: { [`@media screen and (min-width: ${props.theme.breakPoints.medium}px)`]: {
color: props.theme?.palette.white, color: props.theme.palette.white,
}, },
}, },
})); }));
export const StyledInputAdornment = styled(InputAdornment)<{ theme?: Theme }>((props) => ({ export const StyledInputAdornment = styled(InputAdornment)<{ theme?: Theme }>((props) => ({
color: props.theme?.palette.white, color: props.theme.palette.white,
})); }));

View file

@ -21,7 +21,7 @@ interface Props {
} }
const Icon = styled.div<{ theme?: Theme }>(({ theme }) => ({ const Icon = styled.div<{ theme?: Theme }>(({ theme }) => ({
marginLeft: theme?.spacing(1), marginLeft: theme.spacing(1),
})); }));
const ModuleJS: React.FC<{ module: ModuleType | void }> = ({ module }) => { const ModuleJS: React.FC<{ module: ModuleType | void }> = ({ module }) => {
@ -93,6 +93,6 @@ const StyledHeading = styled(Heading)({
}); });
const StyledBoxVersion = styled(Box)<{ theme?: Theme }>(({ theme }) => ({ const StyledBoxVersion = styled(Box)<{ theme?: Theme }>(({ theme }) => ({
color: theme?.palette.text.secondary, color: theme.palette.text.secondary,
fontSize: theme?.fontSize.sm, fontSize: theme.fontSize.sm,
})); }));

View file

@ -5,13 +5,13 @@ import Typography from '@mui/material/Typography';
import { Theme } from '../../Theme'; import { Theme } from '../../Theme';
export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({ export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme?.fontWeight.bold, fontWeight: props.theme.fontWeight.bold,
})); }));
export const Spacer = styled('div')<{ theme?: Theme }>(({ theme }) => ({ export const Spacer = styled('div')<{ theme?: Theme }>(({ theme }) => ({
flex: '1 1 auto', flex: '1 1 auto',
borderBottom: `1px dotted ${ borderBottom: `1px dotted ${
theme?.palette.mode == 'light' ? 'rgba(0, 0, 0, 0.2)' : 'rgba(255, 255, 255, 0.2)' theme.palette.mode == 'light' ? 'rgba(0, 0, 0, 0.2)' : 'rgba(255, 255, 255, 0.2)'
} `, } `,
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
height: '0.5em', height: '0.5em',
@ -20,6 +20,6 @@ export const Spacer = styled('div')<{ theme?: Theme }>(({ theme }) => ({
export const ListItemText = styled(MuiListItemText)<{ theme?: Theme }>(({ theme }) => ({ export const ListItemText = styled(MuiListItemText)<{ theme?: Theme }>(({ theme }) => ({
flex: 'none', flex: 'none',
color: theme?.palette.mode == 'light' ? theme?.palette.black : theme?.palette.white, color: theme.palette.mode == 'light' ? theme.palette.black : theme.palette.white,
opacity: 0.6, opacity: 0.6,
})); }));

View file

@ -5,6 +5,7 @@ import { useTheme } from '@mui/styles';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Theme } from '../../Theme';
import { useConfig } from '../../providers'; import { useConfig } from '../../providers';
import { Time, Versions } from '../../types/packageMeta'; import { Time, Versions } from '../../types/packageMeta';
import { Route, utils } from '../../utils'; import { Route, utils } from '../../utils';
@ -31,7 +32,7 @@ export function filterDeprecated(versions: Versions) {
const VersionsHistoryList: React.FC<Props> = ({ versions, packageName, time }) => { const VersionsHistoryList: React.FC<Props> = ({ versions, packageName, time }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { configOptions } = useConfig(); const { configOptions } = useConfig();
const theme = useTheme(); const theme: Theme = useTheme();
const hideDeprecatedVersions = configOptions.hideDeprecatedVersions; const hideDeprecatedVersions = configOptions.hideDeprecatedVersions;
const listVersions = hideDeprecatedVersions ? filterDeprecated(versions) : versions; const listVersions = hideDeprecatedVersions ? filterDeprecated(versions) : versions;

View file

@ -26,7 +26,7 @@ export const StyledText = styled(Typography)<{ theme?: Theme }>((props) => ({
const Versions: React.FC<Props> = ({ packageMeta, packageName }) => { const Versions: React.FC<Props> = ({ packageMeta, packageName }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { configOptions } = useConfig(); const { configOptions } = useConfig();
const theme = useTheme(); const theme: Theme = useTheme();
const { versions = {}, time = {}, ['dist-tags']: distTags = {} } = packageMeta; const { versions = {}, time = {}, ['dist-tags']: distTags = {} } = packageMeta;
const [packageVersions, setPackageVersions] = useState(versions); const [packageVersions, setPackageVersions] = useState(versions);

View file

@ -6,7 +6,7 @@ import { Theme } from '../../Theme';
export const Spacer = styled('div')<{ theme?: Theme }>(({ theme }) => ({ export const Spacer = styled('div')<{ theme?: Theme }>(({ theme }) => ({
flex: '1 1 auto', flex: '1 1 auto',
borderBottom: `1px dotted ${ borderBottom: `1px dotted ${
theme?.palette.mode == 'light' ? 'rgba(0, 0, 0, 0.2)' : 'rgba(255, 255, 255, 0.2)' theme.palette.mode == 'light' ? 'rgba(0, 0, 0, 0.2)' : 'rgba(255, 255, 255, 0.2)'
} `, } `,
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
height: '0.5em', height: '0.5em',
@ -16,5 +16,5 @@ export const Spacer = styled('div')<{ theme?: Theme }>(({ theme }) => ({
export const ListItemText = styled(MuiListItemText)<{ theme?: Theme }>(({ theme }) => ({ export const ListItemText = styled(MuiListItemText)<{ theme?: Theme }>(({ theme }) => ({
flex: 'none', flex: 'none',
opacity: 0.6, opacity: 0.6,
color: theme?.palette.mode == 'light' ? theme?.palette.black : theme?.palette.white, color: theme.palette.mode == 'light' ? theme.palette.black : theme.palette.white,
})); }));

View file

@ -92,7 +92,7 @@ const Flags = styled('span')<{ theme?: Theme }>(({ theme }) => ({
gridTemplateColumns: 'repeat(10, max-content)', gridTemplateColumns: 'repeat(10, max-content)',
gridGap: theme.spacing(0, 1), gridGap: theme.spacing(0, 1),
position: 'absolute', position: 'absolute',
background: theme?.palette.greyAthens, background: theme.palette.greyAthens,
padding: '1px 4px', padding: '1px 4px',
borderRadius: 3, borderRadius: 3,
height: 20, height: 20,
@ -106,7 +106,7 @@ const Flags = styled('span')<{ theme?: Theme }>(({ theme }) => ({
left: -4, left: -4,
marginLeft: -5, marginLeft: -5,
border: '5px solid', border: '5px solid',
borderColor: `${theme?.palette.greyAthens} transparent transparent transparent`, borderColor: `${theme.palette.greyAthens} transparent transparent transparent`,
transform: 'rotate(90deg)', transform: 'rotate(90deg)',
}, },
})); }));

View file

@ -3,9 +3,9 @@ import styled from '@emotion/styled';
import { Theme } from '../../'; import { Theme } from '../../';
export const Wrapper = styled('div')<{ theme?: Theme }>(({ theme }) => ({ export const Wrapper = styled('div')<{ theme?: Theme }>(({ theme }) => ({
background: theme?.palette.mode === 'light' ? theme?.palette.snow : theme?.palette.cyanBlue, background: theme.palette.mode === 'light' ? theme.palette.snow : theme.palette.cyanBlue,
borderTop: `1px solid ${theme?.palette.greyGainsboro}`, borderTop: `1px solid ${theme.palette.greyGainsboro}`,
color: theme?.palette.mode === 'dark' ? theme?.palette.white : theme?.palette.nobel01, color: theme.palette.mode === 'dark' ? theme.palette.white : theme.palette.nobel01,
fontSize: '14px', fontSize: '14px',
padding: '20px', padding: '20px',
})); }));
@ -17,13 +17,13 @@ export const Inner = styled('div')<{ theme?: Theme }>(({ theme }) => ({
paddingLeft: 16, paddingLeft: 16,
paddingRight: 16, paddingRight: 16,
width: '100%', width: '100%',
[`@media (min-width: ${theme?.breakPoints.medium}px)`]: { [`@media (min-width: ${theme.breakPoints.medium}px)`]: {
minWidth: 400, minWidth: 400,
maxWidth: 800, maxWidth: 800,
margin: 'auto', margin: 'auto',
justifyContent: 'space-between', justifyContent: 'space-between',
}, },
[`@media (min-width: ${theme?.breakPoints.large}px)`]: { [`@media (min-width: ${theme.breakPoints.large}px)`]: {
maxWidth: 1240, maxWidth: 1240,
}, },
})); }));
@ -31,7 +31,7 @@ export const Inner = styled('div')<{ theme?: Theme }>(({ theme }) => ({
export const Left = styled('div')<{ theme?: Theme }>(({ theme }) => ({ export const Left = styled('div')<{ theme?: Theme }>(({ theme }) => ({
alignItems: 'center', alignItems: 'center',
display: 'none', display: 'none',
[`@media (min-width: ${theme?.breakPoints.medium}px)`]: { [`@media (min-width: ${theme.breakPoints.medium}px)`]: {
display: 'flex', display: 'flex',
}, },
marginLeft: 1, marginLeft: 1,
@ -43,6 +43,6 @@ export const Right = styled(Left)({
}); });
export const Love = styled('span')<{ theme?: Theme }>(({ theme }) => ({ export const Love = styled('span')<{ theme?: Theme }>(({ theme }) => ({
color: theme?.palette.love, color: theme.palette.love,
padding: '0 5px', padding: '0 5px',
})); }));

View file

@ -43,7 +43,7 @@ function TabPanel(props) {
const TextContent = styled('div')<{ theme?: Theme }>(({ theme }) => ({ const TextContent = styled('div')<{ theme?: Theme }>(({ theme }) => ({
padding: '10px 0', padding: '10px 0',
backgroundColor: theme?.palette.background.default, backgroundColor: theme.palette.background.default,
})); }));
const HeaderSettingsDialog: React.FC<Props> = ({ onCloseDialog, isOpen }) => { const HeaderSettingsDialog: React.FC<Props> = ({ onCloseDialog, isOpen }) => {

View file

@ -12,9 +12,9 @@ import { Theme, useLanguage } from '../../';
export const CardSelected = styled(Card)<{ theme?: Theme }>(({ theme }) => { export const CardSelected = styled(Card)<{ theme?: Theme }>(({ theme }) => {
return { return {
backgroundColor: theme?.palette?.grey['600'], backgroundColor: theme.palette.grey['600'],
opacity: '0.9', opacity: '0.9',
color: theme?.palette?.error.contrastText, color: theme.palette.error.contrastText,
fontWeight: 'bold', fontWeight: 'bold',
}; };
}); });
@ -23,7 +23,7 @@ export const CardUnSelected = styled(Card)<{ theme?: Theme }>(({ theme }) => {
return { return {
cursor: 'pointer', cursor: 'pointer',
':hover': { ':hover': {
backgroundColor: theme?.palette.greyGainsboro, backgroundColor: theme.palette.greyGainsboro,
}, },
}; };
}); });

View file

@ -4,7 +4,7 @@ import { Theme } from '../../../';
export const TextContent = styled('div')<{ theme?: Theme }>(({ theme }) => ({ export const TextContent = styled('div')<{ theme?: Theme }>(({ theme }) => ({
paddingBottom: '10px', paddingBottom: '10px',
backgroundColor: theme?.palette.background.default, backgroundColor: theme.palette.background.default,
})); }));
export const Description = styled('div')<{ theme?: Theme }>(() => ({ export const Description = styled('div')<{ theme?: Theme }>(() => ({

View file

@ -19,15 +19,15 @@ export const Greetings = styled('span')({
export const MobileNavBar = styled('div')<{ theme?: Theme }>((props) => ({ export const MobileNavBar = styled('div')<{ theme?: Theme }>((props) => ({
alignItems: 'center', alignItems: 'center',
display: 'flex', display: 'flex',
borderBottom: `1px solid ${props.theme?.palette.greyLight}`, borderBottom: `1px solid ${props.theme.palette.greyLight}`,
padding: '8px', padding: '8px',
position: 'relative', position: 'relative',
})); }));
export const InnerMobileNavBar = styled('div')<{ theme?: Theme }>((props) => ({ export const InnerMobileNavBar = styled('div')<{ theme?: Theme }>((props) => ({
borderRadius: '4px', borderRadius: '4px',
backgroundColor: props.theme?.palette.greyLight, backgroundColor: props.theme.palette.greyLight,
color: props.theme?.palette.white, color: props.theme.palette.white,
width: '100%', width: '100%',
padding: '0 5px', padding: '0 5px',
margin: '0 10px 0 0', margin: '0 10px 0 0',
@ -46,12 +46,12 @@ export const SearchWrapper = styled('div')({
export const NavBar = styled(AppBar)<{ theme?: Theme }>(({ theme }) => ({ export const NavBar = styled(AppBar)<{ theme?: Theme }>(({ theme }) => ({
backgroundColor: backgroundColor:
theme?.palette.mode === 'light' ? theme?.palette.primary.main : theme?.palette.cyanBlue, theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.cyanBlue,
color: theme?.palette.white, color: theme.palette.white,
minHeight: 60, minHeight: 60,
display: 'flex', display: 'flex',
justifyContent: 'center', justifyContent: 'center',
[`@media (max-width: ${theme?.breakPoints.xsmall}px)`]: css` [`@media (max-width: ${theme.breakPoints.xsmall}px)`]: css`
${InfoButton} { ${InfoButton} {
display: none; display: none;
} }
@ -62,7 +62,7 @@ export const NavBar = styled(AppBar)<{ theme?: Theme }>(({ theme }) => ({
display: none; display: none;
} }
`, `,
[`@media (min-width: ${theme?.breakPoints.medium}px)`]: css` [`@media (min-width: ${theme.breakPoints.medium}px)`]: css`
${SearchWrapper} { ${SearchWrapper} {
display: flex; display: flex;
} }
@ -73,12 +73,12 @@ export const NavBar = styled(AppBar)<{ theme?: Theme }>(({ theme }) => ({
display: none; display: none;
} }
`, `,
[`@media (min-width: ${theme?.breakPoints.large}px)`]: css` [`@media (min-width: ${theme.breakPoints.large}px)`]: css`
${InnerNavBar} { ${InnerNavBar} {
padding: 0 16px; padding: 0 16px;
} }
`, `,
[`@media (min-width: ${theme?.breakPoints.xlarge}px)`]: css` [`@media (min-width: ${theme.breakPoints.xlarge}px)`]: css`
${InnerNavBar} { ${InnerNavBar} {
max-width: 1240px; max-width: 1240px;
width: 100%; width: 100%;