@papillonarts/components 0.35.0 → 0.36.0
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/build/Legacy/Blankslate/__tests__/Blankslate.doc.md +57 -0
- package/build/Legacy/Breadcrumb/__tests__/Breadcrumb.doc.md +33 -0
- package/build/Legacy/Markdown/__tests__/Markdown.doc.md +3 -3
- package/build/Legacy/SyntaxHighlighter/__tests__/SyntaxHighlighter.doc.md +3 -3
- package/build/Modern/Flash/Flash.d.ts +1 -2
- package/build/Modern/Flash/Flash.d.ts.map +1 -1
- package/build/Modern/Flash/Flash.js +3 -4
- package/build/Modern/Flash/__tests__/Flash.doc.md +0 -1
- package/build/Modern/Flash/index.d.ts +1 -1
- package/build/Modern/Flash/index.d.ts.map +1 -1
- package/build/Modern/Flash/index.js +3 -4
- package/build/Modern/Link/Link.d.ts +19 -0
- package/build/Modern/Link/Link.d.ts.map +1 -0
- package/build/Modern/Link/Link.docs.json +61 -0
- package/build/Modern/Link/Link.js +57 -0
- package/build/Modern/Link/Link.module.scss +39 -0
- package/build/Modern/Link/__tests__/Link.doc.md +10 -0
- package/build/Modern/Link/index.d.ts +3 -0
- package/build/Modern/Link/index.d.ts.map +1 -0
- package/build/Modern/Link/index.js +12 -0
- package/build/Modern/Pagination/Pagination.d.ts +22 -0
- package/build/Modern/Pagination/Pagination.d.ts.map +1 -0
- package/build/Modern/Pagination/Pagination.docs.json +77 -0
- package/build/Modern/Pagination/Pagination.js +132 -0
- package/build/Modern/Pagination/Pagination.model.d.ts +26 -0
- package/build/Modern/Pagination/Pagination.model.d.ts.map +1 -0
- package/build/Modern/Pagination/Pagination.model.js +211 -0
- package/build/Modern/Pagination/Pagination.module.scss +141 -0
- package/build/Modern/Pagination/__tests__/Pagination.doc.md +12 -0
- package/build/Modern/Pagination/index.d.ts +3 -0
- package/build/Modern/Pagination/index.d.ts.map +1 -0
- package/build/Modern/Pagination/index.js +12 -0
- package/build/Modern/hooks/index.d.ts +3 -0
- package/build/Modern/hooks/index.d.ts.map +1 -0
- package/build/Modern/hooks/index.js +19 -0
- package/build/Modern/hooks/useMedia.d.ts +37 -0
- package/build/Modern/hooks/useMedia.d.ts.map +1 -0
- package/build/Modern/hooks/useMedia.js +141 -0
- package/build/Modern/hooks/useRefObjectAsForwardedRef.d.ts +10 -0
- package/build/Modern/hooks/useRefObjectAsForwardedRef.d.ts.map +1 -0
- package/build/Modern/hooks/useRefObjectAsForwardedRef.hookDocs.json +22 -0
- package/build/Modern/hooks/useRefObjectAsForwardedRef.js +19 -0
- package/build/Modern/hooks/useResponsiveValue.d.ts +31 -0
- package/build/Modern/hooks/useResponsiveValue.d.ts.map +1 -0
- package/build/Modern/hooks/useResponsiveValue.js +73 -0
- package/build/Modern/index.d.ts +24 -0
- package/build/Modern/index.d.ts.map +1 -1
- package/build/Modern/index.js +11 -3
- package/build/Modern/type.d.ts +4 -0
- package/build/Modern/type.d.ts.map +1 -0
- package/build/Modern/type.js +5 -0
- package/build/Modern/utils/environment.d.ts +11 -0
- package/build/Modern/utils/environment.d.ts.map +1 -0
- package/build/Modern/utils/environment.js +13 -0
- package/build/Modern/utils/modern-polymorphic.d.ts +22 -0
- package/build/Modern/utils/modern-polymorphic.d.ts.map +1 -0
- package/build/Modern/utils/modern-polymorphic.js +28 -0
- package/build/Modern/utils/types/ComponentProps.d.ts +9 -0
- package/build/Modern/utils/types/ComponentProps.d.ts.map +1 -0
- package/build/Modern/utils/types/ComponentProps.js +5 -0
- package/build/Modern/utils/types/index.d.ts +3 -0
- package/build/Modern/utils/types/index.d.ts.map +1 -0
- package/build/Modern/utils/types/index.js +27 -0
- package/build/Modern/utils/warning.d.ts +4 -0
- package/build/Modern/utils/warning.d.ts.map +1 -0
- package/build/Modern/utils/warning.js +25 -0
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/build/Modern/Typing/index.d.js +0 -1
- package/build/Modern/global.d.js +0 -1
- /package/build/{Legacy/Typing → Typing}/index.d.js +0 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Pagination = Pagination;
|
|
9
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _octiconsReact = require("@primer/octicons-react");
|
|
12
|
+
var _clsx = require("clsx");
|
|
13
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
14
|
+
var _useResponsiveValue = require("../hooks/useResponsiveValue");
|
|
15
|
+
var _Pagination = require("./Pagination.model");
|
|
16
|
+
var _PaginationModule = _interopRequireDefault(require("./Pagination.module.scss"));
|
|
17
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
var _excluded = ["className", "pageCount", "currentPage", "onPageChange", "hrefBuilder", "marginPageCount", "showPages", "surroundingPageCount", "renderPage"];
|
|
19
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
20
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
21
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /* eslint-disable @typescript-eslint/consistent-type-definitions */
|
|
22
|
+
var getViewportRangesToHidePages = function getViewportRangesToHidePages(showPages) {
|
|
23
|
+
if (showPages && typeof showPages !== 'boolean') {
|
|
24
|
+
return Object.keys(showPages).filter(function (key) {
|
|
25
|
+
return !showPages[key];
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (showPages) {
|
|
29
|
+
return [];
|
|
30
|
+
} else {
|
|
31
|
+
return Object.keys(_useResponsiveValue.viewportRanges);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var PageLabel = function PageLabel(_ref) {
|
|
35
|
+
var children = _ref.children,
|
|
36
|
+
direction = _ref.direction;
|
|
37
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
38
|
+
children: [direction === 'page-prev' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_octiconsReact.ChevronLeftIcon, {}) : null, children, direction === 'page-next' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_octiconsReact.ChevronRightIcon, {}) : null]
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
function usePaginationPages(_ref2) {
|
|
42
|
+
var pageCount = _ref2.pageCount,
|
|
43
|
+
currentPage = _ref2.currentPage,
|
|
44
|
+
onPageChange = _ref2.onPageChange,
|
|
45
|
+
hrefBuilder = _ref2.hrefBuilder,
|
|
46
|
+
marginPageCount = _ref2.marginPageCount,
|
|
47
|
+
showPages = _ref2.showPages,
|
|
48
|
+
surroundingPageCount = _ref2.surroundingPageCount,
|
|
49
|
+
renderPage = _ref2.renderPage;
|
|
50
|
+
var pageChange = (0, _react.useCallback)(function (n) {
|
|
51
|
+
return function (e) {
|
|
52
|
+
return onPageChange(e, n);
|
|
53
|
+
};
|
|
54
|
+
}, [onPageChange]);
|
|
55
|
+
var model = (0, _react.useMemo)(function () {
|
|
56
|
+
return (0, _Pagination.buildPaginationModel)(pageCount, currentPage, !!showPages, marginPageCount, surroundingPageCount);
|
|
57
|
+
}, [pageCount, currentPage, showPages, marginPageCount, surroundingPageCount]);
|
|
58
|
+
var children = (0, _react.useMemo)(function () {
|
|
59
|
+
return model.map(function (page) {
|
|
60
|
+
var _buildComponentData = (0, _Pagination.buildComponentData)(page, hrefBuilder, pageChange(page.num)),
|
|
61
|
+
props = _buildComponentData.props,
|
|
62
|
+
key = _buildComponentData.key,
|
|
63
|
+
content = _buildComponentData.content;
|
|
64
|
+
if (renderPage && props.as !== 'span') {
|
|
65
|
+
return renderPage(_objectSpread({
|
|
66
|
+
key: key,
|
|
67
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PageLabel, {
|
|
68
|
+
direction: key,
|
|
69
|
+
children: content
|
|
70
|
+
}),
|
|
71
|
+
number: page.num,
|
|
72
|
+
className: _PaginationModule["default"].Page
|
|
73
|
+
}, props));
|
|
74
|
+
}
|
|
75
|
+
var Component = props.as || 'a';
|
|
76
|
+
return (
|
|
77
|
+
/*#__PURE__*/
|
|
78
|
+
// @ts-ignore giving me grief about children and "as" props
|
|
79
|
+
(0, _jsxRuntime.jsx)(Component, _objectSpread(_objectSpread({
|
|
80
|
+
className: (0, _clsx.clsx)(_PaginationModule["default"].Page)
|
|
81
|
+
}, props), {}, {
|
|
82
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PageLabel, {
|
|
83
|
+
direction: key,
|
|
84
|
+
children: content
|
|
85
|
+
})
|
|
86
|
+
}), key)
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
}, [model, hrefBuilder, pageChange, renderPage]);
|
|
90
|
+
return children;
|
|
91
|
+
}
|
|
92
|
+
function Pagination(_ref3) {
|
|
93
|
+
var className = _ref3.className,
|
|
94
|
+
pageCount = _ref3.pageCount,
|
|
95
|
+
currentPage = _ref3.currentPage,
|
|
96
|
+
_ref3$onPageChange = _ref3.onPageChange,
|
|
97
|
+
onPageChange = _ref3$onPageChange === void 0 ? noop : _ref3$onPageChange,
|
|
98
|
+
_ref3$hrefBuilder = _ref3.hrefBuilder,
|
|
99
|
+
hrefBuilder = _ref3$hrefBuilder === void 0 ? defaultHrefBuilder : _ref3$hrefBuilder,
|
|
100
|
+
_ref3$marginPageCount = _ref3.marginPageCount,
|
|
101
|
+
marginPageCount = _ref3$marginPageCount === void 0 ? 1 : _ref3$marginPageCount,
|
|
102
|
+
_ref3$showPages = _ref3.showPages,
|
|
103
|
+
showPages = _ref3$showPages === void 0 ? true : _ref3$showPages,
|
|
104
|
+
_ref3$surroundingPage = _ref3.surroundingPageCount,
|
|
105
|
+
surroundingPageCount = _ref3$surroundingPage === void 0 ? 2 : _ref3$surroundingPage,
|
|
106
|
+
renderPage = _ref3.renderPage,
|
|
107
|
+
rest = (0, _objectWithoutProperties2["default"])(_ref3, _excluded);
|
|
108
|
+
var pageElements = usePaginationPages({
|
|
109
|
+
pageCount: pageCount,
|
|
110
|
+
currentPage: currentPage,
|
|
111
|
+
onPageChange: onPageChange,
|
|
112
|
+
hrefBuilder: hrefBuilder,
|
|
113
|
+
marginPageCount: marginPageCount,
|
|
114
|
+
showPages: showPages,
|
|
115
|
+
surroundingPageCount: surroundingPageCount,
|
|
116
|
+
renderPage: renderPage
|
|
117
|
+
});
|
|
118
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("nav", _objectSpread(_objectSpread({
|
|
119
|
+
className: (0, _clsx.clsx)(_PaginationModule["default"].PaginationContainer, className),
|
|
120
|
+
"aria-label": "Pagination"
|
|
121
|
+
}, rest), {}, {
|
|
122
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
123
|
+
className: _PaginationModule["default"].TablePaginationSteps,
|
|
124
|
+
"data-hidden-viewport-ranges": getViewportRangesToHidePages(showPages).join(' '),
|
|
125
|
+
children: pageElements
|
|
126
|
+
})
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
function defaultHrefBuilder(pageNum) {
|
|
130
|
+
return "#".concat(pageNum);
|
|
131
|
+
}
|
|
132
|
+
function noop() {}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare function buildPaginationModel(pageCount: number, currentPage: number, showPages: boolean, marginPageCount: number, surroundingPageCount: number): PageType[];
|
|
2
|
+
interface PageType {
|
|
3
|
+
type: string;
|
|
4
|
+
num: number;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
selected?: boolean;
|
|
7
|
+
precedesBreak?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PageDataProps {
|
|
10
|
+
props: {
|
|
11
|
+
href?: string;
|
|
12
|
+
rel?: string;
|
|
13
|
+
'aria-label'?: string;
|
|
14
|
+
'aria-current'?: 'page' | 'step' | 'location' | 'date' | 'time' | 'true' | 'false' | boolean;
|
|
15
|
+
'aria-hidden'?: boolean;
|
|
16
|
+
'aria-disabled'?: boolean;
|
|
17
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
18
|
+
as?: string;
|
|
19
|
+
role?: string;
|
|
20
|
+
};
|
|
21
|
+
key: string;
|
|
22
|
+
content: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function buildComponentData(page: PageType, hrefBuilder: (n: number) => string, onClick: (e: React.MouseEvent) => void): PageDataProps;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=Pagination.model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pagination.model.d.ts","sourceRoot":"","sources":["../../../src/Modern/Pagination/Pagination.model.tsx"],"names":[],"mappings":"AACA,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,OAAO,EAClB,eAAe,EAAE,MAAM,EACvB,oBAAoB,EAAE,MAAM,cAsH7B;AAED,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE;QACL,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAA;QAC5F,aAAa,CAAC,EAAE,OAAO,CAAA;QACvB,eAAe,CAAC,EAAE,OAAO,CAAA;QACzB,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAA;QACvC,EAAE,CAAC,EAAE,MAAM,CAAA;QACX,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAClC,OAAO,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,GACrC,aAAa,CA4Df"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.buildComponentData = buildComponentData;
|
|
8
|
+
exports.buildPaginationModel = buildPaginationModel;
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-inferrable-types */
|
|
13
|
+
function buildPaginationModel(pageCount, currentPage, showPages, marginPageCount, surroundingPageCount) {
|
|
14
|
+
var prev = {
|
|
15
|
+
type: 'PREV',
|
|
16
|
+
num: currentPage - 1,
|
|
17
|
+
disabled: currentPage === 1
|
|
18
|
+
};
|
|
19
|
+
var next = {
|
|
20
|
+
type: 'NEXT',
|
|
21
|
+
num: currentPage + 1,
|
|
22
|
+
disabled: currentPage === pageCount
|
|
23
|
+
};
|
|
24
|
+
if (!showPages) {
|
|
25
|
+
return [prev, next];
|
|
26
|
+
}
|
|
27
|
+
if (pageCount <= 0) {
|
|
28
|
+
return [prev, _objectSpread(_objectSpread({}, next), {}, {
|
|
29
|
+
disabled: true
|
|
30
|
+
})];
|
|
31
|
+
}
|
|
32
|
+
var pages = [];
|
|
33
|
+
|
|
34
|
+
// number of pages shown on each side of the current page
|
|
35
|
+
// [1, ..., 7, 8, _9_, 10, 11, ..., 15]
|
|
36
|
+
// standardGap: 3
|
|
37
|
+
var standardGap = surroundingPageCount + marginPageCount;
|
|
38
|
+
|
|
39
|
+
// the maximum number of pages that can be shown at a given time (account for current page, left and right ellipsis)
|
|
40
|
+
// [1, ..., 7, 8, _9_, 10, 11, ..., 15]
|
|
41
|
+
// maxVisiblePages: 9
|
|
42
|
+
var maxVisiblePages = standardGap + standardGap + 3;
|
|
43
|
+
|
|
44
|
+
// if the number of pages is less than the maximum number of pages that can be shown just return all of them
|
|
45
|
+
if (pageCount <= maxVisiblePages) {
|
|
46
|
+
addPages(1, pageCount, false);
|
|
47
|
+
return [prev].concat(pages, [next]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// startGap is the number of pages hidden by the start ellipsis
|
|
51
|
+
// startOffset is the number of pages to offset at the start to compensate
|
|
52
|
+
// [1, ..., 7, 8, _9_, 10, 11, ..., 15]
|
|
53
|
+
// startGap: 5
|
|
54
|
+
// startOffset: 0
|
|
55
|
+
// when the margin and the surrounding windows overlap.
|
|
56
|
+
// [1, _2_, 3, 4, 5, 6, ..., 15]
|
|
57
|
+
// startGap = 0
|
|
58
|
+
// startOffset: -3 <--
|
|
59
|
+
var startGap = 0;
|
|
60
|
+
var startOffset = 0;
|
|
61
|
+
|
|
62
|
+
// When there is overlap
|
|
63
|
+
if (currentPage - standardGap - 1 <= 1) {
|
|
64
|
+
startOffset = currentPage - standardGap - 2;
|
|
65
|
+
} else {
|
|
66
|
+
startGap = currentPage - standardGap - 1;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// These are equivalent to startGap and startOffset but at the end of the list
|
|
70
|
+
var endGap = 0;
|
|
71
|
+
var endOffset = 0;
|
|
72
|
+
|
|
73
|
+
// When there is overlap
|
|
74
|
+
if (pageCount - currentPage - standardGap <= 1) {
|
|
75
|
+
endOffset = pageCount - currentPage - standardGap - 1;
|
|
76
|
+
} else {
|
|
77
|
+
endGap = pageCount - currentPage - standardGap;
|
|
78
|
+
}
|
|
79
|
+
var hasStartEllipsis = startGap > 0;
|
|
80
|
+
var hasEndEllipsis = endGap > 0;
|
|
81
|
+
|
|
82
|
+
// add pages "before" the start ellipsis (if any)
|
|
83
|
+
// [1, ..., 7, 8, _9_, 10, 11, ..., 15]
|
|
84
|
+
// marginPageCount: 1
|
|
85
|
+
// addPages(1, 1, true)
|
|
86
|
+
addPages(1, marginPageCount, hasStartEllipsis);
|
|
87
|
+
if (hasStartEllipsis) {
|
|
88
|
+
addEllipsis(marginPageCount);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// add middle pages
|
|
92
|
+
// [1, ..., 7, 8, _9_, 10, 11, ..., 15]
|
|
93
|
+
// marginPageCount: 1
|
|
94
|
+
// surroundingPageCount: 2
|
|
95
|
+
// startGap: 5
|
|
96
|
+
// startOffset: 0
|
|
97
|
+
// endGap: 3
|
|
98
|
+
// endOffset: 0
|
|
99
|
+
// addPages(7, 11, true)
|
|
100
|
+
addPages(marginPageCount + startGap + endOffset + 1, pageCount - startOffset - endGap - marginPageCount, hasEndEllipsis);
|
|
101
|
+
if (hasEndEllipsis) {
|
|
102
|
+
addEllipsis(pageCount - startOffset - endGap - marginPageCount);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// add pages "after" the start ellipsis (if any)
|
|
106
|
+
// [1, ..., 7, 8, _9_, 10, 11, ..., 15]
|
|
107
|
+
// marginPageCount: 1
|
|
108
|
+
// surroundingPageCount: 2
|
|
109
|
+
// startGap: 5
|
|
110
|
+
// startOffset: 0
|
|
111
|
+
// endGap: 3
|
|
112
|
+
// endOffset: 0
|
|
113
|
+
// addPages(15, 15)
|
|
114
|
+
addPages(pageCount - marginPageCount + 1, pageCount);
|
|
115
|
+
return [prev].concat(pages, [next]);
|
|
116
|
+
function addEllipsis(previousPage) {
|
|
117
|
+
pages.push({
|
|
118
|
+
type: 'BREAK',
|
|
119
|
+
num: previousPage + 1
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function addPages(start, end) {
|
|
123
|
+
var precedesBreak = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
124
|
+
for (var i = start; i <= end; i++) {
|
|
125
|
+
pages.push({
|
|
126
|
+
type: 'NUM',
|
|
127
|
+
num: i,
|
|
128
|
+
selected: i === currentPage,
|
|
129
|
+
precedesBreak: i === end && precedesBreak
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function buildComponentData(page, hrefBuilder, onClick) {
|
|
135
|
+
var props = {};
|
|
136
|
+
var content = '';
|
|
137
|
+
var key = '';
|
|
138
|
+
switch (page.type) {
|
|
139
|
+
case 'PREV':
|
|
140
|
+
{
|
|
141
|
+
key = 'page-prev';
|
|
142
|
+
content = 'Previous';
|
|
143
|
+
if (page.disabled) {
|
|
144
|
+
Object.assign(props, {
|
|
145
|
+
rel: 'prev',
|
|
146
|
+
'aria-hidden': 'true',
|
|
147
|
+
'aria-disabled': 'true'
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
Object.assign(props, {
|
|
151
|
+
rel: 'prev',
|
|
152
|
+
href: hrefBuilder(page.num),
|
|
153
|
+
'aria-label': 'Previous Page',
|
|
154
|
+
'data-testid': 'page-prev',
|
|
155
|
+
onClick: onClick
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case 'NEXT':
|
|
161
|
+
{
|
|
162
|
+
key = 'page-next';
|
|
163
|
+
content = 'Next';
|
|
164
|
+
if (page.disabled) {
|
|
165
|
+
Object.assign(props, {
|
|
166
|
+
rel: 'next',
|
|
167
|
+
'aria-hidden': 'true',
|
|
168
|
+
'aria-disabled': 'true'
|
|
169
|
+
});
|
|
170
|
+
} else {
|
|
171
|
+
Object.assign(props, {
|
|
172
|
+
rel: 'next',
|
|
173
|
+
href: hrefBuilder(page.num),
|
|
174
|
+
'aria-label': 'Next Page',
|
|
175
|
+
'data-testid': 'page-next',
|
|
176
|
+
onClick: onClick
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
case 'NUM':
|
|
182
|
+
{
|
|
183
|
+
key = "page-".concat(page.num);
|
|
184
|
+
content = String(page.num);
|
|
185
|
+
Object.assign(props, {
|
|
186
|
+
href: hrefBuilder(page.num),
|
|
187
|
+
// We append "..." to the aria-label for pages that preceed a break because screen readers will
|
|
188
|
+
// change the tone the text is read in.
|
|
189
|
+
// This is a slightly nicer experience than skipping a bunch of numbers unexpectedly.
|
|
190
|
+
'aria-label': "Page ".concat(page.num).concat(page.precedesBreak ? '...' : ''),
|
|
191
|
+
'aria-current': page.selected ? 'page' : undefined,
|
|
192
|
+
onClick: onClick
|
|
193
|
+
});
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case 'BREAK':
|
|
197
|
+
{
|
|
198
|
+
key = "page-".concat(page.num, "-break");
|
|
199
|
+
content = '…';
|
|
200
|
+
Object.assign(props, {
|
|
201
|
+
as: 'span',
|
|
202
|
+
role: 'presentation'
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
props: props,
|
|
208
|
+
key: key,
|
|
209
|
+
content: content
|
|
210
|
+
};
|
|
211
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* stylelint-disable custom-property-pattern, selector-not-notation, no-descending-specificity */
|
|
2
|
+
.Page {
|
|
3
|
+
min-width: 32px; /* primer.control.medium.size */
|
|
4
|
+
height: 32px; /* primer.control.medium.size */
|
|
5
|
+
padding: var(--base-size-8) calc((var(--base-size-32) - var(--base-size-20)) / 2); /* primer.control.medium.paddingInline.condensed primer.control.medium.paddingBlock */
|
|
6
|
+
margin-right: var(--base-size-4);
|
|
7
|
+
font-style: normal;
|
|
8
|
+
/* stylelint-disable-next-line primer/typography */
|
|
9
|
+
line-height: 1;
|
|
10
|
+
color: var(--fgColor-default);
|
|
11
|
+
text-align: center;
|
|
12
|
+
text-decoration: none;
|
|
13
|
+
white-space: nowrap;
|
|
14
|
+
vertical-align: middle;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
user-select: none;
|
|
17
|
+
background-color: transparent;
|
|
18
|
+
border-radius: var(--borderRadius-medium);
|
|
19
|
+
transition: background-color 0.2s cubic-bezier(0.3, 0, 0.5, 1);
|
|
20
|
+
display: inline-flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
justify-content: center;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.Page[rel='prev'] > svg,
|
|
26
|
+
.Page[rel='next'] > svg {
|
|
27
|
+
/* sizing with `em` so icons scale with inherited font-size */
|
|
28
|
+
height: 1em;
|
|
29
|
+
width: 1em;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.Page[rel='prev'] > svg {
|
|
33
|
+
margin-inline-end: var(--base-size-4);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.Page[rel='next'] > svg {
|
|
37
|
+
margin-inline-start: var(--base-size-4);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.Page:last-child {
|
|
41
|
+
margin-right: 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.Page:hover,
|
|
45
|
+
.Page:focus {
|
|
46
|
+
text-decoration: none;
|
|
47
|
+
background-color: var(--control-transparent-bgColor-hover);
|
|
48
|
+
outline: 0;
|
|
49
|
+
transition-duration: 0.1s;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.Page:focus-visible {
|
|
53
|
+
outline: 2px solid var(--bgColor-accent-emphasis);
|
|
54
|
+
outline-offset: -2px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.Page:active {
|
|
58
|
+
border-color: var(--borderColor-muted);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.Page[rel='prev'],
|
|
62
|
+
.Page[rel='next'] {
|
|
63
|
+
color: var(--fgColor-accent);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.Page[aria-current],
|
|
67
|
+
.Page[aria-current]:hover {
|
|
68
|
+
color: var(--fgColor-onEmphasis);
|
|
69
|
+
background-color: var(--bgColor-accent-emphasis);
|
|
70
|
+
border-color: transparent;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.Page[aria-current]:focus-visible {
|
|
74
|
+
outline: 2px solid var(--bgColor-accent-emphasis);
|
|
75
|
+
outline-offset: -2px;
|
|
76
|
+
/* stylelint-disable-next-line primer/box-shadow */
|
|
77
|
+
box-shadow: inset 0 0 0 3px var(--fgColor-onEmphasis);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.Page[aria-hidden],
|
|
81
|
+
.Page[aria-hidden]:hover,
|
|
82
|
+
.Page[role='presentation'],
|
|
83
|
+
.Page[role='presentation']:hover {
|
|
84
|
+
color: var(--fgColor-disabled);
|
|
85
|
+
cursor: default;
|
|
86
|
+
background-color: transparent;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.PaginationContainer {
|
|
90
|
+
/* stylelint-disable-next-line primer/spacing */
|
|
91
|
+
margin-top: 20px;
|
|
92
|
+
/* stylelint-disable-next-line primer/spacing */
|
|
93
|
+
margin-bottom: 15px;
|
|
94
|
+
text-align: center;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.TablePaginationSteps {
|
|
98
|
+
display: inline-block;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@media screen and (--viewportRange-narrow) {
|
|
102
|
+
.TablePaginationSteps[data-hidden-viewport-ranges*='narrow'] > *:not(:first-child):not(:last-child) {
|
|
103
|
+
display: none;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.TablePaginationSteps[data-hidden-viewport-ranges*='narrow'] > *:first-child {
|
|
107
|
+
margin-inline-end: 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.TablePaginationSteps[data-hidden-viewport-ranges*='narrow'] > *:last-child {
|
|
111
|
+
margin-inline-start: 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@media screen and (--viewportRange-regular) {
|
|
116
|
+
.TablePaginationSteps[data-hidden-viewport-ranges*='regular'] > *:not(:first-child):not(:last-child) {
|
|
117
|
+
display: none;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.TablePaginationSteps[data-hidden-viewport-ranges*='regular'] > *:first-child {
|
|
121
|
+
margin-inline-end: 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.TablePaginationSteps[data-hidden-viewport-ranges*='regular'] > *:last-child {
|
|
125
|
+
margin-inline-start: 0;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@media screen and (--viewportRange-wide) {
|
|
130
|
+
.TablePaginationSteps[data-hidden-viewport-ranges*='wide'] > *:not(:first-child):not(:last-child) {
|
|
131
|
+
display: none;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.TablePaginationSteps[data-hidden-viewport-ranges*='wide'] > *:first-child {
|
|
135
|
+
margin-inline-end: 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.TablePaginationSteps[data-hidden-viewport-ranges*='wide'] > *:last-child {
|
|
139
|
+
margin-inline-start: 0;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Modern/Pagination/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Pagination", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _Pagination.Pagination;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _Pagination = require("./Pagination");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Modern/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AAEzE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "useMedia", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _useMedia.useMedia;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "useRefObjectAsForwardedRef", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _useRefObjectAsForwardedRef.useRefObjectAsForwardedRef;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _useRefObjectAsForwardedRef = require("./useRefObjectAsForwardedRef");
|
|
19
|
+
var _useMedia = require("./useMedia");
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* `useMedia` will use the given `mediaQueryString` with `matchMedia` to
|
|
4
|
+
* determine if the document matches the media query string.
|
|
5
|
+
*
|
|
6
|
+
* If `MatchMedia` is used as an ancestor, `useMedia` will instead use the
|
|
7
|
+
* value of the media query string, if available
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* function Example() {
|
|
11
|
+
* const coarsePointer = useMedia('(pointer: coarse)');
|
|
12
|
+
* // ...
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export declare function useMedia(mediaQueryString: string, defaultState?: boolean): boolean;
|
|
16
|
+
type MediaQueryFeatures = Record<string, boolean | undefined>;
|
|
17
|
+
interface MatchMediaProps {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
features?: MediaQueryFeatures;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Use `MatchMedia` to emulate media conditions by passing in feature
|
|
23
|
+
* queries to the `features` prop. If a component uses `useMedia` with the
|
|
24
|
+
* feature passed in to `MatchMedia` it will force its value to match what is
|
|
25
|
+
* provided to `MatchMedia`
|
|
26
|
+
*
|
|
27
|
+
* This should be used for development and documentation only in situations
|
|
28
|
+
* where devtools cannot emulate this feature
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* <MatchMedia features={{ "(pointer: coarse)": true}}>
|
|
32
|
+
* <Children />
|
|
33
|
+
* </MatchMedia>
|
|
34
|
+
*/
|
|
35
|
+
export declare function MatchMedia({ children, features }: MatchMediaProps): import("react/jsx-runtime").JSX.Element;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=useMedia.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMedia.d.ts","sourceRoot":"","sources":["../../../src/Modern/hooks/useMedia.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyD,MAAM,OAAO,CAAA;AAI7E;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,WAgExE;AAED,KAAK,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC,CAAA;AAO7D,UAAU,eAAe;IACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,QAAQ,CAAC,EAAE,kBAAkB,CAAA;CAC9B;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,QAA0B,EAAE,EAAE,eAAe,2CAGnF"}
|