Simple React component for simple SVG placeholder images based on the awesome Cloudfour Simple SVG Placeholder
npm install --save react-simple-svg-placeholder
yarn add react-simple-svg-placeholder
import React from "react";
import PlaceholderImage from "react-simple-svg-placeholder";
const Example = () => <PlaceholderImage width={300} height={150} />;
import React from "react";
import PlaceholderImage from "react-simple-svg-placeholder";
const Example = () => {
const placeholderSettings = {
width: 300,
height: 150,
bgColor: "#aaa",
textColor: "#333",
};
return <PlaceholderImage {...placeholderSettings} />;
};
Defaults to 300
, the default width of SVG elements in most browsers.
Defaults to 150
, the default height of SVG elements in most browsers.
Defaults to false
, toggles if the component only returns the source-string or an actual <img>
Please also watch the "getImgSrc Function"-section below
The text to display. Defaults to the image dimensions.
The font to use for the text. For data URIs, this needs to be a system-installed font. Defaults to 'sans-serif'
.
Defaults to 'bold'
.
Defaults to 20% of the shortest image dimension, rounded down.
The background color of the image. Defaults to #ddd
.
The color of the text. For transparency, use an rgba
or hsla
color value. Defaults to rgba(0,0,0,0.5)
.
Defaults to UTF-8
, but if your source HTML document's character set is different, you may want to update this to match.
If you only want to generate an image-src you don't need to use a react-component.
You can use the getImgSrc-function of this project.
The defaults and props-usage is the same as in the react-component.
import { getImgSrc } from "react-simple-svg-placeholder";
const imgSrcWithDefaults = getImgSrc();
const imgSrcWithWidth = getImgSrc({ width: 800 });
MIT © r3sMetz