Skip to content

Commit

Permalink
added more attributes (form, label, name, selected, value) (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
sliemeobn authored Sep 13, 2024
1 parent 421ebcf commit 2af5cc4
Showing 1 changed file with 63 additions and 4 deletions.
67 changes: 63 additions & 4 deletions Sources/Elementary/HtmlAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,58 @@ public extension HTMLAttribute where Tag: HTMLTrait.Attributes.autocomplete {
}
}

// label attribute
public extension HTMLTrait.Attributes {
protocol label {}
}

extension HTMLTag.optgroup: HTMLTrait.Attributes.label {}
extension HTMLTag.option: HTMLTrait.Attributes.label {}

public extension HTMLAttribute where Tag: HTMLTrait.Attributes.label {
static func label(_ value: String) -> Self {
HTMLAttribute(name: "label", value: value)
}
}

// form attribute
public extension HTMLTrait.Attributes {
protocol form {}
}

extension HTMLTag.button: HTMLTrait.Attributes.form {}
extension HTMLTag.fieldset: HTMLTrait.Attributes.form {}
extension HTMLTag.input: HTMLTrait.Attributes.form {}
extension HTMLTag.label: HTMLTrait.Attributes.form {}
extension HTMLTag.option: HTMLTrait.Attributes.form {}
extension HTMLTag.select: HTMLTrait.Attributes.form {}
extension HTMLTag.textarea: HTMLTrait.Attributes.form {}

public extension HTMLAttribute where Tag: HTMLTrait.Attributes.form {
static func form(_ id: String) -> Self {
HTMLAttribute(name: "form", value: id)
}
}

// name attribute (for basic string case, meta has its own typed name attribute)
public extension HTMLTrait.Attributes {
protocol name {}
}

extension HTMLTag.button: HTMLTrait.Attributes.name {}
extension HTMLTag.fieldset: HTMLTrait.Attributes.name {}
extension HTMLTag.form: HTMLTrait.Attributes.name {}
extension HTMLTag.iframe: HTMLTrait.Attributes.name {}
extension HTMLTag.input: HTMLTrait.Attributes.name {}
extension HTMLTag.select: HTMLTrait.Attributes.name {}
extension HTMLTag.textarea: HTMLTrait.Attributes.name {}

public extension HTMLAttribute where Tag: HTMLTrait.Attributes.name {
static func name(_ value: String) -> Self {
HTMLAttribute(name: "name", value: value)
}
}

// form tag attributes
public extension HTMLAttribute where Tag == HTMLTag.form {
struct Method: Sendable, Equatable {
Expand Down Expand Up @@ -341,10 +393,6 @@ public extension HTMLAttribute where Tag == HTMLTag.input {
HTMLAttribute(name: "type", value: type.value)
}

static func name(_ name: String) -> Self {
HTMLAttribute(name: "name", value: name)
}

static func value(_ value: String) -> Self {
HTMLAttribute(name: "value", value: value)
}
Expand All @@ -360,3 +408,14 @@ public extension HTMLAttribute where Tag == HTMLTag.label {
HTMLAttribute(name: "for", value: id)
}
}

// option tag attributes
public extension HTMLAttribute where Tag == HTMLTag.option {
static func value(_ value: String) -> Self {
HTMLAttribute(name: "value", value: value)
}

static var selected: Self {
HTMLAttribute(name: "selected", value: nil)
}
}

0 comments on commit 2af5cc4

Please sign in to comment.