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
|
@@ -2,16 +2,71 @@
|
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const candidateSelector = ["a[href]", "button", "textarea", 'input:not([type="hidden"])', "select", "[tabindex]", '[role="button"]'].join(",");
|
|
6
|
+
// The selector only finds candidates: `[tabindex]` also matches disabled
|
|
7
|
+
// controls and `[role="button"]` alone does not make an element focusable.
|
|
8
|
+
const isTabbable = node => node.tabIndex >= 0 && !node.matches(":disabled");
|
|
9
|
+
const getFocusableElements = element => Array.from(element.querySelectorAll(candidateSelector)).filter(isTabbable);
|
|
10
|
+
// Open traps in mount order, so a closing trap can hand its saved focus to
|
|
11
|
+
// traps opened on top of it.
|
|
12
|
+
const focusStack = [];
|
|
13
|
+
/**
|
|
14
|
+
* Moves focus into `element` when it mounts (first focusable element, or the
|
|
15
|
+
* element itself, which needs tabIndex={-1}), keeps Tab inside it while
|
|
16
|
+
* `isActive` returns true, and returns focus to the previously focused
|
|
17
|
+
* element when it unmounts.
|
|
18
|
+
*/
|
|
19
|
+
function useTrapFocus(element, isActive) {
|
|
20
|
+
// Read during render, before children with autoFocus take focus.
|
|
21
|
+
const previousFocusRef = React.useRef(null);
|
|
22
|
+
if (!element && typeof document !== "undefined") {
|
|
23
|
+
previousFocusRef.current = document.activeElement;
|
|
24
|
+
}
|
|
7
25
|
React.useEffect(() => {
|
|
26
|
+
var _a;
|
|
27
|
+
if (!element) return;
|
|
28
|
+
const entry = {
|
|
29
|
+
element,
|
|
30
|
+
previousFocus: previousFocusRef.current
|
|
31
|
+
};
|
|
32
|
+
focusStack.push(entry);
|
|
33
|
+
if (!element.contains(document.activeElement)) {
|
|
34
|
+
((_a = getFocusableElements(element)[0]) !== null && _a !== void 0 ? _a : element).focus();
|
|
35
|
+
}
|
|
36
|
+
return () => {
|
|
37
|
+
focusStack.splice(focusStack.indexOf(entry), 1);
|
|
38
|
+
// Traps opened from inside this one would restore focus to a removed
|
|
39
|
+
// element; give them the focus this trap saved instead.
|
|
40
|
+
focusStack.forEach(other => {
|
|
41
|
+
if (element.contains(other.previousFocus)) {
|
|
42
|
+
other.previousFocus = entry.previousFocus;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
// Focus inside another trap stays there. Focus removed with this
|
|
46
|
+
// element falls back to body.
|
|
47
|
+
const active = document.activeElement;
|
|
48
|
+
const ownsFocus = !active || active === document.body || element.contains(active);
|
|
49
|
+
const {
|
|
50
|
+
previousFocus
|
|
51
|
+
} = entry;
|
|
52
|
+
if (ownsFocus && previousFocus instanceof HTMLElement && previousFocus.isConnected) {
|
|
53
|
+
previousFocus.focus();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}, [element]);
|
|
57
|
+
React.useEffect(() => {
|
|
58
|
+
if (!element) return;
|
|
8
59
|
const handler = event => {
|
|
9
|
-
if (
|
|
60
|
+
if (event.key !== "Tab") return;
|
|
10
61
|
if (isActive && !isActive()) return;
|
|
11
|
-
const focusable =
|
|
62
|
+
const focusable = getFocusableElements(element);
|
|
12
63
|
const firstElement = focusable[0];
|
|
13
64
|
const lastElement = focusable[focusable.length - 1];
|
|
14
|
-
if (!lastElement || !firstElement)
|
|
65
|
+
if (!lastElement || !firstElement) {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
element.focus();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
15
70
|
const focusOutside = document.activeElement ? !focusable.includes(document.activeElement) : true;
|
|
16
71
|
if (event.shiftKey && (document.activeElement === firstElement || focusOutside)) {
|
|
17
72
|
lastElement.focus();
|
|
@@ -25,7 +80,7 @@ function useTrapFocus(refObject, isActive) {
|
|
|
25
80
|
return () => {
|
|
26
81
|
document.removeEventListener("keydown", handler);
|
|
27
82
|
};
|
|
28
|
-
}, [
|
|
83
|
+
}, [element, isActive]);
|
|
29
84
|
}
|
|
30
85
|
|
|
31
86
|
exports.useTrapFocus = useTrapFocus;
|
package/index.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export { MultiSelect } from "./MultiSelect";
|
|
|
52
52
|
export type { MultiSelectProps } from "./MultiSelect/index.props";
|
|
53
53
|
export { NumberInput } from "./NumberInput";
|
|
54
54
|
export type { NumberInputGroupStyle, NumberInputProps, NumberInputSize, NumberInputValues, } from "./NumberInput";
|
|
55
|
+
export { Pagination, getPaginationItems } from "./Pagination";
|
|
56
|
+
export type { PaginationItem, PaginationMode, PaginationProps, PaginationSize, } from "./Pagination";
|
|
55
57
|
export { Portal } from "./Portal";
|
|
56
58
|
export type { PortalProps } from "./Portal/index.props";
|
|
57
59
|
export { Progress } from "./Progress";
|
package/index.js
CHANGED
|
@@ -27,6 +27,7 @@ var index$f = require('./Menu/components/MenuItem/index.js');
|
|
|
27
27
|
var index$g = require('./Modal/index.js');
|
|
28
28
|
var index$l = require('./MultiSelect/index.js');
|
|
29
29
|
require('./NumberInput/index.js');
|
|
30
|
+
require('./Pagination/index.js');
|
|
30
31
|
var index$m = require('./Portal/index.js');
|
|
31
32
|
require('./Progress/index.js');
|
|
32
33
|
var index$n = require('./RadioGroup/index.js');
|
|
@@ -78,6 +79,7 @@ var index$j = require('./Modal/components/Header/index.js');
|
|
|
78
79
|
var index$k = require('./Modal/components/Title/index.js');
|
|
79
80
|
var More = require('./Icons/More.js');
|
|
80
81
|
var NumberInput = require('./NumberInput/NumberInput.js');
|
|
82
|
+
var Pagination = require('./Pagination/Pagination.js');
|
|
81
83
|
var Plus = require('./Icons/Plus.js');
|
|
82
84
|
var Progress = require('./Progress/Progress.js');
|
|
83
85
|
var Rating = require('./Rating/Rating.js');
|
|
@@ -87,6 +89,7 @@ var Shield = require('./Icons/Shield.js');
|
|
|
87
89
|
var Slider = require('./Slider/Slider.js');
|
|
88
90
|
var Trash = require('./Icons/Trash.js');
|
|
89
91
|
var User = require('./Icons/User.js');
|
|
92
|
+
var helpers = require('./Pagination/helpers.js');
|
|
90
93
|
|
|
91
94
|
|
|
92
95
|
|
|
@@ -166,6 +169,7 @@ exports.ModalHeader = index$j.Header;
|
|
|
166
169
|
exports.ModalTitle = index$k.Title;
|
|
167
170
|
exports.More = More.More;
|
|
168
171
|
exports.NumberInput = NumberInput.NumberInput;
|
|
172
|
+
exports.Pagination = Pagination.Pagination;
|
|
169
173
|
exports.Plus = Plus.Plus;
|
|
170
174
|
exports.Progress = Progress.Progress;
|
|
171
175
|
exports.Rating = Rating.Rating;
|
|
@@ -175,3 +179,4 @@ exports.Shield = Shield.Shield;
|
|
|
175
179
|
exports.Slider = Slider.Slider;
|
|
176
180
|
exports.Trash = Trash.Trash;
|
|
177
181
|
exports.User = User.User;
|
|
182
|
+
exports.getPaginationItems = helpers.getPaginationItems;
|
package/package.json
CHANGED
package/theme_ba_variables.css
CHANGED
|
@@ -608,6 +608,11 @@
|
|
|
608
608
|
--component-calendar-fade-inline-size: 2.5rem;
|
|
609
609
|
--component-calendar-day-size: 2rem;
|
|
610
610
|
--component-calendar-day-radius: 0.375rem;
|
|
611
|
+
--component-pagination-text: #163300;
|
|
612
|
+
--component-pagination-text-current: #9FE870;
|
|
613
|
+
--component-pagination-bg-current: #163300;
|
|
614
|
+
--component-pagination-bg-hover: #EDF0EA;
|
|
615
|
+
--component-pagination-focus-ring: #9FE870;
|
|
611
616
|
--component-navigation-item-bg-selected: #163300;
|
|
612
617
|
--component-chip-bg-selected: #163300;
|
|
613
618
|
--component-chip-bg-selected-strong: #9FE870;
|
|
@@ -608,6 +608,11 @@
|
|
|
608
608
|
--component-calendar-fade-inline-size: 2.5rem;
|
|
609
609
|
--component-calendar-day-size: 2rem;
|
|
610
610
|
--component-calendar-day-radius: 0.375rem;
|
|
611
|
+
--component-pagination-text: #2C2242;
|
|
612
|
+
--component-pagination-text-current: #FFA8CD;
|
|
613
|
+
--component-pagination-bg-current: #2C2242;
|
|
614
|
+
--component-pagination-bg-hover: #F2F1EE;
|
|
615
|
+
--component-pagination-focus-ring: #FFA8CD;
|
|
611
616
|
--component-navigation-item-bg-selected: #2C2242;
|
|
612
617
|
--component-chip-bg-selected: #2C2242;
|
|
613
618
|
--component-chip-bg-selected-strong: #FFA8CD;
|