PanelPanel is a grouping component with the optional content toggle feature.

Panel - 图1

Documentation

Import

  1. import {PanelModule} from 'primeng/panel';
  2.  

Getting Started

Panel is defined with p-panel element.

  1. <p-panel header="Title">
  2. Content
  3. </p-panel>
  4.  

Toggleable

Content of the panel can be expanded and collapsed using toggleable option, default state is defined with collapsed option. By default, toggle icon is used to toggle the contents whereas setting toggler to "header" enables clicking anywhere in the header to trigger a toggle.

  1. <p-panel header="Title" [toggleable]="true">
  2. Content
  3. </p-panel>
  4.  

Header and Footers sections can be customized using p-header and p-footer components.

  1. <p-panel >
  2. <p-header>
  3. Header content here
  4. </p-header>
  5. Body Content
  6. <p-footer>
  7. Footer content here
  8. </p-footer>
  9. </p-panel>
  10.  

Animation Configuration

Transition of the toggle animation can be customized using the transitionOptions property with a default value as 400ms cubic-bezier(0.86, 0, 0.07, 1), example below disables the animation altogether.

  1. <p-panel [transitionOptions]="'0ms'">
  2. </p-panel>
  3.  

Properties

NameTypeDefaultDescription
headerstringnullHeader text of the panel.
toggleablebooleanfalseDefines if content of panel can be expanded and collapsed.
collapsedbooleanfalseDefines the initial state of panel content, supports one or two-way binding as well.
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
expandIconstringpi pi-plusExpand icon of the toggle button.
collapseIconstringpi pi-minusCollapsed icon of the toggle button.
showHeaderbooleantrueSpecifies if header of panel cannot be displayed.
transitionOptionsstring400ms cubic-bezier(0.86, 0, 0.07, 1)Transition options of the animation.
togglerstringiconSpecifies the toggler element to toggle the panel content, valid values are "icon" and "header".

Events

NameParametersDescription
onBeforeToggleevent.originalEvent: browser event event.collapsed: state as a booleanCallback to invoke before content toggle.
onAfterToggleevent.originalEvent: browser event event.collapsed: state as a booleanCallback to invoke after content toggle.

Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
ui-panelContainer element.
ui-panel-titlebarHeader section.
ui-panel-titleTitle text of panel.
ui-panel-titlebar-togglerToggle icon.
ui-panel-contentContent of panel.

Dependencies

None.

Source

View on GitHub

  1. <p-toast [style]="{marginTop: '80px'}"></p-toast>
  2. <p-panel header="Godfather I" [toggleable]="true" [style]="{'margin-bottom':'20px'}">
  3. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.
  4. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
  5. Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family,
  6. kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
  7. </p-panel>
  8. <p-panel>
  9. <p-header>
  10. <div class="ui-helper-clearfix">
  11. <span class="ui-panel-title" style="font-size:16px;display:inline-block;margin-top:2px">Custom Header</span>
  12. <p-splitButton [style]="{'float':'right'}" label="Save" icon="pi pi-check" (onClick)="save()" [model]="items"></p-splitButton>
  13. </div>
  14. </p-header>
  15. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.
  16. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
  17. Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family,
  18. kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
  19. <p-footer>
  20. <button pButton type="button" icon="pi pi-plus" label="New" class="ui-button-info" style="margin-right: .25em"></button>
  21. <button pButton type="button" icon="pi pi-search" label="View" class="ui-button-success"></button>
  22. </p-footer>
  23. </p-panel>
  24.