Skip to content

Commit a568f63

Browse files
committed
chore: refactor grid cell expander
1 parent 7071db6 commit a568f63

File tree

6 files changed

+64
-40
lines changed

6 files changed

+64
-40
lines changed

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,19 @@ class BlankCell extends StatelessWidget {
4848
}
4949
}
5050

51+
abstract class GridCellExpander implements Widget {
52+
void onExpand(BuildContext context);
53+
}
54+
5155
abstract class GridCellWidget implements FlowyHoverWidget {
5256
@override
5357
final ValueNotifier<bool> onFocus = ValueNotifier<bool>(false);
5458

5559
final GridCellRequestFocusNotifier requestFocus = GridCellRequestFocusNotifier();
60+
61+
GridCellExpander? buildExpander() {
62+
return null;
63+
}
5664
}
5765

5866
class GridCellRequestFocusNotifier extends ChangeNotifier {
@@ -125,7 +133,7 @@ class CellStateNotifier extends ChangeNotifier {
125133

126134
class CellContainer extends StatelessWidget {
127135
final GridCellWidget child;
128-
final Widget? expander;
136+
final GridCellExpander? expander;
129137
final double width;
130138
final RegionStateNotifier rowStateNotifier;
131139
const CellContainer({
@@ -182,17 +190,33 @@ class CellContainer extends StatelessWidget {
182190

183191
class CellEnterRegion extends StatelessWidget {
184192
final Widget child;
185-
final Widget expander;
193+
final GridCellExpander expander;
186194
const CellEnterRegion({required this.child, required this.expander, Key? key}) : super(key: key);
187195

188196
@override
189197
Widget build(BuildContext context) {
198+
final theme = context.watch<AppTheme>();
199+
190200
return Selector<CellStateNotifier, bool>(
191201
selector: (context, notifier) => notifier.onEnter,
192202
builder: (context, onEnter, _) {
193203
List<Widget> children = [child];
194204
if (onEnter) {
195-
children.add(expander.positioned(right: 0));
205+
final hover = FlowyHover(
206+
style: HoverStyle(hoverColor: theme.bg3, backgroundColor: theme.surface),
207+
builder: (_, onHover) => Container(
208+
width: 26,
209+
height: 26,
210+
padding: const EdgeInsets.all(3),
211+
child: expander,
212+
),
213+
);
214+
215+
children.add(GestureDetector(
216+
child: hover,
217+
behavior: HitTestBehavior.opaque,
218+
onTap: () => expander.onExpand(context),
219+
).positioned(right: 0));
196220
}
197221

198222
return MouseRegion(

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/cell_editor.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class URLCellEditor extends StatefulWidget {
2525
//
2626
FlowyOverlay.of(context).insertWithAnchor(
2727
widget: OverlayContainer(
28-
child: SizedBox(width: 200, child: editor),
28+
child: SizedBox(
29+
width: 200,
30+
child: Padding(padding: const EdgeInsets.all(6), child: editor),
31+
),
2932
constraints: BoxConstraints.loose(const Size(300, 160)),
3033
),
3134
identifier: URLCellEditor.identifier(),

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22
import 'package:app_flowy/workspace/application/grid/cell/url_cell_bloc.dart';
33
import 'package:flowy_infra/image.dart';
44
import 'package:flowy_infra/theme.dart';
5+
import 'package:flowy_infra_ui/style_widget/hover.dart';
56
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
67
import 'package:flutter/gestures.dart';
78
import 'package:flutter/material.dart';
@@ -36,6 +37,12 @@ class GridURLCell extends StatefulWidget with GridCellWidget {
3637

3738
@override
3839
State<GridURLCell> createState() => _GridURLCellState();
40+
41+
@override
42+
GridCellExpander? buildExpander() {
43+
final cellContext = cellContextBuilder.build() as GridURLCellContext;
44+
return _EditURLCellIndicator(cellContext: cellContext);
45+
}
3946
}
4047

4148
class _GridURLCellState extends State<GridURLCell> {
@@ -70,13 +77,7 @@ class _GridURLCellState extends State<GridURLCell> {
7077
),
7178
);
7279

73-
return CellEnterRegion(
74-
child: Align(alignment: Alignment.centerLeft, child: richText),
75-
expander: _EditCellIndicator(onTap: () {
76-
final cellContext = widget.cellContextBuilder.build() as GridURLCellContext;
77-
URLCellEditor.show(context, cellContext);
78-
}),
79-
);
80+
return Align(alignment: Alignment.centerLeft, child: richText);
8081
},
8182
),
8283
);
@@ -115,20 +116,18 @@ class _GridURLCellState extends State<GridURLCell> {
115116
}
116117
}
117118

118-
class _EditCellIndicator extends StatelessWidget {
119-
final VoidCallback onTap;
120-
const _EditCellIndicator({required this.onTap, Key? key}) : super(key: key);
119+
class _EditURLCellIndicator extends StatelessWidget with GridCellExpander {
120+
final GridURLCellContext cellContext;
121+
const _EditURLCellIndicator({required this.cellContext, Key? key}) : super(key: key);
121122

122123
@override
123124
Widget build(BuildContext context) {
124125
final theme = context.watch<AppTheme>();
125-
return FlowyIconButton(
126-
width: 26,
127-
onPressed: onTap,
128-
hoverColor: theme.hover,
129-
radius: BorderRadius.circular(4),
130-
iconPadding: const EdgeInsets.all(5),
131-
icon: svgWidget("editor/edit", color: theme.iconColor),
132-
);
126+
return svgWidget("editor/edit", color: theme.iconColor);
127+
}
128+
129+
@override
130+
void onExpand(BuildContext context) {
131+
URLCellEditor.show(context, cellContext);
133132
}
134133
}

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/field_cell.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class _GridHeaderCellContainer extends StatelessWidget {
8686
Widget build(BuildContext context) {
8787
final theme = context.watch<AppTheme>();
8888
final borderSide = BorderSide(color: theme.shader5, width: 1.0);
89-
9089
final decoration = BoxDecoration(
9190
border: Border(
9291
top: borderSide,

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,15 @@ class _RowCells extends StatelessWidget {
170170
List<Widget> _makeCells(BuildContext context, GridCellMap gridCellMap) {
171171
return gridCellMap.values.map(
172172
(gridCell) {
173-
Widget? expander;
173+
final GridCellWidget child = buildGridCellWidget(gridCell, cellCache);
174+
GridCellExpander? expander = child.buildExpander();
174175
if (gridCell.field.isPrimary) {
175-
expander = _CellExpander(onExpand: onExpand);
176+
expander = _PrimaryCellExpander(onTap: onExpand);
176177
}
177178

178179
return CellContainer(
179180
width: gridCell.field.width.toDouble(),
180-
child: buildGridCellWidget(gridCell, cellCache),
181+
child: child,
181182
rowStateNotifier: Provider.of<RegionStateNotifier>(context, listen: false),
182183
expander: expander,
183184
);
@@ -199,23 +200,19 @@ class RegionStateNotifier extends ChangeNotifier {
199200
bool get onEnter => _onEnter;
200201
}
201202

202-
class _CellExpander extends StatelessWidget {
203-
final VoidCallback onExpand;
204-
const _CellExpander({required this.onExpand, Key? key}) : super(key: key);
203+
class _PrimaryCellExpander extends StatelessWidget with GridCellExpander {
204+
final VoidCallback onTap;
205+
const _PrimaryCellExpander({required this.onTap, Key? key}) : super(key: key);
205206

206207
@override
207208
Widget build(BuildContext context) {
208209
final theme = context.watch<AppTheme>();
209-
return FittedBox(
210-
fit: BoxFit.contain,
211-
child: FlowyIconButton(
212-
width: 26,
213-
onPressed: onExpand,
214-
iconPadding: const EdgeInsets.all(5),
215-
radius: BorderRadius.circular(4),
216-
icon: svgWidget("grid/expander", color: theme.main1),
217-
),
218-
);
210+
return svgWidget("grid/expander", color: theme.main1);
211+
}
212+
213+
@override
214+
void onExpand(BuildContext context) {
215+
onTap();
219216
}
220217
}
221218

frontend/app_flowy/packages/flowy_infra_ui/lib/style_widget/hover.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class _FlowyHoverState extends State<FlowyHover> {
5252
child: child,
5353
);
5454
} else {
55-
return child;
55+
return Container(child: child, color: widget.style.backgroundColor);
5656
}
5757
}
5858
}
@@ -63,12 +63,14 @@ class HoverStyle {
6363
final Color hoverColor;
6464
final BorderRadius borderRadius;
6565
final EdgeInsets contentMargin;
66+
final Color backgroundColor;
6667

6768
const HoverStyle(
6869
{this.borderColor = Colors.transparent,
6970
this.borderWidth = 0,
7071
this.borderRadius = const BorderRadius.all(Radius.circular(6)),
7172
this.contentMargin = EdgeInsets.zero,
73+
this.backgroundColor = Colors.transparent,
7274
required this.hoverColor});
7375
}
7476

0 commit comments

Comments
 (0)