Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add Banner section and corresponding tests for state previews

AmanRajSinghMourya102d32e07719
diff --git a/mobile/packages/ente_components/example/lib/main.dart b/mobile/packages/ente_components/example/lib/main.dart
index 6b835c2b93..eb4570ee3d 100644
--- a/mobile/packages/ente_components/example/lib/main.dart
+++ b/mobile/packages/ente_components/example/lib/main.dart
@@ -219,6 +219,20 @@ class _CatalogHomeState extends State<CatalogHome> {
],
previewBuilder: (_) => const _PopupMenuPreview(),
),
+ CatalogSection(
+ title: 'Banner',
+ icon: HugeIcons.strokeRoundedAlertCircle,
+ components: const [
+ 'Failure',
+ 'Informative',
+ 'Success',
+ 'Warning',
+ 'Neutral',
+ 'Custom leading',
+ 'Custom trailing',
+ ],
+ previewBuilder: (_) => const _BannerPreview(),
+ ),
CatalogSection(
title: 'Buttons',
icon: HugeIcons.strokeRoundedCursorPointer02,
@@ -1122,6 +1136,134 @@ class _TypeSample extends StatelessWidget {
}
}
+const _bannerPreviewSpecs = [
+ _BannerPreviewSpec(
+ state: BannerComponentState.failure,
+ title: 'Failure!',
+ subtitle: 'Some subtext that describes the failure',
+ ),
+ _BannerPreviewSpec(
+ state: BannerComponentState.informative,
+ title: 'Informative!',
+ subtitle: 'Some subtext that describes the info',
+ ),
+ _BannerPreviewSpec(
+ state: BannerComponentState.success,
+ title: 'Success!',
+ subtitle: 'Some subtext that describes the success',
+ ),
+ _BannerPreviewSpec(
+ state: BannerComponentState.warning,
+ title: 'Warning!',
+ subtitle: 'Some subtext that describes the warning',
+ ),
+ _BannerPreviewSpec(
+ state: BannerComponentState.neutral,
+ title: 'Neutral!',
+ subtitle: 'Some subtext that describes the neutral text',
+ ),
+];
+
+class _BannerPreviewSpec {
+ const _BannerPreviewSpec({
+ required this.state,
+ required this.title,
+ required this.subtitle,
+ });
+
+ final BannerComponentState state;
+ final String title;
+ final String subtitle;
+}
+
+class _BannerPreview extends StatelessWidget {
+ const _BannerPreview();
+
+ @override
+ Widget build(BuildContext context) {
+ return _CatalogPreviewList(
+ children: [
+ _CatalogPreviewGroup(
+ title: 'States',
+ child: Column(
+ children: [
+ for (
+ var index = 0;
+ index < _bannerPreviewSpecs.length;
+ index++
+ ) ...[
+ _BannerStatePreview(spec: _bannerPreviewSpecs[index]),
+ if (index != _bannerPreviewSpecs.length - 1)
+ const SizedBox(height: Spacing.md),
+ ],
+ ],
+ ),
+ ),
+ const _CatalogPreviewGroup(
+ title: 'Custom leading',
+ child: BannerComponent(
+ title: 'Syncing backup',
+ subtitle: 'Preparing secure upload',
+ state: BannerComponentState.informative,
+ leadingWidget: _BannerLoadingLeading(),
+ onTap: _noop,
+ ),
+ ),
+ const _CatalogPreviewGroup(
+ title: 'Custom trailing',
+ child: BannerComponent(
+ title: 'Dismissible info',
+ subtitle: 'Some subtext with a custom trailing icon',
+ state: BannerComponentState.informative,
+ trailingWidget: _CatalogHugeIcon(
+ HugeIcons.strokeRoundedCancel01,
+ size: IconSizes.small,
+ ),
+ onTap: _noop,
+ ),
+ ),
+ ],
+ );
+ }
+}
+
+class _BannerLoadingLeading extends StatelessWidget {
+ const _BannerLoadingLeading();
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+
+ return SizedBox(
+ width: IconSizes.small,
+ height: IconSizes.small,
+ child: CircularProgressIndicator(color: colors.blue, strokeWidth: 2),
+ );
+ }
+}
+
+void _noop() {}
+
+class _BannerStatePreview extends StatelessWidget {
+ const _BannerStatePreview({required this.spec});
+
+ final _BannerPreviewSpec spec;
+
+ @override
+ Widget build(BuildContext context) {
+ return BannerComponent(
+ title: spec.title,
+ subtitle: spec.subtitle,
+ state: spec.state,
+ onTap: () {
+ ScaffoldMessenger.of(
+ context,
+ ).showSnackBar(SnackBar(content: Text('${spec.title} tapped')));
+ },
+ );
+ }
+}
+
class _ButtonMatrix extends StatelessWidget {
const _ButtonMatrix();
diff --git a/mobile/packages/ente_components/example/test/smoke_test.dart b/mobile/packages/ente_components/example/test/smoke_test.dart
index ca8d584a0a..066b8423cf 100644
--- a/mobile/packages/ente_components/example/test/smoke_test.dart
+++ b/mobile/packages/ente_components/example/test/smoke_test.dart
@@ -21,6 +21,21 @@ void main() {
expect(find.byTooltip('Theme: Dark. Tap for Light'), findsOneWidget);
});
+ testWidgets('banner catalog shows all Figma states', (tester) async {
+ await tester.pumpWidget(const ComponentsCatalogApp());
+
+ await tester.tap(find.byKey(const ValueKey('catalog-section-Banner')));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 350));
+
+ expect(find.text('Failure!'), findsOneWidget);
+ expect(find.text('Informative!'), findsOneWidget);
+ expect(find.text('Success!'), findsOneWidget);
+ expect(find.text('Warning!'), findsOneWidget);
+ expect(find.text('Neutral!'), findsOneWidget);
+ expect(find.text('Syncing backup'), findsOneWidget);
+ });
+
testWidgets('button transition preview surfaces loading and success', (
tester,
) async {