Skip to content

Commit 3419824

Browse files
authored
Restore idle option to LogoSuite.Logobar (#1055)
1 parent 6772b34 commit 3419824

10 files changed

+75
-20
lines changed

.changeset/twelve-lamps-roll.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@primer/react-brand': patch
3+
---
4+
5+
Restore `idle` option to `LogoSuite.Logobar` for enabling a default paused state, and programmatic control over animation.
6+
7+
Use `marqueeSpeed="idle"` to display a logo bar that is initially paused.
8+
9+
```jsx
10+
<LogoSuite>
11+
<LogoSuite.Heading />
12+
<LogoSuite.Logobar marquee marqueeSpeed="idle" />
13+
</LogoSuite>
14+
```

packages/e2e/scripts/playwright/playwright.generate-tests.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@
9999
'components-pillar-features--frosted-glass-effect': 3000, // for image to load
100100
'components-testimonial-examples--with-frosted-glass': 4000, // for animation to complete
101101
'components-testimonial-examples--with-frosted-glass-dark': 4000, // for animation to complete
102-
'components-logosuite-features--condensed-gap': 6000, // animation only
103-
'components-logosuite-features--marquee': 6000, // animation only
104102
}
105103

106104
/**
@@ -139,6 +137,7 @@
139137
'components-hero-features--with-native-block-end-default', // for being non-deterministic due to video buffering
140138
'components-hero-features--with-youtube-video-block-end-default', // for loading a remote video
141139
'components-hero-features--with-youtube-video-inline-end', // for loading a remote video
140+
'components-logosuite-features--marquee', // for the animation
142141
]
143142

144143
const categorisedStories = Object.keys((stories as typeof StoryIndex).entries).reduce((acc, key) => {

packages/react/src/LogoSuite/LogoSuite.features.stories.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,13 @@ export const CondensedGap = () => (
102102
</LogoSuite>
103103
<LogoSuite>
104104
<LogoSuite.Heading visuallyHidden>Heading</LogoSuite.Heading>
105-
<LogoSuite.Logobar gap="condensed" marquee>
105+
<LogoSuite.Logobar gap="condensed" marquee marqueeSpeed="idle">
106106
{logos.slice(0, 12)}
107107
</LogoSuite.Logobar>
108108
</LogoSuite>
109109
</Grid.Column>
110110
</Grid>
111111
)
112-
CondensedGap.play = async ({canvasElement}) => {
113-
const canvas = within(canvasElement)
114-
115-
await new Promise(resolve => setTimeout(resolve, 3000))
116-
117-
const pauseButton = canvas.getByLabelText('Pause animation')
118-
await userEvent.click(pauseButton)
119-
}
120112

121113
export const Marquee = () => (
122114
<LogoSuite>
@@ -134,6 +126,15 @@ Marquee.play = async ({canvasElement}) => {
134126
await userEvent.click(pauseButton)
135127
}
136128

129+
export const IdleMarqueeSpeed = () => (
130+
<LogoSuite>
131+
<LogoSuite.Heading visuallyHidden>Heading</LogoSuite.Heading>
132+
<LogoSuite.Logobar marquee marqueeSpeed="idle">
133+
{logos.slice(0, 12)}
134+
</LogoSuite.Logobar>
135+
</LogoSuite>
136+
)
137+
137138
export const SlowerMarqueeSpeed = () => (
138139
<LogoSuite>
139140
<LogoSuite.Heading visuallyHidden>Heading</LogoSuite.Heading>

packages/react/src/LogoSuite/LogoSuite.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const meta: Meta<StoryProps> = {
9797

9898
marqueeSpeed: {
9999
control: 'radio',
100-
options: ['slow', 'normal'],
100+
options: ['slow', 'normal', 'idle'],
101101
table: {
102102
category: 'LogoSuite.Logobar',
103103
},

packages/react/src/LogoSuite/LogoSuite.test.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,45 @@ describe('LogoSuite', () => {
236236
expect(el.classList).toContain(expectedClass)
237237
})
238238

239+
it('can render a marquee logobar sans-animation using the idle speed option', () => {
240+
const {container, getByRole} = render(
241+
<LogoSuite>
242+
<LogoSuite.Heading visuallyHidden>{mockHeading}</LogoSuite.Heading>
243+
<LogoSuite.Logobar marquee marqueeSpeed="idle">
244+
<svg data-testid="svg1" aria-label="Mock SVG" />
245+
<svg data-testid="svg2" aria-label="Mock SVG" />
246+
</LogoSuite.Logobar>
247+
</LogoSuite>,
248+
)
249+
250+
const playButton = getByRole('button', {name: 'Play animation'})
251+
expect(playButton).toBeInTheDocument()
252+
expect(container.querySelector('.LogoSuite__logobar--paused')).toBeInTheDocument()
253+
})
254+
255+
it('can start the animation on idle marquee speed settings by pressing the play button', async () => {
256+
const user = userEvent.setup()
257+
258+
const {container, getByRole} = render(
259+
<LogoSuite>
260+
<LogoSuite.Heading visuallyHidden>{mockHeading}</LogoSuite.Heading>
261+
<LogoSuite.Logobar marquee marqueeSpeed="idle">
262+
<svg data-testid="svg1" aria-label="Mock SVG" />
263+
<svg data-testid="svg2" aria-label="Mock SVG" />
264+
</LogoSuite.Logobar>
265+
</LogoSuite>,
266+
)
267+
268+
const playButtonEl = getByRole('button', {name: 'Play animation'})
269+
270+
await user.click(playButtonEl)
271+
272+
const pauseButtonEl = getByRole('button', {name: 'Pause animation'})
273+
274+
expect(pauseButtonEl).toBeInTheDocument()
275+
expect(container.querySelector('.LogoSuite__logobar--paused')).not.toBeInTheDocument()
276+
})
277+
239278
it('renders a pause button when the marquee prop is true', () => {
240279
const {getByRole} = render(
241280
<LogoSuite>

packages/react/src/LogoSuite/LogoSuite.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export type LogoSuiteLogoBarProps = BaseProps<HTMLDivElement> & {
200200
/**
201201
* The speed of the marquee effect
202202
*/
203-
marqueeSpeed?: 'slow' | 'normal'
203+
marqueeSpeed?: 'slow' | 'normal' | 'idle'
204204
/**
205205
* The stylistic variant of the LogoBar.
206206
*/
@@ -221,7 +221,7 @@ const _LogoBar = forwardRef(
221221
ref: Ref<HTMLDivElement>,
222222
) => {
223223
const [prefersReducedMotion, setPrefersReducedMotion] = useState(false)
224-
const [isPlaying, setIsPlaying] = useState(marquee && !prefersReducedMotion)
224+
const [isPlaying, setIsPlaying] = useState(marquee && !prefersReducedMotion && marqueeSpeed !== 'idle')
225225

226226
const childrenCount = React.Children.toArray(children).length
227227
variant ??= childrenCount <= 5 ? 'emphasis' : 'muted'
@@ -242,8 +242,8 @@ const _LogoBar = forwardRef(
242242
}, [])
243243

