Skip to content

Commit

Permalink
refactor: order policy option theme (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
nank1ro authored Jan 23, 2025
1 parent 2d4ca60 commit 636d9cd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- **FIX**: Improve `ShadAvatar` (thanks to @mickey35vn).
- **FIX**: Locale not handled in `ShadCalendar` and `ShadDatePicker`.
- **REFACTOR**: Remove `optionsOrderPolicy` from `ShadSelectTheme` and move it to `ShadOptionTheme` with the name `orderPolicy`.

## 0.18.2

Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ class _ShadOptionState<T> extends State<ShadOption<T>> {
widget.radius ?? theme.optionTheme.radius ?? theme.radius;

final effectiveOrderPolicy = widget.orderPolicy ??
theme.selectTheme.optionsOrderPolicy ??
theme.optionTheme.orderPolicy ??
const WidgetOrderPolicy.linear();

final effectiveSelectedIcon = widget.selectedIcon ??
Expand Down
15 changes: 13 additions & 2 deletions lib/src/theme/components/option.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/src/utils/extensions/order_policy.dart';

@immutable
class ShadOptionTheme {
Expand All @@ -7,6 +8,7 @@ class ShadOptionTheme {
this.hoveredBackgroundColor,
this.padding,
this.radius,
this.orderPolicy,
});

final bool merge;
Expand All @@ -15,6 +17,9 @@ class ShadOptionTheme {
final EdgeInsets? padding;
final BorderRadius? radius;

/// {@macro ShadOption.orderPolicy}
final WidgetOrderPolicy? orderPolicy;

static ShadOptionTheme lerp(
ShadOptionTheme a,
ShadOptionTheme b,
Expand All @@ -27,6 +32,7 @@ class ShadOptionTheme {
Color.lerp(a.hoveredBackgroundColor, b.hoveredBackgroundColor, t),
padding: EdgeInsets.lerp(a.padding, b.padding, t),
radius: BorderRadius.lerp(a.radius, b.radius, t),
orderPolicy: t < 0.5 ? a.orderPolicy : b.orderPolicy,
);
}

Expand All @@ -35,13 +41,15 @@ class ShadOptionTheme {
Color? hoveredBackgroundColor,
EdgeInsets? padding,
BorderRadius? radius,
WidgetOrderPolicy? orderPolicy,
}) {
return ShadOptionTheme(
merge: merge ?? this.merge,
hoveredBackgroundColor:
hoveredBackgroundColor ?? this.hoveredBackgroundColor,
padding: padding ?? this.padding,
radius: radius ?? this.radius,
orderPolicy: orderPolicy ?? this.orderPolicy,
);
}

Expand All @@ -52,6 +60,7 @@ class ShadOptionTheme {
hoveredBackgroundColor: other.hoveredBackgroundColor,
padding: other.padding,
radius: other.radius,
orderPolicy: other.orderPolicy,
);
}

Expand All @@ -63,14 +72,16 @@ class ShadOptionTheme {
other.merge == merge &&
other.hoveredBackgroundColor == hoveredBackgroundColor &&
other.padding == padding &&
other.radius == radius;
other.radius == radius &&
other.orderPolicy == orderPolicy;
}

@override
int get hashCode {
return merge.hashCode ^
hoveredBackgroundColor.hashCode ^
padding.hashCode ^
radius.hashCode;
radius.hashCode ^
orderPolicy.hashCode;
}
}
13 changes: 2 additions & 11 deletions lib/src/theme/components/select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ShadSelectTheme {
this.effects,
this.shadows,
this.filter,
this.optionsOrderPolicy,
});

final bool merge;
Expand All @@ -52,9 +51,6 @@ class ShadSelectTheme {
/// {@macro popover.shadows}
final List<BoxShadow>? shadows;

/// {@macro ShadOption.orderPolicy}
final WidgetOrderPolicy? optionsOrderPolicy;

static ShadSelectTheme lerp(
ShadSelectTheme a,
ShadSelectTheme b,
Expand All @@ -78,7 +74,6 @@ class ShadSelectTheme {
clearSearchOnClose: t < 0.5 ? a.clearSearchOnClose : b.clearSearchOnClose,
effects: t < 0.5 ? a.effects : b.effects,
shadows: t < 0.5 ? a.shadows : b.shadows,
optionsOrderPolicy: t < .5 ? a.optionsOrderPolicy : b.optionsOrderPolicy,
);
}

Expand Down Expand Up @@ -120,7 +115,6 @@ class ShadSelectTheme {
effects: effects ?? this.effects,
shadows: shadows ?? this.shadows,
filter: filter ?? this.filter,
optionsOrderPolicy: optionsOrderPolicy ?? this.optionsOrderPolicy,
);
}

Expand All @@ -142,7 +136,6 @@ class ShadSelectTheme {
effects: other.effects,
shadows: other.shadows,
filter: other.filter,
optionsOrderPolicy: other.optionsOrderPolicy,
);
}

Expand All @@ -165,8 +158,7 @@ class ShadSelectTheme {
other.clearSearchOnClose == clearSearchOnClose &&
other.effects == effects &&
other.shadows == shadows &&
other.filter == filter &&
other.optionsOrderPolicy == optionsOrderPolicy;
other.filter == filter;
}

@override
Expand All @@ -185,7 +177,6 @@ class ShadSelectTheme {
clearSearchOnClose.hashCode ^
effects.hashCode ^
shadows.hashCode ^
filter.hashCode ^
optionsOrderPolicy.hashCode;
filter.hashCode;
}
}

0 comments on commit 636d9cd

Please sign in to comment.