Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more typings for props #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,56 @@ export type Size = "small" | "regular" | "big";
export type Theme = "dark" | "light" | "transparent";

export interface TooltipProps {
title?: string;
disabled?: boolean;
open?: boolean;
useContext?: boolean;
onRequestClose?: () => void;
html?: React.ReactElement<any>;
position?: Position;
trigger?: Trigger;
tabIndex?: number;
interactive?: boolean;
interactiveBorder?: number;
delay?: number;
hideDelay?: number;
animation?: Animation;
animateFill?: boolean;
arrow?: boolean;
arrowSize?: Size;
animateFill?: boolean;
delay?: number;
hideDelay?: number;
trigger?: Trigger;
duration?: number;
hideDuration?: number;
distance?: number;
interactive?: boolean;
interactiveBorder?: number;
theme?: Theme;
offset?: number;
hideOnClick?: boolean | "persistent";
multiple?: boolean;
followCursor?: boolean;
inertia?: boolean;
transitionFlip?: boolean;
popperOptions?: any;
html?: React.ReactElement<any>;
unmountHTMLWhenHide?: boolean;
onShow: () => void,
onShown: () => void,
onHide: () => void,
onHidden: () => void,
disabled?: boolean;
size?: Size;
className?: string;
style?: React.CSSProperties;
distance?: number;
onRequestClose?: () => void;
sticky?: boolean;
stickyDuration?: boolean;
tag?: 'div' | 'span' | 'a';
touchHold?: boolean;
unmountHTMLWhenHide?: boolean;
zIndex?: number;
rawTemplate?: any;
title?: string;
open?: boolean;
useContext?: boolean;
tabIndex?: number;
transitionFlip?: boolean;
unmountHTMLWhenHide?: boolean;
beforeShown?: () => void;
shown?: () => void;
beforeHidden?: () => void;
hidden?: () => void;
theme?: Theme;
className?: string;
style?: React.CSSProperties;
}

export class Tooltip extends React.Component<TooltipProps> {}
export class Tooltip extends React.Component<TooltipProps> { }

export declare function withTooltip<P>(
component: React.ComponentType<P>,
Expand Down
61 changes: 30 additions & 31 deletions src/Tooltip/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import tippy from './js/tippy';
import {Browser} from './js/core/globals';
import { Browser } from './js/core/globals';

const stopPortalEvent = e => e.stopPropagation();

Expand All @@ -10,6 +10,7 @@ const defaultProps = {
animation: 'shift',
animateFill: true,
arrow: false,
arrowSize: 'regular',
delay: 0,
hideDelay: 0,
trigger: 'mouseenter focus',
Expand All @@ -24,17 +25,16 @@ const defaultProps = {
followCursor: false,
inertia: false,
popperOptions: {},
onShow: () => {},
onShown: () => {},
onHide: () => {},
onHidden: () => {},
onShow: () => { },
onShown: () => { },
onHide: () => { },
onHidden: () => { },
disabled: false,
arrowSize: 'regular',
size: 'regular',
className: '',
style: {},
distance: 10,
onRequestClose: () => {},
onRequestClose: () => { },
sticky: false,
stickyDuration: 200,
tag: 'div',
Expand Down Expand Up @@ -72,22 +72,22 @@ class Tooltip extends Component {
}

componentDidMount() {
if (typeof window === 'undefined' || typeof document === 'undefined' ) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
this.initTippy();
}

componentWillUnmount() {
if (typeof window === 'undefined' || typeof document === 'undefined' ) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
this.destroyTippy();
}

componentDidUpdate(prevProps) {
// enable and disabled
if (typeof window === 'undefined' || typeof document === 'undefined' ) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
if (this.props.disabled === false && prevProps.disabled === true) {
Expand Down Expand Up @@ -132,7 +132,7 @@ class Tooltip extends Component {
}

_showTooltip() {
if (typeof window === 'undefined' || typeof document === 'undefined' ) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
if (this.tippy) {
Expand All @@ -142,7 +142,7 @@ class Tooltip extends Component {
}

_hideTooltip() {
if (typeof window === 'undefined' || typeof document === 'undefined' ) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
if (this.tippy) {
Expand All @@ -152,7 +152,7 @@ class Tooltip extends Component {
}

_updateSettings(name, value) {
if (typeof window === 'undefined' || typeof document === 'undefined' ) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
if (this.tippy) {
Expand All @@ -162,7 +162,7 @@ class Tooltip extends Component {
}

_updateReactDom() {
if (typeof window === 'undefined' || typeof document === 'undefined' ) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
if (this.tippy) {
Expand All @@ -176,7 +176,7 @@ class Tooltip extends Component {
}

_updateTippy() {
if (typeof window === 'undefined' || typeof document === 'undefined' ) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
if (this.tippy) {
Expand All @@ -186,7 +186,7 @@ class Tooltip extends Component {
}

_initTippy() {
if (typeof window === 'undefined' || typeof document === 'undefined' || !Browser.SUPPORTED) {
if (typeof window === 'undefined' || typeof document === 'undefined' || !Browser.SUPPORTED) {
return;
}
if (!this.props.disabled) {
Expand Down Expand Up @@ -245,7 +245,7 @@ class Tooltip extends Component {
}

_destroyTippy() {
if (typeof window === 'undefined' || typeof document === 'undefined' ) {
if (typeof window === 'undefined' || typeof document === 'undefined') {
return;
}
if (this.tippy) {
Expand All @@ -265,17 +265,16 @@ class Tooltip extends Component {
return (
<React.Fragment>
<Tag
ref={(tooltip) =>
{ this.tooltipDOM = tooltip; }}
title={this.props.title}
className={this.props.className}
tabIndex={this.props.tabIndex}
style={{
display: 'inline',
...this.props.style
}}
>
{this.props.children}
ref={(tooltip) => { this.tooltipDOM = tooltip; }}
title={this.props.title}
className={this.props.className}
tabIndex={this.props.tabIndex}
style={{
display: 'inline',
...this.props.style
}}
>
{this.props.children}

</Tag>
{this.state.reactDOMValue && (
Expand All @@ -298,14 +297,14 @@ class Tooltip extends Component {
onMouseOver={stopPortalEvent}
onMouseOut={stopPortalEvent}
onMouseUp={stopPortalEvent}

onKeyDown={stopPortalEvent}
onKeyPress={stopPortalEvent}
onKeyUp={stopPortalEvent}

onFocus={stopPortalEvent}
onBlur={stopPortalEvent}

onChange={stopPortalEvent}
onInput={stopPortalEvent}
onInvalid={stopPortalEvent}
Expand Down