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

More options to customize tooltip and additional navigator #122

Open
wants to merge 2 commits 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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ You can customize the tooltip by passing a component to the `copilot` HOC maker.

```js
const TooltipComponent = ({
tooltipPosition,
arrowPosition,
isFirstStep,
isLastStep,
handleNext,
Expand Down Expand Up @@ -166,6 +168,28 @@ copilot({
})(RootComponent)
```

### Custom navigator
You can add a custom navigator, by passing a React Component to the `copilot` HOC maker.

This is the same prop as [tooltip](#custom-tooltip-component).

```js
const customNavigator = ({
isFirstStep,
isLastStep,
handleNext,
handlePrev,
handleStop,
currentStep,
}) => (
// ...
);

copilot({
customNavigator: customNavigator
})(RootComponent)
```

### Custom components as steps
The components wrapped inside `CopilotStep`, will receive a `copilot` prop of type `Object` which the outermost rendered element of the component or the element that you want the tooltip be shown around, must extend.

Expand Down
36 changes: 32 additions & 4 deletions src/components/CopilotModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type Props = {
overlay: 'svg' | 'view',
animated: boolean,
androidStatusBarVisible: boolean,
backdropColor: string
backdropColor: string,
customNavigator?: React$Component,
};

type State = {
Expand Down Expand Up @@ -263,23 +264,40 @@ class CopilotModal extends Component<Props, State> {
currentStepNumber={this.props.currentStepNumber}
/>
</Animated.View>,
<Animated.View key="arrow" style={[styles.arrow, this.state.arrow]} />,
<Animated.View key="tooltip" style={[styles.tooltip, this.state.tooltip]}>
TooltipComponent ? null : (
<Animated.View key="arrow" style={[styles.arrow, this.state.arrow]} />
),
TooltipComponent ? (
<TooltipComponent
key="tooltip"
arrowPosition={[this.state.arrow, { position: 'absolute' }]}
tooltipPosition={[this.state.tooltip, { position: 'absolute' }]}
isFirstStep={this.props.isFirstStep}
isLastStep={this.props.isLastStep}
currentStep={this.props.currentStep}
handleNext={this.handleNext}
handlePrev={this.handlePrev}
handleStop={this.handleStop}
/>
</Animated.View>,
) : (
<Animated.View key="tooltip" style={[styles.tooltip, this.state.tooltip]}>
<Tooltip
isFirstStep={this.props.isFirstStep}
isLastStep={this.props.isLastStep}
currentStep={this.props.currentStep}
handleNext={this.handleNext}
handlePrev={this.handlePrev}
handleStop={this.handleStop}
/>
</Animated.View>
),
];
}

render() {
const containerVisible = this.state.containerVisible || this.props.visible;
const contentVisible = this.state.layout && containerVisible;
const CustomNavigator = this.props.customNavigator;

return (
<Modal
Expand All @@ -295,6 +313,16 @@ class CopilotModal extends Component<Props, State> {
>
{contentVisible && this.renderMask()}
{contentVisible && this.renderTooltip()}
{!!CustomNavigator && (
<CustomNavigator
isFirstStep={this.props.isFirstStep}
isLastStep={this.props.isLastStep}
currentStep={this.props.currentStep}
handleNext={this.handleNext}
handlePrev={this.handlePrev}
handleStop={this.handleStop}
/>
)}
</View>
</Modal>
);
Expand Down
2 changes: 2 additions & 0 deletions src/hocs/copilot.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const copilot = ({
animated,
androidStatusBarVisible,
backdropColor,
customNavigator,
verticalOffset = 0,
wrapperStyle,
} = {}) =>
Expand Down Expand Up @@ -193,6 +194,7 @@ const copilot = ({
animated={animated}
androidStatusBarVisible={androidStatusBarVisible}
backdropColor={backdropColor}
customNavigator={customNavigator}
ref={(modal) => { this.modal = modal; }}
/>
</View>
Expand Down