musae 0.2.8 → 0.2.10
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/components/badge/badge.d.ts +4 -0
- package/dist/components/badge/badge.js +118 -0
- package/dist/components/badge/index.d.ts +2 -0
- package/dist/components/badge/types.d.ts +34 -0
- package/dist/components/checkbox/group.js +1 -1
- package/dist/components/clock/clock.js +2 -1
- package/dist/components/dialog/dialog.d.ts +1 -1
- package/dist/components/dialog/dialog.js +2 -2
- package/dist/components/dialog/popup.d.ts +1 -1
- package/dist/components/dialog/popup.js +5 -5
- package/dist/components/dialog/types.d.ts +3 -3
- package/dist/components/drawer/drawer.d.ts +1 -1
- package/dist/components/drawer/drawer.js +2 -2
- package/dist/components/drawer/popup.d.ts +1 -1
- package/dist/components/drawer/popup.js +5 -5
- package/dist/components/drawer/types.d.ts +3 -3
- package/dist/components/highlight/highlight.d.ts +4 -0
- package/dist/components/highlight/index.d.ts +2 -0
- package/dist/components/highlight/types.d.ts +11 -0
- package/dist/components/image/preview/preview.js +1 -1
- package/dist/components/notification/notification.js +16 -4
- package/dist/components/otp-input/otp-input.js +6 -6
- package/dist/components/picker/picker.js +14 -14
- package/dist/components/picker/types.d.ts +1 -1
- package/dist/components/popconfirm/popconfirm.d.ts +4 -0
- package/dist/components/popconfirm/types.d.ts +9 -0
- package/dist/components/popover/index.d.ts +2 -0
- package/dist/components/popover/popover.js +21 -10
- package/dist/components/popper/dropdown.d.ts +3 -2
- package/dist/components/popper/dropdown.js +24 -23
- package/dist/components/popper/popper.d.ts +1 -1
- package/dist/components/popper/popper.js +4 -4
- package/dist/components/skeleton/index.d.ts +2 -0
- package/dist/components/skeleton/skeleton.d.ts +4 -0
- package/dist/components/skeleton/skeleton.js +37 -0
- package/dist/components/skeleton/types.d.ts +19 -0
- package/dist/components/theme/hooks.d.ts +2 -1
- package/dist/components/theme/hooks.js +12 -16
- package/dist/components/theme/types.d.ts +1 -1
- package/dist/components/tree/hooks.d.ts +8 -2
- package/dist/components/tree/hooks.js +11 -12
- package/dist/components/tree/node.js +8 -2
- package/dist/components/tree/tree.d.ts +1 -1
- package/dist/components/tree/tree.js +16 -4
- package/dist/components/tree/types.d.ts +36 -0
- package/dist/components/visually-hidden/index.d.ts +2 -0
- package/dist/components/visually-hidden/types.d.ts +12 -0
- package/dist/components/visually-hidden/visually-hidden.d.ts +4 -0
- package/dist/hooks/use-class-names.d.ts +11 -0
- package/dist/hooks/use-closable.d.ts +18 -0
- package/dist/hooks/{use-dismissable.js → use-closable.js} +20 -16
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/stylex.css +12 -0
- package/dist/utils/class-name.d.ts +37 -1
- package/dist/utils/class-name.js +29 -1
- package/package.json +2 -2
- package/dist/components/picker/hooks.d.ts +0 -12
- package/dist/components/picker/hooks.js +0 -23
- package/dist/hooks/use-dismissable.d.ts +0 -18
- /package/dist/node_modules/.pnpm/{@aiszlab_relax@1.2.59_react-dom@18.3.1_react@18.3.1__react@18.3.1 → @aiszlab_relax@1.2.64_react-dom@18.3.1_react@18.3.1__react@18.3.1}/node_modules/@aiszlab/relax/dist/dom/contains.js +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useClassNames } from '../../hooks/use-class-names.js';
|
|
3
|
+
import { ComponentToken, BadgeClassToken } from '../../utils/class-name.js';
|
|
4
|
+
import _stylex from '../../node_modules/.pnpm/@stylexjs_stylex@0.7.5/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
5
|
+
import clsx from 'clsx';
|
|
6
|
+
import { typography } from '../theme/theme.js';
|
|
7
|
+
import { sizes } from '../theme/tokens.stylex.js';
|
|
8
|
+
import { useTheme } from '../theme/hooks.js';
|
|
9
|
+
import { ColorToken } from '../../utils/colors.js';
|
|
10
|
+
import { isVoid } from '@aiszlab/relax';
|
|
11
|
+
|
|
12
|
+
const styles = {
|
|
13
|
+
badge: {
|
|
14
|
+
default: {
|
|
15
|
+
position: "musae-1n2onr6",
|
|
16
|
+
display: "musae-3nfvp2",
|
|
17
|
+
$$css: true
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
tail: {
|
|
21
|
+
default: props => [{
|
|
22
|
+
position: "musae-10l6tqk",
|
|
23
|
+
borderRadius: "musae-iipnba",
|
|
24
|
+
borderStartStartRadius: null,
|
|
25
|
+
borderStartEndRadius: null,
|
|
26
|
+
borderEndStartRadius: null,
|
|
27
|
+
borderEndEndRadius: null,
|
|
28
|
+
borderTopLeftRadius: null,
|
|
29
|
+
borderTopRightRadius: null,
|
|
30
|
+
borderBottomLeftRadius: null,
|
|
31
|
+
borderBottomRightRadius: null,
|
|
32
|
+
minWidth: "musae-70jws7",
|
|
33
|
+
textAlign: "musae-2b8uid",
|
|
34
|
+
boxShadow: "musae-igitpm",
|
|
35
|
+
backgroundColor: "musae-q1mx2j",
|
|
36
|
+
color: "musae-19dipnz",
|
|
37
|
+
$$css: true
|
|
38
|
+
}, {
|
|
39
|
+
"--boxShadow": `0 0 0 ${sizes.smallest} ${props.color}` != null ? `0 0 0 ${sizes.smallest} ${props.color}` : "initial",
|
|
40
|
+
"--backgroundColor": props.backgroundColor != null ? props.backgroundColor : "initial",
|
|
41
|
+
"--color": props.color != null ? props.color : "initial"
|
|
42
|
+
}],
|
|
43
|
+
dot: {
|
|
44
|
+
minWidth: null,
|
|
45
|
+
width: "musae-2jq81",
|
|
46
|
+
height: "musae-1v3ox18",
|
|
47
|
+
$$css: true
|
|
48
|
+
},
|
|
49
|
+
invisible: {
|
|
50
|
+
display: "musae-1s85apg",
|
|
51
|
+
$$css: true
|
|
52
|
+
},
|
|
53
|
+
"top-right": {
|
|
54
|
+
top: "musae-13vifvy",
|
|
55
|
+
right: "musae-3m8u43",
|
|
56
|
+
insetInlineStart: null,
|
|
57
|
+
insetInlineEnd: null,
|
|
58
|
+
transform: "musae-rycbv3",
|
|
59
|
+
$$css: true
|
|
60
|
+
},
|
|
61
|
+
"top-left": {
|
|
62
|
+
top: "musae-13vifvy",
|
|
63
|
+
left: "musae-u96u03",
|
|
64
|
+
insetInlineStart: null,
|
|
65
|
+
insetInlineEnd: null,
|
|
66
|
+
transform: "musae-1i3z1r0",
|
|
67
|
+
$$css: true
|
|
68
|
+
},
|
|
69
|
+
"bottom-right": {
|
|
70
|
+
bottom: "musae-1ey2m1c",
|
|
71
|
+
right: "musae-3m8u43",
|
|
72
|
+
insetInlineStart: null,
|
|
73
|
+
insetInlineEnd: null,
|
|
74
|
+
transform: "musae-1vfo23u",
|
|
75
|
+
$$css: true
|
|
76
|
+
},
|
|
77
|
+
"bottom-left": {
|
|
78
|
+
bottom: "musae-1ey2m1c",
|
|
79
|
+
left: "musae-u96u03",
|
|
80
|
+
insetInlineStart: null,
|
|
81
|
+
insetInlineEnd: null,
|
|
82
|
+
transform: "musae-itovws",
|
|
83
|
+
$$css: true
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const Badge = ({
|
|
88
|
+
className,
|
|
89
|
+
style,
|
|
90
|
+
children,
|
|
91
|
+
content,
|
|
92
|
+
invisible = false,
|
|
93
|
+
placement = "top-right"
|
|
94
|
+
}) => {
|
|
95
|
+
const classNames = useClassNames(ComponentToken.Badge);
|
|
96
|
+
const theme = useTheme();
|
|
97
|
+
const isDot = isVoid(content);
|
|
98
|
+
const styled = {
|
|
99
|
+
badge: _stylex.props(styles.badge.default),
|
|
100
|
+
tail: _stylex.props(styles.tail.default({
|
|
101
|
+
backgroundColor: theme.colors[ColorToken.Primary],
|
|
102
|
+
color: theme.colors[ColorToken.OnPrimary]
|
|
103
|
+
}), isDot && styles.tail.dot, typography.label.small, invisible && styles.tail.invisible, styles.tail[placement])
|
|
104
|
+
};
|
|
105
|
+
return React.createElement("span", {
|
|
106
|
+
className: clsx(classNames[BadgeClassToken.Badge], className, styled.badge.className),
|
|
107
|
+
style: {
|
|
108
|
+
...styled.badge.style,
|
|
109
|
+
...style
|
|
110
|
+
}
|
|
111
|
+
}, children, React.createElement("span", {
|
|
112
|
+
className: clsx(classNames[BadgeClassToken.Tail], styled.tail.className),
|
|
113
|
+
style: styled.tail.style
|
|
114
|
+
}, content));
|
|
115
|
+
};
|
|
116
|
+
var Badge$1 = Badge;
|
|
117
|
+
|
|
118
|
+
export { Badge$1 as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ComponentProps } from "../../types/element";
|
|
3
|
+
type Placement = "top-right" | "top-left" | "bottom-right" | "bottom-left";
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* badge props
|
|
7
|
+
*/
|
|
8
|
+
export type BadgeProps = ComponentProps & {
|
|
9
|
+
/**
|
|
10
|
+
* @description
|
|
11
|
+
* children
|
|
12
|
+
* @requires
|
|
13
|
+
*/
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* @description
|
|
17
|
+
* content
|
|
18
|
+
* @default void 0
|
|
19
|
+
*/
|
|
20
|
+
content?: ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* @description
|
|
23
|
+
* invisible
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
invisible?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @description
|
|
29
|
+
* placement
|
|
30
|
+
* @default "top-right"
|
|
31
|
+
*/
|
|
32
|
+
placement?: Placement;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -19,7 +19,7 @@ const Group = ({ value: controlledValue, children, onChange, disabled = false })
|
|
|
19
19
|
const _checkedKeys = Array.from(checkedKeys);
|
|
20
20
|
onChange?.(_checkedKeys);
|
|
21
21
|
setValue(_checkedKeys);
|
|
22
|
-
}, [setValue, value]);
|
|
22
|
+
}, [onChange, setValue, value]);
|
|
23
23
|
// context value
|
|
24
24
|
const contextValue = useMemo(() => {
|
|
25
25
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { DialogProps } from "./types";
|
|
3
|
-
declare const Dialog: ({ open,
|
|
3
|
+
declare const Dialog: ({ open, closable, ...props }: DialogProps) => React.JSX.Element;
|
|
4
4
|
export default Dialog;
|
|
@@ -3,7 +3,7 @@ import React, { useEffect } from 'react';
|
|
|
3
3
|
import Popup from './popup.js';
|
|
4
4
|
import { useBoolean } from '@aiszlab/relax';
|
|
5
5
|
|
|
6
|
-
const Dialog = ({ open,
|
|
6
|
+
const Dialog = ({ open, closable = true, ...props }) => {
|
|
7
7
|
/// `Portal` should disappear after `Dialog` disappear completely
|
|
8
8
|
const [_isVisible, { turnOn, turnOff }] = useBoolean(false);
|
|
9
9
|
useEffect(() => {
|
|
@@ -13,7 +13,7 @@ const Dialog = ({ open, dismissable = true, ...props }) => {
|
|
|
13
13
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
14
|
}, [open]);
|
|
15
15
|
return (React.createElement(Portal, { open: open || _isVisible, lockable: true },
|
|
16
|
-
React.createElement(Popup, { ...props,
|
|
16
|
+
React.createElement(Popup, { ...props, closable: closable, open: open, onClosed: turnOff })));
|
|
17
17
|
};
|
|
18
18
|
var Dialog$1 = Dialog;
|
|
19
19
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { PopupProps } from "./types";
|
|
3
|
-
declare const Popup: ({ onClose, open,
|
|
3
|
+
declare const Popup: ({ onClose, open, closable, onClosed, ...props }: PopupProps) => React.JSX.Element;
|
|
4
4
|
export default Popup;
|
|
@@ -8,8 +8,8 @@ import { useTheme } from '../theme/hooks.js';
|
|
|
8
8
|
import { ColorToken } from '../../utils/colors.js';
|
|
9
9
|
import { typography } from '../theme/theme.js';
|
|
10
10
|
import clsx from 'clsx';
|
|
11
|
-
import {
|
|
12
|
-
import { contains } from '../../node_modules/.pnpm/@aiszlab_relax@1.2.
|
|
11
|
+
import { useClosable } from '../../hooks/use-closable.js';
|
|
12
|
+
import { contains } from '../../node_modules/.pnpm/@aiszlab_relax@1.2.64_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@aiszlab/relax/dist/dom/contains.js';
|
|
13
13
|
|
|
14
14
|
const styles = {
|
|
15
15
|
header: {
|
|
@@ -88,7 +88,7 @@ const styles = {
|
|
|
88
88
|
const Popup = ({
|
|
89
89
|
onClose,
|
|
90
90
|
open,
|
|
91
|
-
|
|
91
|
+
closable,
|
|
92
92
|
onClosed,
|
|
93
93
|
...props$1
|
|
94
94
|
}) => {
|
|
@@ -103,8 +103,8 @@ const Popup = ({
|
|
|
103
103
|
closer,
|
|
104
104
|
onKeyDown,
|
|
105
105
|
onOverlayClick
|
|
106
|
-
} =
|
|
107
|
-
|
|
106
|
+
} = useClosable({
|
|
107
|
+
closable,
|
|
108
108
|
onClose
|
|
109
109
|
});
|
|
110
110
|
useEffect(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CSSProperties, ReactNode } from "react";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Closable } from "../../hooks/use-closable";
|
|
3
3
|
import { RequiredIn } from "@aiszlab/relax/types";
|
|
4
4
|
/**
|
|
5
5
|
* @description
|
|
@@ -29,7 +29,7 @@ export interface DialogProps {
|
|
|
29
29
|
* Whether the dialog can be closed by clicking on the overlay or pressing the Esc key.
|
|
30
30
|
* @default true
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
closable?: boolean | Closable[];
|
|
33
33
|
/**
|
|
34
34
|
* @description
|
|
35
35
|
* title
|
|
@@ -67,7 +67,7 @@ export interface DialogProps {
|
|
|
67
67
|
* @description
|
|
68
68
|
* popup
|
|
69
69
|
*/
|
|
70
|
-
export type PopupProps = RequiredIn<DialogProps, "
|
|
70
|
+
export type PopupProps = RequiredIn<DialogProps, "closable"> & {
|
|
71
71
|
/**
|
|
72
72
|
* @description
|
|
73
73
|
* callback will be toggled after close animation end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { DrawerProps } from "./types";
|
|
3
|
-
declare const Drawer: ({ open, size,
|
|
3
|
+
declare const Drawer: ({ open, size, closable, placement, ...props }: DrawerProps) => React.JSX.Element;
|
|
4
4
|
export default Drawer;
|
|
@@ -3,7 +3,7 @@ import Portal from '../portal/portal.js';
|
|
|
3
3
|
import Popup from './popup.js';
|
|
4
4
|
import { useBoolean } from '@aiszlab/relax';
|
|
5
5
|
|
|
6
|
-
const Drawer = ({ open, size = 400,
|
|
6
|
+
const Drawer = ({ open, size = 400, closable = true, placement = "right", ...props }) => {
|
|
7
7
|
/// `Portal` should disappear after `Dialog` disappear completely
|
|
8
8
|
const [_isVisible, { turnOn, turnOff }] = useBoolean(false);
|
|
9
9
|
useEffect(() => {
|
|
@@ -13,7 +13,7 @@ const Drawer = ({ open, size = 400, dismissable = true, placement = "right", ...
|
|
|
13
13
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
14
|
}, [open]);
|
|
15
15
|
return (React.createElement(Portal, { open: open || _isVisible, lockable: true },
|
|
16
|
-
React.createElement(Popup, { ...props, onClosed: turnOff, size: size, open: open,
|
|
16
|
+
React.createElement(Popup, { ...props, onClosed: turnOff, size: size, open: open, closable: closable, placement: placement })));
|
|
17
17
|
};
|
|
18
18
|
var Drawer$1 = Drawer;
|
|
19
19
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { PopupProps } from "./types";
|
|
3
|
-
declare const Popup: ({ open, onClose, placement,
|
|
3
|
+
declare const Popup: ({ open, onClose, placement, closable, onClosed, size, ...props }: PopupProps) => React.JSX.Element;
|
|
4
4
|
export default Popup;
|
|
@@ -8,8 +8,8 @@ import { useTheme } from '../theme/hooks.js';
|
|
|
8
8
|
import { ColorToken } from '../../utils/colors.js';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
10
|
import { typography } from '../theme/theme.js';
|
|
11
|
-
import {
|
|
12
|
-
import { contains } from '../../node_modules/.pnpm/@aiszlab_relax@1.2.
|
|
11
|
+
import { useClosable } from '../../hooks/use-closable.js';
|
|
12
|
+
import { contains } from '../../node_modules/.pnpm/@aiszlab_relax@1.2.64_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@aiszlab/relax/dist/dom/contains.js';
|
|
13
13
|
|
|
14
14
|
const styles = {
|
|
15
15
|
popup: {
|
|
@@ -137,7 +137,7 @@ const Popup = ({
|
|
|
137
137
|
open,
|
|
138
138
|
onClose,
|
|
139
139
|
placement,
|
|
140
|
-
|
|
140
|
+
closable,
|
|
141
141
|
onClosed,
|
|
142
142
|
size,
|
|
143
143
|
...props$1
|
|
@@ -153,8 +153,8 @@ const Popup = ({
|
|
|
153
153
|
closer,
|
|
154
154
|
onKeyDown,
|
|
155
155
|
onOverlayClick
|
|
156
|
-
} =
|
|
157
|
-
|
|
156
|
+
} = useClosable({
|
|
157
|
+
closable,
|
|
158
158
|
onClose
|
|
159
159
|
});
|
|
160
160
|
useEffect(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Closable } from "../../hooks/use-closable";
|
|
3
3
|
export type Placement = "right" | "left" | "top" | "bottom";
|
|
4
4
|
/**
|
|
5
5
|
* @description
|
|
@@ -35,7 +35,7 @@ export interface DrawerProps {
|
|
|
35
35
|
* Whether the drawer can be closed by clicking on the overlay or pressing the Esc key.
|
|
36
36
|
* @default true
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
closable?: boolean | Closable[];
|
|
39
39
|
/**
|
|
40
40
|
* @description
|
|
41
41
|
* size
|
|
@@ -58,7 +58,7 @@ export interface DrawerProps {
|
|
|
58
58
|
*/
|
|
59
59
|
export type PopupProps = DrawerProps & {
|
|
60
60
|
size: number;
|
|
61
|
-
|
|
61
|
+
closable: boolean | Closable[];
|
|
62
62
|
placement: Placement;
|
|
63
63
|
/**
|
|
64
64
|
* @description
|
|
@@ -174,10 +174,22 @@ const Notification = ({
|
|
|
174
174
|
const classNames = useClassNames(ComponentToken.Notification);
|
|
175
175
|
// after duration, `Notification` will auto destroy
|
|
176
176
|
useTimeout(async () => {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
switch (placement) {
|
|
178
|
+
case "bottom":
|
|
179
|
+
case "bottomLeft":
|
|
180
|
+
case "bottomRight":
|
|
181
|
+
await animate(scope.current, {
|
|
182
|
+
opacity: 0,
|
|
183
|
+
marginBottom: (scope.current.getBoundingClientRect().height + 12) * -1
|
|
184
|
+
});
|
|
185
|
+
break;
|
|
186
|
+
default:
|
|
187
|
+
await animate(scope.current, {
|
|
188
|
+
opacity: 0,
|
|
189
|
+
marginTop: (scope.current.getBoundingClientRect().height + 12) * -1
|
|
190
|
+
});
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
181
193
|
onClose?.();
|
|
182
194
|
}, duration);
|
|
183
195
|
const styled = {
|
|
@@ -20,12 +20,12 @@ const OtpInput = ({
|
|
|
20
20
|
length
|
|
21
21
|
}).fill(null));
|
|
22
22
|
const [focusedAt, setFocusedAt] = useState(0);
|
|
23
|
-
const refocus = useEvent(
|
|
24
|
-
const
|
|
25
|
-
// handle input
|
|
26
|
-
inputRefs.current[
|
|
27
|
-
inputRefs.current[
|
|
28
|
-
setFocusedAt(
|
|
23
|
+
const refocus = useEvent(_foucsAt => {
|
|
24
|
+
const foucsAt = clamp(_foucsAt, 0, length - 1);
|
|
25
|
+
// handle input, only select when prev input
|
|
26
|
+
inputRefs.current[foucsAt]?.focus?.();
|
|
27
|
+
_foucsAt < length && inputRefs.current[foucsAt]?.select?.();
|
|
28
|
+
setFocusedAt(foucsAt);
|
|
29
29
|
});
|
|
30
30
|
const changeValue = useEvent(value => {
|
|
31
31
|
_change(focusedAt, value);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { forwardRef, useRef, useCallback, useImperativeHandle } from 'react';
|
|
2
2
|
import Popper from '../popper/popper.js';
|
|
3
|
-
import { useBoolean,
|
|
4
|
-
import { useEvents } from './hooks.js';
|
|
3
|
+
import { useBoolean, useEvent, useFocus } from '@aiszlab/relax';
|
|
5
4
|
import { ComponentToken, PickerClassToken } from '../../utils/class-name.js';
|
|
6
5
|
import { useClassNames } from '../../hooks/use-class-names.js';
|
|
7
6
|
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.7.5/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
@@ -42,7 +41,6 @@ const Picker = forwardRef(({
|
|
|
42
41
|
const classNames = useClassNames(ComponentToken.Picker);
|
|
43
42
|
const theme = useTheme();
|
|
44
43
|
const pickableRef = useRef(null);
|
|
45
|
-
const onDropdownClick = useCallback(e => e.preventDefault(), []);
|
|
46
44
|
const getDropdownWidth = useCallback(() => {
|
|
47
45
|
if (!popupWidth) return void 0;
|
|
48
46
|
if (!trigger.current) return void 0;
|
|
@@ -51,17 +49,19 @@ const Picker = forwardRef(({
|
|
|
51
49
|
useImperativeHandle(ref, () => ({
|
|
52
50
|
close
|
|
53
51
|
}));
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
const click = useEvent(event => {
|
|
53
|
+
event.stopPropagation();
|
|
54
|
+
toggle();
|
|
55
|
+
onClick?.(event);
|
|
56
|
+
});
|
|
57
|
+
const onBlur = useEvent(e => {
|
|
58
|
+
e.stopPropagation();
|
|
59
|
+
close();
|
|
61
60
|
});
|
|
62
61
|
const [isFocused, focusProps] = useFocus({
|
|
63
|
-
onBlur
|
|
62
|
+
onBlur
|
|
64
63
|
});
|
|
64
|
+
const onDropdownClick = useCallback(e => e.preventDefault(), []);
|
|
65
65
|
const styled = {
|
|
66
66
|
picker: props(typography.body.medium, styles$1.wrapper({
|
|
67
67
|
outlineColor: theme.colors[ColorToken.Outline]
|
|
@@ -94,11 +94,11 @@ const Picker = forwardRef(({
|
|
|
94
94
|
trigger: trigger.current,
|
|
95
95
|
open: isOpen,
|
|
96
96
|
className: classNames[PickerClassToken.Dropdown],
|
|
97
|
-
// click on popper, keep select focused
|
|
98
|
-
onMouseDown: onDropdownClick,
|
|
99
97
|
onEntered: onPopperEntered,
|
|
100
98
|
onExit: onPopperExite,
|
|
101
|
-
onExited: onPopperExited
|
|
99
|
+
onExited: onPopperExited,
|
|
100
|
+
// click on popper, keep select focused
|
|
101
|
+
onMouseDown: onDropdownClick
|
|
102
102
|
}, React.createElement("div", {
|
|
103
103
|
ref: pickableRef,
|
|
104
104
|
className: clsx(pickableClassName, styled.pickable.className),
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DOMAttributes, RefAttributes } from "react";
|
|
2
|
+
import type { PopoverProps } from "../popover";
|
|
3
|
+
import { ComponentProps } from "../../types/element";
|
|
4
|
+
export type ChildProps<T> = Pick<DOMAttributes<T>, "onClick"> & RefAttributes<T>;
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* popconfirm props
|
|
8
|
+
*/
|
|
9
|
+
export type PopconfirmProps<P extends ChildProps<T>, T extends HTMLElement> = Pick<PopoverProps<P, T>, "children" | "placement" | "title" | "description"> & ComponentProps;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useBoolean, toArray, useRefs, useEvent, useHover, chain, useFocus } from '@aiszlab/relax';
|
|
1
|
+
import { useBoolean, toArray, useRefs, useEvent, useHover, chain, useFocus, useClickAway } from '@aiszlab/relax';
|
|
2
2
|
import React, { useRef, useMemo, cloneElement } from 'react';
|
|
3
3
|
import Popper from '../popper/popper.js';
|
|
4
4
|
import _stylex from '../../node_modules/.pnpm/@stylexjs_stylex@0.7.5/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
@@ -31,21 +31,24 @@ const Popover = ({
|
|
|
31
31
|
const _ref = useRef(null);
|
|
32
32
|
const [_isOpen, {
|
|
33
33
|
toggle,
|
|
34
|
-
turnOn
|
|
34
|
+
turnOn,
|
|
35
|
+
turnOff
|
|
35
36
|
}] = useBoolean(false);
|
|
36
37
|
const triggerBy = useMemo(() => new Set(toArray(_triggerBy)), [_triggerBy]);
|
|
37
38
|
const classNames = useClassNames(ComponentToken.Popover);
|
|
38
39
|
const childRef = useRefs(_ref, _children.props.ref);
|
|
39
|
-
const
|
|
40
|
-
|
|
40
|
+
const popperRef = useRef(null);
|
|
41
|
+
const onClick = useEvent(e => {
|
|
41
42
|
e.stopPropagation();
|
|
43
|
+
toggle();
|
|
42
44
|
});
|
|
43
|
-
const
|
|
45
|
+
const onContextMenu = useEvent(e => {
|
|
46
|
+
e.preventDefault();
|
|
44
47
|
turnOn();
|
|
45
48
|
});
|
|
46
49
|
const [isHovered, hoverProps] = useHover({
|
|
47
|
-
onEnter:
|
|
48
|
-
onLeave:
|
|
50
|
+
onEnter: event => chain(_children.props.onMouseOver, _children.props.onMouseEnter, _children.props.onPointerEnter)(event),
|
|
51
|
+
onLeave: event => chain(_children.props.onMouseLeave, _children.props.onPointerLeave)(event)
|
|
49
52
|
});
|
|
50
53
|
const [isFocused, focusProps] = useFocus({
|
|
51
54
|
onFocus: _children.props.onFocus,
|
|
@@ -64,8 +67,12 @@ const Popover = ({
|
|
|
64
67
|
ref: childRef,
|
|
65
68
|
...hoverProps,
|
|
66
69
|
...focusProps,
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
...(triggerBy.has("click") && {
|
|
71
|
+
onClick
|
|
72
|
+
}),
|
|
73
|
+
...(triggerBy.has("contextMenu") && {
|
|
74
|
+
onContextMenu
|
|
75
|
+
})
|
|
69
76
|
});
|
|
70
77
|
const enterPopper = useEvent(e => {
|
|
71
78
|
hoverProps.onPointerEnter(e);
|
|
@@ -73,6 +80,9 @@ const Popover = ({
|
|
|
73
80
|
const leavePopper = useEvent(e => {
|
|
74
81
|
hoverProps.onPointerLeave(e);
|
|
75
82
|
});
|
|
83
|
+
useClickAway(() => {
|
|
84
|
+
turnOff();
|
|
85
|
+
}, popperRef);
|
|
76
86
|
const styled = {
|
|
77
87
|
popover: _stylex.props(styles.popover, typography.body.medium),
|
|
78
88
|
title: _stylex.props(styles.title, typography.title.medium)
|
|
@@ -85,7 +95,8 @@ const Popover = ({
|
|
|
85
95
|
onPointerEnter: enterPopper,
|
|
86
96
|
onPointerLeave: leavePopper
|
|
87
97
|
}),
|
|
88
|
-
placement: placement
|
|
98
|
+
placement: placement,
|
|
99
|
+
ref: popperRef
|
|
89
100
|
}, React.createElement("div", {
|
|
90
101
|
className: clsx(classNames[PopoverClassToken.Popover], className, styled.popover.className),
|
|
91
102
|
style: {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
declare const Dropdown: React.ForwardRefExoticComponent<Omit<import("./types").PopperProps, "placement" | "portal"> & {
|
|
3
|
+
placement: import("@floating-ui/dom").Placement;
|
|
4
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
4
5
|
export default Dropdown;
|