Skip to content

Commit

Permalink
feat: Component tooltip (#33)
Browse files Browse the repository at this point in the history
* create tooltip

* create Widgetbook for ZetaTooltip

* add LayoutBuilder

* [automated commit] lint format and import sort

* fix text overflow when there is horizontal arrow and maxWidth is null

---------

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
2 people authored and thelukewalton committed Apr 25, 2024
1 parent 155357b commit 85cab8e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/src/components/tooltip/tooltip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import 'package:flutter/rendering.dart';

import '../../../zeta_flutter.dart';

const _horizontalArrowSize = Size(4, 8);
const _verticalArrowSize = Size(8, 4);

/// The direction of [ZetaTooltip]'s arrow
enum ZetaTooltipArrowDirection {
/// [up]
Expand Down Expand Up @@ -74,6 +77,10 @@ class ZetaTooltip extends StatelessWidget {
Widget build(BuildContext context) {
final zeta = Zeta.of(context);
final color = this.color ?? zeta.colors.textDefault;
final horizontalArrowWidth =
[ZetaTooltipArrowDirection.left, ZetaTooltipArrowDirection.right].contains(arrowDirection)
? _horizontalArrowSize.width
: 0;

return LayoutBuilder(
builder: (context, constraints) {
Expand All @@ -87,7 +94,7 @@ class ZetaTooltip extends StatelessWidget {
color: color,
direction: arrowDirection,
),
size: const Size(8, 4),
size: _verticalArrowSize,
),
),
Row(
Expand All @@ -100,12 +107,12 @@ class ZetaTooltip extends StatelessWidget {
color: color,
direction: arrowDirection,
),
size: const Size(4, 8),
size: _horizontalArrowSize,
),
),
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: maxWidth ?? constraints.maxWidth,
maxWidth: maxWidth ?? (constraints.maxWidth - horizontalArrowWidth),
),
child: DecoratedBox(
decoration: BoxDecoration(
Expand Down Expand Up @@ -136,7 +143,7 @@ class ZetaTooltip extends StatelessWidget {
color: color,
direction: arrowDirection,
),
size: const Size(4, 8),
size: _horizontalArrowSize,
),
),
],
Expand All @@ -148,7 +155,7 @@ class ZetaTooltip extends StatelessWidget {
color: color,
direction: arrowDirection,
),
size: const Size(8, 4),
size: _verticalArrowSize,
),
),
],
Expand Down

0 comments on commit 85cab8e

Please sign in to comment.