Skip to content

Commit

Permalink
fix/popover overlay padding
Browse files Browse the repository at this point in the history
  • Loading branch information
nank1ro committed Jun 21, 2024
1 parent 4a03eb0 commit 488e102
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.5.6

- Fix mismatch of `childAlignment` and `overlayAlignment` in `ShadPortal`
- Remove top padding of `ShadPopover`
- Set default values to `ShadAnchor` and `ShadAnchorAuto`

## 0.5.5

- Remove `inputDecoration` from form fields.
Expand Down
13 changes: 8 additions & 5 deletions lib/src/components/popover.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,20 @@ class _ShadPopoverState extends State<ShadPopover> {
theme.popoverTheme.padding ??
const EdgeInsets.symmetric(horizontal: 12, vertical: 6);
final effectiveShadows = widget.shadows ?? theme.popoverTheme.shadows;
final effectiveDecoration =
var effectiveDecoration =
(theme.popoverTheme.decoration ?? const ShadDecoration())
.mergeWith(widget.decoration)
.copyWith(shadows: effectiveShadows);
// remove the top padding of the popover
effectiveDecoration = effectiveDecoration.copyWith(
secondaryBorder: ShadBorder(
padding: theme.decoration.secondaryBorder?.padding?.copyWith(top: 0),
),
);

final effectiveAnchor = widget.anchor ??
theme.popoverTheme.anchor ??
const ShadAnchorAuto(
verticalOffset: 24,
preferBelow: true,
);
const ShadAnchorAuto(verticalOffset: 24);

Widget popover = ShadDecorator(
decoration: effectiveDecoration,
Expand Down
9 changes: 2 additions & 7 deletions lib/src/components/select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,8 @@ class ShadSelectState<T> extends State<ShadSelect<T>> {
theme.selectTheme.showScrollToBottomChevron ??
true;

final effectiveAnchor = widget.anchor ??
theme.selectTheme.anchor ??
const ShadAnchor(
overlayAlignment: Alignment.bottomLeft,
childAlignment: Alignment.topLeft,
offset: Offset.zero,
);
final effectiveAnchor =
widget.anchor ?? theme.selectTheme.anchor ?? const ShadAnchor();

final Widget effectiveText;
if (selected is T) {
Expand Down
23 changes: 17 additions & 6 deletions lib/src/raw_components/portal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@ sealed class ShadAnchorBase {
/// [preferBelow] properties.
class ShadAnchorAuto extends ShadAnchorBase {
const ShadAnchorAuto({
required this.verticalOffset,
required this.preferBelow,
this.verticalOffset = 0,
this.preferBelow = true,
this.followTargetOnResize = true,
});

/// The vertical offset of the overlay from the start of target widget.
final double verticalOffset;

/// Whether the overlay is displayed below its widget by default, if there is
/// enough space.
final bool preferBelow;

/// Whether the overlay is automatically adjusted to follow the target
/// widget when the target widget moves dues to a window resize.
final bool followTargetOnResize;
}

/// Manually specifies the position of the [ShadPortal] in the global
/// coordinate system.
class ShadAnchor extends ShadAnchorBase {
const ShadAnchor({
required this.childAlignment,
required this.overlayAlignment,
required this.offset,
this.childAlignment = Alignment.topLeft,
this.overlayAlignment = Alignment.bottomLeft,
this.offset = Offset.zero,
});

final Alignment childAlignment;
Expand All @@ -34,7 +43,6 @@ class ShadAnchor extends ShadAnchorBase {
static const center = ShadAnchor(
childAlignment: Alignment.topCenter,
overlayAlignment: Alignment.bottomCenter,
offset: Offset.zero,
);

ShadAnchor copyWith({
Expand Down Expand Up @@ -114,6 +122,9 @@ class _ShadPortalState extends State<ShadPortal> {
BuildContext context,
ShadAnchorAuto anchor,
) {
if (anchor.followTargetOnResize) {
MediaQuery.sizeOf(context);
}
final overlayState = Overlay.of(context, debugRequiredFor: widget);
final box = this.context.findRenderObject()! as RenderBox;
final target = box.localToGlobal(
Expand Down
8 changes: 2 additions & 6 deletions lib/src/theme/themes/component_defaults.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ abstract class ShadDefaultComponentThemes {
color: colorScheme.border,
),
),
anchor: const ShadAnchorAuto(preferBelow: true, verticalOffset: 24),
anchor: const ShadAnchorAuto(verticalOffset: 24),
);
}

Expand Down Expand Up @@ -300,11 +300,7 @@ abstract class ShadDefaultComponentThemes {
optionsPadding: const EdgeInsets.all(4),
showScrollToTopChevron: true,
showScrollToBottomChevron: true,
anchor: const ShadAnchor(
overlayAlignment: Alignment.bottomLeft,
childAlignment: Alignment.topLeft,
offset: Offset.zero,
),
anchor: const ShadAnchor(),
searchPadding: const EdgeInsets.all(12),
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: shadcn_ui
description: shadcn-ui ported in Flutter. Awesome UI components for Flutter, fully customizable.
version: 0.5.5
version: 0.5.6
homepage: https://mariuti.com/shadcn-ui
repository: https://github.com/nank1ro/flutter-shadcn-ui
documentation: https://mariuti.com/shadcn-ui
Expand Down

0 comments on commit 488e102

Please sign in to comment.