npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@terminus/ui-expansion-panel

v2.0.0

Published

<h1>Expansion Panel</h1>

Downloads

10

Readme

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 |