@canlooks/can-ui 0.0.165 → 0.0.166

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.
@@ -1,8 +1,10 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { OverlayBaseProps } from '../overlayBase';
3
- import { ResponsiveProp } from '../../types';
3
+ import { DivProps, ResponsiveProp, SlotsAndProps } from '../../types';
4
4
  import { TransitionBaseProps } from '../transitionBase';
5
- export interface DrawerProps extends Omit<OverlayBaseProps, 'title'> {
5
+ export interface DrawerProps extends Omit<OverlayBaseProps, 'title'>, SlotsAndProps<{
6
+ scroller: DivProps;
7
+ }> {
6
8
  title?: ReactNode;
7
9
  footer?: ReactNode;
8
10
  showClose?: ReactNode;
@@ -21,4 +23,4 @@ export interface DrawerProps extends Omit<OverlayBaseProps, 'title'> {
21
23
  onScrollToBottom?(): void;
22
24
  }
23
25
  export type DrawerCloseReason = 'escape' | 'closed' | 'maskClicked';
24
- export declare function Drawer({ title, footer, showClose, size, placement, maskClosable, escapeClosable, defaultOpen, open, onClose, slideProps, onScrollToTop, toBottomThreshold, onScrollToBottom, ...props }: DrawerProps): import("@emotion/react/jsx-runtime").JSX.Element;
26
+ export declare function Drawer({ slots, slotProps, title, footer, showClose, size, placement, maskClosable, escapeClosable, defaultOpen, open, onClose, slideProps, onScrollToTop, toBottomThreshold, 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, onScrollToTop, toBottomThreshold = 5, onScrollToBottom, ...props }) {
19
+ function Drawer({ slots = {}, slotProps = {}, 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, toBottomThreshold = 5, onScrollToBottom, ...props }) {
20
20
  const [innerOpen, setInnerOpen] = (0, utils_1.useControlled)(defaultOpen, open);
21
21
  const close = (reason) => {
22
22
  onClose?.(reason);
@@ -46,7 +46,7 @@ function Drawer({ title, footer, showClose = true, size = { xs: '100%', sm: '75%
46
46
  }
47
47
  };
48
48
  (0, react_1.useEffect)(() => {
49
- if (innerOpen.current) {
49
+ if (innerOpen.current && bodyWrapRef.current) {
50
50
  const resizeObserver = new ResizeObserver(onScroll);
51
51
  resizeObserver.observe(bodyWrapRef.current);
52
52
  return () => {
@@ -55,6 +55,8 @@ function Drawer({ title, footer, showClose = true, size = { xs: '100%', sm: '75%
55
55
  }
56
56
  return;
57
57
  }, [innerOpen.current]);
58
+ const { scroller: Scroller = 'div' } = slots;
59
+ const { scroller: scrollerProps } = slotProps;
58
60
  return ((0, jsx_runtime_1.jsx)(overlayBase_1.OverlayBase, { ...props, css: (0, drawer_style_1.useStyle)({ size: typeof size === 'object' ? size : { xs: size } }), className: (0, utils_1.clsx)(drawer_style_1.classes.root, props.className), open: innerOpen.current, onMaskClick: onMaskClick, "data-placement": placement, children: (0, jsx_runtime_1.jsx)(transitionBase_1.Slide, { direction: placementToDirection[placement], ...slideProps, in: innerOpen.current, className: (0, utils_1.clsx)(drawer_style_1.classes.drawer, slideProps?.className), children: (0, jsx_runtime_1.jsxs)("div", { className: drawer_style_1.classes.drawerWrap, children: [!!(title || showClose) &&
59
61
  (0, jsx_runtime_1.jsxs)("div", { className: drawer_style_1.classes.titleRow, children: [(0, jsx_runtime_1.jsx)("div", { className: drawer_style_1.classes.title, children: title }), showClose &&
60
62
  (0, jsx_runtime_1.jsx)(button_1.Button, { className: drawer_style_1.classes.close, shape: "circular", variant: "text", color: "text.secondary", onClick: closeHandler, children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faAnglesRight_1.faAnglesRight, style: {
@@ -64,5 +66,9 @@ function Drawer({ title, footer, showClose = true, size = { xs: '100%', sm: '75%
64
66
  top: '-90deg',
65
67
  bottom: '90deg',
66
68
  }[placement]
67
- } }) })] }), (0, jsx_runtime_1.jsx)("div", { ref: bodyRef, className: drawer_style_1.classes.body, onScroll: onScroll, children: (0, jsx_runtime_1.jsx)("div", { ref: bodyWrapRef, className: drawer_style_1.classes.bodyWrap, children: props.children }) })] }) }) }));
69
+ } }) })] }), (0, jsx_runtime_1.jsx)(Scroller, { ...(0, utils_1.mergeComponentProps)(scrollerProps, {
70
+ ref: bodyRef,
71
+ className: drawer_style_1.classes.body,
72
+ onScroll
73
+ }), children: (0, jsx_runtime_1.jsx)("div", { ref: bodyWrapRef, className: drawer_style_1.classes.bodyWrap, children: props.children }) })] }) }) }));
68
74
  }
