Skip to content

Commit ad81056

Browse files
Load more component misc fixes (#740)
* feat(components): add LoadMore component for dynamic list expansion Introduce LoadMore component to allow users to load additional items into a list. This component includes a "Show More" button and an optional count indicator. It supports a loading state and automatically hides the button when all items are loaded. This addition enhances user experience by providing a seamless way to view more content without navigating away from the current page. * refactor(stories): update LoadMore stories to use StoryObj for improved type safety and readability fix(stories): correct story names to follow consistent naming convention * style(types.ts): add semicolons to type definitions for consistency and readability * refactor(LoadMore.tsx, LoadMoreList.tsx): convert components from arrow functions to named functions for improved readability and consistency fix(LoadMoreList.tsx): change key in list items from index to item value to ensure unique keys and prevent potential rendering issues * style(loadMore): remove redundant comments for cleaner code Remove unnecessary comments in LoadMoreList.tsx and LoadMore.stories.tsx to improve code readability and maintainability. * feat(loadMore): add "Show Less" button functionality to LoadMore component Add a "Show Less" button to allow users to reduce the number of displayed items. This enhances user control over the list view, especially when dealing with large datasets. Update stories to reflect the new feature and rename "WithoutCount" to "WithCount" for clarity. * feat(loadMore): add "Show Less" button functionality to allow users to reduce items docs(loadMore): update documentation to include "Show Less" button usage style(PaginationAmount): adjust spacing in pagination result display for consistency * Update src/components/loadMore/LoadMore.stories.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/components/loadMore/LoadMore.stories.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * chore(package.json): bump version from 10.4.6 to 10.4.8 to prepare for new release * test(ExtendedPagination.spec.tsx): remove space in result range display to ensure consistency in text rendering * style(pagination): add space after dash in pagination display Ensure consistent spacing in pagination text for better readability. * chore(package.json): bump version from 10.4.8 to 10.5.0 to reflect new features or improvements * test(ExtendedPagination.spec.tsx): fix spacing in expected text for consistency in test assertions * style(vscode): change eslint fixAll setting to "explicit" for clarity fix(ExtendedPagination.spec.tsx): add space after hyphen in text assertions for consistency style(LoadMore.tsx): change height to min-height for better layout flexibility feat(LoadMore.tsx): add inline styles and icons to buttons for improved UI feat(PaginationAmount.tsx): add optional style prop for custom styling of pagination results * restore vscode eslint setting * chore(package.json): bump version from 10.5.0 to 10.5.1 for patch release * test(extendedPagination.spec.tsx): add assertions to verify elements are in the document to improve test reliability --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 16e12b8 commit ad81056

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nordcloud/gnui",
33
"description": "Nordcloud Design System - a collection of reusable React components used in Nordcloud's SaaS products",
4-
"version": "10.5.0",
4+
"version": "10.5.1",
55
"license": "MIT",
66
"repository": {
77
"type": "git",

src/components/extendedPagination/ExtendedPagination.spec.tsx

+14-6
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,31 @@ const getParams = (firstPage = 0, from = 0, count = 200) => ({
3838
test("shows current number of results", async () => {
3939
const params = getParams();
4040
getComponent(params);
41-
await screen.findByText(`1 -${params.size} of ${params.count}`);
41+
const element = await screen.findByText(
42+
`1 - ${params.size} of ${params.count}`
43+
);
44+
expect(element).toBeInTheDocument();
4245
});
4346

4447
test("shows current number of results for start index 1", async () => {
4548
const params = getParams(1);
4649
getComponent(params);
47-
await screen.findByText(`1 -${params.size} of ${params.count}`);
50+
const element = await screen.findByText(
51+
`1 - ${params.size} of ${params.count}`
52+
);
53+
expect(element).toBeInTheDocument();
4854
});
4955

5056
test("shows `per page` component", async () => {
5157
getComponent(getParams());
52-
await screen.findByText(/show/i);
58+
const element = await screen.findByText(/show/i);
59+
expect(element).toBeInTheDocument();
5360
});
5461

5562
test("shows `per page` component for start index 1", async () => {
5663
getComponent(getParams(1));
57-
await screen.findByText(/show/i);
64+
const element = await screen.findByText(/show/i);
65+
expect(element).toBeInTheDocument();
5866
});
5967

6068
test("shows last page button on 1st page", () => {
@@ -182,7 +190,7 @@ test("renders without number of results and `per page` for small screens", () =>
182190

183191
expect(screen.queryByText(/show/i)).not.toBeInTheDocument();
184192
expect(
185-
screen.queryByText(`1 -${params.size} of ${params.count}`)
193+
screen.queryByText(`1 - ${params.size} of ${params.count}`)
186194
).not.toBeInTheDocument();
187195
});
188196

@@ -202,6 +210,6 @@ test("renders without number of results and `per page` for small screens for sta
202210

203211
expect(screen.queryByText(/show/i)).not.toBeInTheDocument();
204212
expect(
205-
screen.queryByText(`1 -${params.size} of ${params.count}`)
213+
screen.queryByText(`1 - ${params.size} of ${params.count}`)
206214
).not.toBeInTheDocument();
207215
});

src/components/loadMore/LoadMore.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const Container = styled(StyledPaginationBox)<{ hideCount?: boolean }>`
99
justify-content: ${({ hideCount }) =>
1010
hideCount ? "center" : "space-between"};
1111
padding: ${theme.spacing.spacing02} ${theme.spacing.spacing03};
12-
height: 36px;
12+
min-height: 36px;
1313
`;
1414

1515
/**
@@ -31,7 +31,12 @@ export function LoadMore({
3131
return (
3232
<Container className={className} small={false} hideCount={hideCount}>
3333
{!hideCount && (
34-
<PaginationAmount from={0} size={currentCount} count={total} />
34+
<PaginationAmount
35+
from={0}
36+
size={currentCount}
37+
count={total}
38+
style={{ width: "auto" }}
39+
/>
3540
)}
3641

3742
{hasMoreItems && (
@@ -41,6 +46,8 @@ export function LoadMore({
4146
initialState={isLoading ? "loading" : undefined}
4247
aria-label="Show more items"
4348
disabled={isLoading}
49+
style={{ margin: 0 }}
50+
icon="chevronDown"
4451
onClick={onLoadMore}
4552
>
4653
{isLoading ? "Loading..." : "Show more"}
@@ -54,6 +61,8 @@ export function LoadMore({
5461
aria-label="Show less items"
5562
initialState={isLoading ? "loading" : undefined}
5663
disabled={isLoading}
64+
style={{ margin: 0 }}
65+
icon="chevronUp"
5766
onClick={onLoadLess}
5867
>
5968
{isLoading ? "Loading..." : "Show less"}

src/components/paginationHelpers/PaginationAmount.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ type Props = {
55
size: number;
66
count: number;
77
firstPage?: number;
8+
style?: React.CSSProperties;
89
};
910

10-
export function PaginationAmount({ from, size, count, firstPage = 0 }: Props) {
11+
export function PaginationAmount({
12+
from,
13+
size,
14+
count,
15+
firstPage = 0,
16+
style,
17+
}: Props) {
1118
const isFirstPageZero = firstPage === 0;
1219

1320
const s = Number(size);
@@ -21,8 +28,8 @@ export function PaginationAmount({ from, size, count, firstPage = 0 }: Props) {
2128
const max = maxCurrentPage < 1 ? size : maxCurrentPage;
2229

2330
return (
24-
<div className="pagination-result">
25-
{min} -{max > count ? count : max} of {count}
31+
<div className="pagination-result" style={style}>
32+
{min} - {max > count ? count : max} of {count}
2633
</div>
2734
);
2835
}

0 commit comments

Comments
 (0)