Skip to content

Commit 5c2c9d9

Browse files
authored
feat: fix layout shifts (#1392)
* feat/fix layout shifts * fix: name refactoring;
1 parent 167be7b commit 5c2c9d9

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

docusaurus.config.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ module.exports = {
256256
logo: {
257257
alt: 'An octopus representing the DOM Testing Library Logo',
258258
src: 'img/octopus-64x64.png',
259+
width: 32,
260+
height: 32,
259261
},
260262
items: [
261263
{
@@ -314,7 +316,8 @@ module.exports = {
314316
},
315317
{
316318
label: 'Stack Overflow',
317-
href: 'https://stackoverflow.com/questions/tagged/react-testing-library',
319+
href:
320+
'https://stackoverflow.com/questions/tagged/react-testing-library',
318321
},
319322
{
320323
label: 'Discord',
@@ -355,6 +358,8 @@ module.exports = {
355358
logo: {
356359
src: 'img/octopus-128x128.png',
357360
alt: 'An octopus representing the DOM Testing Library Logo',
361+
width: 128,
362+
height: 128,
358363
},
359364
},
360365
algolia: {

src/components/GridBlock/index.jsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React from 'react'
99
import classNames from 'classnames'
1010
import {MarkdownBlock} from '../MarkdownBlock'
1111

12-
const renderBlockImage = (image, imageLink, imageAlt) => {
12+
const renderBlockImage = (image, imageLink, imageAlt, imageWidth, imageHeight) => {
1313
if (!image) {
1414
return null
1515
}
@@ -18,10 +18,10 @@ const renderBlockImage = (image, imageLink, imageAlt) => {
1818
<div className="blockImage">
1919
{imageLink ? (
2020
<a href={imageLink}>
21-
<img src={image} alt={imageAlt} />
21+
<img src={image} alt={imageAlt} width={imageWidth} height={imageHeight} />
2222
</a>
2323
) : (
24-
<img src={image} alt={imageAlt} />
24+
<img src={image} alt={imageAlt} width={imageWidth} height={imageHeight} />
2525
)}
2626
</div>
2727
)
@@ -67,11 +67,11 @@ export const GridBlock = props => {
6767

6868
const topLeftImage =
6969
(block.imageAlign === 'top' || block.imageAlign === 'left') &&
70-
renderBlockImage(block.image, block.imageLink, block.imageAlt)
70+
renderBlockImage(block.image, block.imageLink, block.imageAlt, block.imageWidth, block.imageHeight)
7171

7272
const bottomRightImage =
7373
(block.imageAlign === 'bottom' || block.imageAlign === 'right') &&
74-
renderBlockImage(block.image, block.imageLink, block.imageAlt)
74+
renderBlockImage(block.image, block.imageLink, block.imageAlt, block.imageWidth, block.imageHeight)
7575

7676
return (
7777
<div className={blockClasses} key={block.title}>

src/pages/index.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ const HomeSplash = props => {
3030

3131
const Logo = props => (
3232
<div className="projectLogo">
33-
<img src={props.img_src} alt="Project Logo" />
33+
<img
34+
src={props.imgSrc}
35+
alt="Project Logo"
36+
height={props.imgHeight}
37+
width={props.imgWidth}
38+
/>
3439
</div>
3540
)
3641

@@ -55,7 +60,11 @@ const HomeSplash = props => {
5560

5661
return (
5762
<SplashContainer>
58-
<Logo img_src={`${baseUrl}img/logo-large.png`} />
63+
<Logo
64+
imgSrc={`${baseUrl}img/logo-large.png`}
65+
imgWidth={128}
66+
imgHeight={128}
67+
/>
5968
<div className="inner">
6069
<ProjectTitle siteConfig={siteConfig} />
6170
<div className="pluginWrapper buttonWrapper">
@@ -82,6 +91,8 @@ export default class Index extends React.Component {
8291
imageAlign={props.imageAlign || 'center'}
8392
contents={props.children}
8493
layout={props.layout}
94+
imageHeight={props.imageHeight}
95+
imageWidth={props.imageWidth}
8596
/>
8697
</Container>
8798
)
@@ -109,6 +120,7 @@ export default class Index extends React.Component {
109120
"## The Problem \n - You want tests for your UI that avoid including implementation details and rather focus on making your tests give you the confidence for which they are intended. \n - You want your tests to be maintainable so refactors _(changes to implementation but not functionality)_ don't break your tests and slow you and your team down.",
110121
image: `${baseUrl}img/interrobang-128x128.png`,
111122
imageAlt: 'The problem (picture of a question mark)',
123+
imageHeight: 128,
112124
imageAlign: 'left',
113125
},
114126
]}
@@ -124,6 +136,7 @@ export default class Index extends React.Component {
124136
image: `${baseUrl}img/star-128x128.png`,
125137
imageAlign: 'right',
126138
imageAlt: 'The solution (picture of a star)',
139+
imageHeight: 128,
127140
content:
128141
'## The Solution \n The Testing Library family of libraries is a very light-weight solution for testing without all the implementation details. The main utilities it provides involve querying for nodes similarly to how users would find them. In this way, testing-library helps ensure your tests give you confidence in your UI code.',
129142
},
@@ -136,6 +149,7 @@ export default class Index extends React.Component {
136149
image: `${baseUrl}img/trophy-128x128.png`,
137150
imageAlign: 'left',
138151
imageAlt: 'The guiding principle (picture of a brick wall)',
152+
imageHeight: 128,
139153
content:
140154
'_The more your tests resemble the way your software is used, the more confidence they can give you._',
141155
},
@@ -153,13 +167,17 @@ export default class Index extends React.Component {
153167
imageAlign: 'top',
154168
title: 'Write Maintainable Tests',
155169
imageAlt: '',
170+
imageWidth: 80,
171+
imageHeight: 80,
156172
},
157173
{
158174
content: 'Interact with your app the same way as your users',
159175
image: `${baseUrl}img/check-128x128.png`,
160176
imageAlign: 'top',
161177
title: 'Develop with Confidence',
162178
imageAlt: '',
179+
imageWidth: 80,
180+
imageHeight: 80,
163181
},
164182
{
165183
content:
@@ -168,6 +186,8 @@ export default class Index extends React.Component {
168186
imageAlign: 'top',
169187
title: 'Accessible by Default',
170188
imageAlt: '',
189+
imageWidth: 80,
190+
imageHeight: 80,
171191
},
172192
]}
173193
</Block>
@@ -181,72 +201,84 @@ export default class Index extends React.Component {
181201
imageAlign: 'top',
182202
title: '[React](./docs/react-testing-library/intro)',
183203
imageAlt: 'React logo',
204+
imageHeight: 80,
184205
},
185206
{
186207
image: `${baseUrl}img/vue-400x400.png`,
187208
imageAlign: 'top',
188209
title: '[Vue](./docs/vue-testing-library/intro)',
189210
imageAlt: 'Vue logo',
211+
imageHeight: 80,
190212
},
191213
{
192214
image: `${baseUrl}img/angular-128x128.png`,
193215
imageAlign: 'top',
194216
title: '[Angular](./docs/angular-testing-library/intro)',
195217
imageAlt: 'Angular logo',
218+
imageHeight: 80,
196219
},
197220
{
198221
image: `${baseUrl}img/svelte-logo.png`,
199222
imageAlign: 'top',
200223
title: '[Svelte](./docs/svelte-testing-library/intro)',
201224
imageAlt: 'Svelte logo',
225+
imageHeight: 80,
202226
},
203227
{
204228
image: `${baseUrl}img/preact-128x128.png`,
205229
imageAlign: 'top',
206230
title: '[Preact](./docs/preact-testing-library/intro)',
207231
imageAlt: 'Preact logo',
232+
imageHeight: 80,
208233
},
209234
{
210235
image: `${baseUrl}img/reason-200x200.png`,
211236
imageAlign: 'top',
212237
title: '[ReasonReact](./docs/bs-react-testing-library/intro)',
213238
imageAlt: 'ReasonReact logo',
239+
imageHeight: 80,
214240
},
215241
{
216242
image: `${baseUrl}img/react-native-128x128.png`,
217243
imageAlign: 'top',
218244
title: '[React Native](./docs/react-native-testing-library/intro)',
219245
imageAlt: 'React Native logo',
246+
imageHeight: 80,
220247
},
221248
{
222249
image: `${baseUrl}img/cypress-128x128.png`,
223250
imageAlign: 'top',
224251
title: '[Cypress](./docs/cypress-testing-library/intro)',
225252
imageAlt: 'Cypress logo',
253+
imageHeight: 80,
226254
},
227255
{
228256
image: `${baseUrl}img/puppeteer-275x275.png`,
229257
imageAlign: 'top',
230258
title: '[Puppeteer](./docs/pptr-testing-library/intro)',
231259
imageAlt: 'Puppeteer logo',
260+
imageHeight: 80,
232261
},
233262
{
234263
image: `${baseUrl}img/testcafe-128x128.jpg`,
235264
imageAlign: 'top',
236265
title: `[Testcafe](./docs/testcafe-testing-library/intro)`,
237266
imageAlt: 'Testcafe logo',
267+
imageHeight: 80,
238268
},
239269
{
240270
image: `${baseUrl}img/nightwatch-128x128.png`,
241271
imageAlign: 'top',
242272
title: '[Nightwatch](./docs/nightwatch-testing-library/intro)',
243273
imageAlt: 'Nightwatch logo',
274+
imageHeight: 80,
244275
},
245276
{
246277
image: `${baseUrl}img/construction-128x128.png`,
247278
imageAlign: 'top',
248279
title: '[And more...](./docs/user-event/intro)',
249280
imageAlt: '',
281+
imageHeight: 80,
250282
},
251283
]}
252284
</Block>
@@ -289,13 +321,15 @@ export default class Index extends React.Component {
289321
imageLink: 'https://osawards.com/react/2019',
290322
imageAlt:
291323
'Winner of the Open Source Awards 2019 in the category "The most impactful contribution to the community"',
324+
imageHeight: 273,
292325
},
293326
{
294327
image: `${baseUrl}img/highest-satisfaction-638x574.png`,
295328
imageAlign: 'top',
296329
imageLink: 'https://2020.stateofjs.com/en-US/awards/',
297330
imageAlt:
298331
'Winner of the State of JS 2020 award for the technology with the highest percentage of satisfied users',
332+
imageHeight: 180,
299333
},
300334
]}
301335
</Block>

0 commit comments

Comments
 (0)