Skip to content

Commit

Permalink
Fix type error in walkthroughable
Browse files Browse the repository at this point in the history
  • Loading branch information
mohebifar committed Apr 11, 2024
1 parent b67bf9c commit b948967
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,21 @@ By default, if overlay is not explicitly specified, the `svg` overlay will be us
You can customize the tooltip and the step number components by passing a component to the `CopilotProvider` component. If you are looking for an example tooltip component, take a look at [the default ui implementations](https://github.com/mohebifar/react-native-copilot/blob/master/src/components/default-ui).

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

return (
// ...
)
};


<CopilotProvider tooltipComponent={TooltipComponent} stepNumberComponent={StepComponent}>
Expand Down
20 changes: 9 additions & 11 deletions src/hocs/walkthroughable.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import React, { type FunctionComponent } from "react";
import { type NativeMethods } from "react-native/types";

type PropsWithCopilot<P> = P & {
copilot: {
ref?: React.RefObject<NativeMethods>;
onLayout?: () => void;
};
};
interface CopilotType {
ref?: React.RefObject<NativeMethods>;
onLayout?: () => void;
}

export function walkthroughable<P = any>(
WrappedComponent: React.ComponentType<P>
WrappedComponent: React.ComponentType<P>,
) {
const Component: FunctionComponent<PropsWithCopilot<P>> = ({
copilot,
...props
}) => <WrappedComponent {...(copilot as any)} {...props} />;
const Component: FunctionComponent<P> = (props: P) => {
const { copilot, ...rest } = props as { copilot: CopilotType } & P;
return <WrappedComponent {...copilot} {...(rest as any)} />;
};

Component.displayName = "Walkthroughable";

Expand Down

0 comments on commit b948967

Please sign in to comment.