1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-14 01:16:17 +02:00

Fix plan upgrade tooltip (#2549)

Related: https://github.com/Unleash/unleash/pull/2544
From:
https://linear.app/unleash/issue/1-414/add-a-badge-for-oss-users-on-the-projects-page-to-see-that-extra

Includes some fixes and suggestions:
 - Should only show when OSS (icon was showing every time);
 - Link now works correctly, opens on new tab;
- Improves styling to be more aligned with original design:
https://www.figma.com/file/qdwpPfuitJUNinm6mvmCmG/Unleash-application?node-id=6961%3A38443&t=zsXNAnOurapoLm9j-0;
 - Fixes text to be like in the design;
- Improves `HtmlTooltip` look and behaviour: white arrow, custom width,
etc;
 - Some refactoring and cleanup;
 
Let me know if I should change anything 👍
This commit is contained in:
Nuno Góis 2022-11-29 08:06:29 +00:00 committed by GitHub
parent ad7c139992
commit 4518ed6642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 34 deletions

View File

@ -3,14 +3,24 @@ import { styled, Tooltip, tooltipClasses, TooltipProps } from '@mui/material';
const StyledHtmlTooltip = styled(({ className, ...props }: TooltipProps) => ( const StyledHtmlTooltip = styled(({ className, ...props }: TooltipProps) => (
<Tooltip {...props} classes={{ popper: className }} /> <Tooltip {...props} classes={{ popper: className }} />
))(({ theme }) => ({ ))(({ theme }) => ({
maxWidth: theme.spacing(37.5),
[`& .${tooltipClasses.tooltip}`]: { [`& .${tooltipClasses.tooltip}`]: {
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
backgroundColor: theme.palette.background.paper, backgroundColor: theme.palette.background.paper,
padding: theme.spacing(1, 1.5), padding: theme.spacing(1, 1.5),
borderRadius: theme.shape.borderRadius, borderRadius: theme.shape.borderRadiusMedium,
boxShadow: theme.shadows[2], boxShadow: theme.shadows[2],
color: theme.palette.text.primary, color: theme.palette.text.primary,
fontWeight: theme.fontWeight.medium,
maxWidth: 'inherit',
border: `1px solid ${theme.palette.lightBorder}`,
},
[`& .${tooltipClasses.arrow}`]: {
'&:before': {
border: `1px solid ${theme.palette.lightBorder}`,
},
color: theme.palette.background.paper,
}, },
})); }));

View File

@ -2,41 +2,47 @@ import { ReactComponent as ProPlanIcon } from 'assets/icons/pro-enterprise-featu
import { Box, Link, styled, Typography } from '@mui/material'; import { Box, Link, styled, Typography } from '@mui/material';
export interface ProFeatureTooltipProps { export interface ProFeatureTooltipProps {
text: string; children: React.ReactNode;
} }
const ProFeatureTooltipWrapper = styled(Box)(({ theme }) => ({ const ProFeatureTooltipWrapper = styled(Box)(({ theme }) => ({
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
backgroundColor: theme.palette.background.paper, padding: theme.spacing(1, 0.5),
padding: theme.spacing(1, 1.5),
borderRadius: theme.shape.borderRadius,
color: theme.palette.text.primary,
width: '100%',
})); }));
const StyledTitle = styled(Typography)(({ theme }) => ({ const StyledTitle = styled(Typography)(({ theme }) => ({
display: 'inline-flex', display: 'inline-flex',
justifyContent: 'flex-start', alignItems: 'center',
flexDirection: 'row', fontWeight: theme.fontWeight.bold,
marginBottom: theme.spacing(1), fontSize: theme.fontSizes.smallBody,
gap: theme.spacing(1),
})); }));
export const ProFeatureTooltip = ({ text }: ProFeatureTooltipProps) => { const StyledBody = styled(Typography)(({ theme }) => ({
fontSize: theme.fontSizes.smallBody,
margin: theme.spacing(1, 0),
}));
const StyledLink = styled(Link)(({ theme }) => ({
fontSize: theme.fontSizes.smallBody,
width: 'fit-content',
}));
export const ProFeatureTooltip = ({ children }: ProFeatureTooltipProps) => {
return ( return (
<ProFeatureTooltipWrapper> <ProFeatureTooltipWrapper>
<StyledTitle> <StyledTitle>
<ProPlanIcon /> <ProPlanIcon />
<span style={{ marginLeft: '4px' }}> Pro & Enterprise feature
Pro & Enterprise feature
</span>
</StyledTitle> </StyledTitle>
<Typography sx={{ alignContent: 'center' }}>{text}</Typography> <StyledBody>{children}</StyledBody>
<Typography sx={{ alignContent: 'center' }}> <StyledLink
<Link target={'https://www.getunleash.io/plans'}> href={'https://www.getunleash.io/plans'}
Upgrade now target="_blank"
</Link> >
</Typography> Upgrade now
</StyledLink>
</ProFeatureTooltipWrapper> </ProFeatureTooltipWrapper>
); );
}; };

View File

@ -1,11 +1,11 @@
import React, { ReactNode } from 'react'; import { ReactNode } from 'react';
import { Tooltip, TooltipProps } from '@mui/material'; import { Tooltip, TooltipProps } from '@mui/material';
import { HtmlTooltip } from '../HtmlTooltip/HtmlTooltip'; import { HtmlTooltip } from '../HtmlTooltip/HtmlTooltip';
export interface ITooltipResolverProps extends Omit<TooltipProps, 'title'> { export interface ITooltipResolverProps extends Omit<TooltipProps, 'title'> {
title?: string | undefined; title?: string;
titleComponent?: ReactNode | undefined; titleComponent?: ReactNode;
variant?: 'default' | 'white'; variant?: 'default' | 'custom';
} }
export const TooltipResolver = ({ export const TooltipResolver = ({
@ -19,7 +19,7 @@ export const TooltipResolver = ({
return children; return children;
} }
if (variant === 'white') { if (variant === 'custom') {
return ( return (
<HtmlTooltip {...rest} title={title || titleComponent} arrow> <HtmlTooltip {...rest} title={title || titleComponent} arrow>
{children} {children}

View File

@ -21,8 +21,8 @@ import { TablePlaceholder } from 'component/common/Table';
import { useMediaQuery } from '@mui/material'; import { useMediaQuery } from '@mui/material';
import theme from 'themes/theme'; import theme from 'themes/theme';
import { Search } from 'component/common/Search/Search'; import { Search } from 'component/common/Search/Search';
import { ProFeatureTooltip } from '../../common/ProFeatureTooltip/ProFeatureTooltip'; import { ProFeatureTooltip } from 'component/common/ProFeatureTooltip/ProFeatureTooltip';
import { ITooltipResolverProps } from '../../common/TooltipResolver/TooltipResolver'; import { ITooltipResolverProps } from 'component/common/TooltipResolver/TooltipResolver';
import { ReactComponent as ProPlanIcon } from 'assets/icons/pro-enterprise-feature-badge.svg'; import { ReactComponent as ProPlanIcon } from 'assets/icons/pro-enterprise-feature-badge.svg';
type PageQueryType = Partial<Record<'search', string>>; type PageQueryType = Partial<Record<'search', string>>;
@ -34,6 +34,7 @@ type projectMap = {
interface ICreateButtonData { interface ICreateButtonData {
disabled: boolean; disabled: boolean;
tooltip?: Omit<ITooltipResolverProps, 'children'>; tooltip?: Omit<ITooltipResolverProps, 'children'>;
endIcon?: React.ReactNode;
} }
function resolveCreateButtonData( function resolveCreateButtonData(
@ -45,14 +46,15 @@ function resolveCreateButtonData(
disabled: true, disabled: true,
tooltip: { tooltip: {
titleComponent: ( titleComponent: (
<ProFeatureTooltip <ProFeatureTooltip>
text={ To be able to add more projects you need to upgrade to
'To be able to add more projects you need to upgrade to Pro version' Pro or Enterprise plan
} </ProFeatureTooltip>
/>
), ),
variant: 'white', sx: { maxWidth: '320px' },
variant: 'custom',
}, },
endIcon: <ProPlanIcon />,
}; };
} else if (!hasAccess) { } else if (!hasAccess) {
return { return {
@ -196,7 +198,7 @@ export const ProjectListNew = () => {
/> />
<ResponsiveButton <ResponsiveButton
Icon={Add} Icon={Add}
endIcon={<ProPlanIcon />} endIcon={createButtonData.endIcon}
onClick={() => navigate('/projects/create')} onClick={() => navigate('/projects/create')}
maxWidth="700px" maxWidth="700px"
permission={CREATE_PROJECT} permission={CREATE_PROJECT}