The-Agency/lib/ui/widgets/sidebar/thread_button.dart

91 lines
2.2 KiB
Dart

import "package:shadcn_flutter/shadcn_flutter.dart";
import '../../utils/format_relative_time.dart';
class ThreadButton extends StatelessWidget {
final String label;
final IconData? icon;
final VoidCallback? onPressed;
final VoidCallback? onDelete;
final DateTime? lastMessage;
final bool selected;
final bool muted;
final bool isRunning;
ThreadButton({
required this.label,
this.icon,
this.onPressed,
this.onDelete,
this.lastMessage,
this.selected = false,
this.muted = false,
this.isRunning = false,
});
@override
Widget build(BuildContext context) {
ButtonStyle style = selected ? ButtonStyle.secondary() : ButtonStyle.ghost();
ColorScheme colorScheme = Theme.of(context).colorScheme;
final button = SizedBox(
width: double.infinity,
child: Button(
style: style.copyWith(
padding: (context, state, edgeInsets) {
return EdgeInsets.only(
top: 8,
left: 12,
bottom: 8,
right: 12
);
}
),
disableFocusOutline: true,
onPressed: onPressed ?? () {},
enabled: onPressed != null,
leading: Icon(
icon,
color: icon == null ? Colors.transparent : (muted ? colorScheme.mutedForeground : null),
).iconSmall,
trailingGap: 32,
trailing: isRunning
? SizedBox(
width: 12,
height: 12,
child: CircularProgressIndicator(
strokeWidth: 1.5,
color: colorScheme.primary,
),
)
: lastMessage != null
? Text(formatRelativeTime(lastMessage!)).muted.small.light
: null,
child: Text(
label,
style: TextStyle(
color: (muted ? colorScheme.mutedForeground : null)
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
).small.light,
),
);
if (onDelete == null) return button;
return ContextMenu(
items: [
MenuButton(
onPressed: (_) => onDelete!(),
child: const Text("Delete"),
),
],
child: button,
);
}
}