Card Widget Plugin
The CardWidget plugin provides collapse, expand, remove, and maximize functionality for card components.
Usage
This plugin is activated via data attributes on buttons inside a
.card element.
Data API
Add data-lte-toggle="card-collapse" to toggle card body
visibility, data-lte-toggle="card-remove" to remove the
card, or data-lte-toggle="card-maximize" to maximize
it.
<div class="card">
<div class="card-header">
<h3 class="card-title">Card Title</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-lte-toggle="card-collapse" title="Collapse">
<i data-lte-icon="expand" class="bi bi-plus-lg"></i>
<i data-lte-icon="collapse" class="bi bi-dash-lg"></i>
</button>
<button type="button" class="btn btn-tool" data-lte-toggle="card-maximize" title="Maximize">
<i class="bi bi-fullscreen"></i>
</button>
<button type="button" class="btn btn-tool" data-lte-toggle="card-remove" title="Remove">
<i class="bi bi-x-lg"></i>
</button>
</div>
</div>
<div class="card-body">Card content here.</div>
<div class="card-footer">Card footer</div>
</div>
Events
The plugin dispatches these events on the card (the
.card element, not the button that was clicked). They bubble, so
you can listen on the card or on any ancestor, such as document.
The three “before” events are cancelable: call
event.preventDefault() to stop the action.
| Event | Cancelable | Description |
|---|---|---|
collapse.lte.card-widget |
Yes | Fired before the card body collapses. |
collapsed.lte.card-widget |
No | Fired when the card body is collapsed. |
expand.lte.card-widget |
Yes | Fired before the card body expands. |
expanded.lte.card-widget |
No | Fired when the card body is expanded. |
remove.lte.card-widget |
Yes | Fired before the card is removed, so a listener can ask for confirmation. |
removed.lte.card-widget |
No | Fired when the remove animation ends, just before the card is detached from the DOM. |
maximized.lte.card-widget |
No | Fired when the card is maximized. |
minimized.lte.card-widget |
No | Fired when the card is minimized (restored from maximized). |
// Ask before removing any card on the page
document.addEventListener("remove.lte.card-widget", (event) => {
if (!confirm("Remove this card?")) {
event.preventDefault()
}
})
// Clean up after a card is gone, e.g. destroy a chart it contained
document.addEventListener("removed.lte.card-widget", (event) => {
event.target.querySelectorAll("canvas").forEach((canvas) => Chart.getChart(canvas)?.destroy())
})
CSS Classes
| Class | Description |
|---|---|
collapsed-card |
Applied to the card when collapsed. |
maximized-card |
Applied to the card when maximized. |
Configuration
The plugin reads no data-* configuration attributes. To customize
behaviour, instantiate it programmatically and pass a config:
| Option | Default | Description |
|---|---|---|
animationSpeed |
500 |
Slide animation duration in milliseconds. |
collapseTrigger |
[data-lte-toggle="card-collapse"] |
CSS selector for collapse buttons. |
removeTrigger |
[data-lte-toggle="card-remove"] |
CSS selector for remove buttons. |
maximizeTrigger |
[data-lte-toggle="card-maximize"] |
CSS selector for maximize buttons. |
Programmatic API
import { CardWidget } from "admin-lte"
const card = document.querySelector("#chart-card")
const widget = new CardWidget(card, { animationSpeed: 250 })
widget.maximize() // expand to fullscreen
widget.collapse() // hide body and footer
widget.expand() // restore from collapsed
widget.remove() // animate out and remove from DOM
widget.toggle() // expand / collapse based on current state
widget.toggleMaximize() // maximize / minimize based on current state
Methods
| Method | Returns | Description |
|---|---|---|
collapse() |
void |
Slides up body and footer, adds collapsed-card. Fires
collapsed.lte.card-widget.
|
expand() |
void |
Slides down body and footer, removes collapsed-card.
Fires expanded.lte.card-widget.
|
toggle() |
void |
Calls collapse() or expand() based on the
collapsed-card class.
|
maximize() |
void |
Sets the card to fixed fullscreen positioning, adds
maximized-card. Fires
maximized.lte.card-widget.
|
minimize() |
void |
Restores original size, removes maximized-card. Fires
minimized.lte.card-widget.
|
toggleMaximize() |
void |
Calls maximize() or minimize() based on the
maximized-card class.
|
remove() |
void |
Animates the card out and removes it from the DOM. Fires
remove.lte.card-widget.
|
Notes
- Nested cards are handled correctly: collapsing a parent card does not affect child cards.
-
Maximizing a card also adds
maximized-cardto<html>so global styles can react. -
A card that’s collapsed when you maximize it remembers that — the
was-collapsedclass tracks this state.