import type { Meta, StoryObj } from "@storybook/react" import type React from "react" import Highlighter from "./Highlighter" type HighlighterProps = React.ComponentProps const meta: Meta = { component: Highlighter, title: "Highlighter / Highlighter", // argTypes allows you to define the behavior of the args in each story argTypes: { searchWords: { control: "object", description: "Array of search words to highlight", }, textToHighlight: { control: "text", description: "The text to highlight matches in", }, highlightClassName: { control: "text", description: "CSS class name applied to highlighted text", }, highlightStyle: { control: "object", description: "Inline styles applied to highlighted text", }, caseSensitive: { control: "boolean", description: "Whether the search should be case sensitive", }, autoEscape: { control: "boolean", description: "Escape characters in searchWords which are meaningful in regular expressions", }, activeIndex: { control: "number", description: "Specify the match index that should be actively highlighted", }, activeClassName: { control: "text", description: "The class name to be applied to an active match", }, }, } export default meta type Story = StoryObj export const Default: Story = { args: { searchWords: ["text", "highlight"], textToHighlight: "This is some sample text that we want to highlight certain words in.", highlightClassName: "bg-yellow-200", "data-testid": "default", }, } export const CaseSensitive: Story = { args: { searchWords: ["Text", "Sample"], textToHighlight: "This is some sample text that we want to highlight certain words in. Text and text are different.", caseSensitive: true, highlightClassName: "bg-blue-200", "data-testid": "case-sensitive", }, } export const WithActiveHighlight: Story = { args: { searchWords: ["sample", "text", "highlight"], textToHighlight: "This is some sample text that we want to highlight certain words in. More sample text here.", activeIndex: 1, highlightClassName: "bg-yellow-200", activeClassName: "bg-red-300 font-bold", "data-testid": "active-highlight", }, } export const CustomStyles: Story = { args: { searchWords: ["important", "note"], textToHighlight: "This is an important note that contains some important information.", highlightStyle: { backgroundColor: "#ff6b6b", color: "white", padding: "2px 4px", borderRadius: "4px", fontWeight: "bold", }, "data-testid": "custom-styles", }, } export const MultipleWords: Story = { args: { searchWords: ["React", "component", "highlight", "text"], textToHighlight: "This React component is designed to highlight specific text within a larger body of text. The highlight functionality makes it easy to emphasize important words in your React applications.", highlightClassName: "bg-green-200 px-1 rounded", "data-testid": "multiple-words", }, } export const LongText: Story = { args: { searchWords: ["Lorem", "ipsum", "dolor"], textToHighlight: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit.", highlightClassName: "bg-purple-200", className: "max-w-md", "data-testid": "long-text", }, render: args => (
), }