diginet-core-ui 1.3.78 → 1.3.79
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/components/accordion/details.js +2 -6
- package/components/accordion/group.js +2 -9
- package/components/accordion/index.js +2 -15
- package/components/accordion/summary.js +4 -27
- package/components/alert/index.js +98 -137
- package/components/alert/notify.js +97 -166
- package/components/avatar/index.js +4 -63
- package/components/badge/index.js +7 -34
- package/components/button/icon.js +120 -186
- package/components/button/index.js +136 -205
- package/components/button/more.js +0 -12
- package/components/button/ripple-effect.js +46 -44
- package/components/card/body.js +2 -7
- package/components/card/extra.js +2 -7
- package/components/card/footer.js +2 -7
- package/components/card/header.js +2 -7
- package/components/card/index.js +2 -22
- package/components/chart/Pie/Circle.js +0 -1
- package/components/chart/Pie/Sector.js +0 -17
- package/components/chart/Pie/Sectors.js +0 -10
- package/components/chart/Pie/index.js +4 -36
- package/components/chart/Pie-v2/Circle.js +0 -1
- package/components/chart/Pie-v2/Sector.js +0 -13
- package/components/chart/Pie-v2/Sectors.js +0 -20
- package/components/chart/Pie-v2/index.js +11 -38
- package/components/chart/bar/Axis.js +0 -12
- package/components/chart/bar/Bar.js +13 -35
- package/components/chart/bar/Grid.js +0 -18
- package/components/chart/bar/Labels.js +0 -18
- package/components/chart/bar/Points.js +0 -17
- package/components/chart/bar/index.js +6 -26
- package/components/chart/bar-v2/Axis.js +0 -12
- package/components/chart/bar-v2/Bar.js +15 -36
- package/components/chart/bar-v2/Grid.js +0 -18
- package/components/chart/bar-v2/Labels.js +0 -18
- package/components/chart/bar-v2/Points.js +0 -17
- package/components/chart/bar-v2/index.js +6 -26
- package/components/chart/line/Axis.js +4 -16
- package/components/chart/line/Grid.js +2 -19
- package/components/chart/line/Labels.js +0 -18
- package/components/chart/line/Path.js +23 -33
- package/components/chart/line/Point.js +6 -40
- package/components/chart/line/Title.js +0 -3
- package/components/chart/line/index.js +12 -35
- package/components/chart/line-v2/Axis.js +0 -13
- package/components/chart/line-v2/Grid.js +0 -18
- package/components/chart/line-v2/Labels.js +0 -18
- package/components/chart/line-v2/Path.js +23 -33
- package/components/chart/line-v2/Point.js +6 -35
- package/components/chart/line-v2/Title.js +0 -3
- package/components/chart/line-v2/index.js +12 -30
- package/components/check-text/index.js +0 -8
- package/components/check-text/interview-confirmation.js +0 -7
- package/components/check-text/interview-status.js +0 -7
- package/components/chip/attach.js +4 -17
- package/components/chip/index.js +6 -33
- package/components/collapse/index.js +0 -13
- package/components/divider/index.js +0 -8
- package/components/form-control/attachment/index.js +24 -202
- package/components/form-control/calendar/function.js +40 -94
- package/components/form-control/calendar/index.js +5 -30
- package/components/form-control/calendar/range.js +11 -28
- package/components/form-control/checkbox/index.js +4 -37
- package/components/form-control/control/index.js +3 -13
- package/components/form-control/date-picker/index-old.js +18 -0
- package/components/form-control/date-picker/index.js +23 -99
- package/components/form-control/date-range-picker/index.js +86 -221
- package/components/form-control/dropdown/index.js +72 -289
- package/components/form-control/dropdown-box/index.js +6 -35
- package/components/form-control/form/index.js +0 -2
- package/components/form-control/form-group/index.js +1 -6
- package/components/form-control/helper-text/index.js +2 -9
- package/components/form-control/input-base/index.js +218 -399
- package/components/form-control/label/index.js +2 -12
- package/components/form-control/money-input/index.js +43 -132
- package/components/form-control/number-input/index.js +15 -113
- package/components/form-control/number-input/index2.js +78 -119
- package/components/form-control/phone-input/index.js +16 -78
- package/components/form-control/radio/index.js +4 -23
- package/components/form-control/text-input/index.js +33 -256
- package/components/form-control/time-picker/index.js +14 -71
- package/components/form-control/time-picker/swiper.js +21 -73
- package/components/form-control/toggle/index.js +4 -19
- package/components/form-view/helper-text.js +2 -2
- package/components/form-view/index.js +0 -14
- package/components/form-view/input.js +2 -13
- package/components/form-view/label.js +0 -2
- package/components/grid/Col.js +2 -15
- package/components/grid/Container.js +2 -21
- package/components/grid/Row.js +2 -21
- package/components/grid/index.js +2 -43
- package/components/image/index.js +2 -22
- package/components/index.js +62 -31
- package/components/list/list-item-action.js +0 -9
- package/components/list/list-item-icon.js +0 -9
- package/components/list/list-item-text.js +0 -5
- package/components/list/list-item.js +0 -11
- package/components/list/list.js +0 -13
- package/components/list/sub-header.js +0 -4
- package/components/modal/body.js +2 -6
- package/components/modal/footer.js +2 -11
- package/components/modal/header.js +2 -12
- package/components/modal/index.js +2 -10
- package/components/modal/modal.js +11 -52
- package/components/others/extra/index.js +3 -10
- package/components/others/import/index.js +0 -7
- package/components/others/option-wrapper/index.js +4 -7
- package/components/others/scrollbar/index.js +0 -3
- package/components/paging/page-info.js +39 -101
- package/components/paging/page-selector.js +7 -35
- package/components/paging/page-selector2.js +35 -74
- package/components/paper/index.js +0 -11
- package/components/popover/body.js +2 -6
- package/components/popover/footer.js +2 -11
- package/components/popover/header.js +2 -7
- package/components/popover/index.js +39 -123
- package/components/popup/danger_popup.js +0 -19
- package/components/popup/index.js +2 -48
- package/components/popup/proposals_popup.js +10 -49
- package/components/popup/v2/index.js +0 -31
- package/components/progress/circular.js +19 -81
- package/components/progress/linear.js +4 -20
- package/components/rating/index.js +0 -24
- package/components/slider/slider-container.js +3 -40
- package/components/slider/slider-item.js +10 -25
- package/components/status/index.js +2 -16
- package/components/tab/tab-container.js +2 -16
- package/components/tab/tab-header.js +4 -24
- package/components/tab/tab-panel.js +4 -16
- package/components/tab/tab.js +4 -28
- package/components/tooltip/index.js +12 -97
- package/components/tooltip/portal.js +0 -2
- package/components/transfer/index.js +22 -67
- package/components/tree-view/index.js +62 -202
- package/components/typography/index.js +3 -31
- package/global/index.js +0 -8
- package/icons/basic.js +0 -48
- package/icons/effect.js +17 -29
- package/icons/general/clock/clock.js +0 -2
- package/icons/general/color-handler/background.js +0 -2
- package/icons/general/color-handler/text.js +0 -2
- package/icons/general/emoji/emoji.js +0 -2
- package/icons/general/font-properties/bold.js +0 -2
- package/icons/general/font-properties/font-family.js +0 -2
- package/icons/general/font-properties/font-size.js +0 -2
- package/icons/general/font-properties/italic.js +0 -2
- package/icons/general/font-properties/underline.js +0 -2
- package/icons/general/hyperlink/hyperlink.js +0 -2
- package/icons/general/indent/decrease.js +0 -2
- package/icons/general/indent/increase.js +0 -2
- package/icons/general/list/bullets.js +0 -2
- package/icons/general/list/numbering.js +0 -2
- package/icons/general/picture/picture.js +0 -2
- package/icons/general/steps/redo.js +0 -2
- package/icons/general/steps/undo.js +0 -2
- package/icons/general/text-align/center.js +0 -2
- package/icons/general/text-align/justify.js +0 -2
- package/icons/general/text-align/left.js +0 -2
- package/icons/general/text-align/right.js +0 -2
- package/icons/menu/dhr.js +2 -1
- package/icons/menu/index.js +2 -2
- package/icons/menu/v2/index.js +0 -10
- package/package.json +1 -1
- package/readme.md +11 -1
- package/styles/animation.js +15 -58
- package/styles/color-helper.js +24 -54
- package/styles/colors.js +17 -9
- package/styles/general.js +6 -2
- package/styles/typography.js +4 -4
- package/styles/utils.js +2 -2
- package/theme/createBreakpoints.js +7 -18
- package/theme/make-styles.js +2 -5
- package/theme/set-theme.js +3 -6
- package/theme/settings.js +3 -2
- package/theme/theme-provider.js +0 -1
- package/utils/array/array.js +14 -23
- package/utils/classNames.js +0 -5
- package/utils/console.js +0 -6
- package/utils/date.js +13 -82
- package/utils/error/error.js +1 -9
- package/utils/error/errors.js +1 -48
- package/utils/getFileType.js +0 -9
- package/utils/handleBreakpoints.js +0 -5
- package/utils/intersectionObserver.js +0 -5
- package/utils/iterator.js +0 -9
- package/utils/map-parent.js +3 -10
- package/utils/object/extend.js +0 -10
- package/utils/object/object.js +12 -11
- package/utils/parseHTML.js +0 -1
- package/utils/promisify.js +0 -5
- package/utils/randomString.js +0 -7
- package/utils/remove-unicode.js +0 -1
- package/utils/render-portal.js +1 -9
- package/utils/renderHTML.js +4 -6
- package/utils/renderIcon.js +4 -14
- package/utils/sb-template.js +6 -5
- package/utils/string/capitalize.js +0 -1
- package/utils/string/capitalizeSentenceCase.js +0 -2
- package/utils/string/string.js +0 -13
- package/utils/type.js +0 -21
- package/utils/updatePosition.js +4 -5
- package/utils/useDelayUnmount.js +0 -4
- package/utils/useElementSize.js +9 -3
- package/utils/useEventListener.js +12 -6
- package/utils/useInput.js +0 -6
- package/utils/useMediaQuery.js +8 -10
- package/utils/useOnClickOutside.js +0 -2
- package/utils/usePortal.js +3 -10
- package/utils/validate.js +6 -20
|
@@ -1,198 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/** @jsxRuntime classic */
|
|
2
|
+
/** @jsx jsx */
|
|
3
|
+
import { memo, useEffect, forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
|
4
|
+
import ReactDOM, { createPortal } from 'react-dom';
|
|
3
5
|
import PropTypes from 'prop-types';
|
|
6
|
+
import { jsx, css } from '@emotion/core';
|
|
4
7
|
import Alert from './';
|
|
5
|
-
import { randomString } from '../../utils';
|
|
6
8
|
import theme from '../../theme/settings';
|
|
9
|
+
import { classNames, refType as ref } from '../../utils';
|
|
10
|
+
import { backgroundTransparent, pointerEventsNone, positionFixed } from '../../styles/general';
|
|
7
11
|
const {
|
|
8
12
|
zIndex: zIndexCORE
|
|
9
13
|
} = theme;
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
horizontal: {
|
|
32
|
-
left: {
|
|
33
|
-
left: '15px'
|
|
34
|
-
},
|
|
35
|
-
center: {
|
|
36
|
-
left: '50%',
|
|
37
|
-
transform: 'translateX(-50%)'
|
|
38
|
-
},
|
|
39
|
-
right: {
|
|
40
|
-
right: '15px'
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const str = randomString(6, {
|
|
45
|
-
allowSymbol: false
|
|
46
|
-
});
|
|
47
|
-
const AlertNotify = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
48
|
-
position,
|
|
14
|
+
const positionVerticalMap = new Map([['top', css`
|
|
15
|
+
top: 15px;
|
|
16
|
+
`], ['center', css`
|
|
17
|
+
top: 50%;
|
|
18
|
+
transform: translateY(-50%);
|
|
19
|
+
`], ['bottom', css`
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: column-reverse;
|
|
22
|
+
bottom: 0;
|
|
23
|
+
`]]);
|
|
24
|
+
const positionHorizontalMap = new Map([['left', css`
|
|
25
|
+
left: 15px;
|
|
26
|
+
`], ['center', css`
|
|
27
|
+
left: 50%;
|
|
28
|
+
transform: translateX(-50%);
|
|
29
|
+
`], ['right', css`
|
|
30
|
+
right: 15px;
|
|
31
|
+
`]]);
|
|
32
|
+
const Notify = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
33
|
+
action = {},
|
|
34
|
+
className,
|
|
49
35
|
getAddNotify,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
maxHeight,
|
|
36
|
+
id,
|
|
37
|
+
position,
|
|
38
|
+
style,
|
|
54
39
|
...props
|
|
55
40
|
}, reference) => {
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (pos === 'center') {
|
|
63
|
-
pos = {
|
|
64
|
-
vertical: 'center',
|
|
65
|
-
horizontal: 'center'
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (pos.vertical && pos.horizontal && /^top|center|bottom$/.test(pos.vertical) && /^left|center|right$/.test(pos.horizontal)) {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return false;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const renderNotifyAlertPosition = (pos, className) => {
|
|
77
|
-
if (pos === 'center') {
|
|
78
|
-
pos = {
|
|
79
|
-
vertical: 'center',
|
|
80
|
-
horizontal: 'center'
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const el = document.createElement('div');
|
|
85
|
-
el.className = `Notify-Alert-${className || pos.vertical + '-' + pos.horizontal}`;
|
|
86
|
-
Object.assign(el.style, positions.general, positions.vertical[pos.vertical || 'bottom'], positions.horizontal[pos.horizontal || 'center'], pos.vertical === pos.horizontal ? {
|
|
87
|
-
transform: 'translate(-50%, -50%)'
|
|
88
|
-
} : {}, {
|
|
89
|
-
width,
|
|
90
|
-
maxWidth,
|
|
91
|
-
height,
|
|
92
|
-
maxHeight
|
|
93
|
-
});
|
|
94
|
-
document.body.appendChild(el);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const onClose = (e, removePosition) => {
|
|
98
|
-
var _e$parentNode;
|
|
99
|
-
|
|
100
|
-
(_e$parentNode = e.parentNode) === null || _e$parentNode === void 0 ? void 0 : _e$parentNode.remove();
|
|
101
|
-
|
|
102
|
-
if (removePosition) {
|
|
103
|
-
const node = document.querySelector(`div[class^="Notify-Alert-${removePosition.vertical}-${removePosition.horizontal}"]`);
|
|
104
|
-
|
|
105
|
-
if (node && node.childNodes && !node.childNodes.length) {
|
|
106
|
-
node.remove();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const onAddAlert = (message, {
|
|
41
|
+
const ref = useRef(null);
|
|
42
|
+
const [positionState, setPositionState] = useState(position);
|
|
43
|
+
const PositionVerticalCSS = positionVerticalMap.get((positionState === null || positionState === void 0 ? void 0 : positionState.vertical) || 'bottom');
|
|
44
|
+
const PositionHorizontalCSS = positionHorizontalMap.get((positionState === null || positionState === void 0 ? void 0 : positionState.horizontal) || 'center');
|
|
45
|
+
const showNotify = (message, {
|
|
112
46
|
position,
|
|
113
47
|
...options
|
|
114
48
|
} = {}) => {
|
|
115
49
|
options = typeof options === 'object' ? options : {};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (position && checkPosition(position)) {
|
|
120
|
-
if (!document.querySelector(`div[class^="Notify-Alert-${position.vertical}-${position.horizontal}"]`)) {
|
|
121
|
-
renderNotifyAlertPosition(position);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
ReactDOM.render( /*#__PURE__*/React.createElement(Alert, {
|
|
125
|
-
onClose: e => onClose(e, position),
|
|
126
|
-
secondary: message,
|
|
127
|
-
...props,
|
|
128
|
-
...options
|
|
129
|
-
}), document.querySelector(`div[class^="Notify-Alert-${position.vertical}-${position.horizontal}"]`).appendChild(el));
|
|
130
|
-
} else {
|
|
131
|
-
ReactDOM.render( /*#__PURE__*/React.createElement(Alert, {
|
|
132
|
-
onClose: onClose,
|
|
133
|
-
secondary: message,
|
|
134
|
-
...props,
|
|
135
|
-
...options
|
|
136
|
-
}), document.querySelector(`div[class^="Notify-Alert-"]`).appendChild(el));
|
|
50
|
+
if (position) {
|
|
51
|
+
setPositionState(position);
|
|
137
52
|
}
|
|
53
|
+
const el = document.createElement('div');
|
|
54
|
+
el.className = 'DGN-UI-Notify-Alert-Item';
|
|
55
|
+
ReactDOM.render(jsx(Alert
|
|
56
|
+
// onClose={() => el.remove()}
|
|
57
|
+
, {
|
|
58
|
+
secondary: message,
|
|
59
|
+
...props,
|
|
60
|
+
...options
|
|
61
|
+
}), ref.current.appendChild(el));
|
|
138
62
|
};
|
|
139
|
-
|
|
140
63
|
useEffect(() => {
|
|
141
|
-
if (getAddNotify && typeof getAddNotify === 'function') getAddNotify(
|
|
64
|
+
if (getAddNotify && typeof getAddNotify === 'function') getAddNotify(showNotify);
|
|
142
65
|
}, [props]);
|
|
143
66
|
useEffect(() => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
67
|
+
setPositionState(position);
|
|
68
|
+
}, [position]);
|
|
69
|
+
useImperativeHandle(reference, () => {
|
|
70
|
+
const currentRef = ref.current || {};
|
|
71
|
+
currentRef.element = ref.current;
|
|
72
|
+
const _instance = {
|
|
73
|
+
show: showNotify,
|
|
74
|
+
...action
|
|
75
|
+
}; // methods
|
|
76
|
+
_instance.__proto__ = {}; // hidden methods
|
|
77
|
+
currentRef.instance = _instance;
|
|
78
|
+
currentRef.add = showNotify;
|
|
79
|
+
return currentRef;
|
|
80
|
+
});
|
|
81
|
+
const NotifyContainerView = jsx("div", {
|
|
82
|
+
ref: ref,
|
|
83
|
+
css: [AlertCSS, PositionVerticalCSS, PositionHorizontalCSS],
|
|
84
|
+
id: id,
|
|
85
|
+
style: style,
|
|
86
|
+
className: classNames('DGN-UI-Notify-Alert', (position === null || position === void 0 ? void 0 : position.vertical) || 'center' + '-' + (position === null || position === void 0 ? void 0 : position.horizontal) || 'center', className)
|
|
87
|
+
});
|
|
88
|
+
return /*#__PURE__*/createPortal(NotifyContainerView, document.body);
|
|
153
89
|
}));
|
|
154
|
-
|
|
90
|
+
const AlertCSS = css`
|
|
91
|
+
${positionFixed};
|
|
92
|
+
${pointerEventsNone};
|
|
93
|
+
${backgroundTransparent};
|
|
94
|
+
z-index: ${zIndexCORE(2)};
|
|
95
|
+
`;
|
|
96
|
+
Notify.defaultProps = {
|
|
97
|
+
className: '',
|
|
155
98
|
position: {
|
|
156
99
|
vertical: 'bottom',
|
|
157
100
|
horizontal: 'center'
|
|
158
|
-
}
|
|
101
|
+
},
|
|
102
|
+
style: {}
|
|
159
103
|
};
|
|
160
|
-
|
|
104
|
+
Notify.propTypes = {
|
|
105
|
+
/** Class for component. */
|
|
106
|
+
className: PropTypes.string,
|
|
161
107
|
/**
|
|
162
108
|
* used to set position of Alert (is a string or an object)
|
|
163
109
|
* string is center (obligatory) as {vertical: 'center', horizontal: 'center'}
|
|
164
110
|
*/
|
|
165
111
|
position: PropTypes.oneOfType([PropTypes.oneOf(['center']), PropTypes.shape({
|
|
166
|
-
|
|
167
|
-
|
|
112
|
+
horizontal: PropTypes.oneOf(['center', 'left', 'right']),
|
|
113
|
+
vertical: PropTypes.oneOf(['bottom', 'center', 'top'])
|
|
168
114
|
})]),
|
|
169
|
-
|
|
115
|
+
/** Style inline of component. */
|
|
116
|
+
style: PropTypes.object,
|
|
117
|
+
/** Any [props](https://core.diginet.com.vn/ui/?path=/docs/alert--basic) of Alert */
|
|
118
|
+
props: PropTypes.any,
|
|
170
119
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* color: new color,<br />
|
|
178
|
-
* progressing: new progressing value,<br />
|
|
179
|
-
* autoDisappear: new autoDisappear value,<br />
|
|
180
|
-
* size: new autoDisappear,<br />
|
|
181
|
-
* and any props else in Alert component <br />
|
|
182
|
-
* }
|
|
120
|
+
* ref methods (ref.current.instance.*method*)
|
|
121
|
+
*
|
|
122
|
+
* * show(message, option): Show notify
|
|
123
|
+
* * @param {message} - number
|
|
124
|
+
* * @param {options} - object
|
|
125
|
+
* * {[Props](https://core.diginet.com.vn/ui/?path=/docs/alert--basic) applied to the `Alert`.}
|
|
183
126
|
*/
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
/** the width of the alert box */
|
|
187
|
-
width: PropTypes.string,
|
|
188
|
-
|
|
189
|
-
/** the maximum width of the alert box */
|
|
190
|
-
maxWidth: PropTypes.string,
|
|
191
|
-
|
|
192
|
-
/** the height of the alert box */
|
|
193
|
-
height: PropTypes.string,
|
|
194
|
-
|
|
195
|
-
/** the maximum height of the alert box */
|
|
196
|
-
maxHeight: PropTypes.string
|
|
127
|
+
reference: ref
|
|
197
128
|
};
|
|
198
|
-
export default
|
|
129
|
+
export default Notify;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { Fragment, memo, useRef, forwardRef, useState, useEffect, useMemo, useImperativeHandle, isValidElement } from 'react';
|
|
5
4
|
import PropTypes from 'prop-types';
|
|
@@ -29,8 +28,8 @@ const {
|
|
|
29
28
|
zIndex: zIndexCORE
|
|
30
29
|
} = theme;
|
|
31
30
|
const existed = {},
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
urlAvatar = {},
|
|
32
|
+
popupHandler = {};
|
|
34
33
|
const blurKeyframe = keyframes`
|
|
35
34
|
0% { -webkit-filter: blur(4px);}
|
|
36
35
|
25% { -webkit-filter: blur(3px);}
|
|
@@ -38,7 +37,6 @@ const blurKeyframe = keyframes`
|
|
|
38
37
|
75% { -webkit-filter: blur(1px);}
|
|
39
38
|
100% { -webkit-filter: blur(0px);}
|
|
40
39
|
`;
|
|
41
|
-
|
|
42
40
|
const checkFileType = (type, matchType) => {
|
|
43
41
|
if (typeof matchType === 'object' && matchType instanceof RegExp) {
|
|
44
42
|
return matchType.test(type);
|
|
@@ -49,7 +47,6 @@ const checkFileType = (type, matchType) => {
|
|
|
49
47
|
return new RegExp(matchType).test(type);
|
|
50
48
|
}
|
|
51
49
|
};
|
|
52
|
-
|
|
53
50
|
const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
54
51
|
action = {},
|
|
55
52
|
actionIconHeight,
|
|
@@ -94,17 +91,11 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
94
91
|
useIntersection(ref, () => {
|
|
95
92
|
setIsInView(true);
|
|
96
93
|
});
|
|
97
|
-
|
|
98
94
|
const _ActionIconCSS = ActionIconCSS(actionIconWidth);
|
|
99
|
-
|
|
100
95
|
const _AvatarPreviewCSS = AvatarPreviewCSS(readOnly);
|
|
101
|
-
|
|
102
96
|
const _AvatarContainerCSS = AvatarContainerCSS(_AvatarPreviewCSS.name, _ActionIconCSS.name);
|
|
103
|
-
|
|
104
97
|
const _AvatarRootCSS = AvatarRootCSS(width, height, outlined);
|
|
105
|
-
|
|
106
98
|
const _isMobile = isMobile.any();
|
|
107
|
-
|
|
108
99
|
const triggerInput = e => {
|
|
109
100
|
if (e || !existed[unique]) {
|
|
110
101
|
inputRef.current.click();
|
|
@@ -113,45 +104,37 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
113
104
|
setViewAvatar(true);
|
|
114
105
|
}
|
|
115
106
|
};
|
|
116
|
-
|
|
117
107
|
const onChangeAvatar = input => {
|
|
118
108
|
const [file] = input.target.files;
|
|
119
109
|
if (!file) return;
|
|
120
110
|
const reader = new FileReader();
|
|
121
|
-
|
|
122
111
|
if (!checkFileType(file.type, matchType)) {
|
|
123
112
|
input.target.value = '';
|
|
124
113
|
popupHandler[unique].show(wrongTypeError);
|
|
125
114
|
return;
|
|
126
115
|
}
|
|
127
|
-
|
|
128
116
|
if (+maxSize && file.size > maxSize * 1024 ** 2) {
|
|
129
117
|
input.target.value = '';
|
|
130
118
|
popupHandler[unique].show(maxSizeError);
|
|
131
119
|
return;
|
|
132
120
|
}
|
|
133
|
-
|
|
134
121
|
reader.onload = e => {
|
|
135
122
|
urlAvatar[unique] = e.target.result;
|
|
136
123
|
setSrcState(urlAvatar[unique]);
|
|
137
124
|
existed[unique] = true;
|
|
138
125
|
};
|
|
139
|
-
|
|
140
126
|
reader.readAsDataURL(file);
|
|
141
127
|
!!onChange && onChange(input);
|
|
142
128
|
};
|
|
143
|
-
|
|
144
129
|
const onRemoveAvatar = () => {
|
|
145
130
|
setSrcState(null);
|
|
146
131
|
existed[unique] = false;
|
|
147
132
|
inputRef.current.value = '';
|
|
148
133
|
!!onRemove && onRemove();
|
|
149
134
|
};
|
|
150
|
-
|
|
151
135
|
const renderData = () => {
|
|
152
136
|
if ( /*#__PURE__*/isValidElement(data)) return data;
|
|
153
137
|
const info = Object.keys(data || {});
|
|
154
|
-
|
|
155
138
|
if (info !== null && info !== void 0 && info.length) {
|
|
156
139
|
return info.map((key, index) => {
|
|
157
140
|
return jsx(Typography, {
|
|
@@ -161,13 +144,11 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
161
144
|
}, key + ': ' + data[key]);
|
|
162
145
|
});
|
|
163
146
|
}
|
|
164
|
-
|
|
165
147
|
return jsx(Typography, {
|
|
166
148
|
color: textTooltip,
|
|
167
149
|
type: 'p1'
|
|
168
150
|
}, getGlobal('noDataText'));
|
|
169
151
|
};
|
|
170
|
-
|
|
171
152
|
const renderImage = () => {
|
|
172
153
|
const _image = jsx(Fragment, null, !onLoaded && jsx("img", {
|
|
173
154
|
src: defaultSrc,
|
|
@@ -184,7 +165,6 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
184
165
|
},
|
|
185
166
|
onLoad: () => setOnLoaded(true)
|
|
186
167
|
}));
|
|
187
|
-
|
|
188
168
|
if (lazyLoading) {
|
|
189
169
|
return isInView ? _image : jsx("img", {
|
|
190
170
|
src: defaultSrc,
|
|
@@ -195,34 +175,27 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
195
175
|
});
|
|
196
176
|
} else return _image;
|
|
197
177
|
};
|
|
198
|
-
|
|
199
178
|
const showMoreInfo = () => {
|
|
200
179
|
if (hoverAble) setViewMoreInfo(true);
|
|
201
180
|
};
|
|
202
|
-
|
|
203
181
|
const closeMoreInfo = () => {
|
|
204
182
|
if (hoverAble) setViewMoreInfo(false);
|
|
205
183
|
};
|
|
206
|
-
|
|
207
184
|
const _onClick = event => {
|
|
208
185
|
onClick && event.stopPropagation();
|
|
209
186
|
if (disabled) return;
|
|
210
|
-
|
|
211
187
|
if (readOnly) {
|
|
212
188
|
if (_isMobile) showMoreInfo();
|
|
213
189
|
} else {
|
|
214
190
|
allowEdit ? triggerInput() : onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
215
191
|
}
|
|
216
192
|
};
|
|
217
|
-
|
|
218
193
|
const _onMouseEnter = () => {
|
|
219
194
|
if (!_isMobile) showMoreInfo();
|
|
220
195
|
};
|
|
221
|
-
|
|
222
196
|
const _onMouseLeave = () => {
|
|
223
197
|
if (!_isMobile) closeMoreInfo();
|
|
224
198
|
};
|
|
225
|
-
|
|
226
199
|
useEffect(() => {
|
|
227
200
|
if (src) {
|
|
228
201
|
if (isInView || !lazyLoading) {
|
|
@@ -231,12 +204,10 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
231
204
|
urlAvatar[unique] = src;
|
|
232
205
|
img.src = src;
|
|
233
206
|
img.alt = '';
|
|
234
|
-
|
|
235
207
|
img.onerror = () => {
|
|
236
208
|
setSrcState(defaultSrc);
|
|
237
209
|
existed[unique] = false;
|
|
238
210
|
};
|
|
239
|
-
|
|
240
211
|
img.onload = () => {
|
|
241
212
|
setSrcState(src);
|
|
242
213
|
existed[unique] = true;
|
|
@@ -247,11 +218,10 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
247
218
|
useImperativeHandle(reference, () => {
|
|
248
219
|
const currentRef = ref.current || {};
|
|
249
220
|
currentRef.element = ref.current;
|
|
250
|
-
const _instance = {
|
|
221
|
+
const _instance = {
|
|
222
|
+
...action
|
|
251
223
|
}; // methods
|
|
252
|
-
|
|
253
224
|
_instance.__proto__ = {}; // hidden methods
|
|
254
|
-
|
|
255
225
|
currentRef.instance = _instance;
|
|
256
226
|
return currentRef;
|
|
257
227
|
});
|
|
@@ -334,7 +304,6 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
334
304
|
}));
|
|
335
305
|
}, [actionIconHeight, actionIconWidth, allowEdit, clearAble, data, defaultSrc, direction, disabled, height, hoverAble, lazyLoading, matchType, maxSize, maxSizeError, outlined, readOnly, width, isInView, onLoaded, srcState, viewAvatar, viewMoreInfo]);
|
|
336
306
|
}));
|
|
337
|
-
|
|
338
307
|
const ActionIconCSS = actionIconWidth => css`
|
|
339
308
|
${flexCol};
|
|
340
309
|
${positionAbsolute};
|
|
@@ -344,7 +313,6 @@ const ActionIconCSS = actionIconWidth => css`
|
|
|
344
313
|
opacity: 0;
|
|
345
314
|
z-index: ${zIndexCORE(2)};
|
|
346
315
|
`;
|
|
347
|
-
|
|
348
316
|
const AvatarPreviewCSS = readOnly => css`
|
|
349
317
|
${displayBlock};
|
|
350
318
|
${positionRelative};
|
|
@@ -354,7 +322,6 @@ const AvatarPreviewCSS = readOnly => css`
|
|
|
354
322
|
border-radius: 50%;
|
|
355
323
|
cursor: ${readOnly ? 'initial' : 'pointer'};
|
|
356
324
|
`;
|
|
357
|
-
|
|
358
325
|
const AvatarContainerCSS = (AvatarPreviewCSSName, ActionIconCSSName) => css`
|
|
359
326
|
${inlineFlex};
|
|
360
327
|
${positionRelative};
|
|
@@ -374,7 +341,6 @@ const AvatarContainerCSS = (AvatarPreviewCSSName, ActionIconCSSName) => css`
|
|
|
374
341
|
}
|
|
375
342
|
}
|
|
376
343
|
`;
|
|
377
|
-
|
|
378
344
|
const AvatarRootCSS = (width, height, outlined) => css`
|
|
379
345
|
${displayBlock};
|
|
380
346
|
${positionRelative};
|
|
@@ -393,7 +359,6 @@ const AvatarRootCSS = (width, height, outlined) => css`
|
|
|
393
359
|
height: 100%;
|
|
394
360
|
}
|
|
395
361
|
`;
|
|
396
|
-
|
|
397
362
|
const MoreInfoCSS = css`
|
|
398
363
|
${displayBlock};
|
|
399
364
|
${positionRelative};
|
|
@@ -425,82 +390,58 @@ Avatar.defaultProps = {
|
|
|
425
390
|
Avatar.propTypes = {
|
|
426
391
|
/** The height of action icon. */
|
|
427
392
|
actionIconHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
428
|
-
|
|
429
393
|
/** The width of action icon. */
|
|
430
394
|
actionIconWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
431
|
-
|
|
432
395
|
/** If `true`, allow to edit avatar. */
|
|
433
396
|
allowEdit: PropTypes.bool,
|
|
434
|
-
|
|
435
397
|
/** Class for component. */
|
|
436
398
|
className: PropTypes.string,
|
|
437
|
-
|
|
438
399
|
/** If `true`, display remove avatar icon. */
|
|
439
400
|
clearAble: PropTypes.bool,
|
|
440
|
-
|
|
441
401
|
/**
|
|
442
402
|
* data to display when hoverAble is true<br />
|
|
443
403
|
* data is an object or function return a jsx element
|
|
444
404
|
*/
|
|
445
405
|
data: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.node]),
|
|
446
|
-
|
|
447
406
|
/**
|
|
448
407
|
* it is used to display the default if there is no src<br />
|
|
449
408
|
* if undefined, will display icons available in the icons store
|
|
450
409
|
*/
|
|
451
410
|
defaultSrc: PropTypes.string,
|
|
452
|
-
|
|
453
411
|
/** the direction to display more info */
|
|
454
412
|
direction: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
|
|
455
|
-
|
|
456
413
|
/** prevent all events, only view */
|
|
457
414
|
disabled: PropTypes.bool,
|
|
458
|
-
|
|
459
415
|
/** The height of avatar box (48 or '48px' or ...) */
|
|
460
416
|
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
461
|
-
|
|
462
417
|
/** show more info in popover if true */
|
|
463
418
|
hoverAble: PropTypes.bool,
|
|
464
|
-
|
|
465
419
|
/** lazy loading */
|
|
466
420
|
lazyLoading: PropTypes.bool,
|
|
467
|
-
|
|
468
421
|
/** type of image was allowed */
|
|
469
422
|
matchType: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.func, PropTypes.array]),
|
|
470
|
-
|
|
471
423
|
/** maximum size for avatar file (unit: MB) */
|
|
472
424
|
maxSize: PropTypes.number,
|
|
473
|
-
|
|
474
425
|
/** the error to show on exceeded allowed size */
|
|
475
426
|
maxSizeError: PropTypes.string,
|
|
476
|
-
|
|
477
427
|
/** will run after change avatar */
|
|
478
428
|
onChange: PropTypes.func,
|
|
479
|
-
|
|
480
429
|
/** Callback fired when the component is clicked. */
|
|
481
430
|
onClick: PropTypes.func,
|
|
482
|
-
|
|
483
431
|
/** will run after remove avatar */
|
|
484
432
|
onRemove: PropTypes.func,
|
|
485
|
-
|
|
486
433
|
/** border of avatar (true or '1px solid #color') */
|
|
487
434
|
outlined: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
488
|
-
|
|
489
435
|
/** only view and allow show more info if hoverAble is true */
|
|
490
436
|
readOnly: PropTypes.bool,
|
|
491
|
-
|
|
492
437
|
/** source of file (http:// or https://) */
|
|
493
438
|
src: PropTypes.string,
|
|
494
|
-
|
|
495
439
|
/** Style inline of component. */
|
|
496
440
|
style: PropTypes.object,
|
|
497
|
-
|
|
498
441
|
/** The width of avatar box (48 or '48px' or ...) */
|
|
499
442
|
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
500
|
-
|
|
501
443
|
/** the error to show on wrong type */
|
|
502
444
|
wrongTypeError: PropTypes.string,
|
|
503
|
-
|
|
504
445
|
/**
|
|
505
446
|
* ref methods
|
|
506
447
|
*
|