|
| 1 | +import React, { Component, ReactElement, ElementRef } from 'react'; |
| 2 | +import { Animated, GestureResponderEvent, ImageSourcePropType, ImageStyle, StyleProp, TextStyle, ViewStyle, LayoutChangeEvent, View as ViewRN } from 'react-native'; |
| 3 | +declare enum TARGET_POSITIONS { |
| 4 | + LEFT = "left", |
| 5 | + RIGHT = "right", |
| 6 | + CENTER = "center" |
| 7 | +} |
| 8 | +declare enum HintPositions { |
| 9 | + TOP = "top", |
| 10 | + BOTTOM = "bottom" |
| 11 | +} |
| 12 | +interface HintTargetFrame { |
| 13 | + x?: number; |
| 14 | + y?: number; |
| 15 | + width?: number; |
| 16 | + height?: number; |
| 17 | +} |
| 18 | +interface Position { |
| 19 | + top?: number; |
| 20 | + bottom?: number; |
| 21 | + left?: number; |
| 22 | + right?: number; |
| 23 | +} |
| 24 | +interface HintPositionStyle extends Position { |
| 25 | + alignItems?: string; |
| 26 | +} |
| 27 | +interface Paddings { |
| 28 | + paddingLeft?: number; |
| 29 | + paddingRight?: number; |
| 30 | + paddingVertical?: number; |
| 31 | + paddingHorizontal?: number; |
| 32 | +} |
| 33 | +export interface HintProps { |
| 34 | + /** |
| 35 | + * Control the visibility of the hint |
| 36 | + */ |
| 37 | + visible?: boolean; |
| 38 | + /** |
| 39 | + * The hint background color |
| 40 | + */ |
| 41 | + color?: string; |
| 42 | + /** |
| 43 | + * The hint message |
| 44 | + */ |
| 45 | + message?: string | ReactElement; |
| 46 | + /** |
| 47 | + * The hint message custom style |
| 48 | + */ |
| 49 | + messageStyle?: StyleProp<TextStyle>; |
| 50 | + /** |
| 51 | + * Icon to show next to the hint's message |
| 52 | + */ |
| 53 | + icon?: ImageSourcePropType; |
| 54 | + /** |
| 55 | + * The icon's style |
| 56 | + */ |
| 57 | + iconStyle?: StyleProp<ImageStyle>; |
| 58 | + /** |
| 59 | + * The hint's position |
| 60 | + */ |
| 61 | + position?: HintPositions; |
| 62 | + /** |
| 63 | + * Provide custom target position instead of wrapping a child |
| 64 | + */ |
| 65 | + targetFrame?: HintTargetFrame; |
| 66 | + /** |
| 67 | + * Show side tips instead of the middle tip |
| 68 | + */ |
| 69 | + useSideTip?: boolean; |
| 70 | + /** |
| 71 | + * The hint's border radius |
| 72 | + */ |
| 73 | + borderRadius?: number; |
| 74 | + /** |
| 75 | + * Hint margins from screen edges |
| 76 | + */ |
| 77 | + edgeMargins?: number; |
| 78 | + /** |
| 79 | + * Hint offset from target |
| 80 | + */ |
| 81 | + offset?: number; |
| 82 | + /** |
| 83 | + * Callback for the background press |
| 84 | + */ |
| 85 | + onBackgroundPress?: (event: GestureResponderEvent) => void; |
| 86 | + /** |
| 87 | + * The hint container width |
| 88 | + */ |
| 89 | + containerWidth?: number; |
| 90 | + /** |
| 91 | + * The hint's test identifier |
| 92 | + */ |
| 93 | + testID?: string; |
| 94 | + /** |
| 95 | + * Additional styling |
| 96 | + */ |
| 97 | + style?: StyleProp<ViewStyle>; |
| 98 | +} |
| 99 | +interface HintState { |
| 100 | + targetLayout?: HintTargetFrame; |
| 101 | + targetLayoutInWindow?: HintTargetFrame; |
| 102 | +} |
| 103 | +/** |
| 104 | + * @description: Hint component for displaying a tooltip over wrapped component |
| 105 | + * @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/HintsScreen.js |
| 106 | + * @notes: You can either wrap a component or pass a specific targetFrame |
| 107 | + */ |
| 108 | +declare class Hint extends Component<HintProps, HintState> { |
| 109 | + static displayName: string; |
| 110 | + static defaultProps: { |
| 111 | + position: HintPositions; |
| 112 | + }; |
| 113 | + static positions: typeof HintPositions; |
| 114 | + targetRef: ElementRef<typeof ViewRN> | null; |
| 115 | + hintRef: ElementRef<typeof ViewRN> | null; |
| 116 | + state: { |
| 117 | + targetLayoutInWindow: undefined; |
| 118 | + targetLayout: HintTargetFrame | undefined; |
| 119 | + }; |
| 120 | + visibleAnimated: Animated.Value; |
| 121 | + componentDidUpdate(prevProps: HintProps): void; |
| 122 | + focusAccessibilityOnHint: () => void; |
| 123 | + setTargetRef: (ref: ElementRef<typeof ViewRN>) => void; |
| 124 | + setHintRef: (ref: ElementRef<typeof ViewRN>) => void; |
| 125 | + onTargetLayout: ({ nativeEvent: { layout } }: LayoutChangeEvent) => void; |
| 126 | + getAccessibilityInfo(): { |
| 127 | + accessible: boolean; |
| 128 | + accessibilityLabel: string; |
| 129 | + } | undefined; |
| 130 | + get containerWidth(): number; |
| 131 | + get targetLayout(): HintTargetFrame | undefined; |
| 132 | + get showHint(): boolean; |
| 133 | + get tipSize(): { |
| 134 | + width: number; |
| 135 | + height: number; |
| 136 | + }; |
| 137 | + get hintOffset(): number; |
| 138 | + get edgeMargins(): number; |
| 139 | + get useSideTip(): boolean; |
| 140 | + getTargetPositionOnScreen(): TARGET_POSITIONS; |
| 141 | + getContainerPosition(): { |
| 142 | + top: number | undefined; |
| 143 | + left: number | undefined; |
| 144 | + } | undefined; |
| 145 | + getHintPosition(): HintPositionStyle; |
| 146 | + getHintPadding(): Paddings; |
| 147 | + getHintAnimatedStyle: () => { |
| 148 | + opacity: Animated.Value; |
| 149 | + transform: { |
| 150 | + translateY: Animated.AnimatedInterpolation; |
| 151 | + }[]; |
| 152 | + }; |
| 153 | + getTipPosition(): Position; |
| 154 | + renderHintTip(): JSX.Element; |
| 155 | + renderHint(): JSX.Element | undefined; |
| 156 | + renderHintContainer(): JSX.Element; |
| 157 | + renderChildren(): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)> | undefined; |
| 158 | + render(): {} | null | undefined; |
| 159 | +} |
| 160 | +declare const _default: React.ComponentClass<HintProps & { |
| 161 | + useCustomTheme?: boolean | undefined; |
| 162 | +}, any> & typeof Hint; |
| 163 | +export default _default; |
0 commit comments