2019-07-29 13:40:18 +00:00
---
layout: page
2019-08-20 10:33:52 +00:00
title: Card Widget Plugin
2019-07-29 13:40:18 +00:00
---
2019-08-20 10:33:52 +00:00
The card widget plugin provides the functionality for collapsing, expanding and removing a card.
2019-07-29 13:40:18 +00:00
2020-06-02 13:57:24 +00:00
### Usage
2019-07-29 13:40:18 +00:00
2020-06-02 13:57:24 +00:00
This plugin can be activated as a jQuery plugin or using the data API.
2019-07-29 13:40:18 +00:00
2020-06-02 13:57:24 +00:00
#### Data API
This plugin provides two `data-api` attributes. Any element using one of the following attributes should be placed within the `.card-tools` div, which is usually in the card header. For more information about the [card HTML structure ]({% link components/cards.md %} ), visit the card component documentation
##### `data-card-widget="collapse"`
2019-07-29 13:40:18 +00:00
This attribute, when attached to a button, allows the box to be collapsed/expanded when clicked.
2020-06-02 13:57:24 +00:00
2019-07-29 13:40:18 +00:00
< div class = "row" >
< div class = "col-12 col-md-4" >
< div class = "card" >
< div class = "card-header" >
< h3 class = "card-title" > Collapsible Card Example< / h3 >
< div class = "card-tools" >
2019-08-20 10:33:52 +00:00
< button type = "button" class = "btn btn-tool" data-card-widget = "collapse" > < i class = "fas fa-minus" > < / i > < / button >
2019-07-29 13:40:18 +00:00
< / div >
< / div >
< div class = "card-body" >
The body of the card
< / div >
< / div >
< / div >
< div class = "col-12 col-md-8" markdown = "1" >
```html
< div class = "card" >
< div class = "card-header" >
< h3 class = "card-title" > Collapsible Card Example< / h3 >
< div class = "card-tools" >
<!-- Collapse Button -->
2019-08-20 10:33:52 +00:00
< button type = "button" class = "btn btn-tool" data-card-widget = "collapse" > < i class = "fas fa-minus" > < / i > < / button >
2019-07-29 13:40:18 +00:00
< / div >
<!-- /.card - tools -->
< / div >
<!-- /.card - header -->
< div class = "card-body" >
The body of the card
< / div >
<!-- /.card - body -->
< / div >
<!-- /.card -->
```
{: .max-height-300}
< / div >
< / div >
2020-06-02 13:57:24 +00:00
##### `data-card-widget="remove"`
2019-07-29 13:40:18 +00:00
This attribute, when attached to a button, allows the box to be removed when clicked.
2020-06-02 13:57:24 +00:00
2019-07-29 13:40:18 +00:00
< div class = "row" >
< div class = "col-12 col-md-4" >
< div class = "card" >
< div class = "card-header" >
< h3 class = "card-title" > Removable Card Example< / h3 >
< div class = "card-tools" >
2019-08-20 10:33:52 +00:00
< button type = "button" class = "btn btn-tool" data-card-widget = "remove" > < i class = "fas fa-times" > < / i > < / button >
2019-07-29 13:40:18 +00:00
< / div >
< / div >
< div class = "card-body" >
The body of the card
< / div >
< / div >
< / div >
< div class = "col-12 col-md-8" markdown = "1" >
```html
< div class = "card" >
< div class = "card-header" >
< h3 class = "card-title" > Removable Card Example< / h3 >
< div class = "card-tools" >
<!-- Remove Button -->
2019-08-20 10:33:52 +00:00
< button type = "button" class = "btn btn-tool" data-card-widget = "remove" > < i class = "fas fa-times" > < / i > < / button >
2019-07-29 13:40:18 +00:00
< / div >
<!-- /.card - tools -->
< / div >
<!-- /.card - header -->
< div class = "card-body" >
The body of the card
< / div >
<!-- /.card - body -->
< / div >
<!-- /.card -->
```
{: .max-height-300}
< / div >
< / div >
2020-06-02 13:57:24 +00:00
##### `data-card-widget="maximize"`
2019-07-29 13:40:18 +00:00
This attribute, when attached to a button, allows the box to be maximize/minimize when clicked.
2020-06-02 13:57:24 +00:00
2019-07-29 13:40:18 +00:00
< div class = "row" >
< div class = "col-12 col-md-4" >
< div class = "card" >
< div class = "card-header" >
< h3 class = "card-title" > Maximizable Card Example< / h3 >
< div class = "card-tools" >
2019-08-20 10:33:52 +00:00
< button type = "button" class = "btn btn-tool" data-card-widget = "maximize" > < i class = "fas fa-expand" > < / i > < / button >
2019-07-29 13:40:18 +00:00
< / div >
< / div >
< div class = "card-body" >
The body of the card
< / div >
< / div >
< / div >
< div class = "col-12 col-md-8" markdown = "1" >
```html
< div class = "card" >
< div class = "card-header" >
< h3 class = "card-title" > Maximizable Card Example< / h3 >
< div class = "card-tools" >
<!-- Maximize Button -->
2019-08-20 10:33:52 +00:00
< button type = "button" class = "btn btn-tool" data-card-widget = "maximize" > < i class = "fas fa-expand" > < / i > < / button >
2019-07-29 13:40:18 +00:00
< / div >
<!-- /.card - tools -->
< / div >
<!-- /.card - header -->
< div class = "card-body" >
The body of the card
< / div >
<!-- /.card - body -->
< / div >
<!-- /.card -->
```
{: .max-height-300}
< / div >
< / div >
###### jQuery
{: .text-bold }
2019-08-20 10:33:52 +00:00
To activate any button using jQuery, you must provide the removeTrigger and collapseTrigger options. Otherwise, the plugin will assume the default `data-card-widget` selectors.
2019-07-29 13:40:18 +00:00
```js
2019-08-29 07:57:49 +00:00
$('#my-card').CardWidget(options)
2019-07-29 13:40:18 +00:00
```
##### Options
{: .mt-4}
|---
| Name | Type | Default | Description
|-|-|-|-
|animationSpeed | Number | 300 | Speed of slide down/up animation in milliseconds.
2020-03-08 23:13:10 +00:00
|collapseTrigger | String | `[data-card-widget="collapse"]` | jQuery selector to the element responsible for collapsing the box.
|removeTrigger | String | `[data-card-widget="remove"]` | jQuery selector to the element responsible for removing the box.
2019-08-20 10:33:52 +00:00
|maximizeTrigger | String | `[data-card-widget="maximize"]` | jQuery selector to the element responsible for maximizing the box.
2019-07-29 13:40:18 +00:00
{: .table .table-bordered .bg-light}
> ##### Tip!
> You can use any option via the data-attributes like this.
> ```html
2019-08-20 10:33:52 +00:00
> <button type="button" class="btn btn-tool" data-card-widget="collapse" data-animation-speed="1000"><i class="fas fa-minus"></i></button>
2019-07-29 13:40:18 +00:00
> ```
{: .quote-info}
##### Events
{: .mt-4}
|---
| Event Type | Description
|-|-
2019-08-20 10:33:52 +00:00
|expanded.lte.cardwidget | Triggered after a card expanded.
|collapsed.lte.cardwidget | Triggered after a card collapsed.
|maximized.lte.cardwidget | Triggered after a card maximized.
|minimized.lte.cardwidget | Triggered after a card minimized.
|removed.lte.cardwidget | Triggered after a card removed.
2019-07-29 13:40:18 +00:00
{: .table .table-bordered .bg-light}
2019-08-20 10:33:52 +00:00
Example: `$('#my-card').on('expanded.lte.cardwidget', handleExpandedEvent)`
2019-07-29 13:40:18 +00:00
##### Methods
{: .mt-4}
|---
| Method | Description
|-|-
|collapse | Collapses the card
|expand | Expands the card
|remove | Removes the card
|toggle | Toggles the state of the card between expanded and collapsed
2019-08-20 10:33:52 +00:00
|maximize | Maximizes the card
|minimize | Minimizes the card
2019-07-29 13:40:18 +00:00
|toggleMaximize | Toggles the state of the card between maximized and minimized
{: .table .table-bordered .bg-light}
2019-08-29 07:57:49 +00:00
Example: `$('#my-card-widget').CardWidget('toggle')` or `$('#my-card').CardWidget('toggle')`