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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-widget-trigger

v2.1.0

Published

trigger

Downloads

106

Readme

trigger

Trigger触发组件

安装

npm install --save react-widget-trigger

使用

Edit react-wiget-trigger

import React from "react";
import Trigger from "react-widget-trigger";
import "react-widget-trigger/style";
import "./styles.css";

export default function App() {
  return (
    <div
      className="App"
      style={{
        padding: 100
      }}
    >
      <Trigger
        offset={1}
        placement="bottomRight"
        popup={trigger => (
          <div
            style={{
              width: 100,
              height: 100,
              border: "1px solid #f2f2f2",
              padding: 10
            }}
          >
            <div>Title</div>
            <div>
              Content
              <Trigger
                usePortal={false}
                action="hover"
                delay={50}
                offset={1}
                popup={
                  <div
                    style={{
                      width: 150
                    }}
                  >
                    hover popup test...
                  </div>
                }
              >
                <a href="###">Hover</a>
              </Trigger>
            </div>

            <button onClick={() => trigger.hide()}>关闭</button>
          </div>
        )}
        action={["click"]}
      >
        <button>点击试试</button>
      </Trigger>
    </div>
  );
}

Interfaces

import React from "react";
import Popup, { PopupProps } from "react-widget-popup";
import { PositionOptions } from "jq-position";

type Placements =
	| "left"
	| "top"
	| "right"
	| "bottom"
	| "topLeft"
	| "topRight"
	| "leftTop"
	| "leftBottom"
	| "rightTop"
	| "rightBottom"
	| "bottomRight"
	| "bottomLeft"

declare type ActionType = "click" | "contextMenu" | "focus" | "hover" | "mouseDown";
declare type ShowActionType = "click" | "contextMenu" | "focus" | "mouseEnter" | "mouseDown";
declare type HideActionType = "click" | "mouseLeave" | "blur" | "resize" | "scroll" | "mouseDown";
declare type Delay = {
    show?: number;
    hide?: number;
};
export declare const version = "%VERSION%";
export interface TriggerProps {
    /** 样式前缀 */
    prefixCls?: string;
    /** 弹出框显示位置 */
    placement?: Placements;
    /** 弹出框位置偏移量 */
    offset?: [number, number] | number;
    /** 触发事件 */
    action?: ActionType | ActionType[] | null;
    /** 显示触发事件,同action合并 */
    showAction?: ShowActionType | ShowActionType[] | null;
    /** 隐藏触发事件,同action合并 */
    hideAction?: HideActionType | HideActionType[] | null;
    /** 点击popup或trigger元素以外的节点时隐藏popup事件 */
    outsideHideEventName?: Array<keyof HTMLElementEventMap> | keyof HTMLElementEventMap;
    /** 显示/隐藏延迟时间 */
    delay?: number | Delay;
    /** 禁用触发器 */
	disabled?: boolean;
    /** 触发后弹出显示内容 */
    popup?: React.ReactNode | ((trigger: Trigger) => React.ReactNode);
    /** 弹出框CSS样式 */
    popupClassName?: string;
    /** 弹出框遮罩层CSS样式 */
    popupMaskClassName?: string;
    /** 弹出框根节点元素CSS样式 */
    popupRootClassName?: string;
    /** 弹出框CSSTransition参数,参考:react-transition-group */
    popupTransition?: PopupProps["transition"];
    /** 弹出框遮罩层CSSTransition参数,参考:react-transition-group */
    popupMaskTransition?: PopupProps["maskTransition"];
    /** 初始时弹出框是否可见 */
    defaultPopupVisible?: boolean;
    /** 控制弹出框是否可见(受控) */
    popupVisible?: boolean;
    /** 弹出框组件(Popup)属性,参考:react-widget-popup */
    popupProps?: Omit<PopupProps, "className" | "maskClassName" | "rootClassName" | "prefixCls" | "transition" | "maskTransition" | "maskProps" | "style" | "mask" | "disableMask" | "destroyOnClose" | "maskStyle" | "rootStyle" | "zIndex">;
    /** 弹出框样式 */
    popupStyle?: React.CSSProperties;
    /** 弹出框遮罩层样式 */
    popupMaskStyle?: React.CSSProperties;
    popupRootStyle?: React.CSSProperties;
    /** 弹出框的遮罩层元素的属性,参考:PopupProps["maskProps"] */
    popupMaskProps?: PopupProps["maskProps"];
    /** 是否显示遮罩层 */
    mask?: boolean;
    /** 是否禁用遮罩层 */
    disableMask?: boolean;
    /** 点击遮罩层隐藏弹出框 */
    maskClosable?: boolean;
    /** 隐藏销毁弹出框 */
    destroyPopupOnHide?: boolean;
    /** 设置弹出框的zIndex */
    zIndex?: number;
    /** popup位置最终适配方法 */
	adjustPosition?: (
		dom: HTMLElement,
		pos: {
			left: number;
			top: number;
		},
		feedback: Feedback
	) => void;
    /** 是否使用Portal进行渲染弹出框 */
    usePortal?: boolean;
    /** 当destroyPopupOnHide=false时,组件刷新时强制更新弹出框组件 */
    forceRender?: boolean;
    /** jquery-ui/position.js 的配置参数 */
    position?: PositionOptions;
    /** portal挂载容器 */
    container?: PortalProps["container"];
    /** 内部使用 */
    getDocument?: () => Document | Element;
    /** 内部使用 */
    checkDefaultPrevented?: boolean;
    onPopupVisibleChange?: (visible: boolean) => void;
    onBeforeShow?: (popupNode: HTMLElement) => void;
    onAfterShow?: (popupNode: HTMLElement) => void;
    onBeforeHide?: (popupNode: HTMLElement) => void;
    onAfterHide?: (popupNode: HTMLElement) => void;
}
export interface TriggerState {
    popupVisible: boolean;
}
export declare class Trigger extends React.Component<TriggerProps, TriggerState> {
    popupInstance: Popup;
    triggerInstance: React.ReactInstance;
    show(): void;
    hide(): void;
    updatePopupPosition(): void;
}
export default Trigger;

defaultProps

{
	prefixCls: "rw-trigger",
	placement: "bottomLeft",
	offset: 0,
	defaultPopupVisible: false,
	action: ["click"],
	showAction: [],
    hideAction: [],
    outsideHideEventName: ["mousedown", "click", "scroll"],
	delay: 0,
	getDocument: () => window.document,
	container: document.body,
	mask: false,
	maskClosable: true,
	destroyPopupOnHide: true,
	popupProps: {},
	popupStyle: {},
	popupMaskStyle: {},
	checkDefaultPrevented: false,
	usePortal: true,
}

基础样式

.rw-trigger-root {
	position: absolute;
	left: 0;
	right: 0;
	top: 0;
}

.rw-trigger {
	position: absolute;
	left: 0;
	top: 0;
	z-index: 2000;
}

.rw-trigger-mask {
	position: fixed;
	left: 0;
	top: 0;
	right: 0;
	bottom: 0;
	background: #000;
	opacity: 0.1;
	z-index: 2000;
}