-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathLogo.tsx
More file actions
110 lines (98 loc) · 3.25 KB
/
Copy pathLogo.tsx
File metadata and controls
110 lines (98 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { styled } from '@linaria/react';
import { isNonEmptyString } from '@sniptt/guards';
import { AppPath } from 'twenty-shared/types';
import { getImageAbsoluteURI, isDefined } from 'twenty-shared/utils';
import { Avatar } from 'twenty-ui/display';
import { UndecoratedLink } from 'twenty-ui/navigation';
import { themeCssVariables } from 'twenty-ui/theme-constants';
import { REACT_APP_SERVER_BASE_URL } from '~/config';
import { useRedirectToDefaultDomain } from '~/modules/domain-manager/hooks/useRedirectToDefaultDomain';
type LogoProps = {
primaryLogo?: string | null;
secondaryLogo?: string | null;
placeholder?: string | null;
onClick?: () => void;
};
const StyledContainer = styled.div`
height: ${themeCssVariables.spacing[12]};
margin-bottom: ${themeCssVariables.spacing[4]};
margin-top: ${themeCssVariables.spacing[4]};
position: relative;
width: ${themeCssVariables.spacing[12]};
`;
const StyledSecondaryLogo = styled.img`
border-radius: ${themeCssVariables.border.radius.xs};
height: ${themeCssVariables.spacing[6]};
width: ${themeCssVariables.spacing[6]};
`;
const StyledSecondaryLogoContainer = styled.div`
align-items: center;
background-color: ${themeCssVariables.background.primary};
border-radius: ${themeCssVariables.border.radius.sm};
bottom: calc(-1 * ${themeCssVariables.spacing[3]});
display: flex;
height: ${themeCssVariables.spacing[7]};
justify-content: center;
position: absolute;
right: calc(-1 * ${themeCssVariables.spacing[3]});
width: ${themeCssVariables.spacing[7]};
`;
const StyledPrimaryLogo = styled.div`
background-size: cover;
height: 100%;
width: 100%;
`;
export const Logo = ({
primaryLogo,
secondaryLogo,
placeholder,
onClick,
}: LogoProps) => {
const { redirectToDefaultDomain } = useRedirectToDefaultDomain();
const defaultPrimaryLogoUrl = `${window.location.origin}/images/icons/android/android-launchericon-192-192.png`;
const primaryLogoUrl = getImageAbsoluteURI({
imageUrl: primaryLogo ?? defaultPrimaryLogoUrl,
baseUrl: REACT_APP_SERVER_BASE_URL,
});
const secondaryLogoUrl = isNonEmptyString(secondaryLogo)
? getImageAbsoluteURI({
imageUrl: secondaryLogo,
baseUrl: REACT_APP_SERVER_BASE_URL,
})
: null;
const isUsingDefaultLogo = !isDefined(primaryLogo);
return (
<StyledContainer onClick={() => onClick?.()}>
{isUsingDefaultLogo ? (
<UndecoratedLink
to={AppPath.SignInUp}
onClick={() => redirectToDefaultDomain()}
>
<StyledPrimaryLogo
style={{ backgroundImage: `url(${primaryLogoUrl})` }}
/>
</UndecoratedLink>
) : (
<StyledPrimaryLogo
style={{ backgroundImage: `url(${primaryLogoUrl})` }}
/>
)}
{isDefined(secondaryLogoUrl) ? (
<StyledSecondaryLogoContainer>
<StyledSecondaryLogo src={secondaryLogoUrl} />
</StyledSecondaryLogoContainer>
) : (
isDefined(placeholder) && (
<StyledSecondaryLogoContainer>
<Avatar
size="lg"
placeholder={placeholder}
type="squared"
placeholderColorSeed={placeholder}
/>
</StyledSecondaryLogoContainer>
)
)}
</StyledContainer>
);
};