106 lines
2.9 KiB
Dart
106 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shadcn_ui/shadcn_ui.dart';
|
|
|
|
import '../theme/yanting_tokens.dart';
|
|
|
|
class AppButton extends StatelessWidget {
|
|
const AppButton({
|
|
required this.label,
|
|
required this.onPressed,
|
|
this.icon,
|
|
this.kind = AppButtonKind.primary,
|
|
this.expand = false,
|
|
super.key,
|
|
});
|
|
|
|
final String label;
|
|
final VoidCallback? onPressed;
|
|
final IconData? icon;
|
|
final AppButtonKind kind;
|
|
final bool expand;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final leading = icon == null ? null : Icon(icon, size: 16);
|
|
final width = expand ? double.infinity : null;
|
|
final child = Text(label);
|
|
|
|
return switch (kind) {
|
|
AppButtonKind.primary => ShadButton(
|
|
width: width,
|
|
onPressed: onPressed,
|
|
leading: leading,
|
|
child: child,
|
|
),
|
|
AppButtonKind.dark => ShadButton(
|
|
width: width,
|
|
onPressed: onPressed,
|
|
leading: leading,
|
|
backgroundColor: YantingColors.foreground,
|
|
foregroundColor: YantingColors.background,
|
|
hoverBackgroundColor: YantingColors.foreground.withValues(alpha: 0.9),
|
|
child: child,
|
|
),
|
|
AppButtonKind.accent => ShadButton.secondary(
|
|
width: width,
|
|
onPressed: onPressed,
|
|
leading: leading,
|
|
backgroundColor: YantingColors.brandSoft,
|
|
foregroundColor: YantingColors.primaryForeground,
|
|
hoverBackgroundColor: YantingColors.brandSoftBorder,
|
|
child: child,
|
|
),
|
|
AppButtonKind.ghost => ShadButton.outline(
|
|
width: width,
|
|
onPressed: onPressed,
|
|
leading: leading,
|
|
child: child,
|
|
),
|
|
};
|
|
}
|
|
}
|
|
|
|
class AppIconButton extends StatelessWidget {
|
|
const AppIconButton({
|
|
required this.icon,
|
|
required this.onPressed,
|
|
this.kind = AppButtonKind.ghost,
|
|
super.key,
|
|
});
|
|
|
|
final IconData icon;
|
|
final VoidCallback? onPressed;
|
|
final AppButtonKind kind;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final iconWidget = Icon(icon, size: 16);
|
|
return switch (kind) {
|
|
AppButtonKind.primary => ShadIconButton(
|
|
onPressed: onPressed,
|
|
icon: iconWidget,
|
|
),
|
|
AppButtonKind.dark => ShadIconButton(
|
|
onPressed: onPressed,
|
|
backgroundColor: YantingColors.foreground,
|
|
foregroundColor: YantingColors.background,
|
|
hoverBackgroundColor: YantingColors.foreground.withValues(alpha: 0.9),
|
|
icon: iconWidget,
|
|
),
|
|
AppButtonKind.accent => ShadIconButton.secondary(
|
|
onPressed: onPressed,
|
|
backgroundColor: YantingColors.brandSoft,
|
|
foregroundColor: YantingColors.primaryForeground,
|
|
hoverBackgroundColor: YantingColors.brandSoftBorder,
|
|
icon: iconWidget,
|
|
),
|
|
AppButtonKind.ghost => ShadIconButton.outline(
|
|
onPressed: onPressed,
|
|
icon: iconWidget,
|
|
),
|
|
};
|
|
}
|
|
}
|
|
|
|
enum AppButtonKind { primary, dark, accent, ghost }
|