Ripples are visual representations used to communicate the status of a component or interactive element.
We use @material/ripple for Ripple effects, which can be used from a CDN or installed using a package manager.
<!-- MDC Ripple JS -->
<script src="https://unpkg.com/@material/ripple@14.0.0/dist/mdc.ripple.min.js"
integrity="sha384-9QANVmWxL3S8VRs8x1Q+bF1Zzogpy7P/Qw1+y5qHLdC1ig0EuoHg9VbB1SXyecdZ"
crossorigin="anonymous"></script>
npm i @material/ripple@14.0.0
To add Ripple to your component:
<span class="ripple-surface"></span>
) to your component.relative
, absolute
, fixed
, or sticky
(In other words, anything except static
), since a Ripple surface is absolute
positioned.<button type="button" class="btn btn-success m-1">
Success | Green
<span class="ripple-surface"></span>
</button>
<button type="button" class="btn btn-warning m-1">
Warning | Yellow
<span class="ripple-surface"></span>
</button>
<button type="button" class="btn btn-outline-purple m-1">
Outlined Button
<span class="ripple-surface"></span>
</button>
<button type="button" class="btn btn-outline-pink border-0 m-1">
Text Button
<span class="ripple-surface"></span>
</button>
<ul class="nav nav-tabs nav-justified primary-indigo base-pink" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link" data-bs-toggle="tab" role="tab" data-bs-target="#apple">
Apple
<span class="ripple-surface"></span>
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link active" data-bs-toggle="tab" role="tab" data-bs-target="#apricot">
Apricot
<span class="ripple-surface"></span>
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" data-bs-toggle="tab" role="tab" data-bs-target="#avocado">
Avocado
<span class="ripple-surface"></span>
</button>
</li>
</ul>
<!-- Tab Panes -->
<div class="tab-content">
<div class="tab-pane container-fluid fade" role="tabpanel" id="apple">Apple</div>
<div class="tab-pane container-fluid active" role="tabpanel" id="apricot">Apricot</div>
<div class="tab-pane container-fluid fade" role="tabpanel" id="avocado">Avocado</div>
</div>
<div class="bg-teal p-4 position-relative">
Ripple on a div
<span class="ripple-surface"></span>
</div>
Use the custom property --mdc-ripple-color
to set the color of the Ripple.
<div class="bg-white border p-4 position-relative" style="--mdc-ripple-color: blue;">
Ripple with custom color
<span class="ripple-surface"></span>
</div>
Use the custom properties:
--mdc-ripple-hover-opacity
to set hover color opacity.--mdc-ripple-focus-opacity
to set focus color opacity.--mdc-ripple-press-opacity
to set active color opacity.<div class="bg-white border p-4 position-relative"
style="--mdc-ripple-color: blue; --mdc-ripple-hover-opacity: .3; --mdc-ripple-focus-opacity: .4; --mdc-ripple-press-opacity: .5;">
Ripple with custom color
<span class="ripple-surface"></span>
</div>
If CDN is used to add @material/ripple to the project
// Initialize Ripple
const rippleSurface = Array.prototype.slice.call(document.querySelectorAll('.ripple-surface'))
rippleSurface.map(s => {
return new mdc.ripple.MDCRipple(s)
})
Else
// Import MDCRipple
import { MDCRipple } from '@material/ripple';
// Initialize Ripple
const rippleSurface = Array.prototype.slice.call(document.querySelectorAll('.ripple-surface'))
rippleSurface.map(s => {
return new MDCRipple(s)
})