From 676468dc7ccfc37bb2719d5ac55ac263adcd9964 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 15 Dec 2024 07:35:47 +0530 Subject: [PATCH] Add ADPopupMenu --- .../lib/widgets/popup_menu.dart | 74 +++++++++++++++++++ .../lib/widgets/widgets.dart | 1 + 2 files changed, 75 insertions(+) create mode 100644 packages/apidash_design_system/lib/widgets/popup_menu.dart diff --git a/packages/apidash_design_system/lib/widgets/popup_menu.dart b/packages/apidash_design_system/lib/widgets/popup_menu.dart new file mode 100644 index 00000000..06adea10 --- /dev/null +++ b/packages/apidash_design_system/lib/widgets/popup_menu.dart @@ -0,0 +1,74 @@ +import 'package:flutter/material.dart'; +import '../tokens/tokens.dart'; + +class ADPopupMenu extends StatelessWidget { + const ADPopupMenu({ + super.key, + this.value, + required this.values, + this.onChanged, + this.tooltip, + this.width, + this.isOutlined = false, + }); + + final String? value; + final Iterable<(T, String?)> values; + final void Function(T? value)? onChanged; + final String? tooltip; + final double? width; + final bool isOutlined; + + @override + Widget build(BuildContext context) { + final double containerWidth = width ?? 220; + var popup = PopupMenuButton( + tooltip: tooltip, + surfaceTintColor: kColorTransparent, + constraints: BoxConstraints(minWidth: containerWidth), + itemBuilder: (BuildContext context) => values + .map((item) => PopupMenuItem( + value: item.$1, + child: Text( + item.$2 ?? "", + style: kTextStylePopupMenuItem, + ), + )) + .toList(), + onSelected: onChanged, + child: Container( + width: containerWidth, + padding: kP8, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Text( + value ?? "", + style: kTextStylePopupMenuItem, + softWrap: false, + overflow: TextOverflow.ellipsis, + ), + ), + const Icon( + Icons.unfold_more, + size: 16, + ) + ], + ), + ), + ); + if (isOutlined) { + return Container( + decoration: BoxDecoration( + border: Border.all( + color: Theme.of(context).colorScheme.onSurface, + ), + borderRadius: kBorderRadius8, + ), + child: popup, + ); + } + return popup; + } +} diff --git a/packages/apidash_design_system/lib/widgets/widgets.dart b/packages/apidash_design_system/lib/widgets/widgets.dart index dca4466f..7b1f06a3 100644 --- a/packages/apidash_design_system/lib/widgets/widgets.dart +++ b/packages/apidash_design_system/lib/widgets/widgets.dart @@ -1,6 +1,7 @@ export 'button_icon.dart'; export 'checkbox.dart'; export 'dropdown.dart'; +export 'popup_menu.dart'; export 'snackbar.dart'; export 'textfield_outlined.dart'; export 'textfield_raw.dart';