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 5 commits into
base: main
Choose a base branch
from

Conversation

AMoreaux
Copy link
Contributor

@AMoreaux AMoreaux commented Nov 19, 2024

This Pull Request adds support for resizing the logo and optionally including the Twenty logo in the component.

  • Added size and includeTwentyLogo props to the Logo component.
  • Updated the styled components to handle dynamic sizing based on the new size prop.
  • Added logic to conditionally render the Twenty logo based on the includeTwentyLogo prop.
  • Incorporated the useTheme hook to access theme values directly within the component.

Enhanced Logo component to accept dynamic size and an optional twenty logo display. This allows for more flexible and customizable logo dimensions, and the inclusion of Twenty's logo can now be controlled via props.
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Enhanced the Logo component with dynamic sizing and optional Twenty logo display, improving flexibility for authentication UI customization.

  • Added size prop with theme-based default of theme.spacing(12) in /packages/twenty-front/src/modules/auth/components/Logo.tsx
  • Implemented dynamic calculations for Twenty logo container dimensions (28/48 of main size) and positioning
  • Added includeTwentyLogo boolean prop to control Twenty logo visibility
  • Introduced TypeScript interfaces LogoProps and StyledMainLogoProps for better type safety
  • Refactored fixed pixel values to use relative sizing based on the size prop

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Changed StyledMainLogo type to use Pick for logo prop. This ensures only the required 'logo' property is passed, improving type safety and code clarity.
Consolidated the size prop inside the StyledMainLogo component call. This removes redundancy and aligns with component usage patterns in the codebase.
right: ${({ theme }) => `-${theme.spacing(3)}`};
width: 28px;
right: calc(-12 * ${({ size }) => size} / 48);
width: calc(28 * ${({ size }) => size} / 48);
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.


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

Updated the Logo component to accept primary and secondary logos, replacing the workspaceLogo prop. Adjusted the getImageAbsoluteURI utility function for type safety and URL handling.
Use the new `Spacing` type to ensure consistent spacing units across the theme and Logo components. This change streamlines unit handling and improves type safety throughout the codebase.
@AMoreaux
Copy link
Contributor Author

Following a discussion with Thomas, he requested that we swap the twenty logo with the other one.

To accommodate this, I updated the pull request to create a more flexible component by introducing primaryLogo and secondaryLogo properties.

Regarding the size, nothing changes if you retain the default value. However, if you opt for a different size, we need to adjust the logo positions accordingly. This is why you'll notice several proportional calculations.

horizontalCellMargin: '8px',
checkboxColumnWidth: '32px',
horizontalCellPadding: '8px',
horizontalCellMargin: '8px' as Spacing,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think I've ever seen us doing this. Why do we need it here? Seems like a pattern we want to be careful introducing, if we do it we probably have to do it everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's beneficial to use this type because it ensures that a prop is a Spacing. This doesn't affect the current usage since Spacing is a string. Therefore, if you use a prop of type string, you can provide a Spacing. However, by opting to use a Spacing, as I did in the components, you ensure that the prop will be a spacing.
Additionally, in the Logo component, this is particularly useful because when using the CSS calc function, you need to define the unit in only one of the parameters.

For example:

  calc((${({ theme }) => theme.spacing(3)} * -1) * ${({ size }) => size} / 48);

This is valid because:

  • theme.spacing(3) * -1 = -12px
  • ${({ size }) => size} = 48
  • 48 = 48

Only one parameter returns a unit, so CSS recognizes it as a px spacing.

With a string type instead of a Spacing type, developers might make mistakes, such as using 2rem. So this kind of improvement should increase the DX and the coherence of the global codebase.

@@ -1,15 +1,26 @@
import { REACT_APP_SERVER_BASE_URL } from '~/config';

export const getImageAbsoluteURI = (imageUrl?: string | null) => {
type ImageAbsoluteURI<T extends string | null | undefined> = T extends string
Copy link
Member

Choose a reason for hiding this comment

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

this feels odd, not sure what issue it was trying to solve but we can probably do better no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It enables the inference of the type. When you use the function with a specified parameter, you can be confident that the return type will be determined. As a result, you won't need to add a condition to verify the return type. For example:

Before:

const myPath = '/img.png'
const myImage = getImageAbsoluteURI(myPath);
// myImage type is string | undefined si I will need to check the type

Now:

const myPath = '/img.png'
const myImage = getImageAbsoluteURI(myPath);
// myImage type is string.  
const myPath: string | null;
const myImage = getImageAbsoluteURI(myPath);
// myImage type is string | undefined because myPath could be null. So to use myImage I will need to add a condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants