input

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 5 Imported by: 0

README

Input Component

Text input component with variants, sizes, and validation states.

Installation

import "github.com/xraph/forgeui/components/input"

Basic Usage

textInput := input.Input(
    input.WithType("text"),
    input.WithPlaceholder("Enter text..."),
)

Props

  • Type - Input type (text, email, password, etc.)
  • ID - Input ID
  • Name - Input name
  • Value - Input value
  • Placeholder - Placeholder text
  • Disabled - Disabled state
  • Required - Required state
  • ReadOnly - Read-only state
  • Class - Custom CSS classes
  • Attrs - Additional HTML attributes

Options

input.WithType(t string)
input.WithID(id string)
input.WithName(name string)
input.WithValue(value string)
input.WithPlaceholder(placeholder string)
input.Disabled()
input.Required()
input.ReadOnly()
input.WithClass(class string)
input.WithAttrs(attrs ...g.Node)

Examples

Text Input
textInput := input.Input(
    input.WithType("text"),
    input.WithName("username"),
    input.WithPlaceholder("Enter username"),
)
Email Input
emailInput := input.Input(
    input.WithType("email"),
    input.WithName("email"),
    input.WithPlaceholder("[email protected]"),
    input.Required(),
)
Password Input
passwordInput := input.Input(
    input.WithType("password"),
    input.WithName("password"),
    input.WithPlaceholder("••••••••"),
    input.Required(),
)
Disabled Input
disabledInput := input.Input(
    input.WithType("text"),
    input.WithValue("Cannot edit"),
    input.Disabled(),
)
Read-Only Input
readOnlyInput := input.Input(
    input.WithType("text"),
    input.WithValue("Read only value"),
    input.ReadOnly(),
)

Input Types

Supports all HTML5 input types:

  • text - Single-line text
  • email - Email address
  • password - Password (hidden text)
  • number - Numeric input
  • tel - Telephone number
  • url - URL
  • search - Search input
  • date - Date picker
  • time - Time picker
  • datetime-local - Date and time
  • month - Month picker
  • week - Week picker
  • color - Color picker
  • file - File upload
  • range - Slider
  • hidden - Hidden input

With Form Field

Use with the form.Field component for complete form fields:

field := form.Field(
    "Email Address",
    input.Input(
        input.WithType("email"),
        input.WithID("email"),
        input.WithName("email"),
        input.WithPlaceholder("[email protected]"),
    ),
    form.WithID("email"),
    form.WithRequired(),
    form.WithDescription("We'll never share your email."),
)

Validation States

The input component supports validation states through CSS classes:

// Error state (use with form.Field)
field := form.Field(
    "Email",
    input.Input(
        input.WithType("email"),
        input.WithClass("border-destructive"),
    ),
    form.WithError("Invalid email address"),
)

Styling

The input component uses Tailwind CSS classes:

// Base classes
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2"
"text-sm ring-offset-background"
"file:border-0 file:bg-transparent file:text-sm file:font-medium"
"placeholder:text-muted-foreground"
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
"disabled:cursor-not-allowed disabled:opacity-50"
Custom Styling
customInput := input.Input(
    input.WithType("text"),
    input.WithClass("bg-blue-50 border-blue-300"),
)

Accessibility

  • Uses semantic HTML <input> element
  • Supports aria-* attributes via WithAttrs
  • Works with <label> elements via id attribute
  • Proper focus states with visible outline
  • Disabled state prevents interaction

File Input

fileInput := input.Input(
    input.WithType("file"),
    input.WithName("upload"),
    input.WithAttrs(g.Attr("accept", "image/*")),
)

Number Input

numberInput := input.Input(
    input.WithType("number"),
    input.WithName("quantity"),
    input.WithAttrs(
        g.Attr("min", "1"),
        g.Attr("max", "100"),
        g.Attr("step", "1"),
    ),
)

Search Input

searchInput := input.Input(
    input.WithType("search"),
    input.WithName("query"),
    input.WithPlaceholder("Search..."),
)

Date Input

dateInput := input.Input(
    input.WithType("date"),
    input.WithName("birthdate"),
)

Complete Example

func LoginForm() g.Node {
    return form.Form(
        []form.Option{
            form.WithAction("/auth/login"),
            form.WithMethod("POST"),
        },
        form.Field(
            "Email",
            input.Input(
                input.WithType("email"),
                input.WithID("email"),
                input.WithName("email"),
                input.WithPlaceholder("[email protected]"),
                input.Required(),
            ),
            form.WithID("email"),
            form.WithRequired(),
        ),
        form.Field(
            "Password",
            input.Input(
                input.WithType("password"),
                input.WithID("password"),
                input.WithName("password"),
                input.WithPlaceholder("••••••••"),
                input.Required(),
            ),
            form.WithID("password"),
            form.WithRequired(),
        ),
        button.Button(
            g.Text("Sign In"),
            button.WithType("submit"),
        ),
    )
}

