diginet-core-ui 1.3.86-beta.1 → 1.3.87

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.
@@ -1,19 +1,20 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { css, jsx } from '@emotion/core';
3
+ import { jsx, css, keyframes } from '@emotion/core';
4
4
  import AvatarDefault from "../../assets/avatar/default.svg";
5
- import { ButtonIcon, Image, ModalSample, Popover, Popup, Typography } from "./..";
6
- import OptionWrapper from "../others/option-wrapper";
5
+ import { ButtonIcon, ModalSample, Popover, Popup, Typography } from "./..";
7
6
  import { getGlobal } from "../../global";
8
7
  import PropTypes from 'prop-types';
9
8
  import { forwardRef, Fragment, isValidElement, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
10
- import { borderNone, borderRadius, boxContent, cursorInherit, cursorPointer, displayBlock, displayFlex, displayInlineFlex, displayNone, flexCol, itemsCenter, overflowHidden, parseMinWidth, parseWidthHeight, pd, positionAbsolute, positionRelative, userSelectNone, z } from "../../styles/general";
9
+ import { itemsCenter, borderNone, displayBlock, displayNone, flexCol, displayInlineFlex, overflowHidden, parseWidthHeight, pointerEventsNone, positionAbsolute, positionRelative, userSelectNone } from "../../styles/general";
11
10
  import { useTheme } from "../../theme";
12
- import { classNames, isMobile } from "../../utils";
11
+ import { classNames, isMobile, randomString } from "../../utils";
12
+ import { useIntersection } from "../../utils/intersectionObserver";
13
+ import OptionWrapper from "../others/option-wrapper";
13
14
  const {
14
15
  colors: {
15
16
  system: {
16
- white: systemWhite
17
+ white
17
18
  },
18
19
  fill: {
19
20
  tooltip: fillTooltip
@@ -21,8 +22,19 @@ const {
21
22
  text: {
22
23
  tooltip: textTooltip
23
24
  }
24
- }
25
+ },
26
+ spacing,
27
+ zIndex: zIndexCORE
25
28
  } = useTheme();
29
+ const existed = {},
30
+ urlAvatar = {};
31
+ const blurKeyframe = keyframes`
32
+ 0% { -webkit-filter: blur(4px);}
33
+ 25% { -webkit-filter: blur(3px);}
34
+ 50% { -webkit-filter: blur(2px);}
35
+ 75% { -webkit-filter: blur(1px);}
36
+ 100% { -webkit-filter: blur(0px);}
37
+ `;
26
38
  const checkFileType = (type, matchType) => {
27
39
  if (typeof matchType === 'object' && matchType instanceof RegExp) {
28
40
  return matchType.test(type);
@@ -61,22 +73,30 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
61
73
  width,
62
74
  wrongTypeError
63
75
  }, reference) => {
64
- if (!reference) reference = useRef(null);
65
76
  if (!defaultSrc) defaultSrc = AvatarDefault;
66
77
  const ref = useRef(null);
67
78
  const inputRef = useRef(null);
68
79
  const avatarRef = useRef(null);
69
80
  const popupRef = useRef(null);
81
+ const [unique] = useState(randomString(6, {
82
+ allowNumber: false,
83
+ allowSymbol: false
84
+ }));
70
85
  const [viewAvatar, setViewAvatar] = useState(false);
71
86
  const [viewMoreInfo, setViewMoreInfo] = useState(false);
72
87
  const [srcState, setSrcState] = useState(src);
88
+ const [isInView, setIsInView] = useState(false);
89
+ const [onLoaded, setOnLoaded] = useState(false);
90
+ useIntersection(ref, () => {
91
+ setIsInView(true);
92
+ });
73
93
  const _ActionIconCSS = ActionIconCSS(actionIconWidth);
74
- const _AvatarPreviewCSS = AvatarPreviewCSS(readOnly || disabled);
75
- const _AvatarContainerCSS = AvatarContainerCSS(_ActionIconCSS.name);
94
+ const _AvatarPreviewCSS = AvatarPreviewCSS(readOnly);
95
+ const _AvatarContainerCSS = AvatarContainerCSS(_AvatarPreviewCSS.name, _ActionIconCSS.name);
76
96
  const _AvatarRootCSS = AvatarRootCSS(width, height, outlined);
77
97
  const _isMobile = isMobile.any();
78
98
  const triggerInput = e => {
79
- if (e || !srcState) {
99
+ if (e || !existed[unique]) {
80
100
  inputRef.current.click();
81
101
  } else {
82
102
  // on View
@@ -102,13 +122,16 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
102
122
  return;
103
123
  }
104
124
  reader.onload = e => {
105
- setSrcState(e.target.result);
125
+ urlAvatar[unique] = e.target.result;
126
+ setSrcState(urlAvatar[unique]);
127
+ existed[unique] = true;
106
128
  };
107
129
  reader.readAsDataURL(file);
108
130
  !!onChange && onChange(input);
109
131
  };
110
132
  const onRemoveAvatar = () => {
111
133
  setSrcState(null);
134
+ existed[unique] = false;
112
135
  inputRef.current.value = '';
113
136
  !!onRemove && onRemove();
114
137
  };
@@ -129,6 +152,32 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
129
152
  type: 'p1'
130
153
  }, getGlobal('noDataText'));
131
154
  };
155
+ const renderImage = () => {
156
+ const _image = jsx(Fragment, null, !onLoaded && jsx("img", {
157
+ src: defaultSrc,
158
+ alt: '',
159
+ style: {
160
+ objectFit: 'cover'
161
+ }
162
+ }), jsx("img", {
163
+ css: blurAnimationCSS,
164
+ src: srcState,
165
+ alt: srcState,
166
+ style: {
167
+ objectFit: 'cover'
168
+ },
169
+ onLoad: () => setOnLoaded(true)
170
+ }));
171
+ if (lazyLoading) {
172
+ return isInView ? _image : jsx("img", {
173
+ src: defaultSrc,
174
+ alt: '',
175
+ style: {
176
+ objectFit: 'cover'
177
+ }
178
+ });
179
+ } else return _image;
180
+ };
132
181
  const showMoreInfo = () => {
133
182
  if (hoverAble) setViewMoreInfo(true);
134
183
  };
@@ -152,11 +201,22 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
152
201
  };
