Skip to content

Commit d90c7fb

Browse files
katina-anachkovaKatina Anachkova
andauthored
use styled components; preserve next/link styling and extract style c… (#2030)
* use styled components; preserve next/link styling and extract style constants * revert changes in LinkButton.tsx --------- Co-authored-by: Katina Anachkova <[email protected]>
1 parent 3437316 commit d90c7fb

File tree

6 files changed

+79
-68
lines changed

6 files changed

+79
-68
lines changed

src/components/client/auth/profile/MyCampaignsTable.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useTranslation } from 'next-i18next'
22
import { useState, useMemo } from 'react'
33
import { DataGrid, GridColDef, GridRenderCellParams } from '@mui/x-data-grid'
44
import { Tooltip, Button, Box, Typography } from '@mui/material'
5+
import { styled } from '@mui/material/styles'
56

67
import { getExactDateTime, getRelativeDate } from 'common/util/date'
78
import { money } from 'common/util/money'
@@ -30,6 +31,16 @@ const classes = {
3031
boxTitle: `${PREFIX}-boxTitle`,
3132
}
3233

34+
const StyledDataGrid = styled(DataGrid)({
35+
background: theme.palette.common.white,
36+
border: 'none',
37+
width: 'calc(100% - 48px)',
38+
left: '24px',
39+
overflowY: 'auto',
40+
overflowX: 'hidden',
41+
borderRadius: '0 0 13px 13px',
42+
})
43+
3344
export default function MyCampaingsTable() {
3445
const { t, i18n } = useTranslation()
3546
const [viewId, setViewId] = useState<string | undefined>()
@@ -240,16 +251,7 @@ export default function MyCampaingsTable() {
240251
<Typography className={classes.h3}>{t('profile:myCampaigns.history')}</Typography>
241252
</Box>
242253
<ProfileTab name={ProfileTabs.myCampaigns}>
243-
<DataGrid
244-
style={{
245-
background: theme.palette.common.white,
246-
border: 'none',
247-
width: 'calc(100% - 48px)',
248-
left: '24px',
249-
overflowY: 'auto',
250-
overflowX: 'hidden',
251-
borderRadius: '0 0 13px 13px',
252-
}}
254+
<StyledDataGrid
253255
rows={campaigns || []}
254256
columns={columns}
255257
initialState={{ pagination: { paginationModel: { pageSize: 5 } } }}

src/components/common/LinkButton.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ export type NextLinkProps = ButtonProps &
99
const LinkButton = (
1010
{ href, as, prefetch, legacyBehavior, locale, disabled, ...props }: NextLinkProps,
1111
ref: Ref<LinkRef>,
12-
) => (
13-
<Link
14-
href={href}
15-
as={as}
16-
prefetch={prefetch}
17-
locale={locale}
18-
passHref
19-
tabIndex={disabled ? -1 : 0}
20-
legacyBehavior={legacyBehavior}
21-
style={{ pointerEvents: disabled ? 'none' : 'all' }}>
22-
<Button tabIndex={-1} ref={ref} disabled={disabled} {...props} />
23-
</Link>
24-
)
12+
) => {
13+
return (
14+
<Link
15+
href={href}
16+
as={as}
17+
prefetch={prefetch}
18+
locale={locale}
19+
passHref
20+
tabIndex={disabled ? -1 : 0}
21+
legacyBehavior={legacyBehavior}
22+
style={{ pointerEvents: disabled ? 'none' : 'all' }}>
23+
<Button tabIndex={-1} ref={ref} disabled={disabled} {...props} />
24+
</Link>
25+
)
26+
}
2527

2628
export default forwardRef(LinkButton)

src/components/common/LinkMenuItem.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ import theme from 'common/theme'
55

66
export type LinkRef = HTMLAnchorElement
77
export type NextLinkProps = MenuItemProps & Pick<LinkProps, 'href' | 'as' | 'prefetch' | 'locale'>
8+
89
export default function LinkMenuItem({ href, as, prefetch, locale, ...props }: NextLinkProps) {
10+
const style = { color: theme.palette.text.primary }
11+
912
return (
10-
<Link
11-
as={as}
12-
passHref
13-
href={href}
14-
prefetch={prefetch}
15-
locale={locale}
16-
style={{ color: theme.palette.text.primary }}>
13+
<Link as={as} passHref href={href} prefetch={prefetch} locale={locale} style={style}>
1714
<MenuItem {...props} />
1815
</Link>
1916
)

src/components/common/campaign-types/grid/Grid.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useTranslation } from 'next-i18next'
44
import { Box, Typography } from '@mui/material'
55
import { DataGrid, GridColDef, GridRenderCellParams } from '@mui/x-data-grid'
66
import { observer } from 'mobx-react'
7-
7+
import { styled } from '@mui/material/styles'
88
import { routes } from 'common/routes'
99
import GridActions from 'components/admin/GridActions'
1010
import { CampaignTypesResponse } from 'gql/campaign-types'
@@ -15,6 +15,18 @@ import { ModalStore } from '../CampaignTypesPage'
1515
import DetailsModal from './DetailsModal'
1616
import DeleteModal from './DeleteModal'
1717

18+
const StyledDataGrid = styled(DataGrid)({
19+
background: theme.palette.common.white,
20+
position: 'absolute',
21+
height: 'calc(100vh - 300px)',
22+
border: 'none',
23+
width: 'calc(100% - 48px)',
24+
left: '24px',
25+
overflowY: 'auto',
26+
overflowX: 'hidden',
27+
borderRadius: '0 0 13px 13px',
28+
})
29+
1830
export default observer(function Grid() {
1931
const [paginationModel, setPaginationModel] = useState({
2032
pageSize: 10,
@@ -82,18 +94,7 @@ export default observer(function Grid() {
8294
return (
8395
<>
8496
<Box sx={{ marginTop: '2%', mx: 'auto', width: 700 }}>
85-
<DataGrid
86-
style={{
87-
background: theme.palette.common.white,
88-
position: 'absolute',
89-
height: 'calc(100vh - 300px)',
90-
border: 'none',
91-
width: 'calc(100% - 48px)',
92-
left: '24px',
93-
overflowY: 'auto',
94-
overflowX: 'hidden',
95-
borderRadius: '0 0 13px 13px',
96-
}}
97+
<StyledDataGrid
9798
rows={data || []}
9899
columns={columns}
99100
pageSizeOptions={[5, 10]}

src/components/common/file-upload/FileUpload.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { Button } from '@mui/material'
1+
import Button from '@mui/material/Button'
2+
import { styled } from '@mui/material/styles'
3+
4+
const Input = styled('input')({
5+
display: 'none',
6+
})
27

38
function FileUpload({
49
onUpload,
@@ -11,11 +16,10 @@ function FileUpload({
1116
}) {
1217
return (
1318
<label htmlFor="contained-button-file">
14-
<input
19+
<Input
1520
id="contained-button-file"
1621
multiple
1722
type="file"
18-
style={{ display: 'none' }}
1923
onChange={(e) => onUpload([...(e.target.files as FileList)])}
2024
{...rest}
2125
/>

src/components/common/file-upload/UploadedFilesList.tsx

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { useTranslation } from 'next-i18next'
1313
import { createContext, useContext, useEffect, useState } from 'react'
1414
import CenteredSpinner from '../CenteredSpinner'
15-
15+
import { styled } from '@mui/material/styles'
1616
export interface FilesListContext {
1717
deleteMutation: (file: UploadedFile) => Promise<unknown>
1818
files: UploadedFile[]
@@ -100,6 +100,27 @@ export function FilePreview(f: UploadedFile) {
100100
const [display, setDisplay] = useState<'block' | 'none'>('none')
101101
const [blobUrl, setBlobUrl] = useState<string | undefined>()
102102

103+
const StyledDiv = styled('div')({
104+
position: 'fixed',
105+
top: '5vw',
106+
left: '5vh',
107+
boxShadow: '2px 4px 5px',
108+
width: '90vw',
109+
height: '90vh',
110+
zIndex: 99999,
111+
display,
112+
backgroundColor: 'white',
113+
})
114+
115+
const FixedDimentionsDiv = styled('div')({
116+
width: '100%',
117+
height: '100%',
118+
})
119+
120+
const StyledIFrame = styled('iframe')({
121+
width: '100%',
122+
height: '100%',
123+
})
103124
useEffect(() => {
104125
if (fetch) {
105126
setDisplay('block')
@@ -118,29 +139,13 @@ export function FilePreview(f: UploadedFile) {
118139
<Preview />
119140
</IconButton>
120141
</Tooltip>
121-
<div
122-
style={{
123-
position: 'fixed',
124-
top: '5vw',
125-
left: '5vh',
126-
boxShadow: '2px 4px 5px',
127-
width: '90vw',
128-
height: '90vh',
129-
zIndex: 99999,
130-
display,
131-
backgroundColor: 'white',
132-
}}>
142+
<StyledDiv>
133143
{display === 'block' ? (
134-
<iframe
135-
id={f.id}
136-
src={blobUrl}
137-
allowFullScreen={true}
138-
style={{ width: '100%', height: '100%' }}
139-
/>
144+
<StyledIFrame id={f.id} src={blobUrl} allowFullScreen={true} />
140145
) : (
141-
<div style={{ width: '100%', height: '100%' }}>
146+
<FixedDimentionsDiv>
142147
<CenteredSpinner />
143-
</div>
148+
</FixedDimentionsDiv>
144149
)}
145150
<Button
146151
color="secondary"
@@ -149,7 +154,7 @@ export function FilePreview(f: UploadedFile) {
149154
onClick={() => setDisplay('none')}>
150155
<Close />
151156
</Button>
152-
</div>
157+
</StyledDiv>
153158
</>
154159
)
155160
}

0 commit comments

Comments
 (0)