@terminus/ui-expansion-panel
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Expansion Panel

CI/CD Status Codecov MIT License
NPM version Library size

Expansion panel & accordion components.

Table of Contents

Installation

Use the ng add command to quickly install all the needed dependencies:

ng add @terminus/ui-expansion-panel

CSS imports

In your top-level stylesheet, add these imports:

@import '~@terminus/design-tokens/css/library-design-tokens.css';
@import '~@terminus/ui-styles/terminus-ui.css';

CSS resources

Load the needed font families by adding this link to the <head> of your application:

<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">

Usage

Panel

The most basic usage is a single panel with a trigger:

<ts-expansion-panel>
  <ts-expansion-panel-trigger>
    Here is my trigger!
  </ts-expansion-panel-trigger>

  <p>And here is my standard panel content.</p>
</ts-expansion-panel>

NOTE: Without a trigger, the panel will not be visible.

Title and description

Trigger text can be split into title and description using the TsExpansionPanelTitleComponent and TsExpansionPanelDescriptionComponent respectively.

<!-- Standard trigger -->
<ts-expansion-panel-trigger>
  Here is my trigger!
</ts-expansion-panel-trigger>


<!-- Trigger with title and description -->
<ts-expansion-panel-trigger>
  <ts-expansion-panel-trigger-title>
    My title
  </ts-expansion-panel-trigger-title>

  <ts-expansion-panel-trigger-description>
    My description
  </ts-expansion-panel-trigger-description>
</ts-expansion-panel-trigger>

Disable a panel

The isDisabled flag will disable a panel and it's trigger:

<ts-expansion-panel [isDisabled]="true">
  <ts-expansion-panel-trigger>
    Here is my trigger!
  </ts-expansion-panel-trigger>

  <p>I will never be seen.</p>
</ts-expansion-panel>

Default a panel open

The isExpanded flag will change the state of a panel. This can be used to default to a specific state or to dynamically change the state.

<ts-expansion-panel [isExpanded]="true">
  <ts-expansion-panel-trigger>
    Here is my trigger!
  </ts-expansion-panel-trigger>

  <p>I'll be visible by default!</p>
</ts-expansion-panel>

Lazy loaded content

Panel content can be lazily loaded by using a template with the tsExpansionPanelContent directive. The template will not be loaded until the panel is opened for the first time. The content will remain in the DOM until the panel is destroyed.

<ts-expansion-panel>
  <ts-expansion-panel-trigger>
    Here is my trigger!
  </ts-expansion-panel-trigger>

  <ng-template tsExpansionPanelContent>
    Here is my deferred template!
  </ng-template>
</ts-expansion-panel>

Transparent mode

Expansion panel with transparent mode on has no box shadow and padding on the side. It's default to false.

<ts-expansion-panel [transparentMode]="true">
  <ts-expansion-panel-trigger>
    Here is my trigger!
  </ts-expansion-panel-trigger>

  <p>And here is my standard panel content.</p>
</ts-expansion-panel>

Panel events

Event Description Payload
opened Fired when the panel is opened void
afterExpand Fired after the panel expansion animation finishes void
closed Fired when the panel is closed void
afterCollapse Fired after the panel collapse animation finishes void
expandedChange Fired when the panel state changes boolean
destroyed Fired when the panel is destroyed void
<ts-expansion-panel (opened)="myFunction()">...</ts-expansion-panel>

Custom trigger heights

Custom heights can be set for a trigger's collapsed and/or expanded state.

<ts-expansion-panel>
  <!-- When collapsed the trigger will be 100px tall
       When expanded the trigger will be 200px tall -->
  <ts-expansion-panel-trigger
    collapsedHeight="100px"
    expandedHeight="200px"
  >Panel Trigger (100px -> 200px)</ts-expansion-panel-trigger>

  <p>And here is my standard panel content.</p>
</ts-expansion-panel>

Manual control

Panels can be programmatically opened, closed or toggled through a reference to the instance:

@ViewChild(TsExpansionPanelComponent, {static: false})
public panel: TsExpansionPanelComponent;

...

panel.open();
panel.close();
panel.toggle();

NOTE: Disabled panels cannot be controlled with these methods. Disabled panels can only be controlled via the isExpanded input.

Accordion

An accordion is created by wrapping two or more TsExpansionPanelComponents inside a TsAccordionComponent.

<ts-accordion>
  <ts-expansion-panel>...</ts-expansion-panel>
  <ts-expansion-panel>...</ts-expansion-panel>
</ts-accordion>

Allow multiple panels to be open

