Skip to content

[#405] Add switch component #528

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

Merged
merged 29 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
07575ee
refactor: Udpate language translations (#622) (#624)
B3nz01d Apr 18, 2025
88ba91b
fix: update wroding for arabic (#622) (#625)
ludovic35 Apr 18, 2025
933458c
Add swtch component without all tokens
ludovic35 Mar 21, 2025
9e37e5f
Add screen in demo app
ludovic35 Mar 21, 2025
cb9fc6a
Add documentation
ludovic35 Mar 21, 2025
a0bfe1c
Update changelog
ludovic35 Mar 21, 2025
db2d1ba
Add Ui trests
ludovic35 Mar 24, 2025
8d9fc6b
Update Switch UI tests wthout snapshots
ludovic35 Mar 25, 2025
00221dd
Use component tokens
ludovic35 Mar 25, 2025
8c28028
Add animation when ispressed change state
ludovic35 Mar 26, 2025
771641d
Use opacity token on tick
ludovic35 Mar 28, 2025
bd791d5
Use InteractionState for switch
ludovic35 Mar 28, 2025
c9bed3d
Udate size of Switch only
ludovic35 Mar 31, 2025
d7b8993
review: first review, nedd update when PR 575 was merged
ludovic35 Apr 1, 2025
9957f6d
review: used new API for fourground and background colors
ludovic35 Apr 1, 2025
6bb0e52
Add vibration when value of change as changed
ludovic35 Apr 2, 2025
674b5e2
Add snapshots for UI Tests
ludovic35 Apr 2, 2025
2d0270b
Update changelog with right order
ludovic35 Apr 2, 2025
30fd12a
Fix wording
ludovic35 Apr 16, 2025
a28ab58
Upodate animation
ludovic35 Apr 17, 2025
9732088
Update doc and changelog
ludovic35 Apr 17, 2025
9e5a61c
Update doc
ludovic35 Apr 17, 2025
4c6f967
Test after reanming
ludovic35 Apr 17, 2025
670c93e
review: update testUI
ludovic35 Apr 18, 2025
9bab30b
review: update changelog
ludovic35 Apr 18, 2025
6cc3eba
review: update naming
ludovic35 Apr 18, 2025
4598a85
refactor(review): typos, renaming, docs (#405)
pylapp Apr 24, 2025
e7ae00e
refactor(review): code snippets for disabled cases and handball figur…
pylapp Apr 24, 2025
59b3811
chore(rebase): clean up (#405)
pylapp Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [Library] Switch component ([#405](https://github.com/Orange-OpenSource/ouds-ios/issues/405))
- [Tool] New system to generate, build ad upload documentation ([#628](https://github.com/Orange-OpenSource/ouds-ios/issues/628))
- [Library] Add divider component ([#511](https://github.com/Orange-OpenSource/ouds-ios/issues/511))
- [Library] Add divider component ([#511](https://github.com/Orange-OpenSource/ouds-ios/issues/511))
- [Library] Let control-item-based component flip the icons programatically or not ([#556](https://github.com/Orange-OpenSource/ouds-ios/issues/556))
- [Library] Radio picker component ([#586](https://github.com/Orange-OpenSource/ouds-ios/issues/586))
- [Library] Let control-item-based component flip the icons programatically or not ([#556](https://github.com/Orange-OpenSource/ouds-ios/issues/556))
Expand All @@ -19,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [DesignToolbox] Udpate language translations ([#622](https://github.com/Orange-OpenSource/ouds-ios/issues/622))
- [Tool] Fix Gitleaks configuration file and update documentation about version in use
- [Library] Renaming of API ([#608](https://github.com/Orange-OpenSource/ouds-ios/issues/608))
- [DesignToolbox] Order of components and tokens in design toolbox component page ([#585](https://github.com/Orange-OpenSource/ouds-ios/issues/585))
- [DesignToolbox] Order of OCHAcomponents and tokens in design toolbox component page ([#585](https://github.com/Orange-OpenSource/ouds-ios/issues/585))
- [Library] Default hierarchy and style for button component ([#609](https://github.com/Orange-OpenSource/ouds-ios/issues/609))
- [DesignToolbox] Rename checkbox and radio button entries ([#584](https://github.com/Orange-OpenSource/ouds-ios/issues/584))
- [DesignToolbox] Rename the radio buton component ([#583](https://github.com/Orange-OpenSource/ouds-ios/issues/583))
Expand All @@ -28,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- [DesignToolbox] Fixed code samples for disabled cases of components
- [DesignToolbox] Name of layouts for control item components ([#588](https://github.com/Orange-OpenSource/ouds-ios/issues/588))
- [DesignToolbox] Add illustration for link component in RTL mode checkbox and radio button entries ([#555](https://github.com/Orange-OpenSource/ouds-ios/issues/555))

Expand Down
100 changes: 87 additions & 13 deletions DesignToolbox/DesignToolbox.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class ButtonConfigurationModel: ComponentConfiguration {

private var disableCode: String {
if case .`default` = style {
".disable(\(enabled ? "false" : "true"))"
".disabled(\(enabled ? "false" : "true"))"
} else {
""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class CheckboxConfigurationModel: ComponentConfiguration {
}

private var disableCode: String {
".disable(\(enabled ? "false" : "true"))"
".disabled(\(enabled ? "false" : "true"))"
}

private var isErrorPattern: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class CheckboxIndeterminateConfigurationModel: ComponentConfiguration {
}

private var disableCode: String {
".disable(\(enabled ? "false" : "true"))"
".disabled(\(enabled ? "false" : "true"))"
}

private var isErrorPattern: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ final class CheckboxItemConfigurationModel: ComponentConfiguration {
// swiftlint:enable line_length

private var disableCode: String {
".disable(\(enabled ? "false" : "true"))"
".disabled(\(enabled ? "false" : "true"))"
}

private var helperTextPattern: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ final class CheckboxItemIndeterminateConfigurationModel: ComponentConfiguration
// swiftlint:enable line_length

private var disableCode: String {
".disable(\(enabled ? "false" : "true"))"
".disabled(\(enabled ? "false" : "true"))"
}

private var helperTextPattern: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ final class CheckboxItemConfigurationModel: ComponentConfiguration {
// swiftlint:enable line_length

private var disableCode: String {
".disable(\(enabled ? "false" : "true"))"
".disabled(\(enabled ? "false" : "true"))"
}

private var helperTextPatern: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct ComponentsPage: View {
DividerElements(),
LinkElement(),
RadioElements(),
SwitchElements(),
]

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class LinkConfigurationModel: ComponentConfiguration {
}

private var disableCode: String {
".disable(\(enabled ? "false" : "true"))"
".disabled(\(enabled ? "false" : "true"))"
}

override func updateCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class RadioConfigurationModel: ComponentConfiguration {
}

private var disableCode: String {
".disable(\(enabled ? "false" : "true"))"
".disabled(\(enabled ? "false" : "true"))"
}

private var isErrorPattern: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ final class RadioItemConfigurationModel: ComponentConfiguration {
// swiftlint:enable line_length

private var disableCode: String {
".disable(\(enabled ? "false" : "true"))"
".disabled(\(enabled ? "false" : "true"))"
}

private var additionalLabelTextPattern: String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// 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 `SwitchConfiguration` view and `SwitchPage` view.
final class SwitchConfigurationModel: ComponentConfiguration {

// MARK: - Properties

@Published var enabled: Bool {
didSet { updateCode() }
}

@Published var selection: Bool {
didSet { updateCode() }
}

// MARK: - Initializer

override init() {
selection = true
enabled = true
}

deinit { }

// MARK: - Component Configuration

override func updateCode() {
code =
"""
OUDSSwitch(isOn: $isOn, accessibilityLabel: "A label for accessibility")
\(disableCode)
"""
}

private var disableCode: String {
".disabled(\(enabled ? "false" : "true"))"
}
}

// MARK: - Switch Configuration View

struct SwitchConfiguration: View {

@ObservedObject var model: SwitchConfigurationModel

@Environment(\.theme) private var theme

var body: some View {
VStack(alignment: .leading, spacing: theme.spaces.spaceFixedMedium) {
Toggle("app_components_switch_selection_label", isOn: $model.selection)
.typeHeadingMedium(theme)
.oudsForegroundStyle(theme.colors.colorContentDefault)
.disabled(!model.enabled)

Toggle("app_common_enabled_label", isOn: $model.enabled)
.typeHeadingMedium(theme)
.oudsForegroundStyle(theme.colors.colorContentDefault)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// 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_selectorOnly_label".localized()
image = Image(decorative: "il_component_switch").renderingMode(.original)
pageDescription = AnyView(DesignToolboxElementPage(
name: name,
image: nil,
description: "app_components_switch_description_text",
illustration: AnyView(SwitchPage())))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// 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 OUDS
import OUDSComponents
import SwiftUI

// MARK: - Switch Page

struct SwitchPage: View {

@StateObject private var configuration: SwitchConfigurationModel

init() {
_configuration = StateObject(wrappedValue: SwitchConfigurationModel())
}

var body: some View {
ComponentConfigurationView(
configuration: configuration,
componentView: componentView,
configurationView: configurationView
)
}

@ViewBuilder
private func componentView(with configuration: ComponentConfiguration) -> some View {
if let model = configuration as? SwitchConfigurationModel {
SwitchIllustration(model: model)
}
}

@ViewBuilder
private func configurationView(with configuration: ComponentConfiguration) -> some View {
if let model = configuration as? SwitchConfigurationModel {
SwitchConfiguration(model: model)
}
}
}

// MARK: - Switch Illustration

private struct SwitchIllustration: View {

let model: SwitchConfigurationModel
@Environment(\.colorScheme) private var colorScheme

var body: some View {
VStack(alignment: .center) {
// TODO: Build a modifier to inverse colorscheme or force to a colorscheme
SwitchDemo(model: model)
SwitchDemo(model: model)
.colorScheme(colorScheme == .dark ? .light : .dark)
}
}
}

// MARK: - Switch Demo

private struct SwitchDemo: View {

@ObservedObject var model: SwitchConfigurationModel
@Environment(\.theme) private var theme

var body: some View {
HStack(alignment: .center) {
Spacer()
OUDSSwitch(isOn: $model.selection,
accessibilityLabel: "app_components_switch_hint_a11y".localized()) // No LocalizedStringKey tpe inference in the component
.disabled(!model.enabled)
Spacer()
}
.padding(.all, theme.spaces.spaceFixedMedium)
.designToolboxColoredSurface(false)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// 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 OUDS
import OUDSComponents
import OUDSThemesOrange
import SwiftUI

struct SwitchElements: DesignToolboxElement {
let name: String
let image: Image
let pageDescription: AnyView

init() {
let variants: [DesignToolboxElement] = [
SwitchElement(),
SwitchItemElement(),
]

name = "app_components_switch_label".localized()
image = Image(decorative: "il_component_switch").renderingMode(.original)
pageDescription = AnyView(DesignToolboxElementPage(
name: name,
image: Image(decorative: "il_component_switch").renderingMode(.original),
description: "app_components_switch_description_text",
illustration: AnyView(DesignToolboxVariantElement(elements: variants))))
}
}
Loading