From 3c0fb7f4d12ea8de6aadf12e4a24f7c19e903be9 Mon Sep 17 00:00:00 2001 From: Mattes Mohr Date: Fri, 28 Nov 2025 13:30:33 +0100 Subject: [PATCH 1/2] Tidy up a bit --- .../Actions/SubmitAction.swift | 10 +++--- .../Actions/ViewAction.swift | 30 ++++++++-------- .../HTMLKitComponents/Components/Alert.swift | 4 +-- .../Components/BarMark.swift | 6 ++-- .../HTMLKitComponents/Components/Button.swift | 6 ++-- .../HTMLKitComponents/Components/Card.swift | 7 ++-- .../Components/Carousel.swift | 2 +- .../HTMLKitComponents/Components/Chart.swift | 2 +- .../Components/CheckField.swift | 4 +-- .../Components/DatePicker.swift | 12 +++---- .../Components/Disclosure.swift | 2 +- .../Components/Divider.swift | 2 +- .../Components/Dropdown.swift | 6 ++-- .../Components/FieldLabel.swift | 2 +- .../Components/FileDialog.swift | 2 +- .../HTMLKitComponents/Components/Form.swift | 6 ++-- .../HTMLKitComponents/Components/Grid.swift | 4 +-- .../Components/Grouping.swift | 16 ++++----- .../HTMLKitComponents/Components/HStack.swift | 8 ++--- .../HTMLKitComponents/Components/Image.swift | 14 ++++---- .../HTMLKitComponents/Components/Link.swift | 8 ++--- .../Components/LinkButton.swift | 4 +-- .../HTMLKitComponents/Components/List.swift | 12 +++---- .../HTMLKitComponents/Components/Modal.swift | 4 +-- .../Components/Navigation.swift | 8 ++--- .../HTMLKitComponents/Components/Pane.swift | 16 ++++----- .../Components/Progress.swift | 6 ++-- .../Components/RadioSelect.swift | 2 +- .../HTMLKitComponents/Components/Scroll.swift | 2 +- .../Components/SearchField.swift | 2 +- .../Components/SectorMark.swift | 6 ++-- .../Components/SecureField.swift | 2 +- .../Components/SelectField.swift | 4 +-- .../HTMLKitComponents/Components/Slide.swift | 8 ++--- .../HTMLKitComponents/Components/Slider.swift | 2 +- .../Components/Snippet.swift | 4 +-- .../HTMLKitComponents/Components/Symbol.swift | 16 ++++----- .../HTMLKitComponents/Components/Tabs.swift | 4 +-- .../HTMLKitComponents/Components/Text.swift | 8 ++--- .../Components/TextEditor.swift | 10 +++--- .../Components/TextField.swift | 2 +- .../Components/TextPad.swift | 36 +++++++++---------- .../HTMLKitComponents/Components/VStack.swift | 8 ++--- .../HTMLKitComponents/Components/Video.swift | 2 +- .../HTMLKitComponents/Components/ZStack.swift | 10 +++--- .../Extensions/Components+Image.swift | 4 +-- .../Modifiers/ButtonModifier.swift | 6 ++-- .../Modifiers/GraphicsModifier.swift | 12 +++---- .../Modifiers/ImageModifier.swift | 14 +++----- .../Modifiers/InputModifier.swift | 4 +-- .../Modifiers/TextModifier.swift | 22 ++++++------ .../Modifiers/ViewModifier.swift | 16 ++++----- .../Primitives/DynamicType.swift | 14 ++------ .../Primitives/PromptType.swift | 11 ++++++ .../Properties/Actionable.swift | 20 +++++------ .../Properties/Identifiable.swift | 6 ++-- .../Properties/Modifiable.swift | 16 ++++----- .../Properties/Selectable.swift | 12 +++---- .../ComponentTests.swift | 1 - 59 files changed, 240 insertions(+), 249 deletions(-) create mode 100644 Sources/HTMLKitComponents/Primitives/PromptType.swift diff --git a/Sources/HTMLKitComponents/Actions/SubmitAction.swift b/Sources/HTMLKitComponents/Actions/SubmitAction.swift index 96ee6128..b96c25b3 100644 --- a/Sources/HTMLKitComponents/Actions/SubmitAction.swift +++ b/Sources/HTMLKitComponents/Actions/SubmitAction.swift @@ -4,19 +4,19 @@ public struct SubmitAction: Action { public func validate(_ target: String, _ validators: [Validator]) -> SubmitAction { - var newSelf = self + var copy = self if !validators.isEmpty { let result = validators.map { "{\"field\":\"\($0.field)\",\"rule\":\"\($0.rule)\"}" } - newSelf.actions.append("$('#\(target.escape())').validate('[\(result.joined(separator: ","))]');") + copy.actions.append("$('#\(target.escape())').validate('[\(result.joined(separator: ","))]');") - return newSelf + return copy } - newSelf.actions.append("$('#\(target.escape())').validate('[]');") + copy.actions.append("$('#\(target.escape())').validate('[]');") - return newSelf + return copy } } diff --git a/Sources/HTMLKitComponents/Actions/ViewAction.swift b/Sources/HTMLKitComponents/Actions/ViewAction.swift index 1fe0c661..c87f87ad 100644 --- a/Sources/HTMLKitComponents/Actions/ViewAction.swift +++ b/Sources/HTMLKitComponents/Actions/ViewAction.swift @@ -9,10 +9,10 @@ public struct ViewAction: Action { /// - Returns: The action public func show(_ target: String) -> ViewAction { - var newSelf = self - newSelf.actions.append("$('#\(target.escape())').show();") + var copy = self + copy.actions.append("$('#\(target.escape())').show();") - return newSelf + return copy } /// Hide a target based on a event. @@ -22,10 +22,10 @@ public struct ViewAction: Action { /// - Returns: The action public func hide(_ target: String) -> ViewAction { - var newSelf = self - newSelf.actions.append("$('#\(target.escape())').hide();") + var copy = self + copy.actions.append("$('#\(target.escape())').hide();") - return newSelf + return copy } /// Play an animation based on a event. @@ -35,10 +35,10 @@ public struct ViewAction: Action { /// - Returns: The action public func animate(_ target: String) -> ViewAction { - var newSelf = self - newSelf.actions.append("$('#\(target.escape())').animate();") + var copy = self + copy.actions.append("$('#\(target.escape())').animate();") - return newSelf + return copy } /// Open a target based on a event. @@ -48,10 +48,10 @@ public struct ViewAction: Action { /// - Returns: The action public func open(_ target: String) -> ViewAction { - var newSelf = self - newSelf.actions.append("$('#\(target.escape())').open();") + var copy = self + copy.actions.append("$('#\(target.escape())').open();") - return newSelf + return copy } /// Close a target based on a event. @@ -61,9 +61,9 @@ public struct ViewAction: Action { /// - Returns: The action public func close(_ target: String) -> ViewAction { - var newSelf = self - newSelf.actions.append("$('#\(target.escape())').close();") + var copy = self + copy.actions.append("$('#\(target.escape())').close();") - return newSelf + return copy } } diff --git a/Sources/HTMLKitComponents/Components/Alert.swift b/Sources/HTMLKitComponents/Components/Alert.swift index f0588209..615115c5 100644 --- a/Sources/HTMLKitComponents/Components/Alert.swift +++ b/Sources/HTMLKitComponents/Components/Alert.swift @@ -15,7 +15,7 @@ public struct Alert: View, Identifiable, Modifiable { internal var id: String? /// The body content of the alert - internal var content: [Content] + internal let content: [Content] /// The class names for the alert. internal var classes: [String] @@ -89,7 +89,7 @@ extension Alert: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight?, alignment: Tokens.FrameAlignment?) -> Alert { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet, length: Tokens.MarginLength) -> Alert { diff --git a/Sources/HTMLKitComponents/Components/BarMark.swift b/Sources/HTMLKitComponents/Components/BarMark.swift index 3132252e..29595136 100644 --- a/Sources/HTMLKitComponents/Components/BarMark.swift +++ b/Sources/HTMLKitComponents/Components/BarMark.swift @@ -15,10 +15,10 @@ import HTMLKit public struct BarMark: View, Modifiable { /// The value of the mark. - internal var value: Int + internal let value: Int /// The title of the mark. - internal var label: String + internal let label: String /// The class names of the bar mark. internal var classes: [String] @@ -54,6 +54,6 @@ public struct BarMark: View, Modifiable { /// /// - Returns: The mark public func foregroundColor(_ color: Tokens.ForegroundColor) -> BarMark { - return self.mutate(class: "foreground:\(color.value)") + return self.mutate(classes: "foreground:\(color.value)") } } diff --git a/Sources/HTMLKitComponents/Components/Button.swift b/Sources/HTMLKitComponents/Components/Button.swift index e65290ef..b954a186 100644 --- a/Sources/HTMLKitComponents/Components/Button.swift +++ b/Sources/HTMLKitComponents/Components/Button.swift @@ -16,10 +16,10 @@ public struct Button: View, Modifiable, Actionable { internal var id: String? /// The role of the button. - internal var role: HTMLKit.Values.Button + internal let role: HTMLKit.Values.Button /// The body content of the button. - internal var content: [Content] + internal let content: [Content] /// The class names for the button. internal var classes: [String] @@ -156,7 +156,7 @@ extension Button: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Button { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet, length: Tokens.MarginLength = .small) -> Button { diff --git a/Sources/HTMLKitComponents/Components/Card.swift b/Sources/HTMLKitComponents/Components/Card.swift index fea0e07d..172c4209 100644 --- a/Sources/HTMLKitComponents/Components/Card.swift +++ b/Sources/HTMLKitComponents/Components/Card.swift @@ -19,10 +19,10 @@ public struct Card: View, Modifiable, Identifiable { internal var id: String? /// The header content of the card. - internal var header: [Content]? + internal let header: [Content]? /// The body content of the card. - internal var content: [Content] + internal let content: [Content] /// The class names for the card. internal var classes: [String] @@ -32,6 +32,7 @@ public struct Card: View, Modifiable, Identifiable { /// - Parameter content: The card's content public init(@ContentBuilder content: () -> [Content]) { + self.header = nil self.content = content() self.classes = ["card"] } @@ -125,7 +126,7 @@ extension Card: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Card { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Card { diff --git a/Sources/HTMLKitComponents/Components/Carousel.swift b/Sources/HTMLKitComponents/Components/Carousel.swift index ec918d47..2ac1a914 100644 --- a/Sources/HTMLKitComponents/Components/Carousel.swift +++ b/Sources/HTMLKitComponents/Components/Carousel.swift @@ -115,7 +115,7 @@ extension Carousel: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Carousel { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Carousel { diff --git a/Sources/HTMLKitComponents/Components/Chart.swift b/Sources/HTMLKitComponents/Components/Chart.swift index 0e3a6550..fe137f1c 100644 --- a/Sources/HTMLKitComponents/Components/Chart.swift +++ b/Sources/HTMLKitComponents/Components/Chart.swift @@ -43,6 +43,6 @@ public struct Chart: View, Modifiable { /// /// - Returns: The chart public func innerRadius(_ color: Tokens.InnerRadius) -> Chart { - return self.mutate(class: "radius:\(color.value)") + return self.mutate(classes: "radius:\(color.value)") } } diff --git a/Sources/HTMLKitComponents/Components/CheckField.swift b/Sources/HTMLKitComponents/Components/CheckField.swift index 0c45b5cc..207d51f4 100644 --- a/Sources/HTMLKitComponents/Components/CheckField.swift +++ b/Sources/HTMLKitComponents/Components/CheckField.swift @@ -27,7 +27,7 @@ public struct CheckField: View, Modifiable, Selectable, Identifiable { internal var isSelected: Bool /// The body content of the field. - internal var content: Content + internal let content: Content /// The class names for the field. internal var classes: [String] @@ -147,7 +147,7 @@ extension CheckField: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> CheckField { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> CheckField { diff --git a/Sources/HTMLKitComponents/Components/DatePicker.swift b/Sources/HTMLKitComponents/Components/DatePicker.swift index 592e2c32..751b2bff 100644 --- a/Sources/HTMLKitComponents/Components/DatePicker.swift +++ b/Sources/HTMLKitComponents/Components/DatePicker.swift @@ -2,7 +2,7 @@ import HTMLKit /// A view that represents a date picker. /// -/// Use `DatePicker` to pick a date from a calendar +/// Use `DatePicker` to pick a date from a calendar. /// /// ```swift /// DatePicker(name: "lorem") @@ -63,7 +63,7 @@ public struct DatePicker: View, Modifiable, Identifiable { } .points("10 2 4 8 10 14") } - .viewBox("0 0 16 16") + .viewBox(x: 0, y: 0, width: 16, height: 16) .namespace("http://www.w3.org/2000/svg") .fill("currentColor") .strokeWidth(2) @@ -71,7 +71,7 @@ public struct DatePicker: View, Modifiable, Identifiable { .strokeLineJoin(.round) } .type(.button) - .value("previous") + .value(verbatim: "previous") } ListItem { Bold { @@ -85,7 +85,7 @@ public struct DatePicker: View, Modifiable, Identifiable { } .points("6 2 12 8 6 14") } - .viewBox("0 0 16 16") + .viewBox(x: 0, y: 0, width: 16, height: 16) .namespace("http://www.w3.org/2000/svg") .fill("currentColor") .strokeWidth(2) @@ -93,7 +93,7 @@ public struct DatePicker: View, Modifiable, Identifiable { .strokeLineJoin(.round) } .type(.button) - .value("next") + .value(verbatim: "next") } } .class("calendar-navigation") @@ -185,7 +185,7 @@ extension DatePicker: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> DatePicker { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> DatePicker { diff --git a/Sources/HTMLKitComponents/Components/Disclosure.swift b/Sources/HTMLKitComponents/Components/Disclosure.swift index 5e8d9380..998d4bc0 100644 --- a/Sources/HTMLKitComponents/Components/Disclosure.swift +++ b/Sources/HTMLKitComponents/Components/Disclosure.swift @@ -62,7 +62,7 @@ public struct Disclosure: View, Modifiable { } .draw("M7.28,2.241C6.987,1.957 6.987,1.497 7.28,1.213C7.573,0.929 8.048,0.929 8.341,1.213L14.811,7.486C15.103,7.77 15.103,8.23 14.811,8.514L8.28,14.787C7.987,15.071 7.512,15.071 7.22,14.787C6.927,14.503 6.927,14.043 7.22,13.759L13.22,8L7.28,2.241Z") } - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) .namespace("http://www.w3.org/2000/svg") .class("state-indicator") } diff --git a/Sources/HTMLKitComponents/Components/Divider.swift b/Sources/HTMLKitComponents/Components/Divider.swift index 7ba1d6e5..75afcfc7 100644 --- a/Sources/HTMLKitComponents/Components/Divider.swift +++ b/Sources/HTMLKitComponents/Components/Divider.swift @@ -10,7 +10,7 @@ import HTMLKit public struct Divider: View { /// The class names for the divider. - internal var classes: [String] + internal var classes: [String] /// Create a divider. public init() { diff --git a/Sources/HTMLKitComponents/Components/Dropdown.swift b/Sources/HTMLKitComponents/Components/Dropdown.swift index 1c62d680..8f56e543 100644 --- a/Sources/HTMLKitComponents/Components/Dropdown.swift +++ b/Sources/HTMLKitComponents/Components/Dropdown.swift @@ -24,10 +24,10 @@ public struct Dropdown: View, Modifiable, Identifiable { internal var id: String? /// The label content for the dropdown. - internal var label: [Content] + internal let label: [Content] /// The body content of the dropdown. - internal var content: [Content] + internal let content: [Content] /// The class names for the dropdown. internal var classes: [String] @@ -111,7 +111,7 @@ extension Dropdown: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Dropdown { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Dropdown { diff --git a/Sources/HTMLKitComponents/Components/FieldLabel.swift b/Sources/HTMLKitComponents/Components/FieldLabel.swift index 83b011ab..39862879 100644 --- a/Sources/HTMLKitComponents/Components/FieldLabel.swift +++ b/Sources/HTMLKitComponents/Components/FieldLabel.swift @@ -15,7 +15,7 @@ public struct FieldLabel: View { internal let id: String /// The body content of the label. - internal var content: [Content] + internal let content: [Content] /// The class names for the label. internal var classes: [String] diff --git a/Sources/HTMLKitComponents/Components/FileDialog.swift b/Sources/HTMLKitComponents/Components/FileDialog.swift index 18048647..c2d2d945 100644 --- a/Sources/HTMLKitComponents/Components/FileDialog.swift +++ b/Sources/HTMLKitComponents/Components/FileDialog.swift @@ -106,7 +106,7 @@ extension FileDialog: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> FileDialog { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> FileDialog { diff --git a/Sources/HTMLKitComponents/Components/Form.swift b/Sources/HTMLKitComponents/Components/Form.swift index 774304fd..daf25046 100644 --- a/Sources/HTMLKitComponents/Components/Form.swift +++ b/Sources/HTMLKitComponents/Components/Form.swift @@ -21,13 +21,13 @@ public struct Form: View, Actionable { internal var id: String? /// The form method of the submission. - internal var method: HTMLKit.Values.Method + internal let method: HTMLKit.Values.Method /// The encoding strategy for the submission. - internal var encoding: HTMLKit.Values.Encoding + internal let encoding: HTMLKit.Values.Encoding /// The body content of the form. - internal var content: [FormElement] + internal let content: [FormElement] /// The class names for the form. internal var classes: [String] diff --git a/Sources/HTMLKitComponents/Components/Grid.swift b/Sources/HTMLKitComponents/Components/Grid.swift index 53176076..6ee13b06 100644 --- a/Sources/HTMLKitComponents/Components/Grid.swift +++ b/Sources/HTMLKitComponents/Components/Grid.swift @@ -28,7 +28,7 @@ public struct Grid: View, Modifiable, Actionable { internal var id: String? /// The body content of the grid. - internal var content: [Content] + internal let content: [Content] /// The class names for the grid. internal var classes: [String] @@ -150,7 +150,7 @@ extension Grid: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Grid { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Grid { diff --git a/Sources/HTMLKitComponents/Components/Grouping.swift b/Sources/HTMLKitComponents/Components/Grouping.swift index 8d4a9cde..485ee89e 100644 --- a/Sources/HTMLKitComponents/Components/Grouping.swift +++ b/Sources/HTMLKitComponents/Components/Grouping.swift @@ -20,7 +20,7 @@ public struct Grouping: View, Modifiable, Identifiable { internal var id: String? /// The body content of the grouping. - internal var content: [Content] + internal let content: [Content] /// The class names for the grouping. internal var classes: [String] @@ -54,19 +54,19 @@ public struct Grouping: View, Modifiable, Identifiable { /// - Returns: The grouping public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Grouping { - var newSelf = self + var copy = self if let height { - newSelf.classes.append("height:\(height.value)") + copy.classes.append("height:\(height.value)") } if let alignment { - newSelf.classes.append("frame-alignment:\(alignment.value)") + copy.classes.append("frame-alignment:\(alignment.value)") } - newSelf.classes.append("width:\(width.value)") + copy.classes.append("width:\(width.value)") - return newSelf + return copy } /// Set the identifier for the grouping. @@ -82,7 +82,7 @@ public struct Grouping: View, Modifiable, Identifiable { extension Grouping: TextModifier { public func font(_ family: Tokens.FontFamily) -> Grouping { - return mutate(fontfamily: family.value) + return self.mutate(fontfamily: family.value) } public func textStyle(_ style: Tokens.TextStyle) -> Grouping { @@ -162,6 +162,6 @@ extension Grouping: TextModifier { } public func shadow(_ radius: Tokens.BlurRadius, color: Tokens.ShadowColor = .black) -> Grouping { - return mutate(shadow: radius.value, color: color.value) + return self.mutate(shadow: radius.value, color: color.value) } } diff --git a/Sources/HTMLKitComponents/Components/HStack.swift b/Sources/HTMLKitComponents/Components/HStack.swift index 45990c47..ef6b78ad 100644 --- a/Sources/HTMLKitComponents/Components/HStack.swift +++ b/Sources/HTMLKitComponents/Components/HStack.swift @@ -18,7 +18,7 @@ public struct HStack: View, Actionable, Modifiable { internal var id: String? /// The body content of the stack. - internal var content: [Content] + internal let content: [Content] /// The class names for the stack. internal var classes: [String] @@ -76,14 +76,14 @@ public struct HStack: View, Actionable, Modifiable { /// /// - Returns: The stack public func shadow(_ radius: Tokens.BlurRadius = .small, color: Tokens.ShadowColor = .black) -> HStack { - return self.mutate(classes: ["shadow:\(radius.value)", "shadow:\(color.value)"]) + return self.mutate(classes: "shadow:\(radius.value)", "shadow:\(color.value)") } /// Clip the content for the stack. /// /// - Returns: The stack public func clipped() -> HStack { - return self.mutate(class: "overflow:clip") + return self.mutate(classes: "overflow:clip") } } @@ -138,7 +138,7 @@ extension HStack: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> HStack { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> HStack { diff --git a/Sources/HTMLKitComponents/Components/Image.swift b/Sources/HTMLKitComponents/Components/Image.swift index 262b0a78..49ebe4ef 100644 --- a/Sources/HTMLKitComponents/Components/Image.swift +++ b/Sources/HTMLKitComponents/Components/Image.swift @@ -128,7 +128,7 @@ extension Image: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Image { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Image { @@ -139,26 +139,26 @@ extension Image: ViewModifier { extension Image: GraphicsModifier { public func blur(_ level: Tokens.BlurLevel) -> Image { - return mutate(blur: level.value) + return self.mutate(blur: level.value) } public func grayscale(_ depth: Tokens.GrayscaleDepth) -> Image { - return mutate(grayscale: depth.value) + return self.mutate(grayscale: depth.value) } public func brightness(_ level: Tokens.BrightnessLevel) -> Image { - return mutate(brightness: level.value) + return self.mutate(brightness: level.value) } public func saturation(_ level: Tokens.SaturationLevel) -> Image { - return mutate(saturation: level.value) + return self.mutate(saturation: level.value) } public func contrast(_ level: Tokens.ContrastLevel) -> Image { - return mutate(contrast: level.value) + return self.mutate(contrast: level.value) } public func shadow(_ radius: Tokens.BlurRadius = .small, color: Tokens.ShadowColor = .black) -> Image { - return mutate(shadow: radius.value, color: color.value) + return self.mutate(shadow: radius.value, color: color.value) } } diff --git a/Sources/HTMLKitComponents/Components/Link.swift b/Sources/HTMLKitComponents/Components/Link.swift index 4f576be2..8322a80d 100644 --- a/Sources/HTMLKitComponents/Components/Link.swift +++ b/Sources/HTMLKitComponents/Components/Link.swift @@ -24,7 +24,7 @@ public struct Link: View, Modifiable, Identifiable { internal let destination: String /// The body content of the link. - internal var content: [Content] + internal let content: [Content] /// The class names for the link. internal var classes: [String] @@ -85,7 +85,7 @@ public struct Link: View, Modifiable, Identifiable { extension Link: TextModifier { public func font(_ family: Tokens.FontFamily) -> Link { - return mutate(fontfamily: family.value) + return self.mutate(fontfamily: family.value) } public func textStyle(_ style: Tokens.TextStyle) -> Link { @@ -165,7 +165,7 @@ extension Link: TextModifier { } public func shadow(_ radius: Tokens.BlurRadius, color: Tokens.ShadowColor = .black) -> Link { - return mutate(shadow: radius.value, color: color.value) + return self.mutate(shadow: radius.value, color: color.value) } } @@ -209,7 +209,7 @@ extension Link: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Link { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Link { diff --git a/Sources/HTMLKitComponents/Components/LinkButton.swift b/Sources/HTMLKitComponents/Components/LinkButton.swift index b0a7593d..6b776707 100644 --- a/Sources/HTMLKitComponents/Components/LinkButton.swift +++ b/Sources/HTMLKitComponents/Components/LinkButton.swift @@ -22,7 +22,7 @@ public struct LinkButton: View, Modifiable, Identifiable { internal let destination: String /// The body content of the button. - internal var content: [Content] + internal let content: [Content] /// The class names for the button. internal var classes: [String] @@ -168,7 +168,7 @@ extension LinkButton: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> LinkButton { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> LinkButton { diff --git a/Sources/HTMLKitComponents/Components/List.swift b/Sources/HTMLKitComponents/Components/List.swift index 4bcdf010..777a14f4 100644 --- a/Sources/HTMLKitComponents/Components/List.swift +++ b/Sources/HTMLKitComponents/Components/List.swift @@ -20,7 +20,7 @@ public struct List: View, Modifiable, Actionable { internal var id: String? /// The body content of the list. - internal var content: [ListElement] + internal let content: [ListElement] /// The class names for the list. internal var classes: [String] @@ -65,11 +65,7 @@ public struct List: View, Modifiable, Actionable { /// /// - Returns: The list public func listStyle(_ style: Tokens.ListStyle) -> List { - - var newSelf = self - newSelf.classes.append("style:\(style.value)") - - return newSelf + return self.mutate(classes: "style:\(style.value)") } /// Set the style for the list. @@ -87,7 +83,7 @@ public struct List: View, Modifiable, Actionable { /// /// - Returns: The list public func listSpacing(_ size: Tokens.ListSpace) -> List { - return mutate(class: "spacing:\(size.value)") + return self.mutate(classes: "spacing:\(size.value)") } /// Set the identifier for the list. @@ -151,7 +147,7 @@ extension List: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> List { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> List { diff --git a/Sources/HTMLKitComponents/Components/Modal.swift b/Sources/HTMLKitComponents/Components/Modal.swift index ed3124c4..d148662e 100644 --- a/Sources/HTMLKitComponents/Components/Modal.swift +++ b/Sources/HTMLKitComponents/Components/Modal.swift @@ -19,7 +19,7 @@ public struct Modal: View, Modifiable, Actionable { internal var id: String? /// The body content of the modal. - internal var content: [Content] + internal let content: [Content] /// The class names for the modal. internal var classes: [String] @@ -110,7 +110,7 @@ extension Modal: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Modal { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Modal { diff --git a/Sources/HTMLKitComponents/Components/Navigation.swift b/Sources/HTMLKitComponents/Components/Navigation.swift index d24806fa..d642ddba 100644 --- a/Sources/HTMLKitComponents/Components/Navigation.swift +++ b/Sources/HTMLKitComponents/Components/Navigation.swift @@ -52,10 +52,10 @@ public struct Navigation: View, Modifiable, Identifiable { /// - Returns: The navigation public func navigationStyle(_ style: Tokens.NavigationStyle) -> Navigation { - var newSelf = self - newSelf.classes.append("style:\(style.value)") + var copy = self + copy.classes.append("style:\(style.value)") - return newSelf + return copy } /// Set the style for the navigation. @@ -117,7 +117,7 @@ extension Navigation: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Navigation { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Navigation { diff --git a/Sources/HTMLKitComponents/Components/Pane.swift b/Sources/HTMLKitComponents/Components/Pane.swift index 1974019a..2b90b547 100644 --- a/Sources/HTMLKitComponents/Components/Pane.swift +++ b/Sources/HTMLKitComponents/Components/Pane.swift @@ -24,13 +24,13 @@ public struct Pane: View, Modifiable { internal var id: String? /// The body content of the pane. - internal var content: [Content] + internal let content: [Content] /// The class names for the pane. internal var classes: [String] /// The label content of the pane. - internal var label: [Content] + internal let label: [Content] /// A badge indicator for the pane. internal var badge: Int? @@ -64,10 +64,10 @@ public struct Pane: View, Modifiable { /// - Returns: The pane public func tag(_ value: String) -> Pane { - var newSelf = self - newSelf.id = value + var copy = self + copy.id = value - return newSelf + return copy } /// Show a badge within the pane's tab. @@ -77,9 +77,9 @@ public struct Pane: View, Modifiable { /// - Returns: The pane public func badge(_ value: Int) -> Pane { - var newSelf = self - newSelf.badge = value + var copy = self + copy.badge = value - return newSelf + return copy } } diff --git a/Sources/HTMLKitComponents/Components/Progress.swift b/Sources/HTMLKitComponents/Components/Progress.swift index 7910cd6c..60e1d178 100644 --- a/Sources/HTMLKitComponents/Components/Progress.swift +++ b/Sources/HTMLKitComponents/Components/Progress.swift @@ -20,7 +20,7 @@ public struct Progress: View, Modifiable, Identifiable { internal let value: String /// The body content of the progress. - internal var content: [Content] + internal let content: [Content] /// The class names for the progress. internal var classes: [String] @@ -75,7 +75,7 @@ public struct Progress: View, Modifiable, Identifiable { /// /// - Returns: The progress public func progressStyle(_ style: Tokens.ProgressStyle) -> Progress { - return self.mutate(class: "style:\(style.value)") + return self.mutate(classes: "style:\(style.value)") } /// Set a tint color for the progress. @@ -84,6 +84,6 @@ public struct Progress: View, Modifiable, Identifiable { /// /// - Returns: The progress public func tint(_ color: Tokens.TintColor) -> Progress { - return self.mutate(class: "tint:\(color.value)") + return self.mutate(classes: "tint:\(color.value)") } } diff --git a/Sources/HTMLKitComponents/Components/RadioSelect.swift b/Sources/HTMLKitComponents/Components/RadioSelect.swift index 170dc56d..9fa576af 100644 --- a/Sources/HTMLKitComponents/Components/RadioSelect.swift +++ b/Sources/HTMLKitComponents/Components/RadioSelect.swift @@ -147,7 +147,7 @@ extension RadioSelect: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> RadioSelect { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> RadioSelect { diff --git a/Sources/HTMLKitComponents/Components/Scroll.swift b/Sources/HTMLKitComponents/Components/Scroll.swift index dc9b8668..30b9894a 100644 --- a/Sources/HTMLKitComponents/Components/Scroll.swift +++ b/Sources/HTMLKitComponents/Components/Scroll.swift @@ -27,7 +27,7 @@ import HTMLKit public struct Scroll: View { /// The body content of the scroll. - internal var content: [Content] + internal let content: [Content] /// The class names for the scroll. internal var classes: [String] diff --git a/Sources/HTMLKitComponents/Components/SearchField.swift b/Sources/HTMLKitComponents/Components/SearchField.swift index 24ac4879..156a1998 100644 --- a/Sources/HTMLKitComponents/Components/SearchField.swift +++ b/Sources/HTMLKitComponents/Components/SearchField.swift @@ -138,7 +138,7 @@ extension SearchField: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> SearchField { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> SearchField { diff --git a/Sources/HTMLKitComponents/Components/SectorMark.swift b/Sources/HTMLKitComponents/Components/SectorMark.swift index c9e935db..243f4b9a 100644 --- a/Sources/HTMLKitComponents/Components/SectorMark.swift +++ b/Sources/HTMLKitComponents/Components/SectorMark.swift @@ -15,10 +15,10 @@ import HTMLKit public struct SectorMark: View, Modifiable { /// The value of the mark. - internal var value: Int + internal let value: Int /// The title of the mark. - internal var label: String + internal let label: String /// The class names of the sector mark. internal var classes: [String] @@ -50,6 +50,6 @@ public struct SectorMark: View, Modifiable { /// /// - Returns: The mark public func foregroundColor(_ color: Tokens.ForegroundColor) -> SectorMark { - return self.mutate(class: "foreground:\(color.value)") + return self.mutate(classes: "foreground:\(color.value)") } } diff --git a/Sources/HTMLKitComponents/Components/SecureField.swift b/Sources/HTMLKitComponents/Components/SecureField.swift index 83d01069..dee53814 100644 --- a/Sources/HTMLKitComponents/Components/SecureField.swift +++ b/Sources/HTMLKitComponents/Components/SecureField.swift @@ -138,7 +138,7 @@ extension SecureField: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> SecureField { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> SecureField { diff --git a/Sources/HTMLKitComponents/Components/SelectField.swift b/Sources/HTMLKitComponents/Components/SelectField.swift index 048eed74..2cc348e8 100644 --- a/Sources/HTMLKitComponents/Components/SelectField.swift +++ b/Sources/HTMLKitComponents/Components/SelectField.swift @@ -27,7 +27,7 @@ public struct SelectField: View, Modifiable, Identifiable { internal let selection: String? /// The body content of the field. - internal var content: [Selectable] + internal let content: [Selectable] /// The class names for the field. internal var classes: [String] @@ -189,7 +189,7 @@ extension SelectField: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> SelectField { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> SelectField { diff --git a/Sources/HTMLKitComponents/Components/Slide.swift b/Sources/HTMLKitComponents/Components/Slide.swift index 28ac3ff5..f4a7abe2 100644 --- a/Sources/HTMLKitComponents/Components/Slide.swift +++ b/Sources/HTMLKitComponents/Components/Slide.swift @@ -17,12 +17,12 @@ public struct Slide: View, Identifiable, Modifiable { /// The unique identifier of the slide. internal var id: String? + /// The class names for the slide. + internal let content: [Content] + /// The body content of the slide. internal var classes: [String] - /// The class names for the slide. - internal var content: [Content] - /// Create a slide. /// /// - Parameter content: The slide's content. @@ -92,7 +92,7 @@ extension Slide: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Slide { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Slide { diff --git a/Sources/HTMLKitComponents/Components/Slider.swift b/Sources/HTMLKitComponents/Components/Slider.swift index 2480ebc7..73381fb2 100644 --- a/Sources/HTMLKitComponents/Components/Slider.swift +++ b/Sources/HTMLKitComponents/Components/Slider.swift @@ -106,7 +106,7 @@ extension Slider: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Slider { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Slider { diff --git a/Sources/HTMLKitComponents/Components/Snippet.swift b/Sources/HTMLKitComponents/Components/Snippet.swift index b4f47304..03f204d4 100644 --- a/Sources/HTMLKitComponents/Components/Snippet.swift +++ b/Sources/HTMLKitComponents/Components/Snippet.swift @@ -17,7 +17,7 @@ public struct Snippet: View, Modifiable, Identifiable { internal var id: String? /// The body content of the snippet. - internal var content: String + internal let content: String /// The class names for the snippet. internal var classes: [String] @@ -104,7 +104,7 @@ extension Snippet: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Snippet { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Snippet { diff --git a/Sources/HTMLKitComponents/Components/Symbol.swift b/Sources/HTMLKitComponents/Components/Symbol.swift index 75596d05..7c753e2e 100644 --- a/Sources/HTMLKitComponents/Components/Symbol.swift +++ b/Sources/HTMLKitComponents/Components/Symbol.swift @@ -241,7 +241,7 @@ public struct Symbol: View, Modifiable { Vector { content } - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) .class(classes.joined(separator: " ")) } @@ -252,10 +252,10 @@ public struct Symbol: View, Modifiable { /// - Returns: The symbol public func fontSize(_ size: Tokens.FontSize) -> Symbol { - var newSelf = self - newSelf.classes.append("size:\(size.value)") + var copy = self + copy.classes.append("size:\(size.value)") - return newSelf + return copy } /// Fill the foreground of the symbol. @@ -265,10 +265,10 @@ public struct Symbol: View, Modifiable { /// - Returns: The symbol public func foregroundColor(_ color: Tokens.ForegroundColor) -> Symbol { - var newSelf = self - newSelf.classes.append("foreground:\(color.value)") + var copy = self + copy.classes.append("foreground:\(color.value)") - return newSelf + return copy } /// Set the drop shadow for the symbol. @@ -279,7 +279,7 @@ public struct Symbol: View, Modifiable { /// /// - Returns: The symbol public func shadow(_ radius: Tokens.BlurRadius, color: Tokens.ShadowColor = .black) -> Symbol { - return mutate(classes: ["shadow:\(radius.value)", "shadow:\(color.value)"]) + return self.mutate(classes: "shadow:\(radius.value)", "shadow:\(color.value)") } } diff --git a/Sources/HTMLKitComponents/Components/Tabs.swift b/Sources/HTMLKitComponents/Components/Tabs.swift index 1782f691..57bd286b 100644 --- a/Sources/HTMLKitComponents/Components/Tabs.swift +++ b/Sources/HTMLKitComponents/Components/Tabs.swift @@ -34,7 +34,7 @@ public struct Tabs: View, Identifiable, Modifiable { internal var id: String? /// The panes of the tabs. - internal var content: [Pane] + internal let content: [Pane] /// The class names of the tabs. internal var classes: [String] @@ -134,7 +134,7 @@ extension Tabs: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight?, alignment: Tokens.FrameAlignment?) -> Tabs { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet, length: Tokens.MarginLength) -> Tabs { diff --git a/Sources/HTMLKitComponents/Components/Text.swift b/Sources/HTMLKitComponents/Components/Text.swift index 59d40aa2..51bbde76 100644 --- a/Sources/HTMLKitComponents/Components/Text.swift +++ b/Sources/HTMLKitComponents/Components/Text.swift @@ -15,7 +15,7 @@ public struct Text: View, Actionable, Modifiable { internal var id: String? /// The body content of the text. - internal var content: [Content] + internal let content: [Content] /// The class names for the text. internal var classes: [String] @@ -99,7 +99,7 @@ extension Text: PressEvent { extension Text: TextModifier { public func font(_ family: Tokens.FontFamily) -> Text { - return mutate(fontfamily: family.value) + return self.mutate(fontfamily: family.value) } public func textStyle(_ style: Tokens.TextStyle) -> Text { @@ -179,7 +179,7 @@ extension Text: TextModifier { } public func shadow(_ radius: Tokens.BlurRadius, color: Tokens.ShadowColor = .black) -> Text { - return mutate(shadow: radius.value, color: color.value) + return self.mutate(shadow: radius.value, color: color.value) } } @@ -223,7 +223,7 @@ extension Text: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Text { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Text { diff --git a/Sources/HTMLKitComponents/Components/TextEditor.swift b/Sources/HTMLKitComponents/Components/TextEditor.swift index 58981634..ccc37774 100644 --- a/Sources/HTMLKitComponents/Components/TextEditor.swift +++ b/Sources/HTMLKitComponents/Components/TextEditor.swift @@ -23,7 +23,7 @@ public struct TextEditor: View, Modifiable, Identifiable { internal var rows: Int = 3 /// The body content of the editor. - internal var content: [String] + internal let content: [String] /// The class names for the editor. internal var classes: [String] @@ -82,10 +82,10 @@ public struct TextEditor: View, Modifiable, Identifiable { /// - Returns: The editor public func lineLimit(_ value: Int) -> TextEditor { - var newSelf = self - newSelf.rows = value + var copy = self + copy.rows = value - return newSelf + return copy } /// Set the identifier for the editor. @@ -154,7 +154,7 @@ extension TextEditor: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> TextEditor { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> TextEditor { diff --git a/Sources/HTMLKitComponents/Components/TextField.swift b/Sources/HTMLKitComponents/Components/TextField.swift index cc5831ea..62533c01 100644 --- a/Sources/HTMLKitComponents/Components/TextField.swift +++ b/Sources/HTMLKitComponents/Components/TextField.swift @@ -147,7 +147,7 @@ extension TextField: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> TextField { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> TextField { diff --git a/Sources/HTMLKitComponents/Components/TextPad.swift b/Sources/HTMLKitComponents/Components/TextPad.swift index 06d64eaf..cf810d95 100644 --- a/Sources/HTMLKitComponents/Components/TextPad.swift +++ b/Sources/HTMLKitComponents/Components/TextPad.swift @@ -24,7 +24,7 @@ public struct TextPad: View, Modifiable, Identifiable { internal var rows: Int = 3 /// The body content of the pad. - internal var content: [String] + internal let content: [String] /// The class names of the pad. internal var classes: [String] @@ -72,7 +72,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M15.5,6.5C16.328,6.5 17,7.172 17,8C17,8.828 16.328,9.5 15.5,9.5C14.672,9.5 14,8.828 14,8C14,7.172 14.672,6.5 15.5,6.5ZM10,6.5C10.828,6.5 11.5,7.172 11.5,8C11.5,8.828 10.828,9.5 10,9.5C9.172,9.5 8.5,8.828 8.5,8C8.5,7.172 9.172,6.5 10,6.5ZM4.5,6.5C5.328,6.5 6,7.172 6,8C6,8.828 5.328,9.5 4.5,9.5C3.672,9.5 3,8.828 3,8C3,7.172 3.672,6.5 4.5,6.5Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } UnorderedList { ListItem { @@ -86,7 +86,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M4.25,14.25L4.25,1.75C4.25,1.336 4.586,1 5,1L10.769,1C12.646,1 14.212,2.659 14.212,4.75C14.212,5.686 13.898,6.785 13.383,7.438C14.746,7.929 15.75,9.576 15.75,11.25C15.75,13.341 14.184,15 12.308,15L5,15C4.586,15 4.25,14.664 4.25,14.25ZM10.769,2.5L5.75,2.5C5.75,2.5 5.75,7.25 5.75,7.25L10.769,7.25C11.865,7.25 12.712,5.971 12.712,4.75C12.712,3.529 11.865,2.5 10.769,2.5ZM14.25,11.25C14.25,10.029 13.403,8.75 12.308,8.75L5.75,8.75C5.75,8.75 5.75,13.5 5.75,13.5L12.308,13.5C13.403,13.5 14.25,12.471 14.25,11.25Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool") @@ -107,7 +107,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M8.989,15L4,15C3.586,15 3.25,14.664 3.25,14.25C3.25,13.836 3.586,13.5 4,13.5L8.36,13.5L10.12,2.5L6,2.5C5.586,2.5 5.25,2.164 5.25,1.75C5.25,1.336 5.586,1 6,1C6,1 11.003,1 11.011,1L16,1C16.414,1 16.75,1.336 16.75,1.75C16.75,2.164 16.414,2.5 16,2.5L11.64,2.5L9.88,13.5L14,13.5C14.414,13.5 14.75,13.836 14.75,14.25C14.75,14.664 14.414,15 14,15C14,15 8.997,15 8.989,15Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool") @@ -128,7 +128,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M6.068,7C5.894,6.829 5.745,6.646 5.621,6.45C5.305,5.95 5.148,5.39 5.148,4.771C5.148,4.09 5.341,3.454 5.727,2.862C6.113,2.27 6.678,1.821 7.42,1.514C8.162,1.208 8.987,1.054 9.894,1.054C10.894,1.054 11.775,1.215 12.539,1.537C13.302,1.859 13.89,2.333 14.301,2.959C14.711,3.584 14.932,4.292 14.963,5.083L13.252,5.212C13.16,4.36 12.849,3.716 12.318,3.28C11.788,2.845 11.004,2.627 9.968,2.627C8.888,2.627 8.102,2.825 7.608,3.221C7.115,3.616 6.868,4.093 6.868,4.651C6.868,5.136 7.043,5.534 7.392,5.847C7.736,6.16 8.632,6.48 10.083,6.808C10.373,6.874 10.644,6.938 10.898,7L6.068,7ZM14.776,9C14.787,9.014 14.797,9.029 14.806,9.044C15.181,9.599 15.368,10.238 15.368,10.962C15.368,11.679 15.162,12.355 14.751,12.99C14.34,13.625 13.75,14.118 12.98,14.471C12.211,14.824 11.345,15 10.382,15C9.161,15 8.139,14.822 7.314,14.466C6.489,14.111 5.842,13.576 5.373,12.861C4.904,12.147 4.657,11.339 4.632,10.437L6.316,10.29C6.396,10.965 6.581,11.518 6.872,11.951C7.164,12.383 7.616,12.732 8.229,12.999C8.842,13.266 9.532,13.399 10.299,13.399C10.98,13.399 11.581,13.298 12.102,13.096C12.623,12.893 13.011,12.616 13.266,12.263C13.52,11.911 13.647,11.526 13.647,11.109C13.647,10.686 13.525,10.316 13.279,10C13.034,9.685 12.629,9.419 12.065,9.205C11.922,9.149 11.709,9.081 11.428,9L14.776,9ZM17,7.277L17,8.777L3,8.777L3,7.277L17,7.277Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool") @@ -149,7 +149,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M10.025,11.51C9.368,11.335 8.747,10.99 8.232,10.475L7.525,9.768C5.964,8.207 5.964,5.672 7.525,4.111L10.354,1.282C11.915,-0.279 14.449,-0.279 16.01,1.282L16.718,1.99C18.279,3.551 18.279,6.085 16.718,7.646L13.933,10.431C14.165,9.703 14.207,8.928 14.06,8.183L15.303,6.939C16.474,5.769 16.474,3.867 15.303,2.697C14.133,1.526 12.231,1.526 11.061,2.697L8.939,4.818C7.769,5.989 7.769,7.89 8.939,9.061C9.581,9.703 10.443,9.993 11.283,9.931C11.162,10.258 10.97,10.565 10.707,10.828L10.025,11.51ZM9.975,4.49C10.632,4.665 11.253,5.01 11.768,5.525L12.475,6.232C14.036,7.793 14.036,10.328 12.475,11.889L9.646,14.718C8.085,16.279 5.551,16.279 3.99,14.718L3.282,14.01C1.721,12.449 1.721,9.915 3.282,8.354L6.067,5.569C5.835,6.297 5.793,7.072 5.94,7.817L4.697,9.061C3.526,10.231 3.526,12.133 4.697,13.303C5.867,14.474 7.769,14.474 8.939,13.303L11.061,11.182C12.231,10.011 12.231,8.11 11.061,6.939C10.419,6.297 9.557,6.007 8.717,6.069C8.838,5.742 9.03,5.435 9.293,5.172L9.975,4.49Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool") @@ -170,7 +170,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M11.829,2.171C11.57,1.848 11.623,1.376 11.946,1.117C12.269,0.859 12.741,0.911 13,1.234L17.546,7.532C17.765,7.805 17.765,8.195 17.546,8.469L13.171,14.883C12.913,15.206 12.44,15.259 12.117,15C11.794,14.741 11.741,14.269 12,13.946C12,13.946 16,8 16,8L11.829,2.171ZM8.288,13.946C8.547,14.269 8.495,14.741 8.171,15C7.848,15.259 7.376,15.206 7.117,14.883L2.454,8.469C2.235,8.195 2.235,7.805 2.454,7.532L6.946,1.351C7.204,1.028 7.677,0.976 8,1.234C8.323,1.493 8.376,1.965 8.117,2.288C8.117,2.288 4,8 4,8L8.288,13.946Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool") @@ -195,7 +195,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M4.25,14.25L4.25,1.75C4.25,1.336 4.586,1 5,1L10.769,1C12.646,1 14.212,2.659 14.212,4.75C14.212,5.686 13.898,6.785 13.383,7.438C14.746,7.929 15.75,9.576 15.75,11.25C15.75,13.341 14.184,15 12.308,15L5,15C4.586,15 4.25,14.664 4.25,14.25ZM10.769,2.5L5.75,2.5C5.75,2.5 5.75,7.25 5.75,7.25L10.769,7.25C11.865,7.25 12.712,5.971 12.712,4.75C12.712,3.529 11.865,2.5 10.769,2.5ZM14.25,11.25C14.25,10.029 13.403,8.75 12.308,8.75L5.75,8.75C5.75,8.75 5.75,13.5 5.75,13.5L12.308,13.5C13.403,13.5 14.25,12.471 14.25,11.25Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool") @@ -216,7 +216,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M8.989,15L4,15C3.586,15 3.25,14.664 3.25,14.25C3.25,13.836 3.586,13.5 4,13.5L8.36,13.5L10.12,2.5L6,2.5C5.586,2.5 5.25,2.164 5.25,1.75C5.25,1.336 5.586,1 6,1C6,1 11.003,1 11.011,1L16,1C16.414,1 16.75,1.336 16.75,1.75C16.75,2.164 16.414,2.5 16,2.5L11.64,2.5L9.88,13.5L14,13.5C14.414,13.5 14.75,13.836 14.75,14.25C14.75,14.664 14.414,15 14,15C14,15 8.997,15 8.989,15Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool") @@ -237,7 +237,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M6.068,7C5.894,6.829 5.745,6.646 5.621,6.45C5.305,5.95 5.148,5.39 5.148,4.771C5.148,4.09 5.341,3.454 5.727,2.862C6.113,2.27 6.678,1.821 7.42,1.514C8.162,1.208 8.987,1.054 9.894,1.054C10.894,1.054 11.775,1.215 12.539,1.537C13.302,1.859 13.89,2.333 14.301,2.959C14.711,3.584 14.932,4.292 14.963,5.083L13.252,5.212C13.16,4.36 12.849,3.716 12.318,3.28C11.788,2.845 11.004,2.627 9.968,2.627C8.888,2.627 8.102,2.825 7.608,3.221C7.115,3.616 6.868,4.093 6.868,4.651C6.868,5.136 7.043,5.534 7.392,5.847C7.736,6.16 8.632,6.48 10.083,6.808C10.373,6.874 10.644,6.938 10.898,7L6.068,7ZM14.776,9C14.787,9.014 14.797,9.029 14.806,9.044C15.181,9.599 15.368,10.238 15.368,10.962C15.368,11.679 15.162,12.355 14.751,12.99C14.34,13.625 13.75,14.118 12.98,14.471C12.211,14.824 11.345,15 10.382,15C9.161,15 8.139,14.822 7.314,14.466C6.489,14.111 5.842,13.576 5.373,12.861C4.904,12.147 4.657,11.339 4.632,10.437L6.316,10.29C6.396,10.965 6.581,11.518 6.872,11.951C7.164,12.383 7.616,12.732 8.229,12.999C8.842,13.266 9.532,13.399 10.299,13.399C10.98,13.399 11.581,13.298 12.102,13.096C12.623,12.893 13.011,12.616 13.266,12.263C13.52,11.911 13.647,11.526 13.647,11.109C13.647,10.686 13.525,10.316 13.279,10C13.034,9.685 12.629,9.419 12.065,9.205C11.922,9.149 11.709,9.081 11.428,9L14.776,9ZM17,7.277L17,8.777L3,8.777L3,7.277L17,7.277Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool") @@ -258,7 +258,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M10.025,11.51C9.368,11.335 8.747,10.99 8.232,10.475L7.525,9.768C5.964,8.207 5.964,5.672 7.525,4.111L10.354,1.282C11.915,-0.279 14.449,-0.279 16.01,1.282L16.718,1.99C18.279,3.551 18.279,6.085 16.718,7.646L13.933,10.431C14.165,9.703 14.207,8.928 14.06,8.183L15.303,6.939C16.474,5.769 16.474,3.867 15.303,2.697C14.133,1.526 12.231,1.526 11.061,2.697L8.939,4.818C7.769,5.989 7.769,7.89 8.939,9.061C9.581,9.703 10.443,9.993 11.283,9.931C11.162,10.258 10.97,10.565 10.707,10.828L10.025,11.51ZM9.975,4.49C10.632,4.665 11.253,5.01 11.768,5.525L12.475,6.232C14.036,7.793 14.036,10.328 12.475,11.889L9.646,14.718C8.085,16.279 5.551,16.279 3.99,14.718L3.282,14.01C1.721,12.449 1.721,9.915 3.282,8.354L6.067,5.569C5.835,6.297 5.793,7.072 5.94,7.817L4.697,9.061C3.526,10.231 3.526,12.133 4.697,13.303C5.867,14.474 7.769,14.474 8.939,13.303L11.061,11.182C12.231,10.011 12.231,8.11 11.061,6.939C10.419,6.297 9.557,6.007 8.717,6.069C8.838,5.742 9.03,5.435 9.293,5.172L9.975,4.49Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool") @@ -279,7 +279,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M11.829,2.171C11.57,1.848 11.623,1.376 11.946,1.117C12.269,0.859 12.741,0.911 13,1.234L17.546,7.532C17.765,7.805 17.765,8.195 17.546,8.469L13.171,14.883C12.913,15.206 12.44,15.259 12.117,15C11.794,14.741 11.741,14.269 12,13.946C12,13.946 16,8 16,8L11.829,2.171ZM8.288,13.946C8.547,14.269 8.495,14.741 8.171,15C7.848,15.259 7.376,15.206 7.117,14.883L2.454,8.469C2.235,8.195 2.235,7.805 2.454,7.532L6.946,1.351C7.204,1.028 7.677,0.976 8,1.234C8.323,1.493 8.376,1.965 8.117,2.288C8.117,2.288 4,8 4,8L8.288,13.946Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool") @@ -303,7 +303,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M5.825,6.444L9.783,9.009C10.13,9.234 10.23,9.699 10.004,10.046C9.779,10.394 9.314,10.493 8.967,10.268L2.967,6.379C2.755,6.242 2.627,6.007 2.625,5.755C2.623,5.502 2.749,5.266 2.959,5.126L8.959,1.126C9.303,0.896 9.769,0.99 9.999,1.334C10.229,1.678 10.135,2.144 9.791,2.374L5.936,4.944L12.375,4.944C15.135,4.944 17.375,7.185 17.375,9.944C17.375,12.704 15.135,14.944 12.375,14.944L10.142,14.944C9.939,14.944 9.743,14.863 9.6,14.719C9.456,14.576 9.375,14.38 9.375,14.177C9.375,13.982 9.452,13.796 9.589,13.659C9.727,13.521 9.913,13.444 10.107,13.444L12.375,13.444C14.307,13.444 15.875,11.876 15.875,9.944C15.875,8.012 14.307,6.444 12.375,6.444L5.825,6.444Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool state:disabled") @@ -324,7 +324,7 @@ public struct TextPad: View, Modifiable, Identifiable { .draw("M14.175,6.444L10.217,9.009C9.87,9.234 9.77,9.699 9.996,10.046C10.221,10.394 10.686,10.493 11.033,10.268L17.033,6.379C17.245,6.242 17.373,6.007 17.375,5.755C17.377,5.502 17.251,5.266 17.041,5.126L11.041,1.126C10.697,0.896 10.231,0.99 10.001,1.334C9.771,1.678 9.865,2.144 10.209,2.374L14.064,4.944L7.625,4.944C4.865,4.944 2.625,7.185 2.625,9.944C2.625,12.704 4.865,14.944 7.625,14.944L9.858,14.944C10.061,14.944 10.257,14.863 10.4,14.719C10.544,14.576 10.625,14.38 10.625,14.177C10.625,13.982 10.548,13.796 10.411,13.659C10.273,13.521 10.087,13.444 9.893,13.444L7.625,13.444C5.693,13.444 4.125,11.876 4.125,9.944C4.125,8.012 5.693,6.444 7.625,6.444L14.175,6.444Z") } .namespace("http://www.w3.org/2000/svg") - .viewBox("0 0 20 16") + .viewBox(x: 0, y: 0, width: 20, height: 16) } .type(.button) .class("toolbar-tool state:disabled") @@ -361,10 +361,10 @@ public struct TextPad: View, Modifiable, Identifiable { /// - Returns: The pad public func lineLimit(_ value: Int) -> TextPad { - var newSelf = self - newSelf.rows = value + var copy = self + copy.rows = value - return newSelf + return copy } /// Set the identifier for the pad. @@ -433,7 +433,7 @@ extension TextPad: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> TextPad { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> TextPad { diff --git a/Sources/HTMLKitComponents/Components/VStack.swift b/Sources/HTMLKitComponents/Components/VStack.swift index 3106c662..cb9e74cb 100644 --- a/Sources/HTMLKitComponents/Components/VStack.swift +++ b/Sources/HTMLKitComponents/Components/VStack.swift @@ -22,7 +22,7 @@ public struct VStack: View, Actionable, Modifiable { internal var id: String? /// The body content of the stack. - internal var content: [Content] + internal let content: [Content] /// The class names for the stack. internal var classes: [String] @@ -80,14 +80,14 @@ public struct VStack: View, Actionable, Modifiable { /// /// - Returns: The stack public func shadow(_ radius: Tokens.BlurRadius = .small, color: Tokens.ShadowColor = .black) -> VStack { - return self.mutate(classes: ["shadow:\(radius.value)", "shadow:\(color.value)"]) + return self.mutate(classes: "shadow:\(radius.value)", "shadow:\(color.value)") } /// Clip the content for the stack. /// /// - Returns: The stack public func clipped() -> VStack { - return self.mutate(class: "overflow:clip") + return self.mutate(classes: "overflow:clip") } } @@ -142,7 +142,7 @@ extension VStack: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> VStack { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> VStack { diff --git a/Sources/HTMLKitComponents/Components/Video.swift b/Sources/HTMLKitComponents/Components/Video.swift index 290c2bd2..0a405098 100644 --- a/Sources/HTMLKitComponents/Components/Video.swift +++ b/Sources/HTMLKitComponents/Components/Video.swift @@ -98,7 +98,7 @@ extension Video: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> Video { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> Video { diff --git a/Sources/HTMLKitComponents/Components/ZStack.swift b/Sources/HTMLKitComponents/Components/ZStack.swift index f4f650ea..a78f64c1 100644 --- a/Sources/HTMLKitComponents/Components/ZStack.swift +++ b/Sources/HTMLKitComponents/Components/ZStack.swift @@ -17,13 +17,13 @@ public struct ZStack: View, Actionable, Modifiable { internal var id: String? /// The body content of the stack. - internal var content: [Content] + internal let content: [Content] /// The class names for the stack. internal var classes: [String] /// The event handlers on the stack. - var events: [String]? + internal var events: [String]? /// Create a stack. /// @@ -66,14 +66,14 @@ public struct ZStack: View, Actionable, Modifiable { /// /// - Returns: The stack public func shadow(_ radius: Tokens.BlurRadius = .small, color: Tokens.ShadowColor = .black) -> ZStack { - return self.mutate(classes: ["shadow:\(radius.value)", "shadow:\(color.value)"]) + return self.mutate(classes: "shadow:\(radius.value)", "shadow:\(color.value)") } /// Clip the content for the stack. /// /// - Returns: The stack public func clipped() -> ZStack { - return self.mutate(class: "overflow:clip") + return self.mutate(classes: "overflow:clip") } } @@ -128,7 +128,7 @@ extension ZStack: ViewModifier { } public func frame(width: Tokens.ViewWidth, height: Tokens.ViewHeight? = nil, alignment: Tokens.FrameAlignment? = nil) -> ZStack { - return mutate(frame: width.value, height: height?.value, alignment: alignment?.value) + return self.mutate(frame: width.value, height: height?.value, alignment: alignment?.value) } public func margin(insets: EdgeSet = .all, length: Tokens.MarginLength = .small) -> ZStack { diff --git a/Sources/HTMLKitComponents/Extensions/Components+Image.swift b/Sources/HTMLKitComponents/Extensions/Components+Image.swift index f3d1b4dd..8e85230d 100644 --- a/Sources/HTMLKitComponents/Extensions/Components+Image.swift +++ b/Sources/HTMLKitComponents/Extensions/Components+Image.swift @@ -7,7 +7,7 @@ extension HTMLKit.Image { /// - Parameter value: A container holding the concrete source type. /// /// - Returns: The image - public func source(_ value: DynamicType) -> HTMLKit.Image { + internal func source(_ value: DynamicType) -> HTMLKit.Image { switch value { case .string(let string): @@ -26,7 +26,7 @@ extension HTMLKit.Video { /// - Parameter value: A container holding the concrete source type. /// /// - Returns: The video - public func source(_ value: DynamicType) -> HTMLKit.Video { + internal func source(_ value: DynamicType) -> HTMLKit.Video { switch value { case .string(let string): diff --git a/Sources/HTMLKitComponents/Modifiers/ButtonModifier.swift b/Sources/HTMLKitComponents/Modifiers/ButtonModifier.swift index a55ac69b..cef225a8 100644 --- a/Sources/HTMLKitComponents/Modifiers/ButtonModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/ButtonModifier.swift @@ -33,14 +33,14 @@ public protocol ButtonModifier { extension ButtonModifier where Self: Modifiable { internal func mutate(controlsize value: String) -> Self { - return self.mutate(class: "size:\(value)") + return self.mutate(classes: "size:\(value)") } internal func mutate(buttonstyle value: String) -> Self { - return self.mutate(class: "style:\(value)") + return self.mutate(classes: "style:\(value)") } internal func mutate(buttonstate value: String) -> Self { - return self.mutate(class: "state:\(value)") + return self.mutate(classes: "state:\(value)") } } diff --git a/Sources/HTMLKitComponents/Modifiers/GraphicsModifier.swift b/Sources/HTMLKitComponents/Modifiers/GraphicsModifier.swift index 2d781788..08eb2e12 100644 --- a/Sources/HTMLKitComponents/Modifiers/GraphicsModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/GraphicsModifier.swift @@ -49,26 +49,26 @@ public protocol GraphicsModifier { extension GraphicsModifier where Self: Modifiable { internal func mutate(blur value: String) -> Self { - return self.mutate(class: "blur:\(value)") + return self.mutate(classes: "blur:\(value)") } internal func mutate(grayscale value: String) -> Self { - return self.mutate(class: "grayscale:\(value)") + return self.mutate(classes: "grayscale:\(value)") } internal func mutate(brightness value: String) -> Self { - return self.mutate(class: "brightness:\(value)") + return self.mutate(classes: "brightness:\(value)") } internal func mutate(saturation value: String) -> Self { - return self.mutate(class: "saturation:\(value)") + return self.mutate(classes: "saturation:\(value)") } internal func mutate(contrast value: String) -> Self { - return self.mutate(class: "contrast:\(value)") + return self.mutate(classes: "contrast:\(value)") } internal func mutate(shadow radius: String, color: String) -> Self { - return mutate(classes: ["shadow:\(radius)", "shadow:\(color)"]) + return self.mutate(classes: "shadow:\(radius)", "shadow:\(color)") } } diff --git a/Sources/HTMLKitComponents/Modifiers/ImageModifier.swift b/Sources/HTMLKitComponents/Modifiers/ImageModifier.swift index 2fe9bb76..43a735f6 100644 --- a/Sources/HTMLKitComponents/Modifiers/ImageModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/ImageModifier.swift @@ -38,24 +38,18 @@ public protocol ImageModifier { extension ImageModifier where Self: Modifiable { internal func mutate(objectfit value: String) -> Self { - return self.mutate(class: "fit:\(value)") + return self.mutate(classes: "fit:\(value)") } internal func mutate(imagescale value: String) -> Self { - return self.mutate(class: "scale:\(value)") + return self.mutate(classes: "scale:\(value)") } internal func mutate(clipshape value: String) -> Self { - return self.mutate(class: "shape:\(value)") + return self.mutate(classes: "shape:\(value)") } internal func mutate(aspectratio ratio: String, fit: String) -> Self { - - var classes: [String] = [] - - classes.append("aspect:\(ratio)") - classes.append("fit:\(fit)") - - return self.mutate(classes: classes) + return self.mutate(classes: "aspect:\(ratio)", "fit:\(fit)") } } diff --git a/Sources/HTMLKitComponents/Modifiers/InputModifier.swift b/Sources/HTMLKitComponents/Modifiers/InputModifier.swift index f5ecfc80..b525fb4c 100644 --- a/Sources/HTMLKitComponents/Modifiers/InputModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/InputModifier.swift @@ -19,10 +19,10 @@ public protocol InputModifier { extension InputModifier where Self: Modifiable { internal func mutate(inputstate value: String) -> Self { - return self.mutate(class: "state:\(value)") + return self.mutate(classes: "state:\(value)") } internal func mutate(focuscolor value: String) -> Self { - return self.mutate(class: "focus:\(value)") + return self.mutate(classes: "focus:\(value)") } } diff --git a/Sources/HTMLKitComponents/Modifiers/TextModifier.swift b/Sources/HTMLKitComponents/Modifiers/TextModifier.swift index b1db904b..0005a097 100644 --- a/Sources/HTMLKitComponents/Modifiers/TextModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/TextModifier.swift @@ -119,46 +119,46 @@ public protocol TextModifier { extension TextModifier where Self: Modifiable { internal func mutate(fontfamily value: String) -> Self { - return self.mutate(class: "font:\(value)") + return self.mutate(classes: "font:\(value)") } internal func mutate(textstyle value: String) -> Self { - return self.mutate(class: "style:\(value)") + return self.mutate(classes: "style:\(value)") } internal func mutate(foregroundcolor value: String) -> Self { - return self.mutate(class: "foreground:\(value)") + return self.mutate(classes: "foreground:\(value)") } internal func mutate(fontsize value: String) -> Self { - return self.mutate(class: "size:\(value)") + return self.mutate(classes: "size:\(value)") } internal func mutate(fontweight value: String) -> Self { - return self.mutate(class: "weight:\(value)") + return self.mutate(classes: "weight:\(value)") } internal func mutate(textcase value: String) -> Self { - return self.mutate(class: "case:\(value)") + return self.mutate(classes: "case:\(value)") } internal func mutate(fontstyle value: String) -> Self { - return self.mutate(class: "style:\(value)") + return self.mutate(classes: "style:\(value)") } internal func mutate(textdecoration value: String) -> Self { - return self.mutate(class: "decoration:\(value)") + return self.mutate(classes: "decoration:\(value)") } internal func mutate(lineheight value: String) -> Self { - return self.mutate(class: "height:\(value)") + return self.mutate(classes: "height:\(value)") } internal func mutate(linelimit value: String) -> Self { - return self.mutate(class: "limit:\(value)") + return self.mutate(classes: "limit:\(value)") } internal func mutate(shadow radius: String, color: String) -> Self { - return mutate(classes: ["shadow:\(radius)", "shadow:\(color)"]) + return self.mutate(classes: "shadow:\(radius)", "shadow:\(color)") } } diff --git a/Sources/HTMLKitComponents/Modifiers/ViewModifier.swift b/Sources/HTMLKitComponents/Modifiers/ViewModifier.swift index 872b4cb5..3df093b0 100644 --- a/Sources/HTMLKitComponents/Modifiers/ViewModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/ViewModifier.swift @@ -84,27 +84,27 @@ public protocol ViewModifier { extension ViewModifier where Self: Modifiable { internal func mutate(opacity value: String) -> Self { - return self.mutate(class: "opacity:\(value)") + return self.mutate(classes: "opacity:\(value)") } internal func mutate(zindex value: String) -> Self { - return self.mutate(class: "zindex:\(value)") + return self.mutate(classes: "zindex:\(value)") } internal func mutate(backgroundcolor value: String) -> Self { - return self.mutate(class: "background:\(value)") + return self.mutate(classes: "background:\(value)") } internal func mutate(viewstate value: String) -> Self { - return self.mutate(class: "state:\(value)") + return self.mutate(classes: "state:\(value)") } internal func mutate(scheme value: String) -> Self { - return self.mutate(class: "scheme:\(value)") + return self.mutate(classes: "scheme:\(value)") } internal func mutate(padding value: String) -> Self { - return self.mutate(class: "padding:\(value)") + return self.mutate(classes: "padding:\(value)") } internal func mutate(padding value: String, insets: EdgeSet) -> Self { @@ -145,11 +145,11 @@ extension ViewModifier where Self: Modifiable { } internal func mutate(bordershape value: String) -> Self { - return self.mutate(class: "shape:\(value)") + return self.mutate(classes: "shape:\(value)") } internal func mutate(border color: String, width: String) -> Self { - return self.mutate(classes: ["border:\(color)", "border:\(width)"]) + return self.mutate(classes: "border:\(color)", "border:\(width)") } internal func mutate(frame width: String, height: String? = nil, alignment: String? = nil) -> Self { diff --git a/Sources/HTMLKitComponents/Primitives/DynamicType.swift b/Sources/HTMLKitComponents/Primitives/DynamicType.swift index 36500556..d33174bd 100644 --- a/Sources/HTMLKitComponents/Primitives/DynamicType.swift +++ b/Sources/HTMLKitComponents/Primitives/DynamicType.swift @@ -1,21 +1,11 @@ import HTMLKit /// An enum that represents a dynamic source type. -public enum DynamicType { +internal enum DynamicType { - /// Holds a environment value + /// Holds a environment value. case value(EnvironmentValue) /// Holds a string case string(String) } - -/// An enum that represents a dynamic prompt type. -internal enum PromptType { - - /// Holds a key for the localized string. - case value(LocalizedStringKey) - - /// Holds a string. - case string(String) -} diff --git a/Sources/HTMLKitComponents/Primitives/PromptType.swift b/Sources/HTMLKitComponents/Primitives/PromptType.swift new file mode 100644 index 00000000..0434ad6f --- /dev/null +++ b/Sources/HTMLKitComponents/Primitives/PromptType.swift @@ -0,0 +1,11 @@ +import HTMLKit + +/// An enum that represents a dynamic prompt type. +internal enum PromptType { + + /// Holds a key for the localized string. + case value(LocalizedStringKey) + + /// Holds a string. + case string(String) +} diff --git a/Sources/HTMLKitComponents/Properties/Actionable.swift b/Sources/HTMLKitComponents/Properties/Actionable.swift index 73c94932..585b53a3 100644 --- a/Sources/HTMLKitComponents/Properties/Actionable.swift +++ b/Sources/HTMLKitComponents/Properties/Actionable.swift @@ -9,35 +9,35 @@ extension Actionable { internal func mutate(event: String) -> Self { - var newSelf = self + var copy = self - if var events = newSelf.events { + if var events = copy.events { events.append(event) - newSelf.events = events + copy.events = events } else { - newSelf.events = [event] + copy.events = [event] } - return newSelf + return copy } internal func mutate(events: [String]) -> Self { - var newSelf = self + var copy = self - if var events = newSelf.events { + if var events = copy.events { events.append(contentsOf: events) - newSelf.events = events + copy.events = events } else { - newSelf.events = events + copy.events = events } - return newSelf + return copy } } diff --git a/Sources/HTMLKitComponents/Properties/Identifiable.swift b/Sources/HTMLKitComponents/Properties/Identifiable.swift index 4de2366b..376c036c 100644 --- a/Sources/HTMLKitComponents/Properties/Identifiable.swift +++ b/Sources/HTMLKitComponents/Properties/Identifiable.swift @@ -14,9 +14,9 @@ extension Identifiable { /// - Returns: The component internal func mutate(id: String) -> Self { - var newSelf = self - newSelf.id = id + var copy = self + copy.id = id - return newSelf + return copy } } diff --git a/Sources/HTMLKitComponents/Properties/Modifiable.swift b/Sources/HTMLKitComponents/Properties/Modifiable.swift index cf087fef..68f18b6b 100644 --- a/Sources/HTMLKitComponents/Properties/Modifiable.swift +++ b/Sources/HTMLKitComponents/Properties/Modifiable.swift @@ -7,19 +7,19 @@ internal protocol Modifiable { extension Modifiable { - internal func mutate(`class`: String) -> Self { + internal func mutate(classes: [String]) -> Self { - var newSelf = self - newSelf.classes.append(`class`) + var copy = self + copy.classes.append(contentsOf: classes) - return newSelf + return copy } - internal func mutate(classes: [String]) -> Self { + internal func mutate(classes: String...) -> Self { - var newSelf = self - newSelf.classes.append(contentsOf: classes) + var copy = self + copy.classes.append(contentsOf: classes) - return newSelf + return copy } } diff --git a/Sources/HTMLKitComponents/Properties/Selectable.swift b/Sources/HTMLKitComponents/Properties/Selectable.swift index 0452b630..049f181b 100644 --- a/Sources/HTMLKitComponents/Properties/Selectable.swift +++ b/Sources/HTMLKitComponents/Properties/Selectable.swift @@ -17,17 +17,17 @@ extension Selectable { internal func selected(_ condition: Bool) -> Self { - var newSelf = self - newSelf.isSelected = condition + var copy = self + copy.isSelected = condition - return newSelf + return copy } internal func tag(_ name: String) -> Self { - var newSelf = self - newSelf.name = name + var copy = self + copy.name = name - return newSelf + return copy } } diff --git a/Tests/HTMLKitComponentsTests/ComponentTests.swift b/Tests/HTMLKitComponentsTests/ComponentTests.swift index 2cb94ad3..a3a655a5 100644 --- a/Tests/HTMLKitComponentsTests/ComponentTests.swift +++ b/Tests/HTMLKitComponentsTests/ComponentTests.swift @@ -511,7 +511,6 @@ final class ComponentTests: XCTestCase { ) } - func testNavigation() throws { let view = TestView { From b0374374d58b0427beeb6b3ab539b67841c36265 Mon Sep 17 00:00:00 2001 From: Mattes Mohr Date: Fri, 28 Nov 2025 13:34:40 +0100 Subject: [PATCH 2/2] Fix missing prompt in datepicker component --- .../Components/DatePicker.swift | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Sources/HTMLKitComponents/Components/DatePicker.swift b/Sources/HTMLKitComponents/Components/DatePicker.swift index 751b2bff..f163cf16 100644 --- a/Sources/HTMLKitComponents/Components/DatePicker.swift +++ b/Sources/HTMLKitComponents/Components/DatePicker.swift @@ -5,7 +5,7 @@ import HTMLKit /// Use `DatePicker` to pick a date from a calendar. /// /// ```swift -/// DatePicker(name: "lorem") +/// DatePicker(name: "lorem", prompt: "Lorem ipsum", value: "Lorem ipsum") /// ``` public struct DatePicker: View, Modifiable, Identifiable { @@ -15,6 +15,9 @@ public struct DatePicker: View, Modifiable, Identifiable { /// The name of the picker. internal let name: String + /// The content hint for the field. + internal let prompt: PromptType? + /// The content of the picker. internal let value: String? @@ -25,13 +28,30 @@ public struct DatePicker: View, Modifiable, Identifiable { internal var events: [String]? /// Create a date picker. - /// + /// + /// - Parameters: + /// - name: The name to assign to the field. + /// - prompt: The prompt to guide the user. + /// - value: The date to edit within the field. + @_disfavoredOverload + public init(name: String, prompt: String? = nil, value: String? = nil) { + + self.name = name + self.prompt = prompt.map(PromptType.string(_:)) + self.value = value + self.classes = ["datepicker"] + } + + /// Create a date picker. + /// /// - Parameters: /// - name: The name to assign to the field. + /// - prompt: The prompt to guide the user. /// - value: The date to edit within the field. - public init(name: String, value: String? = nil) { + public init(name: String, prompt: LocalizedStringKey? = nil, value: String? = nil) { self.name = name + self.prompt = prompt.map(PromptType.value(_:)) self.value = value self.classes = ["datepicker"] } @@ -45,6 +65,9 @@ public struct DatePicker: View, Modifiable, Identifiable { .modify(unwrap: value) { $0.value($1) } + .modify(unwrap: prompt) { + $0.placeholder($1) + } self.calendar } .class(classes.joined(separator: " "))