By default an accordion can only have a single panel open at a time. This functionality can be change with the multi input.

<ts-accordion [multi]="true">
  <ts-expansion-panel>...</ts-expansion-panel>
  <ts-expansion-panel>...</ts-expansion-panel>
</ts-accordion>

Accordion events

Event Description Payload
destroyed Fired when the accordion is destroyed void
<ts-accordion (destroyed)="myFunction()">...</ts-accordion>

Accordion as a stepper

An accordion can function as a stepper which can be useful for guided flows. To facilitate this we can use a combination of hideToggle and the ts-expansion-panel-action-row.

<!-- Hide the toggle icon since this is a programmatically controlled flow -->
<ts-accordion [hideToggle]="true">
  <!-- STEP 1 -->
  <ts-expansion-panel [isExpanded]="activeStep === 0">
    <ts-expansion-panel-trigger>Step 1</ts-expansion-panel-trigger>

    And here is my standard panel content.

    <ts-expansion-panel-action-row>
      <ts-button (clicked)="nextStep()">Next</ts-button>
    </ts-expansion-panel-action-row>
  </ts-expansion-panel>

  <!-- STEP 2 -->
  <ts-expansion-panel [isExpanded]="activeStep === 1">
    <ts-expansion-panel-trigger>Step 2</ts-expansion-panel-trigger>

    And here is my standard panel content.

    <ts-expansion-panel-action-row>
      <ts-button format="hollow" (clicked)="previousStep()">Previous</ts-button>
      <ts-button (clicked)="nextStep()">Next</ts-button>
    </ts-expansion-panel-action-row>
  </ts-expansion-panel>

  <!-- STEP 3 -->
  <ts-expansion-panel [isExpanded]="activeStep === 2">
    <ts-expansion-panel-trigger>Step 3</ts-expansion-panel-trigger>

    And here is my standard panel content.

    <ts-expansion-panel-action-row>
      <ts-button format="hollow" (clicked)="previousStep()">Previous</ts-button>
      <ts-button (clicked)="nextStep()">End</ts-button>
    </ts-expansion-panel-action-row>
  </ts-expansion-panel>
</ts-accordion>

Hide toggle

When an accordion is controlled programmatically, the toggle icon can be hidden to avoid confusion for the user. Setting hideToggle on the accordion will hide the toggle icon for all panels within.

NOTE: This should only be used in cases when the accordion is functioning as a stepper.

<ts-accordion [hideToggle]="true">
  <ts-expansion-panel>...</ts-expansion-panel>
  <ts-expansion-panel>...</ts-expansion-panel>
</ts-accordion>

Action row

The action row is useful when an accordion is functioning as a stepper. Controls added within the action row will be right aligned as panel controls.

NOTE: See Accordion as a stepper for a complete example.

<ts-expansion-panel>
  <ts-expansion-panel-trigger>
    Step 1
  </ts-expansion-panel-trigger>

  And here is my standard panel content.

  <ts-expansion-panel-action-row>
    <button (click)="nextStep()">Next</button>
  </ts-expansion-panel-action-row>
</ts-expansion-panel>

Open or close all panels

An accordion can programmatically open or close all panels at once.

@ViewChild(TsAccordionComponent, {static: false})
public accordion: TsAccordionComponent;

...

accordion.openAll();
accordion.closeAll();

NOTE: These methods will not change the state of disabled panels.

Test Helpers

Some helpers are exposed to assist with testing. These are imported from @terminus/ui-expansion-panel/testing;

[source]

Function
getAllPanelDebugElements
getAllPanelInstances
getPanelDebugElement
getPanelInstance
getPanelElement
getPanelBodyElement
getPanelBodyContentElement
getAllAccordionDebugElements
getAllAccordionInstances
getAccordionInstance
getAccordionDebugElement
getAccordionElement
getTriggerDebugElement
getTriggerInstance
getTriggerElement
getTriggerTitleElement
getTriggerDescriptionElement
getPanelActionRow
togglePanel

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.10next
2.0.00latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.10
2.0.00
1.1.50
1.1.40
1.1.30
1.1.20
1.1.10
1.1.00
1.0.250
1.0.240
1.0.230
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.160
1.0.150
1.0.140
1.0.130
1.0.120
1.0.110
1.0.100
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.11
1.0.00
0.0.10

Package Sidebar

Install

npm i @terminus/ui-expansion-panel

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

547 kB

Total Files

83

Last publish

Collaborators

  • bmalinconico-terminus
  • atlwendy
  • terminus_devops