Documentation

Overview

Package input provides input components for forms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Field

func Field(labelText string, inputOpts []Option, children ...g.Node) g.Node

Field creates a complete form field with label, input, and optional description/error

func FormDescription

func FormDescription(text string) g.Node

FormDescription creates a form field description

func FormError

func FormError(text string) g.Node

FormError creates a form field error message

func Input

func Input(opts ...Option) g.Node

Input creates an input field following shadcn/ui patterns

Example:

input.Input(
    input.WithPlaceholder("Enter email"),
    input.WithType("email"),
    input.WithName("email"),
)

With error state:

input.Input(
    input.WithPlaceholder("Enter email"),
    input.Invalid(), // Shows error styling via aria-invalid
)

func InputGroup

func InputGroup(opts []GroupOption, children ...g.Node) g.Node

InputGroup creates a group of inputs with addons or positioned elements.

This follows the shadcn/ui input-group pattern with support for: - Inline addons (inline-start, inline-end) - Block addons (block-start, block-end) - Focus and error states - Disabled state

Example with inline addons:

input.InputGroup(
    []input.GroupOption{},
    input.InputGroupAddon(
        []input.AddonOption{input.WithAddonAlign(input.AlignInlineStart)},
        icons.Mail(),
    ),
    input.InputGroupInput(input.WithPlaceholder("Enter email")),
)

Example with button:

input.InputGroup(
    []input.GroupOption{},
    input.InputGroupInput(input.WithPlaceholder("Search...")),
    input.InputGroupAddon(
        []input.AddonOption{input.WithAddonAlign(input.AlignInlineEnd)},
        input.InputGroupButton(
            g.Text("Search"),
            input.WithGroupButtonSize(input.GroupButtonSizeSM),
        ),
    ),
)

func InputGroupAddon

func InputGroupAddon(opts []AddonOption, children ...g.Node) g.Node

InputGroupAddon creates an addon container for icons, text, or buttons.

Supports four alignment positions: - inline-start: Left side of the input (default) - inline-end: Right side of the input - block-start: Above the input (stacked layout) - block-end: Below the input (stacked layout)

Example:

input.InputGroupAddon(
    []input.AddonOption{input.WithAddonAlign(input.AlignInlineStart)},
    icons.Search(),
)

func InputGroupButton

func InputGroupButton(children g.Node, opts ...GroupButtonOption) g.Node

InputGroupButton creates a button styled for use inside input groups.

Uses ghost variant by default with smaller sizing options appropriate for input groups.

Example:

input.InputGroupButton(
    g.Text("Search"),
    input.WithGroupButtonSize(input.GroupButtonSizeXS),
)

func InputGroupInput

func InputGroupInput(opts ...GroupInputOption) g.Node

InputGroupInput creates an input styled for use inside input groups.

This input removes its own border and shadow since the parent InputGroup handles those. Note: You can also use the regular Input() component inside InputGroup - it will be styled automatically.

Example:

input.InputGroupInput(
    input.WithGroupInputPlaceholder("Enter value..."),
    input.WithGroupInputName("search"),
)

func InputGroupText

func InputGroupText(text string, opts ...func(*textProps)) g.Node

InputGroupText creates a text element for use inside addons.

Example:

input.InputGroupAddon(
    []input.AddonOption{input.WithAddonAlign(input.AlignInlineStart)},
    input.InputGroupText("https://"),
)

func InputGroupTextarea

func InputGroupTextarea(opts ...GroupTextareaOption) g.Node

InputGroupTextarea creates a textarea styled for use inside input groups.

This textarea removes its own border and shadow since the parent InputGroup handles those. Note: You can also use the regular Textarea component inside InputGroup - it will be styled automatically.

Example:

input.InputGroupTextarea(
    input.WithGroupTextareaPlaceholder("Enter message..."),
    input.WithGroupTextareaRows(4),
)

func InputLeftAddon deprecated

func InputLeftAddon(opts []AddonOption, children ...g.Node) g.Node

InputLeftAddon creates a left addon (prefix) attached to the input.

Deprecated: Use InputGroupAddon with WithAddonAlign(AlignInlineStart) instead.

func InputLeftElement deprecated

func InputLeftElement(opts []ElementOption, children ...g.Node) g.Node

