Skip to content

Commit

Permalink
Merge pull request #12 from Cement-Labs/environments
Browse files Browse the repository at this point in the history
Environments
  • Loading branch information
KrLite authored Dec 6, 2024
2 parents 022e132 + d02208c commit 8495ef0
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 716 deletions.
6 changes: 0 additions & 6 deletions .swiftlint.yml

This file was deleted.

58 changes: 32 additions & 26 deletions Sources/Luminare/Components/Auxiliary/LuminareButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public struct LuminareButtonStyle: ButtonStyle {
@Environment(\.luminareAnimationFast) private var animationFast
@Environment(\.luminareMinHeight) private var minHeight
@Environment(\.luminareButtonMaterial) private var material
@Environment(\.luminareButtonCornerRadius) private var buttonCornerRadius
@Environment(\.luminareButtonCornerRadius) private var cornerRadius
@Environment(\.luminareButtonHighlightOnHover) private var highlightOnHover

@State private var isHovering: Bool = false

Expand All @@ -43,14 +44,14 @@ public struct LuminareButtonStyle: ButtonStyle {
.opacity(isEnabled ? 1 : 0.5)
.background(with: material) {
LuminareProminentButtonStyle.tintedBackgroundForState(
isPressed: configuration.isPressed, isEnabled: isEnabled, isHovering: isHovering,
isPressed: configuration.isPressed, isEnabled: isEnabled, isHovering: highlightOnHover && isHovering,
styles: (
.quaternary, .quaternary.opacity(0.7), .quinary
)
)
.opacity(isEnabled ? 1 : 0.5)
}
.clipShape(.rect(cornerRadius: buttonCornerRadius))
.clipShape(.rect(cornerRadius: cornerRadius))
}
}

Expand All @@ -64,7 +65,8 @@ public struct LuminareDestructiveButtonStyle: ButtonStyle {
@Environment(\.luminareAnimationFast) private var animationFast
@Environment(\.luminareMinHeight) private var minHeight
@Environment(\.luminareButtonMaterial) private var material
@Environment(\.luminareButtonCornerRadius) private var buttonCornerRadius
@Environment(\.luminareButtonCornerRadius) private var cornerRadius
@Environment(\.luminareButtonHighlightOnHover) private var highlightOnHover

@State private var isHovering: Bool = false

Expand All @@ -90,12 +92,12 @@ public struct LuminareDestructiveButtonStyle: ButtonStyle {
.opacity(isEnabled ? 1 : 0.5)
.background(with: material) {
LuminareProminentButtonStyle.tintedBackgroundForState(
isPressed: configuration.isPressed, isEnabled: isEnabled, isHovering: isHovering,
isPressed: configuration.isPressed, isEnabled: isEnabled, isHovering: highlightOnHover && isHovering,
layered: .red
)
.opacity(isEnabled ? 1 : 0.5)
}
.clipShape(.rect(cornerRadius: buttonCornerRadius))
.clipShape(.rect(cornerRadius: cornerRadius))
}
}