153
202
  useEffect(() => {
154
203
  if (src) {
155
- setSrcState(src);
204
+ if (isInView || !lazyLoading) {
205
+ inputRef.current.value = '';
206
+ const img = document.createElement('img');
207
+ urlAvatar[unique] = src;
208
+ img.src = src;
209
+ img.alt = '';
210
+ img.onerror = () => {
211
+ setSrcState(defaultSrc);
212
+ existed[unique] = false;
213
+ };
214
+ img.onload = () => {
215
+ setSrcState(src);
216
+ existed[unique] = true;
217
+ };
218
+ }
156
219
  }
157
- return () => {
158
- setSrcState(defaultSrc);
159
- };
160
220
  }, [src]);
161
221
  useImperativeHandle(reference, () => {
162
222
  const currentRef = ref.current || {};
@@ -170,9 +230,11 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
170
230
  });
171
231
  return useMemo(() => {
172
232
  return jsx(Fragment, null, jsx("div", {
173
- css: _AvatarContainerCSS
174
- }, jsx("div", {
233
+ css: _AvatarContainerCSS,
175
234
  ref: ref,
235
+ id: unique,
236
+ className: classNames(disabled && 'disabled')
237
+ }, jsx("div", {
176
238
  css: _AvatarRootCSS,
177
239
  className: classNames('DGN-UI-Avatar', className),
178
240
  style: style,
@@ -185,21 +247,14 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
185
247
  onChange: onChangeAvatar,
186
248
  disabled: disabled
187
249
  }), jsx("div", {
188
- ref: avatarRef,
189
250
  css: _AvatarPreviewCSS,
190
251
  onClick: _onClick,
252
+ ref: avatarRef,
191
253
  onMouseEnter: _onMouseEnter,
192
254
  onMouseLeave: _onMouseLeave,
193
255
  tabIndex: "-1",
194
256
  onBlur: closeMoreInfo
195
- }, jsx(Image, {
196
- circular: true,
197
- defaultSrc: defaultSrc,
198
- src: srcState,
199
- width: '100%',
200
- height: '100%',
201
- lazyLoading: lazyLoading
202
- }))), allowEdit && !readOnly && !disabled ? jsx("span", {
257
+ }, renderImage())), allowEdit && !readOnly && !disabled && jsx("span", {
203
258
  css: _ActionIconCSS
204
259
  }, jsx(ButtonIcon, {
205
260
  viewType: 'ghost',
@@ -208,7 +263,7 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
208
263
  height: actionIconHeight,
209
264
  className: 'icon-edit',
210
265
  onClick: triggerInput
211
- }), clearAble && srcState ? jsx(ButtonIcon, {
266
+ }), clearAble && srcState && jsx(ButtonIcon, {
212
267
  viewType: 'ghost',
213
268
  name: 'Delete',
214
269
  width: actionIconWidth,
@@ -218,53 +273,68 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
218
273
  style: {
219
274
  marginTop: '8px'
220
275
  }
221
- }) : null) : null), jsx(ModalSample, {
276
+ }))), jsx(ModalSample, {
222
277
  open: viewAvatar,
223
278
  onClose: () => setViewAvatar(false),
224
279
  width: 'max-content'
225
- }, jsx(Image, {
226
- defaultSrc: defaultSrc,
227
- src: srcState,
228
- width: '100%',
229
- height: '100%'
230
- })), hoverAble ? jsx(Popover, {
280
+ }, jsx("img", {
281
+ src: urlAvatar[unique],
282
+ alt: "",
283
+ style: {
284
+ objectFit: 'cover',
285
+ maxHeight: '100%',
286
+ maxWidth: '100%',
287
+ margin: 'auto',
288
+ display: 'block'
289
+ }
290
+ })), hoverAble && jsx(Popover, {
231
291
  arrow: true,
232
292
  open: viewMoreInfo,
233
293
  pressESCToClose: false,
234
294
  bgColor: fillTooltip,
235
295
  anchor: avatarRef,
236
296
  fullScreen: false,
297
+ width: 'max-content',
237
298
  direction: direction
238
299
  }, jsx("div", {
239
300
  css: MoreInfoCSS
240
- }, typeof data === 'function' ? data() : renderData())) : null, !disabled && !readOnly ? jsx(Popup, {
301
+ }, typeof data === 'function' ? data() : renderData())), !disabled && !readOnly && jsx(Popup, {
241
302
  ref: popupRef,
242
303
  type: 'danger'
243
- }) : null);
244
- }, [actionIconHeight, actionIconWidth, allowEdit, clearAble, data, defaultSrc, direction, disabled, height, hoverAble, lazyLoading, matchType, maxSize, maxSizeError, outlined, readOnly, width, srcState, viewAvatar, viewMoreInfo]);
304
+ }));
305
+ }, [actionIconHeight, actionIconWidth, allowEdit, clearAble, data, defaultSrc, direction, disabled, height, hoverAble, lazyLoading, matchType, maxSize, maxSizeError, outlined, readOnly, width, isInView, onLoaded, srcState, viewAvatar, viewMoreInfo]);
245
306
  }));
246
307
  const ActionIconCSS = actionIconWidth => css`
247
- ${displayFlex};
248
308
  ${flexCol};
249
309
  ${positionAbsolute};
250
- ${parseMinWidth(actionIconWidth)};
251
310
  right: ${-actionIconWidth}px;
311
+ min-width: ${actionIconWidth}px;
252
312
  transition: opacity 0.5s;
253
313
  opacity: 0;
254
- ${z(2)};
314
+ z-index: ${zIndexCORE(2)};
255
315
  `;
