Wrap your React Router Link with the React Link Preview and feed it a component. You'll get a modal with a preview of that component on long-press and a regular link otherwise.
npm install react-link-previewDemo: LinkPreview Github Page
import 'LinkPreview' from 'react-link-preview';
Start the dev server: npm run dev
Compile the production version of the demo (do this before pushing to master or making an MR/PR): npm run docs:prod
Compile the distribution version of the component (do this before pushing to master or to NPM): npm run dist-build
This wrapper adds a modal preview to links or buttons -- on long-press -- that displays any react component you provide.
A small progress bar shows the long-press progress.
This is a very simple component that wraps the react-router-dom component with a bit of added functionality.
Wrap any link or button with
This might be the react route component you intend to send the user to, or another component with useful preview information.
This component is intended for use on mobile devices primarily, but can be toggled to be used on desktop as well.
``javascript``
loadBarAbove={false}
previewComponent={
This text can be any element you like instead
Property | Default | Required? | Description
-------- | ------- | --------- | -----------
previewComponent | N/A | yes | A component to show in the preview.
clickWindow | 500 | no | The window of time (ms) where a regular click is registered.
longPressTime | 1000 | no | The time (ms) it takes the user to hold before it's considered a longpress.
mobileOnly | true | no | Setting this to false allows the preview to work on desktop, too.
loadBarAbove | true | no | Settings this to false moves the longpress bar below your link.