import React, { useRef } from 'react' import { type Meta } from '@storybook/react-vite' import { useShowElement } from '..' import { DocsTemplate } from '../../../.storybook' export const Example = (args: { threshold?: number }): React.JSX.Element => { const myRef = useRef() as React.MutableRefObject const refIsVisible = useShowElement(myRef, args.threshold || 0) return (

Scroll Me!

Part 1 - not visible
Part 2 - visible
Part 3 - not visible
{refIsVisible && (
Hello There!
)}
) } Example.storyName = 'useShowElement' Example.args = { threshold: 0.1, } export default { title: 'Hooks/useShowElement', component: Example, argTypes: { threshold: { control: { type: 'range', min: 0, max: 1, step: 0.1 } }, }, parameters: { viewMode: 'docs', previewTabs: { canvas: { hidden: true }, }, docs: { page: () => ( <> Part of a page ... {refIsVisible &&
Element shown conditionally
} `} description='A hook used to conditionally show an element based on if a ref is visible on the page.' infoBullets={[ useShowElement is a hook and will run anytime the ref or threshold change. , This hook is used to conditionally show an element based on if a ref is visible on the page. This can be used in tables to show the bulk action option only if the table is on the page. , ]} /> ), }, }, } as Meta