-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created status chip docs: added description for status chip fix: converted child widget function to a stateless widget class in status chip feat: implemented status chip widgetbook use case fix: set rounded to default to true test: wrote tests for status chip
- Loading branch information
Showing
9 changed files
with
380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../../zeta_flutter.dart'; | ||
|
||
/// The [ZetaStatusChip] is a chip that displays a status/label. | ||
/// It can be dragged around the screen and placed in new locations using [DragTarget]. | ||
/// | ||
/// {@category Components} | ||
/// | ||
/// Figma: https://www.figma.com/file/JesXQFLaPJLc1BdBM4sisI/%F0%9F%A6%93-ZDS---Components?node-id=21265-2159 | ||
/// | ||
/// Widgetbook: https://zeta-ds.web.app/flutter/widgetbook/index.html#/?path=components/chips/input-chip | ||
class ZetaStatusChip extends ZetaStatelessWidget { | ||
/// Creates a [ZetaStatusChip]. | ||
const ZetaStatusChip({ | ||
super.key, | ||
required this.label, | ||
super.rounded = true, | ||
this.draggable = false, | ||
this.data, | ||
this.onDragCompleted, | ||
this.semanticLabel, | ||
}); | ||
|
||
/// The label on the [ZetaStatusChip] | ||
final String label; | ||
|
||
/// Whether the chip can be dragged. | ||
final bool draggable; | ||
|
||
/// Draggable data. | ||
final dynamic data; | ||
|
||
/// Called when the draggable is dropped and accepted by a [DragTarget]. | ||
/// | ||
/// See also: | ||
/// * [DragTarget] | ||
/// * [Draggable] | ||
final VoidCallback? onDragCompleted; | ||
|
||
/// A semantic label for the chip. | ||
final String? semanticLabel; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ZetaRoundedScope( | ||
rounded: context.rounded, | ||
child: MouseRegion( | ||
cursor: draggable ? SystemMouseCursors.click : SystemMouseCursors.basic, | ||
child: Semantics( | ||
label: semanticLabel ?? label, | ||
child: SelectionContainer.disabled( | ||
child: draggable | ||
? Draggable( | ||
feedback: Material( | ||
color: Colors.transparent, | ||
child: _Child(context: context, label: label), | ||
), | ||
childWhenDragging: const Nothing(), | ||
data: data, | ||
onDragCompleted: onDragCompleted, | ||
child: _Child(context: context, label: label), | ||
) | ||
: _Child(context: context, label: label), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
void debugFillProperties(DiagnosticPropertiesBuilder properties) { | ||
super.debugFillProperties(properties); | ||
properties | ||
..add(StringProperty('label', label)) | ||
..add(DiagnosticsProperty<bool>('draggable', draggable)) | ||
..add(DiagnosticsProperty('data', data)) | ||
..add(ObjectFlagProperty<VoidCallback?>.has('onDragCompleted', onDragCompleted)) | ||
..add(StringProperty('semanticLabel', semanticLabel)); | ||
} | ||
} | ||
|
||
/// The child widget of the [ZetaStatusChip]. | ||
class _Child extends StatelessWidget { | ||
const _Child({required this.context, required this.label}); | ||
|
||
final BuildContext context; | ||
|
||
final String label; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
decoration: BoxDecoration( | ||
color: Zeta.of(context).colors.surfaceWarm, | ||
borderRadius: context.rounded | ||
? BorderRadius.all( | ||
Radius.circular( | ||
Zeta.of(context).spacing.small, | ||
), | ||
) | ||
: null, | ||
), | ||
padding: EdgeInsets.symmetric( | ||
horizontal: Zeta.of(context).spacing.small, | ||
vertical: Zeta.of(context).spacing.minimum, | ||
), | ||
child: Text( | ||
label, | ||
style: ZetaTextStyles.bodyXSmall.copyWith( | ||
color: Zeta.of(context).colors.textDefault, | ||
), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
void debugFillProperties(DiagnosticPropertiesBuilder properties) { | ||
super.debugFillProperties(properties); | ||
properties | ||
..add(DiagnosticsProperty<BuildContext>('context', context)) | ||
..add(StringProperty('label', label)); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.