InputLeftElement creates a left element positioned absolutely inside the input.

Deprecated: Use InputGroupAddon with WithAddonAlign(AlignInlineStart) instead.

func InputRightAddon deprecated

func InputRightAddon(opts []AddonOption, children ...g.Node) g.Node

InputRightAddon creates a right addon (suffix) attached to the input.

Deprecated: Use InputGroupAddon with WithAddonAlign(AlignInlineEnd) instead.

func InputRightElement deprecated

func InputRightElement(opts []ElementOption, children ...g.Node) g.Node

InputRightElement creates a right element positioned absolutely inside the input.

Deprecated: Use InputGroupAddon with WithAddonAlign(AlignInlineEnd) instead.

func SearchInput

func SearchInput(opts ...Option) g.Node

SearchInput creates a search input with a search icon

func WithTextClass

func WithTextClass(class string) func(*textProps)

WithTextClass adds custom classes to the text element

Types

type AddonOption

type AddonOption func(*AddonProps)

AddonOption is a functional option for configuring addons

func WithAddonAlign

func WithAddonAlign(align Alignment) AddonOption

WithAddonAlign sets the alignment of the addon

func WithAddonAttrs

func WithAddonAttrs(attrs ...g.Node) AddonOption

WithAddonAttrs adds custom attributes to the addon

func WithAddonClass

func WithAddonClass(class string) AddonOption

WithAddonClass adds custom classes to the addon

type AddonProps

type AddonProps struct {
	Align Alignment
	Class string
	Attrs []g.Node
}

AddonProps defines addon configuration

type Alignment

type Alignment string

Alignment defines the position of addons in an input group

const (
	AlignInlineStart Alignment = "inline-start"
	AlignInlineEnd   Alignment = "inline-end"
	AlignBlockStart  Alignment = "block-start"
	AlignBlockEnd    Alignment = "block-end"
)

type ElementOption

type ElementOption func(*ElementProps)

ElementOption is a functional option for configuring positioned elements

func WithElementAttrs

func WithElementAttrs(attrs ...g.Node) ElementOption

WithElementAttrs adds custom attributes to the element

func WithElementClass

func WithElementClass(class string) ElementOption

WithElementClass adds custom classes to the element

type ElementProps

type ElementProps struct {
	Class string
	Attrs []g.Node
}

ElementProps defines positioned element configuration

type GroupButtonOption

type GroupButtonOption func(*GroupButtonProps)

GroupButtonOption is a functional option for configuring group buttons

func WithGroupButtonAttrs

func WithGroupButtonAttrs(attrs ...g.Node) GroupButtonOption

WithGroupButtonAttrs adds custom attributes to the button

func WithGroupButtonClass

func WithGroupButtonClass(class string) GroupButtonOption

WithGroupButtonClass adds custom classes to the button

func WithGroupButtonSize

func WithGroupButtonSize(size GroupButtonSize) GroupButtonOption

WithGroupButtonSize sets the button size

func WithGroupButtonType

func WithGroupButtonType(t string) GroupButtonOption

WithGroupButtonType sets the button type

func WithGroupButtonVariant

func WithGroupButtonVariant(v forgeui.Variant) GroupButtonOption

WithGroupButtonVariant sets the button variant

type GroupButtonProps

type GroupButtonProps struct {
	Size    GroupButtonSize
	Variant forgeui.Variant
	Type    string
	Class   string
	Attrs   []g.Node
}

GroupButtonProps defines input group button configuration

type GroupButtonSize

type GroupButtonSize string

GroupButtonSize defines the size of buttons in input groups

const (
	GroupButtonSizeXS     GroupButtonSize = "xs"
	GroupButtonSizeSM     GroupButtonSize = "sm"
	GroupButtonSizeIconXS GroupButtonSize = "icon-xs"
	GroupButtonSizeIconSM GroupButtonSize = "icon-sm"
)

type GroupInputOption

type GroupInputOption func(*GroupInputProps)

GroupInputOption is a functional option for configuring group inputs

func GroupInputDisabled

func GroupInputDisabled() GroupInputOption

GroupInputDisabled sets the disabled attribute

func GroupInputInvalid

func GroupInputInvalid() GroupInputOption

GroupInputInvalid sets the aria-invalid attribute for error states

func GroupInputRequired

func GroupInputRequired() GroupInputOption

GroupInputRequired sets the required attribute

func WithGroupInputAttrs

func WithGroupInputAttrs(attrs ...g.Node) GroupInputOption

WithGroupInputAttrs adds custom attributes to the input

func WithGroupInputClass

