Package form

import "gitlab.com/zoralab/bissetii/pkg/internal/form"

Package form is for render the input form in multiple formats.

The HTML template codes are written in Go’s string format under the corresponding group. This allows one to embed the HTML codes instead of parsing it from file.

Constants

Constants for managing the package as a whole.

const (
	// Name is the block name (`{{- define "this-name" -}}`).
	Name = "form"

	// AMPName is the AMP HTML block name.
	AMPName = root.AMPPrefix + Name

	// ParametersComment are the list of comment headers
	// describing inputs.
	ParametersComment = `
{{- /* .Method            = Form method                             */ -}}
{{- /* .Action            = Form action                             */ -}}
{{- /* .Content           = Form content                            */ -}}
{{- /* .ID                = Form id attribute (optional)            */ -}}
{{- /* .Class             = Form class attribute (optional)         */ -}}
{{- /* .Label             = Form aria-label attribute (optional)    */ -}}
`
)

Dependencies are the dependent codes for building independent template.

This is useful for rendering portable template usage like Hugo partials where they do not share a common definition source.

const (
	// DepHTML is the vanilla HTML output type.
	DepHTML = ``

	// DepAMPHTML is the Accelerated Mobile Pages HTML output
	// type.
	DepAMPHTML = ``
)

Full HTML codes for rendering templates without needing to parse file.

const (
	// HTML is the vanilla HTML output type.
	HTML = `
<form method="{{- .Method -}}" action="{{- .Action -}}"
{{- if .ID }}

	id="{{- .ID -}}"
{{- end }}
{{- if .Class }}

	class="{{- .Class -}}"
{{- end }}
{{- if .Label }}

	aria-label="{{- .Label -}}"
{{- end -}}
>
{{- if .Content }}

	{{ .Content }}
{{- end }}
</form>
`

	// AMPHTML is the Accelerated Mobile Pages HTML output type.
	AMPHTML = `
<form method="{{- .Method -}}"
{{- if eq .Method "post" }}

	action-xhr="{{- .Action -}}"
{{- else }}

	action="{{- .Action -}}"
{{- end }}
{{- if .ID }}

	id="{{- .ID -}}"
{{- end }}
{{- if .Class }}

	class="{{- .Class -}}"
{{- end }}
{{- if .Label }}

	aria-label="{{- .Label -}}"
{{- end -}}
>

	{{ .Content }}
</form>
`
)

Data

type Data struct {
	Method  string
	Action  string
	Content string
	ID      string
	Class   string
	Label   string
}

Data is the data structure for rendering the component.