diginet-core-ui 1.3.83 → 1.3.84
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/badge/index.js +86 -75
- package/components/form-control/input-base/index.js +20 -20
- package/package.json +1 -1
- package/readme.md +4 -0
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
/** @jsx jsx */
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { jsx, css } from '@emotion/core';
|
|
3
|
+
import { css, jsx } from '@emotion/core';
|
|
4
|
+
import { Icon } from "./..";
|
|
6
5
|
import OptionWrapper from "../others/option-wrapper";
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import { alignCenter, borderBox, borderRadius4px, flexRow, flexWrap, inlineFlex, justifyCenter, pointerEventsNone, positionAbsolute, positionRelative } from "../../styles/general";
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
paragraph1,
|
|
13
|
-
paragraph2,
|
|
14
|
-
paragraph3
|
|
15
|
-
} = typography;
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
|
|
8
|
+
import { alignCenter, borderBox, borderRadius4px, flexRow, flexWrap, inlineFlex, justifyCenter, parseMinWidthHeight, parseWidthHeight, pointerEventsNone, positionAbsolute, positionRelative } from "../../styles/general";
|
|
9
|
+
import { useColor as colors, useTheme } from "../../theme";
|
|
10
|
+
import { classNames, refType as ref } from "../../utils";
|
|
16
11
|
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
12
|
+
colors: {
|
|
13
|
+
system: {
|
|
14
|
+
rest: systemRest,
|
|
15
|
+
white: systemWhite
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
typography: {
|
|
19
|
+
paragraph1,
|
|
20
|
+
paragraph2,
|
|
21
|
+
paragraph3
|
|
22
|
+
},
|
|
23
|
+
spacing
|
|
24
|
+
} = useTheme();
|
|
25
|
+
const colorMap = new Map([['default', systemRest]]);
|
|
23
26
|
const iconSizeMap = new Map([['medium', 24], ['large', 32], ['giant', 40]]);
|
|
24
27
|
const dotSizeMap = new Map([['medium', 8], ['large', 10], ['giant', 12]]);
|
|
25
28
|
const dotIndentMap = new Map([['medium', 4], ['large', 2]]);
|
|
@@ -70,28 +73,30 @@ const calDotPos = (anchorOrigin, contentDirection, dotSize, hasContent, size) =>
|
|
|
70
73
|
const Badge = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
71
74
|
action = {},
|
|
72
75
|
anchorOrigin,
|
|
73
|
-
|
|
76
|
+
children,
|
|
77
|
+
className,
|
|
78
|
+
color,
|
|
74
79
|
content,
|
|
80
|
+
contentDirection,
|
|
81
|
+
iconProps,
|
|
82
|
+
id,
|
|
83
|
+
invisible,
|
|
75
84
|
max,
|
|
76
85
|
name,
|
|
77
|
-
|
|
86
|
+
showZero,
|
|
78
87
|
size,
|
|
79
|
-
className,
|
|
80
88
|
style,
|
|
81
|
-
showZero,
|
|
82
|
-
invisible,
|
|
83
|
-
children,
|
|
84
|
-
iconProps,
|
|
85
89
|
...props
|
|
86
90
|
}, reference) => {
|
|
91
|
+
if (!reference) reference = useRef(null);
|
|
87
92
|
const ref = useRef(null);
|
|
88
93
|
const typographySize = typographySizeMap.get(size);
|
|
89
94
|
const iconSize = iconSizeMap.get(size);
|
|
90
95
|
const dotSize = content || content === 0 && showZero ? dotSizeMap.get(size) + 8 : dotSizeMap.get(size);
|
|
91
96
|
const dotColor = colors[color] || colorMap.get(color) || color;
|
|
92
97
|
const dotPos = calDotPos(anchorOrigin, !children && name ? 'right' : contentDirection, dotSize, content || content === 0, size);
|
|
93
|
-
const _BadgeNumberCSS = BadgeNumberCSS(typographySize, children, name, dotSize, dotColor
|
|
94
|
-
const _BadgeRootCSS = BadgeRootCSS(children, name, dotPos, _BadgeNumberCSS);
|
|
98
|
+
const _BadgeNumberCSS = BadgeNumberCSS(typographySize, children, name, dotSize, dotColor);
|
|
99
|
+
const _BadgeRootCSS = BadgeRootCSS(children, name, dotPos, _BadgeNumberCSS.name);
|
|
95
100
|
useImperativeHandle(reference, () => {
|
|
96
101
|
const currentRef = ref.current || {};
|
|
97
102
|
currentRef.element = ref.current;
|
|
@@ -106,28 +111,30 @@ const Badge = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
106
111
|
let node = children;
|
|
107
112
|
if (!node && name) {
|
|
108
113
|
node = jsx(Icon, {
|
|
114
|
+
viewBox: true,
|
|
109
115
|
name: name,
|
|
110
116
|
width: iconSize,
|
|
111
117
|
height: iconSize,
|
|
112
|
-
|
|
118
|
+
color: 'currentColor',
|
|
113
119
|
...iconProps
|
|
114
120
|
});
|
|
115
121
|
}
|
|
116
122
|
return jsx("div", {
|
|
117
123
|
css: _BadgeRootCSS,
|
|
118
124
|
ref: ref,
|
|
119
|
-
|
|
125
|
+
id: id,
|
|
126
|
+
className: classNames('DGN-UI-Badge', className),
|
|
120
127
|
style: style,
|
|
121
128
|
...props
|
|
122
129
|
}, jsx("span", {
|
|
123
130
|
className: 'DGN-UI-Badge-Children'
|
|
124
|
-
}, node), content !== undefined && jsx("span", {
|
|
131
|
+
}, node), content !== undefined && !invisible ? jsx("span", {
|
|
125
132
|
css: _BadgeNumberCSS,
|
|
126
133
|
className: 'DGN-UI-Badge-Dot'
|
|
127
|
-
}, max && content > max ? max + '+' : content === 0 && !showZero ? null : content));
|
|
128
|
-
}, [anchorOrigin,
|
|
134
|
+
}, max && content > max ? max + '+' : content === 0 && !showZero ? null : content) : null);
|
|
135
|
+
}, [anchorOrigin, children, className, color, content, contentDirection, iconProps, id, invisible, max, name, showZero, size, style, props]);
|
|
129
136
|
}));
|
|
130
|
-
const BadgeNumberCSS = (typographySize, children, name, dotSize, dotColor
|
|
137
|
+
const BadgeNumberCSS = (typographySize, children, name, dotSize, dotColor) => css`
|
|
131
138
|
${typographySize};
|
|
132
139
|
${flexRow};
|
|
133
140
|
${alignCenter};
|
|
@@ -136,84 +143,88 @@ const BadgeNumberCSS = (typographySize, children, name, dotSize, dotColor, invis
|
|
|
136
143
|
${borderBox};
|
|
137
144
|
${pointerEventsNone};
|
|
138
145
|
${children || name ? positionAbsolute : positionRelative};
|
|
139
|
-
color: ${
|
|
140
|
-
|
|
141
|
-
min-width: ${dotSize}px;
|
|
146
|
+
color: ${systemWhite};
|
|
147
|
+
${parseMinWidthHeight(dotSize)};
|
|
142
148
|
background-color: ${dotColor};
|
|
143
149
|
border-radius: ${dotSize / 2}px;
|
|
144
|
-
padding: 0
|
|
145
|
-
transition: transform 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
|
146
|
-
${invisible && 'transform: scale(0) translate(50%, -50%);'};
|
|
150
|
+
padding: ${spacing([0, 1])};
|
|
147
151
|
`;
|
|
148
|
-
const BadgeRootCSS = (children, name, dotPos,
|
|
152
|
+
const BadgeRootCSS = (children, name, dotPos, BadgeNumberCSSName) => css`
|
|
149
153
|
${inlineFlex};
|
|
150
154
|
${alignCenter};
|
|
151
155
|
${justifyCenter};
|
|
152
156
|
${positionRelative};
|
|
153
157
|
${borderBox};
|
|
154
158
|
${borderRadius4px};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
min-width: max-content;
|
|
160
|
-
.css-${_BadgeNumberCSS.name} {
|
|
161
|
-
${(children || name) && dotPos}
|
|
159
|
+
${parseWidthHeight('max-content')};
|
|
160
|
+
${parseMinWidthHeight('max-content')};
|
|
161
|
+
.css-${BadgeNumberCSSName} {
|
|
162
|
+
${(children || name) && dotPos};
|
|
162
163
|
}
|
|
163
164
|
`;
|
|
164
165
|
Badge.defaultProps = {
|
|
165
|
-
color: 'default',
|
|
166
|
-
size: 'medium',
|
|
167
166
|
anchorOrigin: {
|
|
168
167
|
vertical: 'top',
|
|
169
168
|
horizontal: 'right'
|
|
170
169
|
},
|
|
170
|
+
className: '',
|
|
171
|
+
color: 'default',
|
|
171
172
|
content: null,
|
|
172
|
-
max: 99,
|
|
173
173
|
contentDirection: 'left',
|
|
174
|
-
showZero: false,
|
|
175
174
|
invisible: false,
|
|
176
|
-
|
|
175
|
+
max: 99,
|
|
176
|
+
showZero: false,
|
|
177
|
+
size: 'medium',
|
|
177
178
|
style: {}
|
|
178
179
|
};
|
|
179
180
|
Badge.propTypes = {
|
|
181
|
+
/** The anchor of the badge. */
|
|
180
182
|
anchorOrigin: PropTypes.shape({
|
|
181
183
|
horizontal: PropTypes.oneOf(['left', 'right']),
|
|
182
184
|
vertical: PropTypes.oneOf(['top', 'bottom'])
|
|
183
185
|
}),
|
|
184
|
-
/**
|
|
186
|
+
/** The badge will be added relative to this node. */
|
|
187
|
+
children: PropTypes.node,
|
|
188
|
+
/** Class for component. */
|
|
189
|
+
className: PropTypes.string,
|
|
190
|
+
/** The color of the component. */
|
|
191
|
+
color: PropTypes.oneOfType([PropTypes.oneOf(['default', 'primary', 'info', 'success', 'warning', 'danger']), PropTypes.string]),
|
|
192
|
+
/** The content rendered within the badge. */
|
|
185
193
|
content: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
186
|
-
/**
|
|
187
|
-
max: PropTypes.number,
|
|
188
|
-
/** used to fill background for button */
|
|
194
|
+
/** Direction of content within the badge */
|
|
189
195
|
contentDirection: PropTypes.oneOf(['left', 'right']),
|
|
190
|
-
/**
|
|
191
|
-
|
|
192
|
-
/**
|
|
196
|
+
/** If `true`, the badge is invisible */
|
|
197
|
+
invisible: PropTypes.bool,
|
|
198
|
+
/** Max count to show. */
|
|
199
|
+
max: PropTypes.number,
|
|
200
|
+
/** Prop name of [ButtonIcon](https://core.diginet.com.vn/ui/?path=/docs/buttonicon) components. */
|
|
193
201
|
name: PropTypes.string,
|
|
194
|
-
/**
|
|
195
|
-
|
|
196
|
-
/**
|
|
202
|
+
/** Controls whether the badge is hidden when `content` is zero. */
|
|
203
|
+
showZero: PropTypes.bool,
|
|
204
|
+
/** Size of the components.
|
|
197
205
|
*
|
|
198
206
|
* * medium (dot 8px, typography p3)
|
|
199
207
|
* * large (button 10px, typography p2)
|
|
200
208
|
* * giant (button 12px, typography p1)
|
|
201
209
|
* */
|
|
202
210
|
size: PropTypes.oneOf(['medium', 'large', 'giant']),
|
|
203
|
-
/**
|
|
204
|
-
showZero: PropTypes.bool,
|
|
205
|
-
/** If true, the badge is invisible */
|
|
206
|
-
invisible: PropTypes.bool,
|
|
207
|
-
/** className of component */
|
|
208
|
-
className: PropTypes.string,
|
|
209
|
-
/** style inline of component */
|
|
211
|
+
/** Style inline of component. */
|
|
210
212
|
style: PropTypes.object,
|
|
211
|
-
/**
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
/**
|
|
214
|
+
* ref methods (ref.current.instance.*method*)
|
|
215
|
+
*
|
|
216
|
+
* * option(): Gets all UI component properties
|
|
217
|
+
* * Returns value - object
|
|
218
|
+
* * option(optionName): Gets the value of a single property
|
|
219
|
+
* * @param {optionName} - string
|
|
220
|
+
* * Returns value - any
|
|
221
|
+
* * option(optionName, optionValue): Updates the value of a single property
|
|
222
|
+
* * @param {optionName} - string
|
|
223
|
+
* * @param {optionValue} - any
|
|
224
|
+
* * option(options): Updates the values of several properties
|
|
225
|
+
* * @param {options} - object
|
|
226
|
+
*/
|
|
227
|
+
reference: ref
|
|
217
228
|
};
|
|
218
229
|
export { Badge };
|
|
219
230
|
export default OptionWrapper(Badge);
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
/** @jsx jsx */
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import { jsx, css } from '@emotion/core';
|
|
3
|
+
import { css, jsx } from '@emotion/core';
|
|
4
|
+
import { Icon, Typography } from "../..";
|
|
7
5
|
import { getGlobal } from "../../../global";
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
8
|
+
import { alignCenter, backgroundTransparent, border, borderBox, borderNone, borderRadius4px, displayBlock, flexRow, outlineNone, parseHeight, parseMinHeight, parseMinWidthHeight, parseWidth, parseWidthHeight, pointerEventsNone, positionAbsolute, positionRelative } from "../../../styles/general";
|
|
9
|
+
import { useColor as colors, useTheme } from "../../../theme";
|
|
10
|
+
import { classNames, refType as ref, useInput } from "../../../utils";
|
|
13
11
|
const {
|
|
14
12
|
colors: {
|
|
15
13
|
system: {
|
|
@@ -77,6 +75,7 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
77
75
|
viewType,
|
|
78
76
|
...props
|
|
79
77
|
}, reference) => {
|
|
78
|
+
if (!reference) reference = useRef(null);
|
|
80
79
|
if (!autoWidth && inputProps !== null && inputProps !== void 0 && inputProps.autoWidth) autoWidth = inputProps.autoWidth;
|
|
81
80
|
const _onChange = e => {
|
|
82
81
|
onChange && onChange(e);
|
|
@@ -94,7 +93,7 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
94
93
|
const widthInit = useRef(null);
|
|
95
94
|
const isEnabled = !readOnly && !disabled;
|
|
96
95
|
const _InputBaseCSS = InputBaseCSS(readOnly, status);
|
|
97
|
-
const _SingleLineCSS = SingleLineCSS(autoWidth);
|
|
96
|
+
const _SingleLineCSS = SingleLineCSS(autoWidth, readOnly);
|
|
98
97
|
const _InputCSS = InputCSS(autoWidth, isEnabled, hoverTooltip);
|
|
99
98
|
const _TypoCSS = TypoCSS(disabled);
|
|
100
99
|
const _TextAreaCSS = TextAreaCSS(resize, readOnly);
|
|
@@ -406,20 +405,22 @@ const InputBaseCSS = (readOnly, status) => css`
|
|
|
406
405
|
}`}
|
|
407
406
|
& + .DGN-UI-HelperText {
|
|
408
407
|
${positionAbsolute};
|
|
409
|
-
|
|
408
|
+
${parseMinHeight(16)};
|
|
410
409
|
top: 100%;
|
|
411
410
|
}
|
|
412
411
|
`;
|
|
413
|
-
const SingleLineCSS = autoWidth => css`
|
|
412
|
+
const SingleLineCSS = (autoWidth, readOnly) => css`
|
|
414
413
|
${parseWidthHeight(autoWidth ? 'max-content' : 'auto', 'max-content')}
|
|
415
414
|
${alignCenter};
|
|
416
415
|
flex: 1 1 auto;
|
|
417
416
|
&:focus-within {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
417
|
+
${!readOnly && `
|
|
418
|
+
border-bottom-color: ${semanticInfo};
|
|
419
|
+
&::after {
|
|
420
|
+
border-bottom-color: inherit;
|
|
421
|
+
transform: scaleX(1);
|
|
422
|
+
}
|
|
423
|
+
`}
|
|
423
424
|
}
|
|
424
425
|
&.outlined {
|
|
425
426
|
${parseHeight(40)};
|
|
@@ -432,7 +433,7 @@ const InputCSS = (autoWidth, isEnabled, hoverTooltip) => css`
|
|
|
432
433
|
${outlineNone};
|
|
433
434
|
transition: all 0.1s;
|
|
434
435
|
color: ${textMain};
|
|
435
|
-
|
|
436
|
+
${backgroundTransparent};
|
|
436
437
|
padding-top: 0;
|
|
437
438
|
padding-bottom: 0;
|
|
438
439
|
${paragraph1};
|
|
@@ -493,9 +494,8 @@ const TextAreaCSS = (resize, readOnly) => css`
|
|
|
493
494
|
${positionRelative};
|
|
494
495
|
${borderBox};
|
|
495
496
|
${parseWidth('100%')};
|
|
497
|
+
${parseMinWidthHeight('max-content')};
|
|
496
498
|
color: ${textMain};
|
|
497
|
-
min-height: max-content;
|
|
498
|
-
min-width: max-content;
|
|
499
499
|
background-color: transparent;
|
|
500
500
|
padding: ${spacing(0.5, 0)};
|
|
501
501
|
overflow-y: auto;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -38,6 +38,10 @@ npm test
|
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Changelog
|
|
41
|
+
## 1.3.84
|
|
42
|
+
- \[Fixed\]: Badge – Remove animation, conditional rendering with prop invisible
|
|
43
|
+
- \[Fixed\]: InputBase – Fix css focus when readOnly
|
|
44
|
+
|
|
41
45
|
## 1.3.83
|
|
42
46
|
- \[Changed\]: IconMenu – Add prop className, style
|
|
43
47
|
- \[Changed\]: Grid – Add prop verticalAlign
|