|
1 | 1 | # trigger
|
2 |
| -trigger |
| 2 | + |
| 3 | +Trigger触发组件 |
| 4 | + |
| 5 | +## 安装 |
| 6 | + |
| 7 | +`npm install --save react-widget-trigger` |
| 8 | + |
| 9 | + |
| 10 | +## 使用 |
| 11 | + |
| 12 | +[](https://codesandbox.io/s/react-wiget-trigger-llvwn?fontsize=14&hidenavigation=1&theme=dark) |
| 13 | + |
| 14 | + |
| 15 | +### Interfaces |
| 16 | + |
| 17 | +```ts |
| 18 | +import React from "react"; |
| 19 | +import Popup, { PopupProps } from "react-widget-popup"; |
| 20 | +import { PositionOptions } from "jq-position"; |
| 21 | +import { Placements } from "./getPlacement"; |
| 22 | +declare type ActionType = "click" | "contextMenu" | "focus" | "hover" | "mouseDown"; |
| 23 | +declare type ShowActionType = "click" | "contextMenu" | "focus" | "mouseEnter" | "mouseDown"; |
| 24 | +declare type HideActionType = "click" | "mouseLeave" | "blur" | "resize" | "scroll" | "mouseDown"; |
| 25 | +declare type Delay = { |
| 26 | + show?: number; |
| 27 | + hide?: number; |
| 28 | +}; |
| 29 | +export declare const version = "%VERSION%"; |
| 30 | +export interface TriggerProps { |
| 31 | + /** 样式前缀 */ |
| 32 | + prefixCls?: string; |
| 33 | + /** 弹出框显示位置 */ |
| 34 | + placement?: Placements; |
| 35 | + /** 弹出框位置偏移量 */ |
| 36 | + offset?: [number, number] | number; |
| 37 | + /** 触发事件 */ |
| 38 | + action?: ActionType | ActionType[] | null; |
| 39 | + /** 显示触发事件,同action合并 */ |
| 40 | + showAction?: ShowActionType | ShowActionType[] | null; |
| 41 | + /** 隐藏触发事件,同action合并 */ |
| 42 | + hideAction?: HideActionType | HideActionType[] | null; |
| 43 | + /** 显示/隐藏延迟时间 */ |
| 44 | + delay?: number | Delay; |
| 45 | + /** 触发后弹出显示内容 */ |
| 46 | + popup?: React.ReactNode | ((trigger: Trigger) => React.ReactNode); |
| 47 | + /** 弹出框CSS样式 */ |
| 48 | + popupClassName?: string; |
| 49 | + /** 弹出框遮罩层CSS样式 */ |
| 50 | + popupMaskClassName?: string; |
| 51 | + /** 弹出框根节点元素CSS样式 */ |
| 52 | + popupRootClassName?: string; |
| 53 | + /** 弹出框CSSTransition参数,参考:react-transition-group */ |
| 54 | + popupTransition?: PopupProps["transition"]; |
| 55 | + /** 弹出框遮罩层CSSTransition参数,参考:react-transition-group */ |
| 56 | + popupMaskTransition?: PopupProps["maskTransition"]; |
| 57 | + /** 初始时弹出框是否可见 */ |
| 58 | + defaultPopupVisible?: boolean; |
| 59 | + /** 控制弹出框是否可见(受控) */ |
| 60 | + popupVisible?: boolean; |
| 61 | + /** 弹出框组件(Popup)属性,参考:react-widget-popup */ |
| 62 | + popupProps?: Omit<PopupProps, "className" | "maskClassName" | "rootClassName" | "prefixCls" | "transition" | "maskTransition" | "maskProps" | "style" | "mask" | "disableMask" | "destroyOnClose" | "maskStyle" | "rootStyle" | "zIndex">; |
| 63 | + /** 弹出框样式 */ |
| 64 | + popupStyle?: React.CSSProperties; |
| 65 | + /** 弹出框遮罩层样式 */ |
| 66 | + popupMaskStyle?: React.CSSProperties; |
| 67 | + popupRootStyle?: React.CSSProperties; |
| 68 | + /** 弹出框的遮罩层元素的属性,参考:PopupProps["maskProps"] */ |
| 69 | + popupMaskProps?: PopupProps["maskProps"]; |
| 70 | + /** 是否显示遮罩层 */ |
| 71 | + mask?: boolean; |
| 72 | + /** 是否禁用遮罩层 */ |
| 73 | + disableMask?: boolean; |
| 74 | + /** 点击遮罩层隐藏弹出框 */ |
| 75 | + maskClosable?: boolean; |
| 76 | + /** 隐藏销毁弹出框 */ |
| 77 | + destroyPopupOnHide?: boolean; |
| 78 | + /** 设置弹出框的zIndex */ |
| 79 | + zIndex?: number; |
| 80 | + /** 是否使用Portal进行渲染弹出框 */ |
| 81 | + usePortal?: boolean; |
| 82 | + /** 当destroyPopupOnHide=false时,组件刷新时强制更新弹出框组件 */ |
| 83 | + forceRender?: boolean; |
| 84 | + /** jquery-ui/position.js 的配置参数 */ |
| 85 | + position?: PositionOptions; |
| 86 | + /** 内部使用 */ |
| 87 | + getDocument?: () => Document | Element; |
| 88 | + /** 内部使用 */ |
| 89 | + checkDefaultPrevented?: boolean; |
| 90 | + onPopupVisibleChange?: (visible: boolean) => void; |
| 91 | + onBeforeShow?: (popupNode: HTMLElement) => void; |
| 92 | + onAfterShow?: (popupNode: HTMLElement) => void; |
| 93 | + onBeforeHide?: (popupNode: HTMLElement) => void; |
| 94 | + onAfterHide?: (popupNode: HTMLElement) => void; |
| 95 | +} |
| 96 | +export interface TriggerState { |
| 97 | + popupVisible: boolean; |
| 98 | +} |
| 99 | +export declare class Trigger extends React.Component<TriggerProps, TriggerState> { |
| 100 | + popupInstance: Popup; |
| 101 | + triggerInstance: React.ReactInstance; |
| 102 | + componentDidMount(): void; |
| 103 | + componentDidUpdate(): void; |
| 104 | + componentWillUnmount(): void; |
| 105 | + show(): void; |
| 106 | + hide(): void; |
| 107 | +} |
| 108 | +export default Trigger; |
| 109 | +``` |
| 110 | + |
| 111 | +### defaultProps |
| 112 | +```js |
| 113 | +{ |
| 114 | + prefixCls: "rw-trigger", |
| 115 | + placement: "bottomLeft", |
| 116 | + offset: 0, |
| 117 | + defaultPopupVisible: false, |
| 118 | + action: ["click"], |
| 119 | + showAction: [], |
| 120 | + hideAction: [], |
| 121 | + delay: 0, |
| 122 | + getDocument: () => window.document, |
| 123 | + container: document.body, |
| 124 | + mask: false, |
| 125 | + maskClosable: true, |
| 126 | + destroyPopupOnHide: true, |
| 127 | + popupProps: {}, |
| 128 | + popupStyle: {}, |
| 129 | + popupMaskStyle: {}, |
| 130 | + checkDefaultPrevented: false, |
| 131 | + usePortal: true, |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +### 基础样式 |
| 136 | + |
| 137 | +```css |
| 138 | +.rw-trigger-root { |
| 139 | + position: absolute; |
| 140 | + left: 0; |
| 141 | + top: 0; |
| 142 | +} |
| 143 | + |
| 144 | +.rw-trigger { |
| 145 | + position: absolute; |
| 146 | + left: 0; |
| 147 | + top: 0; |
| 148 | + z-index: 2000; |
| 149 | +} |
| 150 | + |
| 151 | +.rw-trigger-mask { |
| 152 | + position: fixed; |
| 153 | + left: 0; |
| 154 | + top: 0; |
| 155 | + right: 0; |
| 156 | + bottom: 0; |
| 157 | + background: #000; |
| 158 | + opacity: 0.1; |
| 159 | + z-index: 2000; |
| 160 | +} |
| 161 | + |
| 162 | +``` |
0 commit comments