Skip to content

Commit

Permalink
Update documentation and small refactor to remove theme from public api
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic35 committed Jan 23, 2025
1 parent 3be0e03 commit 70a7fd9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 48 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions OUDS/Core/Components/Sources/Link/Internal/OUDSLinkStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ enum InternalLinkState {

struct OUDSLinkStyle: ButtonStyle {

// MARK: stored properties

@Environment(\.theme) private var theme
@Environment(\.isEnabled) private var isEnabled

@State private var isHover: Bool
let layout: OUDSLink.Layout
let size: OUDSLink.Size
Expand Down Expand Up @@ -55,6 +59,9 @@ struct OUDSLinkStyle: ButtonStyle {
.onHover { isHover in
self.isHover = isHover
}
.padding(.horizontal, theme.link.linkSpacePaddingInline)
.padding(.vertical, theme.link.linkSpacePaddingBlock)
.frame(minWidth: minWidth, minHeight: minHeight)
}

// MARK: Private Helpers
Expand All @@ -74,6 +81,24 @@ struct OUDSLinkStyle: ButtonStyle {

return .enabled
}

private var minWidth: Double {
switch size {
case .small:
theme.link.linkSizeMinWidthSmall
case .medium:
theme.link.linkSizeMinWidthMedium
}
}

private var minHeight: Double {
switch size {
case .small:
theme.link.linkSizeMinHeightSmall
case .medium:
theme.link.linkSizeMinHeightMedium
}
}
}

private struct LinkArrayLabelStyle: LabelStyle {
Expand Down
89 changes: 46 additions & 43 deletions OUDS/Core/Components/Sources/Link/OUDSLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,77 @@
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
//

import Foundation

/// An OUDS link which displays a text and an optional icon.

/// In the case it is used in an [OudsColoredBox], its monochrome variant is automatically displayed.
///
/// The tokens associated with this variant can be customized and are identified with the `Mono` suffix (for instance [OudsLinkTokens.colorContentEnabledMono]).
///
///
import SwiftUI

/// The ``OUDSLink`` proposes layout with text only or text with icon.
/// It also proposes layout to navigate forward or backward. The link can be displayed in `small` or `medium` size.
///
/// ## Text only or Text and icon layout
///
/// This layout is used to open a link or to display a specific feature (like send feedbacks, show more, ...)
///
/// ```swift
/// // Text only in small size
/// OUDSLink(text: "Feedback", size: .small) { /* the action to process */ }
///
/// // Text and icon in medium size
/// OUDSLink(text: "Feedback", icon: Image("ic_heart"), size: .medium) { /* the action to process */ }
/// ```
///
/// ## Navigation layout
///
/// This layout is used to navigatate backward or forward.
///
/// ```swift
/// // Navigate to next page with link in a small size
/// OUDSLink(text: "Feedback", arrow: .next, size: .small) { /* the action to process */ }
///
/// // Navigate to previous page with link in a medium size
/// OUDSLink(text: "Back", arrow: .back, size: .medium) { /* the action to process */ }
/// ```
///
/// ## Colored Surface
///
/// If link is placed on colored surface using `OUDSColoredSurface`, the default colors (content text and icon or arrow) are automatically adjusted to switch to monochrom.
///
/// ## Design documentation
/// [unified-design-system.orange.com/472794e18/p/73c701-components](https://unified-design-system.orange.com/472794e18/p/73c701-components)
///
/// - Since: 0.10.0
public struct OUDSLink: View {

// MARK: Stored Properties

@Environment(\.theme) private var theme

private let layout: Layout
private let text: String
private let size: Size
private let action: () -> Void

/// Represents the size of an OUDS link.
/// Represents the size of an `OUDSLink`.
public enum Size {
case small, medium
}

/// Represents the arrow of an OUDS link.
/// Represents the arrow of an `OUDSLink`.
public enum Arrow {
case back, next
}

public enum Layout {
enum Layout {
case arrow(OUDSLink.Arrow)
case textOnly
case iconAndText(Image)
}

// MARK: Initializers

/// Create a button with text and icon.
///
/// - Parameters:
/// - text: Text displayed in the link
/// - icon: Icon displayed in the link
/// - size: Size of the link
/// - action: The action to perform when the user triggers the button
/// - action: The action to perform when the user triggers the link
public init(text: String, icon: Image? = nil, size: Size = .medium, action: @escaping () -> Void) {
if let icon {
layout = .iconAndText(icon)
Expand All @@ -67,17 +93,15 @@ public struct OUDSLink: View {
self.action = action
}

/// Create a button with an `Arrow` before `OIDSLink.Arrow.back` or after `OUDSLink.Arrow.Next` a text.
/// Create a link with an `Arrow` before `OUDSLink.Arrow.back` or after `OUDSLink.Arrow.Next` the text.
///
/// In the case it is used in an `OUDSColoredSurface`, its monochrome variant is automatically displayed.
/// The tokens associated with this variant can be customized and are identified with the `Mono` suffix (for instance `OUDSLinkTokens.colors.colorContentEnabledMono`.
/// - Parameters:
/// - text: Text displayed in the link
/// - arrow: Arrow displayed in the link.
/// When `OUDSLink.Arrow.Back`, the arrow is displayed before the text.
/// When `OudsLink.Arrow.Next`, the arrow is displayed after the text.
/// - arrow: Arrow displayed in the link
/// When `OUDSLink.Arrow.Back`, the arrow is displayed before the text
/// When `OudsLink.Arrow.Next`, the arrow is displayed after the text
/// - size: Size of the link
/// - action: The action to perform when the user triggers the button
/// - action: The action to perform when the user triggers the link
public init(text: String, arrow: Arrow, size: Size = .medium, action: @escaping () -> Void) {
layout = .arrow(arrow)
self.text = text
Expand Down Expand Up @@ -115,26 +139,5 @@ public struct OUDSLink: View {
}
}
.buttonStyle(OUDSLinkStyle(layout: layout, size: size))
.padding(.horizontal, theme.link.linkSpacePaddingInline)
.padding(.vertical, theme.link.linkSpacePaddingBlock)
.frame(minWidth: minWidth, minHeight: minHeight)
}

private var minWidth: Double {
switch size {
case .small:
theme.link.linkSizeMinWidthSmall
case .medium:
theme.link.linkSizeMinWidthMedium
}
}

private var minHeight: Double {
switch size {
case .small:
theme.link.linkSizeMinHeightSmall
case .medium:
theme.link.linkSizeMinHeightMedium
}
}
}

0 comments on commit 70a7fd9

Please sign in to comment.