import { search } from "@simplybusiness/icons"; import type { Meta, StoryObj } from "@storybook/react"; import { useRef } from "react"; import { excludeControls } from "../../utils"; import { StoryContainer } from "../../utils/StoryContainer"; import { Button } from "../Button"; import { Icon } from "../Icon"; import { Segment, SegmentGroup } from "../Segment"; import { Text } from "../Text"; import type { TextFieldProps } from "./TextField"; import { TextField } from "./TextField"; type StoryType = StoryObj; const meta: Meta = { title: "Forms/TextField", component: TextField, excludeStories: ["ExampleHorizontal"], argTypes: { type: { options: ["text", "password", "email", "tel", "url", "hidden"], control: { type: "radio" }, }, ...excludeControls( "description", "prefixInside", "prefixOutside", "suffixInside", "suffixOutside", "validationState", ), }, args: { isRequired: false, isReadOnly: false, }, decorators: [ Story => ( ), ], }; export const Default: StoryType = { render: (args: TextFieldProps) => , args: { label: "First name", placeholder: "", type: "text", isDisabled: false, errorMessage: "", }, }; export const Placeholder: StoryType = { render: (args: TextFieldProps) => , args: { label: "Email", placeholder: "email@example.com", type: "text", isDisabled: false, errorMessage: "", }, }; export const ControlledValue: StoryType = { render: (args: TextFieldProps) => , args: { label: "First name", placeholder: "", defaultValue: "john.doe@email.com", type: "text", isDisabled: false, errorMessage: "", }, }; export const ReadOnly: StoryType = { render: (args: TextFieldProps) => , args: { label: "First name", isReadOnly: true, isRequired: true, defaultValue: "John", type: "text", prefixInside: , }, }; export const Disabled: StoryType = { render: (args: TextFieldProps) => , args: { label: "First name", placeholder: "", defaultValue: "John", type: "text", isDisabled: true, prefixInside: , errorMessage: "", }, }; export const Valid: StoryType = { render: (args: TextFieldProps) => , args: { label: "First name", placeholder: "", defaultValue: "john.doe@email.com", type: "text", isDisabled: false, isInvalid: false, errorMessage: "", }, }; export const Hidden: StoryType = { render: (args: TextFieldProps) => , args: { label: "Secret", placeholder: "", defaultValue: "", type: "hidden", isDisabled: false, errorMessage: "", }, }; export const Invalid: StoryType = { render: (args: TextFieldProps) => , args: { label: "First name", placeholder: "", defaultValue: "john.doe@email.com", type: "text", isDisabled: false, isInvalid: true, prefixInside: , errorMessage: "This is an error message", }, }; export const WithChildren: StoryType = { render: (args: TextFieldProps) => , args: { label: "First name", placeholder: "", type: "text", isDisabled: false, errorMessage: "", children: A custom component, }, }; export const WithPrefixInside: StoryType = { render: (args: TextFieldProps) => , args: { label: "What is your specific trade/profession?", placeholder: "", type: "text", isRequired: true, isDisabled: false, errorMessage: "", prefixInside: , }, }; export const WithPrefixAndSuffixInside: StoryType = { render: (args: TextFieldProps) => , args: { label: "Amount", placeholder: "", type: "text", isRequired: true, isDisabled: false, errorMessage: "", prefixInside: $, suffixInside: .00, }, }; export const WithPrefixInsideAndSuffixOutside: StoryType = { render: (args: TextFieldProps) => , args: { label: "What does your business do?", placeholder: "", type: "text", isRequired: true, isDisabled: false, errorMessage: "", prefixInside: , suffixOutside: , }, }; export const WithPrefixOutsideAndSuffixInside: StoryType = { render: (args: TextFieldProps) => , args: { label: "What is your specific trade/profession?", placeholder: "", type: "text", isRequired: true, isDisabled: false, errorMessage: "", prefixOutside: , suffixInside: , }, }; export const WithPrefixOutside: StoryType = { render: (args: TextFieldProps) => , args: { label: "Link", placeholder: "", type: "text", isDisabled: false, isRequired: true, errorMessage: "", prefixOutside: https://, }, }; export const WithSuffixOutside: StoryType = { render: (args: TextFieldProps) => { // eslint-disable-next-line react-hooks/rules-of-hooks const fieldRef = useRef(null); return ( { try { const value = fieldRef.current?.value; await navigator.clipboard.writeText(value || ""); alert(`Copied to clipboard: ${value}`); } catch (err) { console.error("Failed to copy: ", err); } }} > Copy } /> ); }, args: { label: "Reference number", placeholder: "", type: "text", isRequired: true, isDisabled: false, errorMessage: "", defaultValue: "REF123A456", }, }; export const ExampleHorizontal = () => ( ); export default meta;