@dt-dds/react-pagination 1.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,228 @@
1
+ # @dt-ui/react-pagination
2
+
3
+ ## 1.0.0-beta.21
4
+
5
+ ### Major Changes
6
+
7
+ - refactor!: rename pkg and publish to npmjs
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @dt-dds/react-core@1.0.0-beta.41
13
+ - @dt-dds/react-icon@1.0.0-beta.42
14
+ - @dt-dds/react-typography@1.0.0-beta.32
15
+
16
+ ## 0.1.0-beta.20
17
+
18
+ ### Patch Changes
19
+
20
+ - refactor: drop icon funcional state
21
+ - Updated dependencies
22
+ - @dt-ui/react-icon@0.1.0-beta.41
23
+
24
+ ## 0.1.0-beta.19
25
+
26
+ ### Patch Changes
27
+
28
+ - refactor: theme typography values
29
+ - Updated dependencies
30
+ - @dt-ui/react-core@0.1.0-beta.40
31
+ - @dt-ui/react-icon@0.1.0-beta.40
32
+ - @dt-ui/react-typography@0.1.0-beta.31
33
+
34
+ ## 0.1.0-beta.18
35
+
36
+ ### Minor Changes
37
+
38
+ - feat: update shadow theme values
39
+
40
+ ### Patch Changes
41
+
42
+ - Updated dependencies
43
+ - @dt-ui/react-core@0.1.0-beta.39
44
+ - @dt-ui/react-icon@0.1.0-beta.39
45
+ - @dt-ui/react-typography@0.1.0-beta.30
46
+
47
+ ## 0.1.0-beta.17
48
+
49
+ ### Minor Changes
50
+
51
+ - feat: add new icon font sizes
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies
56
+ - @dt-ui/react-icon@0.1.0-beta.38
57
+
58
+ ## 0.1.0-beta.16
59
+
60
+ ### Patch Changes
61
+
62
+ - chore: update theme font-styles
63
+ - Updated dependencies
64
+ - @dt-ui/react-core@0.1.0-beta.38
65
+ - @dt-ui/react-icon@0.1.0-beta.37
66
+ - @dt-ui/react-typography@0.1.0-beta.29
67
+
68
+ ## 0.1.0-beta.15
69
+
70
+ ### Patch Changes
71
+
72
+ - chore: review OSS files
73
+ - Updated dependencies
74
+ - @dt-ui/react-core@0.1.0-beta.37
75
+ - @dt-ui/react-icon@0.1.0-beta.36
76
+ - @dt-ui/react-typography@0.1.0-beta.28
77
+
78
+ ## 0.1.0-beta.14
79
+
80
+ ### Patch Changes
81
+
82
+ - chore: update contextual colors
83
+ - Updated dependencies
84
+ - @dt-ui/react-core@0.1.0-beta.36
85
+ - @dt-ui/react-icon@0.1.0-beta.35
86
+ - @dt-ui/react-typography@0.1.0-beta.27
87
+
88
+ ## 0.1.0-beta.13
89
+
90
+ ### Minor Changes
91
+
92
+ - feat: implement IconButton contrast and size
93
+
94
+ ### Patch Changes
95
+
96
+ - Updated dependencies
97
+ - @dt-ui/react-icon@0.1.0-beta.34
98
+
99
+ ## 0.1.0-beta.12
100
+
101
+ ### Patch Changes
102
+
103
+ - fix: change content.light contextual color
104
+ - Updated dependencies
105
+ - @dt-ui/react-core@0.1.0-beta.35
106
+ - @dt-ui/react-icon@0.1.0-beta.33
107
+ - @dt-ui/react-typography@0.1.0-beta.26
108
+
109
+ ## 0.1.0-beta.11
110
+
111
+ ### Minor Changes
112
+
113
+ - feat: move icon-button to independent
114
+
115
+ ### Patch Changes
116
+
117
+ - Updated dependencies
118
+ - @dt-ui/react-icon@0.1.0-beta.32
119
+
120
+ ## 0.1.0-beta.10
121
+
122
+ ### Patch Changes
123
+
124
+ - fix: add accent to colors type
125
+ - Updated dependencies
126
+ - @dt-ui/react-core@0.1.0-beta.34
127
+ - @dt-ui/react-icon@0.1.0-beta.31
128
+ - @dt-ui/react-typography@0.1.0-beta.25
129
+
130
+ ## 0.1.0-beta.9
131
+
132
+ ### Patch Changes
133
+
134
+ - fix: change button text according to ux
135
+ - Updated dependencies
136
+ - @dt-ui/react-core@0.1.0-beta.33
137
+ - @dt-ui/react-icon@0.1.0-beta.30
138
+ - @dt-ui/react-typography@0.1.0-beta.24
139
+
140
+ ## 0.1.0-beta.8
141
+
142
+ ### Patch Changes
143
+
144
+ - chore: update contexual colors
145
+ - Updated dependencies
146
+ - @dt-ui/react-core@0.1.0-beta.32
147
+ - @dt-ui/react-typography@0.1.0-beta.23
148
+ - @dt-ui/react-icon@0.1.0-beta.29
149
+
150
+ ## 0.1.0-beta.7
151
+
152
+ ### Patch Changes
153
+
154
+ - style: update responsive font styles
155
+ - Updated dependencies
156
+ - @dt-ui/react-core@0.1.0-beta.31
157
+ - @dt-ui/react-icon@0.1.0-beta.28
158
+ - @dt-ui/react-typography@0.1.0-beta.22
159
+
160
+ ## 0.1.0-beta.6
161
+
162
+ ### Minor Changes
163
+
164
+ - feat: add spinner size 'extra-small' & update specs
165
+
166
+ ### Patch Changes
167
+
168
+ - Updated dependencies
169
+ - @dt-ui/react-core@0.1.0-beta.30
170
+ - @dt-ui/react-icon@0.1.0-beta.27
171
+ - @dt-ui/react-typography@0.1.0-beta.21
172
+
173
+ ## 0.1.0-beta.5
174
+
175
+ ### Patch Changes
176
+
177
+ - chore: add theme breakpoints
178
+ - Updated dependencies
179
+ - @dt-ui/react-core@0.1.0-beta.29
180
+ - @dt-ui/react-icon@0.1.0-beta.26
181
+ - @dt-ui/react-typography@0.1.0-beta.20
182
+
183
+ ## 0.1.0-beta.4
184
+
185
+ ### Minor Changes
186
+
187
+ - feat: add id to base props
188
+
189
+ ### Patch Changes
190
+
191
+ - Updated dependencies
192
+ - @dt-ui/react-core@0.1.0-beta.28
193
+ - @dt-ui/react-typography@0.1.0-beta.19
194
+ - @dt-ui/react-icon@0.1.0-beta.25
195
+
196
+ ## 0.1.0-beta.3
197
+
198
+ ### Minor Changes
199
+
200
+ - feat: change breakpoints values
201
+
202
+ ### Patch Changes
203
+
204
+ - Updated dependencies
205
+ - @dt-ui/react-core@0.1.0-beta.27
206
+ - @dt-ui/react-icon@0.1.0-beta.24
207
+ - @dt-ui/react-typography@0.1.0-beta.18
208
+
209
+ ## 0.1.0-beta.2
210
+
211
+ ### Patch Changes
212
+
213
+ - fix: replace body to correct one
214
+ - Updated dependencies
215
+ - @dt-ui/react-core@0.1.0-beta.26
216
+ - @dt-ui/react-icon@0.1.0-beta.23
217
+ - @dt-ui/react-typography@0.1.0-beta.17
218
+
219
+ ## 0.1.0-beta.1
220
+
221
+ ### Patch Changes
222
+
223
+ - chore: pagination package
224
+ - chore: add theme colors missing types
225
+ - Updated dependencies
226
+ - @dt-ui/react-core@0.1.0-beta.25
227
+ - @dt-ui/react-icon@0.1.0-beta.22
228
+ - @dt-ui/react-typography@0.1.0-beta.16
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Daimler Truck AG.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # Pagination Package
2
+
3
+ The Pagination component enables the user to select a specific page from a range of pages.
4
+
5
+ ## Pagination Usage
6
+
7
+ ```jsx
8
+ import { Pagination, PaginationInput, usePagination } from '@dt-dds/react';
9
+ const totalPages = 10;
10
+
11
+ const { currentPage, handleChange, handleUserInput } = usePagination();
12
+
13
+ return (
14
+ <Pagination>
15
+ <Pagination.PreviousItem
16
+ disabled={currentPage <= 1 || currentPage > totalPages}
17
+ onClick={() => handleChange(currentPage - 1)}
18
+ />
19
+ <PaginationInput
20
+ value={currentPage}
21
+ totalPages={totalPages}
22
+ onHandleKeyDown={handleUserInput}
23
+ onChange={handleChange}
24
+ />
25
+ <Pagination.Content
26
+ totalPages={totalPages}
27
+ onClick={() => handleChange(totalPages)}
28
+ />
29
+ <Pagination.NextItem
30
+ disabled={currentPage >= totalPages || currentPage < 1}
31
+ onClick={() => handleChange(currentPage + 1)}
32
+ />
33
+ </Pagination>
34
+ );
35
+ ```
36
+
37
+ ## Properties
38
+
39
+ ### Pagination
40
+
41
+ | Property | Type | Default | Description |
42
+ | ------------ | ----------- | ------------------ | ------------------------------- |
43
+ | `children` | `ReactNode` | - | Child components to be rendered |
44
+ | `dataTestId` | `string` | pagination-wrapper | Customizable test identifier |
45
+
46
+ ### Pagination.PreviousItem
47
+
48
+ | Property | Type | Default | Description |
49
+ | ---------- | ---------- | ------- | ------------------------------------------------- |
50
+ | `onClick` | `function` | - | The triggered function when clicked on the button |
51
+ | `disabled` | `boolean` | false | Determines the disabled state of the button |
52
+
53
+ ### Pagination.NextItem
54
+
55
+ | Property | Type | Default | Description |
56
+ | ---------- | ---------- | ------- | ------------------------------------------------- |
57
+ | `onClick` | `function` | - | The triggered function when clicked on the button |
58
+ | `disabled` | `boolean` | false | Determines the disabled state of the button |
59
+
60
+ ### Pagination.Content
61
+
62
+ | Property | Type | Default | Description |
63
+ | ------------ | ---------- | ------- | ------------------------------------------------- |
64
+ | `onClick` | `function` | - | The triggered function when clicked on the button |
65
+ | `totalPages` | `number` | - | It will be the number displayed on the button |
66
+
67
+ ### PaginationInput
68
+
69
+ | Property | Type | Default | Description |
70
+ | ----------------- | ---------- | ------- | ---------------------------------------------------- |
71
+ | `totalPages` | `number` | - | Total number of pages |
72
+ | `onChange` | `function` | - | Function to be executed when debounced value changes |
73
+ | `onHandleKeyDown` | `function` | - | Event fired when a key is pressed |
74
+ | `value` | `number` | - | Value to be displayed on the input |
75
+
76
+ ## Stack
77
+
78
+ - [TypeScript](https://www.typescriptlang.org/) for static type checking
79
+ - [React](https://reactjs.org/) — JavaScript library for user interfaces
80
+ - [Emotion](https://emotion.sh/docs/introduction) — for writing css styles with JavaScript
81
+ - [Storybook](https://storybook.js.org/) — UI component environment powered by Vite
82
+ - [Jest](https://jestjs.io/) - JavaScript Testing Framework
83
+ - [React Testing Library](https://testing-library.com/) - to test UI components in a user-centric way
84
+ - [ESLint](https://eslint.org/) for code linting
85
+ - [Prettier](https://prettier.io) for code formatting
86
+ - [Tsup](https://github.com/egoist/tsup) — TypeScript bundler powered by esbuild
87
+ - [Yarn](https://yarnpkg.com/) from managing packages
88
+
89
+ ## Commands
90
+
91
+ - `yarn build` - Build the package
92
+ - `yarn dev` - Run the package locally
93
+ - `yarn lint` - Lint all files within this package
94
+ - `yarn test` - Run all unit tests
95
+ - `yarn test:report` - Open the test coverage report
96
+ - `yarn test:update:snapshot` - Run all unit tests and update the snapshot
97
+
98
+ ## Compilation
99
+
100
+ Running `yarn build` from the root of the package will use [tsup](https://tsup.egoist.dev/) to compile the raw TypeScript and React code to plain JavaScript.
101
+
102
+ The `/dist` folder contains the compiled output.
103
+
104
+ ```bash
105
+ pagination
106
+ └── dist
107
+ ├── index.d.ts <-- Types
108
+ ├── index.js <-- CommonJS version
109
+ └── index.mjs <-- ES Modules version
110
+ ...
111
+ ```
112
+
113
+ ## Versioning
114
+
115
+ Follows [semantic versioning](https://semver.org/)
116
+
117
+ ## &copy; License
118
+
119
+ Licensed under [MIT License](LICENSE.md)
@@ -0,0 +1,38 @@
1
+ import { BaseProps, Theme } from '@dt-dds/react-core';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import React$1 from 'react';
4
+
5
+ interface ContentProps {
6
+ totalPages: number;
7
+ onClick: () => void;
8
+ }
9
+ interface ArrowProps {
10
+ onClick: () => void;
11
+ disabled?: boolean;
12
+ }
13
+ interface PaginationInputProps {
14
+ totalPages: number;
15
+ onChange: (value: number) => void;
16
+ onHandleKeyDown: (event: React$1.KeyboardEvent<HTMLInputElement>) => void;
17
+ value?: number;
18
+ }
19
+ declare const Pagination: {
20
+ ({ children, dataTestId }: BaseProps): react_jsx_runtime.JSX.Element;
21
+ Content({ totalPages, onClick }: ContentProps): react_jsx_runtime.JSX.Element;
22
+ NextItem({ onClick, disabled }: ArrowProps): react_jsx_runtime.JSX.Element;
23
+ PreviousItem({ onClick, disabled }: ArrowProps): react_jsx_runtime.JSX.Element;
24
+ };
25
+ declare const PaginationInput: ({ totalPages, onHandleKeyDown, value, onChange, }: PaginationInputProps) => react_jsx_runtime.JSX.Element;
26
+
27
+ declare const usePagination: () => {
28
+ currentPage: number;
29
+ handleChange: (value: number) => void;
30
+ handleUserInput: (e: React.KeyboardEvent<HTMLInputElement>) => void;
31
+ };
32
+
33
+ declare module '@emotion/react' {
34
+ interface Theme extends Theme {
35
+ }
36
+ }
37
+
38
+ export { ArrowProps, ContentProps, Pagination, PaginationInput, PaginationInputProps, usePagination };
package/dist/index.js ADDED
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.ts
31
+ var pagination_exports = {};
32
+ __export(pagination_exports, {
33
+ Pagination: () => Pagination,
34
+ PaginationInput: () => PaginationInput,
35
+ usePagination: () => usePagination
36
+ });
37
+ module.exports = __toCommonJS(pagination_exports);
38
+
39
+ // src/Pagination.tsx
40
+ var import_react_core = require("@dt-dds/react-core");
41
+ var import_react_icon = require("@dt-dds/react-icon");
42
+ var import_react_typography = require("@dt-dds/react-typography");
43
+ var import_react = require("react");
44
+
45
+ // src/Pagination.styled.ts
46
+ var import_styled = __toESM(require("@emotion/styled"));
47
+ var PaginationStyled = import_styled.default.div`
48
+ display: flex;
49
+ align-items: center;
50
+ gap: 8px;
51
+ margin-top: 48px;
52
+ `;
53
+ var LastPageStyled = import_styled.default.button`
54
+ ${({ theme }) => `
55
+ background-color: transparent;
56
+ color: ${theme.palette.primary.default};
57
+ border: none;
58
+ cursor: pointer;
59
+ `}
60
+ `;
61
+ var ArrowStyled = import_styled.default.button`
62
+ ${({ theme, disabled }) => `
63
+ display: flex;
64
+ justify-content: center;
65
+ background-color: ${theme.palette.surface.contrast};
66
+ border: none;
67
+ border-radius: 3px;
68
+ cursor: ${disabled ? "default" : "pointer"};
69
+ `}
70
+ `;
71
+ var InputStyled = import_styled.default.input`
72
+ ${({ theme, hasError }) => `
73
+ ${theme.fontStyles.pXSmall};
74
+ text-align: center;
75
+ padding: 6px 8px;
76
+ margin: 0px;
77
+ width: 50px;
78
+ height: 32px;
79
+ background-color: ${theme.palette.surface.contrast};
80
+ color: ${theme.palette.content.default};
81
+ border: ${hasError ? `2px solid ${theme.palette.error.default}` : `1px solid ${theme.palette.border.default}`};
82
+ border-radius: 3px;
83
+
84
+ &:focus {
85
+ ${!hasError && `border-bottom: 2px solid ${theme.palette.primary.default}`};
86
+ }
87
+ `}
88
+ `;
89
+
90
+ // src/Pagination.tsx
91
+ var import_jsx_runtime = require("react/jsx-runtime");
92
+ var Pagination = ({ children, dataTestId }) => {
93
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaginationStyled, { "data-testid": dataTestId != null ? dataTestId : "pagination-wrapper", children });
94
+ };
95
+ Pagination.Content = ({ totalPages, onClick }) => {
96
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_typography.Typography, { fontStyles: "pXSmall", children: [
97
+ "of",
98
+ " ",
99
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
100
+ LastPageStyled,
101
+ {
102
+ "data-testid": "pagination-last-page",
103
+ onClick,
104
+ title: "Go to last page",
105
+ children: totalPages
106
+ }
107
+ )
108
+ ] });
109
+ };
110
+ Pagination.NextItem = ({ onClick, disabled }) => {
111
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
112
+ ArrowStyled,
113
+ {
114
+ "data-testid": "pagination-next-item",
115
+ disabled,
116
+ onClick,
117
+ title: "Go to next page",
118
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icon.Icon, { code: "arrow_forward_ios", size: "s" })
119
+ }
120
+ );
121
+ };
122
+ Pagination.PreviousItem = ({ onClick, disabled }) => {
123
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
124
+ ArrowStyled,
125
+ {
126
+ "data-testid": "pagination-previous-item",
127
+ disabled,
128
+ onClick,
129
+ title: "Go to previous page",
130
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icon.Icon, { code: "arrow_back_ios", size: "s" })
131
+ }
132
+ );
133
+ };
134
+ var PaginationInput = ({
135
+ totalPages,
136
+ onHandleKeyDown,
137
+ value,
138
+ onChange
139
+ }) => {
140
+ const [inputValue, setInputValue] = (0, import_react.useState)(1);
141
+ const [hasError, setHasError] = (0, import_react.useState)(false);
142
+ const debouncedFn = (0, import_react.useMemo)(() => (0, import_react_core.debounce)((fn) => fn(), 500), []);
143
+ (0, import_react.useEffect)(() => {
144
+ if (value !== void 0) {
145
+ setInputValue(value);
146
+ }
147
+ }, [value]);
148
+ (0, import_react.useEffect)(() => {
149
+ if (inputValue && inputValue <= totalPages) {
150
+ debouncedFn(() => {
151
+ onChange(inputValue);
152
+ });
153
+ }
154
+ }, [debouncedFn, inputValue, onChange, totalPages]);
155
+ const handleChange = (event) => {
156
+ const value2 = Number(event.target.value);
157
+ setInputValue(value2);
158
+ if (value2 > totalPages || value2 === 0) {
159
+ setHasError(true);
160
+ } else {
161
+ setHasError(false);
162
+ }
163
+ };
164
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
165
+ InputStyled,
166
+ {
167
+ "data-testid": "pagination-input",
168
+ hasError,
169
+ onChange: handleChange,
170
+ onKeyDown: onHandleKeyDown,
171
+ value: inputValue
172
+ }
173
+ );
174
+ };
175
+
176
+ // src/hooks/usePagination.tsx
177
+ var import_react2 = require("react");
178
+ var usePagination = () => {
179
+ const [currentPage, setCurrentPage] = (0, import_react2.useState)(1);
180
+ const handleUserInput = (e) => {
181
+ const validCodes = ["Enter", "Backspace", "Tab"];
182
+ if (!/Digit\d/.test(e.code) && !validCodes.includes(e.code)) {
183
+ e.preventDefault();
184
+ }
185
+ };
186
+ const handleChange = (0, import_react2.useCallback)((value) => {
187
+ setCurrentPage(value);
188
+ }, []);
189
+ return {
190
+ currentPage,
191
+ handleChange,
192
+ handleUserInput
193
+ };
194
+ };
195
+ // Annotate the CommonJS export names for ESM import in node:
196
+ 0 && (module.exports = {
197
+ Pagination,
198
+ PaginationInput,
199
+ usePagination
200
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,161 @@
1
+ // src/Pagination.tsx
2
+ import { debounce } from "@dt-dds/react-core";
3
+ import { Icon } from "@dt-dds/react-icon";
4
+ import { Typography } from "@dt-dds/react-typography";
5
+ import { useEffect, useMemo, useState } from "react";
6
+
7
+ // src/Pagination.styled.ts
8
+ import styled from "@emotion/styled";
9
+ var PaginationStyled = styled.div`
10
+ display: flex;
11
+ align-items: center;
12
+ gap: 8px;
13
+ margin-top: 48px;
14
+ `;
15
+ var LastPageStyled = styled.button`
16
+ ${({ theme }) => `
17
+ background-color: transparent;
18
+ color: ${theme.palette.primary.default};
19
+ border: none;
20
+ cursor: pointer;
21
+ `}
22
+ `;
23
+ var ArrowStyled = styled.button`
24
+ ${({ theme, disabled }) => `
25
+ display: flex;
26
+ justify-content: center;
27
+ background-color: ${theme.palette.surface.contrast};
28
+ border: none;
29
+ border-radius: 3px;
30
+ cursor: ${disabled ? "default" : "pointer"};
31
+ `}
32
+ `;
33
+ var InputStyled = styled.input`
34
+ ${({ theme, hasError }) => `
35
+ ${theme.fontStyles.pXSmall};
36
+ text-align: center;
37
+ padding: 6px 8px;
38
+ margin: 0px;
39
+ width: 50px;
40
+ height: 32px;
41
+ background-color: ${theme.palette.surface.contrast};
42
+ color: ${theme.palette.content.default};
43
+ border: ${hasError ? `2px solid ${theme.palette.error.default}` : `1px solid ${theme.palette.border.default}`};
44
+ border-radius: 3px;
45
+
46
+ &:focus {
47
+ ${!hasError && `border-bottom: 2px solid ${theme.palette.primary.default}`};
48
+ }
49
+ `}
50
+ `;
51
+
52
+ // src/Pagination.tsx
53
+ import { jsx, jsxs } from "react/jsx-runtime";
54
+ var Pagination = ({ children, dataTestId }) => {
55
+ return /* @__PURE__ */ jsx(PaginationStyled, { "data-testid": dataTestId != null ? dataTestId : "pagination-wrapper", children });
56
+ };
57
+ Pagination.Content = ({ totalPages, onClick }) => {
58
+ return /* @__PURE__ */ jsxs(Typography, { fontStyles: "pXSmall", children: [
59
+ "of",
60
+ " ",
61
+ /* @__PURE__ */ jsx(
62
+ LastPageStyled,
63
+ {
64
+ "data-testid": "pagination-last-page",
65
+ onClick,
66
+ title: "Go to last page",
67
+ children: totalPages
68
+ }
69
+ )
70
+ ] });
71
+ };
72
+ Pagination.NextItem = ({ onClick, disabled }) => {
73
+ return /* @__PURE__ */ jsx(
74
+ ArrowStyled,
75
+ {
76
+ "data-testid": "pagination-next-item",
77
+ disabled,
78
+ onClick,
79
+ title: "Go to next page",
80
+ children: /* @__PURE__ */ jsx(Icon, { code: "arrow_forward_ios", size: "s" })
81
+ }
82
+ );
83
+ };
84
+ Pagination.PreviousItem = ({ onClick, disabled }) => {
85
+ return /* @__PURE__ */ jsx(
86
+ ArrowStyled,
87
+ {
88
+ "data-testid": "pagination-previous-item",
89
+ disabled,
90
+ onClick,
91
+ title: "Go to previous page",
92
+ children: /* @__PURE__ */ jsx(Icon, { code: "arrow_back_ios", size: "s" })
93
+ }
94
+ );
95
+ };
96
+ var PaginationInput = ({
97
+ totalPages,
98
+ onHandleKeyDown,
99
+ value,
100
+ onChange
101
+ }) => {
102
+ const [inputValue, setInputValue] = useState(1);
103
+ const [hasError, setHasError] = useState(false);
104
+ const debouncedFn = useMemo(() => debounce((fn) => fn(), 500), []);
105
+ useEffect(() => {
106
+ if (value !== void 0) {
107
+ setInputValue(value);
108
+ }
109
+ }, [value]);
110
+ useEffect(() => {
111
+ if (inputValue && inputValue <= totalPages) {
112
+ debouncedFn(() => {
113
+ onChange(inputValue);
114
+ });
115
+ }
116
+ }, [debouncedFn, inputValue, onChange, totalPages]);
117
+ const handleChange = (event) => {
118
+ const value2 = Number(event.target.value);
119
+ setInputValue(value2);
120
+ if (value2 > totalPages || value2 === 0) {
121
+ setHasError(true);
122
+ } else {
123
+ setHasError(false);
124
+ }
125
+ };
126
+ return /* @__PURE__ */ jsx(
127
+ InputStyled,
128
+ {
129
+ "data-testid": "pagination-input",
130
+ hasError,
131
+ onChange: handleChange,
132
+ onKeyDown: onHandleKeyDown,
133
+ value: inputValue
134
+ }
135
+ );
136
+ };
137
+
138
+ // src/hooks/usePagination.tsx
139
+ import { useCallback, useState as useState2 } from "react";
140
+ var usePagination = () => {
141
+ const [currentPage, setCurrentPage] = useState2(1);
142
+ const handleUserInput = (e) => {
143
+ const validCodes = ["Enter", "Backspace", "Tab"];
144
+ if (!/Digit\d/.test(e.code) && !validCodes.includes(e.code)) {
145
+ e.preventDefault();
146
+ }
147
+ };
148
+ const handleChange = useCallback((value) => {
149
+ setCurrentPage(value);
150
+ }, []);
151
+ return {
152
+ currentPage,
153
+ handleChange,
154
+ handleUserInput
155
+ };
156
+ };
157
+ export {
158
+ Pagination,
159
+ PaginationInput,
160
+ usePagination
161
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@dt-dds/react-pagination",
3
+ "version": "1.0.0-beta.21",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": "./dist/index.js"
7
+ },
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "dist/**"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "dev": "tsup --watch",
17
+ "lint": "eslint --cache .",
18
+ "test": "jest",
19
+ "test:report": "open ./jest-coverage/lcov-report/index.html",
20
+ "test:update:snapshot": "jest -u"
21
+ },
22
+ "dependencies": {
23
+ "@dt-dds/react-core": "1.0.0-beta.41",
24
+ "@dt-dds/react-typography": "1.0.0-beta.32",
25
+ "@dt-dds/react-icon": "1.0.0-beta.42"
26
+ },
27
+ "devDependencies": {
28
+ "@babel/core": "^7.22.9",
29
+ "@babel/preset-env": "^7.22.9",
30
+ "@babel/preset-react": "^7.22.5",
31
+ "@babel/preset-typescript": "^7.23.3",
32
+ "@emotion/babel-plugin": "^11.11.0",
33
+ "@emotion/css": "^11.7.1",
34
+ "@emotion/jest": "^11.10.0",
35
+ "@emotion/react": "^11.8.2",
36
+ "@emotion/styled": "^11.8.1",
37
+ "@types/react": "^18.0.9",
38
+ "@types/react-dom": "^18.0.4",
39
+ "babel-loader": "^8.3.0",
40
+ "eslint-config-custom": "*",
41
+ "eslint-plugin-storybook": "^9.1.0",
42
+ "jest-config": "*",
43
+ "react": "^18.1.0",
44
+ "react-dom": "^18.2.0",
45
+ "tsconfig": "*",
46
+ "tsup": "^6.6.3",
47
+ "typescript": "^4.5.3"
48
+ },
49
+ "peerDependencies": {
50
+ "@emotion/css": "^11.7.1",
51
+ "@emotion/react": "^11.8.2",
52
+ "@emotion/styled": "^11.8.1",
53
+ "react": ">=17.0.2",
54
+ "react-dom": ">=17.0.2"
55
+ }
56
+ }