-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
305 additions
and
112 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
92 changes: 92 additions & 0 deletions
92
WordPress/Classes/ViewRelated/Stats/Traffic/StatsTrafficDatePickerView.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,92 @@ | ||
import SwiftUI | ||
import DesignSystem | ||
|
||
struct StatsTrafficDatePickerView: View { | ||
@ObservedObject var viewModel: StatsTrafficDatePickerViewModel | ||
|
||
var body: some View { | ||
HStack { | ||
Menu { | ||
ForEach([StatsPeriodUnit.day, .week, .month, .year], id: \.self) { period in | ||
Button(period.label, action: { | ||
viewModel.period = period | ||
}) | ||
} | ||
} label: { | ||
Text(viewModel.period.label) | ||
.style(TextStyle.bodySmall(.emphasized)) | ||
.foregroundColor(Color.DS.Foreground.primary) | ||
Image(systemName: "chevron.down") | ||
.font(.system(size: 8)) | ||
.foregroundColor(Color.DS.Foreground.secondary) | ||
|
||
} | ||
.menuStyle(.borderlessButton) | ||
.padding(.vertical, Length.Padding.single) | ||
.padding(.horizontal, Length.Padding.double) | ||
.background(Color.DS.Background.secondary) | ||
.clipShape(RoundedRectangle(cornerRadius: Length.Radius.max)) | ||
.overlay( | ||
RoundedRectangle(cornerRadius: Length.Radius.max) | ||
.strokeBorder(.clear, lineWidth: 0) | ||
) | ||
|
||
Spacer() | ||
|
||
Text(viewModel.formattedCurrentPeriod()) | ||
.style(TextStyle.bodySmall(.emphasized)) | ||
.foregroundColor(Color.DS.Foreground.primary) | ||
.lineLimit(1) | ||
|
||
Spacer().frame(width: Length.Padding.split) | ||
|
||
Button(action: { | ||
viewModel.goToPreviousPeriod() | ||
}) { | ||
Image(systemName: "chevron.left") | ||
.imageScale(.small) | ||
.foregroundColor(Color.DS.Foreground.secondary) | ||
.flipsForRightToLeftLayoutDirection(true) | ||
} | ||
.padding(.trailing, Length.Padding.single) | ||
|
||
let isNextDisabled = !viewModel.isNextPeriodAvailable | ||
let enabledColor = Color.DS.Foreground.secondary | ||
let disabledColor = enabledColor.opacity(0.5) | ||
|
||
Button(action: { | ||
viewModel.goToNextPeriod() | ||
}) { | ||
Image(systemName: "chevron.right") | ||
.imageScale(.small) | ||
.foregroundColor(isNextDisabled ? disabledColor : enabledColor) | ||
.flipsForRightToLeftLayoutDirection(true) | ||
} | ||
.disabled(isNextDisabled) | ||
}.padding(.vertical, Length.Padding.single) | ||
.padding(.horizontal, Length.Padding.double) | ||
.background(Color.DS.Background.primary) | ||
.overlay( | ||
Rectangle() | ||
.frame(height: Length.Border.thin) | ||
.foregroundColor(Color.DS.Foreground.tertiary), | ||
alignment: .bottom | ||
) | ||
.background(Color.DS.Background.secondary) | ||
} | ||
} | ||
|
||
private extension StatsPeriodUnit { | ||
var label: String { | ||
switch self { | ||
case .day: | ||
return NSLocalizedString("stats.traffic.day", value: "By day", comment: "The label for the option to show Stats Traffic by day.") | ||
case .week: | ||
return NSLocalizedString("stats.traffic.week", value: "By week", comment: "The label for the option to show Stats Traffic by week.") | ||
case .month: | ||
return NSLocalizedString("stats.traffic.month", value: "By month", comment: "The label for the option to show Stats Traffic by month.") | ||
case .year: | ||
return NSLocalizedString("stats.traffic.year", value: "By year", comment: "The label for the option to show Stats Traffic by year.") | ||
} | ||
} | ||
} |
Oops, something went wrong.