Skip to content

Commit

Permalink
Update custom-components docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarbara committed Sep 12, 2024
1 parent d162ff8 commit 650ab36
Showing 1 changed file with 66 additions and 54 deletions.
120 changes: 66 additions & 54 deletions docs/custom-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ If you want to customize the default UI, check the [styling](styling.md) docs.

### Example with styled-components

```jsx
import Joyride, { BeaconRenderProps, TooltipRenderProps } from 'react-joyride';
```tsx
import { forwardRef } from 'react';
import Joyride, { BeaconRenderProps } from 'react-joyride';
import { keyframes } from '@emotion/react';
import styled from '@emotion/styled';

const pulse = keyframes`
0% {
Expand All @@ -45,15 +48,20 @@ const Beacon = styled.span`
width: 3rem;
`;

export () => (
<div>
<ReactJoyride
beaconComponent={BeaconComponent}
// beaconComponent={BeaconComponent as React.ElementType<BeaconRenderProps>} for TS
...
/>
</div>
);
const BeaconComponent = forwardRef<HTMLButtonElement, BeaconRenderProps>((props, ref) => {
return <Beacon ref={ref} {...props} />;
});

export function App() {
return (
<div>
<Joyride
beaconComponent={BeaconComponent}
// ...
/>
</div>
);
}
```

## tooltipComponent
Expand All @@ -80,47 +88,51 @@ export () => (

**tooltipProps** {object}: The root element props \(including `ref`\)

### Example with styled-components

```jsx
const Tooltip = ({
continuous,
index,
step,
backProps,
closeProps,
primaryProps,
tooltipProps,
}) => (
<TooltipBody {...tooltipProps}>
{step.title && <TooltipTitle>{step.title}</TooltipTitle>}
<TooltipContent>{step.content}</TooltipContent>
<TooltipFooter>
{index > 0 && (
<Button {...backProps}>
<FormattedMessage id="back" />
</Button>
)}
{continuous && (
<Button {...primaryProps}>
<FormattedMessage id="next" />
</Button>
)}
{!continuous && (
<Button {...closeProps}>
<FormattedMessage id="close" />
</Button>
)}
</TooltipFooter>
</TooltipBody>
);

export () => (
<div>
<ReactJoyride
tooltipComponent={Tooltip}
...
/>
</div>
);
### Example with css classes

```tsx
import Joyride, { TooltipRenderProps } from 'react-joyride';

function CustomTooltip(props: TooltipRenderProps) {
const { backProps, closeProps, continuous, index, primaryProps, skipProps, step, tooltipProps } =
props;

return (
<div className="tooltip__body" {...tooltipProps}>
<button className="tooltip__close" {...closeProps}>
&times;
</button>
{step.title && <h4 className="tooltip__title">{step.title}</h4>}
<div className="tooltip__content">{step.content}</div>
<div className="tooltip__footer">
<button className="tooltip__button" {...skipProps}>
{skipProps.title}
</button>
<div className="tooltip__spacer">
{index > 0 && (
<button className="tooltip__button" {...backProps}>
{backProps.title}
</button>
)}
{continuous && (
<button className="tooltip__button tooltip__button--primary" {...primaryProps}>
{primaryProps.title}
</button>
)}
</div>
</div>
</div>
);
}

export function App() {
return (
<div>
<Joyride
tooltipComponent={CustomTooltip}
// ...
/>
</div>
);
}
```

0 comments on commit 650ab36

Please sign in to comment.