@propellerads/pagination 4.0.2 → 4.1.1
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/dist/index.css +1 -0
- package/dist/index.js +90 -105
- package/dist/index.js.map +1 -1
- package/package.json +14 -10
package/dist/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.pagination{flex-wrap:wrap;align-items:flex-end;gap:16px 32px;display:flex}.pagination__per-page{flex:none}.pagination__per-page .select{width:fit-content}.pagination__size{display:inline-grid}.pagination__size>span,.pagination__size:after{grid-area:1/1}.pagination__size:after{content:attr(data-longest);visibility:hidden}.pagination__amount{white-space:nowrap;flex:none;align-items:center;min-height:36px;display:flex}.pagination__actions{flex:none;display:flex}.pagination__action:not(:last-child){margin-right:8px}
|
package/dist/index.js
CHANGED
|
@@ -2,124 +2,109 @@ import e, { ButtonVariant as t } from "@propellerads/button";
|
|
|
2
2
|
import { ArrowLeft as n, ArrowPageFirst as r, ArrowPageLast as i, ArrowRight as a } from "@propellerads/icon";
|
|
3
3
|
import { LabelPosition as o } from "@propellerads/label";
|
|
4
4
|
import s from "@propellerads/select";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
// src/style.tsx
|
|
9
|
-
var f = l.div`
|
|
10
|
-
display: flex;
|
|
11
|
-
flex-wrap: wrap;
|
|
12
|
-
align-items: flex-end;
|
|
13
|
-
gap: ${c * 4}px ${c * 8}px;
|
|
14
|
-
`, p = l.div`
|
|
15
|
-
flex: none;
|
|
16
|
-
|
|
17
|
-
/* The select is as wide as its sizes, not as the label on top of it. */
|
|
18
|
-
.select {
|
|
19
|
-
width: fit-content;
|
|
20
|
-
}
|
|
21
|
-
`, m = l.span`
|
|
22
|
-
display: inline-grid;
|
|
23
|
-
|
|
24
|
-
> span,
|
|
25
|
-
&::after {
|
|
26
|
-
grid-area: 1 / 1;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
&::after {
|
|
30
|
-
content: attr(data-longest);
|
|
31
|
-
visibility: hidden;
|
|
32
|
-
}
|
|
33
|
-
`, h = l.div`
|
|
34
|
-
display: flex;
|
|
35
|
-
flex: none;
|
|
36
|
-
align-items: center;
|
|
37
|
-
/* 36px, the height of the select and the arrow buttons, so the counter stands on their line. */
|
|
38
|
-
min-height: 36px;
|
|
39
|
-
white-space: nowrap;
|
|
40
|
-
`, g = l.div`
|
|
41
|
-
display: flex;
|
|
42
|
-
flex: none;
|
|
43
|
-
`, _ = l.div`
|
|
44
|
-
&:not(:last-child) {
|
|
45
|
-
margin-right: ${c * 2}px;
|
|
46
|
-
}
|
|
47
|
-
`, v = /\s*:\s*$/, y = (e, t, n) => {
|
|
5
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
6
|
+
import './index.css';// src/index.tsx
|
|
7
|
+
var u = /\s*:\s*$/, d = (e, t, n) => {
|
|
48
8
|
let r = e * (t - 1);
|
|
49
9
|
return {
|
|
50
10
|
from: r + 1,
|
|
51
11
|
to: Math.min(r + e, n),
|
|
52
12
|
total: n
|
|
53
13
|
};
|
|
54
|
-
},
|
|
14
|
+
}, f = ({ from: e, to: t, total: n }) => `${e}-${t} of ${n}`, p = ({ pageIndex: p, perPage: m, pageSizes: h = [
|
|
55
15
|
10,
|
|
56
16
|
20,
|
|
57
17
|
50
|
|
58
|
-
], totalPages:
|
|
59
|
-
let
|
|
60
|
-
label:
|
|
61
|
-
labelPosition:
|
|
18
|
+
], totalPages: g, totalItems: _, setPageSize: v, canNextPage: y, gotoPage: b, canPreviousPage: x, previousPageHandler: S, nextPageHandler: C, parentElementId: w, paginationAmount: T = "", labelPerPage: E = "", labelPosition: D = o.Left }) => {
|
|
19
|
+
let O = `${w}-pagination-select-per-page`, k = E.replace(u, ""), A = k ? {
|
|
20
|
+
label: k,
|
|
21
|
+
labelPosition: D,
|
|
62
22
|
labelWidth: "max-content"
|
|
63
|
-
} : { "aria-label": "Rows per page" },
|
|
23
|
+
} : { "aria-label": "Rows per page" }, j = h.map(String).reduce((e, t) => t.length > e.length ? t : e, ""), M = h.map((e) => ({
|
|
64
24
|
id: e,
|
|
65
25
|
label: e,
|
|
66
26
|
value: e
|
|
67
|
-
})),
|
|
68
|
-
return /* @__PURE__ */
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
27
|
+
})), N = M.find(({ value: e }) => e === m), P = d(m, p + 1, _), F = T || f(P);
|
|
28
|
+
return /* @__PURE__ */ l("div", {
|
|
29
|
+
className: "pagination",
|
|
30
|
+
children: [
|
|
31
|
+
/* @__PURE__ */ c("div", {
|
|
32
|
+
className: "pagination__per-page",
|
|
33
|
+
children: /* @__PURE__ */ c(s, {
|
|
34
|
+
...A,
|
|
35
|
+
id: O,
|
|
36
|
+
onChange: (e) => {
|
|
37
|
+
e !== null && v(Number(e.value));
|
|
38
|
+
},
|
|
39
|
+
options: M,
|
|
40
|
+
value: N,
|
|
41
|
+
formatOptionLabel: (e, { context: t }) => t === "value" ? /* @__PURE__ */ c("span", {
|
|
42
|
+
className: "pagination__size",
|
|
43
|
+
"data-longest": j,
|
|
44
|
+
children: /* @__PURE__ */ c("span", { children: e.label })
|
|
45
|
+
}) : e.label
|
|
46
|
+
})
|
|
47
|
+
}),
|
|
48
|
+
/* @__PURE__ */ c("div", {
|
|
49
|
+
className: "pagination__amount",
|
|
50
|
+
children: F
|
|
51
|
+
}),
|
|
52
|
+
/* @__PURE__ */ l("div", {
|
|
53
|
+
className: "pagination__actions",
|
|
54
|
+
children: [
|
|
55
|
+
/* @__PURE__ */ c("div", {
|
|
56
|
+
className: "pagination__action",
|
|
57
|
+
children: /* @__PURE__ */ c(e, {
|
|
58
|
+
variant: t.Ghost,
|
|
59
|
+
icon: /* @__PURE__ */ c(r, { color: "currentColor" }),
|
|
60
|
+
isQuiet: !0,
|
|
61
|
+
"aria-label": "First page",
|
|
62
|
+
isDisabled: !x,
|
|
63
|
+
id: `${w}-pagination-first-page-button`,
|
|
64
|
+
onClick: () => b(0)
|
|
65
|
+
})
|
|
66
|
+
}),
|
|
67
|
+
/* @__PURE__ */ c("div", {
|
|
68
|
+
className: "pagination__action",
|
|
69
|
+
children: /* @__PURE__ */ c(e, {
|
|
70
|
+
variant: t.Ghost,
|
|
71
|
+
icon: /* @__PURE__ */ c(n, { color: "currentColor" }),
|
|
72
|
+
isQuiet: !0,
|
|
73
|
+
"aria-label": "Previous page",
|
|
74
|
+
isDisabled: !x,
|
|
75
|
+
id: `${w}-pagination-previous-page-button`,
|
|
76
|
+
onClick: S
|
|
77
|
+
})
|
|
78
|
+
}),
|
|
79
|
+
/* @__PURE__ */ c("div", {
|
|
80
|
+
className: "pagination__action",
|
|
81
|
+
children: /* @__PURE__ */ c(e, {
|
|
82
|
+
variant: t.Ghost,
|
|
83
|
+
icon: /* @__PURE__ */ c(a, { color: "currentColor" }),
|
|
84
|
+
isQuiet: !0,
|
|
85
|
+
"aria-label": "Next page",
|
|
86
|
+
isDisabled: !y,
|
|
87
|
+
id: `${w}-pagination-next-page-button`,
|
|
88
|
+
onClick: C
|
|
89
|
+
})
|
|
90
|
+
}),
|
|
91
|
+
/* @__PURE__ */ c("div", {
|
|
92
|
+
className: "pagination__action",
|
|
93
|
+
children: /* @__PURE__ */ c(e, {
|
|
94
|
+
variant: t.Ghost,
|
|
95
|
+
icon: /* @__PURE__ */ c(i, { color: "currentColor" }),
|
|
96
|
+
isQuiet: !0,
|
|
97
|
+
"aria-label": "Last page",
|
|
98
|
+
isDisabled: !y,
|
|
99
|
+
id: `${w}-pagination-last-page-button`,
|
|
100
|
+
onClick: () => b(g - 1)
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
]
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
});
|
|
122
107
|
};
|
|
123
|
-
export {
|
|
108
|
+
export { p as default };
|
|
124
109
|
|
|
125
110
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Button","Select","styled","StyledPagination","spacing","StyledPaginationPerPage","StyledPaginationSize","StyledPaginationAmount","StyledPaginationActions","StyledPaginationAction","TRAILING_COLON","getPaginationAmountData","count","perPage","page","total","getPaginationAmountText","from","to","Pagination","LabelPosition","selectElementId","parentElementId","label","labelPerPage","field","longestSize","pageSizes","size","longest","selectValues","selectedPageSize","value","paginationAmountData","pageIndex","totalItems","paginationAmountText","paginationAmount","newValue","setPageSize","context","option","ButtonVariant","ArrowPageFirst","canPreviousPage","gotoPage","ArrowLeft","previousPageHandler","ArrowRight","canNextPage","nextPageHandler","ArrowPageLast","totalPages"],"sources":["../src/style.tsx","../src/index.tsx"],"sourcesContent":["import {spacing} from '@propellerads/stylevariables';\nimport styled from 'styled-components';\n\n/*\n * Three parts in a row: the rows-per-page select, the counter, the arrows.\n * Where the row has no room, a whole part goes to the next line; none of them\n * shrinks or breaks inside. The parts stand on the line of the select and the\n * arrows, so a label on top of the select rises above the row.\n */\nconst StyledPagination = styled.div`\n display: flex;\n flex-wrap: wrap;\n align-items: flex-end;\n gap: ${spacing * 4}px ${spacing * 8}px;\n`;\n\nconst StyledPaginationPerPage = styled.div`\n flex: none;\n\n /* The select is as wide as its sizes, not as the label on top of it. */\n .select {\n width: fit-content;\n }\n`;\n\n/*\n * The chosen size stands over the longest one, which keeps the room for it\n * out of sight: the select fits every size it offers, and keeps its width\n * when another is chosen. A pseudo-element, so the text of the select is the\n * size alone, for a screen reader and for a test.\n */\nconst StyledPaginationSize = styled.span`\n display: inline-grid;\n\n > span,\n &::after {\n grid-area: 1 / 1;\n }\n\n &::after {\n content: attr(data-longest);\n visibility: hidden;\n }\n`;\n\nconst StyledPaginationAmount = styled.div`\n display: flex;\n flex: none;\n align-items: center;\n /* 36px, the height of the select and the arrow buttons, so the counter stands on their line. */\n min-height: 36px;\n white-space: nowrap;\n`;\n\n// The arrows go to the next line together.\nconst StyledPaginationActions = styled.div`\n display: flex;\n flex: none;\n`;\n\nconst StyledPaginationAction = styled.div`\n &:not(:last-child) {\n margin-right: ${spacing * 2}px;\n }\n`;\n\nexport {\n StyledPagination,\n StyledPaginationAction,\n StyledPaginationActions,\n StyledPaginationAmount,\n StyledPaginationPerPage,\n StyledPaginationSize,\n};\n","import Button, {ButtonVariant} from '@propellerads/button';\nimport {ArrowLeft, ArrowPageFirst, ArrowPageLast, ArrowRight} from '@propellerads/icon';\nimport {LabelPosition} from '@propellerads/label';\nimport type {Option as SelectOption} from '@propellerads/select';\nimport Select from '@propellerads/select';\nimport {\n StyledPagination,\n StyledPaginationAction,\n StyledPaginationActions,\n StyledPaginationAmount,\n StyledPaginationPerPage,\n StyledPaginationSize,\n} from './style';\nimport type {PaginationAmountText, PaginationProps} from './types';\n\n// No label of the library ends with a colon; products wrote \"Rows per page:\".\nconst TRAILING_COLON = /\\s*:\\s*$/;\n\nconst getPaginationAmountData = (perPage: number, page: number, total: number): PaginationAmountText => {\n const count = perPage * (page - 1);\n\n return {\n from: count + 1,\n to: Math.min(count + perPage, total),\n total,\n };\n};\n\nconst getPaginationAmountText = ({from, to, total}: PaginationAmountText): string => {\n return `${from}-${to} of ${total}`;\n};\n\nconst Pagination = ({\n pageIndex,\n perPage,\n pageSizes = [10, 20, 50],\n totalPages,\n totalItems,\n setPageSize,\n canNextPage,\n gotoPage,\n canPreviousPage,\n previousPageHandler,\n nextPageHandler,\n parentElementId,\n paginationAmount = '',\n labelPerPage = '',\n labelPosition = LabelPosition.Left,\n}: PaginationProps) => {\n const selectElementId = `${parentElementId}-pagination-select-per-page`;\n const label = labelPerPage.replace(TRAILING_COLON, '');\n // The select draws its field only when it is given a label, so a pagination\n // without one keeps the bare select, named for a screen reader. On the left\n // the label takes its own width: the column of a form is too wide in a row.\n const field = label ? {label, labelPosition, labelWidth: 'max-content'} : {'aria-label': 'Rows per page'};\n // Measured in characters: the sizes are numbers, and their digits are of one width.\n const longestSize = pageSizes\n .map(String)\n .reduce((longest, size) => (size.length > longest.length ? size : longest), '');\n\n const selectValues: SelectOption[] = pageSizes.map((size) => ({\n id: size,\n label: size,\n value: size,\n }));\n const selectedPageSize = selectValues.find(({value}) => value === perPage);\n\n const paginationAmountData = getPaginationAmountData(perPage, pageIndex + 1, totalItems);\n const paginationAmountText = paginationAmount || getPaginationAmountText(paginationAmountData);\n\n return (\n <StyledPagination>\n <StyledPaginationPerPage>\n <Select\n {...field}\n id={selectElementId}\n onChange={(newValue) => {\n if (newValue === null) {\n return;\n }\n\n setPageSize(Number(newValue.value));\n }}\n options={selectValues}\n value={selectedPageSize}\n formatOptionLabel={(option: SelectOption, {context}: {context: 'menu' | 'value'}) =>\n context === 'value' ? (\n <StyledPaginationSize data-longest={longestSize}>\n <span>{option.label}</span>\n </StyledPaginationSize>\n ) : (\n option.label\n )\n }\n />\n </StyledPaginationPerPage>\n <StyledPaginationAmount>{paginationAmountText}</StyledPaginationAmount>\n {/* The arrows belong to the frame around the table, not to its content: quiet\n ghost buttons, the icons in the button's colour, so the whole button\n answers the pointer and not the icon alone. */}\n <StyledPaginationActions>\n <StyledPaginationAction>\n <Button\n variant={ButtonVariant.Ghost}\n icon={<ArrowPageFirst color=\"currentColor\" />}\n isQuiet\n aria-label=\"First page\"\n isDisabled={!canPreviousPage}\n id={`${parentElementId}-pagination-first-page-button`}\n onClick={() => gotoPage(0)}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <Button\n variant={ButtonVariant.Ghost}\n icon={<ArrowLeft color=\"currentColor\" />}\n isQuiet\n aria-label=\"Previous page\"\n isDisabled={!canPreviousPage}\n id={`${parentElementId}-pagination-previous-page-button`}\n onClick={previousPageHandler}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <Button\n variant={ButtonVariant.Ghost}\n icon={<ArrowRight color=\"currentColor\" />}\n isQuiet\n aria-label=\"Next page\"\n isDisabled={!canNextPage}\n id={`${parentElementId}-pagination-next-page-button`}\n onClick={nextPageHandler}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <Button\n variant={ButtonVariant.Ghost}\n icon={<ArrowPageLast color=\"currentColor\" />}\n isQuiet\n aria-label=\"Last page\"\n isDisabled={!canNextPage}\n id={`${parentElementId}-pagination-last-page-button`}\n onClick={() => gotoPage(totalPages - 1)}\n />\n </StyledPaginationAction>\n </StyledPaginationActions>\n </StyledPagination>\n );\n};\n\nexport default Pagination;\nexport type {PaginationAmountText, PaginationProps};\n"],"mappings":";;;;;;;;AASA,IAAMG,IAAmB,EAAO,GAAG;;;;SAI1BC,IAAU,EAAE,KAAKA,IAAU,EAAE;GAGhCC,IAA0B,EAAO,GAAG;;;;;;;GAepCC,IAAuB,EAAO,IAAI;;;;;;;;;;;;GAclCC,IAAyB,EAAO,GAAG;;;;;;;GAUnCC,IAA0B,EAAO,GAAG;;;GAKpCC,IAAyB,EAAO,GAAG;;oBAErBL,IAAU,EAAE;;GC9C1BM,IAAiB,YAEjBC,KAA2B,GAAiB,GAAc,MAAwC;CACtG,IAAMC,IAAQC,KAAWC,IAAO;CAEhC,OAAO;EACL,MAAMF,IAAQ;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,EAA6C,CAAA;EAItE,kBAAC5B,GAAD,EAAA,UAAA;GACE,kBAACC,GAAD,EAAA,UACE,kBAACT,GAAD;IACE,SAAS0C,EAAc;IACvB,MAAM,kBAACC,GAAD,EAAgB,OAAM,eAAgB,CAAA;IAC5C,SAAA;IACA,cAAW;IACX,YAAY,CAACC;IACb,IAAI,GAAGtB,EAAgB;IACvB,eAAeuB,EAAS,CAAC;GAC1B,CAAA,EACqB,CAAA;GACxB,kBAACpC,GAAD,EAAA,UACE,kBAACT,GAAD;IACE,SAAS0C,EAAc;IACvB,MAAM,kBAACI,GAAD,EAAW,OAAM,eAAgB,CAAA;IACvC,SAAA;IACA,cAAW;IACX,YAAY,CAACF;IACb,IAAI,GAAGtB,EAAgB;IACvB,SAASyB;GACV,CAAA,EACqB,CAAA;GACxB,kBAACtC,GAAD,EAAA,UACE,kBAACT,GAAD;IACE,SAAS0C,EAAc;IACvB,MAAM,kBAACM,GAAD,EAAY,OAAM,eAAgB,CAAA;IACxC,SAAA;IACA,cAAW;IACX,YAAY,CAACC;IACb,IAAI,GAAG3B,EAAgB;IACvB,SAAS4B;GACV,CAAA,EACqB,CAAA;GACxB,kBAACzC,GAAD,EAAA,UACE,kBAACT,GAAD;IACE,SAAS0C,EAAc;IACvB,MAAM,kBAACS,GAAD,EAAe,OAAM,eAAgB,CAAA;IAC3C,SAAA;IACA,cAAW;IACX,YAAY,CAACF;IACb,IAAI,GAAG3B,EAAgB;IACvB,eAAeuB,EAASO,IAAa,CAAC;GACvC,CAAA,EACqB,CAAA;EACD,EAAA,CAAA;CACT,EAAA,CAAA;AAEtB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Button","Select","TRAILING_COLON","getPaginationAmountData","count","perPage","page","total","getPaginationAmountText","from","to","Pagination","LabelPosition","selectElementId","parentElementId","label","labelPerPage","field","longestSize","pageSizes","size","longest","selectValues","selectedPageSize","value","paginationAmountData","pageIndex","totalItems","paginationAmountText","paginationAmount","newValue","setPageSize","context","option","ButtonVariant","ArrowPageFirst","canPreviousPage","gotoPage","ArrowLeft","previousPageHandler","ArrowRight","canNextPage","nextPageHandler","ArrowPageLast","totalPages"],"sources":["../src/index.tsx"],"sourcesContent":["import Button, {ButtonVariant} from '@propellerads/button';\nimport {ArrowLeft, ArrowPageFirst, ArrowPageLast, ArrowRight} from '@propellerads/icon';\nimport {LabelPosition} from '@propellerads/label';\nimport type {Option as SelectOption} from '@propellerads/select';\nimport Select from '@propellerads/select';\nimport './pagination.css';\nimport type {PaginationAmountText, PaginationProps} from './types';\n\n// No label of the library ends with a colon; products wrote \"Rows per page:\".\nconst TRAILING_COLON = /\\s*:\\s*$/;\n\nconst getPaginationAmountData = (perPage: number, page: number, total: number): PaginationAmountText => {\n const count = perPage * (page - 1);\n\n return {\n from: count + 1,\n to: Math.min(count + perPage, total),\n total,\n };\n};\n\nconst getPaginationAmountText = ({from, to, total}: PaginationAmountText): string => {\n return `${from}-${to} of ${total}`;\n};\n\nconst Pagination = ({\n pageIndex,\n perPage,\n pageSizes = [10, 20, 50],\n totalPages,\n totalItems,\n setPageSize,\n canNextPage,\n gotoPage,\n canPreviousPage,\n previousPageHandler,\n nextPageHandler,\n parentElementId,\n paginationAmount = '',\n labelPerPage = '',\n labelPosition = LabelPosition.Left,\n}: PaginationProps) => {\n const selectElementId = `${parentElementId}-pagination-select-per-page`;\n const label = labelPerPage.replace(TRAILING_COLON, '');\n // The select draws its field only when it is given a label, so a pagination\n // without one keeps the bare select, named for a screen reader. On the left\n // the label takes its own width: the column of a form is too wide in a row.\n const field = label ? {label, labelPosition, labelWidth: 'max-content'} : {'aria-label': 'Rows per page'};\n // Measured in characters: the sizes are numbers, and their digits are of one width.\n const longestSize = pageSizes\n .map(String)\n .reduce((longest, size) => (size.length > longest.length ? size : longest), '');\n\n const selectValues: SelectOption[] = pageSizes.map((size) => ({\n id: size,\n label: size,\n value: size,\n }));\n const selectedPageSize = selectValues.find(({value}) => value === perPage);\n\n const paginationAmountData = getPaginationAmountData(perPage, pageIndex + 1, totalItems);\n const paginationAmountText = paginationAmount || getPaginationAmountText(paginationAmountData);\n\n return (\n <div className=\"pagination\">\n <div className=\"pagination__per-page\">\n <Select\n {...field}\n id={selectElementId}\n onChange={(newValue) => {\n if (newValue === null) {\n return;\n }\n\n setPageSize(Number(newValue.value));\n }}\n options={selectValues}\n value={selectedPageSize}\n formatOptionLabel={(option: SelectOption, {context}: {context: 'menu' | 'value'}) =>\n context === 'value' ? (\n <span className=\"pagination__size\" data-longest={longestSize}>\n <span>{option.label}</span>\n </span>\n ) : (\n option.label\n )\n }\n />\n </div>\n <div className=\"pagination__amount\">{paginationAmountText}</div>\n {/* The arrows belong to the frame around the table, not to its content: quiet\n ghost buttons, the icons in the button's colour, so the whole button\n answers the pointer and not the icon alone. */}\n <div className=\"pagination__actions\">\n <div className=\"pagination__action\">\n <Button\n variant={ButtonVariant.Ghost}\n icon={<ArrowPageFirst color=\"currentColor\" />}\n isQuiet\n aria-label=\"First page\"\n isDisabled={!canPreviousPage}\n id={`${parentElementId}-pagination-first-page-button`}\n onClick={() => gotoPage(0)}\n />\n </div>\n <div className=\"pagination__action\">\n <Button\n variant={ButtonVariant.Ghost}\n icon={<ArrowLeft color=\"currentColor\" />}\n isQuiet\n aria-label=\"Previous page\"\n isDisabled={!canPreviousPage}\n id={`${parentElementId}-pagination-previous-page-button`}\n onClick={previousPageHandler}\n />\n </div>\n <div className=\"pagination__action\">\n <Button\n variant={ButtonVariant.Ghost}\n icon={<ArrowRight color=\"currentColor\" />}\n isQuiet\n aria-label=\"Next page\"\n isDisabled={!canNextPage}\n id={`${parentElementId}-pagination-next-page-button`}\n onClick={nextPageHandler}\n />\n </div>\n <div className=\"pagination__action\">\n <Button\n variant={ButtonVariant.Ghost}\n icon={<ArrowPageLast color=\"currentColor\" />}\n isQuiet\n aria-label=\"Last page\"\n isDisabled={!canNextPage}\n id={`${parentElementId}-pagination-last-page-button`}\n onClick={() => gotoPage(totalPages - 1)}\n />\n </div>\n </div>\n </div>\n );\n};\n\nexport default Pagination;\nexport type {PaginationAmountText, PaginationProps};\n"],"mappings":";;;;;;AASA,IAAME,IAAiB,YAEjBC,KAA2B,GAAiB,GAAc,MAAwC;CACtG,IAAMC,IAAQC,KAAWC,IAAO;CAEhC,OAAO;EACL,MAAMF,IAAQ;EACd,IAAI,KAAK,IAAIA,IAAQC,GAASE,CAAK;EACnC;CACF;AACF,GAEMC,KAA2B,EAAC,SAAM,OAAI,eACnC,GAAGC,EAAK,GAAGC,EAAG,MAAMH,KAGvBI,KAAc,EAClB,cACA,YACA,eAAY;CAAC;CAAI;CAAI;AAAE,GACvB,eACA,eACA,gBACA,gBACA,aACA,oBACA,wBACA,oBACA,oBACA,sBAAmB,IACnB,kBAAe,IACf,mBAAgBC,EAAc,WACT;CACrB,IAAMC,IAAkB,GAAGC,EAAgB,8BACrCC,IAAQC,EAAa,QAAQd,GAAgB,EAAE,GAI/Ce,IAAQF,IAAQ;EAAC;EAAO;EAAe,YAAY;CAAa,IAAI,EAAC,cAAc,gBAAe,GAElGG,IAAcC,EACjB,IAAI,MAAM,CAAC,CACX,QAAQ,GAAS,MAAUC,EAAK,SAASC,EAAQ,SAASD,IAAOC,GAAU,EAAE,GAE1EC,IAA+BH,EAAU,KAAK,OAAU;EAC5D,IAAIC;EACJ,OAAOA;EACP,OAAOA;CACT,EAAE,GACIG,IAAmBD,EAAa,MAAM,EAAC,eAAWE,MAAUnB,CAAO,GAEnEoB,IAAuBtB,EAAwBE,GAASqB,IAAY,GAAGC,CAAU,GACjFC,IAAuBC,KAAoBrB,EAAwBiB,CAAoB;CAE7F,OACE,kBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACE,kBAAC,OAAD;IAAK,WAAU;IACb,UAAA,kBAACxB,GAAD;KACE,GAAIgB;KACJ,IAAIJ;KACJ,WAAW,MAAa;MACtB,AAAIiB,MAAa,QAIjBC,EAAY,OAAOD,EAAS,KAAK,CAAC;KACpC;KACA,SAASR;KACT,OAAOC;KACP,oBAA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;;EACF;;AAET"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@propellerads/pagination",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
|
+
"style": "dist/index.css",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
8
9
|
"types": "./dist/index.d.ts",
|
|
9
10
|
"import": "./dist/index.js"
|
|
10
|
-
}
|
|
11
|
+
},
|
|
12
|
+
"./index.css": "./dist/index.css"
|
|
11
13
|
},
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"**/*.css"
|
|
16
|
+
],
|
|
12
17
|
"files": [
|
|
13
18
|
"dist"
|
|
14
19
|
],
|
|
@@ -24,15 +29,13 @@
|
|
|
24
29
|
"homepage": "https://github.com/propellerads/ui-components#readme",
|
|
25
30
|
"private": false,
|
|
26
31
|
"dependencies": {
|
|
27
|
-
"@propellerads/button": "^
|
|
28
|
-
"@propellerads/icon": "^
|
|
29
|
-
"@propellerads/label": "^
|
|
30
|
-
"@propellerads/select": "^
|
|
31
|
-
"@propellerads/stylevariables": "^2.0.2"
|
|
32
|
+
"@propellerads/button": "^14.0.0",
|
|
33
|
+
"@propellerads/icon": "^11.0.0",
|
|
34
|
+
"@propellerads/label": "^7.0.0",
|
|
35
|
+
"@propellerads/select": "^10.0.0"
|
|
32
36
|
},
|
|
33
37
|
"peerDependencies": {
|
|
34
|
-
"react": "^18.0.0 || ^19.0.0"
|
|
35
|
-
"styled-components": "^5.1.1 || ^6.0.0"
|
|
38
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
36
39
|
},
|
|
37
40
|
"devDependencies": {
|
|
38
41
|
"@types/react": "^19.2.14",
|
|
@@ -40,6 +43,7 @@
|
|
|
40
43
|
"rollup": "^4.60.3",
|
|
41
44
|
"rollup-plugin-dts": "^6.4.1",
|
|
42
45
|
"typescript": "^6.0.3",
|
|
43
|
-
"vite": "^8.0.11"
|
|
46
|
+
"vite": "^8.0.11",
|
|
47
|
+
"vite-plugin-lib-inject-css": "^2.2.2"
|
|
44
48
|
}
|
|
45
49
|
}
|