@alifd/chat 0.0.1 → 0.1.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/es/button/index.d.ts +24 -1
- package/es/button/index.js +33 -1
- package/es/button/main.scss +5 -0
- package/es/button/style.d.ts +1 -0
- package/es/button/style.js +1 -0
- package/es/card/index.d.ts +6 -0
- package/es/card/index.js +6 -0
- package/es/card/main.scss +141 -0
- package/es/card/style.d.ts +2 -0
- package/es/card/style.js +2 -0
- package/es/card/types.d.ts +56 -0
- package/es/card/types.js +1 -0
- package/es/card/view/card.d.ts +6 -0
- package/es/card/view/card.js +52 -0
- package/es/card/view/collapsable.d.ts +7 -0
- package/es/card/view/collapsable.js +62 -0
- package/es/core/variables.scss +33 -0
- package/es/feedback/index.d.ts +7 -0
- package/es/feedback/index.js +47 -0
- package/es/feedback/main.scss +42 -0
- package/es/feedback/style.d.ts +1 -0
- package/es/feedback/style.js +1 -0
- package/es/feedback/types.d.ts +54 -0
- package/es/feedback/types.js +1 -0
- package/es/feedback/view/good.d.ts +7 -0
- package/es/feedback/view/good.js +7 -0
- package/es/float-button/hooks/useAutoAlign.d.ts +2 -2
- package/es/float-button/hooks/useAutoAlign.js +2 -2
- package/es/float-button/hooks/useTriggerType.d.ts +3 -0
- package/es/float-button/hooks/useTriggerType.js +31 -0
- package/es/float-button/index.d.ts +3 -2
- package/es/float-button/index.js +2 -1
- package/es/float-button/main.scss +74 -11
- package/es/float-button/style.d.ts +1 -0
- package/es/float-button/style.js +1 -0
- package/es/float-button/types.d.ts +18 -2
- package/es/float-button/view/backtop.js +3 -3
- package/es/float-button/view/drawer.d.ts +7 -1
- package/es/float-button/view/drawer.js +11 -2
- package/es/float-button/view/float-button.d.ts +1 -1
- package/es/float-button/view/float-button.js +71 -28
- package/es/float-button/view/inner-drawer.d.ts +18 -2
- package/es/float-button/view/inner-drawer.js +114 -3
- package/es/index.d.ts +6 -0
- package/es/index.js +7 -1
- package/es/tab/index.d.ts +8 -0
- package/es/tab/index.js +14 -0
- package/es/tab/main.scss +10 -0
- package/es/tab/style.d.ts +2 -0
- package/es/tab/style.js +2 -0
- package/es/tag/index.d.ts +13 -0
- package/es/tag/index.js +21 -0
- package/es/tag/main.scss +9 -0
- package/es/tag/style.d.ts +2 -0
- package/es/tag/style.js +2 -0
- package/es/text/index.d.ts +3 -0
- package/es/text/index.js +301 -0
- package/es/text/main.scss +19 -0
- package/es/text/style.d.ts +1 -0
- package/es/text/style.js +1 -0
- package/es/text/types.d.ts +16 -0
- package/es/text/types.js +1 -0
- package/es/utils/consts.d.ts +1 -0
- package/es/utils/consts.js +1 -0
- package/es/utils/hooks/useControlable.d.ts +1 -1
- package/es/utils/hooks/useControlable.js +4 -3
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +1 -0
- package/lib/button/index.d.ts +24 -1
- package/lib/button/index.js +33 -6
- package/lib/button/main.scss +5 -0
- package/lib/button/style.d.ts +1 -0
- package/lib/button/style.js +1 -0
- package/lib/card/index.d.ts +6 -0
- package/lib/card/index.js +9 -0
- package/lib/card/main.scss +141 -0
- package/lib/card/style.d.ts +2 -0
- package/lib/card/style.js +4 -0
- package/lib/card/types.d.ts +56 -0
- package/lib/card/types.js +2 -0
- package/lib/card/view/card.d.ts +6 -0
- package/lib/card/view/card.js +57 -0
- package/lib/card/view/collapsable.d.ts +7 -0
- package/lib/card/view/collapsable.js +64 -0
- package/lib/core/variables.scss +33 -0
- package/lib/feedback/index.d.ts +7 -0
- package/lib/feedback/index.js +49 -0
- package/lib/feedback/main.scss +42 -0
- package/lib/feedback/style.d.ts +1 -0
- package/lib/feedback/style.js +3 -0
- package/lib/feedback/types.d.ts +54 -0
- package/lib/feedback/types.js +2 -0
- package/lib/feedback/view/good.d.ts +7 -0
- package/lib/feedback/view/good.js +10 -0
- package/lib/float-button/hooks/useAutoAlign.d.ts +2 -2
- package/lib/float-button/hooks/useAutoAlign.js +2 -2
- package/lib/float-button/hooks/useTriggerType.d.ts +3 -0
- package/lib/float-button/hooks/useTriggerType.js +35 -0
- package/lib/float-button/index.d.ts +3 -2
- package/lib/float-button/index.js +2 -1
- package/lib/float-button/main.scss +74 -11
- package/lib/float-button/style.d.ts +1 -0
- package/lib/float-button/style.js +1 -0
- package/lib/float-button/types.d.ts +18 -2
- package/lib/float-button/view/backtop.js +2 -2
- package/lib/float-button/view/drawer.d.ts +7 -1
- package/lib/float-button/view/drawer.js +10 -2
- package/lib/float-button/view/float-button.d.ts +1 -1
- package/lib/float-button/view/float-button.js +69 -26
- package/lib/float-button/view/inner-drawer.d.ts +18 -2
- package/lib/float-button/view/inner-drawer.js +113 -3
- package/lib/index.d.ts +6 -0
- package/lib/index.js +14 -2
- package/lib/tab/index.d.ts +8 -0
- package/lib/tab/index.js +16 -0
- package/lib/tab/main.scss +10 -0
- package/lib/tab/style.d.ts +2 -0
- package/lib/tab/style.js +4 -0
- package/lib/tag/index.d.ts +13 -0
- package/lib/tag/index.js +23 -0
- package/lib/tag/main.scss +9 -0
- package/lib/tag/style.d.ts +2 -0
- package/lib/tag/style.js +4 -0
- package/lib/text/index.d.ts +3 -0
- package/lib/text/index.js +304 -0
- package/lib/text/main.scss +19 -0
- package/lib/text/style.d.ts +1 -0
- package/lib/text/style.js +3 -0
- package/lib/text/types.d.ts +16 -0
- package/lib/text/types.js +2 -0
- package/lib/utils/consts.d.ts +1 -0
- package/lib/utils/consts.js +4 -0
- package/lib/utils/hooks/useControlable.d.ts +1 -1
- package/lib/utils/hooks/useControlable.js +4 -3
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/package.json +81 -1
- package/es/button/view/button.d.ts +0 -23
- package/es/button/view/button.js +0 -26
- package/lib/button/view/button.d.ts +0 -23
- package/lib/button/view/button.js +0 -29
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @component 标签
|
|
3
|
+
* @en Tag
|
|
4
|
+
* @type 通用 - General
|
|
5
|
+
* @remarks 同 Next Tag - Same as Next.Tag
|
|
6
|
+
* @when Tag
|
|
7
|
+
*/
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { Tag as NextTag } from '@alifd/next';
|
|
10
|
+
import type { TagProps } from '@alifd/next/types/tag';
|
|
11
|
+
export type { TagProps } from '@alifd/next/types/tag';
|
|
12
|
+
declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<TagProps & React.RefAttributes<NextTag>, "key" | keyof TagProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, NextTag, {}>;
|
|
13
|
+
export default _default;
|
package/es/tag/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @component 标签
|
|
3
|
+
* @en Tag
|
|
4
|
+
* @type 通用 - General
|
|
5
|
+
* @remarks 同 Next Tag - Same as Next.Tag
|
|
6
|
+
* @when Tag
|
|
7
|
+
*/
|
|
8
|
+
import { __rest } from "tslib";
|
|
9
|
+
import React, { forwardRef } from 'react';
|
|
10
|
+
import { Tag as NextTag, ConfigProvider } from '@alifd/next';
|
|
11
|
+
import cs from 'classnames';
|
|
12
|
+
import { PREFIX_DEFAULT, assignSubComponent } from '../utils';
|
|
13
|
+
const Tag = forwardRef((_a, ref) => {
|
|
14
|
+
var { className, size = 'small', type = 'normal' } = _a, props = __rest(_a, ["className", "size", "type"]);
|
|
15
|
+
return (React.createElement(NextTag, Object.assign({}, props, { ref: ref, className: cs(`${PREFIX_DEFAULT}tag`, className), size: size, type: type })));
|
|
16
|
+
});
|
|
17
|
+
// 暂时只开放 Tag 组件,其它子组件后续看需求
|
|
18
|
+
const TagWithSub = assignSubComponent(Tag, {
|
|
19
|
+
displayName: 'Tag',
|
|
20
|
+
});
|
|
21
|
+
export default ConfigProvider.config(TagWithSub);
|
package/es/tag/main.scss
ADDED
package/es/tag/style.js
ADDED
package/es/text/index.js
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import React, { useRef, useLayoutEffect, useCallback, useEffect, useState, useMemo, } from 'react';
|
|
2
|
+
import { ConfigProvider } from '@alifd/next';
|
|
3
|
+
import cs from 'classnames';
|
|
4
|
+
import { PREFIX_DEFAULT, useControlable, useDebounce } from '../utils';
|
|
5
|
+
import Button from '../button';
|
|
6
|
+
function normalizeTriggerType(triggerType) {
|
|
7
|
+
if (!triggerType) {
|
|
8
|
+
return ['click'];
|
|
9
|
+
}
|
|
10
|
+
const arr = Array.isArray(triggerType) ? triggerType : [triggerType];
|
|
11
|
+
const allowedSet = new Set(['click', 'hover']);
|
|
12
|
+
const results = Array.from(new Set(arr.filter(t => allowedSet.has(t))));
|
|
13
|
+
if (!results.length) {
|
|
14
|
+
results.push('click');
|
|
15
|
+
}
|
|
16
|
+
return results;
|
|
17
|
+
}
|
|
18
|
+
function useCollapseText({ enable, boxRef, textRef, maxLine, placeholder = '...', before, after, }) {
|
|
19
|
+
const callbackRef = useRef({ before, after });
|
|
20
|
+
callbackRef.current = { before, after };
|
|
21
|
+
const [canCollapse, setCanCollapse] = useState(false);
|
|
22
|
+
const getLineHeight = useCallback((dom) => {
|
|
23
|
+
const lineHeight = getComputedStyle(dom).getPropertyValue('line-height');
|
|
24
|
+
if (lineHeight === 'normal') {
|
|
25
|
+
// 向容器里添加一段文本来测试行高
|
|
26
|
+
const span = document.createElement('span');
|
|
27
|
+
span.style.whiteSpace = 'nowrap';
|
|
28
|
+
span.innerText = 'test';
|
|
29
|
+
span.style.visibility = 'hidden';
|
|
30
|
+
dom.appendChild(span);
|
|
31
|
+
const height = span.offsetHeight;
|
|
32
|
+
dom.removeChild(span);
|
|
33
|
+
return height;
|
|
34
|
+
}
|
|
35
|
+
return parseFloat(lineHeight);
|
|
36
|
+
}, []);
|
|
37
|
+
const handleCollapseText = useCallback((box, text, maxLine) => {
|
|
38
|
+
var _a, _b, _c, _d;
|
|
39
|
+
// 计算思路,通过容器的实际高度 / 行高 来判断是否超出限制行数,然后多次通过二分法截断文本
|
|
40
|
+
const lineHeight = getLineHeight(text);
|
|
41
|
+
const maxHeight = maxLine * lineHeight;
|
|
42
|
+
const isOver = () => {
|
|
43
|
+
const height = box.offsetHeight;
|
|
44
|
+
const max = maxHeight + lineHeight - 1;
|
|
45
|
+
return height > max;
|
|
46
|
+
};
|
|
47
|
+
if (!isOver()) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const removeNodeAndTry = (node) => {
|
|
51
|
+
node.parentNode.removeChild(node);
|
|
52
|
+
return !isOver();
|
|
53
|
+
};
|
|
54
|
+
const sliceTextAndTry = (node) => {
|
|
55
|
+
const str = node.textContent;
|
|
56
|
+
if (!str) {
|
|
57
|
+
if (removeNodeAndTry(node)) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
let left = 0;
|
|
63
|
+
let right = str.length - 1;
|
|
64
|
+
while (left < right) {
|
|
65
|
+
const middle = Math.floor((left + right) / 2);
|
|
66
|
+
const temp1 = str.slice(0, middle) + placeholder;
|
|
67
|
+
node.textContent = temp1;
|
|
68
|
+
if (!isOver()) {
|
|
69
|
+
// 若已经到减去一个字符就满足,则中断
|
|
70
|
+
if (right - middle === 1) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
// 减半后高度小于最大高度,向后二分
|
|
74
|
+
left = middle;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// 减半后高度还是大于最大高度,则继续向前二分
|
|
78
|
+
right = middle;
|
|
79
|
+
}
|
|
80
|
+
if (left === right) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (removeNodeAndTry(node)) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
const loop = (childNodes) => {
|
|
91
|
+
const nodes = Array.from(childNodes);
|
|
92
|
+
for (let i = nodes.length - 1; i >= 0; i--) {
|
|
93
|
+
const node = nodes[i];
|
|
94
|
+
if (node.childNodes.length) {
|
|
95
|
+
loop(node.childNodes);
|
|
96
|
+
}
|
|
97
|
+
else if (sliceTextAndTry(node)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const isContinue = (_b = (_a = callbackRef.current).before) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
103
|
+
if (isContinue === false) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
loop(text.childNodes);
|
|
107
|
+
(_d = (_c = callbackRef.current).after) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
108
|
+
}, []);
|
|
109
|
+
useLayoutEffect(() => {
|
|
110
|
+
const box = boxRef.current;
|
|
111
|
+
const text = textRef.current;
|
|
112
|
+
if (!box || !text || typeof maxLine !== 'number' || maxLine <= 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const lineHeight = getLineHeight(text);
|
|
116
|
+
const newCanCollapse = box.offsetHeight > maxLine * lineHeight;
|
|
117
|
+
if (canCollapse !== newCanCollapse) {
|
|
118
|
+
setCanCollapse(newCanCollapse);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
useLayoutEffect(() => {
|
|
122
|
+
const box = boxRef.current;
|
|
123
|
+
const text = textRef.current;
|
|
124
|
+
if (!enable ||
|
|
125
|
+
!box ||
|
|
126
|
+
!text ||
|
|
127
|
+
typeof maxLine !== 'number' ||
|
|
128
|
+
maxLine <= 0 ||
|
|
129
|
+
!canCollapse) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
handleCollapseText(box, text, maxLine);
|
|
133
|
+
});
|
|
134
|
+
return canCollapse;
|
|
135
|
+
}
|
|
136
|
+
function useEnsureBoxFullLine({ enableRef, boxRef, modifierRef, before, after, }) {
|
|
137
|
+
const callbackRef = useRef({ before, after });
|
|
138
|
+
callbackRef.current = { before, after };
|
|
139
|
+
const ensureTriggerEnd = useCallback((box, modifier) => {
|
|
140
|
+
var _a, _b, _c, _d, _e, _f;
|
|
141
|
+
const blank = ' ';
|
|
142
|
+
const isEnd = () => {
|
|
143
|
+
const height = box.offsetHeight;
|
|
144
|
+
const text = document.createElement('span');
|
|
145
|
+
text.innerHTML = blank;
|
|
146
|
+
modifier.appendChild(text);
|
|
147
|
+
// 添加一个空格元素后,容器高度变化了则代表已经在行末
|
|
148
|
+
if (box.offsetHeight > height) {
|
|
149
|
+
modifier.removeChild(text);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
modifier.removeChild(text);
|
|
153
|
+
return false;
|
|
154
|
+
};
|
|
155
|
+
(_b = (_a = callbackRef.current).before) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
156
|
+
if (isEnd()) {
|
|
157
|
+
(_d = (_c = callbackRef.current).after) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const height = box.offsetHeight;
|
|
161
|
+
const text = document.createElement('span');
|
|
162
|
+
text.innerHTML = blank;
|
|
163
|
+
modifier.appendChild(text);
|
|
164
|
+
const MAX_TIMES = 9999;
|
|
165
|
+
let times = 0;
|
|
166
|
+
while (box.offsetHeight === height) {
|
|
167
|
+
text.innerHTML = `${text.innerHTML}${blank}`;
|
|
168
|
+
if (times++ >= MAX_TIMES) {
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
text.innerHTML = text.innerHTML.replace(new RegExp(`${blank}$`), '');
|
|
173
|
+
(_f = (_e = callbackRef.current).after) === null || _f === void 0 ? void 0 : _f.call(_e);
|
|
174
|
+
}, []);
|
|
175
|
+
useLayoutEffect(() => {
|
|
176
|
+
const enable = enableRef.current;
|
|
177
|
+
const box = boxRef.current;
|
|
178
|
+
const modifier = modifierRef.current;
|
|
179
|
+
if (!enable || !box || !modifier) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// 通过向 modifier 添加空格元素来保证 trigger 元素正好在行末
|
|
183
|
+
ensureTriggerEnd(box, modifier);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function useResize(domRef, onResize, shouldTriggerRef) {
|
|
187
|
+
const sizeRef = useRef();
|
|
188
|
+
const debounceOnResize = useDebounce(onResize, 50);
|
|
189
|
+
const observer = useMemo(() => {
|
|
190
|
+
return new ResizeObserver(() => {
|
|
191
|
+
const dom = domRef.current;
|
|
192
|
+
if (!dom || !shouldTriggerRef.current) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const { offsetWidth, offsetHeight } = dom;
|
|
196
|
+
const lastSize = sizeRef.current;
|
|
197
|
+
const newSize = { width: offsetWidth, height: offsetHeight };
|
|
198
|
+
if (!lastSize ||
|
|
199
|
+
newSize.width !== lastSize.width ||
|
|
200
|
+
newSize.height !== lastSize.height) {
|
|
201
|
+
debounceOnResize();
|
|
202
|
+
}
|
|
203
|
+
sizeRef.current = newSize;
|
|
204
|
+
});
|
|
205
|
+
}, []);
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
const dom = domRef.current;
|
|
208
|
+
if (!dom) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
observer.observe(dom);
|
|
212
|
+
return () => {
|
|
213
|
+
observer.unobserve(dom);
|
|
214
|
+
};
|
|
215
|
+
}, [domRef.current, observer]);
|
|
216
|
+
}
|
|
217
|
+
function TextComp(props) {
|
|
218
|
+
const { className, maxLine, renderTrigger, triggerType = 'click', locale, showTrigger = true, children, } = props;
|
|
219
|
+
const collapsable = typeof maxLine === 'number' && maxLine > 0;
|
|
220
|
+
const { collapseText = '收起', expandText = '展开' } = locale || {};
|
|
221
|
+
const prefix = PREFIX_DEFAULT;
|
|
222
|
+
const triggerTypes = normalizeTriggerType(triggerType);
|
|
223
|
+
const clickToTrigger = triggerTypes.includes('click');
|
|
224
|
+
const hoverToTrigger = triggerTypes.includes('hover');
|
|
225
|
+
const [value, onChange] = useControlable(props, {
|
|
226
|
+
valueName: 'visible',
|
|
227
|
+
changeName: 'onVisibleChange',
|
|
228
|
+
});
|
|
229
|
+
const shouldTriggerResizeRef = useRef(false);
|
|
230
|
+
const [, rerender] = useState({});
|
|
231
|
+
const boxRef = useRef(null);
|
|
232
|
+
const textRef = useRef(null);
|
|
233
|
+
const triggerRef = useRef(null);
|
|
234
|
+
const canCollapse = useCollapseText({
|
|
235
|
+
boxRef,
|
|
236
|
+
textRef,
|
|
237
|
+
maxLine,
|
|
238
|
+
enable: !value && collapsable,
|
|
239
|
+
before() {
|
|
240
|
+
shouldTriggerResizeRef.current = false;
|
|
241
|
+
},
|
|
242
|
+
after() {
|
|
243
|
+
shouldTriggerResizeRef.current = true;
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
useEnsureBoxFullLine({
|
|
247
|
+
enableRef: triggerRef,
|
|
248
|
+
boxRef,
|
|
249
|
+
modifierRef: textRef,
|
|
250
|
+
before() {
|
|
251
|
+
shouldTriggerResizeRef.current = false;
|
|
252
|
+
},
|
|
253
|
+
after() {
|
|
254
|
+
shouldTriggerResizeRef.current = true;
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
useResize(boxRef, () => {
|
|
258
|
+
rerender({});
|
|
259
|
+
}, shouldTriggerResizeRef);
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
shouldTriggerResizeRef.current = true;
|
|
262
|
+
}, []);
|
|
263
|
+
const render = renderTrigger ||
|
|
264
|
+
((visible, onVisibleChange) => {
|
|
265
|
+
return (React.createElement(Button, { text: true, className: `${prefix}text-trigger-btn`, component: "a", type: "primary", onClick: () => {
|
|
266
|
+
onVisibleChange(!visible);
|
|
267
|
+
} }, visible ? collapseText : expandText));
|
|
268
|
+
});
|
|
269
|
+
const triggerByContent = (newValue = value) => {
|
|
270
|
+
if (!collapsable) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
onChange(newValue !== null && newValue !== void 0 ? newValue : !value, 'content');
|
|
274
|
+
};
|
|
275
|
+
const debounceTriggerByContent = useDebounce(triggerByContent, 100);
|
|
276
|
+
return (React.createElement("div", { className: cs(`${prefix}text`, className), ref: boxRef },
|
|
277
|
+
React.createElement("span", { ref: textRef, className: `${prefix}text-inner`, role: "textbox", tabIndex: 0, key: Math.random(), onKeyUp: e => {
|
|
278
|
+
if (!clickToTrigger || e.key !== 'Enter') {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
triggerByContent();
|
|
282
|
+
}, onClick: () => {
|
|
283
|
+
if (!clickToTrigger) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
triggerByContent();
|
|
287
|
+
}, onMouseEnter: () => {
|
|
288
|
+
if (!hoverToTrigger) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
debounceTriggerByContent(true);
|
|
292
|
+
}, onMouseLeave: () => {
|
|
293
|
+
if (!hoverToTrigger) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
debounceTriggerByContent(false);
|
|
297
|
+
} }, children),
|
|
298
|
+
showTrigger && canCollapse && collapsable && (React.createElement("span", { className: `${prefix}text-trigger`, ref: triggerRef }, render(value, v => onChange(v, 'trigger'))))));
|
|
299
|
+
}
|
|
300
|
+
TextComp.displayName = 'Text';
|
|
301
|
+
export default ConfigProvider.config(TextComp);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
@import '../core/variables.scss';
|
|
2
|
+
|
|
3
|
+
.#{$prefix}text {
|
|
4
|
+
display: inline-block;
|
|
5
|
+
|
|
6
|
+
&-inner {
|
|
7
|
+
}
|
|
8
|
+
&-trigger {
|
|
9
|
+
line-height: 1;
|
|
10
|
+
|
|
11
|
+
& &-btn {
|
|
12
|
+
font-size: inherit;
|
|
13
|
+
line-height: inherit;
|
|
14
|
+
height: auto;
|
|
15
|
+
vertical-align: baseline;
|
|
16
|
+
margin-left: 12px;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './main.scss';
|
package/es/text/style.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './main.scss';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactElement, ReactNode } from 'react';
|
|
2
|
+
export type HTMLAttributesWeak = Omit<HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
3
|
+
export type TriggerType = 'click' | 'hover';
|
|
4
|
+
export interface TextProps extends HTMLAttributesWeak {
|
|
5
|
+
maxLine?: number;
|
|
6
|
+
visible?: boolean;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
onVisibleChange?: (visible: boolean, type: string) => void;
|
|
9
|
+
triggerType?: TriggerType | Array<TriggerType>;
|
|
10
|
+
showTrigger?: boolean;
|
|
11
|
+
renderTrigger?: (visible: boolean, onVisibleChange: (visible: boolean) => void) => ReactElement | string;
|
|
12
|
+
locale?: {
|
|
13
|
+
expandText?: string;
|
|
14
|
+
collapseText?: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
package/es/text/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PREFIX_DEFAULT = "ct-";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PREFIX_DEFAULT = 'ct-';
|
|
@@ -3,4 +3,4 @@ export interface ControlableOptions {
|
|
|
3
3
|
defaultValueName?: string;
|
|
4
4
|
changeName?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function useControlable<Value = unknown, OnChange extends (nextValue: Value, ...rest: unknown[]) => unknown = (nextValue: Value, ...rest: unknown[]) => unknown>(props:
|
|
6
|
+
export declare function useControlable<Value = unknown, OnChange extends (nextValue: Value, ...rest: unknown[]) => unknown = (nextValue: Value, ...rest: unknown[]) => unknown>(props: object, { valueName, defaultValueName, changeName, }?: ControlableOptions): readonly [Value, OnChange];
|
|
@@ -6,9 +6,10 @@ function getDefaultValueName(valueName) {
|
|
|
6
6
|
return `default${upperFirst(valueName)}`;
|
|
7
7
|
}
|
|
8
8
|
export function useControlable(props, { valueName = 'value', defaultValueName = getDefaultValueName(valueName), changeName = 'onChange', } = {}) {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const typedProps = props;
|
|
10
|
+
const isControl = valueName in typedProps;
|
|
11
|
+
const propValue = (isControl ? typedProps[valueName] : typedProps[defaultValueName]);
|
|
12
|
+
const propOnChange = typedProps[changeName];
|
|
12
13
|
const [value, setValue] = useState(() => propValue);
|
|
13
14
|
const handleChange = (nextValue, ...rest) => {
|
|
14
15
|
if (!isControl) {
|
package/es/utils/index.d.ts
CHANGED
package/es/utils/index.js
CHANGED
package/lib/button/index.d.ts
CHANGED
|
@@ -1 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @component 按钮
|
|
3
|
+
* @en Button
|
|
4
|
+
* @type 通用 - General
|
|
5
|
+
* @remarks 同 Next Button,按钮用于开始一个即时操作。- Same as Next.Button, Button used to trigger an action.
|
|
6
|
+
* @when 标记一个(或封装一组)操作命令,响应用户点击行为,触发相应的业务逻辑。- Buttons are used for emphasizing important functions on your page.
|
|
7
|
+
* @others
|
|
8
|
+
* ## 无障碍键盘操作指南
|
|
9
|
+
* | 按键 | 说明 |
|
|
10
|
+
* | :---- | :---------- |
|
|
11
|
+
* | Enter | 触发 onClick 事件 |
|
|
12
|
+
* | SPACE | 触发 onClick 事件 |
|
|
13
|
+
* @othersEn
|
|
14
|
+
* ## ARIA and KeyBoard
|
|
15
|
+
* | KeyBoard | Description |
|
|
16
|
+
* | :---------- | :------------------------------ |
|
|
17
|
+
* | Enter | Trigger the onClick event |
|
|
18
|
+
* | SPACE | Trigger the onClick event |
|
|
19
|
+
*/
|
|
20
|
+
import React from 'react';
|
|
21
|
+
import type { ButtonProps } from './types';
|
|
22
|
+
export * from './types';
|
|
23
|
+
declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<ButtonProps & React.RefAttributes<import("@alifd/next/types/config-provider/types").ConfiguredComponent<import("@alifd/next/types/button").ButtonProps & import("@alifd/next/types/config-provider/types").ComponentCommonProps, import("@alifd/next/types/button/view/button").default>>, keyof ButtonProps | "key"> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, import("@alifd/next/types/config-provider/types").ConfiguredComponent<import("@alifd/next/types/button").ButtonProps & import("@alifd/next/types/config-provider/types").ComponentCommonProps, import("@alifd/next/types/button/view/button").default>, {}>;
|
|
24
|
+
export default _default;
|
package/lib/button/index.js
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @component 按钮
|
|
4
|
+
* @en Button
|
|
5
|
+
* @type 通用 - General
|
|
6
|
+
* @remarks 同 Next Button,按钮用于开始一个即时操作。- Same as Next.Button, Button used to trigger an action.
|
|
7
|
+
* @when 标记一个(或封装一组)操作命令,响应用户点击行为,触发相应的业务逻辑。- Buttons are used for emphasizing important functions on your page.
|
|
8
|
+
* @others
|
|
9
|
+
* ## 无障碍键盘操作指南
|
|
10
|
+
* | 按键 | 说明 |
|
|
11
|
+
* | :---- | :---------- |
|
|
12
|
+
* | Enter | 触发 onClick 事件 |
|
|
13
|
+
* | SPACE | 触发 onClick 事件 |
|
|
14
|
+
* @othersEn
|
|
15
|
+
* ## ARIA and KeyBoard
|
|
16
|
+
* | KeyBoard | Description |
|
|
17
|
+
* | :---------- | :------------------------------ |
|
|
18
|
+
* | Enter | Trigger the onClick event |
|
|
19
|
+
* | SPACE | Trigger the onClick event |
|
|
20
|
+
*/
|
|
5
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
22
|
+
const tslib_1 = require("tslib");
|
|
23
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
24
|
+
const next_1 = require("@alifd/next");
|
|
25
|
+
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
26
|
+
const utils_1 = require("../utils");
|
|
27
|
+
const Button = (0, react_1.forwardRef)((_a, ref) => {
|
|
28
|
+
var { className, size = 'small' } = _a, props = tslib_1.__rest(_a, ["className", "size"]);
|
|
29
|
+
return (react_1.default.createElement(next_1.Button, Object.assign({}, props, { className: (0, classnames_1.default)(`${utils_1.PREFIX_DEFAULT}button`, className), size: size, ref: ref })));
|
|
30
|
+
});
|
|
31
|
+
const ButtonWithSub = (0, utils_1.assignSubComponent)(Button, {
|
|
32
|
+
displayName: 'Button',
|
|
33
|
+
});
|
|
34
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
35
|
+
exports.default = next_1.ConfigProvider.config(ButtonWithSub);
|
package/lib/button/main.scss
CHANGED
package/lib/button/style.d.ts
CHANGED
package/lib/button/style.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import Collapsable from './view/collapsable';
|
|
2
|
+
declare const CardWithSub: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<import("./types").CardProps & import("@alifd/next/types/config-provider/types").ComponentCommonProps, undefined, {}> & {
|
|
3
|
+
Collapsable: typeof Collapsable;
|
|
4
|
+
};
|
|
5
|
+
export * from './types';
|
|
6
|
+
export default CardWithSub;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const card_1 = tslib_1.__importDefault(require("./view/card"));
|
|
6
|
+
const collapsable_1 = tslib_1.__importDefault(require("./view/collapsable"));
|
|
7
|
+
const CardWithSub = (0, utils_1.assignSubComponent)(card_1.default, { Collapsable: collapsable_1.default });
|
|
8
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
9
|
+
exports.default = CardWithSub;
|