1.0.11 • Published 4 years ago

@co-hooks/popper v1.0.11

Weekly downloads
57
License
-
Repository
-
Last release
4 years ago

Popper 一 气泡浮层

API

属性说明类型默认值
show是否显示,可选booleanfalse
trigger触发方式IRcTriggerhover
placement定位方式,必填IRcPlacement-
offset浮层相对偏移量IOffset-
preventOverflow是否碰撞反向booleantrue
overflowBoundaries碰撞边界IOverFlowBoundaries-
arrow是否有箭头booleanfalse
arrowOffset箭头偏移量IOffset-
getArrowarrow内容渲染方法(arrowInfo: IArrowInfo, touch: ITouch) => React.ReactNode-
getPopperpopper内容渲染方法() => React.ReactNode-
hideToDestory是否隐藏是销毁booleanfalse
lazyInit是否第一次trigger时渲染booleanfalse
zIndex浮层的zIndex,选填number-
classNamepopper classNamestring-
refClassNamereference classNamestring-
childrenreference内容Function/ReactNode-
onShowshow事件,选填Function-
onHidehide事件,选填Function-
onFocusfocus事件,trigger = focus时触发,选填Function-
onBlurblur事件,trigger = focus时触发,选填Function-
hideDelay隐藏等待时间,选填,毫秒number-

类型 定义

import {CSSProperties} from 'react';

export type IRcTrigger = 'click' | 'hover' | 'focus' | 'manual';

export type IRcPlacementLeft = 'left-start' | 'left' | 'left-end';
export type IRcPlacementRight = 'right-start' | 'right' | 'right-end';
export type IRcPlacementTop = 'top-start' | 'top' | 'top-end';
export type IRcPlacementBottom = 'bottom-start' | 'bottom' | 'bottom-end';

export type IRcPlacement = IRcPlacementLeft | IRcPlacementRight | IRcPlacementTop | IRcPlacementBottom;

export interface ITouch {
    touchX?: boolean;
    touchY?: boolean;
}

export interface IOverFlowBoundaries {
    left?: number;
    right?: number;
    top?: number;
    bottom?: number;
}

export interface IArrowInfo {
    arrowStyle: CSSProperties;
    arrowDirection: string;
}

用法

import React, {CSSProperties, useCallback, useState} from 'react';
import {RcPopper, IArrowInfo} from '@rc-hooks/popper';
import './demo.less';

export default (props: {}) => {
    const [showls, setShowLS] = useState(false);

    const getArrow = useCallback((arrowInfo: IArrowInfo) => {
        const {arrowDirection} = arrowInfo;
        const arrowStyle: CSSProperties = {
            borderWidth: '5px',
            width: 0,
            height: 0,
            fontSize: 0,
            lineHeight: 0,
            borderStyle: 'solid',
            display: 'block'
        };
        switch (arrowDirection) {
            case 'top':
                Object.assign(arrowStyle, {
                    borderColor: 'transparent transparent #ccc transparent'
                });
                break;
            case 'bottom':
                Object.assign(arrowStyle, {
                    borderColor: '#ccc transparent transparent transparent'
                });
                break;
            case 'left':
                Object.assign(arrowStyle, {
                    borderColor: 'transparent #ccc transparent transparent'
                });
                break;
            case 'right':
                Object.assign(arrowStyle, {
                    borderColor: 'transparent transparent transparent #ccc'
                });
                break;
        }

        return (
            <span style={arrowStyle} />
        );
    }, []);

    return (
        <div className="dialog-demo">
            <div style={{marginBottom: '50px'}}>以下popper都是lazyInit的, hover会在隐藏时销毁,click的不会销毁</div>
            <div className="part">
                <RcPopper
                    show={showls}
                    trigger="click"
                    placement="left-start"
                    getPopper="提示文字"
                    lazyInit={true}
                    arrow={true}
                    getArrow={getArrow}
                    arrowOffset={{x: 0, y: 5}}
                    offset={{x: -10, y: 0}}
                    onShow={() => setShowLS(true)}
                    onHide={() => setShowLS(false)}
                >
                    <Button>click 左上</Button>
                </RcPopper>
            </div>
        </div>
    );
};
1.0.11

4 years ago

1.0.8

4 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

0.8.23

4 years ago

0.8.22

4 years ago

0.8.16

4 years ago

0.8.5-alpha.1

4 years ago

0.7.23

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.8.2

4 years ago

0.7.17

4 years ago

0.7.11

4 years ago

0.7.10

4 years ago

0.7.9

4 years ago

0.7.7

4 years ago

0.7.6

4 years ago

0.7.4

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.8

4 years ago

0.6.5

4 years ago

0.6.5-alpha.0

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.10

4 years ago

0.5.9

4 years ago

0.5.5

4 years ago

0.5.4

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.4.5

4 years ago

0.5.0

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.10

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.3.0-alpha.5

4 years ago

0.3.0-alpha.2

5 years ago

0.3.0-alpha.1

5 years ago

0.3.0-alpha.0

5 years ago