-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#405] Add switch component #439
base: develop
Are you sure you want to change the base?
Changes from 10 commits
5e9fc86
691f169
a018eee
770cdad
49b80ee
a9b285d
aa12111
0c0542a
0c3e7f0
703d865
dc7ccdf
637c45a
eae0af0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,7 +197,7 @@ struct ButtonConfiguration: View { | |
} | ||
|
||
if model.layout == .iconAndText || model.layout == .textOnly { | ||
DesignToolboxTextField(text: $model.text, prompt: "app_component_common_userText_prompt") | ||
DesignToolboxTextField(text: $model.text, prompt: "app_components_common_userText_prompt") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je trouve curieux d'utiliser du camel case en plus du snake case, c'est normal d'avoir "userText" et pas par exemple "user_text" ? Je ne connais pas les règles appliquées au wording ici :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cf. règles de naming dans le fichier |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,9 @@ struct EmptyState: View { | |
.frame(width: 160, height: 160, alignment: .center) | ||
|
||
VStack(alignment: .center, spacing: theme.spaces.spaceFixedShorter) { | ||
Text("app_component_emptyContent_text") | ||
Text("app_components_emptyContent_text") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem que précédemment, "empty_content" plutôt ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cf règles de naming |
||
.typeHeadingMedium(theme) | ||
Text("app_component_emptyContent_description_text") | ||
Text("app_components_emptyContent_description_text") | ||
.typeBodyDefaultSmall(theme) | ||
} | ||
.padding(.vertical, theme.spaces.spaceFixedMedium) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,7 +167,7 @@ struct LinkConfiguration: View { | |
} | ||
} | ||
|
||
DesignToolboxTextField(text: $model.text, prompt: "app_component_common_userText_prompt") | ||
DesignToolboxTextField(text: $model.text, prompt: "app_components_common_userText_prompt") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "user_text" plutôt que "userText" ? |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
// | ||
// Software Name: OUDS iOS | ||
// SPDX-FileCopyrightText: Copyright (c) Orange SA | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// This software is distributed under the MIT license, | ||
// the text of which is available at https://opensource.org/license/MIT/ | ||
// or see the "LICENSE" file for more details. | ||
// | ||
// Authors: See CONTRIBUTORS.txt | ||
// Software description: A SwiftUI components library with code examples for Orange Unified Design System | ||
// | ||
|
||
import OUDSComponents | ||
import SwiftUI | ||
|
||
// MARK: - Switch Configuration Model | ||
|
||
/// The model shared between `SwitchPageConfiguration` view and `SwitchPageComponent` view. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SwitchPageConfiguration n'existe pas, SwitchPage plutôt ? |
||
final class SwitchConfigurationModel: ComponentConfiguration { | ||
|
||
// MARK: Published properties | ||
|
||
@Published var enabled: Bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tous tes @published sont collés sans saut de ligne ; pour des raisons de clarté il faudrait mettre des sauts de ligne comme d'habitude :) |
||
didSet { updateCode() } | ||
} | ||
@Published var switchOnly: Bool { | ||
didSet { updateCode() } | ||
} | ||
@Published var helperText: Bool { | ||
didSet { updateCode() } | ||
} | ||
@Published var icon: Bool { | ||
didSet { updateCode() } | ||
} | ||
@Published var onError: Bool { | ||
didSet { updateCode() } | ||
} | ||
@Published var divider: Bool { | ||
didSet { updateCode() } | ||
} | ||
@Published var orientation: OUDSSwitch.Orientation { | ||
didSet { updateCode() } | ||
} | ||
@Published var labelContent: String | ||
@Published var helperTextContent: String | ||
|
||
// MARK: Initializer | ||
|
||
override init() { | ||
enabled = true | ||
switchOnly = false | ||
helperText = true | ||
icon = true | ||
onError = false | ||
divider = true | ||
orientation = .default | ||
labelContent = String(localized: "app_components_switch_label_text") | ||
helperTextContent = String(localized: "app_components_switch_helperText_text") | ||
} | ||
|
||
deinit { } | ||
|
||
// MARK: Component Configuration | ||
|
||
override func updateCode() { | ||
if switchOnly { | ||
code = | ||
""" | ||
OUDSSwitch(isOn: $isOn) | ||
\(disableCode)) | ||
""" | ||
} else { | ||
code = | ||
""" | ||
OUDSSwitch(isOn: $isOn, label: \"Label\"\(helperTextPatern)\(iconPatern)\(onErrorPatern)\(dividerPatern)\(orienationPatern) | ||
\(disableCode)) | ||
""" | ||
} | ||
} | ||
|
||
private var disableCode: String { | ||
".disable(\(enabled ? "false" : "true"))" | ||
} | ||
|
||
private var helperTextPatern: String { | ||
if helperText { | ||
return ",helperText: \(String(localized: "app_components_switch_helperText_text"))" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ", helperText" avec un espace plutôt que ",helperText" |
||
} else { | ||
return "" | ||
} | ||
} | ||
private var iconPatern: String { | ||
if icon { | ||
return ", Image(decorative: \"ic_heart\")" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Le paramètre est nommé, il faudrait insérer "icon: " |
||
} else { | ||
return "" | ||
} | ||
} | ||
private var onErrorPatern: String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "pattern" prend deux T, donc "onErrorPattern" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attention, il manque des sauts de ligne dans ce fichier, tout est collé. |
||
if onError { | ||
return ", onError: true" | ||
} else { | ||
return "" | ||
} | ||
} | ||
private var dividerPatern: String { | ||
if onError { | ||
return ", divider: true" | ||
} else { | ||
return "" | ||
} | ||
} | ||
private var orienationPatern: String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "orientationPattern" plutôt que "orienationPatern". |
||
if onError { | ||
return ", orientation: \(orientation.description)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je ne suis pas convaincu par le notion d"orientation" qui me fait penser plutôt à portrait, paysage, portrait inversé. Du côté du checkbox je prends la notion de "layout" pour gérer les trois cas : uniquement le selecteur, seelcteur à gauche et selecteur à droite. Tu peux regarder ici par exemple : https://github.com/Orange-OpenSource/ouds-ios/blob/264-add-component-checkbox-3/OUDS/Core/Components/Sources/Checkbox/OUDSCheckbox.swift |
||
} else { | ||
return "" | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Switch Configuration View | ||
|
||
struct SwitchConfiguration: View { | ||
|
||
@Environment(\.theme) private var theme | ||
@Environment(\.colorScheme) private var colorScheme | ||
|
||
@StateObject var model: SwitchConfigurationModel | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: theme.spaces.spaceFixedMedium) { | ||
Toggle("app_common_enabled_label", isOn: $model.enabled) | ||
.typeHeadingMedium(theme) | ||
.foregroundStyle(theme.colors.colorContentDefault.color(for: colorScheme)) | ||
|
||
Toggle("app_components_switch_switchOnly_label", isOn: $model.switchOnly) | ||
.typeHeadingMedium(theme) | ||
.foregroundStyle(theme.colors.colorContentDefault.color(for: colorScheme)) | ||
|
||
if !model.switchOnly { | ||
Toggle("app_components_common_helperText_label", isOn: $model.helperText) | ||
.typeHeadingMedium(theme) | ||
.foregroundStyle(theme.colors.colorContentDefault.color(for: colorScheme)) | ||
|
||
Toggle("app_components_common_icon_label", isOn: $model.icon) | ||
.typeHeadingMedium(theme) | ||
.foregroundStyle(theme.colors.colorContentDefault.color(for: colorScheme)) | ||
|
||
Toggle("app_components_common_divider_label", isOn: $model.divider) | ||
.typeHeadingMedium(theme) | ||
.foregroundStyle(theme.colors.colorContentDefault.color(for: colorScheme)) | ||
|
||
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("app_components_common_editContent_label") { | ||
DesignToolboxTextField(text: $model.labelContent, prompt: "app_components_common_userText_prompt", title: "app_components_switch_label_text") | ||
if model.helperText { | ||
DesignToolboxTextField(text: $model.helperTextContent, prompt: "app_components_common_userText_prompt", title: "app_components_common_helperText_label") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: Switch Layout Orientation extension | ||
|
||
extension OUDSSwitch.Orientation: @retroactive CaseIterable, @retroactive CustomStringConvertible { | ||
nonisolated(unsafe) public static let allCases: [OUDSSwitch.Orientation] = [.default, .inverse] | ||
|
||
// Note: Not localized because it is a technical name | ||
public var description: String { | ||
switch self { | ||
case .default: | ||
"Default" | ||
case .inverse: | ||
"Inverse" | ||
} | ||
} | ||
|
||
var id: String { description } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Software Name: OUDS iOS | ||
// SPDX-FileCopyrightText: Copyright (c) Orange SA | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// This software is distributed under the MIT license, | ||
// the text of which is available at https://opensource.org/license/MIT/ | ||
// or see the "LICENSE" file for more details. | ||
// | ||
// Authors: See CONTRIBUTORS.txt | ||
// Software description: A SwiftUI components library with code examples for Orange Unified Design System | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SwitchElement: DesignToolboxElement { | ||
let name: String | ||
let image: Image | ||
let pageDescription: AnyView | ||
|
||
init() { | ||
name = "app_components_switch_label" | ||
image = Image(decorative: "il_component_switch").renderingMode(.original) | ||
pageDescription = AnyView(DesignToolboxElementPage( | ||
name: name, | ||
image: nil, | ||
description: "app_components_switch_description_text", | ||
illustration: AnyView(SwitchPage()) | ||
) | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je mettrais cette ligne en haut, avant celle relative à la carte n°436