Skip to content

Commit

Permalink
Add two texfields to get text for label and helper text
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic35 committed Feb 4, 2025
1 parent 0c0542a commit 0c3e7f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ final class SwitchConfigurationModel: ComponentConfiguration {
@Published var orientation: OUDSSwitch.Orientation {
didSet { updateCode() }
}
@Published var labelContent: String
@Published var helperTextContent: String

// MARK: Initializer

Expand All @@ -53,6 +55,8 @@ final class SwitchConfigurationModel: ComponentConfiguration {
onError = false
divider = true
orientation = .default
labelContent = String(localized: "app_components_switch_label_text")
helperTextContent = String(localized: "app_components_switch_helperText_text")
}

deinit { }
Expand Down Expand Up @@ -136,12 +140,6 @@ struct SwitchConfiguration: View {
.foregroundStyle(theme.colors.colorContentDefault.color(for: colorScheme))

if !model.switchOnly {
DesignToolboxChoicePicker(title: "app_components_common_orientation_label", selection: $model.orientation) {
ForEach(OUDSSwitch.Orientation.allCases, id: \.id) { orientation in
Text(LocalizedStringKey(orientation.description)).tag(orientation)
}
}

Toggle("app_components_common_helperText_label", isOn: $model.helperText)
.typeHeadingMedium(theme)
.foregroundStyle(theme.colors.colorContentDefault.color(for: colorScheme))
Expand All @@ -157,6 +155,19 @@ struct SwitchConfiguration: View {
Toggle("app_components_common_onError_label", isOn: $model.onError)
.typeHeadingMedium(theme)
.foregroundStyle(theme.colors.colorContentDefault.color(for: colorScheme))

DesignToolboxChoicePicker(title: "app_components_common_orientation_label", selection: $model.orientation) {
ForEach(OUDSSwitch.Orientation.allCases, id: \.id) { orientation in
Text(LocalizedStringKey(orientation.description)).tag(orientation)
}
}

DisclosureGroup("Edit texts") {
DesignToolboxTextField(text: $model.labelContent, prompt: "app_component_common_userText_prompt", title: "app_components_switch_label_text")
if model.helperText {
DesignToolboxTextField(text: $model.helperTextContent, prompt: "app_component_common_userText_prompt", title: "app_components_common_helperText_label")
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private struct SwitchDemo: View {
} else {
OUDSSwitch(
isOn: $isOn,
label: "app_components_switch_label_text",
helperText: helperText,
label: model.labelContent,
helperText: helperTextContent,
icon: icon,
onError: model.onError,
divider: model.divider,
Expand All @@ -100,8 +100,8 @@ private struct SwitchDemo: View {

// MARK: Private helpers

private var helperText: String? {
model.helperText ? "app_components_switch_helperText_text" : nil
private var helperTextContent: String? {
model.helperText ? model.helperTextContent : nil
}
private var icon: Image? {
model.icon ? Image(decorative: "ic_heart") : nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ struct DesignToolboxTextField: View {

let text: Binding<String>
let prompt: String
let title: String

init(text: Binding<String>, prompt: String, title: String = "app_component_common_userText_label") {
self.title = title
self.text = text
self.prompt = prompt
}

var body: some View {
VStack(alignment: .leading) {
Text("app_component_common_userText_label")
Text(LocalizedStringKey(title))
.typeHeadingMedium(theme)
.foregroundStyle(theme.colors.colorContentDefault.color(for: colorScheme))

Expand Down

0 comments on commit 0c3e7f0

Please sign in to comment.