Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth/logo): Add dynamic sizing and conditional twenty logo #8587

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
61 changes: 41 additions & 20 deletions packages/twenty-front/src/modules/auth/components/Logo.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';

import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { isDefined } from '~/utils/isDefined';

type LogoProps = {
workspaceLogo?: string | null;
size?: string | null;
includeTwentyLogo?: boolean;
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved
};

const StyledContainer = styled.div`
height: 48px;
const StyledContainer = styled.div<StyledMainLogoProps>`
height: ${({ size }) => size};
margin-bottom: ${({ theme }) => theme.spacing(4)};
margin-top: ${({ theme }) => theme.spacing(4)};

position: relative;
width: 48px;
width: ${({ size }) => size};
`;

const StyledTwentyLogo = styled.img`
const StyledTwentyLogo = styled.img<StyledMainLogoProps>`
border-radius: ${({ theme }) => theme.border.radius.xs};
height: 24px;
width: 24px;
height: calc(${({ size }) => size} / 2);
width: calc(${({ size }) => size} / 2);
`;

const StyledTwentyLogoContainer = styled.div`
const StyledTwentyLogoContainer = styled.div<StyledMainLogoProps>`
align-items: center;
background-color: ${({ theme }) => theme.background.primary};
border-radius: ${({ theme }) => theme.border.radius.sm};
bottom: ${({ theme }) => `-${theme.spacing(3)}`};
bottom: calc(-12 * ${({ size }) => size} / 48);
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved
display: flex;
height: 28px;
height: calc((28 * ${({ size }) => size}) / 48);
justify-content: center;

position: absolute;
right: ${({ theme }) => `-${theme.spacing(3)}`};
width: 28px;
right: calc(-12 * ${({ size }) => size} / 48);
width: calc(28 * ${({ size }) => size} / 48);
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-7/12 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression ${({ theme }) => -${theme.spacing(3)}} is equivalent to -12px.

Due to CSS limitations, I initially had to use a raw value like -12. However, with the latest commit, I found a workaround that allows us to avoid using absolute values while still utilizing theme.spacing(...).

Otherwise, it's a proportional calculation.

`;

type StyledMainLogoProps = {
logo?: string | null;
size?: string | null;
};

const StyledMainLogo = styled.div<StyledMainLogoProps>`
Expand All @@ -47,21 +52,37 @@ const StyledMainLogo = styled.div<StyledMainLogoProps>`
width: 100%;
`;

export const Logo = ({ workspaceLogo }: LogoProps) => {
if (!workspaceLogo) {
export const Logo = (props: LogoProps) => {
const theme = useTheme();

const size = props.size ?? theme.spacing(12);

const includeTwentyLogo = isDefined(props.includeTwentyLogo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you handle that through a default prop value? Something feels not very elegant here

? props.includeTwentyLogo
: true;

if (!props.workspaceLogo) {
return (
<StyledContainer>
<StyledMainLogo logo="/icons/android/android-launchericon-192-192.png" />
<StyledContainer size={size}>
<StyledMainLogo
size={size}
logo="/icons/android/android-launchericon-192-192.png"
/>
</StyledContainer>
);
}

return (
<StyledContainer>
<StyledMainLogo logo={getImageAbsoluteURI(workspaceLogo)} />
<StyledTwentyLogoContainer>
<StyledTwentyLogo src="/icons/android/android-launchericon-192-192.png" />
</StyledTwentyLogoContainer>
<StyledContainer size={size}>
<StyledMainLogo logo={getImageAbsoluteURI(props.workspaceLogo)} />
AMoreaux marked this conversation as resolved.
Show resolved Hide resolved
{includeTwentyLogo && (
<StyledTwentyLogoContainer size={size}>
<StyledTwentyLogo
size={size}
src="/icons/android/android-launchericon-192-192.png"
/>
</StyledTwentyLogoContainer>
)}
</StyledContainer>
);
};
Loading