@antscorp/antsomi-ui 1.3.5-beta.540 → 1.3.5-beta.541
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/atoms/Iframe/Iframe.d.ts +4 -0
- package/es/components/atoms/Iframe/Iframe.js +63 -0
- package/es/components/atoms/Iframe/index.d.ts +1 -0
- package/es/components/atoms/Iframe/index.js +1 -0
- package/es/components/molecules/SelectAccount/AccountList.js +2 -2
- package/es/components/molecules/SelectAccount/ButtonAdd.js +1 -1
- package/es/components/molecules/SelectAccount/context/SelectAccountContext.js +11 -8
- package/es/components/molecules/SelectAccount/context/reducer.js +38 -5
- package/es/components/molecules/SelectAccount/index.js +3 -0
- package/es/components/molecules/SelectAccount/type.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
// Libraries
|
|
13
|
+
import clsx from 'clsx';
|
|
14
|
+
import React, { useEffect, useRef } from 'react';
|
|
15
|
+
// Constants
|
|
16
|
+
import { globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
17
|
+
// Styled
|
|
18
|
+
import styled from 'styled-components';
|
|
19
|
+
const StyledIframe = styled.iframe `
|
|
20
|
+
border: none;
|
|
21
|
+
`;
|
|
22
|
+
export const Iframe = props => {
|
|
23
|
+
const { children, className } = props, restProps = __rest(props, ["children", "className"]);
|
|
24
|
+
// Ref
|
|
25
|
+
const iframeRef = useRef(null);
|
|
26
|
+
// Effects
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const iframe = iframeRef.current;
|
|
29
|
+
const handleLoad = () => {
|
|
30
|
+
var _a;
|
|
31
|
+
const iframeDoc = iframe.contentDocument || ((_a = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.document);
|
|
32
|
+
const style = document.createElement('style');
|
|
33
|
+
style.innerHTML = `
|
|
34
|
+
::-webkit-scrollbar {
|
|
35
|
+
background-color: transparent;
|
|
36
|
+
width: 4px;
|
|
37
|
+
}
|
|
38
|
+
::-webkit-scrollbar-thumb {
|
|
39
|
+
background-color: transparent;
|
|
40
|
+
border-radius: 4px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
*:hover {
|
|
44
|
+
&::-webkit-scrollbar-thumb {
|
|
45
|
+
background-color: ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.gray5};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
if (iframeDoc) {
|
|
50
|
+
iframeDoc.head.appendChild(style);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
if (iframe) {
|
|
54
|
+
iframe.addEventListener('load', handleLoad);
|
|
55
|
+
}
|
|
56
|
+
return () => {
|
|
57
|
+
if (iframe) {
|
|
58
|
+
iframe.removeEventListener('load', handleLoad);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}, []);
|
|
62
|
+
return (React.createElement(StyledIframe, Object.assign({}, restProps, { className: clsx('antsomi-iframe', className), ref: iframeRef })));
|
|
63
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Iframe';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Iframe';
|
|
@@ -50,7 +50,7 @@ const AccountList = () => {
|
|
|
50
50
|
React.createElement("div", { id: "account-list" }))) : (React.createElement(AccountListContent, { style: { marginTop: 15 } }, usersDisplay === null || usersDisplay === void 0 ? void 0 : usersDisplay.map(item => (React.createElement(CheckboxStyled, { key: item === null || item === void 0 ? void 0 : item[userIdKey], name: item === null || item === void 0 ? void 0 : item[userIdKey], value: typeof (item === null || item === void 0 ? void 0 : item[userIdKey]), disabled: disabledAccount === null || disabledAccount === void 0 ? void 0 : disabledAccount.includes(item === null || item === void 0 ? void 0 : item[userIdKey]), defaultChecked: usersSelected.includes(item === null || item === void 0 ? void 0 : item[userIdKey]) },
|
|
51
51
|
React.createElement(TextLabel, null, item === null || item === void 0 ? void 0 : item[nameKey])))))))),
|
|
52
52
|
React.createElement(AccountListFooter, null,
|
|
53
|
-
React.createElement(Button, { onClick: () => handleCancel() },
|
|
54
|
-
React.createElement(Button, { type: "primary", onClick: () => handleApply() },
|
|
53
|
+
React.createElement(Button, { onClick: () => handleCancel() }, state.cancelText || 'Cancel'),
|
|
54
|
+
React.createElement(Button, { type: "primary", onClick: () => handleApply() }, state.applyText || 'Apply'))));
|
|
55
55
|
};
|
|
56
56
|
export default AccountList;
|
|
@@ -25,6 +25,6 @@ const ButtonAdd = () => {
|
|
|
25
25
|
: dispatch({ type: 'OPEN_ACCOUNT_LIST' }) },
|
|
26
26
|
React.createElement("div", { className: "icon" },
|
|
27
27
|
React.createElement(Icon, { type: "icon-ants-add", size: 10 })),
|
|
28
|
-
React.createElement("div", { className: "name" },
|
|
28
|
+
React.createElement("div", { className: "name" }, state.addText || 'Add account'))));
|
|
29
29
|
};
|
|
30
30
|
export default ButtonAdd;
|
|
@@ -57,13 +57,16 @@ export const SelectAccountProvider = props => {
|
|
|
57
57
|
}
|
|
58
58
|
}, [data]);
|
|
59
59
|
// Callback OnChange
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
// useEffect(() => {
|
|
61
|
+
// if (isInitDone && typeof onChange === 'function' && changedRef.current <= 0) {
|
|
62
|
+
// onChange(
|
|
63
|
+
// usersSelected,
|
|
64
|
+
// state.users.filter(user => usersSelected.includes(user[state.userIdKey])),
|
|
65
|
+
// );
|
|
66
|
+
// }
|
|
67
|
+
// if (changedRef.current > 0) {
|
|
68
|
+
// changedRef.current--;
|
|
69
|
+
// }
|
|
70
|
+
// }, [usersSelected]);
|
|
68
71
|
return (React.createElement(SelectAccountContext.Provider, { value: contextValue }, children));
|
|
69
72
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import produce from 'immer';
|
|
2
2
|
import { parseValue } from '../utils';
|
|
3
|
-
import {
|
|
3
|
+
import { difference, union } from 'lodash';
|
|
4
4
|
export const initialState = {
|
|
5
5
|
isInitDone: false,
|
|
6
6
|
searchText: '',
|
|
@@ -60,12 +60,34 @@ export const reducer = (state, action) => produce(state, draft => {
|
|
|
60
60
|
for (const element of disabledElements) {
|
|
61
61
|
element.disabled = true;
|
|
62
62
|
}
|
|
63
|
+
// Convert FormData to object
|
|
63
64
|
const entriesFormData = Object.fromEntries(formData);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
];
|
|
65
|
+
// Get new select from form data
|
|
66
|
+
const selected = Object.keys(entriesFormData).map(key => parseValue(key, entriesFormData[key].toString()));
|
|
67
|
+
// Get all display when search
|
|
68
|
+
const allDisplay = [];
|
|
69
|
+
allDisplay.push(...draft.usersDisplay.map(user => user[draft.userIdKey]));
|
|
70
|
+
if (draft.type === 'group') {
|
|
71
|
+
allDisplay.push(...draft.listAccountGroupDisplay.map(user => user[draft.groupIdKey]));
|
|
72
|
+
}
|
|
73
|
+
// Get unselected from all display
|
|
74
|
+
const unSelected = difference(allDisplay, selected);
|
|
75
|
+
// Get selected remaining
|
|
76
|
+
const selectedRemain = difference(draft.usersSelected, unSelected);
|
|
77
|
+
// Merge selected remaining and selected
|
|
78
|
+
draft.usersSelected = [...(union(selectedRemain, selected) || [])];
|
|
68
79
|
draft.openAccountList = false;
|
|
80
|
+
// handle change
|
|
81
|
+
if (typeof draft.onChange === 'function') {
|
|
82
|
+
const optionUsersSelected = [...state.users].filter(user => draft.usersSelected.includes(user[state.userIdKey]));
|
|
83
|
+
const optionGroupSelected = state.type === 'group'
|
|
84
|
+
? [...state.listAccountGroup].filter(group => draft.usersSelected.includes(group[state.groupIdKey]))
|
|
85
|
+
: [];
|
|
86
|
+
draft.onChange(draft.usersSelected, [
|
|
87
|
+
...(optionUsersSelected || []),
|
|
88
|
+
...(optionGroupSelected || []),
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
69
91
|
break;
|
|
70
92
|
}
|
|
71
93
|
case 'UPDATE_USERS':
|
|
@@ -111,6 +133,17 @@ export const reducer = (state, action) => produce(state, draft => {
|
|
|
111
133
|
const clone = [...draft.usersSelected];
|
|
112
134
|
const newSelected = [...clone.slice(0, index), ...clone.slice(index + 1)];
|
|
113
135
|
draft.usersSelected = newSelected;
|
|
136
|
+
// handle change
|
|
137
|
+
if (typeof draft.onChange === 'function') {
|
|
138
|
+
const optionUsersSelected = [...state.users].filter(user => draft.usersSelected.includes(user[state.userIdKey]));
|
|
139
|
+
const optionGroupSelected = state.type === 'group'
|
|
140
|
+
? [...state.listAccountGroup].filter(group => draft.usersSelected.includes(group[state.groupIdKey]))
|
|
141
|
+
: [];
|
|
142
|
+
draft.onChange(draft.usersSelected, [
|
|
143
|
+
...(optionUsersSelected || []),
|
|
144
|
+
...(optionGroupSelected || []),
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
114
147
|
}
|
|
115
148
|
break;
|
|
116
149
|
default:
|
|
@@ -37,6 +37,9 @@ export type SelectAccountProps = {
|
|
|
37
37
|
};
|
|
38
38
|
nameKey: string;
|
|
39
39
|
userIdKey: string;
|
|
40
|
+
addText?: string;
|
|
41
|
+
applyText?: string;
|
|
42
|
+
cancelText?: string;
|
|
40
43
|
onChange?: (idSelected: Array<string | number>, users: Record<string, any>) => void;
|
|
41
44
|
} & (SelectAccountWithUsers | SelectAccountWithApi) & (AccountProps | GroupAccountProps);
|
|
42
45
|
export type TState = SelectAccountProps & {
|