UNPKG

2.5 kBTypeScriptView Raw
1import * as React from 'react';
2import AnchorLink from './AnchorLink';
3import { ConfigConsumerProps } from '../config-provider';
4export declare type AnchorContainer = HTMLElement | Window;
5export interface AnchorProps {
6 prefixCls?: string;
7 className?: string;
8 style?: React.CSSProperties;
9 children?: React.ReactNode;
10 offsetTop?: number;
11 bounds?: number;
12 affix?: boolean;
13 showInkInFixed?: boolean;
14 getContainer?: () => AnchorContainer;
15 /** Return customize highlight anchor */
16 getCurrentAnchor?: () => string;
17 onClick?: (e: React.MouseEvent<HTMLElement>, link: {
18 title: React.ReactNode;
19 href: string;
20 }) => void;
21 /** Scroll to target offset value, if none, it's offsetTop prop value or 0. */
22 targetOffset?: number;
23 /** Listening event when scrolling change active link */
24 onChange?: (currentActiveLink: string) => void;
25}
26export interface AnchorState {
27 activeLink: null | string;
28}
29export interface AnchorDefaultProps extends AnchorProps {
30 prefixCls: string;
31 affix: boolean;
32 showInkInFixed: boolean;
33 getContainer: () => AnchorContainer;
34}
35export interface AntAnchor {
36 registerLink: (link: string) => void;
37 unregisterLink: (link: string) => void;
38 activeLink: string | null;
39 scrollTo: (link: string) => void;
40 onClick?: (e: React.MouseEvent<HTMLElement>, link: {
41 title: React.ReactNode;
42 href: string;
43 }) => void;
44}
45export default class Anchor extends React.Component<AnchorProps, AnchorState, ConfigConsumerProps> {
46 static Link: typeof AnchorLink;
47 static defaultProps: {
48 affix: boolean;
49 showInkInFixed: boolean;
50 };
51 static contextType: React.Context<ConfigConsumerProps>;
52 state: {
53 activeLink: null;
54 };
55 content: ConfigConsumerProps;
56 private wrapperRef;
57 private inkNode;
58 private scrollContainer;
59 private links;
60 private scrollEvent;
61 private animating;
62 private prefixCls?;
63 registerLink: (link: string) => void;
64 unregisterLink: (link: string) => void;
65 getContainer: () => any;
66 componentDidMount(): void;
67 componentDidUpdate(): void;
68 componentWillUnmount(): void;
69 getCurrentAnchor(offsetTop?: number, bounds?: number): string;
70 handleScrollTo: (link: string) => void;
71 saveInkNode: (node: HTMLSpanElement) => void;
72 setCurrentActiveLink: (link: string) => void;
73 handleScroll: () => void;
74 updateInk: () => void;
75 render: () => JSX.Element;
76}