| 143 | // MARK: - Primary (Prominent) Button |
| 144 | |
| 145 | struct GlassButtonStyle: ButtonStyle { |
| 146 | var height: CGFloat? = nil |
| 147 | |
| 148 | func makeBody(configuration: Configuration) -> some View { |
| 149 | GlassButton(configuration: configuration, height: self.height) |
| 150 | } |
| 151 | |
| 152 | private struct GlassButton: View { |
| 153 | @Environment(\.theme) private var theme |
| 154 | @State private var isHovered = false |
| 155 | let configuration: ButtonStyle.Configuration |
| 156 | let height: CGFloat? |
| 157 | |
| 158 | private var shape: RoundedRectangle { |
| 159 | RoundedRectangle(cornerRadius: self.theme.metrics.corners.md, style: .continuous) |
| 160 | } |
| 161 | |
| 162 | var body: some View { |
| 163 | self.configuration.label |
| 164 | .fontWeight(.semibold) |
| 165 | .padding(.horizontal, self.theme.metrics.spacing.lg) |
| 166 | .padding(.vertical, self.theme.metrics.spacing.sm) |
| 167 | .frame(height: self.height ?? 36) |
| 168 | .foregroundStyle(self.theme.palette.primaryText) |
| 169 | .background(self.theme.materials.card, in: self.shape) |
| 170 | .background( |
| 171 | self.shape |
| 172 | .fill(self.theme.palette.cardBackground) |
| 173 | .overlay( |
| 174 | self.shape.stroke( |
| 175 | self.theme.palette.cardBorder.opacity(self.isHovered ? 0.45 : 0.25), |
| 176 | lineWidth: 1 |
| 177 | ) |
| 178 | ) |
| 179 | ) |
| 180 | .overlay( |
| 181 | self.shape |
| 182 | .stroke(self.theme.palette.accent.opacity(self.isHovered ? 0.25 : 0.1), lineWidth: 1) |
| 183 | .blendMode(.plusLighter) |
| 184 | ) |
| 185 | .shadow( |
| 186 | color: self.theme.palette.cardBorder.opacity(self.isHovered ? 0.45 : 0.22), |
| 187 | radius: self.isHovered ? self.theme.metrics.cardShadow.radius : max(self.theme.metrics.cardShadow.radius - 3, 2), |
| 188 | x: 0, |
| 189 | y: self.isHovered ? self.theme.metrics.cardShadow.y : self.theme.metrics.cardShadow.y - 2 |
| 190 | ) |
| 191 | .scaleEffect(FluidInteractionVisuals.scale(isPressed: self.configuration.isPressed, isHovered: self.isHovered)) |
| 192 | .animation(FluidInteractionVisuals.hoverAnimation, value: self.isHovered) |
| 193 | .animation(FluidInteractionVisuals.pressedAnimation, value: self.configuration.isPressed) |
| 194 | .onHover { self.isHovered = $0 } |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // MARK: - Primary Accent Button |
| 200 |
no outgoing calls
no test coverage detected