-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
base: main
Are you sure you want to change the base?
feat(auth/logo): Add dynamic sizing and conditional twenty logo #8587
Conversation
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.
There was a problem hiding this 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 oftheme.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
andStyledMainLogoProps
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-7/12 ?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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}
= 4848
= 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
This Pull Request adds support for resizing the logo and optionally including the Twenty logo in the component.