From bec31e2c40e03679beff2506421e38416571b748 Mon Sep 17 00:00:00 2001 From: Aleph Retamal <7674479+alephao@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:19:06 -0300 Subject: [PATCH] feat: add button 'type' attribute (#43) * feat: add button type attribute * fix: extension to button tag attributes * remove ExpressibleByStringLiteral --- Sources/Elementary/HtmlAttributes.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sources/Elementary/HtmlAttributes.swift b/Sources/Elementary/HtmlAttributes.swift index 08e2551..51b7900 100644 --- a/Sources/Elementary/HtmlAttributes.swift +++ b/Sources/Elementary/HtmlAttributes.swift @@ -123,6 +123,26 @@ public extension HTMLAttribute where Tag == HTMLTag.link { } } +// button tag attributes +// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button +public extension HTMLAttribute where Tag == HTMLTag.button { + struct ButtonType: Sendable { + var value: String + + init(value: String) { + self.value = value + } + + public static let submit = ButtonType(value: "submit") + public static let reset = ButtonType(value: "reset") + public static let button = ButtonType(value: "button") + } + + static func type(_ value: ButtonType) -> Self { + HTMLAttribute(name: "type", value: value.value) + } +} + // href attribute public extension HTMLTrait.Attributes { protocol href {}