Skip to content

Commit

Permalink
Merge pull request #1502 from jay-hodgson/PORTALS-3312b
Browse files Browse the repository at this point in the history
PORTALS-3312 (followup): add a fade and slide to portal feature highlight image
  • Loading branch information
jay-hodgson authored Jan 15, 2025
2 parents 972bd75 + 950bfb4 commit b37d1df
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PortalFeatureHighlights, {
} from './PortalFeatureHighlights'
import { MemoryRouter } from 'react-router-dom'
import { render, screen } from '@testing-library/react'
import { mockAllIsIntersecting } from 'react-intersection-observer/test-utils'

describe('PortalFeatureHighlights component', () => {
const props: PortalFeatureHighlightsProps = {
Expand All @@ -29,6 +30,7 @@ describe('PortalFeatureHighlights component', () => {

it('renders image with correct src', () => {
renderComponent(props)
mockAllIsIntersecting(true)
const image = screen.getByRole('img')
expect(image).toHaveAttribute('src', 'test-image.jpg')
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { Typography, Button, CardMedia, Stack, Box } from '@mui/material'
import {
Typography,
Button,
CardMedia,
Stack,
Box,
Fade,
Slide,
} from '@mui/material'
import React from 'react'
import { useInView } from 'react-intersection-observer'
import { Link } from 'react-router-dom'

export type PortalFeatureHighlightsProps = {
Expand All @@ -11,11 +20,14 @@ export type PortalFeatureHighlightsProps = {
link?: string
}

const transitionTimeoutMs = 400

const PortalFeatureHighlights = (props: PortalFeatureHighlightsProps) => {
const { reverseOrder, image, title, buttonText, summaryText, link } = props

const [ref, inView] = useInView({ threshold: 0.3, triggerOnce: true })
return (
<Box
ref={ref}
sx={{
display: 'grid',
padding: { xs: '40px', lg: '80px' },
Expand All @@ -32,17 +44,29 @@ const PortalFeatureHighlights = (props: PortalFeatureHighlightsProps) => {
},
}}
>
<CardMedia
component="img"
image={image}
sx={{
gridArea: 'image',
borderRadius: '12px',
height: '100%',
width: '100%',
objectFit: 'cover',
}}
/>
<Fade in={inView} timeout={transitionTimeoutMs}>
<div>
<Slide
direction={reverseOrder ? 'left' : 'right'}
timeout={transitionTimeoutMs}
in={inView}
>
<div>
<CardMedia
component="img"
image={image}
sx={{
gridArea: 'image',
borderRadius: '12px',
height: '100%',
width: '100%',
objectFit: 'cover',
}}
/>
</div>
</Slide>
</div>
</Fade>
<Stack
sx={{
gridArea: 'content',
Expand Down

0 comments on commit b37d1df

Please sign in to comment.