@skbkontur/ui-kit
Version:
65 lines (64 loc) • 2.05 kB
TypeScript
/// <reference types="react" />
import * as React from 'react';
export interface PopupProps {
anchorElement: HTMLElement;
backgroundColor?: string;
children: React.ReactNode | (() => React.ReactNode);
hasPin?: boolean;
hasShadow?: boolean;
margin?: number;
opened: boolean;
pinOffset?: number;
pinSize?: number;
popupOffset?: number;
positions: string[];
onCloseRequest?: () => void;
onMouseEnter?: (event: React.MouseEvent<HTMLElement>) => void;
onMouseLeave?: (event: React.MouseEvent<HTMLElement>) => void;
}
export interface DefaultPopupProps {
margin: number;
popupOffset: number;
pinSize: number;
pinOffset: number;
hasPin: boolean;
hasShadow: boolean;
backgroundColor: string;
}
export declare type PropsWithDefaults = PopupProps & DefaultPopupProps;
export interface Location {
coordinates: {
left: number;
top: number;
};
position: string;
}
export interface PopupState {
location: Location | null;
}
export default class Popup extends React.Component<PopupProps, PopupState> {
static defaultProps: DefaultPopupProps;
state: PopupState;
private layoutEventsToken;
private lastPopupElement;
componentDidMount(): void;
componentDidUpdate(): void;
componentWillUnmount(): void;
render(): JSX.Element;
private renderContent(location);
private refPopupElement;
private renderPin(position);
private handleClickOutside;
private handleFocusOutside;
private handleLayoutEvent;
private delayUpdateLocation();
private updateLocation();
private requestClose;
private locationEquals(x, y);
private getDummyLocation();
private getLocation(popupElement);
private getPinnedPopupOffset(anchorRect, positionObject);
private getCoordinates(anchorRect, popupRect, positionObject, margin, popupOffset);
private getHorizontalPosition(anchorRect, popupRect, align, popupOffset);
private getVerticalPosition(anchorRect, popupRect, align, popupOffset);
}