|
2 | 2 |
|
3 | 3 | A React Native library that provides an elegant way to create interactive focus guides and tooltips. It allows you to highlight specific components and display tooltips with smooth animations, perfect for creating onboarding experiences, feature walkthroughs, and interactive tutorials in your React Native applications. |
4 | 4 |
|
| 5 | +## Features |
| 6 | + |
| 7 | +- 🔍 Highlight specific components with customizable overlay |
| 8 | +- 💬 Display tooltips with flexible positioning |
| 9 | +- 🎯 Multiple tooltip position options (top, bottom, left, right, center, and more) |
| 10 | +- 📱 Responsive design that adapts to screen boundaries |
| 11 | +- 🎨 Customizable styling and positioning |
| 12 | +- ⚡️ Smooth animations and transitions |
| 13 | + |
5 | 14 | ## Installation |
6 | 15 |
|
7 | 16 | ```sh |
8 | 17 | npm install react-native-focus-guide |
| 18 | +# or |
| 19 | +yarn add react-native-focus-guide |
9 | 20 | ``` |
10 | 21 |
|
11 | 22 | ## Usage |
12 | 23 |
|
| 24 | +Here's a basic example of how to use the library: |
13 | 25 |
|
14 | | -```js |
15 | | -import { multiply } from 'react-native-focus-guide'; |
| 26 | +```jsx |
| 27 | +import React, { useRef, useState } from 'react'; |
| 28 | +import { View, Text, TouchableOpacity } from 'react-native'; |
| 29 | +import { HighlightToolTip } from 'react-native-focus-guide'; |
16 | 30 |
|
17 | | -// ... |
| 31 | +const App = () => { |
| 32 | + const targetRef = useRef(null); |
| 33 | + const [showTooltip, setShowTooltip] = useState(false); |
18 | 34 |
|
19 | | -const result = await multiply(3, 7); |
| 35 | + return ( |
| 36 | + <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> |
| 37 | + <TouchableOpacity |
| 38 | + ref={targetRef} |
| 39 | + onPress={() => setShowTooltip(true)} |
| 40 | + style={{ |
| 41 | + padding: 20, |
| 42 | + backgroundColor: '#007AFF', |
| 43 | + borderRadius: 8, |
| 44 | + }} |
| 45 | + > |
| 46 | + <Text style={{ color: 'white' }}>Click me!</Text> |
| 47 | + </TouchableOpacity> |
| 48 | + |
| 49 | + {showTooltip && ( |
| 50 | + <HighlightToolTip |
| 51 | + targetRef={targetRef} |
| 52 | + tooltipPosition="bottom" |
| 53 | + onRequestClose={() => setShowTooltip(false)} |
| 54 | + > |
| 55 | + <View |
| 56 | + style={{ padding: 16, backgroundColor: 'white', borderRadius: 8 }} |
| 57 | + > |
| 58 | + <Text>This is a tooltip!</Text> |
| 59 | + </View> |
| 60 | + </HighlightToolTip> |
| 61 | + )} |
| 62 | + </View> |
| 63 | + ); |
| 64 | +}; |
20 | 65 | ``` |
21 | 66 |
|
| 67 | +## Props |
| 68 | + |
| 69 | +The `HighlightToolTip` component accepts the following props: |
| 70 | + |
| 71 | +| Prop | Type | Required | Default | Description | |
| 72 | +| ----------------- | ---------------------------- | -------- | ---------------- | --------------------------------------------------- | |
| 73 | +| `targetRef` | `React.RefObject` | Yes | - | Reference to the component you want to highlight | |
| 74 | +| `children` | `React.ReactNode` | Yes | - | Content to display in the tooltip | |
| 75 | +| `onRequestClose` | `() => void` | Yes | - | Function called when the tooltip should be closed | |
| 76 | +| `tooltipPosition` | `TooltipPosition` | No | 'bottom' | Position of the tooltip relative to the target | |
| 77 | +| `offset` | `{ x?: number; y?: number }` | No | `{ x: 0, y: 0 }` | Offset for tooltip positioning | |
| 78 | +| `allowOverlap` | `boolean` | No | `false` | Whether to allow tooltip to overlap with the target | |
| 79 | + |
| 80 | +### TooltipPosition Types |
| 81 | + |
| 82 | +```typescript |
| 83 | +type TooltipPosition = |
| 84 | + | 'top' |
| 85 | + | 'bottom' |
| 86 | + | 'left' |
| 87 | + | 'right' |
| 88 | + | 'center' |
| 89 | + | 'topLeft' |
| 90 | + | 'topCenter' |
| 91 | + | 'topRight' |
| 92 | + | 'bottomLeft' |
| 93 | + | 'bottomCenter' |
| 94 | + | 'bottomRight'; |
| 95 | +``` |
| 96 | + |
| 97 | +## Advanced Usage |
| 98 | + |
| 99 | +### Custom Styling |
| 100 | + |
| 101 | +You can customize the tooltip's appearance by wrapping your content in a styled View: |
| 102 | + |
| 103 | +```jsx |
| 104 | +<HighlightToolTip |
| 105 | + targetRef={targetRef} |
| 106 | + tooltipPosition="bottom" |
| 107 | + onRequestClose={() => setShowTooltip(false)} |
| 108 | +> |
| 109 | + <View |
| 110 | + style={{ |
| 111 | + padding: 16, |
| 112 | + backgroundColor: 'white', |
| 113 | + borderRadius: 8, |
| 114 | + shadowColor: '#000', |
| 115 | + shadowOffset: { width: 0, height: 2 }, |
| 116 | + shadowOpacity: 0.25, |
| 117 | + shadowRadius: 3.84, |
| 118 | + elevation: 5, |
| 119 | + }} |
| 120 | + > |
| 121 | + <Text style={{ fontSize: 16, color: '#333' }}>Custom styled tooltip!</Text> |
| 122 | + </View> |
| 123 | +</HighlightToolTip> |
| 124 | +``` |
22 | 125 |
|
23 | 126 | ## Contributing |
24 | 127 |
|
|
0 commit comments