@antscorp/antsomi-ui 1.3.5-beta.211 → 1.3.5-beta.212

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.
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  interface MenuItemImageProps {
3
3
  imageUrl: string;
4
4
  fallbackIcon?: string | null;
5
+ className?: string;
5
6
  }
6
7
  export declare const MenuItemImage: React.FC<MenuItemImageProps>;
7
8
  export {};
@@ -2,8 +2,10 @@
2
2
  import React, { memo, useState } from 'react';
3
3
  import Icon from '@antscorp/icons';
4
4
  import { isNil } from 'lodash';
5
- import { Flex } from 'antd';
6
- export const MenuItemImage = memo(({ fallbackIcon, imageUrl }) => {
5
+ // Constants
6
+ import { MenuItemImageWrapper, MaskImage } from './styled';
7
+ export const MenuItemImage = memo(({ fallbackIcon, imageUrl, className }) => {
7
8
  const [isExistImage, setIsExistImage] = useState(true);
8
- return (React.createElement(Flex, { style: { marginRight: '10px' }, align: "center", justify: "center" }, isExistImage ? (React.createElement("img", { src: imageUrl, alt: "", onError: () => setIsExistImage(false) })) : isNil(fallbackIcon) ? null : (React.createElement(Icon, { type: fallbackIcon, style: { fontSize: 25 } }))));
9
+ return (React.createElement(MenuItemImageWrapper, { align: "center", justify: "center", className: className }, isExistImage ? (React.createElement(MaskImage, { url: imageUrl })) : // <img src={imageUrl} alt="" onError={() => setIsExistImage(false)} />
10
+ isNil(fallbackIcon) ? null : (React.createElement(Icon, { type: fallbackIcon }))));
9
11
  });
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export declare const MaskImage: import("styled-components").StyledComponent<"div", any, {
3
+ url: string;
4
+ }, never>;
5
+ export declare const MenuItemImageWrapper: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/flex/interface").FlexProps<import("antd/es/_util/type").AnyObject> & import("react").RefAttributes<HTMLElement>>, any, {}, never>;
@@ -0,0 +1,25 @@
1
+ var _a;
2
+ import styled from 'styled-components';
3
+ // Constants
4
+ import { ICON_SIZE } from '../../../../../constants';
5
+ import { THEME } from '@antscorp/antsomi-ui/es/constants';
6
+ // Components
7
+ import { Flex } from '../../../../../../../atoms';
8
+ export const MaskImage = styled.div `
9
+ width: ${ICON_SIZE}px;
10
+ height: ${ICON_SIZE}px;
11
+ background: black;
12
+ mask-size: contain;
13
+ mask-position: center center;
14
+ mask-repeat: no-repeat;
15
+ mask-image: ${({ url }) => `url(${url})`};
16
+ `;
17
+ export const MenuItemImageWrapper = styled(Flex) `
18
+ margin-right: '10px';
19
+
20
+ &.isActive {
21
+ ${MaskImage} {
22
+ background: ${(_a = THEME === null || THEME === void 0 ? void 0 : THEME.token) === null || _a === void 0 ? void 0 : _a.colorPrimary} !important;
23
+ }
24
+ }
25
+ `;
@@ -2,6 +2,7 @@
2
2
  import React, { memo, useEffect, useState } from 'react';
3
3
  import Icon from '@antscorp/icons';
4
4
  import { isEmpty, isNil, isString, uniq } from 'lodash';
5
+ import classNames from 'classnames';
5
6
  import { Link, useLocation } from 'react-router-dom';
6
7
  import { useContextSelector } from 'use-context-selector';
7
8
  // Components
@@ -91,7 +92,7 @@ export const ChildMenu = memo(props => {
91
92
  return {
92
93
  key,
93
94
  label: isString(menu_item_path) ? (isPushDifferentDomain(menu_item_domain, menu_item_path) ? (React.createElement("div", { onClick: () => navigatePath(menu_item_domain, menu_item_path), className: "menu-link" }, labelComponent())) : (React.createElement(Link, { to: getPath(menu_item_domain, menu_item_path), className: "menu-link" }, labelComponent()))) : (labelComponent()),
94
- icon: !isNil(icon) ? (React.createElement(Icon, { type: icon, style: { fontSize: ICON_SIZE } })) : !isNil(logo_url) ? (React.createElement(MenuItemImage, { imageUrl: logo_url, fallbackIcon: (_a = args === null || args === void 0 ? void 0 : args.parent) === null || _a === void 0 ? void 0 : _a.icon })) : null,
95
+ icon: !isNil(icon) ? (React.createElement(Icon, { type: icon, style: { fontSize: ICON_SIZE } })) : !isNil(logo_url) ? (React.createElement(MenuItemImage, { imageUrl: logo_url, fallbackIcon: (_a = args === null || args === void 0 ? void 0 : args.parent) === null || _a === void 0 ? void 0 : _a.icon, className: classNames({ isActive: currentActiveItem === key }) })) : null,
95
96
  children: customMenuItems({ parent: item, items: children }),
96
97
  };
97
98
  });
@@ -21,11 +21,6 @@ export const MenuWrapper = styled.div `
21
21
  margin: 0 !important;
22
22
  width: 100% !important;
23
23
 
24
- div {
25
- width: ${ICON_SIZE}px;
26
- height: ${ICON_SIZE}px;
27
- }
28
-
29
24
  [role='icon'] {
30
25
  font-size: ${ICON_SIZE}px !important;
31
26
  }
@@ -11,6 +11,7 @@ import { useGetDashboard, useGetDestinationChannel, useGetListMenu, useGetListMe
11
11
  import { findActiveAppCodeByUrl, findLastMatchedCodeByUrl, flattenMenuArray, getMappingAppChildren, recursivePermissionMenu, } from '../utils';
12
12
  // Store
13
13
  import { useLeftMenuStore } from '../stores';
14
+ import { POST_MESSAGE_TYPES } from '@antscorp/antsomi-ui/es/constants/postMessage';
14
15
  const initialState = {
15
16
  hoverItem: '',
16
17
  isExpandMenu: true,
@@ -60,7 +61,7 @@ export const useLeftMenu = (props) => {
60
61
  },
61
62
  },
62
63
  });
63
- const { data: dashboardData } = useGetDashboard({
64
+ const { data: dashboardData, refetch: refetchDashboard } = useGetDashboard({
64
65
  args: {
65
66
  auth: {
66
67
  token: auth === null || auth === void 0 ? void 0 : auth.token,
@@ -100,7 +101,25 @@ export const useLeftMenu = (props) => {
100
101
  dashboardData,
101
102
  destinationChannelEntries: destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries,
102
103
  }), [auth, dashboardData, destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries, permissionMenu]);
104
+ /* Handers */
105
+ const receivePostMessage = (event) => {
106
+ const { data } = event;
107
+ const { type } = data || {};
108
+ switch (type) {
109
+ case POST_MESSAGE_TYPES.REFETCH_DASHBOARD_LIST: {
110
+ refetchDashboard();
111
+ break;
112
+ }
113
+ default:
114
+ break;
115
+ }
116
+ };
103
117
  // Side Effects
118
+ // Receive Post Message
119
+ useEffect(() => {
120
+ window.addEventListener('message', receivePostMessage);
121
+ return () => window.removeEventListener('message', receivePostMessage);
122
+ }, []);
104
123
  /**
105
124
  * Change list menu children when hovering or activating items, giving priority to hovering items
106
125
  */
@@ -9,3 +9,4 @@ export * from './variables';
9
9
  export * from './permissions';
10
10
  export * from './queries';
11
11
  export * from './theme';
12
+ export * from './postMessage';
@@ -9,3 +9,4 @@ export * from './variables';
9
9
  export * from './permissions';
10
10
  export * from './queries';
11
11
  export * from './theme';
12
+ export * from './postMessage';
@@ -0,0 +1,3 @@
1
+ export declare const POST_MESSAGE_TYPES: {
2
+ REFETCH_DASHBOARD_LIST: string;
3
+ };
@@ -0,0 +1,3 @@
1
+ export const POST_MESSAGE_TYPES = {
2
+ REFETCH_DASHBOARD_LIST: 'REFETCH_DASHBOARD_LIST',
3
+ };
package/es/index.d.ts CHANGED
@@ -2,5 +2,5 @@ export * from './components';
2
2
  export * from './types';
3
3
  export * from './queries';
4
4
  export * from './providers';
5
- export { QUERY_KEYS } from './constants';
5
+ export { QUERY_KEYS, POST_MESSAGE_TYPES } from './constants';
6
6
  export { snakeCaseToCamelCase, camelCaseToSnakeCase, getCategoriesFromObjectTemplate, } from './utils';
package/es/index.js CHANGED
@@ -2,5 +2,5 @@ export * from './components';
2
2
  export * from './types';
3
3
  export * from './queries';
4
4
  export * from './providers';
5
- export { QUERY_KEYS } from './constants';
5
+ export { QUERY_KEYS, POST_MESSAGE_TYPES } from './constants';
6
6
  export { snakeCaseToCamelCase, camelCaseToSnakeCase, getCategoriesFromObjectTemplate, } from './utils';
@@ -20,6 +20,7 @@ export * from './service';
20
20
  export * from './templateListing';
21
21
  export * from './share-access';
22
22
  export * from './processingNotification';
23
+ export * from './postMessage';
23
24
  export type PayloadInfo = {
24
25
  url?: string;
25
26
  userId?: string;
package/es/types/index.js CHANGED
@@ -4,3 +4,4 @@ export * from './service';
4
4
  export * from './templateListing';
5
5
  export * from './share-access';
6
6
  export * from './processingNotification';
7
+ export * from './postMessage';
@@ -0,0 +1,4 @@
1
+ export interface IPostMessage {
2
+ type: string;
3
+ payload: any;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.211",
3
+ "version": "1.3.5-beta.212",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",