@antscorp/antsomi-ui 1.3.5-beta.293 → 1.3.5-beta.295

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.
@@ -10,23 +10,67 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { Scrollbars as CustomScrollbars, } from 'react-custom-scrollbars';
13
+ import { cloneDeep } from 'lodash';
13
14
  // Libraries
14
- import React from 'react';
15
+ import React, { useRef } from 'react';
15
16
  // Styled
16
17
  import { HorizontalTrack, ThumbBar, VerticalTrack } from './styled';
17
- import { cloneDeep } from 'lodash';
18
18
  const THUMB_SIZE = 4;
19
+ const MARGIN = 3;
19
20
  export const Scrollbars = props => {
21
+ // Props
20
22
  const { autoHide = true, autoHeightMax = 0 } = props, restProps = __rest(props, ["autoHide", "autoHeightMax"]);
21
- return (React.createElement(CustomScrollbars, Object.assign({ autoHide: autoHide, autoHeightMax: autoHeightMax, renderThumbVertical: props => React.createElement(ThumbBar, Object.assign({}, props)), renderThumbHorizontal: props => React.createElement(ThumbBar, Object.assign({}, props)), renderTrackVertical: props => React.createElement(VerticalTrack, Object.assign({}, props)), renderTrackHorizontal: props => React.createElement(HorizontalTrack, Object.assign({}, props)), renderView: props => {
23
+ // Refs
24
+ const ref = useRef(null);
25
+ /**
26
+ * Updates the size and position of the custom scrollbar thumbs based on the provided dimensions and scroll positions.
27
+ *
28
+ * @param {positionValues} values - An object containing the dimensions and scroll positions of the scrollable element:
29
+ * - {number} clientHeight - The visible height of the scrollable content area.
30
+ * - {number} clientWidth - The visible width of the scrollable content area.
31
+ * - {number} scrollHeight - The total height of the scrollable content.
32
+ * - {number} scrollWidth - The total width of the scrollable content.
33
+ * - {number} scrollLeft - The horizontal scroll position.
34
+ * - {number} scrollTop - The vertical scroll position.
35
+ */
36
+ const onUpdate = (values) => {
37
+ // Destructure the properties from the values object, using default values if undefined
38
+ const { clientHeight, clientWidth, scrollWidth, scrollHeight, scrollLeft, scrollTop } = values || {};
39
+ // Calculate the height of the vertical thumb, ensuring a minimum height of 30px
40
+ const thumbHeight = Math.max(Math.floor(clientHeight * (clientHeight / scrollHeight)), 30);
41
+ // Calculate the width of the horizontal thumb, ensuring a minimum width of 30px
42
+ const thumbWidth = Math.max(Math.floor(clientWidth * (clientWidth / scrollWidth)), 30);
43
+ // Calculate the vertical thumb's position based on the scrollTop value
44
+ const thumbVerticalPosition = (scrollTop / (scrollHeight - clientHeight)) * (clientHeight - thumbHeight) - MARGIN;
45
+ // Calculate the horizontal thumb's position based on the scrollLeft value
46
+ const thumbHorizontalPosition = (scrollLeft / (scrollWidth - clientWidth)) * (clientWidth - thumbWidth) - MARGIN;
47
+ // If the ref.current element is available, update the thumb styles
48
+ if (ref.current) {
49
+ ref.current.thumbVertical.style.height = `${thumbHeight}px`;
50
+ ref.current.thumbVertical.style.transform = `translateY(${thumbVerticalPosition}px)`;
51
+ ref.current.thumbHorizontal.style.width = `${thumbWidth}px`;
52
+ ref.current.thumbHorizontal.style.transform = `translateX(${thumbHorizontalPosition}px)`;
53
+ }
54
+ };
55
+ return (React.createElement(CustomScrollbars, Object.assign({ className: "custom-scrollbars", ref: ref, autoHide: autoHide, autoHeightMax: autoHeightMax, renderThumbVertical: props => React.createElement(ThumbBar, Object.assign({ className: "thumb-vertical" }, props)), renderThumbHorizontal: props => React.createElement(ThumbBar, Object.assign({ className: "thumb-horizontal" }, props)), renderTrackVertical: (_a) => {
56
+ var { style } = _a, restOfProps = __rest(_a, ["style"]);
57
+ return (React.createElement(VerticalTrack, Object.assign({ className: "scrollbar-track" }, restOfProps, { style: Object.assign(Object.assign({}, style), { display: 'block' }) })));
58
+ }, renderTrackHorizontal: (_a) => {
59
+ var { style } = _a, restOfProps = __rest(_a, ["style"]);
60
+ return (React.createElement(HorizontalTrack, Object.assign({ className: "scrollbar-track" }, restOfProps, { style: Object.assign(Object.assign({}, style), { display: 'block' }) })));
61
+ }, renderView: props => {
22
62
  const { style } = props || {};
23
63
  const newStyle = cloneDeep(style);
64
+ // Adjust the margins to account for the custom scrollbar size
24
65
  newStyle.marginBottom = -THUMB_SIZE;
25
66
  newStyle.marginRight = -THUMB_SIZE;
67
+ // Set a minimum height for the view to ensure space for the scrollbar
26
68
  newStyle.minHeight = THUMB_SIZE;
69
+ // If autoHeightMax is defined, adjust the maxHeight to include space for the scrollbar
27
70
  if (autoHeightMax) {
28
71
  newStyle.maxHeight = parseInt(`${autoHeightMax}`) + THUMB_SIZE;
29
72
  }
73
+ // Return a div element with the adjusted styles and original props, applying a custom class for styling
30
74
  return React.createElement("div", Object.assign({ className: "scrollbar-view" }, props, { style: newStyle }));
31
- }, hideTracksWhenNotNeeded: true }, restProps)));
75
+ }, onUpdate: onUpdate, hideTracksWhenNotNeeded: true }, restProps)));
32
76
  };
