Base abstract trigger component for React that manages popup behavior and positioning with hover, click, focus actions and precise alignment.
npx @tessl/cli install tessl/npm-rc-trigger@5.3.0RC-Trigger is a foundational trigger component for React applications that manages popup behavior and positioning. It provides comprehensive trigger functionality including hover, click, focus, and context menu actions with precise popup alignment using dom-align integration, customizable animations and transitions through rc-motion, and built-in accessibility features.
npm install rc-triggerimport Trigger from "rc-trigger";
import type { BuildInPlacements } from "rc-trigger";For CommonJS:
const Trigger = require("rc-trigger");import React from "react";
import Trigger from "rc-trigger";
function BasicExample() {
return (
<Trigger
action={['click']}
popup={<div>This is the popup content</div>}
popupAlign={{
points: ['tl', 'bl'],
offset: [0, 4]
}}
>
<button>Click to toggle popup</button>
</Trigger>
);
}RC-Trigger is built around several key components:
The main Trigger component that manages popup behavior, positioning, and lifecycle.
interface TriggerProps {
children: React.ReactElement;
popup: React.ReactNode | (() => React.ReactNode);
action?: ActionType | ActionType[];
showAction?: ActionType[];
hideAction?: ActionType[];
popupVisible?: boolean;
defaultPopupVisible?: boolean;
onPopupVisibleChange?: (visible: boolean) => void;
afterPopupVisibleChange?: (visible: boolean) => void;
onPopupClick?: React.MouseEventHandler<HTMLDivElement>;
className?: string;
popupClassName?: string;
popupStyle?: React.CSSProperties;
prefixCls?: string;
popupAlign?: AlignType;
popupPlacement?: string;
builtinPlacements?: BuildInPlacements;
mouseEnterDelay?: number;
mouseLeaveDelay?: number;
focusDelay?: number;
blurDelay?: number;
zIndex?: number;
forceRender?: boolean;
destroyPopupOnHide?: boolean;
mask?: boolean;
maskClosable?: boolean;
popupMotion?: CSSMotionProps;
maskMotion?: CSSMotionProps;
// ... and additional props for advanced usage
}
export default class Trigger extends React.Component<TriggerProps>;
/**
* Internal function to generate Trigger class with custom portal component
* @private Internal usage - do not use in production code
*/
function generateTrigger(PortalComponent: any): React.ComponentClass<TriggerProps>;Advanced popup positioning system with precise alignment configuration and overflow handling.
interface AlignType {
points?: AlignPoint[];
offset?: number[];
targetOffset?: number[];
overflow?: {
adjustX?: boolean | number;
adjustY?: boolean | number;
};
useCssRight?: boolean;
useCssBottom?: boolean;
useCssTransform?: boolean;
}
type BuildInPlacements = Record<string, AlignType>;Motion configuration using rc-motion for smooth popup transitions and mask animations.
interface TriggerProps {
popupMotion?: CSSMotionProps;
maskMotion?: CSSMotionProps;
popupTransitionName?: TransitionNameType; // @deprecated
popupAnimation?: AnimationType; // @deprecated
}Comprehensive event system supporting multiple trigger actions with customizable delays and behaviors.
type ActionType = 'click' | 'hover' | 'focus' | 'contextMenu';
interface TriggerProps {
action?: ActionType | ActionType[];
showAction?: ActionType[];
hideAction?: ActionType[];
mouseEnterDelay?: number;
mouseLeaveDelay?: number;
focusDelay?: number;
blurDelay?: number;
}type AlignPoint = string; // Two-character alignment points like 'tl', 'tr', 'cc'
type ActionType = string; // Actions like 'click', 'hover', 'focus', 'contextMenu', etc.
type TransitionNameType = string;
type AnimationType = string;
type StretchType = string; // Popup stretch configuration
interface Point {
pageX: number;
pageY: number;
}
interface CommonEventHandler {
remove: () => void;
}
interface CSSMotionProps {
/** CSS class name or object for motion styling */
motionName?: string | {
appear?: string;
enter?: string;
leave?: string;
appearActive?: string;
enterActive?: string;
leaveActive?: string;
};
/** Whether to trigger motion on initial mount */
motionAppear?: boolean;
/** Whether to trigger motion on enter */
motionEnter?: boolean;
/** Whether to trigger motion on leave */
motionLeave?: boolean;
/** Remove element from DOM when leave motion completes */
removeOnLeave?: boolean;
/** Force render element even when motion is complete */
forceRender?: boolean;
/** Deadline for motion to complete (ms) */
motionDeadline?: number;
/** Lifecycle callbacks */
onAppearStart?: (element: HTMLElement) => void;
onEnterStart?: (element: HTMLElement) => void;
onLeaveStart?: (element: HTMLElement) => void;
onAppearActive?: (element: HTMLElement) => void;
onEnterActive?: (element: HTMLElement) => void;
onLeaveActive?: (element: HTMLElement) => void;
onAppearEnd?: (element: HTMLElement) => void;
onEnterEnd?: (element: HTMLElement) => void;
onLeaveEnd?: (element: HTMLElement) => void;
}
interface MobileConfig {
popupMotion?: CSSMotionProps;
popupClassName?: string;
popupStyle?: React.CSSProperties;
popupRender?: (originNode: React.ReactNode) => React.ReactNode;
}