Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 80 additions & 6 deletions Sources/HTMLKitComponents/Components/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
import HTMLKit
import Foundation

/// A component that initiates an action.
/// A view that represents a button.
///
/// Use `Button` to trigger an action when tapped or clicked.
///
/// ```swift
/// Button(role: .button) {
/// "Lorem ipsum"
/// }
/// ```
public struct Button: View, Modifiable, Actionable {

/// The identifier of the button.
internal var id: String?

/// The role of the button
/// The role of the button.
internal var role: HTMLKit.Values.Button

/// The content of the button.
Expand All @@ -20,16 +29,33 @@ public struct Button: View, Modifiable, Actionable {
/// The classes of the button.
internal var classes: [String]

/// The events of the button.
internal var events: [String]?

/// Creates a action button.
/// Create a button.
///
/// - Parameters:
/// - role: The role of the button.
/// - content: The button's content.
public init(role: HTMLKit.Values.Button, @ContentBuilder<Content> content: () -> [Content]) {

self.role = role
self.content = content()
self.classes = ["button"]
}

/// Create a button.
///
/// - Parameters:
/// - localizedStringKey: The key of the localized string used as a label.
/// - role: The role of the button.
public init(_ localizedStringKey: LocalizedStringKey, role: HTMLKit.Values.Button) {

self.role = role
self.content = [LocalizedString(key: localizedStringKey)]
self.classes = ["button"]
}

public var body: Content {
HTMLKit.Button {
self.content
Expand Down Expand Up @@ -146,11 +172,21 @@ extension Button: ViewModifier {
}
}

/// A component that initiates an action.
/// A view that represents a link button.
///
/// Use `LinkButton`to navigate to a target.
///
/// ```swift
/// LinkButton(destination: "https://..") {
/// "Lorem ipsum"
/// }
/// ```
public struct LinkButton: View, Modifiable, Identifiable {

/// The unique identifier of the button.
internal var id: String?

/// The target behaviour for the destination
internal let target: HTMLKit.Values.Target

/// The url path of the target.
Expand All @@ -165,7 +201,12 @@ public struct LinkButton: View, Modifiable, Identifiable {
/// The events of the button.
internal var events: [String]?

/// Creates a action button.
/// Create a link button.
///
/// - Parameters:
/// - destination: The url of the target to navigate to.
/// - target: The behaviour that determines how to open the target.
/// - content: The content displayed as the label.
public init(destination: String, target: HTMLKit.Values.Target = .current, @ContentBuilder<Content> content: () -> [Content]) {

self.destination = destination
Expand All @@ -174,7 +215,26 @@ public struct LinkButton: View, Modifiable, Identifiable {
self.classes = ["button"]
}

/// Creates a action button.
/// Create a link button.
///
/// - Parameters:
/// - localizedStringKey: The key of the localized string used as the label.
/// - destination: The url of the target to navigate to.
/// - target: The behaviour that determines how to open the target.
public init(_ localizedStringKey: LocalizedStringKey, destination: String, target: HTMLKit.Values.Target = .current) {

self.destination = destination
self.target = target
self.content = [LocalizedString(key: localizedStringKey)]
self.classes = ["button"]
}

/// Create a link button.
///
/// - Parameters:
/// - destination: The url of the target to navigate to.
/// - target: The behaviour that determines how to open the target.
/// - content: The content displayed as the label.
public init(destination: URL, target: HTMLKit.Values.Target = .current, @ContentBuilder<Content> content: () -> [Content]) {

self.destination = destination.absoluteString
Expand All @@ -183,6 +243,20 @@ public struct LinkButton: View, Modifiable, Identifiable {
self.classes = ["button"]
}

/// Create a link button.
///
/// - Parameters:
/// - localizedStringKey: The key of the localized string used as the label.
/// - destination: The url of the target to navigate to.
/// - target: The behaviour that determines how to open the target.
public init(_ localizedStringKey: LocalizedStringKey, destination: URL, target: HTMLKit.Values.Target = .current) {

self.destination = destination.absoluteString
self.target = target
self.content = [LocalizedString(key: localizedStringKey)]
self.classes = ["button"]
}

public var body: Content {
Anchor {
self.content
Expand Down
37 changes: 33 additions & 4 deletions Sources/HTMLKitComponents/Components/Disclosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,53 @@

import HTMLKit

/// A component that distinguish content.
/// A view that represents a disclosure.
///
/// Use `Disclosure` to reveal or hide content when interacted with.
///
/// ```swift
/// Disclosure("Lorem ipsum") {
/// Text {
/// "Lorem ipsum..."
/// }
/// }
/// ```
public struct Disclosure: View, Modifiable {

internal let label: String
/// The label of the disclosure.
internal let label: Content

/// The disclosure's content.
internal let content: [Content]

/// The classes of the content.
internal var classes: [String]

/// Creates a card.

/// Create a disclosure.
///
/// - Parameters:
/// - label: The label to describe the content.
/// - content: The disclosure's content.
@_disfavoredOverload
public init(_ label: String, @ContentBuilder<Content> content: () -> [Content]) {

self.label = label
self.content = content()
self.classes = ["disclosure"]
}

/// Create a disclosure.
///
/// - Parameters:
/// - label: The key of the localized string to describe the content.
/// - content: The disclosure's content.
public init(_ label: LocalizedStringKey, @ContentBuilder<Content> content: () -> [Content]) {

self.label = LocalizedString(key: label)
self.content = content()
self.classes = ["disclosure"]
}

public var body: Content {
Division {
Division {
Expand Down
Loading