Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when initializing VStack with only braces. #197

Merged
merged 2 commits into from
Jan 3, 2025
Merged
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
34 changes: 20 additions & 14 deletions Sources/Ignite/Elements/VStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,32 @@ public struct VStack: BlockHTML {
/// The child elements contained in the stack.
private var items: [any HTML]

/// Creates a new vertical stack with the specified spacing and content.
/// Creates a new `Section` object using a block element builder
/// that returns an array of items to use in this section.
/// - Parameter items: The items to use in this section.
public init(@HTMLBuilder items: () -> some HTML) {
self.items = flatUnwrap(items())
self.customSpacing = nil
self.systemSpacing = nil
}

/// Creates a new `Section` object using a block element builder
/// that returns an array of items to use in this section.
/// - Parameters:
/// - spacing: The number of pixels between each element. Default is `2`.
/// - items: A closure that returns the elements to be arranged vertically.
public init(spacing: Int = 2, @HTMLBuilder _ items: () -> some HTML) {
/// - spacing: The number of pixels between elements.
/// - items: The items to use in this section.
public init(spacing pixels: Int, @HTMLBuilder items: () -> some HTML) {
self.items = flatUnwrap(items())
self.customSpacing = spacing
self.customSpacing = pixels
self.systemSpacing = nil
}

/// Creates a new vertical stack with the specified spacing and content.
/// Creates a new `Section` object using a block element builder
/// that returns an array of items to use in this section.
/// - Parameters:
/// - spacing: The predefined size between each element. Default is `.small`.
/// - items: A closure that returns the elements to be arranged vertically.
public init(spacing: SpacingAmount = .small, @HTMLBuilder _ items: () -> some HTML) {
/// - spacing: The predefined size between elements.
/// - items: The items to use in this section.
public init(spacing: SpacingAmount, @HTMLBuilder items: () -> some HTML) {
self.items = flatUnwrap(items())
self.systemSpacing = spacing
self.customSpacing = nil
Expand All @@ -69,11 +80,6 @@ public struct VStack: BlockHTML {
var attributes = attributes
attributes.append(classes: "vstack")

attributes.append(styles:
.init(name: "display", value: "flex"),
.init(name: "width", value: "100%")
)

if let customSpacing {
attributes.append(styles: .init(name: .gap, value: "\(customSpacing)px"))
} else if let systemSpacing {
Expand Down