Skip to content

Commit a4cad42

Browse files
authored
Merge pull request #2155 from oasisprotocol/kaja/uil-footer
Update Footer component to shadcn
2 parents 62c986a + db6783b commit a4cad42

File tree

4 files changed

+34
-95
lines changed

4 files changed

+34
-95
lines changed

.changelog/2155.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Convert Footer component to shadcn

src/app/components/AnalyticsConsent/index.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createContext, FC, useContext, useEffect, useState } from 'react'
33
import { useBlocker, useLocation } from 'react-router-dom'
44
import { styled } from '@mui/material/styles'
55
import Button from '@mui/material/Button'
6-
import Link from '@mui/material/Link'
6+
import { Link } from '@oasisprotocol/ui-library/src/components/link'
77
import { Trans, useTranslation } from 'react-i18next'
88
import * as matomo from './initializeMatomo'
99
import { ThemeByScope } from '../ThemeByScope'
@@ -87,14 +87,6 @@ export const AnalyticsConsentProvider = (props: { children: React.ReactNode }) =
8787
)
8888
}
8989

90-
const StyledPrivacyButton = styled(Button)(() => ({
91-
padding: 0,
92-
textAlign: 'left',
93-
height: 'auto',
94-
fontSize: 'inherit',
95-
fontWeight: 700,
96-
}))
97-
9890
export const PrivacyPolicyFooterLink: FC = () => {
9991
const { t } = useTranslation()
10092
return (
@@ -111,9 +103,11 @@ export const ReopenAnalyticsConsentButton = () => {
111103
const context = useContext(AnalyticsContext)
112104
if (context === null) throw new Error('must be used within AnalyticsContext')
113105
return (
114-
<StyledPrivacyButton size="small" color="inherit" onClick={() => context.reopenAnalyticsConsent()}>
115-
{t('analyticsConsent.settings')}
116-
</StyledPrivacyButton>
106+
<Link asChild textColor="inherit">
107+
<button type="button" onClick={() => context.reopenAnalyticsConsent()}>
108+
{t('analyticsConsent.settings')}
109+
</button>
110+
</Link>
117111
)
118112
}
119113

@@ -137,11 +131,7 @@ export const AnalyticsConsentView = (props: {
137131
t={t}
138132
components={{
139133
PrivacyPolicyLink: (
140-
<Link
141-
href={import.meta.env.REACT_APP_PRIVACY_POLICY}
142-
target="_blank"
143-
sx={{ fontWeight: 400, textDecoration: 'underline' }}
144-
/>
134+
<Link href={import.meta.env.REACT_APP_PRIVACY_POLICY} target="_blank" className="underline" />
145135
),
146136
}}
147137
values={{ acceptButtonLabel: t('analyticsConsent.acceptButtonLabel') }}
Lines changed: 26 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,14 @@
11
import { FC, ReactNode } from 'react'
22
import { Trans, useTranslation } from 'react-i18next'
3-
import Box from '@mui/material/Box'
4-
import Typography from '@mui/material/Typography'
53
import { useScreenSize } from '../../hooks/useScreensize'
6-
import { styled } from '@mui/material/styles'
7-
import Link from '@mui/material/Link'
8-
import { useTheme } from '@mui/material/styles'
94
import { useConstant } from '../../hooks/useConstant'
105
import { AppendMobileSearch } from '../AppendMobileSearch'
116
import { SearchScope } from '../../../types/searchScope'
127
import { api, github } from '../../utils/externalLinks'
138
import { ReopenAnalyticsConsentButton } from 'app/components/AnalyticsConsent'
14-
15-
const FooterBox = styled(Box, {
16-
shouldForwardProp: prop => prop !== 'enableMobileSearch',
17-
})<{ enableMobileSearch: boolean }>(({ theme, enableMobileSearch }) => ({
18-
display: 'flex',
19-
width: '100%',
20-
justifyContent: 'space-between',
21-
padding: theme.spacing(5, enableMobileSearch ? 4 : 0),
22-
[theme.breakpoints.up('sm')]: {
23-
flex: '0 1 100%',
24-
padding: theme.spacing(5, 0),
25-
},
26-
}))
27-
28-
const StyledBox = styled(Box)(({ theme }) => ({
29-
display: 'flex',
30-
alignItems: 'center',
31-
}))
32-
33-
const StyledLinksGroup = styled(Box)(({ theme }) => ({
34-
display: 'flex',
35-
gap: theme.spacing(3),
36-
paddingLeft: theme.spacing(2),
37-
}))
38-
39-
const StyledTypography = styled(Typography)(() => ({
40-
display: 'flex',
41-
alignItems: 'center',
42-
gap: 2,
43-
flexWrap: 'wrap',
44-
}))
9+
import { Typography } from '@oasisprotocol/ui-library/src/components/typography'
10+
import { Link } from '@oasisprotocol/ui-library/src/components/link'
11+
import { cn } from '@oasisprotocol/ui-library/src/lib/utils'
4512

4613
interface FooterProps {
4714
scope?: SearchScope
@@ -50,36 +17,36 @@ interface FooterProps {
5017
}
5118

5219
export const Footer: FC<FooterProps> = ({ scope, mobileSearchAction, enableMobileSearch = true }) => {
53-
const theme = useTheme()
5420
const { t } = useTranslation()
5521
const { isMobile, isTablet } = useScreenSize()
5622
const currentYear = useConstant(() => new Date().getFullYear())
5723
const hasMobileAction = isMobile && mobileSearchAction
58-
const privacyPolicyLinkStyles = hasMobileAction ? { order: 1, flexBasis: '100%' } : {}
5924

6025
return (
6126
<footer>
62-
<FooterBox enableMobileSearch={enableMobileSearch}>
27+
<div
28+
className={cn('flex justify-between items-center py-6 sm:px-6', enableMobileSearch ? 'px-2' : 'px-4')}
29+
>
6330
{isTablet ? (
6431
<AppendMobileSearch
6532
scope={scope}
6633
action={isMobile && mobileSearchAction}
6734
enableMobileSearch={enableMobileSearch}
6835
>
69-
<StyledTypography variant="footer">
70-
<Box sx={{ whiteSpace: 'nowrap' }}>{t('footer.mobileTitle')} |</Box>
71-
<Box sx={privacyPolicyLinkStyles}>
36+
<Typography variant="xsmall" textColor="muted" className="flex items-center gap-0.5 flex-wrap">
37+
<div className="whitespace-nowrap">{t('footer.mobileTitle')} |</div>
38+
<div className={cn(hasMobileAction && 'order-1 basis-full sm:order-none sm:basis-auto')}>
7239
<ReopenAnalyticsConsentButton />
7340
{!hasMobileAction && ' | '}
74-
</Box>
75-
<Box>{currentYear}</Box>
76-
</StyledTypography>
41+
</div>
42+
<div>{currentYear}</div>
43+
</Typography>
7744
</AppendMobileSearch>
7845
) : (
7946
<>
80-
<StyledBox>
47+
<div className="flex items-center">
8148
{import.meta.env.REACT_APP_BUILD_SHA && (
82-
<Typography variant="footer">
49+
<Typography variant="xsmall" textColor="muted">
8350
<Trans
8451
t={t}
8552
i18nKey="footer.version"
@@ -89,7 +56,7 @@ export const Footer: FC<FooterProps> = ({ scope, mobileSearchAction, enableMobil
8956
href={`${github.releaseTag}${import.meta.env.REACT_APP_BUILD_VERSION}`}
9057
rel="noopener noreferrer"
9158
target="_blank"
92-
sx={{ color: theme.palette.layout.main }}
59+
textColor="inherit"
9360
/>
9461
) : (
9562
<>-</>
@@ -99,7 +66,7 @@ export const Footer: FC<FooterProps> = ({ scope, mobileSearchAction, enableMobil
9966
href={`${github.commit}${import.meta.env.REACT_APP_BUILD_SHA}`}
10067
rel="noopener noreferrer"
10168
target="_blank"
102-
sx={{ color: theme.palette.layout.main }}
69+
textColor="inherit"
10370
/>
10471
),
10572
}}
@@ -125,36 +92,27 @@ export const Footer: FC<FooterProps> = ({ scope, mobileSearchAction, enableMobil
12592
/>
12693
</Typography>
12794
)}
128-
<StyledLinksGroup>
129-
<Typography variant="footer">
95+
<div className="flex gap-2 pl-1">
96+
<Typography variant="xsmall" textColor="muted">
13097
{' | '}
131-
<Link
132-
href={api.spec}
133-
rel="noopener noreferrer"
134-
target="_blank"
135-
sx={{ color: theme.palette.layout.main }}
136-
>
98+
<Link href={api.spec} rel="noopener noreferrer" target="_blank" textColor="inherit">
13799
{t('footer.apiDocs')}
138100
</Link>
139101
</Typography>
140-
<Typography variant="footer">
141-
<Link
142-
href={github.home}
143-
rel="noopener noreferrer"
144-
target="_blank"
145-
sx={{ color: theme.palette.layout.main }}
146-
>
102+
<Typography variant="xsmall" textColor="muted">
103+
{' | '}
104+
<Link href={github.home} rel="noopener noreferrer" target="_blank" textColor="inherit">
147105
{t('footer.github')}
148106
</Link>
149107
</Typography>
150-
</StyledLinksGroup>
151-
</StyledBox>
152-
<Typography variant="footer">
108+
</div>
109+
</div>
110+
<Typography variant="xsmall" textColor="muted">
153111
{t('footer.title')} | <ReopenAnalyticsConsentButton /> | {currentYear}
154112
</Typography>
155113
</>
156114
)}
157-
</FooterBox>
115+
</div>
158116
</footer>
159117
)
160118
}

src/styles/theme/defaultTheme.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ declare module '@mui/material/Button' {
4646

4747
declare module '@mui/material/Typography' {
4848
interface TypographyPropsVariantOverrides {
49-
footer: true
5049
select: true
5150
mono: true
5251
}
@@ -522,15 +521,6 @@ export const defaultTheme = createTheme({
522521
fontWeight: 700,
523522
}),
524523
},
525-
{
526-
props: { variant: 'footer' },
527-
style: ({ theme }) => ({
528-
color: theme.palette.layout.main,
529-
fontWeight: 400,
530-
fontSize: '12px',
531-
lineHeight: '18px',
532-
}),
533-
},
534524
{
535525
props: { variant: 'select' },
536526
style: () => ({

0 commit comments

Comments
 (0)