@antscorp/antsomi-ui 1.3.5-beta.284 → 1.3.5-beta.285
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/components/molecules/DrawerDetail/DrawerDetail.js +32 -7
- package/es/components/molecules/DrawerDetail/constants.d.ts +2 -1
- package/es/components/molecules/DrawerDetail/constants.js +2 -1
- package/es/components/molecules/DrawerDetail/styled.d.ts +2 -0
- package/es/components/molecules/DrawerDetail/styled.js +17 -2
- package/es/components/molecules/DrawerDetail/types.d.ts +8 -2
- package/es/constants/theme.js +1 -0
- package/es/utils/common.d.ts +1 -0
- package/es/utils/common.js +10 -0
- package/package.json +1 -1
|
@@ -10,23 +10,27 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
// Libraries
|
|
13
|
+
import { ConfigProvider } from 'antd';
|
|
14
|
+
import { isNil } from 'lodash';
|
|
13
15
|
import React, { useEffect, useMemo } from 'react';
|
|
14
16
|
// Components
|
|
15
17
|
import { Flex, Icon, Tooltip } from '../../atoms';
|
|
16
18
|
// Styled
|
|
17
|
-
import { CloseBtn, Content, LeftMenu, MenuFooter, MenuItem, StyledDrawer } from './styled';
|
|
19
|
+
import { CloseBtn, Content, DrawerHeader, LeftMenu, MenuFooter, MenuItem, StyledDrawer, } from './styled';
|
|
18
20
|
// Constants
|
|
19
|
-
import { BREAK_POINT, DRAWER_LARGE_MAX_WIDTH, DRAWER_LARGE_MIN_WIDTH, DRAWER_SMALL_MAX_WIDTH, DRAWER_SMALL_MIN_WIDTH, } from './constants';
|
|
21
|
+
import { BREAK_POINT, DRAWER_DETAIL_LOCAL_STORAGE_KEY, DRAWER_LARGE_MAX_WIDTH, DRAWER_LARGE_MIN_WIDTH, DRAWER_SMALL_MAX_WIDTH, DRAWER_SMALL_MIN_WIDTH, } from './constants';
|
|
20
22
|
import { ToggleDrawerSizeButton } from './components';
|
|
21
23
|
// Hooks
|
|
22
24
|
import { useMediaQuery, useToggle } from '@antscorp/antsomi-ui/es/hooks';
|
|
23
|
-
|
|
25
|
+
// Utils
|
|
26
|
+
import { safeParseJson } from '@antscorp/antsomi-ui/es/utils';
|
|
24
27
|
export const DrawerDetail = props => {
|
|
25
28
|
// Props
|
|
26
|
-
const { width, fullScreen, children, menuProps, closeIconProps, maxWidth, minWidth, defaultSize = 'max' } = props, restProps = __rest(props, ["width", "fullScreen", "children", "menuProps", "closeIconProps", "maxWidth", "minWidth", "defaultSize"]);
|
|
29
|
+
const { width, fullScreen, children, menuProps, closeIconProps, maxWidth, minWidth, defaultSize = 'max', headerProps, name } = props, restProps = __rest(props, ["width", "fullScreen", "children", "menuProps", "closeIconProps", "maxWidth", "minWidth", "defaultSize", "headerProps", "name"]);
|
|
27
30
|
const { show: showMenu = true, showExpandButton = true, showClose = true, items, selectedKeys, footer, onClick = () => { }, } = menuProps || {};
|
|
31
|
+
const _a = headerProps || {}, { children: headerChildren } = _a, restOfHeaderProps = __rest(_a, ["children"]);
|
|
28
32
|
const { onClose = () => { } } = props;
|
|
29
|
-
const
|
|
33
|
+
const _b = closeIconProps || {}, { show: showCloseIcon, onClick: onCloseIconClick = () => { } } = _b, restOfCloseIcon = __rest(_b, ["show", "onClick"]);
|
|
30
34
|
// Hooks
|
|
31
35
|
const matchesSmallScreen = useMediaQuery(`(max-width: ${BREAK_POINT})`);
|
|
32
36
|
// State
|
|
@@ -46,6 +50,14 @@ export const DrawerDetail = props => {
|
|
|
46
50
|
break;
|
|
47
51
|
}
|
|
48
52
|
}, [matchesSmallScreen, defaultSize, toggleCollapseDrawer]);
|
|
53
|
+
// Get cache collapse from local storage
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const localStorageValues = safeParseJson(localStorage.getItem(DRAWER_DETAIL_LOCAL_STORAGE_KEY), {});
|
|
56
|
+
const cachedCollapse = localStorageValues[name || ''];
|
|
57
|
+
if (!isNil(cachedCollapse)) {
|
|
58
|
+
toggleCollapseDrawer(cachedCollapse);
|
|
59
|
+
}
|
|
60
|
+
}, [name, toggleCollapseDrawer]);
|
|
49
61
|
// Memo
|
|
50
62
|
const drawerWidth = useMemo(() => {
|
|
51
63
|
if (fullScreen)
|
|
@@ -75,6 +87,17 @@ export const DrawerDetail = props => {
|
|
|
75
87
|
}
|
|
76
88
|
}
|
|
77
89
|
}, [collapseDrawer, fullScreen, matchesSmallScreen, maxWidth, minWidth, width]);
|
|
90
|
+
// Handlers
|
|
91
|
+
const handleToggleDrawerSize = () => {
|
|
92
|
+
const localStorageValues = safeParseJson(localStorage.getItem(DRAWER_DETAIL_LOCAL_STORAGE_KEY), {});
|
|
93
|
+
toggleCollapseDrawer(!collapseDrawer);
|
|
94
|
+
/**
|
|
95
|
+
* Set local storage last collapsed
|
|
96
|
+
*/
|
|
97
|
+
if (name) {
|
|
98
|
+
localStorage.setItem(DRAWER_DETAIL_LOCAL_STORAGE_KEY, JSON.stringify(Object.assign(Object.assign({}, localStorageValues), { [name || '']: !collapseDrawer })));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
78
101
|
return (React.createElement(ConfigProvider, { theme: { components: { Drawer: { motionDurationSlow: '0ms' } } } },
|
|
79
102
|
React.createElement(StyledDrawer, Object.assign({}, restProps, { push: false, closable: false, width: drawerWidth, classNames: {
|
|
80
103
|
body: 'drawer-detail-body',
|
|
@@ -84,7 +107,7 @@ export const DrawerDetail = props => {
|
|
|
84
107
|
onClose(e);
|
|
85
108
|
} }),
|
|
86
109
|
React.createElement(Icon, { type: "icon-ants-remove-slim", size: 14 }))),
|
|
87
|
-
showExpandButton && !fullScreen && (React.createElement(ToggleDrawerSizeButton, { style: Object.assign({}, (!showMenu && { background: '#ffffff' })), onClick: () =>
|
|
110
|
+
showExpandButton && !fullScreen && (React.createElement(ToggleDrawerSizeButton, { style: Object.assign({}, (!showMenu && { background: '#ffffff' })), onClick: () => handleToggleDrawerSize(), collapse: collapseDrawer })),
|
|
88
111
|
showMenu && (React.createElement(LeftMenu, { className: "animate__animated animate__fadeIn" },
|
|
89
112
|
React.createElement("div", null,
|
|
90
113
|
showClose && (React.createElement(CloseBtn, { onClick: onClose },
|
|
@@ -92,6 +115,8 @@ export const DrawerDetail = props => {
|
|
|
92
115
|
React.createElement(Flex, { vertical: true, gap: 10, align: "center", justify: "center" }, items === null || items === void 0 ? void 0 : items.map((item) => (React.createElement(Tooltip, { key: item === null || item === void 0 ? void 0 : item.key, title: item === null || item === void 0 ? void 0 : item.label, mouseEnterDelay: 0.3 },
|
|
93
116
|
React.createElement(MenuItem, { key: item === null || item === void 0 ? void 0 : item.key, className: (selectedKeys === null || selectedKeys === void 0 ? void 0 : selectedKeys.includes(item.key)) ? 'active' : '', onClick: () => onClick && onClick(item) }, item.icon)))))),
|
|
94
117
|
React.createElement(MenuFooter, null, footer))),
|
|
95
|
-
React.createElement(Content, null,
|
|
118
|
+
React.createElement(Content, null,
|
|
119
|
+
(headerProps === null || headerProps === void 0 ? void 0 : headerProps.children) && (React.createElement(DrawerHeader, Object.assign({ align: "center" }, restOfHeaderProps), headerChildren)),
|
|
120
|
+
children))));
|
|
96
121
|
};
|
|
97
122
|
DrawerDetail.defaultProps = {};
|
|
@@ -4,10 +4,11 @@ declare const DRAWER_LARGE_MAX_WIDTH = "calc(100vw - 70px)";
|
|
|
4
4
|
declare const DRAWER_SMALL_MAX_WIDTH = "calc(100vw - 70px)";
|
|
5
5
|
declare const DRAWER_SMALL_MIN_WIDTH = "calc(100vw - 310px)";
|
|
6
6
|
declare const BREAK_POINT = "1440px";
|
|
7
|
+
declare const DRAWER_DETAIL_LOCAL_STORAGE_KEY = "drawer-detail-collapses";
|
|
7
8
|
declare const DRAWER_DETAIL_DIMENSION: {
|
|
8
9
|
LAYER_2: {
|
|
9
10
|
minWidth: string;
|
|
10
11
|
maxWidth: string;
|
|
11
12
|
};
|
|
12
13
|
};
|
|
13
|
-
export { DRAWER_MAX_WIDTH, DRAWER_LARGE_MIN_WIDTH, DRAWER_LARGE_MAX_WIDTH, DRAWER_SMALL_MAX_WIDTH, DRAWER_SMALL_MIN_WIDTH, BREAK_POINT, DRAWER_DETAIL_DIMENSION, };
|
|
14
|
+
export { DRAWER_MAX_WIDTH, DRAWER_LARGE_MIN_WIDTH, DRAWER_LARGE_MAX_WIDTH, DRAWER_SMALL_MAX_WIDTH, DRAWER_SMALL_MIN_WIDTH, BREAK_POINT, DRAWER_DETAIL_DIMENSION, DRAWER_DETAIL_LOCAL_STORAGE_KEY, };
|
|
@@ -4,6 +4,7 @@ const DRAWER_LARGE_MAX_WIDTH = 'calc(100vw - 70px)';
|
|
|
4
4
|
const DRAWER_SMALL_MAX_WIDTH = 'calc(100vw - 70px)';
|
|
5
5
|
const DRAWER_SMALL_MIN_WIDTH = 'calc(100vw - 310px)';
|
|
6
6
|
const BREAK_POINT = '1440px';
|
|
7
|
+
const DRAWER_DETAIL_LOCAL_STORAGE_KEY = 'drawer-detail-collapses';
|
|
7
8
|
const LAYER_2_MIN_WIDTH = '740px';
|
|
8
9
|
const LAYER_2_MAX_WIDTH = 'calc(100vw - 46px)';
|
|
9
10
|
const DRAWER_DETAIL_DIMENSION = {
|
|
@@ -12,4 +13,4 @@ const DRAWER_DETAIL_DIMENSION = {
|
|
|
12
13
|
maxWidth: LAYER_2_MAX_WIDTH,
|
|
13
14
|
},
|
|
14
15
|
};
|
|
15
|
-
export { DRAWER_MAX_WIDTH, DRAWER_LARGE_MIN_WIDTH, DRAWER_LARGE_MAX_WIDTH, DRAWER_SMALL_MAX_WIDTH, DRAWER_SMALL_MIN_WIDTH, BREAK_POINT, DRAWER_DETAIL_DIMENSION, };
|
|
16
|
+
export { DRAWER_MAX_WIDTH, DRAWER_LARGE_MIN_WIDTH, DRAWER_LARGE_MAX_WIDTH, DRAWER_SMALL_MAX_WIDTH, DRAWER_SMALL_MIN_WIDTH, BREAK_POINT, DRAWER_DETAIL_DIMENSION, DRAWER_DETAIL_LOCAL_STORAGE_KEY, };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { DrawerHeaderProps } from './types';
|
|
2
3
|
export declare const StyledDrawer: import("styled-components").StyledComponent<import("react").FC<import("@antscorp/antsomi-ui/es/components/molecules/Drawer/Drawer").DrawerProps>, any, {}, never>;
|
|
3
4
|
export declare const Content: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
5
|
export declare const LeftMenu: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
6
|
export declare const CloseBtn: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
7
|
export declare const MenuItem: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
8
|
+
export declare const DrawerHeader: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/flex/interface").FlexProps<import("antd/es/_util/type").AnyObject> & import("react").RefAttributes<HTMLElement>>, any, DrawerHeaderProps, never>;
|
|
7
9
|
export declare const MenuFooter: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import styled from 'styled-components';
|
|
3
|
+
// Components
|
|
4
|
+
import { Flex } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
3
5
|
// Drawer
|
|
4
6
|
import { Drawer } from '../Drawer';
|
|
5
7
|
import { globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
@@ -16,8 +18,8 @@ export const StyledDrawer = styled(Drawer) `
|
|
|
16
18
|
|
|
17
19
|
.close-btn {
|
|
18
20
|
position: absolute;
|
|
19
|
-
top:
|
|
20
|
-
right:
|
|
21
|
+
top: 20px;
|
|
22
|
+
right: 20px;
|
|
21
23
|
width: 24px;
|
|
22
24
|
height: 24px;
|
|
23
25
|
display: flex;
|
|
@@ -103,4 +105,17 @@ export const MenuItem = styled.div `
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
`;
|
|
108
|
+
export const DrawerHeader = styled(Flex) `
|
|
109
|
+
position: sticky;
|
|
110
|
+
top: 0px;
|
|
111
|
+
height: 64px;
|
|
112
|
+
padding: 0px 20px;
|
|
113
|
+
box-sizing: border-box;
|
|
114
|
+
background-color: ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw0};
|
|
115
|
+
z-index: 20;
|
|
116
|
+
|
|
117
|
+
${props => props.height &&
|
|
118
|
+
`height: ${typeof props.height === 'string' ? props.height : `${props.height}px`};`}
|
|
119
|
+
${props => props.showBorderBottom && `border-bottom: 1px solid ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw4};`}
|
|
120
|
+
`;
|
|
106
121
|
export const MenuFooter = styled.div ``;
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import type { DrawerProps, MenuProps as AntdProps } from 'antd';
|
|
2
|
+
import type { DrawerProps, MenuProps as AntdProps, FlexProps } from 'antd';
|
|
3
3
|
import { ItemType } from 'antd/es/menu/hooks/useItems';
|
|
4
4
|
export type TDefaultSize = 'max' | 'min';
|
|
5
|
-
export interface DrawerDetailProps extends Omit<DrawerProps, 'closeIcon'> {
|
|
5
|
+
export interface DrawerDetailProps extends Omit<DrawerProps, 'closeIcon' | 'title'> {
|
|
6
|
+
name?: string;
|
|
6
7
|
fullScreen?: boolean;
|
|
7
8
|
maxWidth?: string | number;
|
|
8
9
|
minWidth?: string | number;
|
|
9
10
|
defaultSize?: TDefaultSize;
|
|
11
|
+
headerProps?: DrawerHeaderProps;
|
|
10
12
|
menuProps?: DrawerDetailMenuProps;
|
|
11
13
|
closeIconProps?: DrawerDetailCloseIconProps;
|
|
12
14
|
}
|
|
13
15
|
export interface DrawerDetailCloseIconProps extends React.HtmlHTMLAttributes<HTMLDivElement> {
|
|
14
16
|
show?: boolean;
|
|
15
17
|
}
|
|
18
|
+
export interface DrawerHeaderProps extends FlexProps {
|
|
19
|
+
height?: React.CSSProperties['height'];
|
|
20
|
+
showBorderBottom?: boolean;
|
|
21
|
+
}
|
|
16
22
|
export interface DrawerDetailMenuProps extends Omit<AntdProps, 'onClick'> {
|
|
17
23
|
show?: boolean;
|
|
18
24
|
showExpandButton?: boolean;
|
package/es/constants/theme.js
CHANGED
package/es/utils/common.d.ts
CHANGED
|
@@ -85,3 +85,4 @@ export declare const simplifyString: (str: string) => string;
|
|
|
85
85
|
export declare const searchStringQuery: (str: string, queryStr: string) => boolean;
|
|
86
86
|
export declare const isExistedImage: (imageUrl: string) => boolean;
|
|
87
87
|
export declare const getUrlNoCache: (url?: string, cacheValue?: number | string) => string;
|
|
88
|
+
export declare const safeParseJson: (json?: string | null, defaultValue?: any) => any;
|
package/es/utils/common.js
CHANGED
|
@@ -492,3 +492,13 @@ export const getUrlNoCache = (url = '', cacheValue = 0) => {
|
|
|
492
492
|
}
|
|
493
493
|
return urlNoCache;
|
|
494
494
|
};
|
|
495
|
+
export const safeParseJson = (json, defaultValue) => {
|
|
496
|
+
if (!json)
|
|
497
|
+
return defaultValue;
|
|
498
|
+
try {
|
|
499
|
+
return JSON.parse(json);
|
|
500
|
+
}
|
|
501
|
+
catch (error) {
|
|
502
|
+
return defaultValue;
|
|
503
|
+
}
|
|
504
|
+
};
|