-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a237b97
commit 419de28
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# `attrs` Subpackage in `elem-go` | ||
|
||
The `attrs` subpackage within `elem-go` offers a comprehensive set of constants representing HTML attributes, enhancing the process of setting attributes for HTML elements in a type-safe manner. This document outlines the usage and features of the `attrs` subpackage. | ||
|
||
## Table of Contents | ||
|
||
- [Introduction](#introduction) | ||
- [Usage](#usage) | ||
- [Available HTML Attributes](#available-html-attributes) | ||
- [Using `Props` Type](#using-props-type) | ||
- [Examples](#examples) | ||
|
||
## Introduction | ||
|
||
The `attrs` subpackage is designed to simplify the process of defining HTML attributes in Go. By providing constants for common attributes, it helps avoid errors due to typos and enhances code readability. | ||
|
||
## Usage | ||
|
||
To use the `attrs` subpackage, import it alongside the main `elem` package: | ||
|
||
```go | ||
import ( | ||
"github.com/chasefleming/elem-go/attrs" | ||
) | ||
``` | ||
|
||
## Available HTML Attributes | ||
|
||
The subpackage includes a wide range of constants representing universal attributes, link/script attributes, meta attributes, image/embed attributes, semantic text attributes, form/input attributes, interactive attributes, miscellaneous attributes, table attributes, iframe attributes, audio/video attributes, and video-specific attributes. | ||
|
||
For instance, some of the constants are: | ||
|
||
- Universal Attributes like `Class`, `ID`, `Style` | ||
- Link/Script Attributes such as `Href`, `Src` | ||
- Form/Input Attributes including `Type`, `Value`, `Placeholder` | ||
|
||
For a full list of available constants, see the [attrs.go file](attrs.go). | ||
|
||
## Using `Props` Type | ||
|
||
The `Props` type is a map of strings that can be used to pass attribute values to HTML elements in a structured way. This type-safe approach ensures the correct assignment of attributes to elements. | ||
|
||
## Examples | ||
|
||
Here's an example of using `attrs` constants to set attributes for a button: | ||
|
||
```go | ||
buttonAttrs := attrs.Props{ | ||
attrs.Type: "button", | ||
attrs.Class: "btn btn-primary", | ||
attrs.ID: "submitBtn", | ||
} | ||
|
||
button := elem.Button(buttonAttrs, elem.Text("Submit")) | ||
``` | ||
|
||
In this example, attributes for the button element are defined using the attrs.Props map with attrs constants. |