diginet-core-ui 1.3.73 → 1.3.75

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.
Files changed (58) hide show
  1. package/assets/images/menu/dhr/MHRP29N0026.svg +13 -0
  2. package/assets/images/menu/dhr/MHRP29N0027.svg +14 -0
  3. package/assets/images/menu/dhr/MHRP29N0028.svg +15 -0
  4. package/components/accordion/details.js +19 -10
  5. package/components/accordion/group.js +15 -6
  6. package/components/accordion/index.js +20 -11
  7. package/components/accordion/summary.js +18 -9
  8. package/components/avatar/index.js +20 -20
  9. package/components/badge/index.js +17 -9
  10. package/components/button/icon.js +33 -25
  11. package/components/button/index.js +25 -17
  12. package/components/card/body.js +12 -4
  13. package/components/card/extra.js +12 -4
  14. package/components/card/footer.js +12 -4
  15. package/components/card/header.js +12 -4
  16. package/components/card/index.js +12 -4
  17. package/components/chip/index.js +6 -6
  18. package/components/form-control/attachment/index.js +197 -192
  19. package/components/form-control/date-picker/index.js +4 -2
  20. package/components/form-control/date-range-picker/index.js +21 -14
  21. package/components/form-control/dropdown/index.js +69 -48
  22. package/components/form-control/input-base/index.js +505 -483
  23. package/components/form-control/label/index.js +27 -21
  24. package/components/form-control/text-input/index.js +8 -5
  25. package/components/grid/Col.js +8 -7
  26. package/components/grid/Container.js +16 -15
  27. package/components/grid/Row.js +16 -15
  28. package/components/grid/index.js +17 -36
  29. package/components/image/index.js +164 -0
  30. package/components/index.js +3 -1
  31. package/components/modal/body.js +12 -9
  32. package/components/modal/footer.js +22 -11
  33. package/components/modal/header.js +25 -13
  34. package/components/modal/index.js +32 -30
  35. package/components/modal/modal.js +29 -25
  36. package/components/others/option-wrapper/index.js +5 -18
  37. package/components/paging/page-info.js +45 -33
  38. package/components/paging/page-selector2.js +45 -33
  39. package/components/popover/body.js +14 -6
  40. package/components/popover/footer.js +15 -6
  41. package/components/popover/header.js +17 -7
  42. package/components/popover/index.js +262 -129
  43. package/components/status/index.js +12 -4
  44. package/components/tab/tab-container.js +29 -27
  45. package/components/tab/tab-header.js +35 -30
  46. package/components/tab/tab-panel.js +31 -27
  47. package/components/tab/tab.js +47 -37
  48. package/components/tree-view/index.js +146 -111
  49. package/components/typography/index.js +47 -36
  50. package/icons/basic.js +248 -0
  51. package/icons/effect.js +44 -36
  52. package/package.json +1 -1
  53. package/readme.md +43 -0
  54. package/styles/general.js +34 -11
  55. package/theme/index.js +1 -1
  56. package/theme/set-theme.js +5 -4
  57. package/utils/index.js +13 -10
  58. package/utils/useMediaQuery.js +4 -2
@@ -6,52 +6,60 @@ import { render } from 'react-dom';
6
6
  import PropTypes from 'prop-types';
7
7
  import { jsx, css } from '@emotion/core';
8
8
  import { Accordion, AccordionSummary, AccordionDetails, Typography, Checkbox, Divider, InputBase, ButtonIcon } from '..';
9
- import { mapParent, randomString, removeUnicode } from '../../utils';
9
+ import { classNames, mapParent, randomString, removeUnicode } from '../../utils';
10
10
  import { getGlobal } from '../../global';
11
11
  import { alignCenter, borderBox, cursorPointer, displayBlock, displayInlineBlock, flexRow, positionRelative } from '../../styles/general';
12
12
  import theme from '../../theme/settings';
13
13
  const {
14
14
  colors: {
15
+ system: {
16
+ disabled: systemDisabled
17
+ },
15
18
  fill: {
16
19
  focus: fillFocus,
17
20
  hover: fillHover,
18
21
  pressed: fillPressed
22
+ },
23
+ text: {
24
+ main: textMain
19
25
  }
20
- }
26
+ },
27
+ spacing
21
28
  } = theme;
22
29
  const separatorPattern = /\{\w+\}/g;
23
30
  const currentValue = {},
24
31
  itemsRenderAsync = {};
25
32
  const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
26
- expand,
27
- disabled,
28
- selectBox,
29
- multiple,
30
- selectAll,
33
+ action = {},
31
34
  allowSearch,
32
- showSelectedItems,
33
- disabledRelevantValue,
34
- disabledBoldResult,
35
35
  autoExpandToResult,
36
- showChildrenOfResult,
36
+ className,
37
+ collapseIcon,
38
+ dataSource,
39
+ disabled,
40
+ disabledBoldResult,
41
+ disabledRelevantValue,
37
42
  displayExpr,
38
- valueExpr,
43
+ expand,
44
+ expandIcon,
39
45
  id,
40
- parentID,
41
- className,
42
- selectAllLabel,
46
+ multiple,
43
47
  multipleValueMode,
44
- searchMode,
45
- searchDelayTime,
46
- renderAsyncWithLength,
48
+ onChange,
49
+ parentID,
47
50
  renderAsyncFromLevel,
48
- expandIcon,
49
- collapseIcon,
50
- dataSource,
51
- value,
51
+ renderAsyncWithLength,
52
52
  renderItem,
53
- onChange,
53
+ searchDelayTime,
54
+ searchMode,
54
55
  searchProps,
56
+ selectAll,
57
+ selectAllLabel,
58
+ selectBox,
59
+ showChildrenOfResult,
60
+ showSelectedItems,
61
+ value,
62
+ valueExpr,
55
63
  ...props
56
64
  }, reference) => {
57
65
  const ref = useRef(null);
@@ -248,6 +256,12 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
248
256
  if (node.classList.contains('DGN-UI-Accordion') && node.firstChild.classList.contains('DGN-UI-Accordion-Summary')) {
249
257
  var _node$querySelectorAl;
250
258
 
259
+ const summaryEl = node.firstChild;
260
+
261
+ if (!summaryEl.classList.contains('expanding')) {
262
+ summaryEl.lastChild.firstChild.click();
263
+ }
264
+
251
265
  const checkbox = node.firstChild.firstChild.lastChild.firstChild.firstChild.firstChild; // Trường hợp phải set về false để xét các input đã check không bao gồm node này
252
266
 
253
267
  checkbox.firstChild.checked = isChecked;
@@ -258,13 +272,10 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
258
272
  node.classList[mustDisabled || isChecked ? 'add' : 'remove']('disabled');
259
273
  checkbox.classList[mustDisabled || isChecked ? 'add' : 'remove']('disabled');
260
274
  Array.from(node.childNodes).forEach(e => {
261
- e.classList[mustDisabled || isChecked ? 'add' : 'remove']('treeview-disabled');
275
+ setTimeout(() => {
276
+ e.classList[mustDisabled || isChecked ? 'add' : 'remove']('treeview-disabled');
277
+ });
262
278
  });
263
- const summaryEl = node.firstChild;
264
-
265
- if (!summaryEl.classList.contains('expanding')) {
266
- summaryEl.lastChild.firstChild.click();
267
- }
268
279
  }
269
280
  }
270
281
  };
@@ -646,6 +657,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
646
657
 
647
658
  const keyArr = displayExpr.match(separatorPattern);
648
659
  const isTrue = value.includes(data[valueExpr] || data);
660
+ const isParentTrue = value.includes(data[parentID]);
649
661
  const focusClass = isTrue && !selectBox && !multiple ? 'focus' : '';
650
662
  const childItems = data.childItems; // is Summary
651
663
 
@@ -657,7 +669,17 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
657
669
  return jsx(Accordion, {
658
670
  key: index,
659
671
  className: focusClass,
660
- expand: expand || data.expand
672
+ expand: expand || data.expand,
673
+ onExpand: e => {
674
+ if (disabledRelevantValue && !isTrue && !isParentTrue) {
675
+ handleDisabledParent(e, isTrue);
676
+ }
677
+ },
678
+ onCollapse: e => {
679
+ if (disabledRelevantValue && !isTrue && !isParentTrue) {
680
+ handleDisabledParent(e, isTrue);
681
+ }
682
+ }
661
683
  }, jsx(AccordionSummary, {
662
684
  expandIcon: expandIcon,
663
685
  collapseIcon: collapseIcon,
@@ -776,7 +798,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
776
798
  });
777
799
  }
778
800
  }
779
- }, [value]);
801
+ }, []);
780
802
  useEffect(() => {
781
803
  if (selectAllRef.current) {
782
804
  checkedSelectAllCheckbox();
@@ -803,18 +825,32 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
803
825
  });
804
826
  }
805
827
  }, [dataSource, value, multiple, selectBox, onChange]);
806
- useImperativeHandle(reference, () => ({
807
- disabled,
808
- displayExpr,
809
- valueExpr,
810
- id,
811
- parentID,
812
- value,
813
- getValue: () => Object.keys(currentValue[unique]).filter(v => currentValue[unique][v]),
814
- setValue,
815
- handleCheckbox,
816
- get: () => ref.current
817
- }));
828
+ useImperativeHandle(reference, () => {
829
+ const currentRef = ref.current || {};
830
+ currentRef.element = ref.current;
831
+ const _instance = { ...action
832
+ }; // methods
833
+
834
+ _instance.__proto__ = {}; // hidden methods
835
+
836
+ currentRef.instance = _instance; // keep old method
837
+
838
+ currentRef.disabled = disabled;
839
+ currentRef.displayExpr = displayExpr;
840
+ currentRef.valueExpr = valueExpr;
841
+ currentRef.id = id;
842
+ currentRef.parentID = parentID;
843
+ currentRef.value = value;
844
+
845
+ currentRef.getValue = () => Object.keys(currentValue[unique]).filter(v => currentValue[unique][v]);
846
+
847
+ currentRef.setValue = setValue;
848
+ currentRef.handleCheckbox = handleCheckbox;
849
+
850
+ currentRef.get = () => ref.current;
851
+
852
+ return currentRef;
853
+ });
818
854
  return useMemo(() => {
819
855
  var _value3;
820
856
 
@@ -830,7 +866,7 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
830
866
  const sync = (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) > renderAsyncWithLength;
831
867
  return jsx("div", {
832
868
  css: TreeViewRootCSS,
833
- className: 'DGN-UI-TreeView' + (disabled ? ' disabled' : '')
869
+ className: classNames('DGN-UI-TreeView', disabled && 'disabled')
834
870
  }, showSelectedItems && jsx(InputBase, {
835
871
  inputRef: inputValueRef,
836
872
  viewType: 'outlined',
@@ -866,9 +902,9 @@ const TreeView = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
866
902
  })), jsx(Divider, null)), jsx("div", {
867
903
  ref: ref,
868
904
  ...props,
869
- className: ['TreeView-Content', disabled ? 'disabled' : '', className].join(' ').trim().replace(/\s+/g, ' ')
905
+ className: classNames('TreeView-Content', disabled && 'disabled', className)
870
906
  }, mapParent(dataSource, id, parentID, true).map((data, index) => renderTreeView(data, index.toString(), 0, sync))));
871
- }, [dataSource, value, renderAsyncWithLength, disabled, showSelectedItems, allowSearch, multiple, selectAll, selectAllLabel, className, selectBox, id, parentID, disabledBoldResult, autoExpandToResult, showChildrenOfResult, searchMode, onChange, searchProps]);
907
+ }, [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]);
872
908
  }));
873
909
  const TreeViewRootCSS = css`
874
910
  ${displayBlock};
@@ -881,11 +917,11 @@ const TreeViewRootCSS = css`
881
917
  padding: 0;
882
918
  border-radius: 0;
883
919
  &.focus {
884
- background-color: ${theme.colors.focus};
920
+ background-color: ${fillFocus};
885
921
  }
886
922
  .Accordion-Icon-Root {
887
923
  ${flexRow};
888
- margin-right: 4px;
924
+ margin-right: ${spacing([1])};
889
925
  }
890
926
  }
891
927
  .DGN-UI-Accordion-Details-Content {
@@ -916,7 +952,7 @@ const TreeViewRootCSS = css`
916
952
  ${displayInlineBlock};
917
953
  ${positionRelative};
918
954
  height: 100%;
919
- margin-right: 8px;
955
+ margin-right: ${spacing([2])};
920
956
  }
921
957
  .TreeView-Item {
922
958
  ${flexRow};
@@ -925,13 +961,13 @@ const TreeViewRootCSS = css`
925
961
  ${borderBox};
926
962
  min-height: 40px;
927
963
  text-align: left;
928
- color: ${theme.colors.text.main};
964
+ color: ${textMain};
929
965
  width: 100%;
930
966
  &.non-child {
931
967
  ${cursorPointer};
932
968
  transition: background-color 300ms ease;
933
969
  &.disabled {
934
- color: ${theme.colors.disabled};
970
+ color: ${systemDisabled};
935
971
  cursor: no-drop;
936
972
  }
937
973
  &:not(.disabled) {
@@ -950,7 +986,7 @@ const TreeViewRootCSS = css`
950
986
  }
951
987
  }
952
988
  &.focus {
953
- background-color: ${theme.colors.focus};
989
+ background-color: ${fillFocus};
954
990
  }
955
991
  &.TreeView-Item-active .DGN-UI-Typography {
956
992
  font-weight: bold;
@@ -958,40 +994,39 @@ const TreeViewRootCSS = css`
958
994
  }
959
995
  &.expand-able {
960
996
  .TreeView-All {
961
- margin-left: 34px;
997
+ margin-left: ${spacing([8.5])};
962
998
  }
963
999
  .TreeView-Item.non-child {
964
- padding-left: 34px;
1000
+ padding-left: ${spacing([8.5])};
965
1001
  }
966
1002
  }
967
1003
  `;
968
1004
  TreeView.defaultProps = {
969
- expand: false,
970
- disabled: false,
971
- disabledMap: false,
972
- selectBox: false,
973
- multiple: false,
974
- selectAll: false,
975
1005
  allowSearch: false,
976
- showSelectedItems: false,
977
- disabledRelevantValue: false,
978
- disabledBoldResult: false,
979
1006
  autoExpandToResult: true,
980
- showChildrenOfResult: false,
981
- displayExpr: 'name',
982
- id: 'id',
983
- parentID: 'parentID',
984
- valueExpr: '',
985
1007
  className: '',
986
- selectAllLabel: getGlobal('selectAll'),
987
1008
  dataSource: [],
988
- value: [],
1009
+ disabled: false,
1010
+ disabledBoldResult: false,
1011
+ disabledRelevantValue: false,
1012
+ displayExpr: 'name',
1013
+ expand: false,
989
1014
  expandIcon: 'ArrowDown',
1015
+ id: 'id',
1016
+ multiple: false,
990
1017
  multipleValueMode: 'multiple',
991
- searchMode: 'contains',
992
- renderAsyncWithLength: 200,
1018
+ parentID: 'parentID',
993
1019
  renderAsyncFromLevel: 2,
994
- searchProps: {}
1020
+ renderAsyncWithLength: 200,
1021
+ searchMode: 'contains',
1022
+ searchProps: {},
1023
+ selectAll: false,
1024
+ selectAllLabel: getGlobal('selectAll'),
1025
+ selectBox: false,
1026
+ showChildrenOfResult: false,
1027
+ showSelectedItems: false,
1028
+ value: [],
1029
+ valueExpr: ''
995
1030
  };
996
1031
  TreeView.propTypes = {
997
1032
  /** expand immediate if true */
@@ -1036,10 +1071,10 @@ TreeView.propTypes = {
1036
1071
  /** class on element */
1037
1072
  className: PropTypes.string,
1038
1073
 
1039
- /**
1040
- * field name used for text display<br/>
1041
- * Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
1042
- * Note: don't use 'id - name', return undefined
1074
+ /**
1075
+ * field name used for text display<br/>
1076
+ * Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
1077
+ * Note: don't use 'id - name', return undefined
1043
1078
  */
1044
1079
  displayExpr: PropTypes.string,
1045
1080
 
@@ -1049,19 +1084,19 @@ TreeView.propTypes = {
1049
1084
  /** return value for the select multiple use case */
1050
1085
  multipleValueMode: PropTypes.oneOf(['single', 'multiple', 'inheritance']),
1051
1086
 
1052
- /**
1053
- * return value for the select multiple use case
1054
- * * contains: "Công ty" contains "công", but not contains "cong"
1055
- * * similar: "Công ty" contains "công" and "cong"
1087
+ /**
1088
+ * return value for the select multiple use case
1089
+ * * contains: "Công ty" contains "công", but not contains "cong"
1090
+ * * similar: "Công ty" contains "công" and "cong"
1056
1091
  */
1057
1092
  searchMode: PropTypes.oneOf(['contains', 'similar']),
1058
1093
 
1059
1094
  /** The content display for label of checkbox select all */
1060
1095
  selectAllLabel: PropTypes.string,
1061
1096
 
1062
- /**
1063
- * duration wait enter search content on search<br/>
1064
- * Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
1097
+ /**
1098
+ * duration wait enter search content on search<br/>
1099
+ * Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
1065
1100
  */
1066
1101
  searchDelayTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
1067
1102
 
@@ -1077,20 +1112,20 @@ TreeView.propTypes = {
1077
1112
  /** the value was selected */
1078
1113
  value: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
1079
1114
 
1080
- /** function displays items by custom<br/>
1081
- * renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
1082
- * --> such as: displayExpr={'name - role'}
1115
+ /** function displays items by custom<br/>
1116
+ * renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
1117
+ * --> such as: displayExpr={'name - role'}
1083
1118
  */
1084
1119
  renderItem: PropTypes.func,
1085
1120
 
1086
- /**
1087
- * on change value function<br />
1088
- * return 2 parameters (e, data)<br />
1089
- * * e: element (insist {value, justSelected, data})<br/>
1090
- * &nbsp;&nbsp;&nbsp;&nbsp; + value is one or an array of selected values<br />
1091
- * &nbsp;&nbsp;&nbsp;&nbsp; + justSelected is value has just been selected (either true or false))<br />
1092
- * &nbsp;&nbsp;&nbsp;&nbsp; + data is one or an array of selected values with full information<br />
1093
- * * data: array of selected values (not recommend because it's the same e.value)
1121
+ /**
1122
+ * on change value function<br />
1123
+ * return 2 parameters (e, data)<br />
1124
+ * * e: element (insist {value, justSelected, data})<br/>
1125
+ * &nbsp;&nbsp;&nbsp;&nbsp; + value is one or an array of selected values<br />
1126
+ * &nbsp;&nbsp;&nbsp;&nbsp; + justSelected is value has just been selected (either true or false))<br />
1127
+ * &nbsp;&nbsp;&nbsp;&nbsp; + data is one or an array of selected values with full information<br />
1128
+ * * data: array of selected values (not recommend because it's the same e.value)
1094
1129
  */
1095
1130
  onChange: PropTypes.func,
1096
1131
 
@@ -1103,22 +1138,22 @@ TreeView.propTypes = {
1103
1138
  /** the icon to display for collapse icon */
1104
1139
  collapseIcon: PropTypes.any,
1105
1140
 
1106
- /**
1107
- * get ref of TreeView component, insist:<br/>
1108
- * {<br/>
1109
- * &nbsp;&nbsp;&nbsp;&nbsp;disabled: true/false,<br/>
1110
- * &nbsp;&nbsp;&nbsp;&nbsp;displayExpr: string,<br/>
1111
- * &nbsp;&nbsp;&nbsp;&nbsp;valueExpr: string,<br/>
1112
- * &nbsp;&nbsp;&nbsp;&nbsp;id: string,<br/>
1113
- * &nbsp;&nbsp;&nbsp;&nbsp;parentID: string,<br/>
1114
- * &nbsp;&nbsp;&nbsp;&nbsp;value: string/array<br/>
1115
- * &nbsp;&nbsp;&nbsp;&nbsp;getValue: get selected values (instead of onChange function),<br/>
1116
- * &nbsp;&nbsp;&nbsp;&nbsp;setValue: set array of value (only multiple),<br/>
1117
- * &nbsp;&nbsp;&nbsp;&nbsp;handleCheckbox: checked/unchecked a Checkbox, includes 2 parameters (isChecked, value):<br/>
1118
- * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + isChecked: checked if true (default is false) <br/>
1119
- * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + value: selected values, use 'all' for all values (default is 'all') <br/>
1120
- * &nbsp;&nbsp;&nbsp;&nbsp;get: get DOM of TreeView component<br/>
1121
- * }
1141
+ /**
1142
+ * get ref of TreeView component, insist:<br/>
1143
+ * {<br/>
1144
+ * &nbsp;&nbsp;&nbsp;&nbsp;disabled: true/false,<br/>
1145
+ * &nbsp;&nbsp;&nbsp;&nbsp;displayExpr: string,<br/>
1146
+ * &nbsp;&nbsp;&nbsp;&nbsp;valueExpr: string,<br/>
1147
+ * &nbsp;&nbsp;&nbsp;&nbsp;id: string,<br/>
1148
+ * &nbsp;&nbsp;&nbsp;&nbsp;parentID: string,<br/>
1149
+ * &nbsp;&nbsp;&nbsp;&nbsp;value: string/array<br/>
1150
+ * &nbsp;&nbsp;&nbsp;&nbsp;getValue: get selected values (instead of onChange function),<br/>
1151
+ * &nbsp;&nbsp;&nbsp;&nbsp;setValue: set array of value (only multiple),<br/>
1152
+ * &nbsp;&nbsp;&nbsp;&nbsp;handleCheckbox: checked/unchecked a Checkbox, includes 2 parameters (isChecked, value):<br/>
1153
+ * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + isChecked: checked if true (default is false) <br/>
1154
+ * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + value: selected values, use 'all' for all values (default is 'all') <br/>
1155
+ * &nbsp;&nbsp;&nbsp;&nbsp;get: get DOM of TreeView component<br/>
1156
+ * }
1122
1157
  */
1123
1158
  ref: PropTypes.any
1124
1159
  };
@@ -4,9 +4,9 @@
4
4
  import { memo, useRef, forwardRef, useImperativeHandle, Fragment, useMemo, useState } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
- import { renderHTML } from '../../utils';
7
+ import { classNames, renderHTML } from '../../utils';
8
8
  import { Popover } from '..';
9
- import { breakWord, displayBlock, displayInlineBlock, overflowHidden, positionRelative, textCapitalize, textCenter, textUppercase } from '../../styles/general';
9
+ import { cursorPointer, displayBlock, displayInlineBlock, overflowHidden, positionRelative, textCapitalize, textCenter, textUppercase } from '../../styles/general';
10
10
  import { color as colors } from '../../styles/colors';
11
11
  import theme from '../../theme/settings';
12
12
  const {
@@ -36,7 +36,8 @@ const {
36
36
  paragraph1,
37
37
  paragraph2,
38
38
  paragraph3
39
- }
39
+ },
40
+ spacing
40
41
  } = theme;
41
42
  const typographyMap = new Map([['t1', title1], ['t2', title2], ['t3', title3], ['t4', title4], ['h1', heading1], ['h2', heading2], ['h3', heading3], ['h4', heading4], ['h5', heading5], ['h6', heading6], ['p1', paragraph1], ['p2', paragraph2], ['p3', paragraph3]]);
42
43
  const colorMap = new Map([['default', main], ['secondary', rest]]);
@@ -44,28 +45,32 @@ const colorMap = new Map([['default', main], ['secondary', rest]]);
44
45
  const isTextClamped = elm => (elm === null || elm === void 0 ? void 0 : elm.scrollHeight) > (elm === null || elm === void 0 ? void 0 : elm.clientHeight);
45
46
 
46
47
  const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
47
- type,
48
- color,
49
- center,
50
- uppercase,
48
+ action = {},
51
49
  capitalize,
52
- fullWidth,
53
- mapping,
54
- className,
55
- lineClamp,
50
+ center,
56
51
  children,
52
+ className,
53
+ color,
54
+ fullWidth,
57
55
  hoverTooltip,
56
+ lineClamp,
57
+ mapping,
58
+ onClick,
58
59
  tooltipDirection,
60
+ type,
61
+ uppercase,
59
62
  ...props
60
63
  }, reference) => {
61
64
  const ref = useRef(null);
62
65
  const [openTooltip, setOpenTooltip] = useState(false);
63
66
 
64
- const _TextRootCSS = TextRootCSS(color, type, lineClamp);
67
+ const _TextRootCSS = TextRootCSS(color, type, lineClamp, onClick);
65
68
 
66
69
  useImperativeHandle(reference, () => {
67
70
  const currentRef = ref.current || {};
68
- const _instance = {}; // methods
71
+ currentRef.element = ref.current;
72
+ const _instance = { ...action
73
+ }; // methods
69
74
 
70
75
  _instance.__proto__ = {}; // hidden methods
71
76
 
@@ -73,7 +78,7 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
73
78
  return currentRef;
74
79
  });
75
80
 
76
- const classNames = inTooltip => ['DGN-UI-Typography', center && 'DGN-Typography-center', fullWidth && 'DGN-Typography-fullWidth', `DGN-Typography-${type}`, uppercase && `DGN-Typography-Uppercase`, capitalize && 'DGN-Typography-Capitalize', !inTooltip && lineClamp && 'DGN-Typography-Clamp', className].join(' ').trim().replace(/\s+/g, ' ');
81
+ const classes = inTooltip => classNames('DGN-UI-Typography', center && 'DGN-Typography-center', fullWidth && 'DGN-Typography-fullWidth', `DGN-Typography-${type}`, uppercase && `DGN-Typography-Uppercase`, capitalize && 'DGN-Typography-Capitalize', !inTooltip && lineClamp && 'DGN-Typography-Clamp', className);
77
82
 
78
83
  const setHoverTooltip = (open, isTooltip) => {
79
84
  !isTooltip && setOpenTooltip(false);
@@ -105,28 +110,31 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
105
110
  direction: tooltipDirection
106
111
  }, renderHTML(renderChildren(), mapping, {
107
112
  css: _TextRootCSS,
108
- className: classNames(true),
113
+ className: classes(true),
109
114
  style: {
110
115
  color: textTooltip,
111
- padding: '4px 6px'
116
+ padding: spacing([1, 1.5]),
117
+ height: 'fit-content'
112
118
  }
113
119
  }));
114
- }, [openTooltip, tooltipDirection, children, mapping, color, type, lineClamp]);
120
+ }, [openTooltip, capitalize, center, children, className, color, fullWidth, hoverTooltip, lineClamp, mapping, onClick, tooltipDirection, type, uppercase]);
115
121
  return jsx(Fragment, null, renderHTML(renderChildren(), mapping, {
116
122
  ref: ref,
117
123
  css: _TextRootCSS,
118
- className: classNames(false),
124
+ className: classes(false),
119
125
  onMouseEnter: () => setHoverTooltip(true),
120
126
  onMouseLeave: () => setHoverTooltip(false),
127
+ onClick: onClick,
121
128
  ...props
122
129
  }), hoverTooltip && renderTooltip);
123
130
  }));
124
131
 
125
- const TextRootCSS = (color, type, lineClamp) => css`
132
+ const TextRootCSS = (color, type, lineClamp, onClick) => css`
126
133
  ${displayInlineBlock};
127
134
  ${positionRelative};
128
- ${breakWord};
129
135
  ${paragraph1};
136
+ ${onClick && cursorPointer};
137
+ word-break: break-all;
130
138
  white-space: break-spaces;
131
139
  color: ${colorMap.get(color) || colors[color] || color};
132
140
  max-width: max-content;
@@ -155,25 +163,25 @@ const TextRootCSS = (color, type, lineClamp) => css`
155
163
  `;
156
164
 
157
165
  Typography.defaultProps = {
158
- type: 'p1',
159
- color: 'default',
160
166
  center: false,
161
- fullWidth: true,
162
- mapping: 'span',
163
167
  className: '',
168
+ color: 'default',
169
+ fullWidth: true,
164
170
  hoverTooltip: false,
165
- tooltipDirection: 'bottom'
171
+ mapping: 'span',
172
+ tooltipDirection: 'bottom',
173
+ type: 'p1'
166
174
  };
167
- /** type of text<br/>
168
- * h1: Title <br/>
169
- * h2: Header Popup <br/>
170
- * h3: Header popup <br/>
171
- * h4: Button, Tab, Title group <br/>
172
- * h5: Label column, Title group <br/>
173
- * h6: Label form <br/>
174
- * p1: Body text <br/>
175
- * p2: Body text <br/>
176
- * p3: Notice, Tooltip <br/>
175
+ /** type of text<br/>
176
+ * h1: Title <br/>
177
+ * h2: Header Popup <br/>
178
+ * h3: Header popup <br/>
179
+ * h4: Button, Tab, Title group <br/>
180
+ * h5: Label column, Title group <br/>
181
+ * h6: Label form <br/>
182
+ * p1: Body text <br/>
183
+ * p2: Body text <br/>
184
+ * p3: Notice, Tooltip <br/>
177
185
  */
178
186
 
179
187
  export const arrTypeTypography = ['t1', 't2', 't3', 't4', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p1', 'p2', 'p3', 'title1', 'title2', 'title3', 'title4', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6', 'paragraph1', 'paragraph2', 'paragraph3'];
@@ -193,7 +201,7 @@ Typography.propTypes = {
193
201
  /** Color of text ['primary', 'secondary', 'success', 'warning', 'danger', 'info', '#hex', rgb(#,#,#)]. */
194
202
  color: PropTypes.string,
195
203
 
196
- /** If true, the component will take up the full width of its container. */
204
+ /** If `true`, the component will take up the full width of its container. */
197
205
  fullWidth: PropTypes.bool,
198
206
 
199
207
  /** If `true`, hover will show tooltip when text clamped. */
@@ -205,6 +213,9 @@ Typography.propTypes = {
205
213
  /** The component used for the root node. Either a string to use a HTML element or a component. */
206
214
  mapping: PropTypes.string,
207
215
 
216
+ /** Callback fired when the component is clicked. */
217
+ onClick: PropTypes.func,
218
+
208
219
  /** Accepts all props which `mapping` tag support. */
209
220
  props: PropTypes.object,
210
221