@rainbow-oh/yee-c 0.7.0 → 0.8.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/LICENSE +1 -1
- package/README.md +40 -25
- package/dist/cjs/Card/card.js +7 -3
- package/dist/cjs/Carousel/carousel-item.js +7 -2
- package/dist/cjs/Carousel/carousel.js +31 -4
- package/dist/cjs/Cascader/cascader.js +1 -1
- package/dist/cjs/Cascader/column.js +1 -1
- package/dist/cjs/Cascader/node.js +16 -4
- package/dist/cjs/Cascader/search-list.js +13 -4
- package/dist/cjs/Checkbox/checkbox-group.js +1 -1
- package/dist/cjs/Checkbox/checkbox.js +6 -3
- package/dist/cjs/Collapse/panel.js +10 -1
- package/dist/cjs/Dialog/dialog.js +22 -7
- package/dist/cjs/Drawer/drawer.js +14 -5
- package/dist/cjs/Form/form-store.d.ts +2 -1
- package/dist/cjs/Form/form-store.js +32 -17
- package/dist/cjs/Menu/menu-item.js +14 -5
- package/dist/cjs/Menu/menu.js +10 -2
- package/dist/cjs/Pagination/items.js +10 -5
- package/dist/cjs/Pagination/pagination.js +9 -3
- package/dist/cjs/Radio/radio-group.js +6 -5
- package/dist/cjs/Radio/radio.js +39 -29
- package/dist/cjs/Rate/rate.js +6 -1
- package/dist/cjs/Rate/star.js +7 -3
- package/dist/cjs/Steps/step.js +7 -5
- package/dist/cjs/Steps/steps.js +1 -1
- package/dist/cjs/Table/hooks/useColumns.js +1 -1
- package/dist/cjs/Table/style/index.less +35 -11
- package/dist/cjs/Table/table.js +57 -7
- package/dist/cjs/Table/tbody/cell.js +1 -1
- package/dist/cjs/Table/util/header.d.ts +3 -1
- package/dist/cjs/Table/util/header.js +30 -3
- package/dist/cjs/Tabs/tab-content.js +3 -1
- package/dist/cjs/Tabs/tab-header/index.js +3 -1
- package/dist/cjs/Tabs/tab-header/tab-header-title.js +3 -1
- package/dist/cjs/hooks/useDelayState.js +3 -2
- package/dist/cjs/hooks/useFocusManage.d.ts +1 -1
- package/dist/cjs/hooks/useFocusManage.js +27 -22
- package/dist/cjs/style/color.css +2 -0
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +3 -1
- package/dist/cjs/utils/focusStack.d.ts +6 -2
- package/dist/cjs/utils/focusStack.js +40 -11
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Card/card.js +7 -3
- package/dist/esm/Carousel/carousel-item.js +7 -2
- package/dist/esm/Carousel/carousel.js +31 -4
- package/dist/esm/Cascader/cascader.js +3 -1
- package/dist/esm/Cascader/column.js +2 -1
- package/dist/esm/Cascader/node.js +18 -4
- package/dist/esm/Cascader/search-list.js +18 -4
- package/dist/esm/Checkbox/checkbox-group.js +3 -1
- package/dist/esm/Checkbox/checkbox.js +6 -3
- package/dist/esm/Collapse/panel.js +11 -2
- package/dist/esm/Dialog/dialog.js +26 -9
- package/dist/esm/Drawer/drawer.js +16 -7
- package/dist/esm/Form/form-store.d.ts +2 -1
- package/dist/esm/Form/form-store.js +40 -19
- package/dist/esm/Menu/menu-item.js +16 -5
- package/dist/esm/Menu/menu.js +11 -5
- package/dist/esm/Pagination/items.js +14 -5
- package/dist/esm/Pagination/pagination.js +16 -4
- package/dist/esm/Radio/radio-group.js +5 -4
- package/dist/esm/Radio/radio.js +5 -4
- package/dist/esm/Rate/rate.js +6 -1
- package/dist/esm/Rate/star.js +12 -4
- package/dist/esm/Steps/step.js +12 -6
- package/dist/esm/Steps/steps.js +3 -1
- package/dist/esm/Table/hooks/useColumns.js +1 -1
- package/dist/esm/Table/style/index.less +35 -11
- package/dist/esm/Table/table.js +54 -2
- package/dist/esm/Table/tbody/cell.js +1 -1
- package/dist/esm/Table/util/header.d.ts +3 -1
- package/dist/esm/Table/util/header.js +30 -2
- package/dist/esm/Tabs/tab-content.js +3 -1
- package/dist/esm/Tabs/tab-header/index.js +3 -1
- package/dist/esm/Tabs/tab-header/tab-header-title.js +3 -1
- package/dist/esm/hooks/useDelayState.js +5 -2
- package/dist/esm/hooks/useFocusManage.d.ts +1 -1
- package/dist/esm/hooks/useFocusManage.js +31 -13
- package/dist/esm/style/color.css +2 -0
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +3 -1
- package/dist/esm/utils/focusStack.d.ts +6 -2
- package/dist/esm/utils/focusStack.js +37 -14
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +3 -3
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +10 -6
- package/src/Card/card.tsx +5 -1
- package/src/Carousel/carousel-item.tsx +7 -1
- package/src/Carousel/carousel.tsx +30 -3
- package/src/Cascader/cascader.tsx +1 -1
- package/src/Cascader/column.tsx +1 -1
- package/src/Cascader/node.tsx +14 -2
- package/src/Cascader/search-list.tsx +11 -2
- package/src/Checkbox/checkbox-group.tsx +1 -1
- package/src/Checkbox/checkbox.tsx +3 -0
- package/src/Collapse/panel.tsx +11 -1
- package/src/Dialog/dialog.tsx +31 -6
- package/src/Drawer/drawer.tsx +12 -3
- package/src/Form/form-store.ts +42 -15
- package/src/Menu/menu-item.tsx +12 -3
- package/src/Menu/menu.tsx +11 -5
- package/src/Pagination/items.tsx +9 -4
- package/src/Pagination/pagination.tsx +10 -4
- package/src/Radio/radio-group.tsx +2 -1
- package/src/Radio/radio.tsx +7 -2
- package/src/Rate/rate.tsx +5 -0
- package/src/Rate/star.tsx +8 -4
- package/src/Steps/step.tsx +15 -5
- package/src/Steps/steps.tsx +1 -1
- package/src/Table/hooks/useColumns.ts +1 -1
- package/src/Table/style/index.less +35 -11
- package/src/Table/table.tsx +60 -1
- package/src/Table/tbody/cell.tsx +1 -1
- package/src/Table/util/header.ts +48 -2
- package/src/Tabs/tab-content.tsx +2 -0
- package/src/Tabs/tab-header/index.tsx +2 -0
- package/src/Tabs/tab-header/tab-header-title.tsx +3 -1
- package/src/hooks/useDelayState.ts +4 -2
- package/src/hooks/useFocusManage.ts +33 -17
- package/src/style/color.css +2 -0
- package/src/utils/focusStack.ts +55 -12
- package/src/version.ts +1 -1
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
import { popFocus, pushFocus } from '../utils/focusStack';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { type FocusStackEntry, popFocus, pushFocus } from '../utils/focusStack';
|
|
3
|
+
export default function useFocusManage(
|
|
4
|
+
element: HTMLElement | null,
|
|
5
|
+
open: boolean,
|
|
6
|
+
) {
|
|
7
|
+
const entryRef = useRef<FocusStackEntry | null>(null);
|
|
8
|
+
const previousFocusRef = useRef<HTMLElement | null>(null);
|
|
9
|
+
const openCycleRef = useRef(false);
|
|
10
|
+
const releaseEntry = () => {
|
|
11
|
+
if (entryRef.current) {
|
|
12
|
+
popFocus(entryRef.current);
|
|
13
|
+
entryRef.current = null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const endOpenCycle = () => {
|
|
17
|
+
releaseEntry();
|
|
18
|
+
previousFocusRef.current = null;
|
|
19
|
+
openCycleRef.current = false;
|
|
20
|
+
};
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (open && !openCycleRef.current) {
|
|
23
|
+
openCycleRef.current = true;
|
|
24
|
+
previousFocusRef.current = document.activeElement as HTMLElement | null;
|
|
25
|
+
} else if (!open && openCycleRef.current) {
|
|
26
|
+
endOpenCycle();
|
|
27
|
+
}
|
|
28
|
+
}, [open]);
|
|
8
29
|
useEffect(() => {
|
|
9
|
-
if (!
|
|
10
|
-
|
|
11
|
-
pushFocus(ele);
|
|
12
|
-
} else {
|
|
13
|
-
popFocus();
|
|
30
|
+
if (!open || !openCycleRef.current || !element || entryRef.current) {
|
|
31
|
+
return;
|
|
14
32
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
}, [ele, delayOpen]);
|
|
33
|
+
entryRef.current = pushFocus(element, previousFocusRef.current);
|
|
34
|
+
}, [element, open]);
|
|
35
|
+
useEffect(() => releaseEntry, []);
|
|
20
36
|
}
|
package/src/style/color.css
CHANGED
|
@@ -848,6 +848,7 @@
|
|
|
848
848
|
--yee-table-thead-stripe-borderbottom-color: var(
|
|
849
849
|
--yee-table-thead-borderbottom-color
|
|
850
850
|
);
|
|
851
|
+
--yee-table-row-bg-color: var(--yee-color-bg-container);
|
|
851
852
|
--yee-table-odd-row-bg-color: var(--yee-color-bg-container);
|
|
852
853
|
--yee-table-even-row-bg-color: var(--yee-color-bg-head);
|
|
853
854
|
--yee-table-elevated-thead-stripe-borderbottom-color: var(
|
|
@@ -870,6 +871,7 @@
|
|
|
870
871
|
--yee-table-head-filter-active-color: var(--yee-primary-color);
|
|
871
872
|
--yee-table-fixed-left-after-bs-color: var(--yee-box-shadow-color);
|
|
872
873
|
--yee-table-fixed-right-after-bs-color: var(--yee-box-shadow-color);
|
|
874
|
+
--yee-table-fixed-column-bg-color: inherit;
|
|
873
875
|
--yee-table-filter-list-bg-color: var(--yee-color-bg-elevated);
|
|
874
876
|
--yee-table-tbody-tr-expanded-bg-color: var(--yee-color-bg-container);
|
|
875
877
|
--yee-table-elevated-tbody-tr-expanded-bg-color: var(
|
package/src/utils/focusStack.ts
CHANGED
|
@@ -1,22 +1,65 @@
|
|
|
1
|
-
// focusStack.ts
|
|
2
1
|
type Focusable = HTMLElement | null;
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
export interface FocusStackEntry {
|
|
4
|
+
container: HTMLElement;
|
|
5
|
+
previous: Focusable;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const focusableSelector = [
|
|
9
|
+
'a[href]',
|
|
10
|
+
'button:not([disabled])',
|
|
11
|
+
'textarea:not([disabled])',
|
|
12
|
+
'input:not([disabled])',
|
|
13
|
+
'select:not([disabled])',
|
|
14
|
+
'details',
|
|
15
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
16
|
+
].join(',');
|
|
17
|
+
|
|
18
|
+
const stack: FocusStackEntry[] = [];
|
|
5
19
|
let raf = 0;
|
|
6
20
|
|
|
7
|
-
const schedule = (
|
|
21
|
+
const schedule = (callback: () => void) => {
|
|
8
22
|
cancelAnimationFrame(raf);
|
|
9
|
-
raf = requestAnimationFrame(
|
|
23
|
+
raf = requestAnimationFrame(callback);
|
|
10
24
|
};
|
|
11
25
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
const focusInitialElement = (entry: FocusStackEntry) => {
|
|
27
|
+
if (stack[stack.length - 1] !== entry || !entry.container.isConnected) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const activeElement = document.activeElement;
|
|
32
|
+
if (activeElement && entry.container.contains(activeElement)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const firstFocusable =
|
|
37
|
+
entry.container.querySelector<HTMLElement>(focusableSelector);
|
|
38
|
+
(firstFocusable ?? entry.container).focus();
|
|
16
39
|
};
|
|
17
40
|
|
|
18
|
-
export const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
41
|
+
export const pushFocus = (
|
|
42
|
+
container: HTMLElement,
|
|
43
|
+
previous: Focusable = document.activeElement as HTMLElement | null,
|
|
44
|
+
): FocusStackEntry => {
|
|
45
|
+
const entry = { container, previous };
|
|
46
|
+
stack.push(entry);
|
|
47
|
+
schedule(() => focusInitialElement(entry));
|
|
48
|
+
return entry;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const popFocus = (entry: FocusStackEntry) => {
|
|
52
|
+
const index = stack.lastIndexOf(entry);
|
|
53
|
+
if (index === -1) return;
|
|
54
|
+
|
|
55
|
+
const isTopEntry = index === stack.length - 1;
|
|
56
|
+
stack.splice(index, 1);
|
|
57
|
+
|
|
58
|
+
if (!isTopEntry) return;
|
|
59
|
+
|
|
60
|
+
schedule(() => {
|
|
61
|
+
if (entry.previous?.isConnected) {
|
|
62
|
+
entry.previous.focus();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
22
65
|
};
|