Skip to content

Commit 60ceaa8

Browse files
committed
feat(ui): Add inactive state to table
1 parent f2b1d91 commit 60ceaa8

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

packages/memex_ui/lib/color.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class MemexColor {
66

77
static const Color text = Color(0xFF000000);
88
static const Color textSelection = Color(0x55007aFF);
9-
static const Color selection = CupertinoColors.activeBlue;
9+
static const Color selection = CupertinoColors.systemBlue;
10+
static const Color selectionInactive = Color.fromARGB(255, 127, 189, 255);
1011
static const Color grid = Color.fromARGB(44, 0, 0, 0);
1112
static const Color shade = Color.fromARGB(16, 0, 0, 0);
1213
static const Color transparent = Color.fromARGB(0, 0, 0, 0);

packages/memex_ui/lib/key_label.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/cupertino.dart';
12
import 'package:flutter/services.dart';
23
import 'package:memex_ui/memex_ui.dart';
34

@@ -69,7 +70,7 @@ class KeyLabel extends StatelessWidget {
6970
Size textContentSize = _calculateTextContentSize();
7071
return Container(
7172
decoration: BoxDecoration(
72-
color: MemexColor.white,
73+
color: CupertinoColors.systemYellow,
7374
borderRadius: BorderRadius.circular(4),
7475
border: Border.all(
7576
color: MemexColor.grid,

packages/memex_ui/lib/miller_columns/miller_columns.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class MillerColumnsState<Key, Node> extends State<MillerColumns<Key, Node>> {
284284
showHeader: false,
285285
fullWidthHighlight: true,
286286
showEvenRowHighlight: false,
287+
isActive: Prop(isLast),
287288
),
288289
),
289290
),

packages/memex_ui/lib/table/table_row.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class TableViewRow<T> extends StatelessWidget {
1212
required this.row,
1313
required this.rowHeight,
1414
required this.data,
15+
this.isActive,
1516
this.fullWidthHighlight = false,
1617
bool showEvenRowHighlight = true,
1718
}) : hasEvenRowHighlight = (showEvenRowHighlight) ? index % 2 == 1 : false;
@@ -29,14 +30,18 @@ class TableViewRow<T> extends StatelessWidget {
2930
final bool hasEvenRowHighlight;
3031
final bool fullWidthHighlight;
3132

33+
/// When the table is not active, the selection color is grey.
34+
final Prop<bool>? isActive;
35+
3236
@override
3337
Widget build(BuildContext context) {
3438
return GestureDetector(
3539
onTap: () {
3640
data.select(TableSelection(key: row.key, value: row.value));
3741
},
3842
behavior: HitTestBehavior.opaque,
39-
child: Padding(
43+
child: AnimatedContainer(
44+
duration: const Duration(milliseconds: 75),
4045
padding: fullWidthHighlight
4146
? EdgeInsets.zero
4247
: const EdgeInsets.symmetric(horizontal: 10),
@@ -61,6 +66,7 @@ class TableViewRow<T> extends StatelessWidget {
6166
hasEvenRowHighlight: hasEvenRowHighlight,
6267
fullWidthHighlight: fullWidthHighlight,
6368
isSelected: isSelected,
69+
isActive: isActive,
6470
columnWidths: columnWidths,
6571
childrenBuilder: (context) => colDefs.map((colDef) {
6672
final AlignmentGeometry alignmentGeometry =
@@ -89,8 +95,9 @@ class TableViewRow<T> extends StatelessWidget {
8995
}
9096

9197
/// Add selection and even / odd highlighting to table rows
92-
class _RowHighlight extends StatelessWidget {
98+
class _RowHighlight extends ReactiveWidget {
9399
const _RowHighlight({
100+
this.isActive,
94101
required this.hasEvenRowHighlight,
95102
required this.fullWidthHighlight,
96103
required this.isSelected,
@@ -100,6 +107,10 @@ class _RowHighlight extends StatelessWidget {
100107

101108
final bool hasEvenRowHighlight;
102109
final bool fullWidthHighlight;
110+
111+
/// When the table is not active, the selection color is grey.
112+
final Prop<bool>? isActive;
113+
103114
final bool isSelected;
104115
final Map<int, TableColumnWidth> columnWidths;
105116
final List<Widget> Function(BuildContext) childrenBuilder;
@@ -118,7 +129,9 @@ class _RowHighlight extends StatelessWidget {
118129
);
119130
} else if (isSelected) {
120131
decoration = BoxDecoration(
121-
color: MemexColor.selection,
132+
color: (isActive?.value ?? true)
133+
? MemexColor.selection
134+
: MemexColor.selectionInactive,
122135
borderRadius: fullWidthHighlight
123136
? null
124137
: const BorderRadius.all(Radius.circular(5)),

packages/memex_ui/lib/table/table_view.dart

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import './table_row.dart';
44

55
/// A scrollable data table with sorting and selection.
66
class TableView<T> extends ReactiveWidget {
7-
const TableView({
7+
TableView({
88
super.key,
99
this.scrollController,
1010
required this.rowHeight,
1111
required this.dataSource,
1212
this.showHeader = true,
1313
this.showEvenRowHighlight = true,
14+
this.isActive,
1415
this.fullWidthHighlight = false,
1516
});
1617

@@ -28,6 +29,9 @@ class TableView<T> extends ReactiveWidget {
2829
/// in which case it is also not rounded.
2930
final bool fullWidthHighlight;
3031

32+
/// When the table is not active, the selection color is grey.
33+
final Prop<bool>? isActive;
34+
3135
/// Optionally override the scrollController.
3236
final ScrollController? scrollController;
3337
final TableDatasource<T> dataSource;
@@ -45,21 +49,18 @@ class TableView<T> extends ReactiveWidget {
4549
builder: (context, order) => ReactiveBuilder(
4650
() => Column(
4751
children: [
48-
...showHeader
49-
? [
50-
TableHeader<T>(
51-
colDefs: dataSource.colDefs,
52-
order: order.data,
53-
columnHeaderClicked: (colDef) {
54-
if (colDef == order.data?.column) {
55-
dataSource.reverseOrderDirection();
56-
} else {
57-
dataSource.orderBy(TableOrder(column: colDef));
58-
}
59-
},
60-
)
61-
]
62-
: [],
52+
if (showHeader)
53+
TableHeader<T>(
54+
colDefs: dataSource.colDefs,
55+
order: order.data,
56+
columnHeaderClicked: (colDef) {
57+
if (colDef == order.data?.column) {
58+
dataSource.reverseOrderDirection();
59+
} else {
60+
dataSource.orderBy(TableOrder(column: colDef));
61+
}
62+
},
63+
),
6364
Expanded(
6465
child: StreamBuilder<void>(
6566
initialData: null,
@@ -78,6 +79,7 @@ class TableView<T> extends ReactiveWidget {
7879
row: dataSource.getRowValue(index),
7980
showEvenRowHighlight: showEvenRowHighlight,
8081
fullWidthHighlight: fullWidthHighlight,
82+
isActive: isActive,
8183
);
8284
},
8385
),

0 commit comments

Comments
 (0)