@@ -11,9 +11,8 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  // Libraries
13
13
  import React, { useMemo } from 'react';
14
- import { Scrollbars } from 'react-custom-scrollbars';
15
14
  // Components
16
- import { Input, Popover, Icon, Divider, Flex } from '@antscorp/antsomi-ui/es/components/atoms';
15
+ import { Input, Popover, Icon, Divider, Flex, Scrollbars, } from '@antscorp/antsomi-ui/es/components/atoms';
17
16
  import { Menu } from '@antscorp/antsomi-ui/es/components/organism';
18
17
  // Styled
19
18
  import { FilterSelectFieldsContent } from './styled';
@@ -99,7 +98,7 @@ export const SavedFilterAndMetrics = props => {
99
98
  !!removable && (React.createElement(IconButton, null,
100
99
  React.createElement(Icon, { type: "icon-ants-outline-delete" }))))),
101
100
  })) }));
102
- const renderFilterMetrics = () => React.createElement(Menu, { mode: "inline", items: filterMetricItems });
101
+ const renderFilterMetrics = () => (React.createElement(Menu, { mode: "inline", inlineIndent: 10, items: filterMetricItems }));
103
102
  const content = (React.createElement(FilterSelectFieldsContent, null,
104
103
  React.createElement(Input, { bordered: false, className: "search-input", autoFocus: true, suffix: React.createElement(Icon, { type: "icon-ants-search-2", size: 24 }) }),
105
104
  React.createElement(Divider, { style: { borderColor: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw3, margin: '8px 0 2px 0' } }),
@@ -1,3 +1,4 @@
1
+ import { globalToken } from '@antscorp/antsomi-ui/es/constants';
1
2
  export const DATA_TABLE_THEME = {
2
3
  token: {
3
4
  toolbarHeight: 54,
@@ -21,6 +22,7 @@ export const DATA_TABLE_THEME = {
21
22
  itemSelectedColor: '#000000',
22
23
  itemSelectedBg: '#DEEFFE',
23
24
  itemMarginBlock: 6,
25
+ subMenuItemBg: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw0,
24
26
  },
25
27
  },
26
28
  };
@@ -1 +1,2 @@
1
- export { Menu } from 'antd';
1
+ import { Menu } from 'antd';
2
+ export { Menu };
@@ -1,2 +1,14 @@
1
- export { Menu } from 'antd';
2
- // export default AntdMenu;
1
+ // Libraries
2
+ import React from 'react';
3
+ // Types
4
+ import { Menu } from 'antd';
5
+ // Constants
6
+ import { globalToken } from '@antscorp/antsomi-ui/es/constants';
7
+ import { ExpandIcon } from './styled';
8
+ Menu.defaultProps = {
9
+ expandIcon(props) {
10
+ const { isOpen } = props;
11
+ return (React.createElement(ExpandIcon, { "$isOpen": isOpen, type: "icon-ants-expand-more", size: 20, color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw8 }));
12
+ },
13
+ };
14
+ export { Menu };
@@ -0,0 +1,3 @@
1
+ export declare const ExpandIcon: import("styled-components").StyledComponent<any, any, import("@antscorp/antsomi-ui/es/components/atoms/Icon").IconProps & {
2
+ $isOpen?: boolean | undefined;
3
+ }, string | number | symbol>;
@@ -0,0 +1,10 @@
1
+ // Components
2
+ import styled from 'styled-components';
3
+ import { Icon } from '../../atoms';
4
+ export const ExpandIcon = styled(Icon) `
5
+ cursor: pointer;
6
+ position: absolute;
7
+ right: 10px;
8
+ transition: all 200ms;
9
+ transform: rotate(${props => (props.$isOpen ? 180 : 0)}deg);
10
+ `;
@@ -60,15 +60,13 @@ export const TemplateListing = memo(props => {
60
60
  onCancel === null || onCancel === void 0 ? void 0 : onCancel(e);
61
61
  setOpenPreviewModal(false);
62
62
  };
63
- return (
64
- /** The className "template-listing-wrapper" is used to detect dom in useListingItemResize hook */
65
- React.createElement(TemplateListingWrapper, { className: "template-listing-wrapper" },
63
+ return (React.createElement(TemplateListingWrapper, null,
66
64
  React.createElement(CategoryListing, Object.assign({}, categoryListingProps, { emptyProps: emptyProps })),
67
65
  React.createElement(TemplateWrapper, { className: wrapperClassName, style: wrapperStyle },
68
66
  header,
69
67
  React.createElement(Spin, { spinning: loading || !itemPerRow, wrapperClassName: "template-listing__loading template-listing__loading--full" },
70
68
  React.createElement(Scrollbars, { className: "template-listing" },
71
- React.createElement("div", { ref: containerRef, style: {
69
+ React.createElement("div", { className: "template-listing-container", ref: containerRef, style: {
72
70
  display: 'grid',
73
71
  gap: listingGap,
74
72
  gridTemplateColumns: `repeat(${itemPerRow}, minmax(0, 1fr))`,
@@ -41,6 +41,8 @@ export const useListingItemResize = (props) => {
41
41
  return DEFAULT_RATIO;
42
42
  }, [containerWidth, gap, initialWidth, itemPerRow]);
43
43
  useEffect(() => {
44
+ var _a;
45
+ const element = (_a = document.getElementsByClassName('template-listing-container')) === null || _a === void 0 ? void 0 : _a[0];
44
46
  let timeoutAfterChange = null;
45
47
  const handleResize = () => {
46
48
  if (timeoutAfterChange) {
@@ -48,11 +50,12 @@ export const useListingItemResize = (props) => {
48
50
  }
49
51
  timeoutAfterChange = setTimeout(() => {
50
52
  forceUpdate();
51
- }, 500);
53
+ }, 0);
52
54
  };
53
- window.addEventListener('resize', handleResize);
55
+ const resizeObserver = new ResizeObserver(handleResize);
56
+ if (element)
57
+ resizeObserver.observe(element);
54
58
  return () => {
55
- window.removeEventListener('resize', handleResize);
56
59
  if (timeoutAfterChange) {
57
60
  clearTimeout(timeoutAfterChange);
58
61
  }
@@ -41,6 +41,14 @@ export const GlobalStyle = () => {
41
41
  background: ${accent7};
42
42
  }
43
43
 
44
+ .custom-scrollbars {
45
+ &:hover {
46
+ .scrollbar-track {
47
+ opacity: 1 !important;
48
+ }
49
+ }
50
+ }
51
+
44
52
  .antsomi-scroll-box {
45
53
  overflow-y: auto;
46
54
  scrollbar-gutter: stable !important;
@@ -12,8 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  // Libraries
13
13
  import React, { useCallback, useMemo, useState } from 'react';
14
14
  // Components
15
- import { CDP_DATA_TABLE_SAMPLE, FILTER_METRICS, } from '../components/organism/DataTable';
16
- import { Scrollbars } from '../components';
15
+ import { DataTable, CDP_DATA_TABLE_SAMPLE, FILTER_METRICS, } from '../components/organism/DataTable';
17
16
  // Styled
18
17
  import { TableTestWrapper } from './styled';
19
18
  const columns = [
@@ -79,5 +78,31 @@ export const DataTableTest = props => {
79
78
  setState(prev => (Object.assign(Object.assign({}, prev), { tableCollapsed: collapsed })));
80
79
  }, []);
81
80
  return (React.createElement(TableTestWrapper, null,
82
- React.createElement(Scrollbars, { autoHeightMax: 200 }, Array.from({ length: 20 }).map((_, i) => (React.createElement("div", { key: i, style: { borderBottom: '1px solid red' } }, i))))));
81
+ React.createElement(DataTable, { table: {
82
+ columns,
83
+ dataSource,
84
+ rowSelection: {
85
+ selectedRowKeys: [],
86
+ },
87
+ }, filter: {
88
+ savedFilter: {
89
+ list: savedFilters,
90
+ onSelect: savedFilter => {
91
+ console.log(savedFilter);
92
+ },
93
+ },
94
+ filterMetrics,
95
+ }, toolbar: {
96
+ addButton: node => React.createElement("div", null, node),
97
+ actionButtons: {
98
+ SEARCH: {
99
+ // buttonProps: { disabled: true },
100
+ },
101
+ COLUMN: {},
102
+ },
103
+ collapse: {
104
+ collapsed: tableCollapsed,
105
+ onCollapse,
106
+ },
107
+ } })));
83
108
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.293",
3
+ "version": "1.3.5-beta.295",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",