Use loading placeholders for your components or pages to indicate something may still be loading., check out documentation.
In the example below, we take a typical card component and recreate it with placeholders applied to create a “loading card”. Size and proportions are the same between the two.
Some quick example text to build on the card title and make up the bulk of the card's content.
import React from 'react';
import { Button, Card, Col, Placeholder, Row } from 'react-bootstrap';
//Image
import placeholderImg from '../../../Assets/dist/img/placeholder_card.jpg';
const CardExample = () => {
return (
<Row>
<Col sm={4}>
<Card>
<Card.Img variant="top" src={placeholderImg} alt="Card img cap" />
<Card.Body>
<Card.Title>Card title</Card.Title>
<Card.Text>Some quick example text to build on the card title and make up the bulk of the card's content.</Card.Text>
<Button variant="primary">Go somewhere</Button>
</Card.Body>
</Card>
</Col>
<Col sm={4}>
<Card>
<Card.Img variant="top" src={placeholderImg} />
<Card.Body>
<Placeholder as={Card.Title} animation="glow">
<Placeholder xs={6} />
</Placeholder>
<Placeholder as={Card.Text} animation="glow">
<Placeholder xs={7} /> <Placeholder xs={4} /> <Placeholder xs={4} />{' '}
<Placeholder xs={6} /> <Placeholder xs={8} />
</Placeholder>
<Placeholder.Button variant="primary" xs={6} />
</Card.Body>
</Card>
</Col>
</Row>
);
};
export default CardExample;
By default, the Placeholder
uses currentColor
. This can be overridden with a custom color or utility class.
import React from 'react';
import { Placeholder } from 'react-bootstrap';
const ColorsWithPlaceholder = () => {
return (
<Placeholder animation="glow" >
<Placeholder xs={12} />
<Placeholder xs={12} bg="primary" />
<Placeholder xs={12} bg="secondary" />
<Placeholder xs={12} bg="success" />
<Placeholder xs={12} bg="danger" />
<Placeholder xs={12} bg="warning" />
<Placeholder xs={12} bg="info" />
<Placeholder xs={12} bg="light" />
<Placeholder xs={12} bg="dark" />
</Placeholder>
);
};
export default ColorsWithPlaceholder;
The size of Placeholders
are based on the typographic style of the parent element. Customize them with sizing props: lg, sm,
or xs
.
import React from 'react';
import { Placeholder } from 'react-bootstrap';
const PlaceholderSizes = () => {
return (
<Placeholder animation="glow">
<Placeholder xs={12} size="lg" />
<Placeholder xs={12} />
<Placeholder xs={12} size="sm" />
<Placeholder xs={12} size="xs" />
</Placeholder>
);
};
export default PlaceholderSizes;
Animate placeholders
by setting the prop animation to glow
or wave
to better convey the perception of something being actively loaded.
import React from 'react';
import { Placeholder } from 'react-bootstrap';
const PlaceholderAnimations = () => {
return (
<>
<Placeholder as="p" animation="glow">
<Placeholder xs={12} />
</Placeholder>
<Placeholder as="p" animation="wave">
<Placeholder xs={12} />
</Placeholder>
</>
);
};
export default PlaceholderAnimations;