256
- const AvatarPreviewCSS = isDisabled => css`
316
+ const AvatarPreviewCSS = readOnly => css`
257
317
  ${displayBlock};
258
318
  ${positionRelative};
259
319
  ${overflowHidden};
260
- ${parseWidthHeight('100%')};
261
- ${borderRadius('50%')};
262
- ${isDisabled ? cursorInherit : cursorPointer};
320
+ width: 100%;
321
+ height: 100%;
322
+ border-radius: 50%;
323
+ cursor: ${readOnly ? 'initial' : 'pointer'};
263
324
  `;
264
- const AvatarContainerCSS = ActionIconCSSName => css`
325
+ const AvatarContainerCSS = (AvatarPreviewCSSName, ActionIconCSSName) => css`
265
326
  ${displayInlineFlex};
266
327
  ${positionRelative};
267
328
  ${itemsCenter};
329
+ &.disabled {
330
+ .css-${AvatarPreviewCSSName} {
331
+ ${pointerEventsNone}
332
+ cursor: inherit;
333
+ }
334
+ .css-${ActionIconCSSName} {
335
+ display: none !important;
336
+ }
337
+ }
268
338
  &:hover {
269
339
  .css-${ActionIconCSSName} {
270
340
  opacity: 1;
@@ -277,18 +347,25 @@ const AvatarRootCSS = (width, height, outlined) => css`
277
347
  ${overflowHidden};
278
348
  ${userSelectNone};
279
349
  ${borderNone};
280
- ${boxContent};
281
350
  ${parseWidthHeight(width, height)};
282
- ${borderRadius('50%')};
283
- border: ${typeof outlined === 'boolean' && outlined ? `1px solid ${systemWhite}` : outlined};
351
+ border: ${typeof outlined === 'boolean' && outlined ? `1px solid ${white}` : outlined};
352
+ border-radius: 50%;
353
+ box-sizing: content-box;
284
354
  input {
285
355
  ${displayNone};
286
356
  }
357
+ img {
358
+ width: 100%;
359
+ height: 100%;
360
+ }
287
361
  `;
288
362
  const MoreInfoCSS = css`
289
363
  ${displayBlock};
290
364
  ${positionRelative};
291
- ${pd([2])};
365
+ padding: ${spacing([2])};
366
+ `;
367
+ const blurAnimationCSS = css`
368
+ animation: ${blurKeyframe} 1s ease;
292
369
  `;
293
370
  Avatar.defaultProps = {
294
371
  actionIconHeight: 24,
@@ -1301,8 +1301,7 @@ Attachment.defaultProps = {
1301
1301
  maxSize: getGlobal(['errorDefault', 'maxSize']),
1302
1302
  fileType: getGlobal(['errorDefault', 'fileType']),
1303
1303
  existingFile: getGlobal(['errorDefault', 'existingFile'])
1304
- },
1305
- viewType: 'detail'
1304
+ }
1306
1305
  };
1307
1306
  Attachment.propTypes = {
1308
1307
  /** File types that can be accepted. */
@@ -1,12 +1,13 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { css, jsx, keyframes } from '@emotion/core';
4
- import AvatarDefault from "../../assets/avatar/default.svg";
5
- import OptionWrapper from "../others/option-wrapper";
6
- import PropTypes from 'prop-types';
7
3
  import { forwardRef, Fragment, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
8
- import { borderRadius, displayInlineFlex, itemsCenter, objectCover, overflowHidden, parseWidthHeight, positionRelative } from "../../styles/general";
9
- import { classNames, useIntersection } from "../../utils";
4
+ import PropTypes from 'prop-types';
5
+ import { jsx, css, keyframes } from '@emotion/core';
6
+ import OptionWrapper from "../others/option-wrapper";
7
+ import { useIntersection } from "../../utils/intersectionObserver";
8
+ import { classNames } from "../../utils";
9
+ import AvatarDefault from "../../assets/avatar/default.svg";
10
+ import { itemsCenter, displayInlineFlex, overflowHidden, parseWidthHeight, positionRelative } from "../../styles/general";
10
11
  const blurKeyframe = keyframes`
11
12
  0% { -webkit-filter: blur(4px);}
12
13
  25% { -webkit-filter: blur(3px);}
@@ -28,7 +29,6 @@ const Image = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
28
29
  style,
29
30
  width
30
31
  }, reference) => {
31
- if (!reference) reference = useRef(null);
32
32
  if (!defaultSrc) defaultSrc = AvatarDefault;
33
33
  const ref = useRef(null);
34
34
  const [srcState, setSrcState] = useState(src);
@@ -53,9 +53,6 @@ const Image = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
53
53
  };
54
54
  }
55
55
  }
56
- return () => {
57
- setSrcState(defaultSrc);
58
- };
59
56
  }, [src]);
60
57
  useImperativeHandle(reference, () => {
61
58
  const currentRef = ref.current || {};
@@ -69,16 +66,21 @@ const Image = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
69
66
  });
70
67
  const renderImage = () => {
71
68
  const defaultImage = jsx("img", {
72
- css: objectCover,
73
69
  src: defaultSrc,
74
70
  alt: '',
71
+ style: {
72
+ objectFit: 'cover'
73
+ },
75
74
  width: width,
76
75
  height: height
77
76
  });
78
77
  const image = jsx(Fragment, null, !onLoaded && defaultImage, jsx("img", {
79
- css: [blurAnimationCSS, objectCover],
78
+ css: blurAnimationCSS,
80
79
  src: srcState,
81
80
  alt: alt || srcState,
81
+ style: {
82
+ objectFit: 'cover'
83
+ },
82
84
  onLoad: () => setOnLoaded(true),
83
85
  width: width,
84
86
  height: height
@@ -103,7 +105,7 @@ const ImageCSS = (width, height, circular) => css`
103
105
  ${itemsCenter};
104
106
  ${overflowHidden};
105
107
  ${parseWidthHeight(width, height)};
106
- ${circular && borderRadius('50%')};
108
+ ${circular && `border-radius: 50%`};
107
109
  `;
108
110
  const blurAnimationCSS = css`
109
111
  animation: ${blurKeyframe} 1s ease;
@@ -102,7 +102,7 @@ const TabItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
102
102
  css: _IndicatorCSS,
103
103
  className: 'Indicator'
104
104
  }));
105
- }, [children, className, color, disabled, endIcon, index, label, labelProps, level, onClick, props, startIcon, style, isVertical, tabIndexState]);
105
+ }, [children, className, color, disabled, endIcon, index, label, level, onClick, props, startIcon, style, isVertical, tabIndexState]);
106
106
  }));
107
107
  const TabButtonCSS = (color, isVertical) => css`
108
108
  ${flexRow};
@@ -0,0 +1,107 @@
1
+ import { css } from '@emotion/core';
2
+ import { itemsCenter, boxBorder, cursorPointer, displayBlock, displayInlineBlock, flexRow, positionRelative } from "../../styles/general";
3
+ import theme from "../../theme/settings";
4
+ const {
5
+ colors: {
6
+ fill: {
7
+ focus: fillFocus,
8
+ hover: fillHover,
9
+ pressed: fillPressed
10
+ }
11
+ }
12
+ } = theme;
13
+ export const TreeViewRootCSS = css`
14
+ ${displayBlock};
15
+ ${positionRelative};
16
+ .DGN-UI-Accordion {
17
+ box-shadow: none !important;
18
+ .DGN-UI-Accordion-Summary {
19
+ ${itemsCenter};
20
+ min-height: 40px;
21
+ padding: 0;
22
+ border-radius: 0;
23
+ &.focus {
24
+ background-color: ${theme.colors.focus};
25
+ }
26
+ .Accordion-Icon-Root {
27
+ ${flexRow};
28
+ margin-right: 4px;
29
+ }
30
+ }
31
+ .DGN-UI-Accordion-Details-Content {
32
+ padding: 0;
33
+ border-radius: 0;
34
+ }
35
+ .Accordion-Icon-Root {
36
+ ${flexRow};
37
+ transition: opacity 0.2s ease-out;
38
+ opacity: 1;
39
+ &.DGN-Invisible {
40
+ opacity: 0;
41
+ }
42
+ }
43
+ &.DGN-Hidden {
44
+ display: none !important;
45
+ }
46
+ }
47
+ .TreeView-All,
48
+ .TreeView-Content {
49
+ ${displayBlock};
50
+ ${positionRelative};
51
+ .DGN-UI-Accordion {
52
+ margin-bottom: 0;
53
+ }
54
+ }
55
+ .TreeView-Item-Checkbox {
56
+ ${displayInlineBlock};
57
+ ${positionRelative};
58
+ height: 100%;
59
+ margin-right: 8px;
60
+ }
61
+ .TreeView-Item {
62
+ ${flexRow};
63
+ ${positionRelative};
64
+ ${itemsCenter};
65
+ ${boxBorder};
66
+ min-height: 40px;
67
+ text-align: left;
68
+ color: ${theme.colors.text.main};
69
+ width: 100%;
70
+ &.non-child {
71
+ ${cursorPointer};
72
+ transition: background-color 300ms ease;
73
+ &.disabled {
74
+ color: ${theme.colors.disabled};
75
+ cursor: no-drop;
76
+ }
77
+ &:not(.disabled) {
78
+ &:hover {
79
+ background-color: ${fillHover};
80
+ }
81
+ &:focus {
82
+ background-color: ${fillFocus};
83
+ }
84
+ &:active {
85
+ background-color: ${fillPressed};
86
+ }
87
+ }
88
+ &.DGN-Hidden {
89
+ display: none !important;
90
+ }
91
+ }
92
+ &.focus {
93
+ background-color: ${theme.colors.focus};
94
+ }
95
+ &.TreeView-Item-active .DGN-UI-Typography {
96
+ font-weight: bold;
97
+ }
98
+ }
99
+ &.expand-able {
100
+ .TreeView-All {
101
+ margin-left: 34px;
102
+ }
103
+ .TreeView-Item.non-child {
104
+ padding-left: 34px;
105
+ }
106
+ }
107
+ `;
@@ -1,14 +1,14 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { css, jsx } from '@emotion/core';
4
- import { Accordion, AccordionDetails, AccordionSummary, ButtonIcon, Checkbox, Divider, InputBase, Typography } from "./..";
5
- import { getGlobal } from "../../global";
6
- import PropTypes from 'prop-types';
7
- import { forwardRef, Fragment, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
3
+ import { memo, useMemo, useState, useEffect, useRef, forwardRef, Fragment, useImperativeHandle } from 'react';
8
4
  import { render } from 'react-dom';
9
- import { bgColor, borderRadius, boxBorder, cursorNotAllowed, cursorPointer, displayBlock, displayInlineBlock, flexRow, itemsCenter, mgb, mgl, mgr, parseHeight, parseMinHeight, parseWidth, pd, pdl, positionRelative, textLeft } from "../../styles/general";
10
- import { useTheme } from "../../theme";
11
- import { classNames, mapParent, randomString, refType as ref, removeUnicode } from "../../utils";
5
+ import PropTypes from 'prop-types';
6
+ import { jsx, css } from '@emotion/core';
7
+ import { Accordion, AccordionSummary, AccordionDetails, Typography, Checkbox, Divider, InputBase, ButtonIcon } from '..';
8
+ import { classNames, mapParent, randomString, removeUnicode } from "../../utils";
9
+ import { getGlobal } from "../../global";
10
+ import { itemsCenter, boxBorder, cursorPointer, displayBlock, displayInlineBlock, flexRow, positionRelative } from "../../styles/general";
11
+ import theme from "../../theme/settings";
12
12
  const {
13
13
  colors: {
14
14
  system: {
@@ -22,8 +22,9 @@ const {
22
22
  text: {
23
23
  main: textMain
24
24
  }
25
- }
26
- } = useTheme();
25
+ },
26
+ spacing
27
+ } = theme;
27
28
  const separatorPattern = /\{\w+\}/g;
28
29
  const currentValue = {},
29
30
  itemsRenderAsync = {};
@@ -60,7 +61,6 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
60
61
  valueExpr,
61
62
  ...props
62
63
  }, reference) => {
63
- if (!reference) reference = useRef(null);
64
64
  const ref = useRef(null);
65
65
  const selectAllRef = useRef(null);
66
66
  const inputValueRef = useRef(null);
@@ -319,8 +319,8 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
319
319
  const checkBoxEl = currentTarget.querySelector('.TreeView-Item-Checkbox');
320
320
  if (multiple) {
321
321
  var _value;
322
- let checked;
323
- let inputEl;
322
+ let checked = false;
323
+ let inputEl = null;
324
324
  // Click on text (not checkbox)
325
325
  if (!checkBoxEl.contains(target)) {
326
326
  inputEl = checkBoxEl.querySelector('input');
@@ -604,7 +604,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
604
604
  }
605
605
  }, jsx("div", {
606
606
  className: 'TreeView-Item'
607
- }, selectBox || multiple ? jsx("span", {
607
+ }, (selectBox || multiple) && jsx("span", {
608
608
  className: 'TreeView-Item-Checkbox'
609
609
  }, jsx(Checkbox, {
610
610
  forTreeView: true,
@@ -612,19 +612,19 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
612
612
  value: typeof data === 'object' ? data[valueExpr] : data,
613
613
  stopPropagation: false,
614
614
  disabled: disabled
615
- })) : null, renderContent(data, keyArr, index))), jsx(AccordionDetails, {
615
+ })), renderContent(data, keyArr, index))), jsx(AccordionDetails, {
616
616
  id: id
617
617
  }, childItems.map((child, i) => renderTreeView(child, index + i, level + 1, sync, id))));
618
618
  }
619
619
  return jsx("div", {
620
- className: classNames('TreeView-Item', 'non-child', focusClass),
620
+ className: 'TreeView-Item non-child ' + focusClass,
621
621
  style: {
622
622
  paddingLeft: 34 + 16 * level
623
623
  },
624
624
  onClick: multiple || selectBox || onChange ? e => onClickHandler(e, data) : undefined,
625
625
  key: index,
626
626
  tabIndex: "-1"
627
- }, selectBox || multiple ? jsx("span", {
627
+ }, (selectBox || multiple) && jsx("span", {
628
628
  className: 'TreeView-Item-Checkbox'
629
629
  }, jsx(Checkbox, {
630
630
  forTreeView: true,
@@ -632,7 +632,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
632
632
  value: typeof data === 'object' ? data[valueExpr] : data,
633
633
  stopPropagation: false,
634
634
  disabled: disabled
635
- })) : null, renderContent(data, keyArr, index));
635
+ })), renderContent(data, keyArr, index));
636
636
  };
637
637
  useEffect(() => {
638
638
  currentValue[unique] = {};
@@ -756,7 +756,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
756
756
  return jsx("div", {
757
757
  css: TreeViewRootCSS,
758
758
  className: classNames('DGN-UI-TreeView', disabled && 'disabled')
759
- }, showSelectedItems && multiple ? jsx(InputBase, {
759
+ }, showSelectedItems && jsx(InputBase, {
760
760
  inputRef: inputValueRef,
761
761
  viewType: 'outlined',
762
762
  readOnly: true,
@@ -774,12 +774,12 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
774
774
  name: 'Cancel',
775
775
  onClick: clearAllValue
776
776
  })
777
- }) : null, allowSearch ? jsx(InputBase, {
777
+ }), allowSearch && jsx(InputBase, {
778
778
  startIcon: 'Search',
779
779
  onChange: onChangeHandler,
780
780
  viewType: 'outlined',
781
781
  ...searchProps
782
- }) : null, multiple && selectAll ? jsx(Fragment, null, jsx("div", {
782
+ }), multiple && selectAll && jsx(Fragment, null, jsx("div", {
783
783
  className: 'TreeView-All'
784
784
  }, jsx(Checkbox, {
785
785
  forTreeView: true,
@@ -788,10 +788,10 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
788
788
  inputRef: selectAllRef,
789
789
  stopPropagation: false,
790
790
  disabled: disabled
791
- })), jsx(Divider, null)) : null, jsx("div", {
791
+ })), jsx(Divider, null)), jsx("div", {
792
792
  ref: ref,
793
- className: classNames('TreeView-Content', disabled && 'disabled', className),
794
- ...props
793
+ ...props,
794
+ className: classNames('TreeView-Content', disabled && 'disabled', className)
795
795
  }, mapParent(dataSource, id, parentID, true).map((data, index) => renderTreeView(data, index.toString(), 0, sync))));
796
796
  }, [allowSearch, autoExpandToResult, className, collapseIcon, dataSource, disabled, disabledBoldResult, disabledRelevantValue, displayExpr, expandIcon, id, multiple, multipleValueMode, onChange, parentID, renderAsyncFromLevel, renderAsyncWithLength, renderItem, searchMode, searchProps, selectAll, selectAllLabel, selectBox, showChildrenOfResult, showSelectedItems, value, valueExpr]);
797
797
  }));
@@ -802,20 +802,20 @@ const TreeViewRootCSS = css`
802
802
  box-shadow: none !important;
803
803
  .DGN-UI-Accordion-Summary {
804
804
  ${itemsCenter};
805
- ${parseMinHeight(40)};
806
- ${pd(0)};
807
- ${borderRadius(0)};
805
+ min-height: 40px;
806
+ padding: 0;
807
+ border-radius: 0;
808
808
  &.focus {
809
- ${bgColor(fillFocus)};
809
+ background-color: ${fillFocus};
810
810
  }
811
811
  .Accordion-Icon-Root {
812
812
  ${flexRow};
813
- ${mgr([1])};
813
+ margin-right: ${spacing([1])};
814
814
  }
815
815
  }
816
816
  .DGN-UI-Accordion-Details-Content {
817
- ${pd(0)};
818
- ${borderRadius(0)};
817
+ padding: 0;
818
+ border-radius: 0;
819
819
  }
820
820
  .Accordion-Icon-Root {
821
821
  ${flexRow};
@@ -834,40 +834,40 @@ const TreeViewRootCSS = css`
834
834
  ${displayBlock};
835
835
  ${positionRelative};
836
836
  .DGN-UI-Accordion {
837
- ${mgb(0)};
837
+ margin-bottom: 0;
838
838
  }
839
839
  }
840
840
  .TreeView-Item-Checkbox {
841
841
  ${displayInlineBlock};
842
842
  ${positionRelative};
843
- ${parseHeight('100%')};
844
- ${mgr([2])};
843
+ height: 100%;
844
+ margin-right: ${spacing([2])};
845
845
  }
846
846
  .TreeView-Item {
847
847
  ${flexRow};
848
848
  ${positionRelative};
849
849
  ${itemsCenter};
850
850
  ${boxBorder};
851
- ${parseWidth('100%')};
852
- ${parseMinHeight(40)};
853
- ${textLeft};
851
+ min-height: 40px;
852
+ text-align: left;
854
853
  color: ${textMain};
854
+ width: 100%;
855
855
  &.non-child {
856
856
  ${cursorPointer};
857
857
  transition: background-color 300ms ease;
858
858
  &.disabled {
859
- ${cursorNotAllowed};
860
859
  color: ${systemDisabled};
860
+ cursor: no-drop;
861
861
  }
862
862
  &:not(.disabled) {
863
863
  &:hover {
864
- ${bgColor(fillHover)};
864
+ background-color: ${fillHover};
865
865
  }
866
866
  &:focus {
867
- ${bgColor(fillFocus)};
867
+ background-color: ${fillFocus};
868
868
  }
869
869
  &:active {
870
- ${bgColor(fillPressed)};
870
+ background-color: ${fillPressed};
871
871
  }
872
872
  }
873
873
  &.DGN-Hidden {
@@ -875,7 +875,7 @@ const TreeViewRootCSS = css`
875
875
  }
876
876
  }
877
877
  &.focus {
878
- ${bgColor(fillFocus)};
878
+ background-color: ${fillFocus};
879
879
  }
880
880
  &.TreeView-Item-active .DGN-UI-Typography {
881
881
  font-weight: bold;
@@ -883,10 +883,10 @@ const TreeViewRootCSS = css`
883
883
  }
884
884
  &.expand-able {
885
885
  .TreeView-All {
886
- ${mgl([8.5])};
886
+ margin-left: ${spacing([8.5])};
887
887
  }
888
888
  .TreeView-Item.non-child {
889
- ${pdl([8.5])};
889
+ padding-left: ${spacing([8.5])};
890
890
  }
891
891
  }
892
892
  `;
@@ -918,82 +918,86 @@ TreeView.defaultProps = {
918
918
  valueExpr: ''
919
919
  };
920
920
  TreeView.propTypes = {
921
- /** If `true`, display input box search. */
921
+ /** expand immediate if true */
922
+ expand: PropTypes.bool,
923
+ /** prevent all event if true */
924
+ disabled: PropTypes.bool,
925
+ /** show checkbox in each item */
926
+ selectBox: PropTypes.bool,
927
+ /** allow select multiple item if true */
928
+ multiple: PropTypes.bool,
929
+ /** allow select/unselect all items on one click (just support for multiple) */
930
+ selectAll: PropTypes.bool,
931
+ /** display input box search if true */
922
932
  allowSearch: PropTypes.bool,
923
- /** If `true`, expand TreeView to match result. */
933
+ /** display all value in a box */
934
+ showSelectedItems: PropTypes.bool,
935
+ /** disabled parent and children item if true (only supported for multipleValueMode is single) */
936
+ disabledRelevantValue: PropTypes.bool,
937
+ /** prevent display content of match values with bold style */
938
+ disabledBoldResult: PropTypes.bool,
939
+ /** expand TreeView to match result if true */
924
940
  autoExpandToResult: PropTypes.bool,
925
- /** Class for component. */
941
+ /** still show children of last result was found if true */
942
+ showChildrenOfResult: PropTypes.bool,
943
+ /** Used to identify the parent key */
944
+ id: PropTypes.string.isRequired,
945
+ /** used for mapping into a nested list */
946
+ parentID: PropTypes.string.isRequired,
947
+ /** class on element */
926
948
  className: PropTypes.string,
927
- /** Icon display for collapse icon. */
928
- collapseIcon: PropTypes.any,
929
- /** The array of elements that appear in the tree list. */
930
- dataSource: PropTypes.array,
931
- /** If `true`, the component is disabled. */
932
- disabled: PropTypes.bool,
933
- /** If `true`, prevent display content of match values with bold style. */
934
- disabledBoldResult: PropTypes.bool,
935
- /** If `true`, disabled parent and children item (only supported for multipleValueMode is single). */
936
- disabledRelevantValue: PropTypes.bool,
937
- /** Field name used for text display in dropdown list.<br/>
949
+ /**
950
+ * field name used for text display<br/>
938
951
  * Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
939
952
  * Note: don't use 'id - name', return undefined
940
953
  */
941
954
  displayExpr: PropTypes.string,
942
- /** If `true`, expand immediate after render (shouldn't use this). */
943
- expand: PropTypes.bool,
944
- /** Icon display for expand icon. */
945
- expandIcon: PropTypes.any,
946
- /** If `true`, value must be an array and the treeview will support multiple selections. */
947
- multiple: PropTypes.bool,
948
- /** Return value for the select multiple use case. */
955
+ /** the key to determine value to return */
956
+ valueExpr: PropTypes.string,
957
+ /** return value for the select multiple use case */
949
958
  multipleValueMode: PropTypes.oneOf(['single', 'multiple', 'inheritance']),
950
959
  /**
951
- * Callback fired when the value changes.<br />
952
- * return 2 parameters (e, data)<br />
953
- * * e: element (insist {value, justSelected, data})<br/>
954
- * &nbsp;&nbsp;&nbsp;&nbsp; + value is one or an array of selected values<br />
955
- * &nbsp;&nbsp;&nbsp;&nbsp; + justSelected is value has just been selected (either true or false))<br />
956
- * &nbsp;&nbsp;&nbsp;&nbsp; + data is one or an array of selected values with full information<br />
957
- * * data: array of selected values (not recommend because it's the same e.value)
960
+ * return value for the select multiple use case
961
+ * * contains: "Công ty" contains "công", but not contains "cong"
962
+ * * similar: "Công ty" contains "công" and "cong"
958
963
  */
959
- onChange: PropTypes.func,
960
- /** Used for mapping into a nested list. */
961
- parentID: PropTypes.string.isRequired,
962
- /** Will render asynchronously from level equal this number. */
963
- renderAsyncFromLevel: PropTypes.oneOf([2, 3, 4, 5]),
964
- /** Will render asynchronously if the number of elements is greater than this number. */
964
+ searchMode: PropTypes.oneOf(['contains', 'similar']),
965
+ /** The content display for label of checkbox select all */
966
+ selectAllLabel: PropTypes.string,
967
+ /**
968
+ * duration wait enter search content on search<br/>
969
+ * Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
970
+ */
971
+ searchDelayTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
972
+ /** will render asynchronously if the number of elements is greater than this number */
965
973
  renderAsyncWithLength: PropTypes.number,
966
- /** Function displays items by custom.<br/>
974
+ /** will render asynchronously from level equal this number */
975
+ renderAsyncFromLevel: PropTypes.oneOf([2, 3, 4, 5]),
976
+ /** data to show in tree list */
977
+ dataSource: PropTypes.array,
978
+ /** the value was selected */
979
+ value: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
980
+ /** function displays items by custom<br/>
967
981
  * renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
968
982
  * --> such as: displayExpr={'name - role'}
969
983
  */
970
984
  renderItem: PropTypes.func,
971
985
  /**
972
- * Duration wait enter search content on search.<br/>
973
- * Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
974
- * If `true`, used default delayOnInput.
986
+ * on change value function<br />
987
+ * return 2 parameters (e, data)<br />
988
+ * * e: element (insist {value, justSelected, data})<br/>
989
+ * &nbsp;&nbsp;&nbsp;&nbsp; + value is one or an array of selected values<br />
990
+ * &nbsp;&nbsp;&nbsp;&nbsp; + justSelected is value has just been selected (either true or false))<br />
991
+ * &nbsp;&nbsp;&nbsp;&nbsp; + data is one or an array of selected values with full information<br />
992
+ * * data: array of selected values (not recommend because it's the same e.value)
975
993
  */
976
- searchDelayTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
977
- /** Specifies a comparison operation used to search items. */
978
- searchMode: PropTypes.oneOf(['contains', 'similar']),
979
- /** The props for InputBase. */
994
+ onChange: PropTypes.func,
995
+ /** the icon to display for expand icon */
996
+ expandIcon: PropTypes.any,
997
+ /** the props for InputBase */
980
998
  searchProps: PropTypes.object,
981
- /** If `true`, allow select/unselect all items on one click (just support for multiple). */
982
- selectAll: PropTypes.bool,
983
- /** The content display for label of checkbox select all */
984
- selectAllLabel: PropTypes.string,
985
- /** If `true`, show checkbox in each item. */
986
- selectBox: PropTypes.bool,
987
- /** If `true`, still show children of last result was found. */
988
- showChildrenOfResult: PropTypes.bool,
989
- /** If `true`, display all value in a box. */
990
- showSelectedItems: PropTypes.bool,
991
- /** Used to identify the parent key. */
992
- id: PropTypes.string.isRequired,
993
- /** The displayed value of component. */
994
- value: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
995
- /** The field name used for the returned result. */
996
- valueExpr: PropTypes.string,
999
+ /** the icon to display for collapse icon */
1000
+ collapseIcon: PropTypes.any,
997
1001
  /**
998
1002
  * get ref of TreeView component, insist:<br/>
999
1003
  * {<br/>
@@ -1011,6 +1015,6 @@ TreeView.propTypes = {
1011
1015
  * &nbsp;&nbsp;&nbsp;&nbsp;get: get DOM of TreeView component<br/>
1012
1016
  * }
1013
1017
  */
1014
- ref: ref
1018
+ ref: PropTypes.any
1015
1019
  };
1016
1020
  export default TreeView;
package/package.json CHANGED
@@ -1,73 +1,42 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.86-beta.1",
4
- "description": "",
3
+ "version": "1.3.87",
4
+ "description": "The DigiNet core ui",
5
+ "homepage": "https://diginet.com.vn",
5
6
  "main": "index.js",
6
- "license": "UNLICENSED",
7
7
  "scripts": {
8
- "start": "npm-run-all --parallel start-sb eslint-test",
9
- "start-sb": "start-storybook -p 9050",
10
- "build-storybook": "build-storybook -c .storybook -s src",
11
- "build": "run-script-os",
12
- "build:windows": "rimraf dist && mkdirp dist/components && npm run compile && sass --style=compressed src/scss:dist/css && xcopy src\\\\assets dist\\\\assets\\ /e /y",
13
- "build:darwin:linux:default": "rm -rf dist && npm run compile && sass --style=compressed src/scss:dist/css && cp -rf src/assets dist/assets",
14
- "compile": "babel src --out-dir dist --ignore **/*.stories.js",
15
- "pack": "npm run build && cp *.md dist/ && npm run version:bump --silent && npm run version:add --silent && cd dist && npm pack",
16
- "production-keep-version": "npm run build && cp *.md dist/ && cp package.json dist/ && cd dist && npm publish",
17
- "beta": "npm run build && cp *.md dist/ && cp package.json dist/ && cd dist && npm publish --tag beta",
18
- "production": "npm run build && cp *.md dist/ && npm run version:bump --silent && npm run version:add --silent && cd dist && npm publish",
19
- "version:add": "run-script-os",
20
- "version:add:windows": "cat package.json.tmp | sed \"s/0.0.0/%npm_package_version%/g\" > dist/package.json",
21
- "version:add:darwin:linux:default": "VERSION=$(npm run version:extract --silent) && cat package.json.tmp | sed \"s/0.0.0/${VERSION}/g\" > dist/package.json",
22
- "version:bump": "npm version patch --no-git-tag-version --silent",
23
- "version:extract": "cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]'",
24
- "test": "echo \"Error: no test specified\" && exit 1",
25
- "lint": "eslint --fix --config .eslintrc.js \"**/*.js\"",
26
- "eslint-test": "onchange \"src/**/*.{js,jsx,json}\" -- eslint . --fix",
27
- "test-storybook": "test-storybook --url http://localhost:9050"
8
+ "start-js": "react-scripts start --max_old_space_size=4096",
9
+ "start": "npx npm-run-all -p start-js",
10
+ "build": "GENERATE_SOURCEMAP=false && react-scripts build --env=production --max_old_space_size=8192",
11
+ "eject": "react-scripts eject",
12
+ "test": "echo \"Error: no test specified\" && exit 1"
28
13
  },
29
14
  "dependencies": {
30
15
  "@emotion/core": "^10.0.35",
31
- "babel-plugin-module-resolver": "^4.1.0",
32
16
  "prop-types": "^15.7.2"
33
17
  },
34
- "lint-staged": {
35
- "*/**/*.{js,jsx,json}": [
36
- "prettier --write",
37
- "git add"
38
- ]
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://diginetvn@bitbucket.org/diginetvn/diginet-core-ui.git"
39
21
  },
40
- "devDependencies": {
41
- "@babel/cli": "^7.14.3",
42
- "@babel/plugin-proposal-class-properties": "^7.13.0",
43
- "@babel/plugin-proposal-logical-assignment-operators": "^7.16.0",
44
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
45
- "@babel/plugin-proposal-optional-chaining": "^7.14.2",
46
- "@babel/plugin-proposal-private-methods": "^7.18.6",
47
- "@babel/plugin-proposal-private-property-in-object": "^7.18.6",
48
- "@babel/preset-react": "^7.13.13",
49
- "@storybook/addon-actions": "6.2.9",
50
- "@storybook/addon-essentials": "6.2.9",
51
- "@storybook/addon-links": "6.2.9",
52
- "@storybook/addon-postcss": "^2.0.0",
53
- "@storybook/react": "6.2.9",
54
- "@storybook/test-runner": "^0.7.1",
55
- "autoprefixer": "^10.3.1",
56
- "babel-loader": "^8.2.2",
57
- "eslint": "^8.4.1",
58
- "eslint-plugin-react": "^7.27.1",
59
- "eslint-plugin-regex": "^1.10.0",
60
- "husky": "^7.0.4",
61
- "jest": "^27.5.1",
62
- "lint-staged": "^12.1.2",
63
- "mkdirp": "^1.0.4",
64
- "npm-run-all": "^4.1.5",
65
- "onchange": "^7.1.0",
66
- "postcss-flexbugs-fixes": "^5.0.2",
67
- "react": "^17.0.1",
68
- "react-dom": "^17.0.1",
69
- "rimraf": "^3.0.2",
70
- "run-script-os": "^1.1.6",
71
- "sass": "^1.37.0"
72
- }
22
+ "keywords": [
23
+ "core ui",
24
+ "diginet"
25
+ ],
26
+ "author": "rocachien",
27
+ "contributors": [
28
+ {
29
+ "name": "Chien Do",
30
+ "email": "rocachien@gmail.com"
31
+ },
32
+ {
33
+ "name": "Nhat Tran",
34
+ "email": "tranminhnhat1005@gmail.com"
35
+ },
36
+ {
37
+ "name": "Thuan Nguyen",
38
+ "email": "nt.thuan.hutech@gmail.com"
39
+ }
40
+ ],
41
+ "license": "MIT"
73
42
  }
package/readme.md CHANGED
@@ -38,6 +38,10 @@ npm test
38
38
  ```
39
39
 
40
40
  ## Changelog
41
+ ## 1.3.87
42
+ - \[Added\]: Icon – Upload, Workflow
43
+ - \[Fixed\]: InputBase – Fix not run when inputRef is function
44
+
41
45
  ## 1.3.86
42
46
  - \[Changed\]: Icon – Optimize code
43
47
  - \[Fixed\]: Dropdown – Fix bug cannot select multiple after search
package/utils/index.js CHANGED
@@ -19,7 +19,6 @@ export { default as SbTemplate } from "./sb-template";
19
19
  export { default as updatePosition } from "./updatePosition";
20
20
  export { default as useDelayUnmount } from "./useDelayUnmount";
21
21
  export { default as useInput } from "./useInput";
22
- export { default as useIntersection } from "./intersectionObserver";
23
22
  export { default as useMediaQuery } from "./useMediaQuery";
24
23
  export { default as useOnClickOutside } from "./useOnClickOutside";
25
24
  export { default as usePortal } from "./usePortal";
@@ -22,7 +22,7 @@ const getIntersectionObserver = () => {
22
22
  }
23
23
  return observer;
24
24
  };
25
- const useIntersection = (elem, callback) => {
25
+ export const useIntersection = (elem, callback) => {
26
26
  useEffect(() => {
27
27
  let target = elem.current;
28
28
  let observer = getIntersectionObserver();
@@ -33,5 +33,4 @@ const useIntersection = (elem, callback) => {
33
33
  observer.unobserve(target);
34
34
  };
35
35
  }, []);
36
- };
37
- export default useIntersection;
36
+ };