Expand All @@ -111,7 +113,8 @@ public struct LuminareProminentButtonStyle: ButtonStyle {
@Environment(\.luminareAnimationFast) private var animationFast
@Environment(\.luminareMinHeight) private var minHeight
@Environment(\.luminareButtonMaterial) private var material
@Environment(\.luminareButtonCornerRadius) private var buttonCornerRadius
@Environment(\.luminareButtonCornerRadius) private var cornerRadius
@Environment(\.luminareButtonHighlightOnHover) private var highlightOnHover

@State private var isHovering: Bool = false

Expand All @@ -137,12 +140,12 @@ public struct LuminareProminentButtonStyle: ButtonStyle {
.opacity(isEnabled ? 1 : 0.5)
.background(with: material) {
LuminareProminentButtonStyle.tintedBackgroundForState(
isPressed: configuration.isPressed, isEnabled: isEnabled, isHovering: isHovering,
isPressed: configuration.isPressed, isEnabled: isEnabled, isHovering: highlightOnHover && isHovering,
layered: .tint
)
.opacity(isEnabled ? 1 : 0.5)
}
.clipShape(.rect(cornerRadius: buttonCornerRadius))
.clipShape(.rect(cornerRadius: cornerRadius))
}

@ViewBuilder static func tintedBackgroundForState(
Expand Down Expand Up @@ -185,7 +188,8 @@ public struct LuminareCosmeticButtonStyle: ButtonStyle {
@Environment(\.luminareAnimationFast) private var animationFast
@Environment(\.luminareMinHeight) private var minHeight
@Environment(\.luminareButtonMaterial) private var material
@Environment(\.luminareButtonCornerRadius) private var buttonCornerRadius
@Environment(\.luminareButtonCornerRadius) private var cornerRadius
@Environment(\.luminareButtonHighlightOnHover) private var highlightOnHover

@ViewBuilder private let icon: () -> Image

Expand Down Expand Up @@ -223,7 +227,7 @@ public struct LuminareCosmeticButtonStyle: ButtonStyle {
.opacity(isEnabled ? 1 : 0.5)
.background(with: material) {
LuminareProminentButtonStyle.tintedBackgroundForState(
isPressed: configuration.isPressed, isEnabled: isEnabled, isHovering: isHovering,
isPressed: configuration.isPressed, isEnabled: isEnabled, isHovering: highlightOnHover && isHovering,
styles: (
.quaternary, .quaternary.opacity(0.7), .clear
)
Expand All @@ -240,7 +244,7 @@ public struct LuminareCosmeticButtonStyle: ButtonStyle {
.padding(24)
.allowsHitTesting(false)
}
.clipShape(.rect(cornerRadius: buttonCornerRadius))
.clipShape(.rect(cornerRadius: cornerRadius))
}
}

Expand All @@ -256,7 +260,8 @@ public struct LuminareCompactButtonStyle: ButtonStyle {
@Environment(\.luminareAnimationFast) private var animationFast
@Environment(\.luminareMinHeight) private var minHeight
@Environment(\.luminareButtonMaterial) private var material
@Environment(\.luminareCompactButtonCornerRadius) private var buttonCornerRadius
@Environment(\.luminareCompactButtonCornerRadius) private var cornerRadius
@Environment(\.luminareButtonHighlightOnHover) private var highlightOnHover

private let extraCompact: Bool

Expand Down Expand Up @@ -289,14 +294,14 @@ public struct LuminareCompactButtonStyle: ButtonStyle {
.opacity(isEnabled ? 1 : 0.5)
.background(with: material) {
LuminareProminentButtonStyle.tintedBackgroundForState(
isPressed: configuration.isPressed, isEnabled: isEnabled, isHovering: isHovering,
isPressed: configuration.isPressed, isEnabled: isEnabled, isHovering: highlightOnHover && isHovering,
styles: (
.quaternary, .quaternary.opacity(0.7), .quinary
)
)
.opacity(isEnabled ? 1 : 0.5)
}
.clipShape(.rect(cornerRadius: buttonCornerRadius))
.clipShape(.rect(cornerRadius: cornerRadius))
.background(border())
.fixedSize(horizontal: extraCompact, vertical: extraCompact)
.onHover { hover in
Expand All @@ -310,9 +315,9 @@ public struct LuminareCompactButtonStyle: ButtonStyle {
@ViewBuilder private func border() -> some View {
Group {
if isHovering {
RoundedRectangle(cornerRadius: buttonCornerRadius).strokeBorder(.quaternary)
RoundedRectangle(cornerRadius: cornerRadius).strokeBorder(.quaternary)
} else {
RoundedRectangle(cornerRadius: buttonCornerRadius).strokeBorder(.quaternary.opacity(0.7))
RoundedRectangle(cornerRadius: cornerRadius).strokeBorder(.quaternary.opacity(0.7))
}
}
}
Expand All @@ -333,15 +338,15 @@ public struct LuminareCompactButtonStyle: ButtonStyle {
/// }
public struct LuminareBordered: ViewModifier {
@Environment(\.luminareButtonMaterial) private var material
@Environment(\.luminareButtonCornerRadius) private var buttonCornerRadius
@Environment(\.luminareButtonCornerRadius) private var cornerRadius

private let isHighlighted: Bool

/// Initializes a ``LuminareBordered``.
///
/// - Parameters:
/// - isHighlighted: whether to display a highlighted overlay.
/// - buttonCornerRadius: the corner radius of the button.
/// - cornerRadius: the corner radius of the button.
public init(
isHighlighted: Bool = false
) {
Expand All @@ -357,9 +362,9 @@ public struct LuminareBordered: ViewModifier {
Rectangle().foregroundStyle(.quinary)
}
}
.clipShape(.rect(cornerRadius: buttonCornerRadius))
.clipShape(.rect(cornerRadius: cornerRadius))
.background {
RoundedRectangle(cornerRadius: buttonCornerRadius)
RoundedRectangle(cornerRadius: cornerRadius)
.strokeBorder(.quaternary)
}
}
Expand All @@ -384,7 +389,8 @@ public struct LuminareHoverable: ViewModifier {
@Environment(\.luminareHorizontalPadding) private var horizontalPadding
@Environment(\.luminareIsBordered) private var isBordered
@Environment(\.luminareButtonMaterial) private var material
@Environment(\.luminareCompactButtonCornerRadius) private var buttonCornerRadius
@Environment(\.luminareCompactButtonCornerRadius) private var cornerRadius
@Environment(\.luminareButtonHighlightOnHover) private var highlightOnHover

@State private var isHovering: Bool = false

Expand All @@ -408,21 +414,21 @@ public struct LuminareHoverable: ViewModifier {
.frame(minHeight: minHeight)
.padding(.horizontal, horizontalPadding)
.background(with: material) {
if isHovering {
if highlightOnHover, isHovering {
Rectangle()
.foregroundStyle(.quinary)
} else {
Rectangle()
.foregroundStyle(.clear)
}
}
.clipShape(.rect(cornerRadius: buttonCornerRadius))
.clipShape(.rect(cornerRadius: cornerRadius))
.background {
if isHovering {
RoundedRectangle(cornerRadius: buttonCornerRadius)
RoundedRectangle(cornerRadius: cornerRadius)
.strokeBorder(.quaternary)
} else if isBordered {
RoundedRectangle(cornerRadius: buttonCornerRadius)
RoundedRectangle(cornerRadius: cornerRadius)
.strokeBorder(.quaternary.opacity(0.7))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct ColorPickerModalView<R, G, B, Done>: View where R: View, G: View, B: View
// main view containing all components of the color picker
var body: some View {
Group {
LuminareSection(hasPadding: false, hasDividers: false) {
LuminareSection(hasPadding: false) {
VStack(spacing: 2) {
ColorSaturationBrightnessView(selectedColor: $selectedColor)
.scaledToFill()
Expand All @@ -73,6 +73,7 @@ struct ColorPickerModalView<R, G, B, Done>: View where R: View, G: View, B: View
}
.padding(4)
}
.luminareHasDividers(false)

RGBInputFields

Expand Down
Loading

0 comments on commit 8495ef0

Please sign in to comment.