Skip to content

Commit

Permalink
refactor(review): update doc, update minimap MARKs, rmeove typos
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp committed Jan 17, 2025
1 parent 6a0a1fa commit 4e7a324
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ struct ButtonBackgroundModifier: ViewModifier {
// MARK: Body

func body(content: Content) -> some View {
content.background(colorToken.color(for: colorScheme))
content.background(appliedColor.color(for: colorScheme))
}

// MARK: Private helpers

private var colorToken: MultipleColorSemanticTokens {
private var appliedColor: MultipleColorSemanticTokens {
switch state {
case .enabled:
return enabledToken
return enabledColor
case .hover:
return hoverToken
return hoverColor
case .pressed:
return pressedToken
return pressedColor
case .loading:
return loadingToken
return loadingColor
case .disabled:
return disbledToken
return disabledColor
}
}

private var enabledToken: MultipleColorSemanticTokens {
private var enabledColor: MultipleColorSemanticTokens {
switch hierarchy {
case .default:
onColoredSurface ? theme.button.buttonColorBgDefaultEnabledMono : theme.button.buttonColorBgDefaultEnabled
Expand All @@ -64,7 +64,7 @@ struct ButtonBackgroundModifier: ViewModifier {
}
}

private var hoverToken: MultipleColorSemanticTokens {
private var hoverColor: MultipleColorSemanticTokens {
switch hierarchy {
case .default:
onColoredSurface ? theme.button.buttonColorBgDefaultHoverMono : theme.button.buttonColorBgDefaultHover
Expand All @@ -77,7 +77,7 @@ struct ButtonBackgroundModifier: ViewModifier {
}
}

private var pressedToken: MultipleColorSemanticTokens {
private var pressedColor: MultipleColorSemanticTokens {
switch hierarchy {
case .default:
onColoredSurface ? theme.button.buttonColorBgDefaultPressedMono : theme.button.buttonColorBgDefaultPressed
Expand All @@ -90,7 +90,7 @@ struct ButtonBackgroundModifier: ViewModifier {
}
}

private var loadingToken: MultipleColorSemanticTokens {
private var loadingColor: MultipleColorSemanticTokens {
switch hierarchy {
case .default:
onColoredSurface ? theme.button.buttonColorBgDefaultLoadingMono : theme.button.buttonColorBgDefaultLoading
Expand All @@ -103,7 +103,7 @@ struct ButtonBackgroundModifier: ViewModifier {
}
}

private var disbledToken: MultipleColorSemanticTokens {
private var disabledColor: MultipleColorSemanticTokens {
switch hierarchy {
case .default:
onColoredSurface ? theme.button.buttonColorBgDefaultDisabledMono : theme.button.buttonColorBgDefaultDisabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ struct ButtonBorderModifier: ViewModifier {
}
}

// MARK: Private helpers

// MARK: Default hierarchy

private var defaultWidth: BorderWidthSemanticToken {
switch state {
case .enabled:
Expand Down Expand Up @@ -95,6 +94,7 @@ struct ButtonBorderModifier: ViewModifier {
}

// MARK: Minimal hierarchy

private var minimalWidth: BorderWidthSemanticToken {
switch state {
case .enabled:
Expand Down Expand Up @@ -126,6 +126,7 @@ struct ButtonBorderModifier: ViewModifier {
}

// MARK: Strong hierarchy

private var strongColor: MultipleColorSemanticTokens {
switch state {
case .enabled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import OUDSTokensComponent
import OUDSTokensSemantic
import SwiftUI

/// Used to apply the right forgeround color associated to the hierarchy and state
/// Used to apply the right forground color associated to the hierarchy and state
struct ButtonForegroundModifier: ViewModifier {

@Environment(\.theme) private var theme
Expand All @@ -31,29 +31,29 @@ struct ButtonForegroundModifier: ViewModifier {
// MARK: Body

func body(content: Content) -> some View {
content.foregroundStyle(colorToken)
content.foregroundStyle(appliedColor)
}

// MARK: Private helpers

private var colorToken: Color {
private var appliedColor: Color {
switch state {
case .enabled:
enabledToken.color(for: colorScheme)
enabledColor.color(for: colorScheme)
case .hover:
hoverToken.color(for: colorScheme)
hoverColor.color(for: colorScheme)
case .pressed:
pressedToken.color(for: colorScheme)
pressedColor.color(for: colorScheme)
case .loading:
// Hide the content because it is replaced by the loading indicator.
// However the content is nedded to get the size the button in loading state.
// However the content is needed to get the size of the button in loading state.
Color.clear.opacity(0)
case .disabled:
disabledToken.color(for: colorScheme)
disabledColor.color(for: colorScheme)
}
}

private var enabledToken: MultipleColorSemanticTokens {
private var enabledColor: MultipleColorSemanticTokens {
switch hierarchy {
case .default:
onColoredSurface ? theme.button.buttonColorContentDefaultEnabledMono : theme.button.buttonColorContentDefaultEnabled
Expand All @@ -66,7 +66,7 @@ struct ButtonForegroundModifier: ViewModifier {
}
}

private var hoverToken: MultipleColorSemanticTokens {
private var hoverColor: MultipleColorSemanticTokens {
switch hierarchy {
case .default:
onColoredSurface ? theme.button.buttonColorContentDefaultHoverMono : theme.button.buttonColorContentDefaultHover
Expand All @@ -79,7 +79,7 @@ struct ButtonForegroundModifier: ViewModifier {
}
}

private var pressedToken: MultipleColorSemanticTokens {
private var pressedColor: MultipleColorSemanticTokens {
switch hierarchy {
case .default:
onColoredSurface ? theme.button.buttonColorContentDefaultPressedMono : theme.button.buttonColorContentDefaultPressed
Expand All @@ -92,7 +92,7 @@ struct ButtonForegroundModifier: ViewModifier {
}
}

private var disabledToken: MultipleColorSemanticTokens {
private var disabledColor: MultipleColorSemanticTokens {
switch hierarchy {
case .default:
onColoredSurface ? theme.button.buttonColorContentDefaultDisabledMono : theme.button.buttonColorContentDefaultDisabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ import OUDSTokensComponent
import OUDSTokensSemantic
import SwiftUI

// MARK: Loading modifier
// MARK: - Loading indicator

private struct LoagingIndicator: View {

// MARK: Stored Properties

@State private var isAnimating = false
let color: Color

@State private var isAnimating = false

// MARK: Body

var body: some View {
Expand All @@ -40,7 +41,9 @@ private struct LoagingIndicator: View {
}
}

/// Used to add a Progress indicator instead of conent (Text, Icon)
// MARK: - Button Loading Content Modifier

/// Used to add a progress indicator instead of content (Text, Icon)
/// As the button must keep the size of the content, the indicator is
/// added as overlay on top, and the content is hidden applying an opacity.
struct ButtonLoadingContentModifier: ViewModifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ import OUDS
import OUDSTokensSemantic
import SwiftUI

/// The internal state used by modifiers to handle all
/// states of the button.
/// The internal state used by modifiers to handle all states of the button.
enum InternalButtonState {
case enabled, hover, pressed, loading, disabled
}

// MARK: - General modifier
// MARK: - Button View Modifier

/// This modifier has in charge to :
/// - compute the internal state based on `isEnabled`, `isPreessed` and `isHover` flags
/// This modifier has in charge to:
/// - compute the internal state based on `isEnabled`, `isPressed` and `isHover` flags
/// - apply foreground, background colors and add a border (width, radius and color) associated to the hierarchy and according to the internal state
struct ButtonViewModifier: ViewModifier {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import OUDS
import OUDSTokensSemantic
import SwiftUI

/// Used to apply the right style on a `OUDSButton` according to the `hierarchy`
/// Used to apply the right style on an ``OUDSButton`` according to the `hierarchy`
/// and the `style`.
///
/// Four hierarchies are proposed:
Expand All @@ -29,25 +29,27 @@ import SwiftUI
/// - negative: Negative buttons should be used sparingly to warn of a destructive action, for example, delete or remove, typically
/// resulting in the opening of a confirmation dialog.
///
/// Three styles are available:
/// Two styles are available:
/// - normal: is the normal state of a button which can be disabled, pressed, hovered or normal (i.e. enabled)
/// - loading: the style used after button was clicked and probably data are requested before navigate to a next screen or get updated data.
///
struct OUDSButtonStyle: ButtonStyle {

@Environment(\.isEnabled) private var isEnabled

@State private var isHover: Bool

// MARK: Stored Properties

@Environment(\.isEnabled) private var isEnable
private let style: OUDSButton.Style
private let hierarchy: OUDSButton.Hierarchy
@State private var isHover: Bool
private let style: OUDSButton.Style

// MARK: Initializer

/// Initialize the `OUDSButtonStyle` for the `hierarchy`
/// in the `state` of the `OUDSButton`.
///
/// - Parameters:
/// - Parameters:
/// - hierarchy: The button hierarchy
/// - style: The button style
public init(hierarchy: OUDSButton.Hierarchy, style: OUDSButton.Style) {
Expand All @@ -73,8 +75,8 @@ struct OUDSButtonStyle: ButtonStyle {
}
}

func internalState(isPressed: Bool) -> InternalButtonState {
if !isEnable {
private func internalState(isPressed: Bool) -> InternalButtonState {
if !isEnabled {
return .disabled
}

Expand Down
12 changes: 6 additions & 6 deletions OUDS/Core/Components/Sources/Buttons/OUDSButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import SwiftUI
///
/// ## Hierarchies
///
/// Four hieraries are proposed for all layouts:
/// Four hierarchies are proposed for all layouts:
///
/// - **default**: Default buttons are used for actions which are not mandatory or essential for the user.
///
Expand All @@ -28,9 +28,9 @@ import SwiftUI
///
/// - **negative**: Negative buttons should be used sparingly to warn of a destructive action,
/// for example, delete or remove, typically resulting in the opening of a confirmation dialog.
/// A button with [OUDSButton.Hierarchy.Negative] hierarchy is not allowed as a direct or indirect child of an [OUDSColoredSurface].
/// A button with `OUDSButton.Hierarchy.Negative` hierarchy is not allowed as a direct or indirect child of an `OUDSColoredSurface`.
///
/// ```
/// ```swift
/// // Icon only with default hierarchy
/// OUDSButton(hierarchy: .default, icon: Image("ic_heart")) {}
///
Expand All @@ -39,7 +39,6 @@ import SwiftUI
///
/// // Text and icon with strong hierarchy
/// OUDSButton(hierarchy: .strong, icon: Image("ic_heart"), text: "Validate") {}
///
/// ```
///
/// ## Styles
Expand All @@ -53,8 +52,9 @@ import SwiftUI
///
/// If button is placed on colored surface using `OUDSColoredSurface`, the default colors (content, background and border) are automatically adjusted to switch to monochrom.
///
/// **Remark: Today it is not allowed to placed a Negative button on a colored surface.
///
/// **Remark: Today it is not allowed to place a Negative button on a colored surface.**
///
/// - Since: 0.10.0
public struct OUDSButton: View {

// MARK: Stored Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@ The catalog of all components provided by OUDS. It contains also `View` extensio

## Overview

❗More details coming soon.❗
### Buttons

The ``OUDSButton`` propose layout with text only, icon only or text and icon.
Four hierarchies are proposed for all layouts: *default*, *strong*, *minimal* and *negative*.
Two style are available: *default* and *loading*.
If button is placed on colored surface using `OUDSColoredSurface`, the default colors (content, background and border) are automatically adjusted to switch to monochrom.
A button with `OUDSButton.Hierarchy.Negative` hierarchy is not allowed as a direct or indirect child of an `OUDSColoredSurface`.

```swift
// Icon only with default hierarchy
OUDSButton(hierarchy: .default, icon: Image("ic_heart")) {}

// Text only with negative hierarchy
OUDSButton(hierarchy: .negative, text: "Delete") {}

// Text and icon with strong hierarchy
OUDSButton(hierarchy: .strong, icon: Image("ic_heart"), text: "Validate") {}
```

## Customize components

Expand Down Expand Up @@ -85,3 +102,5 @@ The helper is available through `View`, and tokens through the provider of the t
## Topics

### Group

- ``OUDSButton``
14 changes: 9 additions & 5 deletions OUDS/Core/OUDS/Sources/OUDSTheme/OUDSColoredSurface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ import SwiftUI
/// Used to define if a content is used on a colored surface.
///
/// It applies the `color` to the background and set the `oudsOnColoredSurface`
/// environment variable to true. This variable is usefull, for example, to change
/// environment variable to *true*. This variable is usefull, for example, to change
/// the style of a component according to its environment.
///
/// ```swift
/// OUDSColoredSurface(color: .green) {
/// OUDSButton(icon: Image("ic_heart"), hierarchy: .strong, state: .nomal) {}
/// }
/// ```
///
/// - Since: 0.10.0
public struct OUDSColoredSurface<Content>: View where Content: View {

// MARK: Stored Properties
Expand All @@ -37,7 +40,6 @@ public struct OUDSColoredSurface<Content>: View where Content: View {
/// - Parameters:
/// - color: The color applied as background on the content view
/// - content: The content view builder
///
public init(color: Color, @ViewBuilder content: @escaping () -> Content) {
self.color = color
self.content = content
Expand All @@ -53,7 +55,8 @@ public struct OUDSColoredSurface<Content>: View where Content: View {
}

extension View {
/// Helper to set the current view on colored surface based on `OUDSColoredSurface`.

/// Helper to set the current view on colored surface based on ``OUDSColoredSurface``.
///
/// - Parameter color: The color applied as background on the current view.
public func oudsColoredSurface(color: Color) -> some View {
Expand All @@ -71,8 +74,9 @@ private struct ColoredSurfaceClassEnvironmentKey: EnvironmentKey {
}

extension EnvironmentValues {
/// Updated by the `OUDSColoredSurface`, the value tells you if the current view is
/// on a colored surface.

/// Updated by the ``OUDSColoredSurface``, the value tells if the current view is
/// on a colored surface or not.
public var oudsOnColoredSurface: Bool {
get {
self[ColoredSurfaceClassEnvironmentKey.self]
Expand Down
Loading

0 comments on commit 4e7a324

Please sign in to comment.