diginet-core-ui 1.3.45 → 1.3.47

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,35 +1,36 @@
1
1
  /** @jsxRuntime classic */
2
2
 
3
3
  /** @jsx jsx */
4
- import { memo, useMemo, useRef, useState, useEffect, forwardRef, Fragment } from 'react';
4
+ import { memo, useMemo, useRef, useState, useEffect, forwardRef, Fragment, useImperativeHandle } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
7
  import { StarHalf, StarOutline } from '../../icons';
8
8
  import { randomString } from '../../utils';
9
9
  import { hexToRGBA } from '../../styles/color-helper';
10
10
  import { color as colors } from '../../styles/colors';
11
- import { typography } from '../../styles/typography';
11
+ import theme from '../../theme/settings';
12
12
  import { alignCenter, border, cursorPointer, flexRow, flexRowReverse, inlineFlex, outlineNone, overflowHidden, pointerEventsNone, positionAbsolute, positionRelative } from '../../styles/general';
13
13
  const {
14
- paragraph3
15
- } = typography;
16
- const {
17
- system: {
18
- active,
19
- rest
14
+ colors: {
15
+ system: {
16
+ active,
17
+ rest,
18
+ white
19
+ },
20
+ semantic: {
21
+ info
22
+ },
23
+ line: {
24
+ normal
25
+ }
20
26
  },
21
- semantic: {
22
- success,
23
- warning,
24
- danger,
25
- info
27
+ typography: {
28
+ paragraph3
26
29
  },
27
- line: {
28
- normal
29
- }
30
- } = colors;
31
- const colorMap = new Map([['primary', active], ['success', success], ['warning', warning], ['danger', danger], ['info', info]]);
30
+ spacing
31
+ } = theme;
32
32
  const Rating = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
33
+ id,
33
34
  disabled,
34
35
  readOnly,
35
36
  half,
@@ -42,133 +43,61 @@ const Rating = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
42
43
  color,
43
44
  className,
44
45
  style,
45
- starStyle,
46
- onRating,
47
- ...props
48
- }, ref) => {
49
- if (!ref) {
50
- ref = useRef(null);
51
- }
52
-
53
- const selectRef = useRef(null);
46
+ onRating
47
+ }, reference) => {
48
+ if (height === undefined) height = width;
49
+ const ref = useRef(null);
54
50
  const [unique] = useState(randomString(6, {
55
51
  allowSymbol: false,
56
52
  allowNumber: false
57
53
  }));
58
54
  const [valueState, setValueState] = useState(value || defaultValue);
59
55
 
60
- const _color = colorMap.get(color) || color;
56
+ const _color = colors[color] || color;
61
57
 
62
- const RatingRoot = css`
63
- ${inlineFlex}
64
- ${flexRowReverse}
65
- ${positionRelative}
66
- &.disabled, &.read-only {
67
- ${pointerEventsNone}
68
- }
69
- `;
70
- const RatingSelect = css`
71
- ${positionRelative}
72
- ${outlineNone}
73
- ${paragraph3}
74
- ${border(1, normal)}
75
- margin-left: 4px;
76
- color: ${active};
77
- &:hover {
78
- border-color: ${active};
79
- background-color: ${hexToRGBA(active, 0.2)};
80
- }
81
- &:active,
82
- &:focus {
83
- border-color: ${info};
84
- }
85
- option {
86
- background-color: white;
87
- }
88
- `;
89
- const RatingItemHaft = css`
90
- ${flexRow}
91
- ${positionAbsolute}
92
- ${alignCenter}
93
- ${overflowHidden}
94
- width: 50%;
95
- svg {
96
- ${cursorPointer}
97
- color: transparent;
98
- transition: color 0.15s linear;
99
- transform: scale(2);
100
- transform-origin: left;
101
- }
102
- &.right {
103
- transform: rotateY(180deg);
104
- right: 0;
105
- }
106
- &.half {
107
- svg:hover,
108
- &.right:hover + span svg,
109
- &.chosen svg {
110
- color: ${_color};
111
- }
112
- &.chosen {
113
- &.disabled svg {
114
- color: ${rest} !important;
115
- }
116
- }
117
- }
118
- `;
119
- const RatingItem = css`
120
- ${inlineFlex}
121
- ${positionRelative}
122
- ${alignCenter}
123
- svg {
124
- transition: color 0.15s linear;
125
- }
126
- &:hover ~ span > span.css-${RatingItemHaft.name}, ${half ? '' : `&:hover,`} &:hover ~ span.full,
127
- &.chosen ~ span > span.css-${RatingItemHaft.name}, ${half ? '' : `&.chosen,`} &.chosen ~ span.full {
128
- svg {
129
- color: ${_color};
130
- }
131
- }
132
- &.disabled {
133
- &.chosen {
134
- svg {
135
- color: ${rest} !important;
136
- }
137
- }
138
- }
139
- `;
58
+ const _RatingItemHaftCSS = RatingItemHaftCSS(_color);
59
+
60
+ const _RatingItemCSS = RatingItemCSS(_RatingItemHaftCSS.name, _color, half);
140
61
 
141
62
  const onSelectValue = e => {
142
63
  if (disabled || readOnly) return;
143
64
  const newValue = +e.target.value;
144
65
  e.value = newValue;
145
66
  setValueState(newValue);
146
- !!onRating && onRating(e);
67
+ !!onRating && onRating(e, newValue);
147
68
  };
148
69
 
149
70
  const _onRating = (e, value, isHalf = false) => {
150
71
  if (disabled || readOnly || half && !isHalf) return;
151
72
  setValueState(value);
152
- !!onRating && onRating(e);
73
+ !!onRating && onRating(e, value);
153
74
  };
154
75
 
155
76
  useEffect(() => {
156
77
  setValueState(value);
157
78
  }, [value]);
79
+ useImperativeHandle(reference, () => {
80
+ const currentRef = ref.current || {};
81
+ const _instance = {}; // methods
82
+
83
+ _instance.__proto__ = {}; // hidden methods
84
+
85
+ currentRef.instance = _instance;
86
+ return currentRef;
87
+ });
158
88
  return useMemo(() => {
159
89
  let ArrayRating = [];
160
90
  [...Array(quantity).keys()].reverse().forEach(item => ArrayRating = [...ArrayRating, item + 1]);
161
91
  return jsx("div", {
162
- css: RatingRoot,
92
+ id: id,
93
+ css: RatingRootCSS,
163
94
  ref: ref,
164
95
  style: style,
165
- className: ['DGN-UI-Rating', className, disabled && 'disabled', readOnly ? 'read-only' : ''].join(' ').trim(),
166
- ...props
96
+ className: ['DGN-UI-Rating', className, disabled ? 'disabled' : '', readOnly ? 'read-only' : ''].join(' ').trim().replace(/\s+/g, ' ')
167
97
  }, selector && jsx("select", {
168
- css: RatingSelect,
169
- ref: selectRef,
170
- name: `Rating-Select-${unique}`,
171
- id: `Rating-Select-${unique}`,
98
+ css: RatingSelectCSS,
99
+ name: `DGN-UI-Rating-Select-${unique}`,
100
+ id: `DGN-UI-Rating-Select-${unique}`,
172
101
  disabled: disabled,
173
102
  value: valueState,
174
103
  onChange: onSelectValue
@@ -185,8 +114,7 @@ const Rating = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
185
114
  key: i,
186
115
  value: idx + 1
187
116
  }, idx + 1))), ArrayRating.map(i => jsx("span", {
188
- css: RatingItem,
189
- style: starStyle,
117
+ css: _RatingItemCSS,
190
118
  key: i,
191
119
  className: ['DGN-UI-Rating-Item', disabled && 'disabled', i <= valueState && 'chosen'].join(' ').trim().replace(/\s+/g, ' '),
192
120
  onClick: e => _onRating(e, i)
@@ -195,17 +123,17 @@ const Rating = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
195
123
  height: height,
196
124
  color: disabled ? rest : color || 'currentColor'
197
125
  }), jsx("span", {
198
- css: RatingItemHaft,
199
- className: ['DGN-UI-Rating-Item-Star right', disabled && 'disabled', half && 'half', i <= valueState && 'chosen'].join(' ').trim().replace(/\s+/g, ' '),
200
- onClick: e => _onRating(e, i, true)
126
+ css: _RatingItemHaftCSS,
127
+ className: ['DGN-UI-Rating-Item-Star right', disabled && 'disabled', half && 'half', i <= valueState ? 'chosen' : ''].join(' ').trim().replace(/\s+/g, ' '),
128
+ onClick: e => half && _onRating(e, i, true)
201
129
  }, jsx(StarHalf, {
202
130
  width: width,
203
131
  height: height,
204
132
  color: 'currentColor'
205
133
  })), jsx("span", {
206
- css: RatingItemHaft,
207
- className: ['DGN-UI-Rating-Item-Star left', disabled && 'disabled', half && 'half', i - 0.5 <= valueState && 'chosen'].join(' ').trim().replace(/\s+/g, ' '),
208
- onClick: e => _onRating(e, i - 0.5, true)
134
+ css: _RatingItemHaftCSS,
135
+ className: ['DGN-UI-Rating-Item-Star left', disabled && 'disabled', half && 'half', i - 0.5 <= valueState ? 'chosen' : ''].join(' ').trim().replace(/\s+/g, ' '),
136
+ onClick: e => half && _onRating(e, i - 0.5, true)
209
137
  }, jsx(StarHalf, {
210
138
  width: width,
211
139
  height: height,
@@ -213,6 +141,85 @@ const Rating = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
213
141
  })))));
214
142
  }, [half, color, quantity, readOnly, disabled, selector, width, height, onRating, valueState]);
215
143
  }));
144
+ const RatingRootCSS = css`
145
+ ${inlineFlex};
146
+ ${flexRowReverse};
147
+ &.disabled,
148
+ &.read-only {
149
+ ${pointerEventsNone};
150
+ }
151
+ `;
152
+ const RatingSelectCSS = css`
153
+ ${outlineNone};
154
+ ${paragraph3};
155
+ ${border(1, normal)}
156
+ margin-left: ${spacing()}px;
157
+ color: ${active};
158
+ &:hover {
159
+ border-color: ${active};
160
+ background-color: ${hexToRGBA(active, 0.2)};
161
+ }
162
+ &:active,
163
+ &:focus {
164
+ border-color: ${info};
165
+ }
166
+ option {
167
+ background-color: ${white};
168
+ }
169
+ `;
170
+
171
+ const RatingItemHaftCSS = color => css`
172
+ ${flexRow};
173
+ ${positionAbsolute};
174
+ ${overflowHidden};
175
+ width: 50%;
176
+ svg {
177
+ ${cursorPointer}
178
+ color: transparent;
179
+ transition: color 0.15s linear;
180
+ transform: scale(2);
181
+ transform-origin: left;
182
+ }
183
+ &.right {
184
+ transform: rotateY(180deg);
185
+ right: 0;
186
+ }
187
+ &.half {
188
+ svg:hover,
189
+ &.right:hover + span svg,
190
+ &.chosen svg {
191
+ color: ${color};
192
+ }
193
+ &.chosen {
194
+ &.disabled svg {
195
+ color: ${rest} !important;
196
+ }
197
+ }
198
+ }
199
+ `;
200
+
201
+ const RatingItemCSS = (RatingItemHaftCSSName, color, half) => css`
202
+ ${inlineFlex};
203
+ ${positionRelative};
204
+ ${alignCenter};
205
+ svg {
206
+ transition: color 0.15s linear;
207
+ }
208
+ &:hover ~ span > span.css-${RatingItemHaftCSSName}, ${half ? '' : `&:hover,`} &:hover ~ span.full,
209
+ &.chosen ~ span > span.css-${RatingItemHaftCSSName}, ${half ? '' : `&.chosen,`} &.chosen ~ span.full {
210
+ svg {
211
+ color: ${color};
212
+ }
213
+ }
214
+ &.disabled {
215
+ &.chosen {
216
+ svg {
217
+ color: ${rest} !important;
218
+ }
219
+ }
220
+ }
221
+ `;
222
+
216
223
  Rating.defaultProps = {
217
224
  disabled: false,
218
225
  readOnly: false,
@@ -225,49 +232,51 @@ Rating.defaultProps = {
225
232
  className: ''
226
233
  };
227
234
  Rating.propTypes = {
228
- /** prevent all events and effect */
235
+ /** If true, the component is disabled. */
229
236
  disabled: PropTypes.bool,
230
237
 
231
- /** prevent all events and effect and keep style */
238
+ /** Removes all hover effects and pointer events. */
232
239
  readOnly: PropTypes.bool,
233
240
 
234
- /** allows rating with an odd number of stars */
241
+ /** Allows rating with an odd number of stars. */
235
242
  half: PropTypes.bool,
236
243
 
237
- /** display select box to select by number */
244
+ /** Display select box to select by number. */
238
245
  selector: PropTypes.bool,
239
246
 
240
- /** The default number of stars is selected */
247
+ /** The default number of stars is selected. */
241
248
  defaultValue: PropTypes.number,
242
249
 
243
- /** The number of stars is selected */
250
+ /** The number of stars is selected. */
244
251
  value: PropTypes.number,
245
252
 
246
- /** the maximum number of stars allowed to rate */
253
+ /** The maximum number of stars allowed to rate. */
247
254
  quantity: PropTypes.number,
248
255
 
249
- /** width of star icon */
256
+ /** Width of star icon. */
250
257
  width: PropTypes.number,
251
258
 
252
- /** height of star icon */
259
+ /** Height of star icon. */
253
260
  height: PropTypes.number,
254
261
 
255
- /** color of stars, ['primary', 'info', 'success', 'warning', 'danger', #hex, rgb(#, #, #)] */
262
+ /** Color of stars, ['primary', 'info', 'success', 'warning', 'danger', #hex, rgb(#, #, #)]. */
256
263
  color: PropTypes.string,
257
264
 
258
- /** class name of Rating component */
265
+ /** Class for component. */
259
266
  className: PropTypes.string,
260
267
 
261
- /** style inline of Rating component */
268
+ /** Style inline of component. */
262
269
  style: PropTypes.object,
263
270
 
264
- /** style inline of stars icon */
265
- starStyle: PropTypes.object,
266
-
267
271
  /**
268
- * the function for rating handler, return e:{value, ...element}<br />
269
- * value: the quantity of star was selected (insist half)
270
- */
272
+ * Callback fired when the value changes.
273
+ *
274
+ function(event: React.SyntheticEvent, value: number) => void
275
+ *
276
+ * event: The event source of the callback.
277
+ *
278
+ * value: The new value.
279
+ */
271
280
  onRating: PropTypes.func
272
281
  };
273
282
  export default Rating;
@@ -26,79 +26,18 @@ const {
26
26
  } = typography;
27
27
  const {
28
28
  system: {
29
- active,
30
29
  rest
31
30
  },
32
- semantic: {
33
- success,
34
- warning,
35
- danger,
36
- info
37
- },
38
31
  text: {
39
- main
32
+ main,
33
+ tooltip: textTooltip
40
34
  },
41
35
  fill: {
42
36
  tooltip: fillTooltip
43
- },
44
- text: {
45
- tooltip: textTooltip
46
37
  }
47
38
  } = colors;
48
39
  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]]);
49
- const colorMap = new Map([['default', main], ['primary', active], ['secondary', rest], ['success', success], ['warning', warning], ['danger', danger], ['info', info]]);
50
-
51
- const getDirectionPopover = direction => {
52
- switch (direction) {
53
- case 'top':
54
- return {
55
- anchorOrigin: {
56
- vertical: 'top',
57
- horizontal: 'center'
58
- },
59
- transformOrigin: {
60
- vertical: 'bottom',
61
- horizontal: 'center'
62
- }
63
- };
64
-
65
- case 'left':
66
- return {
67
- anchorOrigin: {
68
- vertical: 'center',
69
- horizontal: 'left'
70
- },
71
- transformOrigin: {
72
- vertical: 'center',
73
- horizontal: 'right'
74
- }
75
- };
76
-
77
- case 'right':
78
- return {
79
- anchorOrigin: {
80
- vertical: 'center',
81
- horizontal: 'right'
82
- },
83
- transformOrigin: {
84
- vertical: 'center',
85
- horizontal: 'left'
86
- }
87
- };
88
-
89
- default:
90
- return {
91
- anchorOrigin: {
92
- vertical: 'bottom',
93
- horizontal: 'center'
94
- },
95
- transformOrigin: {
96
- vertical: 'top',
97
- horizontal: 'center'
98
- }
99
- };
100
- }
101
- };
40
+ const colorMap = new Map([['default', main], ['secondary', rest]]);
102
41
 
