-
-
Save akoepcke/41db5c72ad53a1103463e75e1aca6cd7 to your computer and use it in GitHub Desktop.
Placeholder React Components
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
function PlaceholderImage({ | |
height, | |
width, | |
...consumerProps | |
}) { | |
return ( | |
<img | |
{...consumerProps} | |
alt="" | |
src={`https://via.placeholder.com/${width}x${height}`} | |
/> | |
); | |
} |
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
const lipsum = | |
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Molestias quo voluptas fugit quidem nemo autem eos reprehenderit voluptatum nam. Error odio repellendus quisquam magni rerum hic facere laboriosam, aspernatur fugiat.'; | |
function PlaceholderText({ | |
characters, | |
...consumerProps | |
}) { | |
const string = | |
characters <= lipsum.length | |
? lipsum.slice(0, characters) | |
: lipsum | |
.repeat(Math.ceil(characters / lipsum.length)) | |
.slice(0, characters); | |
return ( | |
<span | |
{...consumerProps} | |
style={{ | |
backgroundImage: | |
'repeating-linear-gradient(to bottom, #fff 0px, #fff 2px, #bbb 2px, #bbb 10px, #fff 10px, #fff 18px)', | |
display: 'inline-block', | |
fontSize: 12, | |
lineHeight: 1, | |
}} | |
> | |
<span style={{ visibility: 'hidden' }}>{string}</span> | |
</span> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment