Skip to content

Commit

Permalink
fix: pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Oct 5, 2024
1 parent be31019 commit 3e574b0
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ class PaginationLibraryInputs extends ComponentLibraryInputs {
final ComponentLibraryIntInput page = ComponentLibraryIntInput(
'Page',
initialValue: 1,
min: 1,
);
final ComponentLibraryIntInput amountOfItems = ComponentLibraryIntInput(
'amountOfItems',
initialValue: 55,
min: 1,
);
final ComponentLibraryIntInput itemsPerPage = ComponentLibraryIntInput(
'itemsPerPage',
initialValue: 10,
min: 1,
);
@override
List<ComponentLibraryInputItem> buildInputItems() => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import 'package:impaktfull_ui_2/impaktfull_ui.dart';
import 'package:impaktfull_ui_example/src/component_library/components/pagination/pagination_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/config/component_library_item.dart';

class PaginationLibraryVariant extends ComponentLibraryVariant<PaginationLibraryPrimaryInputs> {
class PaginationLibraryVariant
extends ComponentLibraryVariant<PaginationLibraryPrimaryInputs> {
const PaginationLibraryVariant();

@override
String get title => 'Default';

@override
List<Widget> build(BuildContext context, PaginationLibraryPrimaryInputs inputs) {
List<Widget> build(
BuildContext context, PaginationLibraryPrimaryInputs inputs) {
return [
ImpaktfullUiPagination(
amountOfItems: inputs.amountOfItems.value ?? 0,
itemsPerPage: inputs.itemsPerPage.value ?? 0,
page: inputs.page.value ?? 0,
amountOfItems: inputs.amountOfItems.value ?? 1,
itemsPerPage: inputs.itemsPerPage.value ?? 1,
page: inputs.page.value ?? 1,
onLoadPage: (page) {
inputs.page.updateState(page);
ImpaktfullUiNotification.show(title: 'Load page $page');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import 'package:impaktfull_ui_example/src/component_library/config/component_lib
import 'package:impaktfull_ui_example/src/util/network_images.dart';
import 'package:impaktfull_ui_example/src/widget/components/components_library_variant_descriptor.dart';

class SidebarNavigationLibraryVariant extends ComponentLibraryVariant<SidebarNavigationLibraryPrimaryInputs> {
class SidebarNavigationLibraryVariant
extends ComponentLibraryVariant<SidebarNavigationLibraryPrimaryInputs> {
const SidebarNavigationLibraryVariant();

@override
String get title => 'Default';

@override
List<Widget> build(BuildContext context, SidebarNavigationLibraryPrimaryInputs inputs) {
List<Widget> build(
BuildContext context, SidebarNavigationLibraryPrimaryInputs inputs) {
return [
ComponentsLibraryVariantDescriptor(
height: 250,
Expand Down Expand Up @@ -68,7 +70,8 @@ class SidebarNavigationLibraryVariant extends ComponentLibraryVariant<SidebarNav
title: 'Search',
),
],
secondaryItems: List.generate(inputs.amountOfSecondaryItems.value ?? 0, (index) => index)
secondaryItems: List.generate(
inputs.amountOfSecondaryItems.value ?? 0, (index) => index)
.map(
(index) => ImpaktfullUiSidebarNavigationItem(
leading: theme.assets.icons.confetti,
Expand Down Expand Up @@ -102,7 +105,9 @@ class SidebarNavigationLibraryVariant extends ComponentLibraryVariant<SidebarNav
),
),
trailingWidgetBuilder: (context) => const SizedBox(width: 40),
borderRadius: ImpaktfullUiSidebarNavigationItemTheme.of(context).dimens.borderRadius,
borderRadius: ImpaktfullUiSidebarNavigationItemTheme.of(context)
.dimens
.borderRadius,
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
Expand All @@ -118,7 +123,8 @@ class SidebarNavigationLibraryVariant extends ComponentLibraryVariant<SidebarNav
textDirection: Directionality.of(context),
child: ImpaktfullUiIconButton(
asset: theme.assets.icons.logout,
onTap: () => ImpaktfullUiNotification.show(title: 'Logout tapped'),
onTap: () =>
ImpaktfullUiNotification.show(title: 'Logout tapped'),
),
),
],
Expand All @@ -129,7 +135,9 @@ class SidebarNavigationLibraryVariant extends ComponentLibraryVariant<SidebarNav
}

@override
SidebarNavigationLibraryPrimaryInputs inputs() => SidebarNavigationLibraryPrimaryInputs();
SidebarNavigationLibraryPrimaryInputs inputs() =>
SidebarNavigationLibraryPrimaryInputs();
}

class SidebarNavigationLibraryPrimaryInputs extends SidebarNavigationLibraryInputs {}
class SidebarNavigationLibraryPrimaryInputs
extends SidebarNavigationLibraryInputs {}
11 changes: 8 additions & 3 deletions lib/src/components/button/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class _ImpaktfullUiButtonState extends State<ImpaktfullUiButton> {
child: Padding(
padding: _getPadding(componentTheme),
child: ImpaktfullUiAutoLayout.horizontal(
mainAxisSize: widget.fullWidth ? MainAxisSize.max : MainAxisSize.min,
mainAxisSize: widget.fullWidth
? MainAxisSize.max
: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
spacing: 4,
children: [
Expand Down Expand Up @@ -131,15 +133,18 @@ class _ImpaktfullUiButtonState extends State<ImpaktfullUiButton> {
duration: theme.durations.short,
curve: Curves.easeInOut,
child: ImpaktfullUiAutoLayout.horizontal(
mainAxisSize: widget.fullWidth ? MainAxisSize.max : MainAxisSize.min,
mainAxisSize:
widget.fullWidth ? MainAxisSize.max : MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
spacing: 4,
children: [
Expanded(
flex: widget.fullWidth ? 1 : 0,
child: SizedBox(
height: _getLoadingSize(),
child: _isLoading ? ImpaktfullUiLoadingIndicator(color: color) : const SizedBox(),
child: _isLoading
? ImpaktfullUiLoadingIndicator(color: color)
: const SizedBox(),
),
),
],
Expand Down
8 changes: 5 additions & 3 deletions lib/src/components/pagination/pagination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ export 'pagination_style.dart';

part 'pagination.describe.dart';

class ImpaktfullUiPagination extends StatelessWidget with ComponentDescriptorMixin {
class ImpaktfullUiPagination extends StatelessWidget
with ComponentDescriptorMixin {
final int page;
final int itemsPerPage;
final int amountOfItems;
final ValueChanged<int> onLoadPage;
final ImpaktfullUiPaginationTheme? theme;

int get amountOfPages => (amountOfItems / itemsPerPage).ceil();
bool get isFinalPage => page == amountOfPages;
bool get isFinalPage => page >= amountOfPages;

const ImpaktfullUiPagination({
required this.page,
Expand All @@ -32,7 +33,8 @@ class ImpaktfullUiPagination extends StatelessWidget with ComponentDescriptorMix
Widget build(BuildContext context) {
return ImpaktfullUiComponentThemeBuidler<ImpaktfullUiPaginationTheme>(
overrideComponentTheme: theme,
builder: (context, theme, componentTheme) => ImpaktfullUiAutoLayout.horizontal(
builder: (context, theme, componentTheme) =>
ImpaktfullUiAutoLayout.horizontal(
spacing: 8,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expand Down
5 changes: 3 additions & 2 deletions lib/src/components/pagination/pagination.describe.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
part of 'pagination.dart';

String _describeInstance(BuildContext context, ImpaktfullUiPagination instance) {
String _describeInstance(
BuildContext context, ImpaktfullUiPagination instance) {
final descriptor = ComponentDescriptor();
descriptor.add('theme', instance.theme);
return descriptor.describe();
}
}
3 changes: 2 additions & 1 deletion lib/src/components/pagination/pagination_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class ImpaktfullUiPaginationTheme extends ImpaktfullUiComponentTheme {
required this.textStyles,
});

static ImpaktfullUiPaginationTheme of(BuildContext context) => ImpaktfullUiTheme.of(context).components.pagination;
static ImpaktfullUiPaginationTheme of(BuildContext context) =>
ImpaktfullUiTheme.of(context).components.pagination;
}

class ImpaktfullUiPaginationAssetsTheme {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/theme/asset_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class ImpaktfullUiAssetTheme {
error: ImpaktfullUiAsset.icon(PhosphorIcons.warningDiamond()),
home: ImpaktfullUiAsset.icon(PhosphorIcons.houseSimple()),
info: ImpaktfullUiAsset.icon(PhosphorIcons.info()),
lineVertical: ImpaktfullUiAsset.icon(PhosphorIcons.lineVertical()),
lineVertical:
ImpaktfullUiAsset.icon(PhosphorIcons.lineVertical()),
list: ImpaktfullUiAsset.icon(PhosphorIcons.list()),
logout: ImpaktfullUiAsset.icon(PhosphorIcons.signOut()),
minus: ImpaktfullUiAsset.icon(PhosphorIcons.minus()),
Expand Down
5 changes: 3 additions & 2 deletions lib/src/theme/component_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ class ImpaktfullUiComponentsTheme {
pagination: pagination ?? this.pagination,
refreshIndicator: refreshIndicator ?? this.refreshIndicator,
sidebarNavigation: sidebarNavigation ?? this.sidebarNavigation,
sidebarNavigationItem: sidebarNavigationItem ?? this.sidebarNavigationItem,
sidebarNavigationItem:
sidebarNavigationItem ?? this.sidebarNavigationItem,
simpleListItem: simpleListItem ?? this.simpleListItem,
snackyConfigurator: snackyConfigurator ?? this.snackyConfigurator,
switchTheme: switchTheme ?? this.switchTheme,
Expand Down Expand Up @@ -243,7 +244,7 @@ class ImpaktfullUiComponentsTheme {
return ImpaktfullUiNotificationBadgeTheme.of(context) as T;
} else if (T == ImpaktfullUiPaginationTheme) {
return ImpaktfullUiPaginationTheme.of(context) as T;
} else if (T == ImpaktfullUiRefreshIndicatorTheme) {
} else if (T == ImpaktfullUiRefreshIndicatorTheme) {
return ImpaktfullUiRefreshIndicatorTheme.of(context) as T;
} else if (T == ImpaktfullUiSidebarNavigationTheme) {
return ImpaktfullUiSidebarNavigationTheme.of(context) as T;
Expand Down
17 changes: 11 additions & 6 deletions lib/src/theme/theme_default.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ class DefaultTheme {
destructive: destructive ?? const Color(0xFFBD0D00),
);
final dimens = ImpaktfullUiDimensTheme(
borderRadiusExtraSmall: borderRadiusExtraSmall ?? BorderRadius.circular(4),
borderRadiusExtraSmall:
borderRadiusExtraSmall ?? BorderRadius.circular(4),
borderRadiusSmall: borderRadiusSmall ?? BorderRadius.circular(6),
borderRadius: borderRadiusSmall ?? BorderRadius.circular(8),
borderRadiusLarge: borderRadiusLarge ?? BorderRadius.circular(12),
borderRadiusExtraLarge: borderRadiusExtraLarge ?? BorderRadius.circular(16),
borderRadiusExtraLarge:
borderRadiusExtraLarge ?? BorderRadius.circular(16),
borderRadiusCircle: BorderRadius.circular(99999999),
);
final textStyles = ImpaktfullUiTextStylesTheme(
Expand Down Expand Up @@ -256,7 +258,8 @@ class DefaultTheme {
alternative: textStyles.onCardPrimary.text.small.bold,
grey: textStyles.onCard.text.small.bold,
destructivePrimary: textStyles.onDestructive.text.small.bold,
destructiveAlternative: textStyles.onCardDestructive.text.small.bold,
destructiveAlternative:
textStyles.onCardDestructive.text.small.bold,
),
),
card: ImpaktfullUiCardTheme(
Expand Down Expand Up @@ -375,8 +378,9 @@ class DefaultTheme {
),
textStyles: ImpaktfullUiInputFieldTextStylesTheme(
text: textStyles.onCard.text.medium,
hint: textStyles.onCardSecondary.text.medium
.copyWith(color: textStyles.onCardTertiary.text.medium.color?.withOpacity(0.5)),
hint: textStyles.onCardSecondary.text.medium.copyWith(
color: textStyles.onCardTertiary.text.medium.color
?.withOpacity(0.5)),
label: textStyles.onCard.text.small.medium,
),
),
Expand Down Expand Up @@ -487,7 +491,8 @@ class DefaultTheme {
),
),
refreshIndicator: ImpaktfullUiRefreshIndicatorTheme(
colors: ImpaktfullUiRefreshIndicatorColorTheme(loadingIndicator: colors.accent),
colors: ImpaktfullUiRefreshIndicatorColorTheme(
loadingIndicator: colors.accent),
),
sidebarNavigation: ImpaktfullUiSidebarNavigationTheme(
assets: const ImpaktfullUiSidebarNavigationAssetsTheme(),
Expand Down

0 comments on commit 3e574b0

Please sign in to comment.