Skip to content

Commit

Permalink
Merge pull request #1414 from oasisprotocol/mz/defaultProps
Browse files Browse the repository at this point in the history
Remove usage of deprecated React API
  • Loading branch information
buberdds authored May 15, 2024
2 parents 37a8933 + 67c6549 commit 5ed9ae3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 47 deletions.
1 change: 1 addition & 0 deletions .changelog/1414.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove usage of deprecated React API
12 changes: 6 additions & 6 deletions src/app/components/Search/SearchSuggestionsButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC } from 'react'
import Typography from '@mui/material/Typography'
import { styled } from '@mui/material/styles'
import Button from '@mui/material/Button'
import Button, { ButtonProps } from '@mui/material/Button'
import { Trans, useTranslation } from 'react-i18next'
import { COLORS } from '../../../styles/theme/colors'
import WidgetsIcon from '@mui/icons-material/Widgets'
Expand All @@ -12,18 +12,18 @@ import { searchSuggestionTerms } from './search-utils'
import { OptionalBreak } from '../OptionalBreak'
import { SearchScope } from '../../../types/searchScope'

const PlainTextButton = styled(Button)({
const StyledPlainTextButton = styled(Button)({
fontSize: 'inherit',
textTransform: 'none',
paddingLeft: 0,
paddingRight: 0,
minWidth: 0,
height: '1em',
})
PlainTextButton.defaultProps = {
variant: 'text',
color: 'inherit',
}

const PlainTextButton = (props: ButtonProps) => (
<StyledPlainTextButton variant="text" color="inherit" {...props} />
)

export const SuggestionButton = styled(PlainTextButton)({
gap: '0.2ch', // Space after icon
Expand Down
12 changes: 6 additions & 6 deletions src/app/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNavigate, useSearchParams } from 'react-router-dom'
import TextField, { textFieldClasses } from '@mui/material/TextField'
import InputAdornment, { inputAdornmentClasses } from '@mui/material/InputAdornment'
import { styled } from '@mui/material/styles'
import Button from '@mui/material/Button'
import Button, { ButtonProps } from '@mui/material/Button'
import Box from '@mui/material/Box'
import SearchIcon from '@mui/icons-material/Search'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -70,7 +70,7 @@ const SearchForm = styled('form', {

interface SearchButtonProps extends StyledBaseProps {}

export const SearchButton = styled(Button, {
export const StyledSearchButton = styled(Button, {
shouldForwardProp: (prop: PropertyKey) =>
!(['searchVariant'] as (keyof SearchButtonProps)[]).includes(prop as keyof SearchButtonProps),
})<SearchButtonProps>(({ theme, searchVariant }) => ({
Expand All @@ -90,10 +90,10 @@ export const SearchButton = styled(Button, {
}
: {}),
}))
SearchButton.defaultProps = {
variant: 'contained',
color: 'primary',
}

export const SearchButton = (props: ButtonProps & SearchButtonProps) => (
<StyledSearchButton variant="contained" color="primary" {...props} />
)

export interface SearchProps {
scope?: SearchScope
Expand Down
10 changes: 3 additions & 7 deletions src/app/pages/HomePage/Graph/HelpScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ const SwiperBox = styled(Box)(() => ({
height: '40%',
}))

export const GetStartedBtn = styled(Button)({})
GetStartedBtn.defaultProps = {
variant: 'contained',
color: 'primary',
}

interface Step {
icon: ReactElement
label: string
Expand Down Expand Up @@ -135,7 +129,9 @@ const HelpScreen: FC<HelpScreenProps> = ({ setParaTimeStep }) => {
/>
)}
{activeStep > 1 && (
<GetStartedBtn onClick={onGetStartedClick}>{t('home.helpScreen.getStarted')}</GetStartedBtn>
<Button variant="contained" color="primary" onClick={onGetStartedClick}>
{t('home.helpScreen.getStarted')}
</Button>
)}
</HelpScreenContainer>
)
Expand Down
20 changes: 10 additions & 10 deletions src/app/pages/HomePage/Graph/ParaTimeSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ export const ExploreBtn = styled(Button)(({ theme }) => ({
paddingRight: theme.spacing(6),
},
}))
ExploreBtn.defaultProps = {
color: 'secondary',
variant: 'contained',
}

export const ZoomOutBtn = styled(Button)(({ theme }) => ({
color: theme.palette.layout.graphZoomOutText,
Expand All @@ -118,11 +114,7 @@ export const ZoomOutBtn = styled(Button)(({ theme }) => ({
backgroundColor: 'transparent',
},
}))
ZoomOutBtn.defaultProps = {
color: 'primary',
variant: 'text',
startIcon: <ChevronLeftIcon />,
}

const ZoomOutBtnFade = styled(Fade)(() => ({
transitionDelay: '500ms !important',
}))
Expand Down Expand Up @@ -267,13 +259,21 @@ const ParaTimeSelectorCmp: FC<ParaTimeSelectorProps> = ({
</QuickPinchZoomOuter>
{!isMobile && (
<ZoomOutBtnFade in={graphZoomedIn}>
<ZoomOutBtn onClick={onZoomOutClick} disabled={disabled}>
<ZoomOutBtn
color="primary"
variant="text"
startIcon={<ChevronLeftIcon />}
onClick={onZoomOutClick}
disabled={disabled}
>
{t('home.zoomOutBtnText')}
</ZoomOutBtn>
</ZoomOutBtnFade>
)}
{isMobile && ParaTimeSelectorUtils.showExploreBtn(step) && (
<ExploreBtn
color="secondary"
variant="contained"
onClick={onExploreClick}
aria-label={exploreBtnTextTranslated}
sx={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' }}
Expand Down
15 changes: 2 additions & 13 deletions src/app/pages/SearchResultsPage/ResultsGroupByType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Link as RouterLink } from 'react-router-dom'
import Button from '@mui/material/Button'
import Box from '@mui/material/Box'
import Divider from '@mui/material/Divider'
import { styled } from '@mui/material/styles'
import Typography from '@mui/material/Typography'

interface Props<T> {
Expand All @@ -14,16 +13,6 @@ interface Props<T> {
linkLabel: string
}

export const ViewResultButton = (() => {
const ViewResultButton = styled(Button)({})
ViewResultButton.defaultProps = {
variant: 'contained',
color: 'primary',
}
// Type cast is needed because styled type breaks `<ViewResultButton component={RouterLink}`
return ViewResultButton as typeof Button
})()

/**
* Component for displaying search results of the same type, from the same network.
*
Expand Down Expand Up @@ -51,9 +40,9 @@ export function ResultsGroupByType<T>({ title, results, resultComponent, link, l
<div key={i}>
{resultComponent(item)}
<Box sx={{ display: 'flex', justifyContent: 'center', mt: 5 }}>
<ViewResultButton component={RouterLink} to={link(item)}>
<Button variant="contained" color="primary" component={RouterLink} to={link(item)}>
{linkLabel}
</ViewResultButton>
</Button>
</Box>
{i < results.length - 1 && <Divider variant="card" />}
</div>
Expand Down
5 changes: 0 additions & 5 deletions src/stories/ButtonsShowroom.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { SearchButton } from '../app/components/Search'
import { SuggestionButton } from '../app/components/Search/SearchSuggestionsButtons'
import { Select } from '../app/components/Select'
import { ExploreBtn, ZoomOutBtn } from '../app/pages/HomePage/Graph/ParaTimeSelector'
import { GetStartedBtn } from '../app/pages/HomePage/Graph/HelpScreen'
import { ViewResultButton } from '../app/pages/SearchResultsPage/ResultsGroupByType'
import { LoadMoreButton } from '../app/components/LoadMoreButton'
import { withRouter } from 'storybook-addon-react-router-v6'
import WidgetsIcon from '@mui/icons-material/Widgets'
Expand All @@ -18,7 +16,6 @@ const Template: StoryFn = () => {
return (
<div>
<SearchButton searchVariant="button">SearchButton</SearchButton>
<ViewResultButton>ViewResultButton</ViewResultButton>
<SuggestionButton>
<WidgetsIcon sx={{ fontSize: '18px' }} /> SuggestionButton
</SuggestionButton>
Expand All @@ -28,8 +25,6 @@ const Template: StoryFn = () => {
<Select options={[{ label: 'Select', value: 'Select' }]} />
<br />
<br />

<GetStartedBtn>GetStartedBtn</GetStartedBtn>
<ExploreBtn>ExploreBtn</ExploreBtn>
<ZoomOutBtn>ZoomOutBtn</ZoomOutBtn>
<br />
Expand Down

0 comments on commit 5ed9ae3

Please sign in to comment.