244244
useEffect(() => {
245-
setIsPlaying(marquee && !prefersReducedMotion)
246-
}, [marquee, prefersReducedMotion])
245+
setIsPlaying(marquee && !prefersReducedMotion && marqueeSpeed !== 'idle')
246+
}, [marquee, prefersReducedMotion, marqueeSpeed])
247247

248248
const defaultProps = {
249249
ref,

packages/react/src/LogoSuite/LogoSuite.visual.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ test.describe('Visual Comparison: LogoSuite', () => {
9191
'http://localhost:6006/iframe.html?args=&id=components-logosuite-features--condensed-gap&viewMode=story',
9292
)
9393

94-
await page.waitForTimeout(6000)
94+
await page.waitForTimeout(500)
9595
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
9696
})
9797

98-
test('LogoSuite / Marquee', async ({page}) => {
99-
await page.goto('http://localhost:6006/iframe.html?args=&id=components-logosuite-features--marquee&viewMode=story')
98+
test('LogoSuite / Idle Marquee Speed', async ({page}) => {
99+
await page.goto(
100+
'http://localhost:6006/iframe.html?args=&id=components-logosuite-features--idle-marquee-speed&viewMode=story',
101+
)
100102

101-
await page.waitForTimeout(6000)
103+
await page.waitForTimeout(500)
102104
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
103105
})
104106

-8.89 KB
Loading
Loading

0 commit comments

Comments
 (0)