From ab3ae633a4ecd656df00800ba00d7476eed8819c Mon Sep 17 00:00:00 2001 From: mikecoomber Date: Thu, 21 Nov 2024 12:36:50 +0000 Subject: [PATCH 1/3] feat(UX-1314): Created comment component --- example/lib/pages/components/comment.dart | 67 +++++ example/lib/routes.dart | 10 + .../Flutter/GeneratedPluginRegistrant.swift | 2 - lib/src/components/molecules.dart | 1 + lib/src/components/molecules/comment.dart | 265 ++++++++++++++++++ .../molecules/slidable_list_tile.dart | 28 +- .../chat/message_body/chat_utils.dart | 4 + 7 files changed, 368 insertions(+), 9 deletions(-) create mode 100644 example/lib/pages/components/comment.dart create mode 100644 lib/src/components/molecules/comment.dart diff --git a/example/lib/pages/components/comment.dart b/example/lib/pages/components/comment.dart new file mode 100644 index 0000000..7826249 --- /dev/null +++ b/example/lib/pages/components/comment.dart @@ -0,0 +1,67 @@ +import 'package:flutter/material.dart'; +import 'package:zds_flutter/zds_flutter.dart'; + +class CommentDemo extends StatefulWidget { + const CommentDemo({super.key}); + + @override + State createState() => _CommentDemoState(); +} + +class _CommentDemoState extends State { + @override + Widget build(BuildContext context) { + return Container( + color: Zeta.of(context).colors.surfaceDefault, + child: Column( + children: [ + ZdsComment( + avatar: ZetaAvatar.initials( + initials: 'JP', + size: ZetaAvatarSize.xxxs, + ), + author: 'John Doe', + comment: 'This is a comment', + onReply: () {}, + replySemanticLabel: 'Reply to comment', + onDelete: () {}, + deleteSemanticLabel: 'Delete', + timeStamp: '09:30 AM', + attachment: ZdsChatAttachment( + type: ZdsChatAttachmentType.docNetwork, + name: 'Blueprints.xls', + size: '1234kb', + extension: 'xls', + ), + ), + ZdsComment( + avatar: ZetaAvatar.initials( + initials: 'JP', + size: ZetaAvatarSize.xxxs, + backgroundColor: Zeta.of(context).colors.surfaceAvatarPurple, + ), + onDelete: () {}, + deleteSemanticLabel: 'Delete', + isReply: true, + author: 'John Doe', + comment: 'This is a comment', + timeStamp: '09:30 AM', + ), + ZdsComment( + avatar: ZetaAvatar.initials( + initials: 'JP', + size: ZetaAvatarSize.xxxs, + ), + author: 'John Doe', + comment: 'This is a comment', + onReply: () {}, + replySemanticLabel: 'Reply to comment', + onDelete: () {}, + deleteSemanticLabel: 'Delete', + timeStamp: '09:30 AM', + ), + ], + ), + ); + } +} diff --git a/example/lib/routes.dart b/example/lib/routes.dart index 6042262..010f29e 100644 --- a/example/lib/routes.dart +++ b/example/lib/routes.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:zds_flutter_example/pages/components/chat.dart'; +import 'package:zds_flutter_example/pages/components/comment.dart'; import 'home.dart'; import 'pages/assets/animations.dart'; @@ -92,6 +94,14 @@ final kRoutes = { title: 'Card Actions', child: CardActionsDemo(), ), + const DemoRoute( + title: 'Chat', + child: ChatDemo(), + ), + const DemoRoute( + title: 'Comments', + child: CommentDemo(), + ), const DemoRoute( title: 'Interactive Viewer', wrapper: false, diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index a5fa519..c267112 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -15,7 +15,6 @@ import irondash_engine_context import just_audio import package_info_plus import path_provider_foundation -import quill_native_bridge_macos import record_darwin import share_plus import shared_preferences_foundation @@ -37,7 +36,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin")) FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) - QuillNativeBridgePlugin.register(with: registry.registrar(forPlugin: "QuillNativeBridgePlugin")) RecordPlugin.register(with: registry.registrar(forPlugin: "RecordPlugin")) SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) diff --git a/lib/src/components/molecules.dart b/lib/src/components/molecules.dart index 57576f0..76a45c4 100644 --- a/lib/src/components/molecules.dart +++ b/lib/src/components/molecules.dart @@ -5,6 +5,7 @@ export 'molecules/bottom_sheet.dart'; export 'molecules/card_actions.dart'; export 'molecules/card_header.dart'; export 'molecules/check_button.dart'; +export 'molecules/comment.dart'; export 'molecules/date_range_picker.dart'; export 'molecules/date_time_picker.dart'; export 'molecules/dropdown.dart'; diff --git a/lib/src/components/molecules/comment.dart b/lib/src/components/molecules/comment.dart new file mode 100644 index 0000000..7f0f1d9 --- /dev/null +++ b/lib/src/components/molecules/comment.dart @@ -0,0 +1,265 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; + +import '../../../zds_flutter.dart'; + +/// Displays a comment with an optional attachment and delete and reply swipeable actions. +class ZdsComment extends StatelessWidget { + /// Constructs a [ZdsComment] widget. + const ZdsComment({ + required this.comment, + required this.author, + this.isReply = false, + this.avatar, + this.timeStamp, + this.onDelete, + this.onReply, + super.key, + this.attachment, + this.downloadCallback, + this.deleteSemanticLabel, + this.replySemanticLabel, + this.attachmentThumbnail, + }) : assert( + onReply != null && replySemanticLabel != null || onReply == null && replySemanticLabel == null, + 'replySemanticLabel must be not null if onReply is defined', + ), + assert( + onDelete != null && deleteSemanticLabel != null || onDelete == null && deleteSemanticLabel == null, + 'deleteSemanticLabel must be not null if onDelete is defined', + ); + + /// The comment text. + final String comment; + + /// The avatar widget to display. + /// Should be a [ZetaAvatar] + final Widget? avatar; + + /// The timestamp of the comment. + final String? timeStamp; + + /// The author of the comment. + final String author; + + /// Whether the comment is a reply. + /// If this is true, the reply action will automatically be hidden. + final bool isReply; + + /// The callback to be called when the delete action is tapped. + /// If this is null, the delete action will be hidden. + /// If this is not null, [deleteSemanticLabel] must also be not null. + final VoidCallback? onDelete; + + /// The semantic label for the delete action. + final String? deleteSemanticLabel; + + /// The callback to be called when the reply action is tapped. + /// If this is null, the reply action will be hidden. + /// If this is not null, [replySemanticLabel] must also be not null. + final VoidCallback? onReply; + + /// The semantic label for the reply action. + final String? replySemanticLabel; + + /// The attachment to display. + final ZdsChatAttachment? attachment; + + /// The callback to be called when the attachment is tapped. + final VoidCallback? downloadCallback; + + /// The custom thumbnail to display for the attachment. + final Widget? attachmentThumbnail; + + @override + Widget build(BuildContext context) { + final colors = Zeta.of(context).colors; + final spacing = Zeta.of(context).spacing; + + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (isReply) + Padding( + padding: EdgeInsets.only( + left: spacing.large, + right: spacing.minimum, + top: spacing.minimum, + ), + child: const ZetaIcon( + ZetaIcons.reply, + size: 24, + applyTextScaling: true, + ), + ), + Expanded( + child: LayoutBuilder( + builder: (context, constraints) { + return ZdsSlidableListTile( + width: constraints.maxWidth, + elevation: 0, + actions: [ + if (!isReply && onReply != null && replySemanticLabel != null) + ZdsSlidableAction( + icon: ZetaIcons.reply, + semanticLabel: replySemanticLabel, + foregroundColor: colors.primary, + backgroundColor: colors.surfacePrimarySubtle, + onPressed: (_) => onReply!(), + ), + if (onDelete != null && deleteSemanticLabel != null) + ZdsSlidableAction( + icon: ZetaIcons.delete, + semanticLabel: deleteSemanticLabel, + onPressed: (_) {}, + backgroundColor: colors.surfaceNegativeSubtle, + foregroundColor: colors.error, + ), + ], + child: Container( + decoration: BoxDecoration( + color: colors.surfaceDefault, + border: Border( + bottom: BorderSide( + color: colors.borderSubtle, + ), + ), + ), + padding: EdgeInsets.all(spacing.large), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + if (avatar != null) + Padding( + padding: EdgeInsets.only(right: spacing.small), + child: avatar, + ), + Text( + author, + style: ZetaTextStyles.labelLarge.copyWith( + fontWeight: FontWeight.w500, + ), + ), + const Spacer(), + if (timeStamp != null) + Padding( + padding: EdgeInsets.only(left: spacing.small), + child: Text( + timeStamp!, + style: ZetaTextStyles.bodyXSmall.copyWith(color: colors.textSubtle), + ), + ), + ], + ), + Padding( + padding: EdgeInsets.only(top: spacing.small), + child: Text( + comment, + style: Theme.of(context).textTheme.bodyMedium, + ), + ), + if (attachment != null) + Padding( + padding: EdgeInsets.only(top: spacing.large), + child: _AttachmentRow( + attachment: attachment!, + downloadCallback: downloadCallback, + customThumbnail: attachmentThumbnail, + ), + ), + ], + ), + ), + ); + }, + ), + ), + ], + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(StringProperty('comment', comment)) + ..add(StringProperty('timeStamp', timeStamp)) + ..add(StringProperty('author', author)) + ..add(DiagnosticsProperty('isReply', isReply)) + ..add(ObjectFlagProperty.has('onDelete', onDelete)) + ..add(ObjectFlagProperty.has('onReply', onReply)) + ..add(DiagnosticsProperty('attachment', attachment)) + ..add(ObjectFlagProperty.has('downloadCallback', downloadCallback)) + ..add(StringProperty('deleteSemanticLabel', deleteSemanticLabel)) + ..add(StringProperty('replySemanticLabel', replySemanticLabel)); + } +} + +class _AttachmentRow extends StatelessWidget { + const _AttachmentRow({ + required this.attachment, + this.customThumbnail, + this.downloadCallback, + }); + + final ZdsChatAttachment attachment; + final VoidCallback? downloadCallback; + final Widget? customThumbnail; + + @override + Widget build(BuildContext context) { + final spacing = Zeta.of(context).spacing; + final colors = Zeta.of(context).colors; + final radius = Zeta.of(context).radius; + + return Material( + child: InkWell( + borderRadius: radius.minimal, + onTap: downloadCallback, + child: Row( + children: [ + if (customThumbnail != null) + SizedBox( + width: 44, + height: 44, + child: customThumbnail, + ) + else + ZetaIcon( + extensionIcon('.${attachment.fileType}'), + color: iconColor('.${attachment.fileType}'), + size: 40, + ), + SizedBox(width: spacing.small), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + attachment.name, + style: ZetaTextStyles.bodySmall, + ), + if (attachment.size != null) + Text( + attachment.size!, + style: ZetaTextStyles.bodySmall.copyWith(color: colors.textSubtle), + ), + ], + ), + ], + ), + ), + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('attachment', attachment)) + ..add(ObjectFlagProperty.has('downloadCallback', downloadCallback)); + } +} diff --git a/lib/src/components/molecules/slidable_list_tile.dart b/lib/src/components/molecules/slidable_list_tile.dart index 649c399..224f533 100644 --- a/lib/src/components/molecules/slidable_list_tile.dart +++ b/lib/src/components/molecules/slidable_list_tile.dart @@ -48,6 +48,7 @@ class ZdsSlidableListTile extends StatelessWidget { this.slideButtonWidth = 100, this.minHeight = 80, this.onTap, + this.elevation = 1, this.slideEnabled = true, this.semanticDescription, this.excludeSemantics = false, @@ -56,6 +57,9 @@ class ZdsSlidableListTile extends StatelessWidget { /// The tile's main content. Usually a [Row] final Widget child; + /// The elevation of the tile. Defaults to 1. + final double elevation; + /// The length of the tile. On vertical displays this usually is `MediaQuery.of(context).size.width`. /// Must exceed or be equal to [slideButtonWidth] * [actions].length. final double width; @@ -95,7 +99,7 @@ class ZdsSlidableListTile extends StatelessWidget { final Map semanticActions = {}; for (final ZdsSlidableAction action in [...?actions, ...?leadingActions]) { - semanticActions[CustomSemanticsAction(label: action.label)] = () { + semanticActions[CustomSemanticsAction(label: action.semanticLabel ?? action.label!)] = () { action.onPressed!(context); }; } @@ -123,6 +127,7 @@ class ZdsSlidableListTile extends StatelessWidget { ) : null, child: Card( + elevation: elevation, shape: const ContinuousRectangleBorder(), color: backgroundColor ?? Theme.of(context).colorScheme.surface, margin: EdgeInsets.zero, @@ -152,7 +157,8 @@ class ZdsSlidableListTile extends StatelessWidget { ..add(DiagnosticsProperty('slideEnabled', slideEnabled)) ..add(DoubleProperty('minHeight', minHeight)) ..add(StringProperty('semanticDescription', semanticDescription)) - ..add(DiagnosticsProperty('excludeSemantics', excludeSemantics)); + ..add(DiagnosticsProperty('excludeSemantics', excludeSemantics)) + ..add(DoubleProperty('elevation', elevation)); } } @@ -218,10 +224,10 @@ class _ActionBuilderState extends State<_ActionBuilder> { /// Defines an action that will be shown when sliding on a ZdsSlidableListTile. class ZdsSlidableAction { /// Defines an action that will be shown when sliding on a ZdsSlidableListTile. - /// [label] must not be empty. /// [backgroundColor], [foregroundColor], and [autoclose] must not be null ZdsSlidableAction({ - required this.label, + this.label, + this.semanticLabel, this.onPressed, this.icon, this.backgroundColor, @@ -229,13 +235,21 @@ class ZdsSlidableAction { this.autoclose = true, this.padding = EdgeInsets.zero, this.textOverflow, - }) : assert(label.isNotEmpty, 'Label must have content as it acts as the semantic button description'); + }) : assert( + label != null || semanticLabel != null, + 'Slideable actions must define either a label or semantic label to meet accessability standards.', + ); /// Function called on press of the widget. final void Function(BuildContext)? onPressed; - /// The text that will be shown above the icon. It can't be empty. - final String label; + /// The text that will be shown above the icon. + /// If this is not set, [semanticLabel] must be set. + final String? label; + + /// The semantic label for the action. + /// If this is not set, [label] must be set. + final String? semanticLabel; /// An optional icon that will be shown below the label. final IconData? icon; diff --git a/lib/src/components/organisms/chat/message_body/chat_utils.dart b/lib/src/components/organisms/chat/message_body/chat_utils.dart index d613012..4c82204 100644 --- a/lib/src/components/organisms/chat/message_body/chat_utils.dart +++ b/lib/src/components/organisms/chat/message_body/chat_utils.dart @@ -451,6 +451,7 @@ class ZdsChatAttachment { this.content, this.url, this.localPath, + this.size, this.id, }); @@ -462,6 +463,9 @@ class ZdsChatAttachment { /// If not provided, [name] will be parsed for extensions. final String? extension; + /// The size of the file + final String? size; + /// Content of attachment encoded in base64. final String? content; From 38b06da9e3b218116aa6cfe2764a5ce2e01972c2 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 21 Nov 2024 12:43:39 +0000 Subject: [PATCH 2/3] chore(automated): Lint commit and format --- example/macos/Flutter/GeneratedPluginRegistrant.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index c267112..a5fa519 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -15,6 +15,7 @@ import irondash_engine_context import just_audio import package_info_plus import path_provider_foundation +import quill_native_bridge_macos import record_darwin import share_plus import shared_preferences_foundation @@ -36,6 +37,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin")) FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + QuillNativeBridgePlugin.register(with: registry.registrar(forPlugin: "QuillNativeBridgePlugin")) RecordPlugin.register(with: registry.registrar(forPlugin: "RecordPlugin")) SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) From 384c492a3ba6a32d6a5164ba33a7405007d357b8 Mon Sep 17 00:00:00 2001 From: mikecoomber Date: Thu, 21 Nov 2024 17:19:18 +0000 Subject: [PATCH 3/3] added inkewell padding and fixed custom thumbnail size --- example/lib/pages/components/comment.dart | 1 + lib/src/components/molecules/comment.dart | 117 ++++++++++++---------- 2 files changed, 66 insertions(+), 52 deletions(-) diff --git a/example/lib/pages/components/comment.dart b/example/lib/pages/components/comment.dart index 7826249..5fd2a66 100644 --- a/example/lib/pages/components/comment.dart +++ b/example/lib/pages/components/comment.dart @@ -21,6 +21,7 @@ class _CommentDemoState extends State { size: ZetaAvatarSize.xxxs, ), author: 'John Doe', + downloadCallback: () {}, comment: 'This is a comment', onReply: () {}, replySemanticLabel: 'Reply to comment', diff --git a/lib/src/components/molecules/comment.dart b/lib/src/components/molecules/comment.dart index 7f0f1d9..c4c62d7 100644 --- a/lib/src/components/molecules/comment.dart +++ b/lib/src/components/molecules/comment.dart @@ -126,36 +126,46 @@ class ZdsComment extends StatelessWidget { ), ), ), - padding: EdgeInsets.all(spacing.large), + padding: EdgeInsets.symmetric( + vertical: spacing.large, + horizontal: spacing.medium, + ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - children: [ - if (avatar != null) - Padding( - padding: EdgeInsets.only(right: spacing.small), - child: avatar, - ), - Text( - author, - style: ZetaTextStyles.labelLarge.copyWith( - fontWeight: FontWeight.w500, - ), - ), - const Spacer(), - if (timeStamp != null) - Padding( - padding: EdgeInsets.only(left: spacing.small), - child: Text( - timeStamp!, - style: ZetaTextStyles.bodyXSmall.copyWith(color: colors.textSubtle), + Padding( + padding: EdgeInsets.symmetric(horizontal: spacing.minimum), + child: Row( + children: [ + if (avatar != null) + Padding( + padding: EdgeInsets.only(right: spacing.small), + child: avatar, + ), + Text( + author, + style: ZetaTextStyles.labelLarge.copyWith( + fontWeight: FontWeight.w500, ), ), - ], + const Spacer(), + if (timeStamp != null) + Padding( + padding: EdgeInsets.only(left: spacing.small), + child: Text( + timeStamp!, + style: ZetaTextStyles.bodyXSmall.copyWith(color: colors.textSubtle), + ), + ), + ], + ), ), Padding( - padding: EdgeInsets.only(top: spacing.small), + padding: EdgeInsets.only( + top: spacing.small, + left: spacing.minimum, + right: spacing.minimum, + ), child: Text( comment, style: Theme.of(context).textTheme.bodyMedium, @@ -163,7 +173,7 @@ class ZdsComment extends StatelessWidget { ), if (attachment != null) Padding( - padding: EdgeInsets.only(top: spacing.large), + padding: EdgeInsets.only(top: spacing.medium), child: _AttachmentRow( attachment: attachment!, downloadCallback: downloadCallback, @@ -219,37 +229,40 @@ class _AttachmentRow extends StatelessWidget { child: InkWell( borderRadius: radius.minimal, onTap: downloadCallback, - child: Row( - children: [ - if (customThumbnail != null) - SizedBox( - width: 44, - height: 44, - child: customThumbnail, - ) - else - ZetaIcon( - extensionIcon('.${attachment.fileType}'), - color: iconColor('.${attachment.fileType}'), - size: 40, - ), - SizedBox(width: spacing.small), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - attachment.name, - style: ZetaTextStyles.bodySmall, + child: Padding( + padding: EdgeInsets.all(spacing.minimum), + child: Row( + children: [ + if (customThumbnail != null) + SizedBox( + width: 40, + height: 40, + child: customThumbnail, + ) + else + ZetaIcon( + extensionIcon('.${attachment.fileType}'), + color: iconColor('.${attachment.fileType}'), + size: 40, ), - if (attachment.size != null) + SizedBox(width: spacing.small), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ Text( - attachment.size!, - style: ZetaTextStyles.bodySmall.copyWith(color: colors.textSubtle), + attachment.name, + style: ZetaTextStyles.bodySmall, ), - ], - ), - ], + if (attachment.size != null) + Text( + attachment.size!, + style: ZetaTextStyles.bodySmall.copyWith(color: colors.textSubtle), + ), + ], + ), + ], + ), ), ), );