Bootstrap React Placeholder
Use loading Bootstrap React Placeholders for your components or pages to indicate something may still be loading.
About#
Placeholders can be used to enhance the experience of your application. They're built only with HTML and CSS, meaning you don't need any JavaScript to create them. You will, however, need some custom JavaScript to toggle their visibility. Their appearance, color, and sizing can be easily customized with our utility classes.
Example#
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.
Card title
Some quick example text to build on the card title and make up the bulk of the card's content.
Go somewhere1<CCard style={{ width: '18rem' }}>2 <CCardImage orientation="top" src={ReactImg} />3 <CCardBody>4 <CCardTitle>Card title</CCardTitle>5 <CCardText>6 Some quick example text to build on the card title and make up the bulk of the card's7 content.8 </CCardText>9 <CButton href="#">Go somewhere</CButton>10 </CCardBody>11</CCard>12<CCard style={{ width: '18rem' }}>13 <CCardImage component="svg" orientation="top" width="100%" height="162" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder" preserveAspectRatio="xMidYMid slice" focusable="false">14 <title>Placeholder</title><rect width="100%" height="100%" fill="#868e96"></rect>15 </CCardImage>16 <CCardBody>17 <CPlaceholder component={CCardTitle} animation="glow" xs={7}>18 <CPlaceholder xs={6} />19 </CPlaceholder>20 <CPlaceholder component={CCardText} animation="glow">21 <CPlaceholder xs={7} />22 <CPlaceholder xs={4} />23 <CPlaceholder xs={4} />24 <CPlaceholder xs={6} />25 <CPlaceholder xs={8} />26 </CPlaceholder>27 <CPlaceholder component={CButton} disabled href="#" tabIndex={-1} xs={6}></CPlaceholder>28 </CCardBody>29</CCard>
How it works#
Create placeholders with the <CPlaceholder>
component and a grid column propx (e.g., xs={6}
) to set the width
. They can replace the text inside an element or be added as a modifier class to an existing component.
We apply additional styling to CButton
s via ::before
to ensure the height
is respected. You may extend this pattern for other situations as needed, or add a
within the element to reflect the height when actual text is rendered in its place.
1<p aria-hidden="true">2 <CPlaceholder xs={6} />3</p>4<CPlaceholder component={CButton} aria-hidden="true" disabled href="#" tabIndex={-1} xs={4}></CPlaceholder>
aria-hidden="true"
only indicates that the element should be hidden to screen readers. The loading behavior of the placeholder depends on how authors will actually use the placeholder styles, how they plan to update things, etc. Some JavaScript code may be needed to *swap* the state of the placeholder and inform AT users of the update.Width#
You can change the width
through grid column classes, width utilities, or inline styles.
1<CPlaceholder xs={6} />2<CPlaceholder className="w-75" />3<CPlaceholder style={{ width: '30%'}} />
Color#
By default, the <CPlaceholder>
uses currentColor
. This can be overridden with a custom color or utility class.
1<CPlaceholder xs={12} />23<CPlaceholder color="primary" xs={12} />4<CPlaceholder color="secondary" xs={12} />5<CPlaceholder color="success" xs={12} />6<CPlaceholder color="danger" xs={12} />7<CPlaceholder color="warning" xs={12} />8<CPlaceholder color="info" xs={12} />9<CPlaceholder color="light" xs={12} />10<CPlaceholder color="dark" xs={12} />
Sizing#
The size of <CPlaceholder>
s are based on the typographic style of the parent element. Customize them with size
prop: lg
, sm
, or xs
.
1<CPlaceholder xs={12} size="lg"/>2<CPlaceholder xs={12}/>3<CPlaceholder xs={12} size="sm"/>4<CPlaceholder xs={12} size="xs"/>
Animation#
Animate placeholders with animation="glow"
or animation="wave"
to better convey the perception of something being actively loaded.
1<CPlaceholder component="p" animation="glow">2 <CPlaceholder xs={12} />3</CPlaceholder>45<CPlaceholder component="p" animation="wave">6 <CPlaceholder xs={12} />7</CPlaceholder>
API#
CPlaceholder#
1import { CPlaceholder } from '@coreui/bootstrap-react'2// or3import CPlaceholder from '@coreui/bootstrap-react/src/components/placeholder/CPlaceholder'
Property | Description | Type | Default |
---|---|---|---|
animation | Set animation type to better convey the perception of something being actively loaded. | 'glow' | 'wave' | - |
className | A string of all className you want applied to the component. | string | - |
color | Sets the color context of the component to one of Bootstrap React’s themed colors. | 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string | - |
component | Component used for the root node. Either a string to use a HTML element or a component. | string | ComponentClass<any, any> | FunctionComponent<any> | - |
lg | The number of columns on large devices (<1200px). | number | - |
md | The number of columns on medium devices (<992px). | number | - |
size | Size the component extra small, small, or large. | 'xs' | 'sm' | 'lg' | - |
sm | The number of columns on small devices (<768px). | number | - |
xl | The number of columns on X-Large devices (<1400px). | number | - |
xs | The number of columns on extra small devices (<576px). | number | - |
xxl | The number of columns on XX-Large devices (≥1400px). | number | - |