diginet-core-ui 1.3.53 → 1.3.54

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.
@@ -82,7 +82,7 @@ const Accordion = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
82
82
  display: 'none'
83
83
  }
84
84
  })));
85
- }, [id, disabled, className, boxShadow, onClick, children, expanded, onExpand, onCollapse, expandState]);
85
+ }, [id, disabled, className, style, boxShadow, onClick, children, expanded, onExpand, onCollapse, expandState]);
86
86
  }));
87
87
  const AccordionRootCSS = css`
88
88
  ${displayBlock};
@@ -35,26 +35,25 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
35
35
  const _SummaryRootCSS = SummaryRootCSS(background);
36
36
 
37
37
  const _onClick = e => {
38
- if (!disabled) {
39
- const target = e.target;
38
+ if (disabled) return;
39
+ const target = e.target;
40
40
 
41
- if (onClickAccordion) {
42
- onClickAccordion();
43
- return;
44
- }
41
+ if (onClickAccordion) {
42
+ onClickAccordion();
43
+ return;
44
+ }
45
45
 
46
- if (onClick && (!expandIconRef.current || !expandIconRef.current.contains(target))) {
47
- onClick(e);
48
- return;
49
- }
46
+ if (onClick && (!expandIconRef.current || !expandIconRef.current.contains(target))) {
47
+ onClick(e);
48
+ return;
49
+ }
50
50
 
51
- if (expandState) {
52
- if (expanded === undefined) setExpandState(false);
53
- !!onCollapse && onCollapse(e);
54
- } else if (!expandState) {
55
- if (expanded === undefined) setExpandState(true);
56
- !!onExpand && onExpand(e);
57
- }
51
+ if (expandState) {
52
+ if (expanded === undefined) setExpandState(false);
53
+ !!onCollapse && onCollapse(e);
54
+ } else if (!expandState) {
55
+ if (expanded === undefined) setExpandState(true);
56
+ !!onExpand && onExpand(e);
58
57
  }
59
58
  };
60
59
 
@@ -137,7 +136,7 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
137
136
  }) : jsx("span", {
138
137
  className: 'Accordion-Collapse-Icon effect'
139
138
  }, collapseIcon)))));
140
- }, [id, expandIcon, expandIconAt, className, background, children, collapseIcon, expandIconProps, expandState]);
139
+ }, [id, expandIcon, expandIconAt, className, background, children, collapseIcon, expandIconProps, style, expandState, disabled]);
141
140
  }));
142
141
  AccordionSummary.defaultProps = {
143
142
  expandIconAt: 'start',
@@ -5,7 +5,7 @@ import { css, jsx } from '@emotion/core';
5
5
  import PropTypes from 'prop-types';
6
6
  import { forwardRef, memo, useEffect, useRef, useState, useImperativeHandle } from 'react';
7
7
  import { Typography } from '../..';
8
- import { alignCenter, alignStart, borderBox, cursorPointer, displayBlock, flexRow, positionAbsolute, positionRelative, cursorNoDrop } from '../../../styles/general';
8
+ import { alignCenter, alignStart, borderBox, cursorPointer, displayBlock, flexRow, positionAbsolute, positionRelative, cursorNoDrop, parseWidthHeight } from '../../../styles/general';
9
9
  import { randomString } from '../../../utils';
10
10
  import { color as colors } from '../../../styles/colors';
11
11
  import theme from '../../../theme/settings';
@@ -24,6 +24,7 @@ const {
24
24
  },
25
25
  spacing
26
26
  } = theme;
27
+ const padding = spacing(0.75);
27
28
  const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
28
29
  id,
29
30
  className,
@@ -52,7 +53,6 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
52
53
  const ref = useRef(null);
53
54
  if (typeof width === 'number') width += 'px';
54
55
  const [checkedState, setCheckedState] = useState(checked || defaultChecked);
55
- const padding = spacing(0.5);
56
56
 
57
57
  if (!id) {
58
58
  [id] = useState('DGN-UI-' + randomString(10, {
@@ -62,123 +62,13 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
62
62
  }
63
63
 
64
64
  const clMain = colors[color] || color;
65
- const CheckBoxSquare = css`
66
- ${flexRow};
67
- ${positionRelative};
68
- ${cursorPointer};
69
- ${borderBox};
70
- width: ${width};
71
- min-width: ${width};
72
- height: ${width};
73
- min-height: ${width};
74
- background-color: ${white};
75
- border: 2px solid ${rest};
76
- border-radius: 2px;
77
- margin-right: ${spacing(2)}px;
78
- &.determinate {
79
- &::after {
80
- ${displayBlock}
81
- ${positionAbsolute}
82
- content : '';
83
- height: 7px;
84
- left: 50%;
85
- top: 43%;
86
- transform: translate(-50%, -50%) scale(0) rotate(45deg);
87
- transition: transform 0.3s;
88
- width: 12.6px;
89
- }
90
- }
91
- &.indeterminate {
92
- &::after {
93
- ${flexRow}
94
- ${positionAbsolute}
95
- content: "";
96
- background-color: white;
97
- left: 2px;
98
- top: 6px;
99
- width: 10px;
100
- height: 2px;
101
- transition: transform 0.3s;
102
- transform: scale(0);
103
- }
104
- }
105
- &:not(.disabled):not(.read-only) {
106
- &:hover {
107
- box-shadow: 0 0 0 3px ${clFillHover};
108
- background-color: ${clFillHover};
109
- border-color: ${clMain};
110
- }
111
- &:focus,
112
- &:active {
113
- box-shadow: 0 0 0 3px ${clFillPressed};
114
- background-color: ${clFillPressed};
115
- }
116
- }
117
- &:not(disabled):focus {
118
- box-shadow: 0 0 0 3px ${clFillPressed};
119
- background-color: ${clFillPressed};
120
- }
121
- &.disabled,
122
- &.read-only {
123
- ${cursorNoDrop};
124
- }
125
- `;
126
- const CheckBoxInput = css`
127
- &:checked + label > span.css-${CheckBoxSquare.name} {
128
- &.determinate {
129
- &::after {
130
- transform: translate(-50%, -66%) scale(1) rotate(-45deg);
131
- background: linear-gradient(${white}, ${white}) left bottom/2px 100%,
132
- linear-gradient(${white}, ${white}) left bottom/100% 2px;
133
- background-repeat: no-repeat;
134
- }
135
- }
136
- &.indeterminate {
137
- &::after {
138
- transform: scale(1);
139
- }
140
- }
141
- }
142
- &:checked:not(:disabled) + label > span.css-${CheckBoxSquare.name} {
143
- background-color: ${clMain} !important;
144
- border-color: ${clMain} !important;
145
- }
146
- &:checked:disabled {
147
- & + label > span.css-${CheckBoxSquare.name} {
148
- &:not(.indeterminate) {
149
- background-color: ${clDisabled} !important;
150
- }
151
- &.indeterminate {
152
- background-color: ${clFormal2} !important;
153
- border-color: ${clFormal2} !important;
154
- }
155
- }
156
- }
157
- &:disabled {
158
- & + label > span.css-${CheckBoxSquare.name} {
159
- border-color: ${clDisabled};
160
- }
161
- }
162
- `;
163
- const CheckBoxLabel = css`
164
- ${flexRow};
165
- ${positionRelative};
166
- ${alignCenter};
167
- ${borderBox};
168
- margin-bottom: 0 !important;
169
- `;
170
- const CheckBoxRoot = css`
171
- ${flexRow};
172
- ${alignStart};
173
- ${borderBox};
174
- `;
175
- const CheckboxContainer = css`
176
- ${displayBlock};
177
- ${positionRelative};
178
- padding: ${padding}px;
179
- `;
180
-
181
- const handleChange = () => {
65
+
66
+ const _CheckBoxSquareCSS = CheckBoxSquareCSS(width, clMain);
67
+
68
+ const _CheckBoxInputCSS = CheckBoxInputCSS(_CheckBoxSquareCSS.name, clMain);
69
+
70
+ const handleChange = event => {
71
+ event.stopPropagation();
182
72
  if (readOnly || inputProps.readOnly || disabled || inputProps.disabled) return;
183
73
  const oldLogicChecked = inputRef.current.checked; //Use for TreeView
184
74
 
@@ -225,14 +115,14 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
225
115
  });
226
116
  return jsx("div", {
227
117
  id: 'DGN-UI-Checkbox-' + id.replace('DGN-UI-', ''),
228
- css: CheckboxContainer,
118
+ css: CheckboxContainerCSS,
229
119
  className: ['DGN-UI-Checkbox', className].join(' ').trim().replace(/\s+/g, ' '),
230
120
  ref: ref,
231
121
  ...props,
232
122
  onClick: handleChange
233
123
  }, jsx("div", {
234
- css: CheckBoxRoot,
235
- className: disabled ? 'disabled' : readOnly ? 'read-only' : ''
124
+ css: CheckBoxRootCSS,
125
+ className: ['DGN-UI-Checkbox-Root', disabled ? 'disabled' : readOnly ? 'read-only' : ''].join(' ').trim().replace(/\s+/g, ' ')
236
126
  }, jsx("input", {
237
127
  value: value,
238
128
  ...inputProps,
@@ -240,7 +130,7 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
240
130
  readOnly: readOnly || inputProps.readOnly,
241
131
  disabled: disabled || inputProps.disabled,
242
132
  ref: inputRef,
243
- css: CheckBoxInput,
133
+ css: _CheckBoxInputCSS,
244
134
  id: id,
245
135
  name: name,
246
136
  type: "checkbox",
@@ -248,16 +138,136 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
248
138
  onChange: handleChange,
249
139
  hidden: true
250
140
  }), jsx("label", {
251
- css: CheckBoxLabel
141
+ css: CheckBoxLabelCSS
252
142
  }, jsx("span", {
253
143
  className: [determinate ? 'determinate' : 'indeterminate', readOnly ? 'read-only' : '', disabled ? 'disabled' : ''].join(' '),
254
- css: CheckBoxSquare
144
+ css: _CheckBoxSquareCSS
255
145
  }), (children || label) && jsx(Typography, {
256
146
  type: 'p1',
147
+ style: {
148
+ marginLeft: spacing(1)
149
+ },
257
150
  color: disabled ? clDisabled : '',
258
151
  ...labelProps
259
152
  }, children || label))));
260
153
  }));
154
+
155
+ const CheckBoxSquareCSS = (width, clMain) => css`
156
+ ${flexRow};
157
+ ${positionRelative};
158
+ ${cursorPointer};
159
+ ${borderBox};
160
+ ${parseWidthHeight(width, width)};
161
+ min-width: ${width};
162
+ min-height: ${width};
163
+ background-color: ${white};
164
+ border: 2px solid ${rest};
165
+ border-radius: 2px;
166
+ margin: ${padding}px;
167
+ &.determinate {
168
+ &::after {
169
+ ${displayBlock};
170
+ ${positionAbsolute};
171
+ content: '';
172
+ height: 7px;
173
+ left: 50%;
174
+ top: 43%;
175
+ transform: translate(-50%, -50%) scale(0) rotate(45deg);
176
+ transition: transform 0.3s;
177
+ width: 12.6px;
178
+ }
179
+ }
180
+ &.indeterminate {
181
+ &::after {
182
+ ${flexRow};
183
+ ${positionAbsolute};
184
+ content: '';
185
+ background-color: white;
186
+ left: 2px;
187
+ top: 6px;
188
+ width: 10px;
189
+ height: 2px;
190
+ transition: transform 0.3s;
191
+ transform: scale(0);
192
+ }
193
+ }
194
+ &:not(.disabled):not(.read-only) {
195
+ &:hover {
196
+ box-shadow: 0 0 0 3px ${clFillHover};
197
+ background-color: ${clFillHover};
198
+ border-color: ${clMain};
199
+ }
200
+ &:focus,
201
+ &:active {
202
+ box-shadow: 0 0 0 3px ${clFillPressed};
203
+ background-color: ${clFillPressed};
204
+ }
205
+ }
206
+ &:not(disabled):focus {
207
+ box-shadow: 0 0 0 3px ${clFillPressed};
208
+ background-color: ${clFillPressed};
209
+ }
210
+ &.disabled,
211
+ &.read-only {
212
+ ${cursorNoDrop};
213
+ }
214
+ `;
215
+
216
+ const CheckBoxInputCSS = (CheckBoxSquareCSSName, clMain) => css`
217
+ &:checked + label > span.css-${CheckBoxSquareCSSName} {
218
+ &.determinate {
219
+ &::after {
220
+ transform: translate(-50%, -66%) scale(1) rotate(-45deg);
221
+ background: linear-gradient(${white}, ${white}) left bottom/2px 100%,
222
+ linear-gradient(${white}, ${white}) left bottom/100% 2px;
223
+ background-repeat: no-repeat;
224
+ }
225
+ }
226
+ &.indeterminate {
227
+ &::after {
228
+ transform: scale(1);
229
+ }
230
+ }
231
+ }
232
+ &:checked:not(:disabled) + label > span.css-${CheckBoxSquareCSSName} {
233
+ background-color: ${clMain} !important;
234
+ border-color: ${clMain} !important;
235
+ }
236
+ &:checked:disabled {
237
+ & + label > span.css-${CheckBoxSquareCSSName} {
238
+ &:not(.indeterminate) {
239
+ background-color: ${clDisabled} !important;
240
+ }
241
+ &.indeterminate {
242
+ background-color: ${clFormal2} !important;
243
+ border-color: ${clFormal2} !important;
244
+ }
245
+ }
246
+ }
247
+ &:disabled {
248
+ & + label > span.css-${CheckBoxSquareCSSName} {
249
+ border-color: ${clDisabled};
250
+ }
251
+ }
252
+ `;
253
+
254
+ const CheckBoxLabelCSS = css`
255
+ ${flexRow};
256
+ ${positionRelative};
257
+ ${alignCenter};
258
+ ${borderBox};
259
+ margin-bottom: 0 !important;
260
+ `;
261
+ const CheckBoxRootCSS = css`
262
+ ${flexRow};
263
+ ${alignStart};
264
+ ${borderBox};
265
+ `;
266
+ const CheckboxContainerCSS = css`
267
+ ${displayBlock};
268
+ ${positionRelative};
269
+ width: fit-content;
270
+ `;
261
271
  Checkbox.defaultProps = {
262
272
  label: '',
263
273
  className: '',
@@ -271,57 +281,53 @@ Checkbox.defaultProps = {
271
281
  width: 18
272
282
  };
273
283
  Checkbox.propTypes = {
274
- /** value to check/uncheck square */
284
+ /** If `true`, the component is checked. */
275
285
  checked: PropTypes.bool,
276
286
 
277
- /** value to check/uncheck square (just one time) */
278
- defaultChecked: PropTypes.bool,
287
+ /** Class for component. */
288
+ className: PropTypes.string,
279
289
 
280
- /** Prevent all event if true */
281
- disabled: PropTypes.bool,
290
+ /** The main color of the component. ['primary', 'info', 'success', 'warning', 'danger', #hex, rgb(#, #, #)] */
291
+ color: PropTypes.string,
282
292
 
283
- /** Prevent all event if true (keeping style) */
284
- readOnly: PropTypes.bool,
293
+ /** The default checked state. Use when the component is not controlled. */
294
+ defaultChecked: PropTypes.bool,
285
295
 
286
- /** display tick or hyphen icon */
296
+ /** If `true` display tick or indeterminate if `false`. */
287
297
  determinate: PropTypes.bool,
288
298
 
289
- /** Id is randomized randomly to avoid duplication. */
290
- id: PropTypes.string,
291
-
292
- /** value of input */
293
- value: PropTypes.string,
299
+ /** If `true`, the component is disabled. */
300
+ disabled: PropTypes.bool,
294
301
 
295
- /** class of Checkbox */
296
- className: PropTypes.string,
302
+ /** The id of the component. */
303
+ id: PropTypes.string,
297
304
 
298
- /** The name of the Checkbox corresponds to the label displayed on the interface */
299
- name: PropTypes.string,
305
+ /** [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element. */
306
+ inputProps: PropTypes.object,
300
307
 
301
- /** The name of the Radio is displayed on the interface */
308
+ /** The name of the Radio is displayed on the interface. */
302
309
  label: PropTypes.string,
303
310
 
304
- /** color of checkbox background ['primary', 'info', 'success', 'warning', 'danger', #hex, rgb(#, #, #)] */
305
- color: PropTypes.string,
306
-
307
- /** props for Typography of label */
311
+ /** [Props](https://core.diginet.com.vn/ui/?path=/docs/typography--title) applied to the `Typography` label. */
308
312
  labelProps: PropTypes.object,
309
313
 
310
- /** props for input */
311
- inputProps: PropTypes.object,
312
-
313
- /** width is a number || string, width of Checkbox default 18 */
314
- width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
315
-
316
- /** The function will run to return a true or false value of Radio Component */
317
- onChange: PropTypes.func,
314
+ /** The name of the Checkbox corresponds to the label displayed on the interface. */
315
+ name: PropTypes.string,
318
316
 
319
317
  /**
320
- * ref methods
318
+ * Callback fired when the state is changed.
321
319
  *
322
- * * setChecked: Set check for input
323
- * * getChecked: Get check of input
320
+ * You can pull out the new checked state by accessing `event.value` or `event.target.checked` (boolean).
324
321
  */
325
- ref: PropTypes.any
322
+ onChange: PropTypes.func,
323
+
324
+ /** If `true`, the component is readonly. */
325
+ readOnly: PropTypes.bool,
326
+
327
+ /** The width of checkbox. */
328
+ width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
329
+
330
+ /** The value of input */
331
+ value: PropTypes.any
326
332
  };
327
333
  export default Checkbox;