func WithGroupInputClass(class string) GroupInputOption

WithGroupInputClass adds custom classes to the input

func WithGroupInputID

func WithGroupInputID(id string) GroupInputOption

WithGroupInputID sets the input ID

func WithGroupInputName

func WithGroupInputName(name string) GroupInputOption

WithGroupInputName sets the input name

func WithGroupInputPlaceholder

func WithGroupInputPlaceholder(placeholder string) GroupInputOption

WithGroupInputPlaceholder sets the input placeholder

func WithGroupInputType

func WithGroupInputType(t string) GroupInputOption

WithGroupInputType sets the input type

func WithGroupInputValue

func WithGroupInputValue(value string) GroupInputOption

WithGroupInputValue sets the input value

type GroupInputProps

type GroupInputProps struct {
	Type        string
	Name        string
	ID          string
	Placeholder string
	Value       string
	Required    bool
	Disabled    bool
	Invalid     bool
	Class       string
	Attrs       []g.Node
}

GroupInputProps defines input group input configuration

type GroupOption

type GroupOption func(*GroupProps)

GroupOption is a functional option for configuring input groups

func GroupDisabled

func GroupDisabled() GroupOption

GroupDisabled sets the disabled state on the input group

func WithGroupAttrs

func WithGroupAttrs(attrs ...g.Node) GroupOption

WithGroupAttrs adds custom attributes to the input group

func WithGroupClass

func WithGroupClass(class string) GroupOption

WithGroupClass adds custom classes to the input group

type GroupProps

type GroupProps struct {
	Disabled bool
	Class    string
	Attrs    []g.Node
}

GroupProps defines input group configuration

type GroupTextareaOption

type GroupTextareaOption func(*GroupTextareaProps)

GroupTextareaOption is a functional option for configuring group textareas

func GroupTextareaDisabled

func GroupTextareaDisabled() GroupTextareaOption

GroupTextareaDisabled sets the disabled attribute

func GroupTextareaInvalid

func GroupTextareaInvalid() GroupTextareaOption

GroupTextareaInvalid sets the aria-invalid attribute for error states

func GroupTextareaRequired

func GroupTextareaRequired() GroupTextareaOption

GroupTextareaRequired sets the required attribute

func WithGroupTextareaAttrs

func WithGroupTextareaAttrs(attrs ...g.Node) GroupTextareaOption

WithGroupTextareaAttrs adds custom attributes to the textarea

func WithGroupTextareaClass

func WithGroupTextareaClass(class string) GroupTextareaOption

WithGroupTextareaClass adds custom classes to the textarea

func WithGroupTextareaID

func WithGroupTextareaID(id string) GroupTextareaOption

WithGroupTextareaID sets the textarea ID

func WithGroupTextareaName

func WithGroupTextareaName(name string) GroupTextareaOption

WithGroupTextareaName sets the textarea name

func WithGroupTextareaPlaceholder

func WithGroupTextareaPlaceholder(placeholder string) GroupTextareaOption

WithGroupTextareaPlaceholder sets the textarea placeholder

func WithGroupTextareaRows

func WithGroupTextareaRows(rows int) GroupTextareaOption

WithGroupTextareaRows sets the textarea rows

func WithGroupTextareaValue

func WithGroupTextareaValue(value string) GroupTextareaOption

WithGroupTextareaValue sets the textarea value

type GroupTextareaProps

type GroupTextareaProps struct {
	Name        string
	ID          string
	Placeholder string
	Value       string
	Rows        int
	Required    bool
	Disabled    bool
	Invalid     bool
	Class       string
	Attrs       []g.Node
}

GroupTextareaProps defines input group textarea configuration

type Option

type Option func(*Props)

func Disabled

func Disabled() Option

func Invalid

func Invalid() Option

Invalid sets aria-invalid="true" for error state styling

func Required

func Required() Option

func WithAttrs

func WithAttrs(attrs ...g.Node) Option

func WithClass

func WithClass(class string) Option

func WithID

func WithID(id string) Option

func WithName

func WithName(name string) Option

func WithPlaceholder

func WithPlaceholder(placeholder string) Option

func WithType

func WithType(t string) Option

func WithValue

func WithValue(value string) Option

func WithVariant

func WithVariant(v forgeui.Variant) Option

type Props

type Props struct {
	Type        string // text, email, password, etc.
	Name        string
	ID          string
	Placeholder string
	Value       string
	Required    bool
	Disabled    bool
	Invalid     bool // Sets aria-invalid for error styling
	Variant     forgeui.Variant
	Class       string
	Attrs       []g.Node
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL