2.0.0 • Published 3 years ago

@terminus/ui-expansion-panel v2.0.0

Weekly downloads
78
License
MIT
Repository
github
Last release
3 years ago

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

EventDescriptionPayload
openedFired when the panel is openedvoid
afterExpandFired after the panel expansion animation finishesvoid
closedFired when the panel is closedvoid
afterCollapseFired after the panel collapse animation finishesvoid
expandedChangeFired when the panel state changesboolean
destroyedFired when the panel is destroyedvoid
<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

EventDescriptionPayload
destroyedFired when the accordion is destroyedvoid
<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
2.0.1

3 years ago

2.0.0

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.22

4 years ago

1.0.23

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago