Skip to content

Commit cadb79d

Browse files
committed
NOMERGE button: Add optional buildIcon param, alongside icon
1 parent 2667b7f commit cadb79d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

lib/widgets/button.dart

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import 'theme.dart';
1111
/// The Figma uses this for the "Cancel" and "Save" buttons in the compose box
1212
/// for editing an already-sent message.
1313
///
14+
/// The icon is optional;
15+
/// to provide one, pass [icon] or [buildIcon] but not both.
16+
///
1417
/// See Figma:
1518
/// * Component: https://www.figma.com/design/msWyAJ8cnMHgOMPxi7BUvA/Zulip-Web-UI-kit?node-id=1-2780&t=Wia0D0i1I0GXdD9z-0
1619
/// * Edit-message compose box: https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=3988-38201&m=dev
@@ -22,14 +25,16 @@ class ZulipWebUiKitButton extends StatelessWidget {
2225
this.size = ZulipWebUiKitButtonSize.normal,
2326
required this.label,
2427
this.icon,
28+
this.buildIcon,
2529
required this.onPressed,
26-
});
30+
}) : assert(icon == null || buildIcon == null);
2731

2832
final ZulipWebUiKitButtonAttention attention;
2933
final ZulipWebUiKitButtonIntent intent;
3034
final ZulipWebUiKitButtonSize size;
3135
final String label;
3236
final IconData? icon;
37+
final Widget Function(double size)? buildIcon;
3338
final VoidCallback onPressed;
3439

3540
WidgetStateColor _backgroundColor(DesignVariables designVariables) {
@@ -141,14 +146,24 @@ class ZulipWebUiKitButton extends StatelessWidget {
141146

142147
final labelColor = _labelColor(designVariables);
143148

149+
final iconSize = 16.0;
150+
151+
Widget? effectiveIcon;
152+
if (icon != null) {
153+
effectiveIcon = Icon(icon); // (size is set in TextButton.styleFrom)
154+
}
155+
if (buildIcon != null) {
156+
effectiveIcon = buildIcon!(iconSize);
157+
}
158+
144159
return AnimatedScaleOnTap(
145160
scaleEnd: 0.96,
146161
duration: Duration(milliseconds: 100),
147162
child: TextButton.icon(
148163
// TODO the gap between the icon and label should be 6px, not 8px
149-
icon: icon != null ? Icon(icon) : null,
164+
icon: effectiveIcon,
150165
style: TextButton.styleFrom(
151-
iconSize: 16,
166+
iconSize: iconSize,
152167
iconColor: labelColor,
153168
padding: EdgeInsets.symmetric(
154169
horizontal: _forSize(6, 10),

0 commit comments

Comments
 (0)