103
42
  const isTextClamped = elm => (elm === null || elm === void 0 ? void 0 : elm.scrollHeight) > (elm === null || elm === void 0 ? void 0 : elm.clientHeight);
104
43
 
@@ -119,6 +58,9 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
119
58
  }, reference) => {
120
59
  const ref = useRef(null);
121
60
  const [openTooltip, setOpenTooltip] = useState(false);
61
+
62
+ const _TextRootCSS = TextRootCSS(color, type, lineClamp);
63
+
122
64
  useImperativeHandle(reference, () => {
123
65
  const currentRef = ref.current || {};
124
66
  const _instance = {}; // methods
@@ -131,7 +73,9 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
131
73
 
132
74
  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, ' ');
133
75
 
134
- const setHoverTooltip = open => {
76
+ const setHoverTooltip = (open, isTooltip) => {
77
+ !isTooltip && setOpenTooltip(false);
78
+
135
79
  if (hoverTooltip && isTextClamped(ref.current)) {
136
80
  setOpenTooltip(open);
137
81
  }
@@ -151,11 +95,11 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
151
95
  style: {
152
96
  color: textTooltip
153
97
  },
154
- onMouseEnter: () => setHoverTooltip(true),
155
- onMouseLeave: () => setHoverTooltip(false),
156
- ...getDirectionPopover(tooltipDirection)
98
+ onMouseEnter: () => setHoverTooltip(true, true),
99
+ onMouseLeave: () => setHoverTooltip(false, true),
100
+ direction: tooltipDirection
157
101
  }, renderHTML(renderChildren(), mapping, {
158
- css: TextRoot(color, type, lineClamp),
102
+ css: _TextRootCSS,
159
103
  className: classNames(true),
160
104
  style: {
161
105
  color: textTooltip,
@@ -164,7 +108,7 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
164
108
  })), [openTooltip, tooltipDirection, children, mapping, color, type, lineClamp]);
165
109
  return jsx(Fragment, null, renderHTML(renderChildren(), mapping, {
166
110
  ref: ref,
167
- css: TextRoot(color, type, lineClamp),
111
+ css: _TextRootCSS,
168
112
  className: classNames(false),
169
113
  onMouseEnter: () => setHoverTooltip(true),
170
114
  onMouseLeave: () => setHoverTooltip(false),
@@ -172,7 +116,7 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
172
116
  }), hoverTooltip && renderTooltip);
173
117
  }));
