-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace design screenshots with mShots in New Onboarding (#43428)
Co-authored-by: Andrew Serong <[email protected]> Co-authored-by: Julian de Bhal <[email protected]> Co-authored-by: Louis Laugesen <[email protected]>
- Loading branch information
1 parent
af234ca
commit fcadad2
Showing
4 changed files
with
131 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
client/landing/gutenboarding/components/mshots-image/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React, { useState } from 'react'; | ||
import classnames from 'classnames'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
|
||
/** | ||
* Style dependencies | ||
*/ | ||
import './style.scss'; | ||
|
||
interface MShotsImageProps { | ||
url: string; | ||
alt: string; | ||
'aria-labelledby': string; | ||
} | ||
|
||
const mShotsParams = { | ||
// viewport size (how much of the source page to capture) | ||
vpw: 1200, | ||
vph: 3072, | ||
// size of the resulting image | ||
w: 700, | ||
h: 1800, | ||
}; | ||
|
||
export function mshotsUrl( url: string, count = 0 ): string { | ||
const mshotsUrl = 'https://s0.wp.com/mshots/v1/'; | ||
const mshotsRequest = addQueryArgs( mshotsUrl + encodeURIComponent( url ), { | ||
...mShotsParams, | ||
// this doesn't seem to work: | ||
// requeue: true, // Uncomment this line to force the screenshots to be regenerated | ||
count, | ||
} ); | ||
return mshotsRequest; | ||
} | ||
|
||
const MShotsImage = ( { | ||
url, | ||
'aria-labelledby': labelledby, | ||
alt, | ||
}: MShotsImageProps ): JSX.Element => { | ||
const [ count, setCount ] = React.useState( 0 ); | ||
const [ visible, setVisible ] = useState( false ); | ||
return ( | ||
<div className="mshots-image__container"> | ||
{ ! visible && <div className="mshots-image__loader"></div> } | ||
<img | ||
className={ classnames( 'mshots-image' ) } | ||
style={ { opacity: visible ? 1 : 0 } } | ||
alt={ alt } | ||
aria-labelledby={ labelledby } | ||
src={ mshotsUrl( url, count ) } | ||
onLoad={ ( e ) => { | ||
// Test against mshots h value | ||
if ( e.currentTarget.naturalHeight !== mShotsParams.h ) { | ||
// Only refresh 10 times. | ||
if ( count < 10 ) { | ||
// Triggers a target.src change | ||
setTimeout( () => setCount( count + 1 ), 1000 ); | ||
} | ||
} else { | ||
setVisible( true ); | ||
} | ||
} } | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MShotsImage; |
19 changes: 19 additions & 0 deletions
19
client/landing/gutenboarding/components/mshots-image/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@import '../../mixins.scss'; | ||
|
||
.mshots-image { | ||
opacity: 0; | ||
transition: 0.3s opacity; | ||
} | ||
|
||
.mshots-image__loader { | ||
@include onboarding-placeholder(); | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.mshots-image-visible { | ||
opacity: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters