From 419de288bbd0b5a6b107dec19ac2a02e44d1582a Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Sat, 11 Nov 2023 13:07:44 -0800 Subject: [PATCH] Add attrs readme --- attrs/README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 attrs/README.md diff --git a/attrs/README.md b/attrs/README.md new file mode 100644 index 0000000..c2ae491 --- /dev/null +++ b/attrs/README.md @@ -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. \ No newline at end of file