diginet-core-ui 1.3.91-beta.1 → 1.3.92-beta.1
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.
- package/components/accordion/details.js +10 -16
- package/components/accordion/group.js +9 -12
- package/components/accordion/index.js +58 -23
- package/components/accordion/summary.js +175 -34
- package/components/button/index.js +113 -121
- package/components/form-control/checkbox/index.js +60 -62
- package/components/form-control/dropdown/index.js +24 -22
- package/components/modal/body.js +15 -31
- package/components/modal/footer.js +15 -13
- package/components/modal/header.js +36 -38
- package/components/modal/modal.js +21 -29
- package/components/typography/index.js +3 -3
- package/package.json +1 -1
- package/readme.md +4 -0
- package/styles/color-helper.js +4 -0
- package/styles/general.js +11 -11
- package/components/accordion/css.js +0 -172
|
@@ -7,28 +7,19 @@ import PropTypes from 'prop-types';
|
|
|
7
7
|
import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
8
8
|
import { detectColor, fade, hexToRGBA, hslToRgb, isColor, isColorName, rgbaToHexA, rgbToHex } from "../../styles/color-helper";
|
|
9
9
|
import * as allColors from "../../styles/colors";
|
|
10
|
-
import {
|
|
10
|
+
import { bgColor, bgTransparent, border, borderColor, borderNone, borderRadius4px, boxBorder, cursorPointer, displayFlex, displayInlineFlex, flexRow, itemsCenter, justifyCenter, mg, mgl, mgr, outlineNone, overflowHidden, parseHeight, parseMinWidth, parseMinWidthHeight, parseWidthHeight, pd, pointerEventsNone, positionRelative, textColor, userSelectNone, whiteSpaceNoWrap } from "../../styles/general";
|
|
11
11
|
import { useColor as colors, useTheme } from "../../theme";
|
|
12
12
|
import { classNames, refType as ref } from "../../utils";
|
|
13
13
|
import Ripple from "./ripple-effect";
|
|
14
14
|
const {
|
|
15
15
|
colors: {
|
|
16
16
|
system: {
|
|
17
|
-
|
|
18
|
-
disabled: systemDisabled,
|
|
19
|
-
rest: systemRest,
|
|
20
|
-
white: systemWhite
|
|
21
|
-
},
|
|
22
|
-
semantic: {
|
|
23
|
-
info: semanticInfo
|
|
17
|
+
disabled: systemDisabled
|
|
24
18
|
},
|
|
25
19
|
fill: {
|
|
26
20
|
disabled: fillDisabled
|
|
27
21
|
}
|
|
28
22
|
},
|
|
29
|
-
typography: {
|
|
30
|
-
uppercase
|
|
31
|
-
},
|
|
32
23
|
spacing
|
|
33
24
|
} = useTheme();
|
|
34
25
|
export const getRippleColor = (color, viewType, colors) => {
|
|
@@ -68,10 +59,10 @@ export const getClassNameFromColor = color => {
|
|
|
68
59
|
return !isColor(color) && !isColorName(color) ? color : 'custom-color';
|
|
69
60
|
};
|
|
70
61
|
const iconSizeMap = new Map([['tiny', spacing([4])], ['small', spacing([5])], ['medium', spacing([6])], ['large', spacing([8])], ['giant', spacing([10])]]);
|
|
71
|
-
const paddingSizeMap = new Map([['tiny',
|
|
72
|
-
const outlinedPaddingSizeMap = new Map([['tiny',
|
|
73
|
-
const iconMarginSizeMap = new Map([['tiny',
|
|
74
|
-
const typographySizeMap = new Map([['tiny', '
|
|
62
|
+
const paddingSizeMap = new Map([['tiny', [1, 2]], ['small', [1.5, 3]], ['medium', [2, 4]], ['large', [2, 5]], ['giant', [2, 6]]]);
|
|
63
|
+
const outlinedPaddingSizeMap = new Map([['tiny', [0.75, 1.75]], ['small', [1.25, 2.75]], ['medium', [1.75, 3.75]], ['large', [1.75, 4.75]], ['giant', [1.75, 5.75]]]);
|
|
64
|
+
const iconMarginSizeMap = new Map([['tiny', [1]], ['small', [1]], ['medium', [1]], ['large', [1.5]], ['giant', [2]]]);
|
|
65
|
+
const typographySizeMap = new Map([['tiny', 'h5'], ['small', 'h5'], ['medium', 'h4'], ['large', 'h2'], ['giant', 'h1']]);
|
|
75
66
|
const minHeightSizeMap = new Map([['tiny', '24px'], ['small', '32px'], ['medium', '40px'], ['large', '48px'], ['giant', '56px']]);
|
|
76
67
|
const minHeightSizeLinkMap = new Map([['tiny', '16px'], ['small', '20px'], ['medium', '24px'], ['large', '32px'], ['giant', '40px']]);
|
|
77
68
|
const alphaArr = {
|
|
@@ -102,24 +93,25 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
102
93
|
viewType,
|
|
103
94
|
...props
|
|
104
95
|
}, reference) => {
|
|
96
|
+
if (!reference) reference = useRef(null);
|
|
105
97
|
label = label || text || '';
|
|
106
98
|
const ref = useRef(null);
|
|
107
99
|
const rippleRef = useRef(null);
|
|
108
100
|
const [urlState, setUrlState] = useState(href);
|
|
101
|
+
const isColorDefault = colorProp === 'default';
|
|
102
|
+
const isViewTypeLink = viewType === 'link';
|
|
109
103
|
const iconSize = iconSizeMap.get(size);
|
|
110
|
-
const paddingSize = paddingSizeMap.get(size);
|
|
111
|
-
const outlinedPaddingSize = outlinedPaddingSizeMap.get(size);
|
|
104
|
+
const paddingSize = isViewTypeLink ? 0 : viewType === 'outlined' ? outlinedPaddingSizeMap.get(size) : paddingSizeMap.get(size);
|
|
112
105
|
const typographySize = typographySizeMap.get(size);
|
|
113
106
|
const iconMarginSize = iconMarginSizeMap.get(size);
|
|
114
|
-
const minHeightSize = minHeightSizeMap.get(size);
|
|
115
|
-
const minHeightSizeLink = minHeightSizeLinkMap.get(size);
|
|
107
|
+
const minHeightSize = isViewTypeLink ? minHeightSizeLinkMap.get(size) : minHeightSizeMap.get(size);
|
|
116
108
|
const color = colors[colorProp] || colorProp;
|
|
117
|
-
const isViewTypeLink = viewType === 'link';
|
|
118
109
|
const TagName = href ? 'a' : 'button';
|
|
119
|
-
const _ButtonRootCSS = ButtonRootCSS(color);
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
const
|
|
110
|
+
const _ButtonRootCSS = ButtonRootCSS(color, isColorDefault, viewType, loading);
|
|
111
|
+
const _ButtonIconCSS = ButtonIconCSS(endIcon, label, startIcon, iconMarginSize, iconSize);
|
|
112
|
+
const _NonStartIconCSS = NonStartIconCSS(iconSize);
|
|
113
|
+
const _ButtonLabelCSS = ButtonLabelCSS(loading, iconMarginSize);
|
|
114
|
+
const _ButtonSizeCSS = ButtonSizeCSS(paddingSize, minHeightSize);
|
|
123
115
|
const _onClick = e => {
|
|
124
116
|
if (href) e.preventDefault(); //Prevent open link when click
|
|
125
117
|
onClick && stopPropagation && e.stopPropagation();
|
|
@@ -145,6 +137,10 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
145
137
|
return currentRef;
|
|
146
138
|
});
|
|
147
139
|
const StartIcon = useMemo(() => {
|
|
140
|
+
if (!startIcon) return jsx("span", {
|
|
141
|
+
className: 'non-start-icon',
|
|
142
|
+
css: _NonStartIconCSS
|
|
143
|
+
});
|
|
148
144
|
let node = startIcon;
|
|
149
145
|
if (typeof node === 'string') {
|
|
150
146
|
node = jsx(Icon, {
|
|
@@ -155,12 +151,12 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
155
151
|
viewBox: true
|
|
156
152
|
});
|
|
157
153
|
return jsx("span", {
|
|
158
|
-
css:
|
|
154
|
+
css: _ButtonIconCSS,
|
|
159
155
|
className: 'DGN-UI-Button-Start-Icon'
|
|
160
156
|
}, node);
|
|
161
157
|
}
|
|
162
158
|
return jsx("span", {
|
|
163
|
-
css:
|
|
159
|
+
css: _ButtonIconCSS,
|
|
164
160
|
className: 'DGN-UI-Button-Custom-Start-Icon'
|
|
165
161
|
}, node);
|
|
166
162
|
}, [startIcon, size]);
|
|
@@ -175,41 +171,37 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
175
171
|
viewBox: true
|
|
176
172
|
});
|
|
177
173
|
return jsx("span", {
|
|
178
|
-
css:
|
|
174
|
+
css: _ButtonIconCSS,
|
|
179
175
|
className: 'DGN-UI-Button-End-Icon'
|
|
180
176
|
}, node);
|
|
181
177
|
}
|
|
182
178
|
return jsx("span", {
|
|
183
|
-
css:
|
|
179
|
+
css: _ButtonIconCSS,
|
|
184
180
|
className: 'DGN-UI-Button-Custom-End-Icon'
|
|
185
181
|
}, node);
|
|
186
182
|
}, [endIcon, size]);
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
};
|
|
183
|
+
const IconLoading = jsx(CircularProgress, {
|
|
184
|
+
className: 'DGN-UI-Button-Loading',
|
|
185
|
+
background: 'transparent',
|
|
186
|
+
color: 'currentColor',
|
|
187
|
+
size: parseInt(iconSize)
|
|
188
|
+
});
|
|
195
189
|
return useMemo(() => {
|
|
196
190
|
// 1. Có StartIcon => thay StartIcon
|
|
197
191
|
// 2. Có EndIcon => thay EndIcon
|
|
198
192
|
// 3. Có StartIcon + EndIcon => thay StartIcon
|
|
199
193
|
// 4. Không có Icon => hiện thêm icon loading ở đầu
|
|
200
194
|
|
|
201
|
-
let start =
|
|
202
|
-
className: 'no-icon'
|
|
203
|
-
});
|
|
195
|
+
let start = StartIcon;
|
|
204
196
|
let end = endIcon ? EndIcon : null;
|
|
205
197
|
if (loading) {
|
|
206
|
-
if (startIcon) start =
|
|
207
|
-
if (endIcon) end =
|
|
198
|
+
if (startIcon) start = IconLoading;
|
|
199
|
+
if (endIcon) end = IconLoading;
|
|
208
200
|
if (startIcon && endIcon) {
|
|
209
|
-
start =
|
|
201
|
+
start = IconLoading;
|
|
210
202
|
end = EndIcon;
|
|
211
203
|
}
|
|
212
|
-
if (!startIcon && !endIcon) start =
|
|
204
|
+
if (!startIcon && !endIcon) start = IconLoading;
|
|
213
205
|
}
|
|
214
206
|
return jsx(TagName, {
|
|
215
207
|
css: [_ButtonRootCSS, _ButtonSizeCSS, disabled && ButtonDisabledCSS],
|
|
@@ -218,41 +210,48 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
218
210
|
id: id,
|
|
219
211
|
type: type,
|
|
220
212
|
disabled: disabled,
|
|
221
|
-
className: classNames('DGN-UI-Button', viewType,
|
|
213
|
+
className: classNames('DGN-UI-Button', viewType, size, loading && 'button--loading', className),
|
|
222
214
|
href: urlState || null,
|
|
223
215
|
...props
|
|
224
216
|
}, start, jsx(Typography, {
|
|
225
|
-
css:
|
|
217
|
+
css: _ButtonLabelCSS,
|
|
226
218
|
type: typographySize,
|
|
227
219
|
className: classNames('DGN-UI-Button-Label', 'button-text'),
|
|
220
|
+
format: ['uppercase'],
|
|
228
221
|
...labelProps
|
|
229
|
-
}, children || label), end
|
|
222
|
+
}, children || label), end, !disabled && !loading && !isViewTypeLink ? jsx(Ripple, {
|
|
230
223
|
ref: rippleRef,
|
|
231
224
|
color: getRippleColor(colorProp, viewType, allColors)
|
|
232
225
|
}) : null);
|
|
233
|
-
}, [children, className, colorProp, disabled, endIcon, href, id, label, loading, onClick, size, startIcon, stopPropagation, type, urlParams, viewType, urlState]);
|
|
226
|
+
}, [children, className, colorProp, disabled, endIcon, href, id, label, labelProps, loading, onClick, size, startIcon, stopPropagation, type, urlParams, viewType, urlState]);
|
|
234
227
|
}));
|
|
228
|
+
const NonStartIconCSS = iconSize => css`
|
|
229
|
+
${mg(0)};
|
|
230
|
+
${parseHeight(iconSize)};
|
|
231
|
+
${parseMinWidth(0)};
|
|
232
|
+
`;
|
|
235
233
|
const ButtonIconCSS = (endIcon, label, startIcon, iconMarginSize, iconSize) => css`
|
|
234
|
+
${displayFlex};
|
|
236
235
|
${flexRow};
|
|
237
236
|
${itemsCenter};
|
|
238
237
|
${justifyCenter};
|
|
239
238
|
${positionRelative};
|
|
240
239
|
${boxBorder};
|
|
241
|
-
|
|
240
|
+
${mgr(endIcon || label ? iconMarginSize : 0)};
|
|
242
241
|
&.DGN-UI-Button-End-Icon,
|
|
243
242
|
&.DGN-UI-Button-Custom-End-Icon {
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
${mgr('unset')};
|
|
244
|
+
${mgl(startIcon || label ? iconMarginSize : 0)};
|
|
246
245
|
}
|
|
247
246
|
&.DGN-UI-Button-Start-Icon,
|
|
248
247
|
&.DGN-UI-Button-End-Icon {
|
|
249
248
|
${parseWidthHeight(iconSize)};
|
|
250
249
|
}
|
|
251
250
|
`;
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
const ButtonLabelCSS = (loading, iconMarginSize) => css`
|
|
252
|
+
${whiteSpaceNoWrap};
|
|
253
|
+
${textColor('inherit')};
|
|
254
|
+
${mgl(loading ? iconMarginSize : 0)};
|
|
256
255
|
`;
|
|
257
256
|
const ButtonDisabledCSS = css`
|
|
258
257
|
cursor: not-allowed !important;
|
|
@@ -269,29 +268,17 @@ const ButtonDisabledCSS = css`
|
|
|
269
268
|
background-color: transparent !important;
|
|
270
269
|
}
|
|
271
270
|
`;
|
|
272
|
-
const ButtonSizeCSS = (paddingSize, minHeightSize
|
|
273
|
-
|
|
271
|
+
const ButtonSizeCSS = (paddingSize, minHeightSize) => css`
|
|
272
|
+
${pd(paddingSize)};
|
|
274
273
|
${parseMinWidthHeight('max-content', minHeightSize)};
|
|
275
|
-
&.outlined {
|
|
276
|
-
padding: ${outlinedPaddingSize};
|
|
277
|
-
}
|
|
278
|
-
&.link {
|
|
279
|
-
${parseMinHeight(minHeightSizeLink)};
|
|
280
|
-
}
|
|
281
|
-
.no-icon {
|
|
282
|
-
margin: 0;
|
|
283
|
-
${parseHeight(iconSize)};
|
|
284
|
-
${parseMinWidth(0)};
|
|
285
|
-
}
|
|
286
274
|
`;
|
|
287
|
-
const ButtonRootCSS = color => css`
|
|
275
|
+
const ButtonRootCSS = (color, isColorDefault, viewType, loading) => css`
|
|
288
276
|
${displayInlineFlex};
|
|
289
277
|
${itemsCenter};
|
|
290
278
|
${justifyCenter};
|
|
291
279
|
${positionRelative};
|
|
292
280
|
${borderRadius4px};
|
|
293
281
|
${boxBorder};
|
|
294
|
-
${uppercase};
|
|
295
282
|
${cursorPointer};
|
|
296
283
|
${overflowHidden};
|
|
297
284
|
${outlineNone};
|
|
@@ -299,42 +286,44 @@ const ButtonRootCSS = color => css`
|
|
|
299
286
|
${parseHeight('max-content')};
|
|
300
287
|
text-decoration: none;
|
|
301
288
|
transition: all 0.5s;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
&.outlined {
|
|
306
|
-
${bgTransparent};
|
|
289
|
+
${loading && pointerEventsNone};
|
|
290
|
+
${viewType === 'outlined' && css`
|
|
291
|
+
${bgColor('transparent')};
|
|
307
292
|
${border(1, color)};
|
|
308
|
-
|
|
293
|
+
${textColor(color)};
|
|
309
294
|
&.button--loading {
|
|
310
|
-
|
|
295
|
+
${bgColor(hexToRGBA(color, alphaLoading))};
|
|
311
296
|
}
|
|
312
|
-
${Object.keys(alphaArr).map(key =>
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
297
|
+
${Object.keys(alphaArr).map(key => css`
|
|
298
|
+
&: ${key} {
|
|
299
|
+
${bgColor(hexToRGBA(color, alphaArr[key]))};
|
|
300
|
+
}
|
|
301
|
+
`)}
|
|
302
|
+
${isColorDefault && css`
|
|
303
|
+
${border(1, 'system.rest')};
|
|
304
|
+
${textColor('system.rest')};
|
|
318
305
|
&.button--loading,
|
|
319
306
|
&:hover,
|
|
320
307
|
&:focus,
|
|
321
308
|
&:active {
|
|
322
|
-
|
|
323
|
-
|
|
309
|
+
${textColor('system.active')};
|
|
310
|
+
${borderColor('system.active')};
|
|
324
311
|
}
|
|
325
312
|
&.button--loading {
|
|
326
|
-
|
|
313
|
+
${bgColor(hexToRGBA('system.active', alphaLoading))}
|
|
327
314
|
}
|
|
328
|
-
${Object.keys(alphaArr).map(key =>
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
315
|
+
${Object.keys(alphaArr).map(key => css`
|
|
316
|
+
&: ${key} {
|
|
317
|
+
${bgColor(hexToRGBA('system.active', alphaArr[key]))};
|
|
318
|
+
}
|
|
319
|
+
`)}// &:hover | &:focus | &:active
|
|
320
|
+
`}
|
|
321
|
+
`}
|
|
322
|
+
${viewType === 'filled' && css`
|
|
334
323
|
${borderNone};
|
|
335
|
-
|
|
324
|
+
${textColor('system.white')};
|
|
325
|
+
${bgColor(color)};
|
|
336
326
|
font-weight: bold;
|
|
337
|
-
background-color: ${color};
|
|
338
327
|
&.button--loading,
|
|
339
328
|
&:hover,
|
|
340
329
|
&:focus {
|
|
@@ -343,49 +332,52 @@ const ButtonRootCSS = color => css`
|
|
|
343
332
|
&:active {
|
|
344
333
|
filter: brightness(0.7);
|
|
345
334
|
}
|
|
346
|
-
|
|
347
|
-
|
|
335
|
+
${isColorDefault && css`
|
|
336
|
+
${bgColor('system.rest')};
|
|
348
337
|
&.button--loading {
|
|
349
|
-
|
|
338
|
+
${bgColor('system.active')};
|
|
350
339
|
}
|
|
351
340
|
&:hover,
|
|
352
341
|
&:focus,
|
|
353
342
|
&:active {
|
|
354
|
-
|
|
343
|
+
${bgColor('system.active')};
|
|
355
344
|
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
345
|
+
`}
|
|
346
|
+
`}
|
|
347
|
+
${viewType === 'text' && css`
|
|
359
348
|
${bgTransparent};
|
|
360
349
|
${borderNone};
|
|
361
|
-
|
|
350
|
+
${textColor(color)};
|
|
362
351
|
&.button--loading {
|
|
363
|
-
|
|
352
|
+
${bgColor(hexToRGBA(color, alphaLoading))};
|
|
364
353
|
}
|
|
365
|
-
${Object.keys(alphaArr).map(key =>
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
354
|
+
${Object.keys(alphaArr).map(key => css`
|
|
355
|
+
&: ${key} {
|
|
356
|
+
${bgColor(hexToRGBA(color, alphaArr[key]))};
|
|
357
|
+
}
|
|
358
|
+
`)}
|
|
359
|
+
${isColorDefault && css`
|
|
360
|
+
${textColor('system.rest')};
|
|
370
361
|
&:hover,
|
|
371
362
|
&:focus,
|
|
372
363
|
&:active {
|
|
373
|
-
|
|
364
|
+
${textColor('system.active')};
|
|
374
365
|
}
|
|
375
366
|
&.button--loading {
|
|
376
|
-
|
|
377
|
-
|
|
367
|
+
${textColor('system.active')};
|
|
368
|
+
${bgColor(hexToRGBA('system.active', alphaLoading))};
|
|
378
369
|
}
|
|
379
|
-
${Object.keys(alphaArr).map(key =>
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
370
|
+
${Object.keys(alphaArr).map(key => css`
|
|
371
|
+
&: ${key} {
|
|
372
|
+
${bgColor(hexToRGBA('system.active', alphaArr[key]))};
|
|
373
|
+
}
|
|
374
|
+
`)}
|
|
375
|
+
`}
|
|
376
|
+
`}
|
|
377
|
+
${viewType === 'link' && css`
|
|
386
378
|
${borderNone};
|
|
387
|
-
|
|
388
|
-
|
|
379
|
+
${textColor(color)};
|
|
380
|
+
${bgColor('transparent')};
|
|
389
381
|
&.button--loading,
|
|
390
382
|
&:hover,
|
|
391
383
|
&:focus {
|
|
@@ -395,9 +387,9 @@ const ButtonRootCSS = color => css`
|
|
|
395
387
|
filter: brightness(0.7);
|
|
396
388
|
}
|
|
397
389
|
&.default {
|
|
398
|
-
|
|
390
|
+
${textColor('semantic.info')};
|
|
399
391
|
}
|
|
400
|
-
}
|
|
392
|
+
`}
|
|
401
393
|
`;
|
|
402
394
|
Button.defaultProps = {
|
|
403
395
|
className: '',
|
|
@@ -1,31 +1,25 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
/** @jsx jsx */
|
|
3
3
|
import { css, jsx } from '@emotion/core';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import { forwardRef, memo, useEffect, useRef, useState, useImperativeHandle, Fragment } from 'react';
|
|
6
4
|
import { Typography } from "../..";
|
|
7
|
-
import
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { forwardRef, Fragment, memo, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
7
|
+
import { bgColor, border, borderColor, borderRadius, boxBorder, cursorNotAllowed, cursorPointer, displayBlock, displayFlex, flexRow, itemsCenter, itemsStart, left, mg, mgb, parseMinWidthHeight, parseWidth, parseWidthHeight, positionAbsolute, positionRelative, scale, textColor, top } from "../../../styles/general";
|
|
8
|
+
import { useTheme } from "../../../theme";
|
|
8
9
|
import { classNames, randomString, refType as ref } from "../../../utils";
|
|
9
|
-
import { useTheme, useColor as colors } from "../../../theme";
|
|
10
10
|
const {
|
|
11
11
|
colors: {
|
|
12
12
|
system: {
|
|
13
|
-
|
|
14
|
-
white,
|
|
15
|
-
disabled: systemDisabled
|
|
13
|
+
white: systemWhite
|
|
16
14
|
},
|
|
17
15
|
fill: {
|
|
18
|
-
hover:
|
|
19
|
-
pressed:
|
|
20
|
-
},
|
|
21
|
-
formal2: clFormal2,
|
|
22
|
-
semantic: {
|
|
23
|
-
danger: clDanger
|
|
16
|
+
hover: fillHover,
|
|
17
|
+
pressed: fillPressed
|
|
24
18
|
}
|
|
25
19
|
},
|
|
26
20
|
spacing
|
|
27
21
|
} = useTheme();
|
|
28
|
-
const padding =
|
|
22
|
+
const padding = 0.75;
|
|
29
23
|
const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
30
24
|
action = {},
|
|
31
25
|
checked,
|
|
@@ -50,9 +44,8 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
50
44
|
width,
|
|
51
45
|
...props
|
|
52
46
|
}, reference) => {
|
|
53
|
-
if (!
|
|
54
|
-
|
|
55
|
-
}
|
|
47
|
+
if (!reference) reference = useRef(null);
|
|
48
|
+
if (!inputRef) inputRef = useRef(null);
|
|
56
49
|
const ref = useRef(null);
|
|
57
50
|
if (typeof width === 'number') width += 'px';
|
|
58
51
|
const [checkedState, setCheckedState] = useState(checked || defaultChecked);
|
|
@@ -62,9 +55,8 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
62
55
|
allowSymbol: false
|
|
63
56
|
}));
|
|
64
57
|
}
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const _CheckBoxInputCSS = CheckBoxInputCSS(_CheckBoxSquareCSS.name, clMain);
|
|
58
|
+
const _CheckBoxSquareCSS = CheckBoxSquareCSS(width, color);
|
|
59
|
+
const _CheckBoxInputCSS = CheckBoxInputCSS(_CheckBoxSquareCSS.name, color);
|
|
68
60
|
const handleChange = event => {
|
|
69
61
|
stopPropagation && event.stopPropagation();
|
|
70
62
|
if (readOnly || inputProps.readOnly || disabled || inputProps.disabled) return;
|
|
@@ -112,7 +104,10 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
112
104
|
className: classNames('DGN-UI-Checkbox', className),
|
|
113
105
|
ref: ref,
|
|
114
106
|
...props,
|
|
115
|
-
onClick:
|
|
107
|
+
onClick: () => {
|
|
108
|
+
var _inputRef$current$cli, _inputRef$current;
|
|
109
|
+
return (_inputRef$current$cli = (_inputRef$current = inputRef.current).click) === null || _inputRef$current$cli === void 0 ? void 0 : _inputRef$current$cli.call(_inputRef$current);
|
|
110
|
+
}
|
|
116
111
|
}, jsx("div", {
|
|
117
112
|
css: CheckBoxRootCSS,
|
|
118
113
|
className: classNames('DGN-UI-Checkbox-Root', disabled && 'disabled', readOnly && 'read-only')
|
|
@@ -135,130 +130,133 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
135
130
|
}, jsx("span", {
|
|
136
131
|
className: classNames(determinate ? 'determinate' : 'indeterminate', readOnly && 'read-only', disabled && 'disabled'),
|
|
137
132
|
css: _CheckBoxSquareCSS
|
|
138
|
-
}),
|
|
133
|
+
}), children || label ? jsx(Typography, {
|
|
139
134
|
type: 'p1',
|
|
140
135
|
style: {
|
|
141
136
|
marginLeft: spacing(1)
|
|
142
137
|
},
|
|
143
|
-
color: disabled ?
|
|
138
|
+
color: disabled ? 'system.disabled' : '',
|
|
144
139
|
...labelProps
|
|
145
|
-
}, jsx(Fragment, null, children || label, required
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
}, "*"))))));
|
|
140
|
+
}, jsx(Fragment, null, children || label, required ? jsx("span", {
|
|
141
|
+
css: textColor(disabled ? 'system.disabled' : 'semantic.danger')
|
|
142
|
+
}, "*") : null)) : null)));
|
|
150
143
|
}));
|
|
151
|
-
const CheckBoxSquareCSS = (width,
|
|
144
|
+
const CheckBoxSquareCSS = (width, color) => css`
|
|
145
|
+
${displayFlex};
|
|
152
146
|
${flexRow};
|
|
153
147
|
${positionRelative};
|
|
154
148
|
${cursorPointer};
|
|
155
149
|
${boxBorder};
|
|
156
|
-
${parseWidthHeight(width
|
|
157
|
-
${border(2, rest)};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
margin: ${padding}px;
|
|
150
|
+
${parseWidthHeight(width)};
|
|
151
|
+
${border(2, 'system.rest')};
|
|
152
|
+
${parseMinWidthHeight(width)};
|
|
153
|
+
${bgColor('white')};
|
|
154
|
+
${borderRadius(2)};
|
|
155
|
+
${mg([padding])};
|
|
163
156
|
&.determinate {
|
|
164
157
|
&::after {
|
|
165
158
|
${displayBlock};
|
|
166
159
|
${positionAbsolute};
|
|
167
160
|
${parseWidthHeight(12.6, 7)};
|
|
161
|
+
${left('50%')};
|
|
162
|
+
${top('43%')};
|
|
168
163
|
content: '';
|
|
169
|
-
left: 50%;
|
|
170
|
-
top: 43%;
|
|
171
164
|
transform: translate(-50%, -50%) scale(0) rotate(45deg);
|
|
172
165
|
transition: transform 0.3s;
|
|
173
166
|
}
|
|
174
167
|
}
|
|
175
168
|
&.indeterminate {
|
|
176
169
|
&::after {
|
|
170
|
+
${displayFlex};
|
|
177
171
|
${flexRow};
|
|
178
172
|
${positionAbsolute};
|
|
179
173
|
${parseWidthHeight(10, 2)};
|
|
174
|
+
${bgColor('white')};
|
|
175
|
+
${left(2)};
|
|
176
|
+
${top(6)};
|
|
177
|
+
${scale(0)};
|
|
180
178
|
content: '';
|
|
181
|
-
background-color: white;
|
|
182
|
-
left: 2px;
|
|
183
|
-
top: 6px;
|
|
184
179
|
transition: transform 0.3s;
|
|
185
|
-
transform: scale(0);
|
|
186
180
|
}
|
|
187
181
|
}
|
|
188
182
|
&:not(.disabled):not(.read-only) {
|
|
189
183
|
&:hover {
|
|
190
|
-
box-shadow: 0 0 0 3px ${
|
|
191
|
-
|
|
192
|
-
|
|
184
|
+
box-shadow: 0 0 0 3px ${fillHover};
|
|
185
|
+
${bgColor('fill.hover')};
|
|
186
|
+
${borderColor(color)};
|
|
193
187
|
}
|
|
194
188
|
&:focus,
|
|
195
189
|
&:active {
|
|
196
|
-
box-shadow: 0 0 0 3px ${
|
|
197
|
-
|
|
190
|
+
box-shadow: 0 0 0 3px ${fillPressed};
|
|
191
|
+
${bgColor('fill.pressed')};
|
|
198
192
|
}
|
|
199
193
|
}
|
|
200
194
|
&:not(disabled):focus {
|
|
201
|
-
box-shadow: 0 0 0 3px ${
|
|
202
|
-
|
|
195
|
+
box-shadow: 0 0 0 3px ${fillPressed};
|
|
196
|
+
${bgColor('fill.pressed')};
|
|
203
197
|
}
|
|
204
198
|
&.disabled,
|
|
205
199
|
&.read-only {
|
|
206
|
-
${
|
|
200
|
+
${cursorNotAllowed};
|
|
207
201
|
}
|
|
208
202
|
`;
|
|
209
|
-
const CheckBoxInputCSS = (CheckBoxSquareCSSName,
|
|
203
|
+
const CheckBoxInputCSS = (CheckBoxSquareCSSName, color) => css`
|
|
210
204
|
&:checked + label > span.css-${CheckBoxSquareCSSName} {
|
|
211
205
|
&.determinate {
|
|
212
206
|
&::after {
|
|
213
207
|
transform: translate(-50%, -66%) scale(1) rotate(-45deg);
|
|
214
|
-
background: linear-gradient(${
|
|
215
|
-
linear-gradient(${
|
|
208
|
+
background: linear-gradient(${systemWhite}, ${systemWhite}) left bottom/2px 100%,
|
|
209
|
+
linear-gradient(${systemWhite}, ${systemWhite}) left bottom/100% 2px;
|
|
216
210
|
background-repeat: no-repeat;
|
|
217
211
|
}
|
|
218
212
|
}
|
|
219
213
|
&.indeterminate {
|
|
220
214
|
&::after {
|
|
221
|
-
|
|
215
|
+
${scale(1)};
|
|
222
216
|
}
|
|
223
217
|
}
|
|
224
218
|
}
|
|
225
219
|
&:checked:not(:disabled) + label > span.css-${CheckBoxSquareCSSName} {
|
|
226
|
-
|
|
227
|
-
|
|
220
|
+
${bgColor(color)};
|
|
221
|
+
${borderColor(color)};
|
|
228
222
|
}
|
|
229
223
|
&:checked:disabled {
|
|
230
224
|
& + label > span.css-${CheckBoxSquareCSSName} {
|
|
231
225
|
&:not(.indeterminate) {
|
|
232
|
-
|
|
226
|
+
${bgColor('system.disabled')};
|
|
233
227
|
}
|
|
234
228
|
&.indeterminate {
|
|
235
|
-
|
|
236
|
-
|
|
229
|
+
${bgColor('formal2')};
|
|
230
|
+
${borderColor('formal2')};
|
|
237
231
|
}
|
|
238
232
|
}
|
|
239
233
|
}
|
|
240
234
|
&:disabled {
|
|
241
235
|
& + label > span.css-${CheckBoxSquareCSSName} {
|
|
242
|
-
|
|
236
|
+
${borderColor('system.disabled')};
|
|
243
237
|
}
|
|
244
238
|
}
|
|
245
239
|
`;
|
|
246
240
|
const CheckBoxLabelCSS = css`
|
|
241
|
+
${displayFlex};
|
|
247
242
|
${flexRow};
|
|
248
243
|
${positionRelative};
|
|
249
244
|
${itemsCenter};
|
|
250
245
|
${boxBorder};
|
|
251
|
-
margin-bottom: 0 !important;
|
|
252
246
|
`;
|
|
253
247
|
const CheckBoxRootCSS = css`
|
|
248
|
+
${displayFlex};
|
|
254
249
|
${flexRow};
|
|
255
250
|
${itemsStart};
|
|
256
251
|
${boxBorder};
|
|
252
|
+
& > label {
|
|
253
|
+
${mgb(0)};
|
|
254
|
+
}
|
|
257
255
|
`;
|
|
258
256
|
const CheckboxContainerCSS = css`
|
|
259
257
|
${displayBlock};
|
|
260
258
|
${positionRelative};
|
|
261
|
-
|
|
259
|
+
${parseWidth('fit-content')};
|
|
262
260
|
`;
|
|
263
261
|
Checkbox.defaultProps = {
|
|
264
262
|
className: '',
|