StyleClass manages css classes declaratively to during enter/leave animations or just to toggle classes on an element.
import { StyleClassModule } from 'primeng/styleclass';
StyleClass has two modes, toggleClass to simply add-remove a class and enter/leave animations. The target element to change the styling is defined with the selector property that accepts any valid CSS selector or keywords including @next, prev, parent, grandparent
<button pButton label="Toggle p-disabled" pStyleClass="@next" toggleClass="p-disabled"></button>
<input type="text" pInputText class="block mt-3" />
Classes to apply during enter and leave animations are specified using the enterClass, enterActiveClass, enterToClass, leaveClass, leaveActiveClass,leaveToClassproperties. In addition in case the target is an overlay, hideOnOutsideClick would be handy to hide the target if outside of the popup is clicked, or enable hideOnEscape to close the popup by listening escape key.
<div>
<button pButton label="Show" class="mr-2" pStyleClass=".box" enterClass="hidden" enterActiveClass="fadein"></button>
<button pButton label="Hide" pStyleClass=".box" leaveActiveClass="fadeout" leaveToClass="hidden"></button>
</div>
<div class="hidden animation-duration-500 box">
<div class="flex bg-green-500 text-white align-items-center justify-content-center py-3 border-round-md mt-3 font-bold shadow-2 w-8rem h-8rem">Content</div>
</div>
API defines helper props, events and others for the PrimeNG StyleClass module.
Name | Type | Default | Description |
---|---|---|---|
pStyleClass | string | selector | Selector to define the target element. |
enterClass | string | null | Class to add when item begins to get displayed. |
enterActiveClass | string | null | Class to add during enter animation. |
enterToClass | string | null | Class to add when enter animation is completed. |
leaveClass | string | null | Class to add when item begins to get hidden. |
leaveActiveClass | string | null | Class to add during leave animation |
leaveToClass | string | null | Class to add when leave animation is completed. |
hideOnOutsideClick | boolean | null | Whether to trigger leave animation when outside of the element is clicked. |
hideOnEscape | boolean | null | Whether to trigger leave animation when escape key pressed. |
toggleClass | string | null | Adds or removes a class when no enter-leave animation is required. |