tailush

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 15 Imported by: 0

README

Tailush

Tailush is a library with form plush helpers for TailwindCSS forms and inputs. Its a drop in replacement for the form and form_for helpers that ship with Buffalo and are oriented towards Bootstrap. The goal of this library is to accelerate the development of web applications by make it simpler to develop forms with TailwindCSS in plush.

Installation

go get github.com/wawandco/tailush@latest
Usage

To install Tailush you should replace the form and form_for helpers in your actions/helpers.go file.

// In your helpers.go
import (
    ...
    "tailush"
    ...
)

... 
    // Custom Tailwindcss form helpers
    "formFor": tailush.FormForFn(),
    "form":    tailush.FormFn(),
...

Customizing

Customizing the form helpers is done by passing different instances of tailush.Option to the FormFn and FormForFn functions. The following example shows a set of options that can be passed to the helpers.

... 
    // Custom Tailwindcss form helpers
    "formFor": tailush.FormForFn(
        tailush.UseFieldContainerClass("mb-4"),
        tailush.UseLabelClass("block text-gray-700 text-sm font-bold mb-2"),
        tailush.UseInputClass("shadow border rounded-md w-full p-2 text-gray-700 focus:outline-none focus:shadow-outline"),
        tailush.UseErrorClass("text-red-500 text-xs italic"),
    ),
    ...
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormFn

func FormFn(formOptions ...FormHelperOption) any

FormFn returns a helper function to build forms. The resulting function can be used as replacement for the original form helper.

func FormForFn

func FormForFn(formOptions ...FormHelperOption) any

FormForFn returns a helper function to build forms. The resulting function can be used as replacement for the original form helper.

func NewForm

func NewForm(opts tags.Options, help hctx.Context) *form

NewForm creates a new form from passed options, it sets POST as the default method and also handles other methods as PUT by adding a `_method` hidden input.

func NewFormFor

func NewFormFor(model any, opts tags.Options, hctx hctx.Context) *formFor

NewFormFor creates a new Formfor with passed options. It takes into account the passed model.

func NewSelectTag

func NewSelectTag(opts tags.Options) *tags.Tag

NewSelectTag constructs a new `<select>` tag.

Types

type FormHelperOption

type FormHelperOption func(*form)

func UseCheckboxClass

func UseCheckboxClass(class string) FormHelperOption

UseCheckboxClass is used to override the default classes for the checkbox element.

func UseDateInputClass

func UseDateInputClass(class string) FormHelperOption

UseDateInputClass is used to override the default classes for the errors.

func UseErrorClass

func UseErrorClass(class string) FormHelperOption

UseErrorClass is used to override the default classes for the errors.

func UseFieldContainerClass

func UseFieldContainerClass(class string) FormHelperOption

UseFieldContainerClass is used to override the default classes for the container element.

func UseFileClass

func UseFileClass(class string) FormHelperOption

UseFileClass is used to override the default classes for the file element.

func UseInputClass

func UseInputClass(class string) FormHelperOption

UseInputClass is used to override the default classes for the input element.

func UseLabelClass

func UseLabelClass(class string) FormHelperOption

UseLabelClass is used to override the default classes for the label element.

func UseRadioClass

func UseRadioClass(class string) FormHelperOption

UseRadioClass is used to override the default classes for the radio element.

func UseSelectClass

func UseSelectClass(class string) FormHelperOption

UseSelectClass is used to override the default classes for the select element.

func UseTextAreaClass

func UseTextAreaClass(class string) FormHelperOption

UseTextAreaClass is used to override the default classes for the textarea element.

type Selectable

type Selectable interface {
	SelectValue() interface{}
	SelectLabel() string
}

Selectable allows any struct to become an option in the select tag.

type SelectableMultiple

type SelectableMultiple interface {
	IsSelected() bool
}

SelectableMultiple allows any struct to add Selected option in the select tag.

type SelectableMultiples

type SelectableMultiples []SelectableMultiple

SelectableMultiples is the plural for SelectableMultiple

type Selectables

type Selectables []Selectable

Selectables is the plural for selectable

Jump to

Keyboard shortcuts

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