@3mo/collapsible-card
v0.2.2
Published
A web component for cards whose body collapses and expands from a toggle in the header.
Readme
Collapsible Card
A web component for cards whose body collapses and expands from a toggle in the header.
A card whose body collapses down to its header with a toggle button.
Installation
npm install @3mo/collapsible-cardimport '@3mo/collapsible-card'Usage
<mo-collapsible-card heading='Order #24080' subHeading='Serenity Freight'>
Twelve steel plates and four tubes of weld seam sealant, shipped from Toronto on Monday. Delivery is expected within five working days.
</mo-collapsible-card>Examples
- Sub Heading When Collapsed — With
showSubHeadingOnlyWhenCollapsedthe sub-heading appears only while collapsed, as a summary of the hidden body - expand the card to see it go. - Disable Collapse —
disableCollapsedisables the toggle, keeping the card expanded or collapsed as it is. - Fixed Height — With a height of its own the body fills it, and collapsing gives the height up down to the header.
- Subclassing — A subclass can render more into the card, such as a line between the header and the body, which keeps its place while the body collapses.
- Custom Properties —
--mo-collapsible-card-transition-durationsets how long collapsing takes, one second here, and0sturns the animation off.
API
mo-collapsible-card
Properties
| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| collapsed | collapsed | boolean | false | Whether the body is collapsed |
| disableCollapse | disableCollapse | boolean | false | Disables the toggle, keeping the card in its current state |
| showSubHeadingOnlyWhenCollapsed | showSubHeadingOnlyWhenCollapsed | boolean | false | Shows the sub-heading only while the card is collapsed |
| type | type | CardType | "filled" | Whether the card is filled with a shadow or outlined with a border |
| heading | heading | string \| undefined | | The heading in the header |
| subHeading | subHeading | string \| undefined | | The secondary line below the heading |
| avatar | avatar | string \| undefined | | The text shown in the avatar circle of the header |
| image | image | string \| undefined | | The URL of an image shown above the header |
Events
| Name | Detail | Description |
| --- | --- | --- |
| collapse | boolean | Dispatched when the card is collapsed or expanded |
Slots
| Name | Description |
| --- | --- |
| action | Actions in the header |
| heading | Custom heading in the header |
| subHeading | Custom subHeading in the header |
| avatar | Custom avatar in the header |
| header | Replaces the whole header, including the heading, subHeading, avatar and action slots |
| media | Embedded media |
| (default) | Body / Content |
| footer | Actions in the footer |
CSS custom properties
| Name | Description |
| --- | --- |
| --mo-collapsible-card-transition-duration | The duration of the collapse and expand animation; "0s" turns it off |
| --mo-card-header-padding | Padding of the header |
| --mo-card-avatar-background | Color of the avatar |
| --mo-card-avatar-color | Text color of the avatar |
| --mo-card-body-padding | Padding of the body |
| --mo-card-footer-padding | Padding of the footer |
CSS parts
| Name | Description |
| --- | --- |
| media | Embedded media |
| header | The header |
| avatar | The avatar |
| heading | The heading |
| subHeading | The subHeading |
| footer | The footer |
Links
License
MIT © 3MO GmbH
