@canlooks/can-ui 0.0.93 → 0.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/drawer/drawer.d.ts +3 -1
- package/dist/cjs/components/drawer/drawer.js +7 -1
- package/dist/cjs/components/treeSelect/treeSelect.js +4 -1
- package/dist/cjs/components/typography/typography.js +0 -6
- package/dist/esm/components/drawer/drawer.d.ts +3 -1
- package/dist/esm/components/drawer/drawer.js +7 -1
- package/dist/esm/components/treeSelect/treeSelect.js +4 -1
- package/dist/esm/components/typography/typography.js +1 -7
- package/package.json +1 -1
|
@@ -15,6 +15,8 @@ export interface DrawerProps extends Omit<OverlayBaseProps, 'title'> {
|
|
|
15
15
|
defaultOpen?: boolean;
|
|
16
16
|
onClose?(reason: DrawerCloseReason): void;
|
|
17
17
|
slideProps?: TransitionBaseProps<HTMLDivElement>;
|
|
18
|
+
onScrollToTop?(): void;
|
|
19
|
+
onScrollToBottom?(): void;
|
|
18
20
|
}
|
|
19
21
|
export type DrawerCloseReason = 'escape' | 'closed' | 'maskClicked';
|
|
20
|
-
export declare function Drawer({ title, footer, showClose, size, placement, maskClosable, escapeClosable, defaultOpen, open, onClose, slideProps, ...props }: DrawerProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare function Drawer({ title, footer, showClose, size, placement, maskClosable, escapeClosable, defaultOpen, open, onClose, slideProps, onScrollToTop, onScrollToBottom, ...props }: DrawerProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -16,7 +16,7 @@ const placementToDirection = {
|
|
|
16
16
|
top: 'down',
|
|
17
17
|
bottom: 'up'
|
|
18
18
|
};
|
|
19
|
-
function Drawer({ title, footer, showClose = true, size = { xs: '100%', sm: '75%', md: '50%', lg: '25%' }, placement = 'right', maskClosable = true, escapeClosable = true, defaultOpen = false, open, onClose, slideProps, ...props }) {
|
|
19
|
+
function Drawer({ title, footer, showClose = true, size = { xs: '100%', sm: '75%', md: '50%', lg: '25%' }, placement = 'right', maskClosable = true, escapeClosable = true, defaultOpen = false, open, onClose, slideProps, onScrollToTop, onScrollToBottom, ...props }) {
|
|
20
20
|
const [innerOpen, setInnerOpen] = (0, utils_1.useControlled)(defaultOpen, open);
|
|
21
21
|
const close = (reason) => {
|
|
22
22
|
onClose?.(reason);
|
|
@@ -38,6 +38,12 @@ function Drawer({ title, footer, showClose = true, size = { xs: '100%', sm: '75%
|
|
|
38
38
|
const onScroll = () => {
|
|
39
39
|
const el = bodyRef.current;
|
|
40
40
|
el.dataset.bordered = (el.scrollHeight > el.clientHeight && el.scrollTop > 0).toString();
|
|
41
|
+
if (el.scrollTop === 0) {
|
|
42
|
+
onScrollToTop?.();
|
|
43
|
+
}
|
|
44
|
+
else if (el.scrollTop === el.scrollHeight - el.clientHeight) {
|
|
45
|
+
onScrollToBottom?.();
|
|
46
|
+
}
|
|
41
47
|
};
|
|
42
48
|
(0, react_1.useEffect)(() => {
|
|
43
49
|
if (innerOpen.current) {
|
|
@@ -14,6 +14,7 @@ const treeSelect_style_1 = require("./treeSelect.style");
|
|
|
14
14
|
const selectionContext_1 = require("../selectionContext");
|
|
15
15
|
const icon_1 = require("../icon");
|
|
16
16
|
const faChevronDown_1 = require("@fortawesome/free-solid-svg-icons/faChevronDown");
|
|
17
|
+
const placeholder_1 = require("../placeholder");
|
|
17
18
|
exports.TreeSelect = (0, react_1.memo)(({ inputProps, popperProps, popperRef, nodes, options, defaultValue, value, onChange, sizeAdaptable, loading, defaultOpen, open, onOpenChange, renderBackfill,
|
|
18
19
|
// 以下属性转发至<InputBase/>
|
|
19
20
|
placeholder = '请选择', autoFocus, clearable, onClear, ...props }) => {
|
|
@@ -71,7 +72,9 @@ placeholder = '请选择', autoFocus, clearable, onClear, ...props }) => {
|
|
|
71
72
|
}
|
|
72
73
|
return ((0, jsx_runtime_1.jsx)("div", { className: treeSelect_style_1.classes.backfillWrap, children: optionsMap.get(innerValue)?.[props.labelKey] ?? innerValue }));
|
|
73
74
|
};
|
|
74
|
-
return ((0, jsx_runtime_1.jsx)(popper_1.Popper, { css: popper_style_1.popperStyle, open: innerOpen.current, onOpenChange: openChangeHandler, placement: "bottom", variant: "collapse", trigger: ['click', 'enter'], disabled: props.disabled || props.readOnly, sizeAdaptable: sizeAdaptable, content:
|
|
75
|
+
return ((0, jsx_runtime_1.jsx)(popper_1.Popper, { css: popper_style_1.popperStyle, open: innerOpen.current, onOpenChange: openChangeHandler, placement: "bottom", variant: "collapse", trigger: ['click', 'enter'], disabled: props.disabled || props.readOnly, sizeAdaptable: sizeAdaptable, content: options?.length
|
|
76
|
+
? (0, jsx_runtime_1.jsx)(tree_1.Tree, { primaryKey: "value", ...props, nodes: options, value: innerValue, onChange: setInnerValue })
|
|
77
|
+
: (0, jsx_runtime_1.jsx)(placeholder_1.Placeholder, {}), ...popperProps, popperRef: popperRef, onPointerDown: e => {
|
|
75
78
|
popperProps?.onPointerDown?.(e);
|
|
76
79
|
e.preventDefault();
|
|
77
80
|
}, children: (0, jsx_runtime_1.jsx)(inputBase_1.InputBase, { clearable: !!props.multiple, css: treeSelect_style_1.style, className: (0, utils_1.clsx)(treeSelect_style_1.classes.root, props.className), "data-focused": open, value: innerValue, onClear: clearHandler, placeholder: placeholder, autoFocus: autoFocus, disabled: props.disabled, readOnly: props.readOnly, children: inputBaseProps => (0, jsx_runtime_1.jsxs)("div", { className: treeSelect_style_1.classes.contentWrap, children: [(0, utils_1.isNoValue)(innerValue)
|
|
@@ -59,12 +59,6 @@ exports.Typography = (0, react_1.memo)(({ component: Component = 'p', color = 't
|
|
|
59
59
|
* 省略
|
|
60
60
|
*/
|
|
61
61
|
const [expanded, setExpanded] = (0, react_1.useState)(false);
|
|
62
|
-
(0, react_1.useLayoutEffect)(() => {
|
|
63
|
-
if (textRef.current && ellipsisRows > 1) {
|
|
64
|
-
const { lineHeight } = getComputedStyle(textRef.current);
|
|
65
|
-
textRef.current.style.height = parseFloat(lineHeight) * ellipsisRows + 'px';
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
62
|
const style = (0, typography_style_1.useStyle)({ color: color || 'text.primary' });
|
|
69
63
|
const EditComponent = multipleRows ? textarea_1.Textarea : input_1.Input;
|
|
70
64
|
return editing
|
|
@@ -15,6 +15,8 @@ export interface DrawerProps extends Omit<OverlayBaseProps, 'title'> {
|
|
|
15
15
|
defaultOpen?: boolean;
|
|
16
16
|
onClose?(reason: DrawerCloseReason): void;
|
|
17
17
|
slideProps?: TransitionBaseProps<HTMLDivElement>;
|
|
18
|
+
onScrollToTop?(): void;
|
|
19
|
+
onScrollToBottom?(): void;
|
|
18
20
|
}
|
|
19
21
|
export type DrawerCloseReason = 'escape' | 'closed' | 'maskClicked';
|
|
20
|
-
export declare function Drawer({ title, footer, showClose, size, placement, maskClosable, escapeClosable, defaultOpen, open, onClose, slideProps, ...props }: DrawerProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare function Drawer({ title, footer, showClose, size, placement, maskClosable, escapeClosable, defaultOpen, open, onClose, slideProps, onScrollToTop, onScrollToBottom, ...props }: DrawerProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -13,7 +13,7 @@ const placementToDirection = {
|
|
|
13
13
|
top: 'down',
|
|
14
14
|
bottom: 'up'
|
|
15
15
|
};
|
|
16
|
-
export function Drawer({ title, footer, showClose = true, size = { xs: '100%', sm: '75%', md: '50%', lg: '25%' }, placement = 'right', maskClosable = true, escapeClosable = true, defaultOpen = false, open, onClose, slideProps, ...props }) {
|
|
16
|
+
export function Drawer({ title, footer, showClose = true, size = { xs: '100%', sm: '75%', md: '50%', lg: '25%' }, placement = 'right', maskClosable = true, escapeClosable = true, defaultOpen = false, open, onClose, slideProps, onScrollToTop, onScrollToBottom, ...props }) {
|
|
17
17
|
const [innerOpen, setInnerOpen] = useControlled(defaultOpen, open);
|
|
18
18
|
const close = (reason) => {
|
|
19
19
|
onClose?.(reason);
|
|
@@ -35,6 +35,12 @@ export function Drawer({ title, footer, showClose = true, size = { xs: '100%', s
|
|
|
35
35
|
const onScroll = () => {
|
|
36
36
|
const el = bodyRef.current;
|
|
37
37
|
el.dataset.bordered = (el.scrollHeight > el.clientHeight && el.scrollTop > 0).toString();
|
|
38
|
+
if (el.scrollTop === 0) {
|
|
39
|
+
onScrollToTop?.();
|
|
40
|
+
}
|
|
41
|
+
else if (el.scrollTop === el.scrollHeight - el.clientHeight) {
|
|
42
|
+
onScrollToBottom?.();
|
|
43
|
+
}
|
|
38
44
|
};
|
|
39
45
|
useEffect(() => {
|
|
40
46
|
if (innerOpen.current) {
|
|
@@ -11,6 +11,7 @@ import { classes, style } from './treeSelect.style';
|
|
|
11
11
|
import { useSelection } from '../selectionContext';
|
|
12
12
|
import { Icon } from '../icon';
|
|
13
13
|
import { faChevronDown } from '@fortawesome/free-solid-svg-icons/faChevronDown';
|
|
14
|
+
import { Placeholder } from '../placeholder';
|
|
14
15
|
export const TreeSelect = memo(({ inputProps, popperProps, popperRef, nodes, options, defaultValue, value, onChange, sizeAdaptable, loading, defaultOpen, open, onOpenChange, renderBackfill,
|
|
15
16
|
// 以下属性转发至<InputBase/>
|
|
16
17
|
placeholder = '请选择', autoFocus, clearable, onClear, ...props }) => {
|
|
@@ -68,7 +69,9 @@ placeholder = '请选择', autoFocus, clearable, onClear, ...props }) => {
|
|
|
68
69
|
}
|
|
69
70
|
return (_jsx("div", { className: classes.backfillWrap, children: optionsMap.get(innerValue)?.[props.labelKey] ?? innerValue }));
|
|
70
71
|
};
|
|
71
|
-
return (_jsx(Popper, { css: popperStyle, open: innerOpen.current, onOpenChange: openChangeHandler, placement: "bottom", variant: "collapse", trigger: ['click', 'enter'], disabled: props.disabled || props.readOnly, sizeAdaptable: sizeAdaptable, content:
|
|
72
|
+
return (_jsx(Popper, { css: popperStyle, open: innerOpen.current, onOpenChange: openChangeHandler, placement: "bottom", variant: "collapse", trigger: ['click', 'enter'], disabled: props.disabled || props.readOnly, sizeAdaptable: sizeAdaptable, content: options?.length
|
|
73
|
+
? _jsx(Tree, { primaryKey: "value", ...props, nodes: options, value: innerValue, onChange: setInnerValue })
|
|
74
|
+
: _jsx(Placeholder, {}), ...popperProps, popperRef: popperRef, onPointerDown: e => {
|
|
72
75
|
popperProps?.onPointerDown?.(e);
|
|
73
76
|
e.preventDefault();
|
|
74
77
|
}, children: _jsx(InputBase, { clearable: !!props.multiple, css: style, className: clsx(classes.root, props.className), "data-focused": open, value: innerValue, onClear: clearHandler, placeholder: placeholder, autoFocus: autoFocus, disabled: props.disabled, readOnly: props.readOnly, children: inputBaseProps => _jsxs("div", { className: classes.contentWrap, children: [isNoValue(innerValue)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { memo,
|
|
2
|
+
import { memo, useRef, useState } from 'react';
|
|
3
3
|
import { clsx, cloneRef, useUnmounted } from '../../utils';
|
|
4
4
|
import { useStyle, classes, editStyle } from './typography.style';
|
|
5
5
|
import { Button } from '../button';
|
|
@@ -56,12 +56,6 @@ export const Typography = memo(({ component: Component = 'p', color = 'text.prim
|
|
|
56
56
|
* 省略
|
|
57
57
|
*/
|
|
58
58
|
const [expanded, setExpanded] = useState(false);
|
|
59
|
-
useLayoutEffect(() => {
|
|
60
|
-
if (textRef.current && ellipsisRows > 1) {
|
|
61
|
-
const { lineHeight } = getComputedStyle(textRef.current);
|
|
62
|
-
textRef.current.style.height = parseFloat(lineHeight) * ellipsisRows + 'px';
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
59
|
const style = useStyle({ color: color || 'text.primary' });
|
|
66
60
|
const EditComponent = multipleRows ? Textarea : Input;
|
|
67
61
|
return editing
|