-
-
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.
Make format toolbar and sidebar share styles, configurations and views
- Loading branch information
1 parent
91ea919
commit fb7d7ec
Showing
13 changed files
with
378 additions
and
257 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
55 changes: 55 additions & 0 deletions
55
Sources/RichTextKit/Format/RichTextFormatToolbar+Configuration.swift
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,55 @@ | ||
// | ||
// RichTextFormatToolbar+Configuration.swift | ||
// RichTextKit | ||
// | ||
// Created by Daniel Saidi on 2024-02-16. | ||
// Copyright © 2024 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension RichTextFormatToolbar { | ||
|
||
/// This struct can be used to configure a format sheet. | ||
struct Configuration { | ||
|
||
public init( | ||
alignments: [RichTextAlignment] = .all, | ||
colorPickers: [RichTextColor] = [.foreground], | ||
colorPickersDisclosed: [RichTextColor] = [], | ||
fontPicker: Bool = true, | ||
fontSizePicker: Bool = true, | ||
indentButtons: Bool = true, | ||
styles: [RichTextStyle] = .all, | ||
superscriptButtons: Bool = true | ||
) { | ||
self.alignments = alignments | ||
self.colorPickers = colorPickers | ||
self.colorPickersDisclosed = colorPickersDisclosed | ||
self.fontPicker = fontPicker | ||
self.fontSizePicker = fontSizePicker | ||
self.indentButtons = indentButtons | ||
self.styles = styles | ||
#if macOS | ||
self.superscriptButtons = superscriptButtons | ||
#else | ||
self.superscriptButtons = false | ||
#endif | ||
} | ||
|
||
public var alignments: [RichTextAlignment] | ||
public var colorPickers: [RichTextColor] | ||
public var colorPickersDisclosed: [RichTextColor] | ||
public var fontPicker: Bool | ||
public var fontSizePicker: Bool | ||
public var indentButtons: Bool | ||
public var styles: [RichTextStyle] | ||
public var superscriptButtons: Bool | ||
} | ||
} | ||
|
||
public extension RichTextFormatToolbar.Configuration { | ||
|
||
/// The standard rich text format toolbar configuration. | ||
static var standard = Self.init() | ||
} |
58 changes: 58 additions & 0 deletions
58
Sources/RichTextKit/Format/RichTextFormatToolbar+Style.swift
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,58 @@ | ||
// | ||
// RichTextFormatToolbar+Style.swift | ||
// RichTextKit | ||
// | ||
// Created by Daniel Saidi on 2024-02-16. | ||
// Copyright © 2024 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension RichTextFormatToolbar { | ||
|
||
/// This struct can be used to style a format sheet. | ||
/// | ||
/// Don't specify a font picker height if the toolbar is | ||
/// used in a sheet. Use detents to the toolbar's height. | ||
struct Style { | ||
|
||
public init( | ||
fontPickerHeight: CGFloat? = nil, | ||
padding: Double = 10, | ||
spacing: Double = 10 | ||
) { | ||
self.fontPickerHeight = fontPickerHeight | ||
self.padding = padding | ||
self.spacing = spacing | ||
} | ||
|
||
public var fontPickerHeight: CGFloat? | ||
public var padding: Double | ||
public var spacing: Double | ||
} | ||
|
||
/// This environment key defines a format toolbar style. | ||
struct StyleKey: EnvironmentKey { | ||
|
||
public static let defaultValue = RichTextFormatToolbar.Style() | ||
} | ||
} | ||
|
||
public extension View { | ||
|
||
/// Apply a rich text format toolbar style. | ||
func richTextFormatToolbarStyle( | ||
_ style: RichTextFormatToolbar.Style | ||
) -> some View { | ||
self.environment(\.richTextFormatToolbarStyle, style) | ||
} | ||
} | ||
|
||
public extension EnvironmentValues { | ||
|
||
/// This environment value defines format toolbar styles. | ||
var richTextFormatToolbarStyle: RichTextFormatToolbar.Style { | ||
get { self [RichTextFormatToolbar.StyleKey.self] } | ||
set { self [RichTextFormatToolbar.StyleKey.self] = newValue } | ||
} | ||
} |
Oops, something went wrong.