colibri-ui 0.8.93 → 0.8.95
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/Modal/Modal.module.css +1 -0
- package/Modal/index.js +5 -7
- package/Pagination/Pagination.d.ts +3 -0
- package/Pagination/Pagination.js +162 -0
- package/Pagination/Pagination.module.css +118 -0
- package/Pagination/helpers.d.ts +5 -0
- package/Pagination/helpers.js +36 -0
- package/Pagination/index.d.ts +3 -0
- package/Pagination/index.js +9 -0
- package/Pagination/index.props.d.ts +31 -0
- package/Pagination/package.json +9 -0
- package/Theme/index.d.ts +10 -0
- package/Theme/themes/buenos_aires.d.ts +5 -0
- package/Theme/themes/buenos_aires.js +5 -0
- package/Theme/themes/jaipur.d.ts +5 -0
- package/Theme/themes/jaipur.js +5 -0
- package/esm/Modal/Modal.module.css +1 -0
- package/esm/Modal/index.js +6 -8
- package/esm/Pagination/Pagination.d.ts +3 -0
- package/esm/Pagination/Pagination.js +154 -0
- package/esm/Pagination/Pagination.module.css +118 -0
- package/esm/Pagination/helpers.d.ts +5 -0
- package/esm/Pagination/helpers.js +31 -0
- package/esm/Pagination/index.d.ts +3 -0
- package/esm/Pagination/index.js +2 -0
- package/esm/Pagination/index.props.d.ts +31 -0
- package/esm/Theme/index.d.ts +10 -0
- package/esm/Theme/themes/buenos_aires.d.ts +5 -0
- package/esm/Theme/themes/buenos_aires.js +5 -0
- package/esm/Theme/themes/jaipur.d.ts +5 -0
- package/esm/Theme/themes/jaipur.js +5 -0
- package/esm/hooks/useTrapFocus/index.d.ts +7 -2
- package/esm/hooks/useTrapFocus/index.js +62 -7
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/theme_ba_variables.css +5 -0
- package/esm/theme_jaipur_variables.css +5 -0
- package/hooks/useTrapFocus/index.d.ts +7 -2
- package/hooks/useTrapFocus/index.js +61 -6
- package/index.d.ts +2 -0
- package/index.js +5 -0
- package/package.json +1 -1
- package/theme_ba_variables.css +5 -0
- package/theme_jaipur_variables.css +5 -0
package/Modal/Modal.module.css
CHANGED
package/Modal/index.js
CHANGED
|
@@ -32,7 +32,7 @@ const ModalRoot = ({
|
|
|
32
32
|
title,
|
|
33
33
|
withinParent = false
|
|
34
34
|
}) => {
|
|
35
|
-
const
|
|
35
|
+
const [dialog, setDialog] = React.useState(null);
|
|
36
36
|
const [container, setContainer] = React.useState(null);
|
|
37
37
|
const parentModal = React.useContext(context.ModalContext);
|
|
38
38
|
const parentContainer = withinParent ? parentModal === null || parentModal === void 0 ? void 0 : parentModal.container : undefined;
|
|
@@ -42,7 +42,7 @@ const ModalRoot = ({
|
|
|
42
42
|
const [titleCount, setTitleCount] = React.useState(0);
|
|
43
43
|
const isTopmost = index$5.useModalStack(titleId);
|
|
44
44
|
index$6.useScrollLock();
|
|
45
|
-
index$7.useTrapFocus(
|
|
45
|
+
index$7.useTrapFocus(dialog, isTopmost);
|
|
46
46
|
const handleClose = React.useCallback(() => {
|
|
47
47
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
48
48
|
}, [onClose]);
|
|
@@ -50,10 +50,6 @@ const ModalRoot = ({
|
|
|
50
50
|
setTitleCount(count => count + 1);
|
|
51
51
|
return () => setTitleCount(count => count - 1);
|
|
52
52
|
}, []);
|
|
53
|
-
const setWrapperRef = React.useCallback(node => {
|
|
54
|
-
modalRef.current = node;
|
|
55
|
-
setContainer(node);
|
|
56
|
-
}, []);
|
|
57
53
|
const contextValue = React.useMemo(() => ({
|
|
58
54
|
onClose: handleClose,
|
|
59
55
|
titleId,
|
|
@@ -99,8 +95,10 @@ const ModalRoot = ({
|
|
|
99
95
|
className: clsx__default.default(styles__default.default.root, {
|
|
100
96
|
[styles__default.default.root_contained]: isContained
|
|
101
97
|
}),
|
|
98
|
+
ref: setDialog,
|
|
102
99
|
role: "dialog",
|
|
103
100
|
"aria-modal": "true",
|
|
101
|
+
tabIndex: -1,
|
|
104
102
|
"aria-labelledby": titleCount > 0 ? titleId : undefined
|
|
105
103
|
}, /*#__PURE__*/React__default.default.createElement("div", {
|
|
106
104
|
className: styles__default.default["modal-overlay"],
|
|
@@ -112,7 +110,7 @@ const ModalRoot = ({
|
|
|
112
110
|
[styles__default.default["modal-wrapper_mobile"]]: !isDesktop,
|
|
113
111
|
[styles__default.default["modal-wrapper_contained"]]: isContained
|
|
114
112
|
}, className),
|
|
115
|
-
ref:
|
|
113
|
+
ref: setContainer
|
|
116
114
|
}, content))));
|
|
117
115
|
};
|
|
118
116
|
const Modal = Object.assign(ModalRoot, {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { PaginationProps } from "./index.props";
|
|
3
|
+
export declare const Pagination: ({ totalPages, page, defaultPage, onPageChange, siblingCount, boundaryCount, disabledPages, disabled, mode, size, pageSize, defaultPageSize, pageSizeOptions, onPageSizeChange, showPageSize, showQuickJump, helperText, previousLabel, nextLabel, pageLabel, quickJumpLabel, pageSizeLabel, className, ref, "aria-label": ariaLabel, ...props }: PaginationProps) => React.JSX.Element;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var clsx = require('clsx');
|
|
6
|
+
var Chevron = require('../Icons/Chevron.js');
|
|
7
|
+
var index = require('../Input/index.js');
|
|
8
|
+
var index$1 = require('../Select/index.js');
|
|
9
|
+
var helpers = require('./helpers.js');
|
|
10
|
+
var styles = require('./Pagination.module.css');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
15
|
+
var clsx__default = /*#__PURE__*/_interopDefault(clsx);
|
|
16
|
+
var styles__default = /*#__PURE__*/_interopDefault(styles);
|
|
17
|
+
|
|
18
|
+
const NO_PAGES = [];
|
|
19
|
+
const DEFAULT_PAGE_SIZE_OPTIONS = [20, 50, 100];
|
|
20
|
+
const defaultPageLabel = page => `Page ${page}`;
|
|
21
|
+
const Pagination = _a => {
|
|
22
|
+
var {
|
|
23
|
+
totalPages,
|
|
24
|
+
page,
|
|
25
|
+
defaultPage = 1,
|
|
26
|
+
onPageChange,
|
|
27
|
+
siblingCount = 1,
|
|
28
|
+
boundaryCount = 1,
|
|
29
|
+
disabledPages = NO_PAGES,
|
|
30
|
+
disabled = false,
|
|
31
|
+
mode = "default",
|
|
32
|
+
size = "m",
|
|
33
|
+
pageSize,
|
|
34
|
+
defaultPageSize = 20,
|
|
35
|
+
pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS,
|
|
36
|
+
onPageSizeChange,
|
|
37
|
+
showPageSize = false,
|
|
38
|
+
showQuickJump = false,
|
|
39
|
+
helperText,
|
|
40
|
+
previousLabel = "Previous page",
|
|
41
|
+
nextLabel = "Next page",
|
|
42
|
+
pageLabel = defaultPageLabel,
|
|
43
|
+
quickJumpLabel = "Go to page",
|
|
44
|
+
pageSizeLabel = "Per page",
|
|
45
|
+
className,
|
|
46
|
+
ref,
|
|
47
|
+
"aria-label": ariaLabel = "Pagination"
|
|
48
|
+
} = _a,
|
|
49
|
+
props = tslib.__rest(_a, ["totalPages", "page", "defaultPage", "onPageChange", "siblingCount", "boundaryCount", "disabledPages", "disabled", "mode", "size", "pageSize", "defaultPageSize", "pageSizeOptions", "onPageSizeChange", "showPageSize", "showQuickJump", "helperText", "previousLabel", "nextLabel", "pageLabel", "quickJumpLabel", "pageSizeLabel", "className", "ref", "aria-label"]);
|
|
50
|
+
const total = helpers.toTotalPages(totalPages);
|
|
51
|
+
const [internalPage, setInternalPage] = React.useState(() => helpers.clamp(defaultPage, 1, total));
|
|
52
|
+
const currentPage = helpers.clamp(page !== null && page !== void 0 ? page : internalPage, 1, total);
|
|
53
|
+
const [internalPageSize, setInternalPageSize] = React.useState(defaultPageSize);
|
|
54
|
+
const currentPageSize = pageSize !== null && pageSize !== void 0 ? pageSize : internalPageSize;
|
|
55
|
+
const [quickJumpDraft, setQuickJumpDraft] = React.useState(null);
|
|
56
|
+
const disabledSet = React.useMemo(() => new Set(disabledPages), [disabledPages]);
|
|
57
|
+
const items = React.useMemo(() => helpers.getPaginationItems(total, currentPage, siblingCount, boundaryCount), [total, currentPage, siblingCount, boundaryCount]);
|
|
58
|
+
const pageSizeSelectOptions = React.useMemo(() => pageSizeOptions.map(option => ({
|
|
59
|
+
value: String(option),
|
|
60
|
+
label: option
|
|
61
|
+
})), [pageSizeOptions]);
|
|
62
|
+
const previousPage = helpers.findEnabledPage(currentPage, -1, total, disabledSet);
|
|
63
|
+
const nextPage = helpers.findEnabledPage(currentPage, 1, total, disabledSet);
|
|
64
|
+
const changePage = nextValue => {
|
|
65
|
+
const next = helpers.clamp(Math.floor(nextValue), 1, total);
|
|
66
|
+
if (disabled || disabledSet.has(next) || next === currentPage) return;
|
|
67
|
+
if (page === undefined) setInternalPage(next);
|
|
68
|
+
onPageChange === null || onPageChange === void 0 ? void 0 : onPageChange(next);
|
|
69
|
+
};
|
|
70
|
+
const commitQuickJump = () => {
|
|
71
|
+
if (quickJumpDraft === null) return;
|
|
72
|
+
const parsed = Number(quickJumpDraft);
|
|
73
|
+
if (quickJumpDraft.trim() !== "" && Number.isInteger(parsed)) {
|
|
74
|
+
changePage(parsed);
|
|
75
|
+
}
|
|
76
|
+
setQuickJumpDraft(null);
|
|
77
|
+
};
|
|
78
|
+
const changePageSize = next => {
|
|
79
|
+
if (pageSize === undefined) setInternalPageSize(next);
|
|
80
|
+
onPageSizeChange === null || onPageSizeChange === void 0 ? void 0 : onPageSizeChange(next);
|
|
81
|
+
};
|
|
82
|
+
const hasActions = showQuickJump || showPageSize || Boolean(helperText);
|
|
83
|
+
return /*#__PURE__*/React__default.default.createElement("nav", Object.assign({}, props, {
|
|
84
|
+
ref: ref,
|
|
85
|
+
"aria-label": ariaLabel,
|
|
86
|
+
className: clsx__default.default(styles__default.default.root, styles__default.default[`size_${size}`], {
|
|
87
|
+
[styles__default.default.root_disabled]: disabled
|
|
88
|
+
}, className)
|
|
89
|
+
}), /*#__PURE__*/React__default.default.createElement("div", {
|
|
90
|
+
className: styles__default.default.main
|
|
91
|
+
}, /*#__PURE__*/React__default.default.createElement("button", {
|
|
92
|
+
type: "button",
|
|
93
|
+
className: styles__default.default.arrow,
|
|
94
|
+
"aria-label": previousLabel,
|
|
95
|
+
disabled: disabled || previousPage === undefined,
|
|
96
|
+
onClick: () => {
|
|
97
|
+
if (previousPage !== undefined) changePage(previousPage);
|
|
98
|
+
}
|
|
99
|
+
}, /*#__PURE__*/React__default.default.createElement(Chevron.Chevron, {
|
|
100
|
+
className: styles__default.default.arrow_previous,
|
|
101
|
+
width: 16,
|
|
102
|
+
height: 16,
|
|
103
|
+
"aria-hidden": "true"
|
|
104
|
+
})), mode === "compact" ? (/*#__PURE__*/React__default.default.createElement("span", {
|
|
105
|
+
className: styles__default.default.counter,
|
|
106
|
+
"aria-live": "polite"
|
|
107
|
+
}, /*#__PURE__*/React__default.default.createElement("strong", null, currentPage), /*#__PURE__*/React__default.default.createElement("span", null, "/"), total)) : (/*#__PURE__*/React__default.default.createElement("div", {
|
|
108
|
+
className: styles__default.default.pages
|
|
109
|
+
}, items.map(item => typeof item === "number" ? (/*#__PURE__*/React__default.default.createElement("button", {
|
|
110
|
+
type: "button",
|
|
111
|
+
key: item,
|
|
112
|
+
className: clsx__default.default(styles__default.default.page, {
|
|
113
|
+
[styles__default.default.page_current]: item === currentPage
|
|
114
|
+
}),
|
|
115
|
+
"aria-label": pageLabel(item),
|
|
116
|
+
"aria-current": item === currentPage ? "page" : undefined,
|
|
117
|
+
disabled: disabled || disabledSet.has(item),
|
|
118
|
+
onClick: () => changePage(item)
|
|
119
|
+
}, item)) : (/*#__PURE__*/React__default.default.createElement("span", {
|
|
120
|
+
key: item,
|
|
121
|
+
className: styles__default.default.ellipsis,
|
|
122
|
+
"aria-hidden": "true"
|
|
123
|
+
}, "\u2026"))))), /*#__PURE__*/React__default.default.createElement("button", {
|
|
124
|
+
type: "button",
|
|
125
|
+
className: styles__default.default.arrow,
|
|
126
|
+
"aria-label": nextLabel,
|
|
127
|
+
disabled: disabled || nextPage === undefined,
|
|
128
|
+
onClick: () => {
|
|
129
|
+
if (nextPage !== undefined) changePage(nextPage);
|
|
130
|
+
}
|
|
131
|
+
}, /*#__PURE__*/React__default.default.createElement(Chevron.Chevron, {
|
|
132
|
+
className: styles__default.default.arrow_next,
|
|
133
|
+
width: 16,
|
|
134
|
+
height: 16,
|
|
135
|
+
"aria-hidden": "true"
|
|
136
|
+
}))), hasActions && (/*#__PURE__*/React__default.default.createElement("div", {
|
|
137
|
+
className: styles__default.default.actions
|
|
138
|
+
}, showQuickJump && (/*#__PURE__*/React__default.default.createElement(index.Input, {
|
|
139
|
+
className: styles__default.default.jump,
|
|
140
|
+
size: size,
|
|
141
|
+
label: quickJumpLabel,
|
|
142
|
+
inputMode: "numeric",
|
|
143
|
+
value: quickJumpDraft !== null && quickJumpDraft !== void 0 ? quickJumpDraft : String(currentPage),
|
|
144
|
+
disabled: disabled,
|
|
145
|
+
onChange: (_, value) => setQuickJumpDraft(value),
|
|
146
|
+
onBlur: commitQuickJump,
|
|
147
|
+
onKeyDown: event => {
|
|
148
|
+
if (event.key === "Enter") commitQuickJump();
|
|
149
|
+
}
|
|
150
|
+
})), showPageSize && (/*#__PURE__*/React__default.default.createElement(index$1.Select, {
|
|
151
|
+
size: size,
|
|
152
|
+
label: pageSizeLabel,
|
|
153
|
+
options: pageSizeSelectOptions,
|
|
154
|
+
value: String(currentPageSize),
|
|
155
|
+
disabled: disabled,
|
|
156
|
+
onChange: value => changePageSize(Number(value))
|
|
157
|
+
})), helperText && /*#__PURE__*/React__default.default.createElement("div", {
|
|
158
|
+
className: styles__default.default.helper
|
|
159
|
+
}, helperText))));
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
exports.Pagination = Pagination;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
--pagination-item-size: var(--component-input-height-m);
|
|
3
|
+
--pagination-font-size: var(--font-size-text-md);
|
|
4
|
+
color: var(--component-pagination-text);
|
|
5
|
+
display: inline-flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
font-family: var(--font-family-ui);
|
|
8
|
+
gap: var(--space-3);
|
|
9
|
+
max-inline-size: 100%;
|
|
10
|
+
}
|
|
11
|
+
.root_disabled {
|
|
12
|
+
opacity: 0.55;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.size_s {
|
|
16
|
+
--pagination-item-size: var(--component-input-height-s);
|
|
17
|
+
--pagination-font-size: var(--font-size-text-sm);
|
|
18
|
+
}
|
|
19
|
+
.size_l {
|
|
20
|
+
--pagination-item-size: var(--component-input-height-l);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.main,
|
|
24
|
+
.pages {
|
|
25
|
+
align-items: center;
|
|
26
|
+
display: flex;
|
|
27
|
+
gap: var(--space-1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.page,
|
|
31
|
+
.arrow {
|
|
32
|
+
align-items: center;
|
|
33
|
+
background: transparent;
|
|
34
|
+
block-size: var(--pagination-item-size);
|
|
35
|
+
border: none;
|
|
36
|
+
border-radius: var(--radius-sm);
|
|
37
|
+
box-sizing: border-box;
|
|
38
|
+
color: inherit;
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
display: inline-flex;
|
|
41
|
+
font: inherit;
|
|
42
|
+
font-size: var(--pagination-font-size);
|
|
43
|
+
justify-content: center;
|
|
44
|
+
min-inline-size: var(--pagination-item-size);
|
|
45
|
+
padding: 0 var(--space-2);
|
|
46
|
+
}
|
|
47
|
+
.page:disabled,
|
|
48
|
+
.arrow:disabled {
|
|
49
|
+
color: var(--color-text-disabled);
|
|
50
|
+
cursor: not-allowed;
|
|
51
|
+
}
|
|
52
|
+
.page:focus-visible,
|
|
53
|
+
.arrow:focus-visible {
|
|
54
|
+
outline: var(--focus-ring-width) solid var(--component-pagination-focus-ring);
|
|
55
|
+
outline-offset: var(--focus-ring-width);
|
|
56
|
+
}
|
|
57
|
+
.page:hover:not(:disabled),
|
|
58
|
+
.arrow:hover:not(:disabled) {
|
|
59
|
+
background: var(--component-pagination-bg-hover);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.page_current,
|
|
63
|
+
.page_current:hover:not(:disabled) {
|
|
64
|
+
background: var(--component-pagination-bg-current);
|
|
65
|
+
color: var(--component-pagination-text-current);
|
|
66
|
+
cursor: default;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.arrow_previous {
|
|
70
|
+
transform: rotate(90deg);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.arrow_next {
|
|
74
|
+
transform: rotate(-90deg);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.ellipsis {
|
|
78
|
+
align-items: center;
|
|
79
|
+
block-size: var(--pagination-item-size);
|
|
80
|
+
color: var(--color-text-secondary);
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
font-size: var(--pagination-font-size);
|
|
83
|
+
justify-content: center;
|
|
84
|
+
min-inline-size: var(--space-6);
|
|
85
|
+
-webkit-user-select: none;
|
|
86
|
+
user-select: none;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.counter {
|
|
90
|
+
align-items: center;
|
|
91
|
+
display: flex;
|
|
92
|
+
font-size: var(--pagination-font-size);
|
|
93
|
+
gap: var(--space-1);
|
|
94
|
+
justify-content: center;
|
|
95
|
+
min-inline-size: var(--space-20);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.actions {
|
|
99
|
+
align-items: flex-end;
|
|
100
|
+
display: flex;
|
|
101
|
+
flex-wrap: wrap;
|
|
102
|
+
gap: var(--space-4);
|
|
103
|
+
min-inline-size: 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.jump {
|
|
107
|
+
inline-size: var(--space-20);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.helper {
|
|
111
|
+
color: var(--color-text-secondary);
|
|
112
|
+
font-size: var(--font-size-text-sm);
|
|
113
|
+
line-height: var(--pagination-item-size);
|
|
114
|
+
min-inline-size: 0;
|
|
115
|
+
overflow: hidden;
|
|
116
|
+
text-overflow: ellipsis;
|
|
117
|
+
white-space: nowrap;
|
|
118
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PaginationItem } from "./index.props";
|
|
2
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
|
3
|
+
export declare const toTotalPages: (totalPages: number) => number;
|
|
4
|
+
export declare const getPaginationItems: (totalPages: number, page: number, siblingCount?: number, boundaryCount?: number) => PaginationItem[];
|
|
5
|
+
export declare const findEnabledPage: (from: number, direction: -1 | 1, total: number, disabledPages: ReadonlySet<number>) => number | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const range = (start, end) => Array.from({
|
|
4
|
+
length: Math.max(0, end - start + 1)
|
|
5
|
+
}, (_, index) => start + index);
|
|
6
|
+
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
7
|
+
const toTotalPages = totalPages => Math.max(1, Math.floor(totalPages) || 1);
|
|
8
|
+
const getPaginationItems = (totalPages, page, siblingCount = 1, boundaryCount = 1) => {
|
|
9
|
+
const total = toTotalPages(totalPages);
|
|
10
|
+
const current = clamp(Math.floor(page) || 1, 1, total);
|
|
11
|
+
const siblings = Math.max(0, Math.floor(siblingCount));
|
|
12
|
+
const boundaries = Math.max(0, Math.floor(boundaryCount));
|
|
13
|
+
const pages = [...new Set([...range(1, Math.min(boundaries, total)), ...range(Math.max(1, current - siblings), Math.min(total, current + siblings)), ...range(Math.max(1, total - boundaries + 1), total)])].sort((left, right) => left - right);
|
|
14
|
+
return pages.flatMap((visiblePage, index) => {
|
|
15
|
+
const previous = pages[index - 1];
|
|
16
|
+
if (previous === undefined) return [visiblePage];
|
|
17
|
+
if (visiblePage - previous === 2) return [previous + 1, visiblePage];
|
|
18
|
+
if (visiblePage - previous > 2) {
|
|
19
|
+
const ellipsis = visiblePage > current ? "end-ellipsis" : "start-ellipsis";
|
|
20
|
+
return [ellipsis, visiblePage];
|
|
21
|
+
}
|
|
22
|
+
return [visiblePage];
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const findEnabledPage = (from, direction, total, disabledPages) => {
|
|
26
|
+
let candidate = from + direction;
|
|
27
|
+
while (candidate >= 1 && candidate <= total && disabledPages.has(candidate)) {
|
|
28
|
+
candidate += direction;
|
|
29
|
+
}
|
|
30
|
+
return candidate >= 1 && candidate <= total ? candidate : undefined;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
exports.clamp = clamp;
|
|
34
|
+
exports.findEnabledPage = findEnabledPage;
|
|
35
|
+
exports.getPaginationItems = getPaginationItems;
|
|
36
|
+
exports.toTotalPages = toTotalPages;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode, Ref } from "react";
|
|
2
|
+
export type PaginationSize = "s" | "m" | "l";
|
|
3
|
+
export type PaginationMode = "default" | "compact";
|
|
4
|
+
export type PaginationItem = number | "start-ellipsis" | "end-ellipsis";
|
|
5
|
+
export interface PaginationProps extends Omit<HTMLAttributes<HTMLElement>, "onChange" | "defaultValue"> {
|
|
6
|
+
totalPages: number;
|
|
7
|
+
page?: number;
|
|
8
|
+
defaultPage?: number;
|
|
9
|
+
onPageChange?: (page: number) => void;
|
|
10
|
+
/** Pages shown on each side of the current page. */
|
|
11
|
+
siblingCount?: number;
|
|
12
|
+
/** Pages always shown at the start and at the end. */
|
|
13
|
+
boundaryCount?: number;
|
|
14
|
+
disabledPages?: readonly number[];
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
mode?: PaginationMode;
|
|
17
|
+
size?: PaginationSize;
|
|
18
|
+
pageSize?: number;
|
|
19
|
+
defaultPageSize?: number;
|
|
20
|
+
pageSizeOptions?: readonly number[];
|
|
21
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
22
|
+
showPageSize?: boolean;
|
|
23
|
+
showQuickJump?: boolean;
|
|
24
|
+
helperText?: ReactNode;
|
|
25
|
+
previousLabel?: string;
|
|
26
|
+
nextLabel?: string;
|
|
27
|
+
pageLabel?: (page: number) => string;
|
|
28
|
+
quickJumpLabel?: ReactNode;
|
|
29
|
+
pageSizeLabel?: ReactNode;
|
|
30
|
+
ref?: Ref<HTMLElement>;
|
|
31
|
+
}
|
package/Theme/index.d.ts
CHANGED
|
@@ -687,6 +687,11 @@ export declare const THEMES: {
|
|
|
687
687
|
"component-calendar-fade-inline-size": string;
|
|
688
688
|
"component-calendar-day-size": string;
|
|
689
689
|
"component-calendar-day-radius": string;
|
|
690
|
+
"component-pagination-text": string;
|
|
691
|
+
"component-pagination-text-current": string;
|
|
692
|
+
"component-pagination-bg-current": string;
|
|
693
|
+
"component-pagination-bg-hover": string;
|
|
694
|
+
"component-pagination-focus-ring": string;
|
|
690
695
|
"component-navigation-item-bg-selected": string;
|
|
691
696
|
"component-chip-bg-selected": string;
|
|
692
697
|
"component-chip-bg-selected-strong": string;
|
|
@@ -1526,6 +1531,11 @@ export declare const THEMES: {
|
|
|
1526
1531
|
"component-calendar-fade-inline-size": string;
|
|
1527
1532
|
"component-calendar-day-size": string;
|
|
1528
1533
|
"component-calendar-day-radius": string;
|
|
1534
|
+
"component-pagination-text": string;
|
|
1535
|
+
"component-pagination-text-current": string;
|
|
1536
|
+
"component-pagination-bg-current": string;
|
|
1537
|
+
"component-pagination-bg-hover": string;
|
|
1538
|
+
"component-pagination-focus-ring": string;
|
|
1529
1539
|
"component-navigation-item-bg-selected": string;
|
|
1530
1540
|
"component-chip-bg-selected": string;
|
|
1531
1541
|
"component-chip-bg-selected-strong": string;
|
|
@@ -608,6 +608,11 @@ declare const _default: {
|
|
|
608
608
|
"component-calendar-fade-inline-size": string;
|
|
609
609
|
"component-calendar-day-size": string;
|
|
610
610
|
"component-calendar-day-radius": string;
|
|
611
|
+
"component-pagination-text": string;
|
|
612
|
+
"component-pagination-text-current": string;
|
|
613
|
+
"component-pagination-bg-current": string;
|
|
614
|
+
"component-pagination-bg-hover": string;
|
|
615
|
+
"component-pagination-focus-ring": string;
|
|
611
616
|
"component-navigation-item-bg-selected": string;
|
|
612
617
|
"component-chip-bg-selected": string;
|
|
613
618
|
"component-chip-bg-selected-strong": string;
|
|
@@ -614,6 +614,11 @@ var THEME_BA = {
|
|
|
614
614
|
"component-calendar-fade-inline-size": "2.5rem",
|
|
615
615
|
"component-calendar-day-size": "2rem",
|
|
616
616
|
"component-calendar-day-radius": "0.375rem",
|
|
617
|
+
"component-pagination-text": theme_buenos_aires.default.BRAND_BA_FOREST,
|
|
618
|
+
"component-pagination-text-current": theme_buenos_aires.default.BRAND_BA_LIME,
|
|
619
|
+
"component-pagination-bg-current": theme_buenos_aires.default.BRAND_BA_FOREST,
|
|
620
|
+
"component-pagination-bg-hover": theme_buenos_aires.default.NEUTRAL_BA_100,
|
|
621
|
+
"component-pagination-focus-ring": theme_buenos_aires.default.BRAND_BA_LIME,
|
|
617
622
|
"component-navigation-item-bg-selected": theme_buenos_aires.default.BRAND_BA_FOREST,
|
|
618
623
|
"component-chip-bg-selected": theme_buenos_aires.default.BRAND_BA_FOREST,
|
|
619
624
|
"component-chip-bg-selected-strong": theme_buenos_aires.default.BRAND_BA_LIME,
|
package/Theme/themes/jaipur.d.ts
CHANGED
|
@@ -608,6 +608,11 @@ declare const _default: {
|
|
|
608
608
|
"component-calendar-fade-inline-size": string;
|
|
609
609
|
"component-calendar-day-size": string;
|
|
610
610
|
"component-calendar-day-radius": string;
|
|
611
|
+
"component-pagination-text": string;
|
|
612
|
+
"component-pagination-text-current": string;
|
|
613
|
+
"component-pagination-bg-current": string;
|
|
614
|
+
"component-pagination-bg-hover": string;
|
|
615
|
+
"component-pagination-focus-ring": string;
|
|
611
616
|
"component-navigation-item-bg-selected": string;
|
|
612
617
|
"component-chip-bg-selected": string;
|
|
613
618
|
"component-chip-bg-selected-strong": string;
|
package/Theme/themes/jaipur.js
CHANGED
|
@@ -614,6 +614,11 @@ var theme_jaipur = {
|
|
|
614
614
|
"component-calendar-fade-inline-size": "2.5rem",
|
|
615
615
|
"component-calendar-day-size": "2rem",
|
|
616
616
|
"component-calendar-day-radius": "0.375rem",
|
|
617
|
+
"component-pagination-text": theme_jaipur$1.default.BRAND_JP_EGGPLANT,
|
|
618
|
+
"component-pagination-text-current": theme_jaipur$1.default.BRAND_JP_PINK,
|
|
619
|
+
"component-pagination-bg-current": theme_jaipur$1.default.BRAND_JP_EGGPLANT,
|
|
620
|
+
"component-pagination-bg-hover": theme_jaipur$1.default.NEUTRAL_JP_100,
|
|
621
|
+
"component-pagination-focus-ring": theme_jaipur$1.default.BRAND_JP_PINK,
|
|
617
622
|
"component-navigation-item-bg-selected": theme_jaipur$1.default.BRAND_JP_EGGPLANT,
|
|
618
623
|
"component-chip-bg-selected": theme_jaipur$1.default.BRAND_JP_EGGPLANT,
|
|
619
624
|
"component-chip-bg-selected-strong": theme_jaipur$1.default.BRAND_JP_PINK,
|
package/esm/Modal/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState, useContext, useId, useCallback, useMemo, useEffect, Children, isValidElement } from 'react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import { useScrollLock } from '../hooks/useScrollLock/index.js';
|
|
4
4
|
import { useTrapFocus } from '../hooks/useTrapFocus/index.js';
|
|
@@ -24,7 +24,7 @@ const ModalRoot = ({
|
|
|
24
24
|
title,
|
|
25
25
|
withinParent = false
|
|
26
26
|
}) => {
|
|
27
|
-
const
|
|
27
|
+
const [dialog, setDialog] = useState(null);
|
|
28
28
|
const [container, setContainer] = useState(null);
|
|
29
29
|
const parentModal = useContext(ModalContext);
|
|
30
30
|
const parentContainer = withinParent ? parentModal === null || parentModal === void 0 ? void 0 : parentModal.container : undefined;
|
|
@@ -34,7 +34,7 @@ const ModalRoot = ({
|
|
|
34
34
|
const [titleCount, setTitleCount] = useState(0);
|
|
35
35
|
const isTopmost = useModalStack(titleId);
|
|
36
36
|
useScrollLock();
|
|
37
|
-
useTrapFocus(
|
|
37
|
+
useTrapFocus(dialog, isTopmost);
|
|
38
38
|
const handleClose = useCallback(() => {
|
|
39
39
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
40
40
|
}, [onClose]);
|
|
@@ -42,10 +42,6 @@ const ModalRoot = ({
|
|
|
42
42
|
setTitleCount(count => count + 1);
|
|
43
43
|
return () => setTitleCount(count => count - 1);
|
|
44
44
|
}, []);
|
|
45
|
-
const setWrapperRef = useCallback(node => {
|
|
46
|
-
modalRef.current = node;
|
|
47
|
-
setContainer(node);
|
|
48
|
-
}, []);
|
|
49
45
|
const contextValue = useMemo(() => ({
|
|
50
46
|
onClose: handleClose,
|
|
51
47
|
titleId,
|
|
@@ -91,8 +87,10 @@ const ModalRoot = ({
|
|
|
91
87
|
className: clsx(styles.root, {
|
|
92
88
|
[styles.root_contained]: isContained
|
|
93
89
|
}),
|
|
90
|
+
ref: setDialog,
|
|
94
91
|
role: "dialog",
|
|
95
92
|
"aria-modal": "true",
|
|
93
|
+
tabIndex: -1,
|
|
96
94
|
"aria-labelledby": titleCount > 0 ? titleId : undefined
|
|
97
95
|
}, /*#__PURE__*/React.createElement("div", {
|
|
98
96
|
className: styles["modal-overlay"],
|
|
@@ -104,7 +102,7 @@ const ModalRoot = ({
|
|
|
104
102
|
[styles["modal-wrapper_mobile"]]: !isDesktop,
|
|
105
103
|
[styles["modal-wrapper_contained"]]: isContained
|
|
106
104
|
}, className),
|
|
107
|
-
ref:
|
|
105
|
+
ref: setContainer
|
|
108
106
|
}, content))));
|
|
109
107
|
};
|
|
110
108
|
const Modal = Object.assign(ModalRoot, {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { PaginationProps } from "./index.props";
|
|
3
|
+
export declare const Pagination: ({ totalPages, page, defaultPage, onPageChange, siblingCount, boundaryCount, disabledPages, disabled, mode, size, pageSize, defaultPageSize, pageSizeOptions, onPageSizeChange, showPageSize, showQuickJump, helperText, previousLabel, nextLabel, pageLabel, quickJumpLabel, pageSizeLabel, className, ref, "aria-label": ariaLabel, ...props }: PaginationProps) => React.JSX.Element;
|