diginet-core-ui 1.3.46 → 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.
@@ -1801,14 +1801,14 @@ Dropdown.propTypes = {
1801
1801
  /** display this icon if not found the icon follow iconExpr */
1802
1802
  iconDefault: PropTypes.string,
1803
1803
 
1804
- /** field name used for icon display<br/>
1805
- * Example:<br/>
1806
- * &nbsp;&nbsp;string: 'icon'<br/>
1807
- * &nbsp;&nbsp;object: {<br/>
1808
- * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key: 'icon',<br/>
1809
- * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prefix: 'https://imglink.com',<br/>
1810
- * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;suffix: '.jpg'<br/>
1811
- * &nbsp;&nbsp;}
1804
+ /** field name used for icon display<br/>
1805
+ * Example:<br/>
1806
+ * &nbsp;&nbsp;string: 'icon'<br/>
1807
+ * &nbsp;&nbsp;object: {<br/>
1808
+ * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key: 'icon',<br/>
1809
+ * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prefix: 'https://imglink.com',<br/>
1810
+ * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;suffix: '.jpg'<br/>
1811
+ * &nbsp;&nbsp;}
1812
1812
  */
1813
1813
  iconExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
1814
1814
  key: PropTypes.string,
@@ -1826,9 +1826,9 @@ Dropdown.propTypes = {
1826
1826
  /** field name used for text display in input */
1827
1827
  keyExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
1828
1828
 
1829
- /** field name used for text display<br/>
1830
- * Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
1831
- * Note: don't use 'id - name', return undefined
1829
+ /** field name used for text display<br/>
1830
+ * Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
1831
+ * Note: don't use 'id - name', return undefined
1832
1832
  */
1833
1833
  displayExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
1834
1834
 
@@ -1838,9 +1838,9 @@ Dropdown.propTypes = {
1838
1838
  /** the field name used for the returned result */
1839
1839
  valueExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
1840
1840
 
1841
- /**
1842
- * duration wait enter search content on search<br/>
1843
- * Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
1841
+ /**
1842
+ * duration wait enter search content on search<br/>
1843
+ * Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
1844
1844
  */
1845
1845
  searchDelayTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
1846
1846
 
@@ -1907,19 +1907,19 @@ Dropdown.propTypes = {
1907
1907
  /** The array of elements that appear in the dropdown */
1908
1908
  dataSource: PropTypes.array,
1909
1909
 
1910
- /** function displays items by custom<br/>
1911
- * renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
1912
- * --> such as: displayExpr={'name - role'}
1910
+ /** function displays items by custom<br/>
1911
+ * renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
1912
+ * --> such as: displayExpr={'name - role'}
1913
1913
  */
1914
1914
  renderItem: PropTypes.func,
1915
1915
 
1916
- /** function displays selected items by custom, example:<br/>
1917
- * renderItem={(data, index) => index + ' - ' + data.name}<br/>
1916
+ /** function displays selected items by custom, example:<br/>
1917
+ * renderItem={(data, index) => index + ' - ' + data.name}<br/>
1918
1918
  */
1919
1919
  renderSelectedItem: PropTypes.func,
1920
1920
 
1921
- /** the function will run when entering input<br/>
1922
- * if undefined: the filter function will run (default)
1921
+ /** the function will run when entering input<br/>
1922
+ * if undefined: the filter function will run (default)
1923
1923
  */
1924
1924
  onInput: PropTypes.func,
1925
1925
 
@@ -1938,19 +1938,19 @@ Dropdown.propTypes = {
1938
1938
  /** the contents in Dropdown box (Exp: TreeView) */
1939
1939
  children: PropTypes.node,
1940
1940
 
1941
- /**
1942
- * ref methods
1943
- *
1944
- * how to get component element? ref.current
1945
- *
1946
- * how to call method? ref.current.instance.{method}
1947
- *
1948
- * * showDropdown(): Show dropdown
1949
- * * closeDropdown(): Close dropdown
1950
- * * onClear(): Clear selected value
1951
- * * setPreviousValue(): Set value to previous value
1952
- * * setValue(value): Set value of dropdown
1953
- * * @param {value} - string || number || array
1941
+ /**
1942
+ * ref methods
1943
+ *
1944
+ * how to get component element? ref.current
1945
+ *
1946
+ * how to call method? ref.current.instance.{method}
1947
+ *
1948
+ * * showDropdown(): Show dropdown
1949
+ * * closeDropdown(): Close dropdown
1950
+ * * onClear(): Clear selected value
1951
+ * * setPreviousValue(): Set value to previous value
1952
+ * * setValue(value): Set value of dropdown
1953
+ * * @param {value} - string || number || array
1954
1954
  */
1955
1955
  reference: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
1956
1956
  current: PropTypes.instanceOf(Element)
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.46",
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,9 @@ 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
+
41
44
  ## 1.3.46
42
45
  - \[Added\]: MenuIcon – MHRM09N1025
43
46
  - \[Changed\]: Dropdown – Ref set value not in dataSource