174
118
 
175
- const TextRoot = (color, type, lineClamp) => css`
119
+ const TextRootCSS = (color, type, lineClamp) => css`
176
120
  ${displayInlineBlock};
177
121
  ${positionRelative};
178
122
  ${breakWord};
@@ -213,7 +157,7 @@ Typography.defaultProps = {
213
157
  mapping: 'span',
214
158
  className: '',
215
159
  hoverTooltip: false,
216
- tooltipDirection: 'down'
160
+ tooltipDirection: 'bottom'
217
161
  };
218
162
  /** type of text<br/>
219
163
  * h1: Title <br/>
@@ -246,7 +190,7 @@ Typography.propTypes = {
246
190
  /** text-transform is uppercase if true */
247
191
  uppercase: PropTypes.bool,
248
192
 
249
- /** text-transform is capitalize if true (and uppercase is false) */
193
+ /** text-transform is capitalized if true (and uppercase is false) */
250
194
  capitalize: PropTypes.bool,
251
195
 
252
196
  /** The line-clamp property truncates text at a specific number of lines. */
@@ -256,7 +200,7 @@ Typography.propTypes = {
256
200
  hoverTooltip: PropTypes.bool,
257
201
 
258
202
  /** Tooltip direction */
259
- tooltipDirection: PropTypes.oneOf(['top', 'down', 'left', 'right']),
203
+ tooltipDirection: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
260
204
 
261
205
  /** allows maximum screen width if true */
262
206
  fullWidth: PropTypes.bool,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.45",
3
+ "version": "1.3.47",
4
4
  "description": "The DigiNet core ui",
5
5
  "homepage": "https://diginet.com.vn",
6
6
  "main": "index.js",
package/readme.md CHANGED
@@ -38,6 +38,19 @@ npm test
38
38
  ```
39
39
 
40
40
  ## Changelog
41
+ ## 1.3.47
42
+ - \[Fixed\]: Rating – Fix bug icon render incorrect, return value in func onRating
43
+
44
+ ## 1.3.46
45
+ - \[Added\]: MenuIcon – MHRM09N1025
46
+ - \[Changed\]: Dropdown – Ref set value not in dataSource
47
+ - \[Changed\]: Dropdown – Add logic if multiple then selectBox is true
48
+ - \[Fixed\]: Typography – Fix bug tooltip show wrong when hover
49
+ - \[Fixed\]: Avatar – Fix bug flickering
50
+ - \[Fixed\]: Radio – Fix cursor pointer:none when readonly - Fix event onchange - Fix warning
51
+ - \[Fixed\]: Dropdown – Bug not reload dataSource when onClear
52
+ - \[Fixed\]: Dropdown – Fix bug scroll to top after load more
53
+
41
54
  ## 1.3.45
42
55
  - \[Added\]: MenuIcon – MHRM00N0005, MHRM09N1015, MHRM09N1400, MHRP25L0101, MHRP25L0501, MHRM09N1020
43
56
  - \[Changed\]: LineChart – Allow pointsColor, pathColor use CORE colors; Add prop className, style, pointHoverAlignment