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
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, { useRef, useMemo,
|
|
1
|
+
import React, { forwardRef, useRef, useMemo, useLayoutEffect } from 'react';
|
|
2
2
|
import { ComponentToken, PopperClassToken } from '../../utils/class-name.js';
|
|
3
3
|
import { useClassNames } from '../../hooks/use-class-names.js';
|
|
4
4
|
import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.7.5/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
|
-
import { isFunction } from '@aiszlab/relax';
|
|
6
|
+
import { useRefs, isFunction } from '@aiszlab/relax';
|
|
7
7
|
import { autoUpdate, computePosition, flip, offset, arrow } from '@floating-ui/dom';
|
|
8
8
|
import { useOffsets } from './hooks.js';
|
|
9
9
|
import { useTheme } from '../theme/hooks.js';
|
|
@@ -54,7 +54,7 @@ const styles = {
|
|
|
54
54
|
}]
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
const Dropdown = ({
|
|
57
|
+
const Dropdown = forwardRef(({
|
|
58
58
|
open,
|
|
59
59
|
children,
|
|
60
60
|
placement,
|
|
@@ -68,11 +68,12 @@ const Dropdown = ({
|
|
|
68
68
|
overlay = false,
|
|
69
69
|
arrow: arrowable = false,
|
|
70
70
|
...props$1
|
|
71
|
-
}) => {
|
|
72
|
-
const [
|
|
71
|
+
}, ref) => {
|
|
72
|
+
const [_floatable, animate] = useAnimate();
|
|
73
73
|
const arrowRef = useRef(null);
|
|
74
74
|
const classNames = useClassNames(ComponentToken.Popper);
|
|
75
75
|
const theme = useTheme();
|
|
76
|
+
const floatable = useRefs(_floatable, ref);
|
|
76
77
|
/// how to get trigger
|
|
77
78
|
const trigger = useMemo(() => {
|
|
78
79
|
if (!open) return null;
|
|
@@ -86,10 +87,10 @@ const Dropdown = ({
|
|
|
86
87
|
});
|
|
87
88
|
/// auto update: calc trigger dom to get position
|
|
88
89
|
/// if trigger changed, re-relate
|
|
89
|
-
|
|
90
|
+
useLayoutEffect(() => {
|
|
90
91
|
if (!trigger) return;
|
|
91
|
-
const cleanup = autoUpdate(trigger,
|
|
92
|
-
computePosition(trigger,
|
|
92
|
+
const cleanup = autoUpdate(trigger, _floatable.current, () => {
|
|
93
|
+
computePosition(trigger, _floatable.current, {
|
|
93
94
|
placement: placement,
|
|
94
95
|
middleware: [flip(), offset(offsets), arrowable && !!arrowRef.current && arrow({
|
|
95
96
|
element: arrowRef.current,
|
|
@@ -103,7 +104,7 @@ const Dropdown = ({
|
|
|
103
104
|
}) => {
|
|
104
105
|
const [side] = _placement.split("-");
|
|
105
106
|
// set float element styles
|
|
106
|
-
|
|
107
|
+
_floatable.current.style.translate = `${x}px ${y}px`;
|
|
107
108
|
// set arrwo styles
|
|
108
109
|
if (middlewareData.arrow && !!arrowRef.current) {
|
|
109
110
|
const offsetY = `${middlewareData.arrow.y ?? 0 - 8}px`;
|
|
@@ -119,19 +120,11 @@ const Dropdown = ({
|
|
|
119
120
|
};
|
|
120
121
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
121
122
|
}, [placement, trigger, offsets, arrowable]);
|
|
122
|
-
|
|
123
|
-
dropdown: props(styles.dropdown.default({
|
|
124
|
-
backgroundColor: theme.colors[ColorToken.SurfaceContainer]
|
|
125
|
-
}), overlay && styles.dropdown.overlay),
|
|
126
|
-
arrow: props(styles.arrow.default({
|
|
127
|
-
backgroundColor: theme.colors[ColorToken.SurfaceContainer]
|
|
128
|
-
}))
|
|
129
|
-
};
|
|
130
|
-
useEffect(() => {
|
|
123
|
+
useLayoutEffect(() => {
|
|
131
124
|
(async () => {
|
|
132
125
|
if (open) {
|
|
133
|
-
|
|
134
|
-
await animate(
|
|
126
|
+
_floatable.current.style.display = "";
|
|
127
|
+
await animate(_floatable.current, {
|
|
135
128
|
opacity: 1,
|
|
136
129
|
transform: "scale(1, 1)"
|
|
137
130
|
}, {
|
|
@@ -141,19 +134,27 @@ const Dropdown = ({
|
|
|
141
134
|
await onEntered?.();
|
|
142
135
|
return;
|
|
143
136
|
}
|
|
144
|
-
await Promise.all([onExit?.(), animate(
|
|
137
|
+
await Promise.all([onExit?.(), animate(_floatable.current, {
|
|
145
138
|
opacity: 0,
|
|
146
139
|
transform: "scale(0, 0)"
|
|
147
140
|
}, {
|
|
148
141
|
delay: 0.1,
|
|
149
142
|
duration: 0.2
|
|
150
143
|
}).then(() => {
|
|
151
|
-
|
|
144
|
+
_floatable.current.style.display = "none";
|
|
152
145
|
})]);
|
|
153
146
|
onExited?.();
|
|
154
147
|
})();
|
|
155
148
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
156
149
|
}, [open]);
|
|
150
|
+
const styled = {
|
|
151
|
+
dropdown: props(styles.dropdown.default({
|
|
152
|
+
backgroundColor: theme.colors[ColorToken.SurfaceContainer]
|
|
153
|
+
}), overlay && styles.dropdown.overlay),
|
|
154
|
+
arrow: props(styles.arrow.default({
|
|
155
|
+
backgroundColor: theme.colors[ColorToken.SurfaceContainer]
|
|
156
|
+
}))
|
|
157
|
+
};
|
|
157
158
|
return React.createElement("div", {
|
|
158
159
|
ref: floatable,
|
|
159
160
|
...props$1,
|
|
@@ -167,6 +168,6 @@ const Dropdown = ({
|
|
|
167
168
|
className: styled.arrow.className,
|
|
168
169
|
style: styled.arrow.style
|
|
169
170
|
}));
|
|
170
|
-
};
|
|
171
|
+
});
|
|
171
172
|
|
|
172
173
|
export { Dropdown as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { PopperProps } from "./types";
|
|
3
|
-
declare const Popper:
|
|
3
|
+
declare const Popper: React.ForwardRefExoticComponent<PopperProps & React.RefAttributes<HTMLDivElement>>;
|
|
4
4
|
export default Popper;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
2
|
import Portal from '../portal/portal.js';
|
|
3
3
|
import Dropdown from './dropdown.js';
|
|
4
4
|
|
|
5
|
-
const Popper = ({ destroyable, placement = "bottom-start", ...props }) => {
|
|
5
|
+
const Popper = forwardRef(({ destroyable, placement = "bottom-start", ...props }, ref) => {
|
|
6
6
|
return (React.createElement(Portal, { open: props.open, destroyable: destroyable },
|
|
7
|
-
React.createElement(Dropdown, { ...props, placement: placement })));
|
|
8
|
-
};
|
|
7
|
+
React.createElement(Dropdown, { ...props, placement: placement, ref: ref })));
|
|
8
|
+
});
|
|
9
9
|
|
|
10
10
|
export { Popper as default };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import _stylex from '../../node_modules/.pnpm/@stylexjs_stylex@0.7.5/node_modules/@stylexjs/stylex/lib/es/stylex.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useClassNames } from '../../hooks/use-class-names.js';
|
|
4
|
+
import { ComponentToken, SkeletonClassToken } from '../../utils/class-name.js';
|
|
5
|
+
import clsx from 'clsx';
|
|
6
|
+
|
|
7
|
+
const styles = {
|
|
8
|
+
skeleton: {
|
|
9
|
+
$$css: true
|
|
10
|
+
},
|
|
11
|
+
animation: {
|
|
12
|
+
animationName: "musae-9q1e4u",
|
|
13
|
+
animationDuration: "musae-mg6eyc",
|
|
14
|
+
animationTimingFunction: "musae-1debuo4",
|
|
15
|
+
animationIterationCount: "musae-a4qsjk",
|
|
16
|
+
$$css: true
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const Skeleton = ({
|
|
20
|
+
animation = false,
|
|
21
|
+
variant,
|
|
22
|
+
className,
|
|
23
|
+
style
|
|
24
|
+
}) => {
|
|
25
|
+
const classNames = useClassNames(ComponentToken.Skeleton);
|
|
26
|
+
const styled = _stylex.props(styles.skeleton, animation && styles.animation);
|
|
27
|
+
return React.createElement("div", {
|
|
28
|
+
className: clsx(classNames[SkeletonClassToken.Skeleton], className, styled.className),
|
|
29
|
+
style: {
|
|
30
|
+
...styled.style,
|
|
31
|
+
...style
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
var Skeleton$1 = Skeleton;
|
|
36
|
+
|
|
37
|
+
export { Skeleton$1 as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ComponentProps } from "../../types/element";
|
|
2
|
+
type Variant = "circular" | "rectangular" | "rounded";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* skeleton props
|
|
6
|
+
*/
|
|
7
|
+
export type SkeletonProps = ComponentProps & {
|
|
8
|
+
/**
|
|
9
|
+
* @description
|
|
10
|
+
* animation
|
|
11
|
+
*/
|
|
12
|
+
animation?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* @description
|
|
15
|
+
* variant
|
|
16
|
+
*/
|
|
17
|
+
variant?: Variant;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MouseEvent } from "react";
|
|
1
2
|
import type { Palette, ContextValue, Theme, Mode } from "./types";
|
|
2
3
|
export declare const PALETTE: Readonly<Palette>;
|
|
3
4
|
/**
|
|
@@ -27,6 +28,6 @@ export declare const useSwitchable: ({ theme }: {
|
|
|
27
28
|
theme: Theme;
|
|
28
29
|
}) => {
|
|
29
30
|
mode: Mode;
|
|
30
|
-
toggle: (event
|
|
31
|
+
toggle: (event?: MouseEvent) => void;
|
|
31
32
|
colors: Record<import("../../utils/colors").ColorToken, string>;
|
|
32
33
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useContext, useState, useRef, useMemo
|
|
1
|
+
import { createContext, useContext, useState, useRef, useMemo } from 'react';
|
|
2
2
|
import { toColors } from '../../utils/colors.js';
|
|
3
3
|
import { useEvent, useMounted, isFunction } from '@aiszlab/relax';
|
|
4
4
|
import { toClassList } from '../../utils/styles.js';
|
|
@@ -143,9 +143,6 @@ const useSwitchable = ({
|
|
|
143
143
|
className: "musae-ntwwlm musae-ktw8en musae-qotmtd"
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
|
-
const _toggle = useCallback(() => {
|
|
147
|
-
setMode(_mode => _mode === "light" ? "dark" : "light");
|
|
148
|
-
}, []);
|
|
149
146
|
const repaint = useEvent(_mode => {
|
|
150
147
|
const _isDark = _mode === "dark";
|
|
151
148
|
document.documentElement.classList.remove(...toClassList((_isDark ? styled.light : styled.dark).className));
|
|
@@ -159,25 +156,24 @@ const useSwitchable = ({
|
|
|
159
156
|
trigger.current = subscriber;
|
|
160
157
|
}).pipe(distinctUntilChanged()).subscribe(_mode => {
|
|
161
158
|
repaint(_mode);
|
|
159
|
+
setMode(_mode);
|
|
162
160
|
});
|
|
163
161
|
});
|
|
164
|
-
|
|
165
|
-
trigger.current?.next(mode);
|
|
166
|
-
}, [mode]);
|
|
167
|
-
/// dark, light mode switch
|
|
162
|
+
// dark, light mode switch
|
|
168
163
|
const toggle = useEvent(event => {
|
|
169
|
-
|
|
170
|
-
|
|
164
|
+
const modeSwitchTo = isDark ? "light" : "dark";
|
|
165
|
+
// dom not support animation
|
|
166
|
+
if (!isFunction(document.startViewTransition)) {
|
|
167
|
+
trigger.current?.next(modeSwitchTo);
|
|
171
168
|
return;
|
|
172
169
|
}
|
|
173
|
-
const x = event.clientX;
|
|
174
|
-
const y = event.clientY;
|
|
175
|
-
const radius = Math.hypot(Math.max(x, window.innerWidth - x), Math.max(y, window.innerHeight - y));
|
|
176
170
|
const animation = document.startViewTransition(() => {
|
|
177
|
-
trigger.current?.next(
|
|
171
|
+
trigger.current?.next(modeSwitchTo);
|
|
178
172
|
});
|
|
179
173
|
animation.ready.then(() => {
|
|
180
|
-
|
|
174
|
+
const x = event?.clientX ?? 0;
|
|
175
|
+
const y = event?.clientY ?? 0;
|
|
176
|
+
const radius = Math.hypot(Math.max(x, window.innerWidth - x), Math.max(y, window.innerHeight - y));
|
|
181
177
|
const clipPath = [`circle(0px at ${x}px ${y}px)`, `circle(${radius}px at ${x}px ${y}px)`];
|
|
182
178
|
document.documentElement.animate({
|
|
183
179
|
clipPath: isDark ? [...clipPath].reverse() : clipPath
|
|
@@ -191,7 +187,7 @@ const useSwitchable = ({
|
|
|
191
187
|
return {
|
|
192
188
|
mode,
|
|
193
189
|
toggle,
|
|
194
|
-
colors
|
|
190
|
+
colors
|
|
195
191
|
};
|
|
196
192
|
};
|
|
197
193
|
|
|
@@ -4,7 +4,11 @@ import type { TreeProps } from "./types";
|
|
|
4
4
|
* @description
|
|
5
5
|
* expanded keys
|
|
6
6
|
*/
|
|
7
|
-
export declare const useExpandedKeys: (
|
|
7
|
+
export declare const useExpandedKeys: ({ expandedKeys, onExpand, defaultExpandedKeys, }: {
|
|
8
|
+
expandedKeys?: Key[];
|
|
9
|
+
onExpand: TreeProps["onExpand"];
|
|
10
|
+
defaultExpandedKeys: Key[];
|
|
11
|
+
}) => {
|
|
8
12
|
expandedKeys: Set<Key>;
|
|
9
13
|
toggle: (key: Key) => void;
|
|
10
14
|
};
|
|
@@ -12,8 +16,10 @@ export declare const useExpandedKeys: ([expandedKeys, onExpand]: [TreeProps["exp
|
|
|
12
16
|
* @description
|
|
13
17
|
* selected keys
|
|
14
18
|
*/
|
|
15
|
-
export declare const useSelectedKeys: ({ selectedKeys: _selectedKeys }: {
|
|
19
|
+
export declare const useSelectedKeys: ({ selectedKeys: _selectedKeys, defaultSelectedKeys, onSelect, }: {
|
|
16
20
|
selectedKeys?: Key[];
|
|
21
|
+
defaultSelectedKeys: Key[];
|
|
22
|
+
onSelect?: (key: Key) => void;
|
|
17
23
|
}) => {
|
|
18
24
|
selectedKeys: Set<Key>;
|
|
19
25
|
toggle: (key: Key) => void;
|
|
@@ -5,14 +5,14 @@ import { useMemo, useCallback } from 'react';
|
|
|
5
5
|
* @description
|
|
6
6
|
* expanded keys
|
|
7
7
|
*/
|
|
8
|
-
const useExpandedKeys = (
|
|
9
|
-
const [_expandedKeys, _setExpandedKeys] = useControlledState(expandedKeys);
|
|
8
|
+
const useExpandedKeys = ({ expandedKeys, onExpand, defaultExpandedKeys, }) => {
|
|
9
|
+
const [_expandedKeys, _setExpandedKeys] = useControlledState(expandedKeys, { defaultState: defaultExpandedKeys });
|
|
10
10
|
const readableExpandedKeys = useMemo(() => new Set(_expandedKeys), [_expandedKeys]);
|
|
11
11
|
const toggle = useCallback((key) => {
|
|
12
12
|
// deal expanding key
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const expandingKeys = Array.from(
|
|
13
|
+
const _keys = new Set(_expandedKeys);
|
|
14
|
+
_keys.has(key) ? _keys.delete(key) : _keys.add(key);
|
|
15
|
+
const expandingKeys = Array.from(_keys);
|
|
16
16
|
// change inner state
|
|
17
17
|
// emit change handler
|
|
18
18
|
_setExpandedKeys(expandingKeys);
|
|
@@ -27,16 +27,15 @@ const useExpandedKeys = ([expandedKeys, onExpand]) => {
|
|
|
27
27
|
* @description
|
|
28
28
|
* selected keys
|
|
29
29
|
*/
|
|
30
|
-
const useSelectedKeys = ({ selectedKeys: _selectedKeys }) => {
|
|
31
|
-
const [selectedKeys, setSelectedKeys] = useControlledState(_selectedKeys);
|
|
32
|
-
const
|
|
30
|
+
const useSelectedKeys = ({ selectedKeys: _selectedKeys, defaultSelectedKeys, onSelect, }) => {
|
|
31
|
+
const [selectedKeys, setSelectedKeys] = useControlledState(_selectedKeys, { defaultState: defaultSelectedKeys });
|
|
32
|
+
const readableSelectedKeys = useMemo(() => new Set(selectedKeys), [selectedKeys]);
|
|
33
33
|
const toggle = useEvent((key) => {
|
|
34
|
-
setSelectedKeys(() =>
|
|
35
|
-
|
|
36
|
-
});
|
|
34
|
+
setSelectedKeys(() => [key]);
|
|
35
|
+
onSelect?.(key);
|
|
37
36
|
});
|
|
38
37
|
return {
|
|
39
|
-
selectedKeys:
|
|
38
|
+
selectedKeys: readableSelectedKeys,
|
|
40
39
|
toggle,
|
|
41
40
|
};
|
|
42
41
|
};
|
|
@@ -41,6 +41,7 @@ const styles = {
|
|
|
41
41
|
transitionProperty: null,
|
|
42
42
|
transitionTimingFunction: null,
|
|
43
43
|
transform: "musae-1v0jg1i",
|
|
44
|
+
userSelect: "musae-87ps6o",
|
|
44
45
|
$$css: true
|
|
45
46
|
}, {
|
|
46
47
|
"--transform": (props.isExpanded ? "rotate(90deg)" : null) != null ? props.isExpanded ? "rotate(90deg)" : null : "initial"
|
|
@@ -62,12 +63,17 @@ const styles = {
|
|
|
62
63
|
borderBottomRightRadius: null,
|
|
63
64
|
backgroundColor: "musae-8hsaj5 musae-rl4t6d",
|
|
64
65
|
color: "musae-19dipnz",
|
|
66
|
+
cursor: "musae-t0e3qv",
|
|
65
67
|
$$css: true
|
|
66
68
|
}, {
|
|
67
69
|
"--bcbnzo": (props.isSelected ? props.backgroundColor : null) != null ? props.isSelected ? props.backgroundColor : null : "initial",
|
|
68
70
|
"--1e2mv7m": props.hoveredBackgroundColor != null ? props.hoveredBackgroundColor : "initial",
|
|
69
71
|
"--color": (props.isSelected ? props.color : null) != null ? props.isSelected ? props.color : null : "initial"
|
|
70
|
-
}]
|
|
72
|
+
}],
|
|
73
|
+
selectable: {
|
|
74
|
+
cursor: "musae-1ypdohk",
|
|
75
|
+
$$css: true
|
|
76
|
+
}
|
|
71
77
|
};
|
|
72
78
|
const Node = ({
|
|
73
79
|
value,
|
|
@@ -98,7 +104,7 @@ const Node = ({
|
|
|
98
104
|
backgroundColor: theme.colors[ColorToken.SurfaceContainer],
|
|
99
105
|
hoveredBackgroundColor: theme.colors[ColorToken.SurfaceContainer],
|
|
100
106
|
color: theme.colors[ColorToken.Primary]
|
|
101
|
-
})),
|
|
107
|
+
}), selectable && styles.selectable),
|
|
102
108
|
expander: props(styles.expander({
|
|
103
109
|
isExpanded
|
|
104
110
|
}))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { TreeProps } from "./types";
|
|
3
|
-
declare const Tree: ({ expandedKeys: _expandedKeys,
|
|
3
|
+
declare const Tree: ({ className, style, nodes, selectable, expandedKeys: _expandedKeys, selectedKeys: _selectedKeys, checkedKeys: _checkedKeys, defaultExpandedKeys, defaultSelectedKeys, defaultCheckedKeys, onExpand, onSelect, onCheck, }: TreeProps) => React.JSX.Element;
|
|
4
4
|
export default Tree;
|
|
@@ -4,10 +4,22 @@ import Context from './context.js';
|
|
|
4
4
|
import { useTogglable } from '@aiszlab/relax';
|
|
5
5
|
import { useExpandedKeys, useSelectedKeys } from './hooks.js';
|
|
6
6
|
|
|
7
|
-
const Tree = ({
|
|
8
|
-
const { toggledKeys: checkedKeys, toggle: check } = useTogglable(nodes
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const Tree = ({ className, style, nodes, selectable = true, expandedKeys: _expandedKeys, selectedKeys: _selectedKeys, checkedKeys: _checkedKeys, defaultExpandedKeys = [], defaultSelectedKeys = [], defaultCheckedKeys = [], onExpand, onSelect, onCheck, }) => {
|
|
8
|
+
const { toggledKeys: checkedKeys, toggle: check } = useTogglable(nodes, {
|
|
9
|
+
defaultToggledKeys: defaultCheckedKeys,
|
|
10
|
+
toggledKeys: _checkedKeys,
|
|
11
|
+
onToggle: onCheck,
|
|
12
|
+
});
|
|
13
|
+
const { expandedKeys, toggle: expand } = useExpandedKeys({
|
|
14
|
+
expandedKeys: _expandedKeys,
|
|
15
|
+
onExpand,
|
|
16
|
+
defaultExpandedKeys,
|
|
17
|
+
});
|
|
18
|
+
const { selectedKeys, toggle: select } = useSelectedKeys({
|
|
19
|
+
selectedKeys: _selectedKeys,
|
|
20
|
+
defaultSelectedKeys,
|
|
21
|
+
onSelect,
|
|
22
|
+
});
|
|
11
23
|
const contextValue = useMemo(() => {
|
|
12
24
|
return {
|
|
13
25
|
checkedKeys,
|
|
@@ -38,6 +38,12 @@ export type TreeProps = ComponentProps & {
|
|
|
38
38
|
* @default void 0
|
|
39
39
|
*/
|
|
40
40
|
expandedKeys?: Key[];
|
|
41
|
+
/**
|
|
42
|
+
* @description
|
|
43
|
+
* default expanded keys
|
|
44
|
+
* @default []
|
|
45
|
+
*/
|
|
46
|
+
defaultExpandedKeys?: Key[];
|
|
41
47
|
/**
|
|
42
48
|
* @description
|
|
43
49
|
* expand handler
|
|
@@ -56,6 +62,36 @@ export type TreeProps = ComponentProps & {
|
|
|
56
62
|
* @default void 0
|
|
57
63
|
*/
|
|
58
64
|
selectedKeys?: Key[];
|
|
65
|
+
/**
|
|
66
|
+
* @description
|
|
67
|
+
* default selected keys
|
|
68
|
+
* @default []
|
|
69
|
+
*/
|
|
70
|
+
defaultSelectedKeys?: Key[];
|
|
71
|
+
/**
|
|
72
|
+
* @description
|
|
73
|
+
* select handler
|
|
74
|
+
* @default void 0
|
|
75
|
+
*/
|
|
76
|
+
onSelect?: (key: Key) => void;
|
|
77
|
+
/**
|
|
78
|
+
* @description
|
|
79
|
+
* checked keys
|
|
80
|
+
* @default void 0
|
|
81
|
+
*/
|
|
82
|
+
checkedKeys?: Key[];
|
|
83
|
+
/**
|
|
84
|
+
* @description
|
|
85
|
+
* default checked keys
|
|
86
|
+
* @default []
|
|
87
|
+
*/
|
|
88
|
+
defaultCheckedKeys?: Key[];
|
|
89
|
+
/**
|
|
90
|
+
* @description
|
|
91
|
+
* check handler
|
|
92
|
+
* @default void 0
|
|
93
|
+
*/
|
|
94
|
+
onCheck?: (keys: Key[]) => void;
|
|
59
95
|
};
|
|
60
96
|
/**
|
|
61
97
|
* @description
|
|
@@ -233,4 +233,15 @@ export declare const useClassNames: <T extends ComponentToken>(token: T) => {
|
|
|
233
233
|
2: string;
|
|
234
234
|
4: string;
|
|
235
235
|
};
|
|
236
|
+
40: {
|
|
237
|
+
0: string;
|
|
238
|
+
1: string;
|
|
239
|
+
};
|
|
240
|
+
41: {
|
|
241
|
+
0: string;
|
|
242
|
+
1: string;
|
|
243
|
+
};
|
|
244
|
+
42: {
|
|
245
|
+
0: string;
|
|
246
|
+
};
|
|
236
247
|
}[T];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { KeyboardEvent } from "react";
|
|
2
|
+
export type Closable = "esc" | "overlay" | "close";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* for dialog, close means some events or some elements
|
|
6
|
+
* in musae, we use a hook to handle this
|
|
7
|
+
*
|
|
8
|
+
* by default, closable may be different type, like `false` | ['esc'] | undefined
|
|
9
|
+
* resolve these types, we convert to `Set<Closable>`
|
|
10
|
+
*/
|
|
11
|
+
export declare const useClosable: ({ onClose, closable }: {
|
|
12
|
+
onClose?: VoidFunction;
|
|
13
|
+
closable: boolean | Closable[];
|
|
14
|
+
}) => {
|
|
15
|
+
closer: React.JSX.Element | null;
|
|
16
|
+
onOverlayClick: () => void;
|
|
17
|
+
onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => void;
|
|
18
|
+
};
|
|
@@ -6,22 +6,26 @@ import Close from '../components/icon/icons/navigation/close.js';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @description
|
|
9
|
-
* for dialog,
|
|
9
|
+
* for dialog, close means some events or some elements
|
|
10
10
|
* in musae, we use a hook to handle this
|
|
11
11
|
*
|
|
12
|
-
* by default,
|
|
13
|
-
* resolve these types, we convert to `Set<
|
|
12
|
+
* by default, closable may be different type, like `false` | ['esc'] | undefined
|
|
13
|
+
* resolve these types, we convert to `Set<Closable>`
|
|
14
14
|
*/
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const useClosable = ({
|
|
16
|
+
onClose,
|
|
17
|
+
closable
|
|
18
|
+
}) => {
|
|
19
|
+
// convert closable to enum sets
|
|
20
|
+
const triggers = useMemo(() => {
|
|
21
|
+
if (isUndefined(closable) || closable === true) {
|
|
18
22
|
return new Set(["close", "esc", "overlay"]);
|
|
19
23
|
}
|
|
20
|
-
return new Set(
|
|
21
|
-
}, [
|
|
22
|
-
|
|
24
|
+
return new Set(closable || []);
|
|
25
|
+
}, [closable]);
|
|
26
|
+
// closer react element for dialog
|
|
23
27
|
const closer = useMemo(() => {
|
|
24
|
-
if (!
|
|
28
|
+
if (!triggers.has("close")) return null;
|
|
25
29
|
const styled = {
|
|
26
30
|
className: "musae-9c655z musae-6al1c1"
|
|
27
31
|
};
|
|
@@ -29,7 +33,7 @@ const useDismissable = props => {
|
|
|
29
33
|
shape: "circular",
|
|
30
34
|
variant: "text",
|
|
31
35
|
prefix: React.createElement(Close, null),
|
|
32
|
-
onClick:
|
|
36
|
+
onClick: onClose,
|
|
33
37
|
className: styled.className,
|
|
34
38
|
style: {
|
|
35
39
|
...styled.style,
|
|
@@ -37,16 +41,16 @@ const useDismissable = props => {
|
|
|
37
41
|
},
|
|
38
42
|
size: "small"
|
|
39
43
|
});
|
|
40
|
-
}, [
|
|
44
|
+
}, [triggers, onClose]);
|
|
41
45
|
/// overlay click callback
|
|
42
46
|
const onOverlayClick = useEvent(() => {
|
|
43
|
-
if (!
|
|
44
|
-
|
|
47
|
+
if (!triggers.has("overlay")) return;
|
|
48
|
+
onClose?.();
|
|
45
49
|
});
|
|
46
50
|
/// esc key press callback
|
|
47
51
|
const onKeyDown = useEvent(e => {
|
|
48
52
|
if (e.key !== Keyboard.Escape) return;
|
|
49
|
-
|
|
53
|
+
onClose?.();
|
|
50
54
|
});
|
|
51
55
|
return {
|
|
52
56
|
closer,
|
|
@@ -55,4 +59,4 @@ const useDismissable = props => {
|
|
|
55
59
|
};
|
|
56
60
|
};
|
|
57
61
|
|
|
58
|
-
export {
|
|
62
|
+
export { useClosable };
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ export { Watermark } from "./components/watermark";
|
|
|
50
50
|
export { Collapse } from "./components/collapse";
|
|
51
51
|
export { FloatingActionButton } from "./components/floating-action-button";
|
|
52
52
|
export { Transfer } from "./components/transfer";
|
|
53
|
+
export { Badge } from "./components/badge";
|
|
54
|
+
export { Skeleton } from "./components/skeleton";
|
|
53
55
|
/**
|
|
54
56
|
* @description
|
|
55
57
|
* hooks
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,8 @@ export { default as Watermark } from './components/watermark/watermark.js';
|
|
|
47
47
|
export { default as Collapse } from './components/collapse/collapse.js';
|
|
48
48
|
export { default as FloatingActionButton } from './components/floating-action-button/floating-action-button.js';
|
|
49
49
|
export { default as Transfer } from './components/transfer/transfer.js';
|
|
50
|
+
export { default as Badge } from './components/badge/badge.js';
|
|
51
|
+
export { default as Skeleton } from './components/skeleton/skeleton.js';
|
|
50
52
|
export { useMessage } from './components/message/hooks.js';
|
|
51
53
|
export { useNotification } from './components/notification/hooks.js';
|
|
52
54
|
export { useTheme } from './components/theme/hooks.js';
|