diginet-core-ui 1.3.33 → 1.3.34
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/assets/avatar/default.svg +2 -2
- package/assets/images/menu/dhr/ALL.svg +6 -0
- package/assets/images/menu/dhr/D00.svg +12 -0
- package/assets/images/menu/dhr/D09.svg +8 -0
- package/assets/images/menu/dhr/D13.svg +10 -0
- package/assets/images/menu/dhr/D15.svg +10 -0
- package/assets/images/menu/dhr/D21.svg +10 -0
- package/assets/images/menu/dhr/D25.svg +11 -0
- package/assets/images/menu/dhr/D29.svg +11 -0
- package/assets/images/menu/dhr/D38.svg +6 -0
- package/assets/images/menu/dhr/D39.svg +10 -0
- package/assets/images/menu/dhr/D51.svg +12 -0
- package/assets/images/menu/dhr/D52.svg +16 -0
- package/assets/images/menu/dhr/D77.svg +16 -0
- package/assets/images/menu/dhr/D84.svg +12 -0
- package/assets/images/menu/dhr/D89.svg +8 -0
- package/components/avatar/index.js +153 -204
- package/components/badge/index.js +120 -80
- package/components/button/icon.js +193 -170
- package/components/button/index.js +16 -9
- package/components/button/ripple-effect.js +2 -0
- package/components/chip/index.js +139 -137
- package/components/form-control/dropdown/index.js +337 -316
- package/components/form-control/dropdown-box/index.js +3 -3
- package/components/form-control/toggle/index.js +5 -12
- package/components/typography/index.js +92 -47
- package/icons/basic.js +74 -0
- package/icons/effect.js +51 -23
- package/package.json +1 -1
- package/readme.md +21 -0
- package/styles/colors.js +2 -2
- package/styles/general.js +15 -2
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
|
-
import { memo, useRef, forwardRef, useEffect, useMemo } from 'react';
|
|
4
|
+
import { memo, useRef, forwardRef, useEffect, useMemo, useImperativeHandle } from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { jsx, css } from '@emotion/core';
|
|
7
|
-
import
|
|
8
|
-
import { lighten } from '../../styles/color-helper';
|
|
7
|
+
import OptionWrapper from '../others/option-wrapper';
|
|
9
8
|
import { color as colors } from '../../styles/colors';
|
|
10
9
|
import { typography } from '../../styles/typography';
|
|
11
|
-
import { alignCenter, borderBox, borderRadius4px,
|
|
10
|
+
import { alignCenter, borderBox, borderRadius4px, flexRow, flexWrap, inlineFlex, justifyCenter, pointerEventsNone, positionAbsolute, positionRelative } from '../../styles/general';
|
|
11
|
+
import Icon from '../../icons';
|
|
12
12
|
const {
|
|
13
13
|
paragraph1,
|
|
14
14
|
paragraph2,
|
|
@@ -28,60 +28,96 @@ const {
|
|
|
28
28
|
}
|
|
29
29
|
} = colors;
|
|
30
30
|
const colorMap = new Map([['default', rest], ['primary', active], ['success', success], ['warning', warning], ['danger', danger], ['info', info]]);
|
|
31
|
-
const
|
|
32
|
-
const iconSizeMap = new Map([['medium', '24px'], ['large', '32px'], ['giant', '40px']]);
|
|
31
|
+
const iconSizeMap = new Map([['medium', 24], ['large', 32], ['giant', 40]]);
|
|
33
32
|
const dotSizeMap = new Map([['medium', 8], ['large', 10], ['giant', 12]]);
|
|
34
|
-
const
|
|
33
|
+
const dotIndentMap = new Map([['medium', 4], ['large', 2]]);
|
|
35
34
|
const typographySizeMap = new Map([['medium', paragraph3], ['large', paragraph2], ['giant', paragraph1]]);
|
|
36
35
|
|
|
37
|
-
const calDotPos = (
|
|
38
|
-
|
|
36
|
+
const calDotPos = (anchorOrigin, contentDirection, dotSize, hasContent, size) => {
|
|
37
|
+
const halfDotSize = dotSize / 2;
|
|
38
|
+
const {
|
|
39
|
+
horizontal,
|
|
40
|
+
vertical
|
|
41
|
+
} = anchorOrigin;
|
|
42
|
+
const dotIndent = hasContent ? dotIndentMap.get(size) || 0 : 0;
|
|
43
|
+
const verticalCssRight = vertical === 'bottom' ? css`
|
|
44
|
+
bottom: ${-dotIndent}px;
|
|
45
|
+
` : css`
|
|
46
|
+
top: ${-dotIndent}px;
|
|
47
|
+
`;
|
|
48
|
+
const verticalCssLeft = vertical === 'bottom' ? css`
|
|
49
|
+
bottom: ${-halfDotSize}px;
|
|
50
|
+
` : css`
|
|
51
|
+
top: ${-halfDotSize}px;
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
if (contentDirection === 'right') {
|
|
55
|
+
if (horizontal === 'left') {
|
|
56
|
+
return css`
|
|
57
|
+
left: ${-dotIndent}px;
|
|
58
|
+
${verticalCssRight};
|
|
59
|
+
`;
|
|
60
|
+
} else {
|
|
61
|
+
return css`
|
|
62
|
+
left: ${`calc(100% - ${dotSize - dotIndent}px);`};
|
|
63
|
+
${verticalCssRight};
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
if (horizontal === 'left') {
|
|
68
|
+
return css`
|
|
69
|
+
right: ${`calc(100% - ${halfDotSize}px);`};
|
|
70
|
+
${verticalCssLeft};
|
|
71
|
+
`;
|
|
72
|
+
} else {
|
|
73
|
+
return css`
|
|
74
|
+
right: ${`${-halfDotSize}px;`};
|
|
75
|
+
${verticalCssLeft};
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
39
79
|
};
|
|
40
80
|
|
|
41
81
|
const Badge = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
82
|
+
anchorOrigin,
|
|
83
|
+
contentDirection,
|
|
42
84
|
content,
|
|
43
85
|
max,
|
|
44
|
-
viewType,
|
|
45
86
|
name,
|
|
46
87
|
color,
|
|
47
88
|
size,
|
|
48
89
|
className,
|
|
49
90
|
style,
|
|
50
|
-
|
|
91
|
+
showZero,
|
|
92
|
+
invisible,
|
|
51
93
|
refs,
|
|
52
|
-
onClick,
|
|
53
94
|
children,
|
|
95
|
+
iconProps,
|
|
54
96
|
...props
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
ref = useRef(null);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const _size = sizeMap.get(size);
|
|
61
|
-
|
|
62
|
-
const _color = colorMap.get(color);
|
|
63
|
-
|
|
97
|
+
}, reference) => {
|
|
98
|
+
const ref = useRef(null);
|
|
64
99
|
const typographySize = typographySizeMap.get(size);
|
|
65
100
|
const iconSize = iconSizeMap.get(size);
|
|
66
|
-
const dotSize = content || content === 0 ? dotSizeMap.get(size) + 8 : dotSizeMap.get(size);
|
|
67
|
-
const dotColor = colorMap.get(color);
|
|
68
|
-
const
|
|
69
|
-
const dotPos = calDotPos(dotSize, dotPaddingSize, parseInt(iconSize), viewType === 'text', content);
|
|
101
|
+
const dotSize = content || content === 0 && showZero ? dotSizeMap.get(size) + 8 : dotSizeMap.get(size);
|
|
102
|
+
const dotColor = colorMap.get(color) || colors[color] || color;
|
|
103
|
+
const dotPos = calDotPos(anchorOrigin, !children && name ? 'right' : contentDirection, dotSize, content || content === 0, size);
|
|
70
104
|
const BadgeNumber = css`
|
|
71
105
|
${typographySize};
|
|
72
106
|
${flexRow}
|
|
73
107
|
${alignCenter}
|
|
74
108
|
${justifyCenter}
|
|
75
109
|
${flexWrap}
|
|
76
|
-
${positionAbsolute}
|
|
77
110
|
${borderBox}
|
|
111
|
+
${pointerEventsNone}
|
|
112
|
+
${children || name ? positionAbsolute : positionRelative}
|
|
78
113
|
color: ${white};
|
|
79
114
|
min-height: ${dotSize}px;
|
|
80
115
|
min-width: ${dotSize}px;
|
|
81
116
|
background-color: ${dotColor};
|
|
82
117
|
border-radius: ${dotSize / 2}px;
|
|
83
118
|
padding: 0 4px;
|
|
84
|
-
|
|
119
|
+
transition: transform 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
|
120
|
+
${invisible && 'transform: scale(0) translate(50%, -50%);'};
|
|
85
121
|
`;
|
|
86
122
|
const BadgeRoot = css`
|
|
87
123
|
${inlineFlex}
|
|
@@ -90,39 +126,27 @@ const Badge = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
90
126
|
${positionRelative}
|
|
91
127
|
${borderBox}
|
|
92
128
|
${borderRadius4px}
|
|
93
|
-
|
|
94
|
-
height:
|
|
95
|
-
width:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
bottom: ${dotPos}px;
|
|
101
|
-
left: ${dotPos}px;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
&.filled {
|
|
105
|
-
${name && !children && `
|
|
106
|
-
color: ${white};
|
|
107
|
-
background-color: ${_color};
|
|
108
|
-
`}
|
|
109
|
-
.css-${BadgeNumber.name} {
|
|
110
|
-
top: ${dotPos}px;
|
|
111
|
-
right: ${dotPos}px;
|
|
112
|
-
}
|
|
129
|
+
height: max-content;
|
|
130
|
+
min-height: max-content;
|
|
131
|
+
width: max-content;
|
|
132
|
+
min-width: max-content;
|
|
133
|
+
color: ${white};
|
|
134
|
+
.css-${BadgeNumber.name} {
|
|
135
|
+
${(children || name) && dotPos}
|
|
113
136
|
}
|
|
114
137
|
`;
|
|
115
|
-
const BadgeIcon = css`
|
|
116
|
-
${overflowHidden}
|
|
117
|
-
`;
|
|
118
|
-
|
|
119
|
-
const _onClick = event => {
|
|
120
|
-
onClick && onClick(event);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
138
|
useEffect(() => {
|
|
124
139
|
if (refs) refs(ref);
|
|
125
140
|
}, []);
|
|
141
|
+
useImperativeHandle(reference, () => {
|
|
142
|
+
const currentRef = ref.current || {};
|
|
143
|
+
const _instance = {}; // methods
|
|
144
|
+
|
|
145
|
+
_instance.__proto__ = {}; // hidden methods
|
|
146
|
+
|
|
147
|
+
currentRef.instance = _instance;
|
|
148
|
+
return currentRef;
|
|
149
|
+
});
|
|
126
150
|
return useMemo(() => {
|
|
127
151
|
let node = children;
|
|
128
152
|
|
|
@@ -131,39 +155,46 @@ const Badge = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
131
155
|
name: name,
|
|
132
156
|
width: iconSize,
|
|
133
157
|
height: iconSize,
|
|
134
|
-
|
|
135
|
-
|
|
158
|
+
viewBox: true,
|
|
159
|
+
...iconProps
|
|
136
160
|
});
|
|
137
161
|
}
|
|
138
162
|
|
|
139
163
|
return jsx("div", {
|
|
140
164
|
css: BadgeRoot,
|
|
141
165
|
ref: ref,
|
|
142
|
-
className: ['DGN-UI-Badge',
|
|
166
|
+
className: ['DGN-UI-Badge', className].join(' ').trim().replace(/\s+/g, ' '),
|
|
143
167
|
style: style,
|
|
144
|
-
onClick: _onClick,
|
|
145
168
|
...props
|
|
146
169
|
}, jsx("span", {
|
|
147
|
-
|
|
148
|
-
className: 'DGN-UI-Badge-Icon'
|
|
170
|
+
className: 'DGN-UI-Badge-Children'
|
|
149
171
|
}, node), content !== undefined && jsx("span", {
|
|
150
172
|
css: BadgeNumber,
|
|
151
|
-
className: 'DGN-UI-Badge-Dot'
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}, [content, name, size, children, max, viewType, color, style, className]);
|
|
173
|
+
className: 'DGN-UI-Badge-Dot'
|
|
174
|
+
}, max && content > max ? max + '+' : content === 0 && !showZero ? null : content));
|
|
175
|
+
}, [anchorOrigin, contentDirection, content, name, size, children, max, showZero, invisible, color, style, className]);
|
|
155
176
|
}));
|
|
156
177
|
Badge.defaultProps = {
|
|
157
|
-
viewType: 'filled',
|
|
158
|
-
// name: 'Notification',
|
|
159
178
|
color: 'default',
|
|
160
179
|
size: 'medium',
|
|
180
|
+
anchorOrigin: {
|
|
181
|
+
vertical: 'top',
|
|
182
|
+
horizontal: 'right'
|
|
183
|
+
},
|
|
161
184
|
content: null,
|
|
162
185
|
max: 99,
|
|
186
|
+
contentDirection: 'left',
|
|
187
|
+
showZero: false,
|
|
188
|
+
invisible: false,
|
|
163
189
|
className: '',
|
|
164
190
|
style: {}
|
|
165
191
|
};
|
|
166
192
|
Badge.propTypes = {
|
|
193
|
+
anchorOrigin: PropTypes.shape({
|
|
194
|
+
horizontal: PropTypes.oneOf(['left', 'right']),
|
|
195
|
+
vertical: PropTypes.oneOf(['top', 'bottom'])
|
|
196
|
+
}),
|
|
197
|
+
|
|
167
198
|
/** the quantity is shown on the badge */
|
|
168
199
|
content: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
169
200
|
|
|
@@ -171,36 +202,45 @@ Badge.propTypes = {
|
|
|
171
202
|
max: PropTypes.number,
|
|
172
203
|
|
|
173
204
|
/** used to fill background for button */
|
|
174
|
-
|
|
205
|
+
contentDirection: PropTypes.oneOf(['left', 'right']),
|
|
175
206
|
|
|
176
207
|
/** background color of badge */
|
|
177
|
-
color: PropTypes.oneOf(['default', 'primary', 'info', 'success', 'warning', 'danger']),
|
|
208
|
+
color: PropTypes.oneOfType([PropTypes.oneOf(['default', 'primary', 'info', 'success', 'warning', 'danger']), PropTypes.string]),
|
|
178
209
|
|
|
179
|
-
/** name
|
|
210
|
+
/** use name will replace children with ButtonIcon */
|
|
180
211
|
name: PropTypes.string,
|
|
181
212
|
|
|
182
|
-
/**
|
|
213
|
+
/** other icon props when use prop name */
|
|
214
|
+
iconProps: PropTypes.object,
|
|
215
|
+
|
|
216
|
+
/** size of Badge
|
|
217
|
+
*
|
|
218
|
+
* * medium (dot 8px, typography p3)
|
|
219
|
+
* * large (button 10px, typography p2)
|
|
220
|
+
* * giant (button 12px, typography p1)
|
|
221
|
+
* */
|
|
183
222
|
size: PropTypes.oneOf(['medium', 'large', 'giant']),
|
|
184
223
|
|
|
185
|
-
/**
|
|
224
|
+
/** Controls whether the badge is hidden when content is zero */
|
|
225
|
+
showZero: PropTypes.bool,
|
|
226
|
+
|
|
227
|
+
/** If true, the badge is invisible */
|
|
228
|
+
invisible: PropTypes.bool,
|
|
229
|
+
|
|
230
|
+
/** className of component */
|
|
186
231
|
className: PropTypes.string,
|
|
187
232
|
|
|
188
|
-
/** style inline of
|
|
233
|
+
/** style inline of component */
|
|
189
234
|
style: PropTypes.object,
|
|
190
235
|
|
|
191
|
-
/** style inline of badge number */
|
|
192
|
-
badgeNumStyle: PropTypes.object,
|
|
193
|
-
|
|
194
236
|
/** the function get ref */
|
|
195
237
|
refs: PropTypes.func,
|
|
196
238
|
|
|
197
|
-
/** the function will run when click on badge */
|
|
198
|
-
onClick: PropTypes.func,
|
|
199
|
-
|
|
200
239
|
/** the content displayed under the number of the badge */
|
|
201
240
|
children: PropTypes.node,
|
|
202
241
|
|
|
203
242
|
/** any props else */
|
|
204
243
|
props: PropTypes.any
|
|
205
244
|
};
|
|
206
|
-
export
|
|
245
|
+
export { Badge };
|
|
246
|
+
export default OptionWrapper(Badge);
|