-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use view extensions to configure and style the text editor
- Loading branch information
1 parent
4d3cb44
commit 2ba2b51
Showing
7 changed files
with
122 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// RichTextEditor+Config.swift | ||
// RichTextKit | ||
// | ||
// Created by Daniel Saidi on 2024-02-24. | ||
// Copyright © 2024 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
#if iOS || macOS || os(visionOS) | ||
import SwiftUI | ||
|
||
/// This struct be used to configure a ``RichTextEditor``. | ||
public typealias RichTextEditorConfig = RichTextView.Configuration | ||
|
||
public extension View { | ||
|
||
/// Apply a ``RichTextEditor`` configuration. | ||
func richTextEditorConfig( | ||
_ config: RichTextEditorConfig | ||
) -> some View { | ||
self.environment(\.richTextEditorConfig, config) | ||
} | ||
} | ||
|
||
extension RichTextEditorConfig { | ||
|
||
struct Key: EnvironmentKey { | ||
|
||
public static var defaultValue: RichTextEditorConfig = .standard | ||
} | ||
} | ||
|
||
public extension EnvironmentValues { | ||
|
||
var richTextEditorConfig: RichTextEditorConfig { | ||
get { self [RichTextEditorConfig.Key.self] } | ||
set { self [RichTextEditorConfig.Key.self] = newValue } | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// RichTextEditor+Style.swift | ||
// RichTextKit | ||
// | ||
// Created by Ryan Jarvis on 2024-02-24. | ||
// | ||
|
||
|
||
#if iOS || macOS || os(visionOS) | ||
import SwiftUI | ||
|
||
/// This struct can be used to style a ``RichTextEditor``. | ||
public typealias RichTextEditorStyle = RichTextView.Theme | ||
|
||
public extension View { | ||
|
||
/// Apply a ``RichTextEditor`` style. | ||
func richTextEditorStyle( | ||
_ style: RichTextEditorStyle | ||
) -> some View { | ||
self.environment(\.richTextEditorStyle, style) | ||
} | ||
} | ||
|
||
extension RichTextEditorStyle { | ||
|
||
struct Key: EnvironmentKey { | ||
|
||
static var defaultValue: RichTextEditorStyle = .standard | ||
} | ||
} | ||
|
||
public extension EnvironmentValues { | ||
|
||
var richTextEditorStyle: RichTextEditorStyle { | ||
get { self [RichTextEditorStyle.Key.self] } | ||
set { self [RichTextEditorStyle.Key.self] = newValue } | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters