@rainbow-oh/yee-c 0.1.0 → 0.2.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/dist/cjs/Alert/alert.js +10 -4
- package/dist/cjs/Alert/style/index.less +3 -0
- package/dist/cjs/Anchor/anchor-item.js +6 -4
- package/dist/cjs/Anchor/anchor.js +38 -22
- package/dist/cjs/Anchor/demo/auto.d.ts +11 -0
- package/dist/cjs/Anchor/demo/auto.js +85 -0
- package/dist/cjs/Anchor/demo/basic.js +7 -1
- package/dist/cjs/Anchor/demo/controlled.js +42 -30
- package/dist/cjs/Anchor/interface.d.ts +2 -0
- package/dist/cjs/Anchor/style/index.less +2 -2
- package/dist/cjs/Button/button.d.ts +1 -1
- package/dist/cjs/Checkbox/checkbox-group.js +4 -1
- package/dist/cjs/Checkbox/demo/group.js +1 -0
- package/dist/cjs/Checkbox/interface.d.ts +5 -0
- package/dist/cjs/Checkbox/style/index.less +21 -1
- package/dist/cjs/Dropdown/demo/placement.js +2 -1
- package/dist/cjs/Dropdown/dropdown.js +3 -0
- package/dist/cjs/Dropdown/style/index.less +6 -0
- package/dist/cjs/Form/Field.js +33 -3
- package/dist/cjs/Form/Group.js +3 -2
- package/dist/cjs/Form/demo/form-table.js +1 -8
- package/dist/cjs/Form/demo/tooltip.d.ts +3 -0
- package/dist/cjs/Form/demo/tooltip.js +84 -0
- package/dist/cjs/Form/interface.d.ts +34 -1
- package/dist/cjs/Form/style/index.less +22 -7
- package/dist/cjs/Popconfirm/popconfirm.js +1 -1
- package/dist/cjs/Popconfirm/style/index.less +6 -0
- package/dist/cjs/Popover/popover.js +1 -1
- package/dist/cjs/Popover/style/index.less +6 -0
- package/dist/cjs/Progress/progress.js +2 -2
- package/dist/cjs/Radio/style/index.less +13 -6
- package/dist/cjs/Select/option.js +3 -2
- package/dist/cjs/Select/options.js +9 -1
- package/dist/cjs/Select/select.js +1 -0
- package/dist/cjs/Skeleton/demo/basic.js +1 -1
- package/dist/cjs/Space/interface.d.ts +4 -0
- package/dist/cjs/Space/space.js +36 -16
- package/dist/cjs/Splitter/demo/basic.js +1 -1
- package/dist/cjs/Splitter/demo/vertical.js +23 -1
- package/dist/cjs/Splitter/index.d.ts +1 -1
- package/dist/cjs/Splitter/interface.d.ts +9 -3
- package/dist/cjs/Splitter/splitter-handler.d.ts +1 -1
- package/dist/cjs/Splitter/splitter-handler.js +2 -1
- package/dist/cjs/Splitter/splitter.d.ts +2 -9
- package/dist/cjs/Splitter/splitter.js +53 -50
- package/dist/cjs/Splitter/style/index.less +21 -0
- package/dist/cjs/Table/demo/size.js +1 -1
- package/dist/cjs/Tabs/hooks/useTabScroll.d.ts +1 -1
- package/dist/cjs/Tabs/interface.d.ts +1 -1
- package/dist/cjs/Tabs/style/index.less +4 -0
- package/dist/cjs/Tabs/tab-header/index.js +56 -25
- package/dist/cjs/Tooltip/interface.d.ts +4 -0
- package/dist/cjs/Tooltip/style/index.less +8 -8
- package/dist/cjs/Tooltip/tooltip.js +11 -3
- package/dist/cjs/Tree/demo/draggable.d.ts +3 -0
- package/dist/cjs/Tree/demo/draggable.js +88 -0
- package/dist/cjs/Tree/demo/expanded.js +6 -6
- package/dist/cjs/Tree/index.d.ts +1 -0
- package/dist/cjs/Tree/index.js +3 -1
- package/dist/cjs/Tree/interface.d.ts +26 -0
- package/dist/cjs/Tree/style/index.less +25 -0
- package/dist/cjs/Tree/tree-node.js +38 -4
- package/dist/cjs/Tree/tree.d.ts +12 -1
- package/dist/cjs/Tree/tree.js +174 -18
- package/dist/cjs/Tree/utils/tree-tools.d.ts +21 -0
- package/dist/cjs/Tree/utils/tree-tools.js +88 -0
- package/dist/cjs/Trigger/style/index.less +17 -0
- package/dist/cjs/Trigger/trigger.js +3 -1
- package/dist/cjs/hooks/useDebounceFunction.d.ts +1 -1
- package/dist/cjs/hooks/useLayoutEffect.d.ts +1 -1
- package/dist/cjs/style/size.css +13 -4
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +14 -5
- package/dist/cjs/utils/debounce.d.ts +6 -1
- package/dist/cjs/utils/debounce.js +9 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Alert/alert.js +24 -8
- package/dist/esm/Alert/style/index.less +3 -0
- package/dist/esm/Anchor/anchor-item.js +6 -3
- package/dist/esm/Anchor/anchor.js +38 -19
- package/dist/esm/Anchor/demo/auto.d.ts +11 -0
- package/dist/esm/Anchor/demo/auto.js +62 -0
- package/dist/esm/Anchor/demo/basic.js +3 -1
- package/dist/esm/Anchor/demo/controlled.js +14 -9
- package/dist/esm/Anchor/interface.d.ts +2 -0
- package/dist/esm/Anchor/style/index.less +2 -2
- package/dist/esm/Button/button.d.ts +1 -1
- package/dist/esm/Checkbox/checkbox-group.js +4 -2
- package/dist/esm/Checkbox/demo/group.js +1 -0
- package/dist/esm/Checkbox/interface.d.ts +5 -0
- package/dist/esm/Checkbox/style/index.less +21 -1
- package/dist/esm/Dropdown/demo/placement.js +2 -1
- package/dist/esm/Dropdown/dropdown.js +6 -1
- package/dist/esm/Dropdown/style/index.less +6 -0
- package/dist/esm/Form/Field.js +43 -5
- package/dist/esm/Form/Group.js +4 -2
- package/dist/esm/Form/demo/form-table.js +8 -6
- package/dist/esm/Form/demo/tooltip.d.ts +3 -0
- package/dist/esm/Form/demo/tooltip.js +59 -0
- package/dist/esm/Form/interface.d.ts +34 -1
- package/dist/esm/Form/style/index.less +22 -7
- package/dist/esm/Popconfirm/popconfirm.js +3 -1
- package/dist/esm/Popconfirm/style/index.less +6 -0
- package/dist/esm/Popover/popover.js +3 -1
- package/dist/esm/Popover/style/index.less +6 -0
- package/dist/esm/Progress/progress.js +5 -5
- package/dist/esm/Radio/style/index.less +13 -6
- package/dist/esm/Select/option.js +4 -2
- package/dist/esm/Select/options.js +5 -3
- package/dist/esm/Select/select.js +1 -0
- package/dist/esm/Skeleton/demo/basic.js +2 -8
- package/dist/esm/Space/interface.d.ts +4 -0
- package/dist/esm/Space/space.js +24 -13
- package/dist/esm/Splitter/demo/basic.js +2 -0
- package/dist/esm/Splitter/demo/vertical.js +13 -5
- package/dist/esm/Splitter/index.d.ts +1 -1
- package/dist/esm/Splitter/interface.d.ts +9 -3
- package/dist/esm/Splitter/splitter-handler.d.ts +1 -1
- package/dist/esm/Splitter/splitter-handler.js +3 -1
- package/dist/esm/Splitter/splitter.d.ts +2 -9
- package/dist/esm/Splitter/splitter.js +59 -56
- package/dist/esm/Splitter/style/index.less +21 -0
- package/dist/esm/Table/demo/size.js +2 -7
- package/dist/esm/Tabs/hooks/useTabScroll.d.ts +1 -1
- package/dist/esm/Tabs/interface.d.ts +1 -1
- package/dist/esm/Tabs/style/index.less +4 -0
- package/dist/esm/Tabs/tab-header/index.js +11 -5
- package/dist/esm/Tooltip/interface.d.ts +4 -0
- package/dist/esm/Tooltip/style/index.less +8 -8
- package/dist/esm/Tooltip/tooltip.js +14 -2
- package/dist/esm/Tree/demo/draggable.d.ts +3 -0
- package/dist/esm/Tree/demo/draggable.js +61 -0
- package/dist/esm/Tree/demo/expanded.js +6 -6
- package/dist/esm/Tree/index.d.ts +1 -0
- package/dist/esm/Tree/index.js +1 -0
- package/dist/esm/Tree/interface.d.ts +26 -0
- package/dist/esm/Tree/style/index.less +25 -0
- package/dist/esm/Tree/tree-node.js +29 -4
- package/dist/esm/Tree/tree.d.ts +12 -1
- package/dist/esm/Tree/tree.js +135 -4
- package/dist/esm/Tree/utils/tree-tools.d.ts +21 -0
- package/dist/esm/Tree/utils/tree-tools.js +128 -1
- package/dist/esm/Trigger/style/index.less +17 -0
- package/dist/esm/Trigger/trigger.js +4 -3
- package/dist/esm/hooks/useDebounceFunction.d.ts +1 -1
- package/dist/esm/hooks/useLayoutEffect.d.ts +1 -1
- package/dist/esm/style/size.css +13 -4
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +14 -5
- package/dist/esm/utils/debounce.d.ts +6 -1
- package/dist/esm/utils/debounce.js +9 -2
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +2 -2
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +21 -23
- package/src/Alert/alert.tsx +10 -4
- package/src/Alert/style/index.less +3 -0
- package/src/Anchor/anchor-item.tsx +7 -2
- package/src/Anchor/anchor.tsx +49 -23
- package/src/Anchor/demo/auto.tsx +55 -0
- package/src/Anchor/demo/basic.tsx +7 -1
- package/src/Anchor/demo/controlled.tsx +18 -14
- package/src/Anchor/index.en-US.md +17 -0
- package/src/Anchor/index.zh-CN.md +17 -0
- package/src/Anchor/interface.ts +2 -0
- package/src/Anchor/style/index.less +2 -2
- package/src/Checkbox/checkbox-group.tsx +5 -1
- package/src/Checkbox/demo/group.tsx +1 -0
- package/src/Checkbox/interface.ts +5 -0
- package/src/Checkbox/style/index.less +21 -1
- package/src/Dropdown/demo/placement.tsx +1 -0
- package/src/Dropdown/dropdown.tsx +2 -0
- package/src/Dropdown/style/index.less +6 -0
- package/src/Form/Field.tsx +45 -3
- package/src/Form/Group.tsx +4 -1
- package/src/Form/demo/form-table.tsx +7 -7
- package/src/Form/demo/tooltip.tsx +72 -0
- package/src/Form/form-store.ts +1 -1
- package/src/Form/index.en-US.md +2 -0
- package/src/Form/index.zh-CN.md +83 -85
- package/src/Form/interface.ts +36 -1
- package/src/Form/style/index.less +22 -7
- package/src/Popconfirm/popconfirm.tsx +1 -1
- package/src/Popconfirm/style/index.less +6 -0
- package/src/Popover/popover.tsx +1 -1
- package/src/Popover/style/index.less +6 -0
- package/src/Progress/progress.tsx +2 -2
- package/src/Radio/style/index.less +13 -6
- package/src/Select/option.tsx +2 -1
- package/src/Select/options.tsx +7 -2
- package/src/Select/select.tsx +1 -0
- package/src/Skeleton/demo/basic.tsx +3 -3
- package/src/Space/interface.ts +4 -0
- package/src/Space/space.tsx +40 -16
- package/src/Splitter/demo/basic.tsx +2 -2
- package/src/Splitter/demo/vertical.tsx +19 -5
- package/src/Splitter/index.ts +5 -1
- package/src/Splitter/interface.ts +10 -3
- package/src/Splitter/splitter-handler.tsx +4 -2
- package/src/Splitter/splitter.tsx +55 -60
- package/src/Splitter/style/index.less +21 -0
- package/src/Table/demo/size.tsx +3 -3
- package/src/Table/index.zh-CN.md +50 -50
- package/src/Tabs/interface.ts +1 -1
- package/src/Tabs/style/index.less +4 -0
- package/src/Tabs/tab-header/index.tsx +26 -5
- package/src/Tooltip/index.en-US.md +1 -0
- package/src/Tooltip/index.zh-CN.md +1 -0
- package/src/Tooltip/interface.ts +4 -0
- package/src/Tooltip/style/index.less +8 -8
- package/src/Tooltip/tooltip.tsx +10 -1
- package/src/Tree/demo/draggable.tsx +58 -0
- package/src/Tree/demo/expanded.tsx +7 -7
- package/src/Tree/index.en-US.md +3 -0
- package/src/Tree/index.ts +1 -0
- package/src/Tree/index.zh-CN.md +3 -0
- package/src/Tree/interface.ts +28 -0
- package/src/Tree/style/index.less +25 -0
- package/src/Tree/tree-node.tsx +26 -0
- package/src/Tree/tree.tsx +183 -2
- package/src/Tree/utils/tree-tools.ts +107 -0
- package/src/Trigger/style/index.less +17 -0
- package/src/Trigger/trigger.tsx +3 -1
- package/src/style/size.css +13 -4
- package/src/utils/debounce.ts +22 -3
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rainbow-oh/yee-c",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "yee basic components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -58,26 +58,6 @@
|
|
|
58
58
|
"dist",
|
|
59
59
|
"src"
|
|
60
60
|
],
|
|
61
|
-
"scripts": {
|
|
62
|
-
"build": "node scripts/generate-version.js && rm -rf dist && father build",
|
|
63
|
-
"postbuild": "node scripts/merge-css.js",
|
|
64
|
-
"build:release": "dumi build && node scripts/generate-raw-md.js",
|
|
65
|
-
"build:watch": "father dev",
|
|
66
|
-
"dev": "dumi dev",
|
|
67
|
-
"docs:build": "dumi build && node scripts/generate-raw-md.js",
|
|
68
|
-
"docs:preview": "dumi preview",
|
|
69
|
-
"docs:scan": "node scripts/scan-docs.js",
|
|
70
|
-
"doctor": "father doctor",
|
|
71
|
-
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,css,less,json}\"",
|
|
72
|
-
"format:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,css,less,json}\"",
|
|
73
|
-
"lint": "npm run lint:es && npm run lint:css",
|
|
74
|
-
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\" --ignore-pattern \"src/style/color.*.css\"",
|
|
75
|
-
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
76
|
-
"prepare": "dumi setup",
|
|
77
|
-
"prepublishOnly": "npm run docs:scan && father doctor && node scripts/generate-version.js && npm run build",
|
|
78
|
-
"start": "npm run dev",
|
|
79
|
-
"watch": "father dev"
|
|
80
|
-
},
|
|
81
61
|
"commitlint": {
|
|
82
62
|
"extends": [
|
|
83
63
|
"@commitlint/config-conventional"
|
|
@@ -141,5 +121,23 @@
|
|
|
141
121
|
},
|
|
142
122
|
"authors": [
|
|
143
123
|
"InsureMO"
|
|
144
|
-
]
|
|
145
|
-
|
|
124
|
+
],
|
|
125
|
+
"scripts": {
|
|
126
|
+
"build": "node scripts/generate-version.js && rm -rf dist && father build",
|
|
127
|
+
"postbuild": "node scripts/merge-css.js",
|
|
128
|
+
"build:release": "dumi build && node scripts/generate-raw-md.js",
|
|
129
|
+
"build:watch": "father dev",
|
|
130
|
+
"dev": "dumi dev",
|
|
131
|
+
"docs:build": "dumi build && node scripts/generate-raw-md.js",
|
|
132
|
+
"docs:preview": "dumi preview",
|
|
133
|
+
"docs:scan": "node scripts/scan-docs.js",
|
|
134
|
+
"doctor": "father doctor",
|
|
135
|
+
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,css,less,json}\"",
|
|
136
|
+
"format:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,css,less,json}\"",
|
|
137
|
+
"lint": "npm run lint:es && npm run lint:css",
|
|
138
|
+
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\" --ignore-pattern \"src/style/color.*.css\"",
|
|
139
|
+
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
140
|
+
"start": "npm run dev",
|
|
141
|
+
"watch": "father dev"
|
|
142
|
+
}
|
|
143
|
+
}
|
package/src/Alert/alert.tsx
CHANGED
|
@@ -10,10 +10,16 @@ import './style/index.less';
|
|
|
10
10
|
const ICON_STROKE_WIDTH = 1.5; // Icon stroke width
|
|
11
11
|
|
|
12
12
|
const iconMap = {
|
|
13
|
-
info: { small: <Info />, large: <Info /> },
|
|
14
|
-
success: {
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
info: { small: <Info size={16} />, large: <Info size={24} /> },
|
|
14
|
+
success: {
|
|
15
|
+
small: <CircleCheckBig size={16} />,
|
|
16
|
+
large: <CircleCheckBig size={24} />,
|
|
17
|
+
},
|
|
18
|
+
warning: {
|
|
19
|
+
small: <CircleAlert size={16} />,
|
|
20
|
+
large: <CircleAlert size={24} />,
|
|
21
|
+
},
|
|
22
|
+
error: { small: <CircleX size={16} />, large: <CircleX size={24} /> },
|
|
17
23
|
};
|
|
18
24
|
|
|
19
25
|
const Alert: React.FC<AlertProps> = (baseprops) => {
|
|
@@ -17,7 +17,10 @@ const AnchorItem: React.FC<AnchorItemProps> = (props) => {
|
|
|
17
17
|
...rest
|
|
18
18
|
} = props;
|
|
19
19
|
|
|
20
|
-
const { prefixCls, activeKey, onClick } =
|
|
20
|
+
const { prefixCls, activeKey, onClick, classNames, styles } =
|
|
21
|
+
useContext(AnchorContext);
|
|
22
|
+
|
|
23
|
+
const isActive = targetKey === activeKey;
|
|
21
24
|
|
|
22
25
|
const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
23
26
|
e.preventDefault();
|
|
@@ -28,14 +31,16 @@ const AnchorItem: React.FC<AnchorItemProps> = (props) => {
|
|
|
28
31
|
const cls = clsx(
|
|
29
32
|
`${prefixCls}-item`,
|
|
30
33
|
{
|
|
31
|
-
[`${prefixCls}-item-active`]:
|
|
34
|
+
[`${prefixCls}-item-active`]: isActive,
|
|
32
35
|
[`${prefixCls}-item-${status}`]: status,
|
|
33
36
|
},
|
|
34
37
|
className,
|
|
38
|
+
isActive && classNames?.active,
|
|
35
39
|
);
|
|
36
40
|
|
|
37
41
|
const itemStyle = {
|
|
38
42
|
...style,
|
|
43
|
+
...(isActive ? styles?.active : undefined),
|
|
39
44
|
paddingLeft: `${level * INDENT_WIDTH}px`,
|
|
40
45
|
};
|
|
41
46
|
|
package/src/Anchor/anchor.tsx
CHANGED
|
@@ -59,13 +59,22 @@ const Anchor = forwardRef<HTMLDivElement, AnchorProps>((baseprops, ref) => {
|
|
|
59
59
|
const [anchorList, setAnchorList] = useState<Array<AnchorItemType>>([]);
|
|
60
60
|
|
|
61
61
|
const containerRef = useRef<HTMLElement | Window | null>(null);
|
|
62
|
+
const activeKeyRef = useRef(mergedActiveKey);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
activeKeyRef.current = mergedActiveKey;
|
|
65
|
+
}, [mergedActiveKey]);
|
|
62
66
|
|
|
63
67
|
// Auto-generate anchor list from DOM
|
|
64
68
|
const generateAnchorList = useCallback(() => {
|
|
65
69
|
if (!auto || !name) return;
|
|
66
70
|
|
|
67
71
|
const list: Array<AnchorItemType> = [];
|
|
68
|
-
|
|
72
|
+
// Escape `name` before interpolating into the attribute selector: a raw
|
|
73
|
+
// value containing quotes / brackets / backslashes would either break the
|
|
74
|
+
// selector (throwing) or open an injection vector.
|
|
75
|
+
const elements = document.querySelectorAll(
|
|
76
|
+
`[data-anchor-group="${CSS.escape(name)}"]`,
|
|
77
|
+
);
|
|
69
78
|
|
|
70
79
|
elements.forEach((element) => {
|
|
71
80
|
const key = element.getAttribute('id') || '';
|
|
@@ -87,6 +96,19 @@ const Anchor = forwardRef<HTMLDivElement, AnchorProps>((baseprops, ref) => {
|
|
|
87
96
|
}
|
|
88
97
|
}, [auto, generateAnchorList]);
|
|
89
98
|
|
|
99
|
+
const getTargetOffsetTop = useCallback((target: HTMLElement) => {
|
|
100
|
+
const container = containerRef.current;
|
|
101
|
+
const containerTop =
|
|
102
|
+
container === window
|
|
103
|
+
? 0
|
|
104
|
+
: (container as HTMLElement).getBoundingClientRect().top;
|
|
105
|
+
const currentScroll =
|
|
106
|
+
container === window
|
|
107
|
+
? window.scrollY
|
|
108
|
+
: (container as HTMLElement).scrollTop;
|
|
109
|
+
return currentScroll + (target.getBoundingClientRect().top - containerTop);
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
90
112
|
// Handle scroll to update active key
|
|
91
113
|
const handleScroll = useCallback(() => {
|
|
92
114
|
const container = containerRef.current;
|
|
@@ -107,33 +129,31 @@ const Anchor = forwardRef<HTMLDivElement, AnchorProps>((baseprops, ref) => {
|
|
|
107
129
|
const target = document.getElementById(item.key);
|
|
108
130
|
|
|
109
131
|
if (target) {
|
|
110
|
-
const targetTop = target
|
|
132
|
+
const targetTop = getTargetOffsetTop(target);
|
|
111
133
|
if (scrollTop + offsetTop >= targetTop) {
|
|
112
|
-
|
|
113
|
-
|
|
134
|
+
if (activeKeyRef.current !== item.key) {
|
|
135
|
+
setMergedActiveKey(item.key);
|
|
136
|
+
onChange?.(item.key);
|
|
137
|
+
}
|
|
114
138
|
break;
|
|
115
139
|
}
|
|
116
140
|
}
|
|
117
141
|
}
|
|
118
|
-
}, [auto, anchorList, items, offsetTop, onChange]);
|
|
142
|
+
}, [auto, anchorList, items, offsetTop, onChange, getTargetOffsetTop]);
|
|
119
143
|
|
|
120
144
|
useEffect(() => {
|
|
121
|
-
const container =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
);
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}, [getContainer, handleScroll, activeKey]);
|
|
145
|
+
const container = containerRef.current;
|
|
146
|
+
if (!container) return;
|
|
147
|
+
|
|
148
|
+
const debouncedScroll = debounce(handleScroll, 100);
|
|
149
|
+
container.addEventListener('scroll', debouncedScroll as EventListener);
|
|
150
|
+
handleScroll();
|
|
151
|
+
|
|
152
|
+
return () => {
|
|
153
|
+
container.removeEventListener('scroll', debouncedScroll as EventListener);
|
|
154
|
+
debouncedScroll.cancel();
|
|
155
|
+
};
|
|
156
|
+
}, [getContainer, handleScroll]);
|
|
137
157
|
|
|
138
158
|
// Scroll to target when activeKey changes
|
|
139
159
|
const scrollToAnchor = useCallback(
|
|
@@ -144,7 +164,7 @@ const Anchor = forwardRef<HTMLDivElement, AnchorProps>((baseprops, ref) => {
|
|
|
144
164
|
const container = containerRef.current;
|
|
145
165
|
if (!container) return;
|
|
146
166
|
|
|
147
|
-
const targetTop = target
|
|
167
|
+
const targetTop = getTargetOffsetTop(target) - offsetTop;
|
|
148
168
|
|
|
149
169
|
if (container === window) {
|
|
150
170
|
window.scrollTo({ top: targetTop, behavior: 'smooth' });
|
|
@@ -155,9 +175,13 @@ const Anchor = forwardRef<HTMLDivElement, AnchorProps>((baseprops, ref) => {
|
|
|
155
175
|
});
|
|
156
176
|
}
|
|
157
177
|
},
|
|
158
|
-
[offsetTop],
|
|
178
|
+
[offsetTop, getTargetOffsetTop],
|
|
159
179
|
);
|
|
160
180
|
|
|
181
|
+
useLayoutEffect(() => {
|
|
182
|
+
containerRef.current = getContainer ? getContainer() : window;
|
|
183
|
+
}, [getContainer]);
|
|
184
|
+
|
|
161
185
|
useLayoutEffect(() => {
|
|
162
186
|
if (defaultActiveKey) {
|
|
163
187
|
scrollToAnchor(defaultActiveKey);
|
|
@@ -190,6 +214,8 @@ const Anchor = forwardRef<HTMLDivElement, AnchorProps>((baseprops, ref) => {
|
|
|
190
214
|
prefixCls,
|
|
191
215
|
activeKey: mergedActiveKey,
|
|
192
216
|
onClick: handleItemClick,
|
|
217
|
+
classNames,
|
|
218
|
+
styles,
|
|
193
219
|
};
|
|
194
220
|
|
|
195
221
|
const renderNavArrow = () => {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Anchor } from '@rainbow-oh/yee-c';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `auto` mode: the anchor list is generated from the DOM. Decorate each target
|
|
6
|
+
* section with the following attributes:
|
|
7
|
+
* - data-anchor-group="<name>" must match the Anchor's `name` prop
|
|
8
|
+
* - id="<key>" used as the anchor key and scroll target
|
|
9
|
+
* - data-anchor-title="<title>" the nav label (required; a section without it is skipped)
|
|
10
|
+
* - data-anchor-status="success | error | warning" optional status badge color
|
|
11
|
+
*/
|
|
12
|
+
export default () => {
|
|
13
|
+
return (
|
|
14
|
+
<div
|
|
15
|
+
id="auto-container"
|
|
16
|
+
style={{ display: 'flex', height: 300, overflow: 'auto' }}
|
|
17
|
+
>
|
|
18
|
+
<Anchor
|
|
19
|
+
auto
|
|
20
|
+
name="article"
|
|
21
|
+
affix={false}
|
|
22
|
+
defaultActiveKey="auto-intro"
|
|
23
|
+
getContainer={() => document.getElementById('auto-container')!}
|
|
24
|
+
/>
|
|
25
|
+
<div style={{ flex: 1, padding: 20 }}>
|
|
26
|
+
<section
|
|
27
|
+
id="auto-intro"
|
|
28
|
+
data-anchor-group="article"
|
|
29
|
+
data-anchor-title="Introduction"
|
|
30
|
+
style={{ height: 300, background: '#f0f0f0', marginBottom: 20 }}
|
|
31
|
+
>
|
|
32
|
+
Introduction
|
|
33
|
+
</section>
|
|
34
|
+
<section
|
|
35
|
+
id="auto-usage"
|
|
36
|
+
data-anchor-group="article"
|
|
37
|
+
data-anchor-title="Usage"
|
|
38
|
+
data-anchor-status="success"
|
|
39
|
+
style={{ height: 300, background: '#e0e0e0', marginBottom: 20 }}
|
|
40
|
+
>
|
|
41
|
+
Usage
|
|
42
|
+
</section>
|
|
43
|
+
<section
|
|
44
|
+
id="auto-caveats"
|
|
45
|
+
data-anchor-group="article"
|
|
46
|
+
data-anchor-title="Caveats"
|
|
47
|
+
data-anchor-status="warning"
|
|
48
|
+
style={{ height: 300, background: '#d0d0d0' }}
|
|
49
|
+
>
|
|
50
|
+
Caveats
|
|
51
|
+
</section>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
@@ -20,7 +20,13 @@ export default () => {
|
|
|
20
20
|
return (
|
|
21
21
|
<div
|
|
22
22
|
id="basic-container"
|
|
23
|
-
style={{
|
|
23
|
+
style={{
|
|
24
|
+
position: 'relative',
|
|
25
|
+
display: 'flex',
|
|
26
|
+
height: '100vh',
|
|
27
|
+
overflow: 'auto',
|
|
28
|
+
transform: 'scale(1)',
|
|
29
|
+
}}
|
|
24
30
|
>
|
|
25
31
|
<Anchor
|
|
26
32
|
items={items}
|
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import { Anchor } from '@rainbow-oh/yee-c';
|
|
2
|
-
import React, { useState } from 'react';
|
|
2
|
+
import React, { useRef, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
export default () => {
|
|
5
5
|
const [activeKey, setActiveKey] = useState('part1');
|
|
6
|
-
|
|
6
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
7
7
|
const onChange = (key: string) => {
|
|
8
8
|
console.log('Anchor changed to:', key);
|
|
9
9
|
setActiveKey(key);
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
return (
|
|
13
|
-
<div
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
<div
|
|
14
|
+
style={{ display: 'flex', height: '200px', overflow: 'auto' }}
|
|
15
|
+
ref={containerRef}
|
|
16
|
+
>
|
|
17
|
+
<Anchor
|
|
18
|
+
items={[
|
|
19
|
+
{ key: 'part1', title: 'Part 1' },
|
|
20
|
+
{ key: 'part2', title: 'Part 2' },
|
|
21
|
+
{ key: 'part3', title: 'Part 3' },
|
|
22
|
+
]}
|
|
23
|
+
direction="vertical"
|
|
24
|
+
affix={false}
|
|
25
|
+
activeKey={activeKey}
|
|
26
|
+
onChange={onChange}
|
|
27
|
+
getContainer={() => containerRef.current!}
|
|
28
|
+
/>
|
|
25
29
|
<div style={{ flex: 1, padding: '20px' }}>
|
|
26
30
|
<div
|
|
27
31
|
id="part1"
|
|
@@ -17,6 +17,7 @@ Anchor component for linking to specific sections within a page.
|
|
|
17
17
|
<code src="./demo/basic.tsx" title="Basic" description="Basic usage of Anchor"></code>
|
|
18
18
|
<code src="./demo/direction.tsx" title="Direction" description="Vertical and horizontal directions"></code>
|
|
19
19
|
<code src="./demo/controlled.tsx" title="Controlled" description="Controlled mode with activeKey"></code>
|
|
20
|
+
<code src="./demo/auto.tsx" title="Auto" description="Generate the anchor list from the DOM"></code>
|
|
20
21
|
|
|
21
22
|
## API
|
|
22
23
|
|
|
@@ -69,6 +70,22 @@ Anchor component for linking to specific sections within a page.
|
|
|
69
70
|
| --- |
|
|
70
71
|
| `'item' \| 'active' \| 'content'` |
|
|
71
72
|
|
|
73
|
+
## Auto mode
|
|
74
|
+
|
|
75
|
+
When `auto` is set together with `name`, the component scans the DOM for elements tagged with `data-anchor-group="<name>"` and generates the anchor list automatically. Each target element must be annotated with:
|
|
76
|
+
|
|
77
|
+
| Attribute | Description |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `data-anchor-group` | Group name, must equal `name` |
|
|
80
|
+
| `id` | Used as the anchor key and scroll target (required) |
|
|
81
|
+
| `data-anchor-title` | Nav item label (required; a section without it is skipped) |
|
|
82
|
+
| `data-anchor-status` | Optional status, `success` / `error` / `warning` |
|
|
83
|
+
|
|
84
|
+
Notes:
|
|
85
|
+
|
|
86
|
+
- `auto` and `items` are mutually exclusive; when both are provided, the `auto` scan result wins and `items` is ignored.
|
|
87
|
+
- The DOM is scanned once on mount. If the target sections are rendered asynchronously, make sure they exist in the DOM at mount time, otherwise they will not be picked up.
|
|
88
|
+
|
|
72
89
|
## Notes
|
|
73
90
|
|
|
74
91
|
- Not yet adapted for mobile. Affix mode relies on hover interaction, which is not supported on touch devices
|
|
@@ -17,6 +17,7 @@ toc: 'content'
|
|
|
17
17
|
<code src="./demo/basic.tsx" title="基础用法" description="Anchor的基础用法"></code>
|
|
18
18
|
<code src="./demo/direction.tsx" title="方向" description="垂直和水平方向"></code>
|
|
19
19
|
<code src="./demo/controlled.tsx" title="受控模式" description="通过activeKey控制激活项"></code>
|
|
20
|
+
<code src="./demo/auto.tsx" title="自动生成" description="从 DOM 自动生成锚点列表"></code>
|
|
20
21
|
|
|
21
22
|
## API
|
|
22
23
|
|
|
@@ -69,6 +70,22 @@ toc: 'content'
|
|
|
69
70
|
| --- |
|
|
70
71
|
| `'item' \| 'active' \| 'content'` |
|
|
71
72
|
|
|
73
|
+
## 自动生成模式(auto)
|
|
74
|
+
|
|
75
|
+
设置 `auto` 并提供 `name` 时,组件会从 DOM 中扫描带 `data-anchor-group="<name>"` 的元素,自动生成锚点列表。每个目标元素需标注以下属性:
|
|
76
|
+
|
|
77
|
+
| 属性 | 说明 |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `data-anchor-group` | 分组名,必须等于 `name` |
|
|
80
|
+
| `id` | 作为锚点 key 与滚动目标(必填) |
|
|
81
|
+
| `data-anchor-title` | 导航项标题(必填,缺失则该项被跳过) |
|
|
82
|
+
| `data-anchor-status` | 可选状态,`success` / `error` / `warning` |
|
|
83
|
+
|
|
84
|
+
注意事项:
|
|
85
|
+
|
|
86
|
+
- `auto` 与 `items` 互斥,同时传入时以 `auto` 扫描结果为准,`items` 被忽略。
|
|
87
|
+
- 组件在挂载时扫描一次 DOM;若目标区块为异步渲染,请保证其在组件挂载时已存在于 DOM 中,否则扫描不到。
|
|
88
|
+
|
|
72
89
|
## 注意事项
|
|
73
90
|
|
|
74
91
|
- 移动端暂未适配,affix 模式依赖 hover 交互,触摸设备不支持
|
package/src/Anchor/interface.ts
CHANGED
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
width: var(--yee-anchor-static-item-active-width);
|
|
54
54
|
height: var(--yee-anchor-static-item-active-height);
|
|
55
55
|
border: none;
|
|
56
|
-
border-radius:
|
|
56
|
+
border-radius: var(--yee-anchor-static-item-active-width);
|
|
57
57
|
background-color: var(--yee-anchor-item-active-font-color);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
|
|
166
166
|
&-item {
|
|
167
167
|
position: relative;
|
|
168
|
-
|
|
168
|
+
margin: var(--yee-anchor-item-padding);
|
|
169
169
|
white-space: nowrap;
|
|
170
170
|
color: var(--yee-anchor-item-font-color);
|
|
171
171
|
cursor: pointer;
|
|
@@ -34,6 +34,7 @@ const CheckboxGroup = (baseprops: CheckboxGroupProps) => {
|
|
|
34
34
|
options,
|
|
35
35
|
buttonStyle,
|
|
36
36
|
disabled,
|
|
37
|
+
layout = 'horizontal',
|
|
37
38
|
onChange,
|
|
38
39
|
} = props;
|
|
39
40
|
|
|
@@ -44,6 +45,7 @@ const CheckboxGroup = (baseprops: CheckboxGroupProps) => {
|
|
|
44
45
|
|
|
45
46
|
const cls = clsx(
|
|
46
47
|
prefixCls,
|
|
48
|
+
[`${prefixCls}-${layout}`],
|
|
47
49
|
{
|
|
48
50
|
[`${prefixCls}-${buttonStyle}`]: buttonStyle,
|
|
49
51
|
[`${prefixCls}-disabled`]: disabled,
|
|
@@ -71,7 +73,9 @@ const CheckboxGroup = (baseprops: CheckboxGroupProps) => {
|
|
|
71
73
|
{...option}
|
|
72
74
|
checked={mergedValue.includes(option.value)}
|
|
73
75
|
key={option.value || index}
|
|
74
|
-
|
|
76
|
+
>
|
|
77
|
+
{option.label}
|
|
78
|
+
</Checkbox>
|
|
75
79
|
))}
|
|
76
80
|
</CheckboxGroupCtx.Provider>
|
|
77
81
|
</div>
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
background-color: var(--yee-checkbox-checked-bg-color);
|
|
34
34
|
border-color: var(--yee-checkbox-checked-border-color);
|
|
35
35
|
|
|
36
|
+
--ye-checkbox-checked-border-color: var(
|
|
37
|
+
--yee-checkbox-checked-after-border-color
|
|
38
|
+
);
|
|
39
|
+
|
|
36
40
|
&::after {
|
|
37
41
|
position: absolute;
|
|
38
42
|
top: 50%;
|
|
@@ -41,7 +45,7 @@
|
|
|
41
45
|
width: var(--yee-checkbox-checked-after-width);
|
|
42
46
|
height: var(--yee-checkbox-checked-after-height);
|
|
43
47
|
border: var(--yee-checkbox-checked-after-border-width) solid
|
|
44
|
-
var(--
|
|
48
|
+
var(--ye-checkbox-checked-border-color);
|
|
45
49
|
border-top: 0;
|
|
46
50
|
transform: rotate(45deg) scale(1) translate(-50%, -50%);
|
|
47
51
|
content: '';
|
|
@@ -59,6 +63,14 @@
|
|
|
59
63
|
border-color: var(--yee-checkbox-border-color);
|
|
60
64
|
}
|
|
61
65
|
|
|
66
|
+
&&-checked {
|
|
67
|
+
@{pls}-inner {
|
|
68
|
+
--ye-checkbox-checked-border-color: var(
|
|
69
|
+
--yee-checkbox-disabled-checked-border-color
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
62
74
|
@{pls}-input {
|
|
63
75
|
display: none;
|
|
64
76
|
}
|
|
@@ -100,4 +112,12 @@
|
|
|
100
112
|
}
|
|
101
113
|
}
|
|
102
114
|
}
|
|
115
|
+
|
|
116
|
+
&-group {
|
|
117
|
+
&-vertical {
|
|
118
|
+
display: flex;
|
|
119
|
+
flex-direction: column;
|
|
120
|
+
gap: 8px;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
103
123
|
}
|
|
@@ -20,6 +20,7 @@ const Dropdown: FC<DropdownProps> = (baseprops) => {
|
|
|
20
20
|
menu,
|
|
21
21
|
open,
|
|
22
22
|
defaultOpen,
|
|
23
|
+
arrow = { className: `${prefixCls}-arrow` },
|
|
23
24
|
onOpenChange,
|
|
24
25
|
...rest
|
|
25
26
|
} = props;
|
|
@@ -54,6 +55,7 @@ const Dropdown: FC<DropdownProps> = (baseprops) => {
|
|
|
54
55
|
return (
|
|
55
56
|
<Trigger
|
|
56
57
|
{...rest}
|
|
58
|
+
arrow={arrow}
|
|
57
59
|
popup={renderPopup() as any}
|
|
58
60
|
placement={placement}
|
|
59
61
|
popupClassName={`${prefixCls}-popup`}
|