@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
|
@@ -4,9 +4,9 @@ import { useThrottle } from '../../utils';
|
|
|
4
4
|
/**
|
|
5
5
|
* 自动调整弹层 align 位置逻辑
|
|
6
6
|
*/
|
|
7
|
-
export function useAutoAlign(
|
|
7
|
+
export function useAutoAlign(_dom, trigger, { enable, defaultAlign, }) {
|
|
8
8
|
const [align, setAlign] = useState(defaultAlign);
|
|
9
|
-
const update = () => {
|
|
9
|
+
const update = (dom = _dom) => {
|
|
10
10
|
if (!enable || !dom || !trigger) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
|
+
import type { FloatButtonProps } from '../types';
|
|
3
|
+
export declare function useTriggerType({ triggerType, visible, onVisibleChange, }: Pick<FloatButtonProps, 'triggerType' | 'visible' | 'onVisibleChange'>): Pick<HTMLAttributes<HTMLElement>, "onClick" | "onMouseEnter" | "onMouseLeave">;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useDebounce } from '../../utils';
|
|
2
|
+
function normalizeTriggerType(triggerType, defaultTriggerType) {
|
|
3
|
+
if (!triggerType) {
|
|
4
|
+
return defaultTriggerType;
|
|
5
|
+
}
|
|
6
|
+
const arr = Array.isArray(triggerType) ? triggerType : [triggerType];
|
|
7
|
+
return Array.from(new Set(arr));
|
|
8
|
+
}
|
|
9
|
+
export function useTriggerType({ triggerType, visible, onVisibleChange, }) {
|
|
10
|
+
const normalTriggerTypes = normalizeTriggerType(triggerType, ['click']);
|
|
11
|
+
const allowClick = normalTriggerTypes.includes('click');
|
|
12
|
+
const allowHover = normalTriggerTypes.includes('hover');
|
|
13
|
+
const triggerHandlerProps = {};
|
|
14
|
+
const debounceOnVisibleChange = useDebounce((v, type) => {
|
|
15
|
+
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(v, type);
|
|
16
|
+
}, 150);
|
|
17
|
+
if (allowClick) {
|
|
18
|
+
triggerHandlerProps.onClick = () => {
|
|
19
|
+
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(!visible, 'fromeTrigger');
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (allowHover) {
|
|
23
|
+
triggerHandlerProps.onMouseEnter = () => {
|
|
24
|
+
debounceOnVisibleChange(true, 'fromTrigger');
|
|
25
|
+
};
|
|
26
|
+
triggerHandlerProps.onMouseLeave = () => {
|
|
27
|
+
debounceOnVisibleChange(false, 'fromTrigger');
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return triggerHandlerProps;
|
|
31
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
declare const FloatButtonWithSub: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<import("./types").FloatButtonProps & import("react").RefAttributes<import("./types").FloatButtonRef>, keyof import("./types").FloatButtonProps
|
|
2
|
+
declare const FloatButtonWithSub: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<import("./types").FloatButtonProps & import("react").RefAttributes<import("./types").FloatButtonRef>, "key" | keyof import("./types").FloatButtonProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, import("./types").FloatButtonRef, {}> & {
|
|
3
3
|
Backtop: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<import("./types").BacktopProps & import("react").RefAttributes<import("./types").BacktopRef>, "key" | keyof import("./types").BacktopProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, import("./types").BacktopRef, {}>;
|
|
4
|
+
InnerDrawer: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<import("./types").FloatButtonInnerDrawerProps & import("@alifd/next/types/config-provider/types").ComponentCommonProps, undefined, {}>;
|
|
4
5
|
};
|
|
5
|
-
export type { BacktopRef, BacktopProps, FloatButtonRef, FloatButtonProps } from './types';
|
|
6
|
+
export type { BacktopRef, BacktopProps, FloatButtonRef, FloatButtonProps, FloatButtonInnerDrawerProps, DragableOption, Edge, Margin, Position, RequiredParts, ScreenRatioPosition, Size, TriggerType, } from './types';
|
|
6
7
|
export default FloatButtonWithSub;
|
package/es/float-button/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import FloatButton from './view/float-button';
|
|
2
2
|
import Backtop from './view/backtop';
|
|
3
|
+
import InnerDrawer from './view/inner-drawer';
|
|
3
4
|
import { assignSubComponent } from '../utils/index';
|
|
4
|
-
const FloatButtonWithSub = assignSubComponent(FloatButton, { Backtop });
|
|
5
|
+
const FloatButtonWithSub = assignSubComponent(FloatButton, { Backtop, InnerDrawer });
|
|
5
6
|
export default FloatButtonWithSub;
|
|
@@ -1,16 +1,79 @@
|
|
|
1
|
-
@import '
|
|
1
|
+
@import '../core/variables.scss';
|
|
2
2
|
|
|
3
|
-
.#{$
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
.#{$prefix}float-button {
|
|
4
|
+
position: fixed;
|
|
5
|
+
z-index: 1001;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
&-backtop {
|
|
8
|
+
transition:
|
|
9
|
+
opacity 0.2s,
|
|
10
|
+
transform 0.2s;
|
|
11
|
+
cursor: pointer;
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
&--hidden {
|
|
14
|
+
opacity: 0;
|
|
15
|
+
transform: scale(0);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&-inner-drawer {
|
|
20
|
+
flex: 1;
|
|
21
|
+
display: flex;
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
display: flex;
|
|
24
|
+
box-shadow: $shadow-2;
|
|
25
|
+
border-radius: $size-base * 2;
|
|
26
|
+
|
|
27
|
+
&-outer {
|
|
28
|
+
display: flex;
|
|
29
|
+
}
|
|
30
|
+
&-inner-start {
|
|
31
|
+
flex: 1;
|
|
32
|
+
}
|
|
33
|
+
&-inner-end {
|
|
34
|
+
flex: none;
|
|
35
|
+
transition:
|
|
36
|
+
width 0.3s,
|
|
37
|
+
opacity 0.3s;
|
|
38
|
+
display: flex;
|
|
39
|
+
}
|
|
40
|
+
&-inner {
|
|
41
|
+
flex: 1;
|
|
42
|
+
display: flex;
|
|
43
|
+
flex-direction: column;
|
|
44
|
+
}
|
|
45
|
+
&-header {
|
|
46
|
+
flex: none;
|
|
47
|
+
display: flex;
|
|
48
|
+
justify-content: end;
|
|
49
|
+
padding: $size-base * 2 $size-base * 3;
|
|
50
|
+
&-title {
|
|
51
|
+
flex: 1;
|
|
52
|
+
font-size: $font-size-subhead;
|
|
53
|
+
line-height: 1.5;
|
|
54
|
+
}
|
|
55
|
+
&-close {
|
|
56
|
+
flex: none;
|
|
57
|
+
color: $color-text1-2;
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
transition: color 0.15s;
|
|
60
|
+
outline: 0;
|
|
61
|
+
border: 0;
|
|
62
|
+
padding: 0;
|
|
63
|
+
align-self: flex-start;
|
|
64
|
+
background-color: transparent;
|
|
65
|
+
|
|
66
|
+
&:hover {
|
|
67
|
+
color: $color-brand1-6;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
&-body {
|
|
72
|
+
flex: 1;
|
|
73
|
+
padding: 0 $size-base * 3 $size-base * 2;
|
|
74
|
+
}
|
|
75
|
+
&-footer {
|
|
76
|
+
flex: none;
|
|
77
|
+
}
|
|
14
78
|
}
|
|
15
|
-
}
|
|
16
79
|
}
|
package/es/float-button/style.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
2
|
import { type CommonProps } from '@alifd/next';
|
|
3
3
|
import { type BalloonProps } from '@alifd/next/lib/balloon';
|
|
4
4
|
export type { BalloonProps };
|
|
@@ -100,6 +100,8 @@ export interface FloatButtonRef {
|
|
|
100
100
|
*/
|
|
101
101
|
updateNestleEdge(animation?: boolean): void;
|
|
102
102
|
}
|
|
103
|
+
export type TriggerType = 'hover' | 'click';
|
|
104
|
+
export type RequiredParts<O, K extends keyof O> = Omit<O, K> & Required<Pick<O, K>>;
|
|
103
105
|
/**
|
|
104
106
|
* @api FloatButton
|
|
105
107
|
* @order 1
|
|
@@ -116,6 +118,11 @@ export interface FloatButtonProps extends CommonProps {
|
|
|
116
118
|
* - `inner-drawer`: 文档内部抽屉
|
|
117
119
|
*/
|
|
118
120
|
type?: 'balloon' | 'drawer' | 'inner-drawer';
|
|
121
|
+
drawerProps?: {
|
|
122
|
+
title?: ReactNode;
|
|
123
|
+
width?: number | string;
|
|
124
|
+
target: string | (() => HTMLElement);
|
|
125
|
+
};
|
|
119
126
|
/**
|
|
120
127
|
* 弹层位置,适用 `type`: 'balloon'
|
|
121
128
|
*/
|
|
@@ -196,7 +203,7 @@ export interface FloatButtonProps extends CommonProps {
|
|
|
196
203
|
* 触发方式
|
|
197
204
|
* @defaultValue 'click'
|
|
198
205
|
*/
|
|
199
|
-
triggerType?:
|
|
206
|
+
triggerType?: TriggerType | TriggerType[];
|
|
200
207
|
/**
|
|
201
208
|
* 展示关闭按钮
|
|
202
209
|
* @defaultValue false
|
|
@@ -210,6 +217,7 @@ export interface FloatButtonProps extends CommonProps {
|
|
|
210
217
|
* 弹层内容
|
|
211
218
|
*/
|
|
212
219
|
children?: React.ReactNode;
|
|
220
|
+
_renderView?: (prefix: string, props: RequiredParts<FloatButtonProps, 'visible' | 'onVisibleChange'>) => ReactNode;
|
|
213
221
|
}
|
|
214
222
|
/**
|
|
215
223
|
* @api
|
|
@@ -223,3 +231,11 @@ export interface DragableOption {
|
|
|
223
231
|
onDraging?: (dom: HTMLElement, event: MouseEvent) => void | false;
|
|
224
232
|
onDragend?: (dom: HTMLElement) => void;
|
|
225
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* @api FloatButton.InnerDrawer
|
|
236
|
+
*/
|
|
237
|
+
export interface FloatButtonInnerDrawerProps extends FloatButtonProps {
|
|
238
|
+
width?: string | number;
|
|
239
|
+
target: string | (() => HTMLElement);
|
|
240
|
+
title?: ReactNode;
|
|
241
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
2
2
|
import { ConfigProvider } from '@alifd/next';
|
|
3
3
|
import cs from 'classnames';
|
|
4
|
-
import { debounce } from '../../utils';
|
|
4
|
+
import { PREFIX_DEFAULT, debounce } from '../../utils';
|
|
5
5
|
function getScroller(scroller) {
|
|
6
6
|
if (!scroller) {
|
|
7
7
|
return window;
|
|
@@ -11,9 +11,9 @@ function getScroller(scroller) {
|
|
|
11
11
|
}
|
|
12
12
|
return scroller;
|
|
13
13
|
}
|
|
14
|
-
const Backtop = forwardRef(({
|
|
14
|
+
const Backtop = forwardRef(({ autoHide = true, scroller, offset = 10, smooth = true, children }, ref) => {
|
|
15
15
|
const [visible, setVisible] = useState(true);
|
|
16
|
-
const cls = `${
|
|
16
|
+
const cls = `${PREFIX_DEFAULT}float-button-backtop`;
|
|
17
17
|
const visibleRef = useRef(visible);
|
|
18
18
|
visibleRef.current = visible;
|
|
19
19
|
const handleBackToTop = () => {
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
import type { DrawerProps as NextDrawerProps } from '@alifd/next/types/drawer';
|
|
3
|
+
import type { TriggerType } from '../types';
|
|
4
|
+
export interface DrawerProps extends Omit<NextDrawerProps, 'triggerType' | 'container' | 'onVisibleChange'> {
|
|
5
|
+
onVisibleChange?: (visible: boolean, reason: string) => void;
|
|
6
|
+
triggerType?: TriggerType | TriggerType[];
|
|
7
|
+
}
|
|
8
|
+
export declare function Drawer({ prefix, target, children, trigger, triggerType, visible, onVisibleChange, ...rests }: DrawerProps): React.JSX.Element;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
1
2
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
import { Drawer as NextDrawer } from '@alifd/next';
|
|
4
|
+
import { useTriggerType } from '../hooks/useTriggerType';
|
|
5
|
+
export function Drawer(_a) {
|
|
6
|
+
var { prefix, target, children, trigger, triggerType, visible, onVisibleChange } = _a, rests = __rest(_a, ["prefix", "target", "children", "trigger", "triggerType", "visible", "onVisibleChange"]);
|
|
7
|
+
const handlers = useTriggerType({ visible, onVisibleChange, triggerType });
|
|
8
|
+
return (React.createElement(React.Fragment, null,
|
|
9
|
+
React.createElement("div", Object.assign({}, handlers), trigger),
|
|
10
|
+
React.createElement(NextDrawer, Object.assign({}, rests, { visible: visible, onClose: reason => {
|
|
11
|
+
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(false, reason);
|
|
12
|
+
}, v2: true }), children)));
|
|
4
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { FloatButtonProps, FloatButtonRef } from '../types';
|
|
3
|
-
declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<FloatButtonProps & React.RefAttributes<FloatButtonRef>, keyof FloatButtonProps
|
|
3
|
+
declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<FloatButtonProps & React.RefAttributes<FloatButtonRef>, "key" | keyof FloatButtonProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, FloatButtonRef, {}>;
|
|
4
4
|
export default _default;
|
|
@@ -1,20 +1,40 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
2
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from 'react';
|
|
3
3
|
import cs from 'classnames';
|
|
4
4
|
import { Balloon, ConfigProvider } from '@alifd/next';
|
|
5
|
-
import { useControlable } from '../../utils/index';
|
|
5
|
+
import { PREFIX_DEFAULT, useControlable } from '../../utils/index';
|
|
6
6
|
import { useAutoHide } from '../hooks/useAutoHide';
|
|
7
7
|
import { useAutoAlign } from '../hooks/useAutoAlign';
|
|
8
8
|
import { useNestleEdge } from '../hooks/useNestleEdge';
|
|
9
9
|
import { useDragable } from '../hooks/useDragable';
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// import { InnerDrawer } from './inner-drawer';
|
|
11
|
+
/**
|
|
12
|
+
* @component 悬浮球
|
|
13
|
+
* @en FloatButton
|
|
14
|
+
* @type 通用 - General
|
|
15
|
+
* @remarks 悬浮球组件用于承载机器人入口。- Apply for entry for web bot.
|
|
16
|
+
* @when 机器人入口 - The entry of robot
|
|
17
|
+
* @others
|
|
18
|
+
* ## 无障碍键盘操作指南
|
|
19
|
+
* | 按键 | 说明 |
|
|
20
|
+
* | :---- | :---------- |
|
|
21
|
+
* | Enter | 触发 onClick 事件 |
|
|
22
|
+
* | SPACE | 触发 onClick 事件 |
|
|
23
|
+
* @othersEn
|
|
24
|
+
* ## ARIA and KeyBoard
|
|
25
|
+
* | KeyBoard | Description |
|
|
26
|
+
* | :---------- | :------------------------------ |
|
|
27
|
+
* | Enter | Trigger the onClick event |
|
|
28
|
+
* | SPACE | Trigger the onClick event |
|
|
29
|
+
*/
|
|
30
|
+
const FloatButton = forwardRef((props, ref) => {
|
|
31
|
+
const { className, style, type = 'balloon', addonAfter, addonBefore, dragable, safeAreaMargin = [10, 10, 10, 10], autoNestleEdge = true, interactiveEdges = ['left', 'right'], autoHide, autoAlign, leftSizeOfHidden, defaultPosition, trigger, triggerType = 'click', showClose = true, align, balloonProps, drawerProps, children, _renderView } = props, others = __rest(props, ["className", "style", "type", "addonAfter", "addonBefore", "dragable", "safeAreaMargin", "autoNestleEdge", "interactiveEdges", "autoHide", "autoAlign", "leftSizeOfHidden", "defaultPosition", "trigger", "triggerType", "showClose", "align", "balloonProps", "drawerProps", "children", "_renderView"]);
|
|
12
32
|
const elRef = useRef(null);
|
|
13
33
|
const triggerRef = useRef(null);
|
|
14
34
|
const [el, setEl] = useState(null);
|
|
15
35
|
const [triggerEl, setTriggerEl] = useState(null);
|
|
16
36
|
const draggedRef = useRef(false);
|
|
17
|
-
const cls = `${
|
|
37
|
+
const cls = `${PREFIX_DEFAULT}float-button`;
|
|
18
38
|
const [visible, onVisibleChange] = useControlable(others, {
|
|
19
39
|
valueName: 'visible',
|
|
20
40
|
changeName: 'onVisibleChange',
|
|
@@ -23,10 +43,13 @@ const FloatButton = forwardRef((_a, ref) => {
|
|
|
23
43
|
setEl(elRef.current);
|
|
24
44
|
setTriggerEl(triggerRef.current);
|
|
25
45
|
}, []);
|
|
26
|
-
const { align: currentAlign, update:
|
|
46
|
+
const { align: currentAlign, update: _updateAlign } = useAutoAlign(el === null || el === void 0 ? void 0 : el.querySelector(`.${cls}-popup`), triggerEl, {
|
|
27
47
|
enable: type === 'balloon' && autoAlign,
|
|
28
48
|
defaultAlign: align,
|
|
29
49
|
});
|
|
50
|
+
const updateAlign = () => {
|
|
51
|
+
_updateAlign(el === null || el === void 0 ? void 0 : el.querySelector(`.${cls}-popup`));
|
|
52
|
+
};
|
|
30
53
|
const { isHideRef, setHide, handleMove, saveRestorePosition } = useAutoHide(el, {
|
|
31
54
|
enable: !visible && autoHide,
|
|
32
55
|
interactiveEdges,
|
|
@@ -35,7 +58,6 @@ const FloatButton = forwardRef((_a, ref) => {
|
|
|
35
58
|
useEffect(() => {
|
|
36
59
|
if (visible) {
|
|
37
60
|
setHide(false);
|
|
38
|
-
updateAlign();
|
|
39
61
|
}
|
|
40
62
|
}, [visible]);
|
|
41
63
|
const { update: updateNestleEdge } = useNestleEdge(el, {
|
|
@@ -48,6 +70,9 @@ const FloatButton = forwardRef((_a, ref) => {
|
|
|
48
70
|
return false;
|
|
49
71
|
}
|
|
50
72
|
},
|
|
73
|
+
onUpdateEnd() {
|
|
74
|
+
updateAlign();
|
|
75
|
+
},
|
|
51
76
|
});
|
|
52
77
|
useImperativeHandle(ref, () => ({
|
|
53
78
|
setVisible(value) {
|
|
@@ -81,32 +106,50 @@ const FloatButton = forwardRef((_a, ref) => {
|
|
|
81
106
|
},
|
|
82
107
|
});
|
|
83
108
|
const classNames = cs(cls, className, dragClassName);
|
|
109
|
+
const handleVisibleChange = (v, type) => {
|
|
110
|
+
if (draggedRef.current) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
onVisibleChange(v, type);
|
|
114
|
+
};
|
|
84
115
|
const renderBalloon = () => {
|
|
85
|
-
return (React.createElement(Balloon, Object.assign({ visible: visible, onVisibleChange:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
116
|
+
return (React.createElement(Balloon, Object.assign({ visible: visible, onVisibleChange: handleVisibleChange, popupProps: {
|
|
117
|
+
afterOpen() {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
updateAlign();
|
|
120
|
+
(_b = (_a = balloonProps === null || balloonProps === void 0 ? void 0 : balloonProps.popupProps) === null || _a === void 0 ? void 0 : _a.afterClose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
121
|
+
},
|
|
90
122
|
}, popupClassName: `${cls}-popup`, trigger: trigger, popupContainer: () => el, triggerType: triggerType, align: currentAlign, v2: true, closable: showClose, autoAdjust: false }, balloonProps), children));
|
|
91
123
|
};
|
|
92
|
-
const renderDrawer = () => {
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
const renderInnerDrawer = () => {
|
|
96
|
-
|
|
97
|
-
|
|
124
|
+
// const renderDrawer = () => {
|
|
125
|
+
// return <div></div>;
|
|
126
|
+
// };
|
|
127
|
+
// const renderInnerDrawer = () => {
|
|
128
|
+
// return (
|
|
129
|
+
// <InnerDrawer
|
|
130
|
+
// {...drawerProps}
|
|
131
|
+
// prefix={`${cls}-`}
|
|
132
|
+
// target=".card-legal-affairs"
|
|
133
|
+
// trigger={trigger}
|
|
134
|
+
// triggerType={triggerType}
|
|
135
|
+
// visible={visible}
|
|
136
|
+
// closable={showClose}
|
|
137
|
+
// onVisibleChange={(...args) => {
|
|
138
|
+
// if (draggedRef.current) {
|
|
139
|
+
// return;
|
|
140
|
+
// }
|
|
141
|
+
// onVisibleChange?.(...args);
|
|
142
|
+
// }}
|
|
143
|
+
// >
|
|
144
|
+
// {children}
|
|
145
|
+
// </InnerDrawer>
|
|
146
|
+
// );
|
|
147
|
+
// };
|
|
98
148
|
const renderView = () => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return renderDrawer();
|
|
102
|
-
}
|
|
103
|
-
case 'inner-drawer': {
|
|
104
|
-
return renderInnerDrawer();
|
|
105
|
-
}
|
|
106
|
-
default: {
|
|
107
|
-
return renderBalloon();
|
|
108
|
-
}
|
|
149
|
+
if (typeof _renderView === 'function') {
|
|
150
|
+
return _renderView(`${cls}-`, Object.assign(Object.assign({}, props), { visible, onVisibleChange: handleVisibleChange }));
|
|
109
151
|
}
|
|
152
|
+
return renderBalloon();
|
|
110
153
|
};
|
|
111
154
|
return (React.createElement("div", { className: classNames, style: Object.assign(Object.assign({}, style), dragStyle), ref: elRef },
|
|
112
155
|
!!addonBefore && (React.createElement("div", { className: cs(`${cls}-addon`, `${cls}-addon--before`) }, addonBefore)),
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import type { FloatButtonInnerDrawerProps, FloatButtonProps } from '../types';
|
|
3
|
+
export interface InnerDrawerProps {
|
|
4
|
+
className?: string;
|
|
5
|
+
title?: ReactNode;
|
|
6
|
+
prefix: string;
|
|
7
|
+
target: string | (() => HTMLElement);
|
|
8
|
+
visible?: boolean;
|
|
9
|
+
onVisibleChange?: (visible: boolean, reason: string) => void;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
trigger: ReactNode;
|
|
12
|
+
closable?: boolean;
|
|
13
|
+
triggerType: FloatButtonProps['triggerType'];
|
|
14
|
+
width?: string | number;
|
|
15
|
+
}
|
|
16
|
+
export declare function InnerDrawer({ className, prefix, target, children, trigger, triggerType, visible, onVisibleChange, closable, title, width, }: InnerDrawerProps): React.JSX.Element;
|
|
17
|
+
declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<FloatButtonInnerDrawerProps & import("@alifd/next/types/config-provider/types").ComponentCommonProps, undefined, {}>;
|
|
18
|
+
export default _default;
|
|
@@ -1,4 +1,115 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React, { useRef, useLayoutEffect, useEffect, useState } from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom';
|
|
4
|
+
import cs from 'classnames';
|
|
5
|
+
import { Icon, ConfigProvider } from '@alifd/next';
|
|
6
|
+
import { useTriggerType } from '../hooks/useTriggerType';
|
|
7
|
+
import FloatButton from './float-button';
|
|
8
|
+
function getTarget(target) {
|
|
9
|
+
if (typeof target === 'string') {
|
|
10
|
+
return document.querySelector(target);
|
|
11
|
+
}
|
|
12
|
+
return target();
|
|
4
13
|
}
|
|
14
|
+
function getMountTarget(prefix, target) {
|
|
15
|
+
const dom = getTarget(target);
|
|
16
|
+
let parent = dom === null || dom === void 0 ? void 0 : dom.parentElement;
|
|
17
|
+
if (!dom || !parent) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
if (!parent.dataset.chat) {
|
|
21
|
+
const oldParent = parent;
|
|
22
|
+
parent = document.createElement('div');
|
|
23
|
+
parent.classList.add(`${prefix}outer`);
|
|
24
|
+
parent.dataset.chat = 'drawer';
|
|
25
|
+
oldParent.appendChild(parent);
|
|
26
|
+
parent.appendChild(dom);
|
|
27
|
+
}
|
|
28
|
+
let mountTarget = parent.childNodes[1];
|
|
29
|
+
if (!mountTarget) {
|
|
30
|
+
mountTarget = document.createElement('div');
|
|
31
|
+
mountTarget.dataset.chat = 'drawer-mounted';
|
|
32
|
+
mountTarget.classList.add(`${prefix}inner-end`);
|
|
33
|
+
mountTarget.style.width = '0px';
|
|
34
|
+
mountTarget.style.opacity = '0';
|
|
35
|
+
parent.appendChild(mountTarget);
|
|
36
|
+
}
|
|
37
|
+
dom.classList.add(`${prefix}inner-start`);
|
|
38
|
+
return mountTarget;
|
|
39
|
+
}
|
|
40
|
+
export function InnerDrawer({ className, prefix, target, children, trigger, triggerType, visible, onVisibleChange, closable = true, title, width = 400, }) {
|
|
41
|
+
const [mount, setMount] = useState(!!visible);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (visible) {
|
|
44
|
+
setMount(visible);
|
|
45
|
+
}
|
|
46
|
+
}, [visible]);
|
|
47
|
+
const cls = `${prefix}inner-drawer`;
|
|
48
|
+
const handleVisibleChange = (nextVisible, type) => {
|
|
49
|
+
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(nextVisible, type);
|
|
50
|
+
};
|
|
51
|
+
const handleVisibleChangeRef = useRef(handleVisibleChange);
|
|
52
|
+
handleVisibleChangeRef.current = handleVisibleChange;
|
|
53
|
+
const handlers = useTriggerType({ visible, onVisibleChange: handleVisibleChange, triggerType });
|
|
54
|
+
const mountTarget = mount ? getMountTarget(`${cls}-`, target) : undefined;
|
|
55
|
+
const domRef = useRef(null);
|
|
56
|
+
const triggerRef = useRef(null);
|
|
57
|
+
useLayoutEffect(() => {
|
|
58
|
+
if (mountTarget) {
|
|
59
|
+
const timer = setTimeout(() => {
|
|
60
|
+
mountTarget.style.width = visible
|
|
61
|
+
? `${typeof width === 'number' ? `${width}px` : width}`
|
|
62
|
+
: '0px';
|
|
63
|
+
mountTarget.style.opacity = visible ? '1' : '0';
|
|
64
|
+
}, 16);
|
|
65
|
+
return () => {
|
|
66
|
+
clearTimeout(timer);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!mountTarget || !className) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
mountTarget.classList.add(className);
|
|
75
|
+
return () => {
|
|
76
|
+
mountTarget.classList.remove(className);
|
|
77
|
+
};
|
|
78
|
+
}, [mountTarget, className]);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const onClick = (e) => {
|
|
81
|
+
const dom = domRef.current;
|
|
82
|
+
const trigger = triggerRef.current;
|
|
83
|
+
const target = e.target;
|
|
84
|
+
if (!dom || !trigger || !target) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!dom.contains(target) && !trigger.contains(target)) {
|
|
88
|
+
handleVisibleChangeRef.current(false, 'docClick');
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
window.addEventListener('click', onClick);
|
|
92
|
+
return () => {
|
|
93
|
+
window.removeEventListener('click', onClick);
|
|
94
|
+
};
|
|
95
|
+
}, []);
|
|
96
|
+
return (React.createElement(React.Fragment, null,
|
|
97
|
+
React.createElement("div", Object.assign({}, handlers, { ref: triggerRef }), trigger),
|
|
98
|
+
!!mountTarget &&
|
|
99
|
+
ReactDOM.createPortal(React.createElement("div", { className: cs(cls, { [`${cls}--visible`]: visible }), ref: domRef, style: { width } },
|
|
100
|
+
React.createElement("div", { className: `${cls}-inner` },
|
|
101
|
+
React.createElement("div", { className: `${cls}-header` },
|
|
102
|
+
!!title && React.createElement("div", { className: `${cls}-header-title` }, title),
|
|
103
|
+
!!closable && (React.createElement("button", { className: `${cls}-header-close`, onClick: () => handleVisibleChange(false, 'close') },
|
|
104
|
+
React.createElement(Icon, { className: `${cls}-header-close-icon`, type: "close", size: 12 })))),
|
|
105
|
+
React.createElement("div", { className: `${cls}-body` }, children))), mountTarget)));
|
|
106
|
+
}
|
|
107
|
+
function FloatButtonByInnerDrawer(props) {
|
|
108
|
+
const { width, title, target } = props, rests = __rest(props, ["width", "title", "target"]);
|
|
109
|
+
return (React.createElement(FloatButton, Object.assign({}, rests, { _renderView: (prefix, { trigger, triggerType, visible, onVisibleChange, showClose, children }) => {
|
|
110
|
+
return (React.createElement(InnerDrawer, { prefix: prefix, target: target, width: width, title: title, trigger: trigger, triggerType: triggerType, visible: visible, closable: showClose, onVisibleChange: (...args) => {
|
|
111
|
+
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(...args);
|
|
112
|
+
} }, children));
|
|
113
|
+
} })));
|
|
114
|
+
}
|
|
115
|
+
export default ConfigProvider.config(FloatButtonByInnerDrawer);
|
package/es/index.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export { default as Button } from './button';
|
|
2
|
+
export { default as Card } from './card';
|
|
3
|
+
export { default as Feedback } from './feedback';
|
|
4
|
+
export { default as FloatButton } from './float-button';
|
|
5
|
+
export { default as Text } from './text';
|
|
6
|
+
export { default as Tag } from './tag';
|
|
7
|
+
export { default as Tab } from './tab';
|
|
2
8
|
export declare const version: string;
|
package/es/index.js
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export { default as Button } from './button';
|
|
2
|
-
export
|
|
2
|
+
export { default as Card } from './card';
|
|
3
|
+
export { default as Feedback } from './feedback';
|
|
4
|
+
export { default as FloatButton } from './float-button';
|
|
5
|
+
export { default as Text } from './text';
|
|
6
|
+
export { default as Tag } from './tag';
|
|
7
|
+
export { default as Tab } from './tab';
|
|
8
|
+
export const version = '0.1.1';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Tab as NextTab } from '@alifd/next';
|
|
3
|
+
import type { TabProps } from '@alifd/next/types/tab';
|
|
4
|
+
export type { TabProps, ItemProps } from '@alifd/next/types/tab';
|
|
5
|
+
declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<TabProps & React.RefAttributes<NextTab>, "key" | keyof TabProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, NextTab, {}> & {
|
|
6
|
+
Item: typeof import("@alifd/next/types/tab").Item;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
package/es/tab/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
|
+
import { Tab as NextTab, ConfigProvider } from '@alifd/next';
|
|
4
|
+
import cs from 'classnames';
|
|
5
|
+
import { PREFIX_DEFAULT, assignSubComponent } from '../utils';
|
|
6
|
+
const Tab = forwardRef((_a, ref) => {
|
|
7
|
+
var { className, size = 'small' } = _a, props = __rest(_a, ["className", "size"]);
|
|
8
|
+
return (React.createElement(NextTab, Object.assign({}, props, { className: cs(`${PREFIX_DEFAULT}tabs`, className), ref: ref, size: size })));
|
|
9
|
+
});
|
|
10
|
+
const TabWithSub = assignSubComponent(Tab, {
|
|
11
|
+
Item: NextTab.Item,
|
|
12
|
+
displayName: 'Tab',
|
|
13
|
+
});
|
|
14
|
+
export default ConfigProvider.config(TabWithSub);
|
package/es/tab/main.scss
ADDED
package/es/tab/style.js
ADDED