Skip to content

Commit

Permalink
table progress
Browse files Browse the repository at this point in the history
  • Loading branch information
GittHub-d committed Oct 5, 2023
1 parent 209e4ae commit cc57a49
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 175 deletions.
72 changes: 41 additions & 31 deletions example/lib/src/storybook/stories/table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
import 'package:moon_design/moon_design.dart';
import 'package:storybook_flutter/storybook_flutter.dart';

const _rowsInPage = 25;
const int _rowsInPage = 25;

List<_ExampleTableData> _exampleTableData = _generateTableData();
List<_ExampleTableData> _exampleTableDataToShow = _exampleTableData.sublist(0, _rowsInPage);
Expand All @@ -22,7 +22,7 @@ int _rowsToShow = _rowsInPage;
// Knob variables for methods to use outside TableStory.
bool _showCheckboxes = false;
bool _showDividerKnob = false;
bool _selectableKnob = false;
bool _rowsSelectableKnob = false;
bool _zebraStyleKnob = false;
bool _infiniteScrollKnob = false;
Color? _rowColor;
Expand Down Expand Up @@ -99,20 +99,20 @@ class TableStory extends Story {
max: 16,
);

final fixedHeaderKnob = context.knobs.boolean(
label: "hasFixedHeader",
description: "Show MoonTable with fixed header.",
final isHeaderPinnedKnob = context.knobs.boolean(
label: "isHeaderPinned",
description: "Show MoonTable with pinned header.",
initial: true,
);

final fixedFooterKnob = context.knobs.boolean(
label: "hasFixedFooter",
description: "Show MoonTable with fixed footer.",
final isFooterPinnedKnob = context.knobs.boolean(
label: "isFooterPinned",
description: "Show MoonTable with pinned footer.",
initial: true,
);

_selectableKnob = context.knobs.boolean(
label: "Selectable",
_rowsSelectableKnob = context.knobs.boolean(
label: "Rows selectable",
description: "Row onSelectChanged() is not null.",
initial: true,
);
Expand Down Expand Up @@ -154,23 +154,31 @@ class TableStory extends Story {
}

return Padding(
padding: const EdgeInsets.symmetric(vertical: 64.0),
child: MoonTable(
fixedHeader: fixedHeaderKnob,
fixedFooter: fixedFooterKnob,
sortAscending: _sortAscending,
sortColumnIndex: _sortColumnIndex,
rowGap: rowGapKnob?.toDouble(),
rowSize: tableRowSizeKnob ?? MoonTableRowSize.md,
tableHeader: _generateTableHeader(context, setState),
tableFooter: _generateTableFooter(context),
rows: _generateTableRows(context, setState),
cellPadding: EdgeInsets.symmetric(vertical: tableRowSizeKnob == MoonTableRowSize.xs ? 4 : 8),
onScrollControllersReady: (
ScrollController verticalScrollController,
ScrollController horizontalScrollController,
) =>
_scrollListener(setState, verticalScrollController),
padding: EdgeInsets.only(
top: MediaQuery.of(context).padding.top + 16.0,
bottom: 42.0,
),
child: OverflowBox(
maxWidth: MediaQuery.of(context).size.width,
child: MoonTable(
columnsCount: _showCheckboxes ? 6 : 5,
isHeaderPinned: isHeaderPinnedKnob,
isFooterPinned: isFooterPinnedKnob,
sortAscending: _sortAscending,
sortColumnIndex: _sortColumnIndex,
rowGap: rowGapKnob?.toDouble(),
rowSize: tableRowSizeKnob ?? MoonTableRowSize.md,
header: _generateTableHeader(context, setState),
footer: _generateTableFooter(context),
rows: _generateTableRows(context, setState),
tablePadding: const EdgeInsets.symmetric(horizontal: 16),
cellPadding: EdgeInsets.symmetric(vertical: tableRowSizeKnob == MoonTableRowSize.xs ? 4 : 8),
onScrollControllersReady: (
ScrollController verticalScrollController,
ScrollController horizontalScrollController,
) =>
_scrollListener(setState, verticalScrollController),
),
),
);
},
Expand Down Expand Up @@ -226,7 +234,7 @@ Widget _headerCheckBox(StateSetter setState) {
child: MoonCheckbox(
tapAreaSizeValue: 0,
value: _checkAllBoxes,
onChanged: _selectableKnob
onChanged: _rowsSelectableKnob
? (bool? onChanged) => onChanged != null
? setState(() {
_checkAllBoxes = onChanged;
Expand Down Expand Up @@ -280,7 +288,7 @@ MoonTableHeader _generateTableHeader(BuildContext context, StateSetter setState)
return MoonTableColumn(
width: columnWidth,
onTap: () {
if (checkboxColumn && _selectableKnob) {
if (checkboxColumn && _rowsSelectableKnob) {
setState(() {
_checkAllBoxes = !_checkAllBoxes;

Expand Down Expand Up @@ -337,7 +345,8 @@ List<MoonTableRow> _generateTableRows(BuildContext context, StateSetter setState

return MoonTableRow(
selected: row.selected,
onSelectChanged: _selectableKnob ? (bool? selected) => setState(() => row.selected = selected ?? false) : null,
onSelectChanged:
_rowsSelectableKnob ? (bool? selected) => setState(() => row.selected = selected ?? false) : null,
decoration: ShapeDecorationWithPremultipliedAlpha(
color: _zebraStyleKnob
? row.selected
Expand All @@ -361,7 +370,8 @@ List<MoonTableRow> _generateTableRows(BuildContext context, StateSetter setState
child: MoonCheckbox(
tapAreaSizeValue: 0,
value: row.selected,
onChanged: _selectableKnob ? (bool? onChanged) => setState(() => row.selected = !row.selected) : null,
onChanged:
_rowsSelectableKnob ? (bool? onChanged) => setState(() => row.selected = !row.selected) : null,
),
),
_buildCell(context, _exampleTableDataToShow[index].id, firstCell: !_showCheckboxes),
Expand Down
3 changes: 1 addition & 2 deletions example/lib/src/storybook/storybook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class StorybookPage extends StatelessWidget {
return Stack(
children: [
Storybook(
// initialStory: "Accordion",
initialStory: "Table",
initialStory: "Accordion",
plugins: _plugins,
brandingWidget: const MoonVersionWidget(),
wrapperBuilder: (BuildContext context, Widget? child) => MaterialApp(
Expand Down
18 changes: 10 additions & 8 deletions lib/src/theme/table/table_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class MoonTableColors extends ThemeExtension<MoonTableColors> with Diagnosticabl
/// Table row title text color.
final Color rowTitleTextColor;

/// Table row animated title text color.
final Color rowAnimatedTitleTextColor;
/// Table row pinned and animated title text color.
final Color rowPinnedAnimatedTitleTextColor;

/// Table icon color.
final Color iconColor;
Expand All @@ -27,7 +27,7 @@ class MoonTableColors extends ThemeExtension<MoonTableColors> with Diagnosticabl
required this.columnTextColor,
required this.rowTextColor,
required this.rowTitleTextColor,
required this.rowAnimatedTitleTextColor,
required this.rowPinnedAnimatedTitleTextColor,
required this.iconColor,
required this.rowBackgroundColor,
});
Expand All @@ -37,15 +37,15 @@ class MoonTableColors extends ThemeExtension<MoonTableColors> with Diagnosticabl
Color? columnTextColor,
Color? rowTextColor,
Color? rowTitleTextColor,
Color? rowAnimatedTitleTextColor,
Color? rowPinnedAnimatedTitleTextColor,
Color? iconColor,
Color? rowBackgroundColor,
}) {
return MoonTableColors(
columnTextColor: columnTextColor ?? this.columnTextColor,
rowTextColor: rowTextColor ?? this.rowTextColor,
rowTitleTextColor: rowTitleTextColor ?? this.rowTitleTextColor,
rowAnimatedTitleTextColor: rowAnimatedTitleTextColor ?? this.rowAnimatedTitleTextColor,
rowPinnedAnimatedTitleTextColor: rowPinnedAnimatedTitleTextColor ?? this.rowPinnedAnimatedTitleTextColor,
iconColor: iconColor ?? this.iconColor,
rowBackgroundColor: rowBackgroundColor ?? this.rowBackgroundColor,
);
Expand All @@ -58,8 +58,10 @@ class MoonTableColors extends ThemeExtension<MoonTableColors> with Diagnosticabl
return MoonTableColors(
columnTextColor: colorPremulLerp(columnTextColor, other.columnTextColor, t)!,
rowTextColor: colorPremulLerp(rowTextColor, other.rowTextColor, t)!,
rowTitleTextColor: colorPremulLerp(rowTitleTextColor, other.rowTitleTextColor, t)!,
rowAnimatedTitleTextColor: colorPremulLerp(rowAnimatedTitleTextColor, other.rowAnimatedTitleTextColor, t)!,
rowTitleTextColor:
colorPremulLerp(rowTitleTextColor, other.rowTitleTextColor, t)!,
rowPinnedAnimatedTitleTextColor:
colorPremulLerp(rowPinnedAnimatedTitleTextColor, other.rowPinnedAnimatedTitleTextColor, t)!,
iconColor: colorPremulLerp(iconColor, other.iconColor, t)!,
rowBackgroundColor: colorPremulLerp(rowBackgroundColor, other.rowBackgroundColor, t)!,
);
Expand All @@ -73,7 +75,7 @@ class MoonTableColors extends ThemeExtension<MoonTableColors> with Diagnosticabl
..add(ColorProperty("columnTextColor", columnTextColor))
..add(ColorProperty("rowTextColor", rowTextColor))
..add(ColorProperty("rowTitleTextColor", rowTitleTextColor))
..add(ColorProperty("rowAnimatedTitleTextColor", rowAnimatedTitleTextColor))
..add(ColorProperty("rowPinnedAnimatedTitleTextColor", rowPinnedAnimatedTitleTextColor))
..add(ColorProperty("iconColor", iconColor))
..add(ColorProperty("rowBackgroundColor", rowBackgroundColor));
}
Expand Down
12 changes: 6 additions & 6 deletions lib/src/theme/table/table_size_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MoonTableSizeProperties extends ThemeExtension<MoonTableSizeProperties> wi
final TextStyle rowTitleTextStyle;

/// Table row animated title text style.
final TextStyle rowAnimatedTitleTextStyle;
final TextStyle rowPinnedAnimatedTitleTextStyle;

const MoonTableSizeProperties({
required this.rowBorderRadius,
Expand All @@ -49,7 +49,7 @@ class MoonTableSizeProperties extends ThemeExtension<MoonTableSizeProperties> wi
required this.columnTextStyle,
required this.rowTextStyle,
required this.rowTitleTextStyle,
required this.rowAnimatedTitleTextStyle,
required this.rowPinnedAnimatedTitleTextStyle,
});

@override
Expand All @@ -64,7 +64,7 @@ class MoonTableSizeProperties extends ThemeExtension<MoonTableSizeProperties> wi
TextStyle? columnTextStyle,
TextStyle? rowTextStyle,
TextStyle? rowTitleTextStyle,
TextStyle? rowAnimatedTitleTextStyle,
TextStyle? rowPinnedAnimatedTitleTextStyle,
}) {
return MoonTableSizeProperties(
rowBorderRadius: rowBorderRadius ?? this.rowBorderRadius,
Expand All @@ -77,7 +77,7 @@ class MoonTableSizeProperties extends ThemeExtension<MoonTableSizeProperties> wi
columnTextStyle: columnTextStyle ?? this.columnTextStyle,
rowTextStyle: rowTextStyle ?? this.rowTextStyle,
rowTitleTextStyle: rowTitleTextStyle ?? this.rowTitleTextStyle,
rowAnimatedTitleTextStyle: rowAnimatedTitleTextStyle ?? this.rowAnimatedTitleTextStyle,
rowPinnedAnimatedTitleTextStyle: rowPinnedAnimatedTitleTextStyle ?? this.rowPinnedAnimatedTitleTextStyle,
);
}

Expand All @@ -96,7 +96,7 @@ class MoonTableSizeProperties extends ThemeExtension<MoonTableSizeProperties> wi
columnTextStyle: TextStyle.lerp(columnTextStyle, other.columnTextStyle, t)!,
rowTextStyle: TextStyle.lerp(rowTextStyle, other.rowTextStyle, t)!,
rowTitleTextStyle: TextStyle.lerp(rowTitleTextStyle, other.rowTitleTextStyle, t)!,
rowAnimatedTitleTextStyle: TextStyle.lerp(rowAnimatedTitleTextStyle, other.rowAnimatedTitleTextStyle, t)!,
rowPinnedAnimatedTitleTextStyle: TextStyle.lerp(rowPinnedAnimatedTitleTextStyle, other.rowPinnedAnimatedTitleTextStyle, t)!,
);
}

Expand All @@ -115,6 +115,6 @@ class MoonTableSizeProperties extends ThemeExtension<MoonTableSizeProperties> wi
..add(DiagnosticsProperty<TextStyle>("columnTextStyle", columnTextStyle))
..add(DiagnosticsProperty<TextStyle>("rowTextStyle", rowTextStyle))
..add(DiagnosticsProperty<TextStyle>("rowTitleTextStyle", rowTitleTextStyle))
..add(DiagnosticsProperty<TextStyle>("rowAnimatedTitleTextStyle", rowAnimatedTitleTextStyle));
..add(DiagnosticsProperty<TextStyle>("rowAnimatedTitleTextStyle", rowPinnedAnimatedTitleTextStyle));
}
}
12 changes: 6 additions & 6 deletions lib/src/theme/table/table_sizes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MoonTableSizes extends ThemeExtension<MoonTableSizes> with DiagnosticableT
columnTextStyle: tokens.typography.heading.text12,
rowTextStyle: tokens.typography.body.text12,
rowTitleTextStyle: tokens.typography.body.text12,
rowAnimatedTitleTextStyle: tokens.typography.body.text12,
rowPinnedAnimatedTitleTextStyle: tokens.typography.body.text12,
),
sm = sm ??
MoonTableSizeProperties(
Expand All @@ -61,7 +61,7 @@ class MoonTableSizes extends ThemeExtension<MoonTableSizes> with DiagnosticableT
columnTextStyle: tokens.typography.heading.textDefault,
rowTextStyle: tokens.typography.body.textDefault,
rowTitleTextStyle: tokens.typography.body.textDefault,
rowAnimatedTitleTextStyle: tokens.typography.body.textDefault,
rowPinnedAnimatedTitleTextStyle: tokens.typography.body.textDefault,
),
md = md ??
MoonTableSizeProperties(
Expand All @@ -75,7 +75,7 @@ class MoonTableSizes extends ThemeExtension<MoonTableSizes> with DiagnosticableT
columnTextStyle: tokens.typography.heading.textDefault,
rowTextStyle: tokens.typography.body.textDefault,
rowTitleTextStyle: tokens.typography.body.textDefault,
rowAnimatedTitleTextStyle: tokens.typography.body.textDefault,
rowPinnedAnimatedTitleTextStyle: tokens.typography.body.textDefault,
),
lg = lg ??
MoonTableSizeProperties(
Expand All @@ -89,7 +89,7 @@ class MoonTableSizes extends ThemeExtension<MoonTableSizes> with DiagnosticableT
columnTextStyle: tokens.typography.heading.textDefault,
rowTextStyle: tokens.typography.body.textDefault,
rowTitleTextStyle: tokens.typography.body.textDefault,
rowAnimatedTitleTextStyle: tokens.typography.body.textDefault,
rowPinnedAnimatedTitleTextStyle: tokens.typography.body.textDefault,
),
xl = xl ??
MoonTableSizeProperties(
Expand All @@ -103,7 +103,7 @@ class MoonTableSizes extends ThemeExtension<MoonTableSizes> with DiagnosticableT
columnTextStyle: tokens.typography.heading.textDefault,
rowTextStyle: tokens.typography.body.textDefault,
rowTitleTextStyle: tokens.typography.body.textDefault,
rowAnimatedTitleTextStyle: tokens.typography.body.textDefault,
rowPinnedAnimatedTitleTextStyle: tokens.typography.body.textDefault,
),
x2l = x2l ??
MoonTableSizeProperties(
Expand All @@ -117,7 +117,7 @@ class MoonTableSizes extends ThemeExtension<MoonTableSizes> with DiagnosticableT
columnTextStyle: tokens.typography.heading.textDefault,
rowTextStyle: tokens.typography.body.textDefault,
rowTitleTextStyle: tokens.typography.body.textDefault,
rowAnimatedTitleTextStyle: tokens.typography.body.textDefault,
rowPinnedAnimatedTitleTextStyle: tokens.typography.body.textDefault,
);

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/theme/table/table_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MoonTableTheme extends ThemeExtension<MoonTableTheme> with DiagnosticableT
columnTextColor: tokens.colors.textPrimary,
rowTextColor: tokens.colors.textPrimary,
rowTitleTextColor: tokens.colors.textPrimary,
rowAnimatedTitleTextColor: tokens.colors.trunks,
rowPinnedAnimatedTitleTextColor: tokens.colors.trunks,
iconColor: tokens.colors.iconPrimary,
rowBackgroundColor: tokens.colors.goku,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/common/border_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BorderContainer extends StatefulWidget {
_BorderContainerState createState() => _BorderContainerState();
}

class _BorderContainerState extends State<BorderContainer> with TickerProviderStateMixin {
class _BorderContainerState extends State<BorderContainer> with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _borderAnimation;
late ShapeBorderTween _border;
Expand Down
Loading

0 comments on commit cc57a49

Please sign in to comment.