@@ -1,8 +1,10 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { OverlayBaseProps } from '../overlayBase/index.js';
3
- import { ResponsiveProp } from '../../types.js';
3
+ import { DivProps, ResponsiveProp, SlotsAndProps } from '../../types.js';
4
4
  import { TransitionBaseProps } from '../transitionBase/index.js';
5
- export interface DrawerProps extends Omit<OverlayBaseProps, 'title'> {
5
+ export interface DrawerProps extends Omit<OverlayBaseProps, 'title'>, SlotsAndProps<{
6
+ scroller: DivProps;
7
+ }> {
6
8
  title?: ReactNode;
7
9
  footer?: ReactNode;
8
10
  showClose?: ReactNode;
@@ -21,4 +23,4 @@ export interface DrawerProps extends Omit<OverlayBaseProps, 'title'> {
21
23
  onScrollToBottom?(): void;
22
24
  }
23
25
  export type DrawerCloseReason = 'escape' | 'closed' | 'maskClicked';
24
- export declare function Drawer({ title, footer, showClose, size, placement, maskClosable, escapeClosable, defaultOpen, open, onClose, slideProps, onScrollToTop, toBottomThreshold, onScrollToBottom, ...props }: DrawerProps): import("@emotion/react/jsx-runtime").JSX.Element;
26
+ export declare function Drawer({ slots, slotProps, title, footer, showClose, size, placement, maskClosable, escapeClosable, defaultOpen, open, onClose, slideProps, onScrollToTop, toBottomThreshold, onScrollToBottom, ...props }: DrawerProps): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  import { useEffect, useRef } from 'react';
3
3
  import { classes, useStyle } from './drawer.style.js';
4
- import { clsx, useControlled } from '../../utils/index.js';
4
+ import { clsx, mergeComponentProps, useControlled } from '../../utils/index.js';
5
5
  import { OverlayBase } from '../overlayBase/index.js';
6
6
  import { Button } from '../button/index.js';
7
7
  import { Slide } from '../transitionBase/index.js';
@@ -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, onScrollToTop, toBottomThreshold = 5, onScrollToBottom, ...props }) {
16
+ export function Drawer({ slots = {}, slotProps = {}, 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, toBottomThreshold = 5, onScrollToBottom, ...props }) {
17
17
  const [innerOpen, setInnerOpen] = useControlled(defaultOpen, open);
18
18
  const close = (reason) => {
19
19
  onClose?.(reason);
@@ -43,7 +43,7 @@ export function Drawer({ title, footer, showClose = true, size = { xs: '100%', s
43
43
  }
44
44
  };
45
45
  useEffect(() => {
46
- if (innerOpen.current) {
46
+ if (innerOpen.current && bodyWrapRef.current) {
47
47
  const resizeObserver = new ResizeObserver(onScroll);
48
48
  resizeObserver.observe(bodyWrapRef.current);
49
49
  return () => {
@@ -52,6 +52,8 @@ export function Drawer({ title, footer, showClose = true, size = { xs: '100%', s
52
52
  }
53
53
  return;
54
54
  }, [innerOpen.current]);
55
+ const { scroller: Scroller = 'div' } = slots;
56
+ const { scroller: scrollerProps } = slotProps;
55
57
  return (_jsx(OverlayBase, { ...props, css: useStyle({ size: typeof size === 'object' ? size : { xs: size } }), className: clsx(classes.root, props.className), open: innerOpen.current, onMaskClick: onMaskClick, "data-placement": placement, children: _jsx(Slide, { direction: placementToDirection[placement], ...slideProps, in: innerOpen.current, className: clsx(classes.drawer, slideProps?.className), children: _jsxs("div", { className: classes.drawerWrap, children: [!!(title || showClose) &&
56
58
  _jsxs("div", { className: classes.titleRow, children: [_jsx("div", { className: classes.title, children: title }), showClose &&
57
59
  _jsx(Button, { className: classes.close, shape: "circular", variant: "text", color: "text.secondary", onClick: closeHandler, children: _jsx(Icon, { icon: faAnglesRight, style: {
@@ -61,5 +63,9 @@ export function Drawer({ title, footer, showClose = true, size = { xs: '100%', s
61
63
  top: '-90deg',
62
64
  bottom: '90deg',
63
65
  }[placement]
64
- } }) })] }), _jsx("div", { ref: bodyRef, className: classes.body, onScroll: onScroll, children: _jsx("div", { ref: bodyWrapRef, className: classes.bodyWrap, children: props.children }) })] }) }) }));
66
+ } }) })] }), _jsx(Scroller, { ...mergeComponentProps(scrollerProps, {
67
+ ref: bodyRef,
68
+ className: classes.body,
69
+ onScroll
70
+ }), children: _jsx("div", { ref: bodyWrapRef, className: classes.bodyWrap, children: props.children }) })] }) }) }));
65
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.165",
3
+ "version": "0.0.166",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",
@@ -46,7 +46,6 @@
46
46
  "test:unit": "npx ts-node test/unit.ts"
47
47
  },
48
48
  "dependencies": {
49
- "@dnd-kit/helpers": "^0.3.2",
50
49
  "@dnd-kit/react": "^0.3.2",
51
50
  "@emotion/react": "^11.14.0",
52
51
  "@fortawesome/free-brands-svg-icons": "^7.2.0",