/* eslint-disable react-hooks/rules-of-hooks */ import { useRef, useState } from "react"; import { Button, Flex, Text } from "../../../components"; import { useIsOverflow } from "./"; import type { Meta, StoryObj } from "@storybook/react"; const meta: Meta = { title: "Hooks/useIsOverflow", argTypes: { ref: { control: false, description: "The ref of the Element to check overflow for.", table: { type: { summary: "React.MutableRefObject", }, }, }, direction: { control: false, description: "Specifies the direction in which to detect overflow. If set to `any` X & Y overflow will be searched for.", table: { defaultValue: { summary: "vertical", }, type: { summary: "vertical | horizontal | any", }, }, options: ["vertical", "horizontal", "any"], }, trigger: { control: false, description: "optional trigger input of `unknown` type that when changed will re-search for overflow. It could for example be the text within a container as demonstrated in the demo.", table: { type: { summary: "unknown", }, }, }, }, }; export default meta; type Story = StoryObj; export const Default: Story = { render: () => { const [content, setContent] = useState("i"); const ref = useRef(null); const isOverflow = useIsOverflow({ ref, direction: "horizontal", trigger: content }); const handleLongText = () => { setContent("long"); }; const handleShortText = () => { setContent("i"); }; return ( {content} Is text overflowing? {isOverflow ? "yes" : "no"}