Skip to content

Commit d7fd610

Browse files
authored
Add content attribute for Text, but recommend using children (#1289)
1 parent b099ceb commit d7fd610

File tree

1 file changed

+14
-1
lines changed
  • Sources/LiveViewNative/Views/Text Input and Output

1 file changed

+14
-1
lines changed

Sources/LiveViewNative/Views/Text Input and Output/Text.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ struct Text<R: RootRegistry>: View {
101101

102102
@ObservedElement private var element: ElementNode
103103

104+
/// A string value to use as the text content.
105+
///
106+
/// In most cases, you should provide the content as a child of the element.
107+
///
108+
/// ```html
109+
/// <Text>Hello, world!</Text>
110+
/// ```
111+
@_documentation(visibility: public)
112+
@Attribute("content") private var content: String?
113+
104114
/// A string value to use as the text content without modification.
105115
///
106116
/// In some cases, whitespaces and newlines in the text content are trimmed.
@@ -201,6 +211,7 @@ struct Text<R: RootRegistry>: View {
201211

202212
init(element: ElementNode, overrideStylesheet: (any StylesheetProtocol)?) {
203213
self._element = .init(element: element)
214+
self._content = .init(wrappedValue: nil, "content", element: element)
204215
self._verbatim = .init(wrappedValue: nil, "verbatim", element: element)
205216
self._date = .init(
206217
wrappedValue: nil,
@@ -253,7 +264,9 @@ struct Text<R: RootRegistry>: View {
253264
}
254265

255266
private var text: SwiftUI.Text {
256-
if let verbatim {
267+
if let content {
268+
return SwiftUI.Text(content)
269+
} else if let verbatim {
257270
return SwiftUI.Text(verbatim: verbatim)
258271
} else if let date {
259272
return SwiftUI.Text(date, style: dateStyle)

0 commit comments

Comments
 (0)