TextFields.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. extension BackendFeatures {
  2. /// Backend methods for text fields.
  3. ///
  4. /// These are used by ``TextField``.
  5. @MainActor
  6. public protocol TextFields: Core {
  7. /// Creates an editable text field with a placeholder label and change
  8. /// handler.
  9. ///
  10. /// Predominantly used by ``TextField``.
  11. ///
  12. /// - Returns: A text field.
  13. func createTextField() -> Widget
  14. /// Sets the placeholder label and change handler of an editable text field.
  15. ///
  16. /// - Parameters:
  17. /// - textField: The text field to update.
  18. /// - placeholder: The text field's placeholder label.
  19. /// - environment: The current environment.
  20. /// - onChange: The action to perform when the text field's content
  21. /// changes. This replaces any existing change handlers, and is called
  22. /// whenever the displayed value changes.
  23. /// - onSubmit: The action to perform when the user hits Enter/Return,
  24. /// or whatever the backend decides counts as submission of the field.
  25. func updateTextField(
  26. _ textField: Widget,
  27. placeholder: String,
  28. environment: EnvironmentValues,
  29. onChange: @escaping (String) -> Void,
  30. onSubmit: @escaping () -> Void
  31. )
  32. /// Sets the value of an editable text field.
  33. ///
  34. /// - Parameters:
  35. /// - textField: The text field to set the content of.
  36. /// - content: The new content.
  37. func setContent(ofTextField textField: Widget, to content: String)
  38. /// Gets the value of an editable text field.
  39. ///
  40. /// - Parameter textField: The text field to get the content of.
  41. /// - Returns: `textField`'s content.
  42. func getContent(ofTextField textField: Widget) -> String
  43. }
  44. }