Skip to content

Commit 9ebd1ee

Browse files
committed
add block styling to escape hatches
1 parent 001028e commit 9ebd1ee

41 files changed

Lines changed: 298 additions & 36 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
32 Bytes
Loading

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import lightNarrowBg from '../fixtures/images/light-vertical-banner.png'
99
import lightWideBg from '../fixtures/images/light-horizontal-banner.png'
1010
import darkNarrowBg from '../fixtures/images/dark-vertical-banner.png'
1111
import darkWideBg from '../fixtures/images/dark-horizontal-banner.png'
12+
import placeholderImage from '../fixtures/images/placeholder.png'
1213

1314
import {LogoGithubIcon} from '@primer/octicons-react'
1415
import {ThemeProvider} from '../ThemeProvider'
@@ -100,6 +101,21 @@ export const AlignedCenter = () => (
100101
</BreakoutBanner>
101102
)
102103

104+
export const LeadingMedia = () => (
105+
<BreakoutBanner
106+
leadingVisual={
107+
<picture>
108+
<img src={placeholderImage} alt="Placeholder leading visual" width={64} height={64} />
109+
</picture>
110+
}
111+
>
112+
<BreakoutBanner.Heading>Where the most ambitious teams build great things</BreakoutBanner.Heading>
113+
<BreakoutBanner.LinkGroup>
114+
<Link href="#">Primary action</Link>
115+
</BreakoutBanner.LinkGroup>
116+
</BreakoutBanner>
117+
)
118+
103119
export const OptionalDescription = () => (
104120
<BreakoutBanner>
105121
<BreakoutBanner.Heading>Where the most ambitious teams build great things</BreakoutBanner.Heading>

packages/react/src/BreakoutBanner/BreakoutBanner.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
margin-block-end: var(--base-size-48);
6363
}
6464

