Skip to content

Commit

Permalink
Make radius configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Jul 15, 2024
1 parent 9ae0eb9 commit 81697d8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 6 additions & 0 deletions forui/lib/src/widgets/calendar/day/day_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ final class FCalendarDayPickerStyle with Diagnosticable {
selectedStyle: FCalendarEntryStyle(
backgroundColor: colorScheme.primaryForeground,
textStyle: mutedTextStyle,
radius: const Radius.circular(4),
),
unselectedStyle: FCalendarEntryStyle(
backgroundColor: colorScheme.background,
textStyle: mutedTextStyle,
radius: const Radius.circular(4),
),
);

Expand All @@ -227,22 +229,26 @@ final class FCalendarDayPickerStyle with Diagnosticable {
selectedStyle: FCalendarEntryStyle(
backgroundColor: colorScheme.foreground,
textStyle: typography.sm.copyWith(color: colorScheme.background, fontWeight: FontWeight.w500),
radius: const Radius.circular(4),
),
unselectedStyle: FCalendarEntryStyle(
backgroundColor: colorScheme.background,
textStyle: textStyle,
focusedBackgroundColor: colorScheme.secondary,
radius: const Radius.circular(4),
),
),
enclosing: FCalendarDayStyle(
selectedStyle: FCalendarEntryStyle(
backgroundColor: colorScheme.primaryForeground,
textStyle: mutedTextStyle,
radius: const Radius.circular(4),
),
unselectedStyle: FCalendarEntryStyle(
backgroundColor: colorScheme.background,
textStyle: mutedTextStyle,
focusedBackgroundColor: colorScheme.primaryForeground,
radius: const Radius.circular(4),
),
),
),
Expand Down
24 changes: 18 additions & 6 deletions forui/lib/src/widgets/calendar/shared/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ abstract class Entry extends StatelessWidget {
Widget builder(BuildContext context, bool focused, Widget? child) => _Content(
style: entryStyle,
borderRadius: BorderRadius.horizontal(
left: selected(date.yesterday) ? Radius.zero : const Radius.circular(4),
right: selected(date.tomorrow) ? Radius.zero : const Radius.circular(4),
left: selected(date.yesterday) ? Radius.zero : entryStyle.radius,
right: selected(date.tomorrow) ? Radius.zero : entryStyle.radius,
),
text: '${date.day}', // TODO: localization
focused: focused,
Expand Down Expand Up @@ -76,7 +76,7 @@ abstract class Entry extends StatelessWidget {
// ignore: avoid_positional_boolean_parameters
Widget builder(BuildContext context, bool focused, Widget? child) => _Content(
style: entryStyle,
borderRadius: BorderRadius.circular(8),
borderRadius: BorderRadius.all(entryStyle.radius),
text: format(date),
focused: focused,
current: current,
Expand Down Expand Up @@ -221,10 +221,14 @@ final class FCalendarEntryStyle with Diagnosticable {
/// The focused day's text style. Defaults to [textStyle].
final TextStyle focusedTextStyle;

/// The entry border's radius. Defaults to `Radius.circular(4)`.
final Radius radius;

/// Creates a [FCalendarEntryStyle].
FCalendarEntryStyle({
required this.backgroundColor,
required this.textStyle,
required this.radius,
Color? focusedBackgroundColor,
TextStyle? focusedTextStyle,
}) : focusedBackgroundColor = focusedBackgroundColor ?? backgroundColor,
Expand All @@ -250,12 +254,14 @@ final class FCalendarEntryStyle with Diagnosticable {
TextStyle? textStyle,
Color? focusedBackgroundColor,
TextStyle? focusedTextStyle,
Radius? radius,
}) =>
FCalendarEntryStyle(
backgroundColor: backgroundColor ?? this.backgroundColor,
textStyle: textStyle ?? this.textStyle,
focusedBackgroundColor: focusedBackgroundColor ?? this.focusedBackgroundColor,
focusedTextStyle: focusedTextStyle ?? this.focusedTextStyle,
radius: radius ?? this.radius,
);

@override
Expand All @@ -265,7 +271,8 @@ final class FCalendarEntryStyle with Diagnosticable {
..add(ColorProperty('backgroundColor', backgroundColor))
..add(DiagnosticsProperty('textStyle', textStyle))
..add(ColorProperty('focusedBackgroundColor', focusedBackgroundColor))
..add(DiagnosticsProperty('focusedTextStyle', focusedTextStyle));
..add(DiagnosticsProperty('focusedTextStyle', focusedTextStyle))
..add(DiagnosticsProperty('radius', radius));
}

@override
Expand All @@ -276,9 +283,14 @@ final class FCalendarEntryStyle with Diagnosticable {
backgroundColor == other.backgroundColor &&
textStyle == other.textStyle &&
focusedBackgroundColor == other.focusedBackgroundColor &&
focusedTextStyle == other.focusedTextStyle;
focusedTextStyle == other.focusedTextStyle &&
radius == other.radius;

@override
int get hashCode =>
backgroundColor.hashCode ^ textStyle.hashCode ^ focusedBackgroundColor.hashCode ^ focusedTextStyle.hashCode;
backgroundColor.hashCode ^
textStyle.hashCode ^
focusedBackgroundColor.hashCode ^
focusedTextStyle.hashCode ^
radius.hashCode;
}
2 changes: 2 additions & 0 deletions forui/lib/src/widgets/calendar/year_month_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ final class FCalendarYearMonthPickerStyle with Diagnosticable {
backgroundColor: colorScheme.background,
textStyle: typography.sm.copyWith(color: colorScheme.foreground, fontWeight: FontWeight.w500),
focusedBackgroundColor: colorScheme.secondary,
radius: const Radius.circular(8),
),
disabledStyle: FCalendarEntryStyle(
backgroundColor: colorScheme.background,
textStyle: typography.sm
.copyWith(color: colorScheme.mutedForeground.withOpacity(0.5), fontWeight: FontWeight.w500),
radius: const Radius.circular(8),
),
);

Expand Down

0 comments on commit 81697d8

Please sign in to comment.