65+
.BreakoutBanner-leadingVisual :is(img, picture) {
66+
display: block;
67+
}
68+
6569
/* Regular */
6670
@media screen and (min-width: 48rem) {
6771
.BreakoutBanner {

packages/react/src/BreakoutBanner/BreakoutBanner.test.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,23 @@ describe('BreakoutBanner', () => {
102102
})
103103

104104
it('provides an escape hatch to render a custom leading visual', () => {
105-
const MockLeadingVisual = () => <svg data-testid="mock-svg" aria-label="Mock SVG" />
105+
const MockLeadingVisual = () => (
106+
<picture>
107+
<img src="image.jpg" alt="Mock visual" />
108+
</picture>
109+
)
106110

107-
const {getByTestId} = render(
111+
const {getByRole} = render(
108112
<BreakoutBanner leadingVisual={<MockLeadingVisual />}>
109113
<BreakoutBanner.Heading>This is your heading</BreakoutBanner.Heading>
110114
<BreakoutBanner.Description>This is your description</BreakoutBanner.Description>
111115
</BreakoutBanner>,
112116
)
113117

114-
const elLeadingVisual = getByTestId('mock-svg')
118+
const leadingVisual = getByRole('img', {name: 'Mock visual'})
115119

116-
expect(elLeadingVisual).toBeInTheDocument()
120+
expect(leadingVisual).toBeInTheDocument()
121+
expect(leadingVisual.closest('div')).toHaveClass('BreakoutBanner-leadingVisual')
117122
})
118123

119124
it('provides a way to pass a background image', () => {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ test.describe('Visual Comparison: BreakoutBanner', () => {
7171
await expect(page).toHaveScreenshot({fullPage: true})
7272
})
7373

74+
test('BreakoutBanner / Leading Media', async ({page}) => {
75+
await page.goto(
76+
'http://localhost:6006/iframe.html?args=&id=components-breakoutbanner-features--leading-media&viewMode=story',
77+
{waitUntil: 'networkidle'},
78+
)
79+
await page.locator('body.sb-show-main').waitFor({state: 'visible'})
80+
81+
await page.waitForTimeout(500)
82+
await expect(page).toHaveScreenshot({fullPage: true})
83+
})
84+
7485
test('BreakoutBanner / Optional Description', async ({page}) => {
7586
await page.goto(
7687
'http://localhost:6006/iframe.html?args=&id=components-breakoutbanner-features--optional-description&viewMode=story',
Loading

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,22 @@ export const WithLeadingComponent: Story = {
271271
),
272272
}
273273

274+
export const WithMediaComponents: Story = {
275+
render: () => (
276+
<CTABanner
277+
leadingComponent={() => (
278+
<picture>
279+
<img src={placeholderImage} alt="Placeholder leading visual" width={64} height={64} />
280+
</picture>
281+
)}
282+
trailingComponent={() => <img src={placeholderImage} alt="Placeholder trailing visual" width={64} height={64} />}
283+
>
284+
<CTABanner.Heading>Where the most ambitious teams build great things</CTABanner.Heading>
285+
<CTABanner.Description>Build, scale, and deliver secure software with GitHub.</CTABanner.Description>
286+
</CTABanner>
287+
),
288+
}
289+
274290
export const WithOctovisualLeadingComponent: Story = {
275291
render: () => (
276292
<CTABanner

packages/react/src/CTABanner/CTABanner.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
margin: 0 auto;
106106
}
107107

108+
.CTABanner-content :is(img, picture) {
109+
display: block;
110+
}
111+
108112
.CTABanner--variant-minimal .CTABanner-content {
109113
--CTABanner-content-gap: 0;
110114
}

packages/react/src/CTABanner/CTABanner.test.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,23 @@ describe('CTABanner', () => {
143143
})
144144

145145
it('provides an escape hatch to render a custom trailing component', () => {
146-
const trailingText = 'Custom trailing'
147-
const MockTrailingComponent = () => <div>{trailingText}</div>
146+
const MockTrailingComponent = () => (
147+
<picture>
148+
<img src="trailing.jpg" alt="Custom trailing" />
149+
</picture>
150+
)
148151

149-
const {getByText} = render(
152+
const {getByRole} = render(
150153
<CTABanner trailingComponent={MockTrailingComponent}>
151154
<CTABanner.Heading>This is your heading</CTABanner.Heading>
152155
<CTABanner.Description>This is your description</CTABanner.Description>
153156
</CTABanner>,
154157
)
155158

156-
const elTrailing = getByText(trailingText)
159+
const trailingImage = getByRole('img', {name: 'Custom trailing'})
157160

158-
expect(elTrailing).toBeInTheDocument()
161+
expect(trailingImage).toBeInTheDocument()
162+
expect(trailingImage.closest('[class*="CTABanner-content"]')).toBeInTheDocument()
159163
})
160164

161165
it('provides a way to pass a background image', () => {
@@ -433,19 +437,23 @@ describe('CTABanner', () => {
433437
})
434438

435439
it('provides an escape hatch to render a custom leading component', () => {
436-
const leadingText = 'Custom leading'
437-
const MockLeadingComponent = () => <div>{leadingText}</div>
440+
const MockLeadingComponent = () => (
441+
<picture>
442+
<img src="leading.jpg" alt="Custom leading" />
443+
</picture>
444+
)
438445

439-
const {getByText} = render(
446+
const {getByRole} = render(
440447
<CTABanner leadingComponent={MockLeadingComponent}>
441448
<CTABanner.Heading>This is your heading</CTABanner.Heading>
442449
<CTABanner.Description>This is your description</CTABanner.Description>
443450
</CTABanner>,
444451
)
445452

446-
const elLeading = getByText(leadingText)
453+
const leadingImage = getByRole('img', {name: 'Custom leading'})
447454

448-
expect(elLeading).toBeInTheDocument()
455+
expect(leadingImage).toBeInTheDocument()
456+
expect(leadingImage.closest('[class*="CTABanner-content"]')).toBeInTheDocument()
449457
})
450458

451459
it('renders leading component before heading and trailing component after children', () => {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ test.describe('Visual Comparison: CTABanner', () => {
126126
await expect(page).toHaveScreenshot({fullPage: true})
127127
})
128128

129+
test('CTABanner / With Media Components', async ({page}) => {
130+
await page.goto(
131+
'http://localhost:6006/iframe.html?args=&id=components-ctabanner-features--with-media-components&viewMode=story',
132+
{waitUntil: 'networkidle'},
133+
)
134+
await page.locator('body.sb-show-main').waitFor({state: 'visible'})
135+
136+
await page.waitForTimeout(500)
137+
await expect(page).toHaveScreenshot({fullPage: true})
138+
})
139+
129140
test('CTABanner / With Octovisual Leading Component', async ({page}) => {
130141
await page.goto(
131142
'http://localhost:6006/iframe.html?args=&id=components-ctabanner-features--with-octovisual-leading-component&viewMode=story',

0 commit comments

Comments
 (0)