diginet-core-ui 1.3.45 → 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.
- package/assets/images/menu/dhr/MHRM09N1025.svg +12 -0
- package/components/avatar/index.js +138 -187
- package/components/form-control/dropdown/index.js +20 -15
- package/components/form-control/radio/index.js +126 -113
- package/components/rating/index.js +150 -141
- package/components/typography/index.js +18 -74
- package/package.json +1 -1
- package/readme.md +13 -0
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
4
|
import { css, jsx } from '@emotion/core';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
-
import { forwardRef, memo, useState, useRef } from 'react';
|
|
6
|
+
import { forwardRef, memo, useState, useRef, useEffect, useMemo } from 'react';
|
|
7
7
|
import theme from '../../../theme/settings';
|
|
8
8
|
import { randomString } from '../../../utils';
|
|
9
9
|
import Typography from './../../typography';
|
|
10
|
-
import { cursorPointer, borderBox, positionAbsolute, positionRelative, displayNone, displayBlock,
|
|
10
|
+
import { cursorPointer, borderBox, positionAbsolute, positionRelative, displayNone, displayBlock, cursorNoDrop } from '../../../styles/general';
|
|
11
11
|
const {
|
|
12
12
|
spacing,
|
|
13
13
|
colors: {
|
|
@@ -24,6 +24,7 @@ const {
|
|
|
24
24
|
const Radio = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
25
25
|
id,
|
|
26
26
|
disabled,
|
|
27
|
+
readOnly,
|
|
27
28
|
name,
|
|
28
29
|
defaultChecked,
|
|
29
30
|
checked,
|
|
@@ -34,8 +35,7 @@ const Radio = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
34
35
|
onChange,
|
|
35
36
|
inputRef,
|
|
36
37
|
inputProps,
|
|
37
|
-
|
|
38
|
-
hoverTooltip,
|
|
38
|
+
labelProps,
|
|
39
39
|
...props
|
|
40
40
|
}, ref) => {
|
|
41
41
|
if (!inputRef) {
|
|
@@ -46,127 +46,140 @@ const Radio = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
46
46
|
allowNumber: false,
|
|
47
47
|
allowSymbol: false
|
|
48
48
|
}));
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
`;
|
|
56
|
-
const formCheckInput = css`
|
|
57
|
-
${positionAbsolute};
|
|
58
|
-
${borderBox};
|
|
59
|
-
${displayNone};
|
|
60
|
-
&:hover ~ label::before {
|
|
61
|
-
box-shadow: 0 0 0 2px ${clFillHover};
|
|
62
|
-
background: ${clFillHover};
|
|
63
|
-
}
|
|
64
|
-
&:checked ~ label:after {
|
|
65
|
-
${borderBox};
|
|
66
|
-
${positionAbsolute};
|
|
67
|
-
width: ${width / 2}px;
|
|
68
|
-
height: ${width / 2}px;
|
|
69
|
-
left: ${width / 4}px;
|
|
70
|
-
background: ${clSystemActive};
|
|
71
|
-
border-radius: 50%;
|
|
72
|
-
top: 50%;
|
|
73
|
-
transform: translateY(-50%);
|
|
74
|
-
content: '';
|
|
75
|
-
transition: 0.28s ease;
|
|
76
|
-
}
|
|
77
|
-
&:checked ~ label:before {
|
|
78
|
-
border-color: ${clSystemActive};
|
|
79
|
-
}
|
|
80
|
-
&:disabled + label {
|
|
81
|
-
${pointerEventsNone};
|
|
82
|
-
${cursorNotAllowed};
|
|
83
|
-
color: ${clDisabled};
|
|
84
|
-
&::after {
|
|
85
|
-
background: ${clDisabled};
|
|
86
|
-
}
|
|
87
|
-
&::before {
|
|
88
|
-
border-color: ${clDisabled};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
`;
|
|
92
|
-
const formCheckLabel = css`
|
|
93
|
-
${displayBlock};
|
|
94
|
-
${positionRelative};
|
|
95
|
-
${cursorPointer};
|
|
96
|
-
padding-left: ${width + spacing(1.5)}px;
|
|
97
|
-
min-height: ${width}px;
|
|
98
|
-
margin: 2px;
|
|
99
|
-
&:before {
|
|
100
|
-
${positionAbsolute};
|
|
101
|
-
${borderBox};
|
|
102
|
-
width: ${width}px;
|
|
103
|
-
height: ${width}px;
|
|
104
|
-
border-radius: 50%;
|
|
105
|
-
top: 50%;
|
|
106
|
-
transform: translateY(-50%);
|
|
107
|
-
left: 0;
|
|
108
|
-
content: '';
|
|
109
|
-
border: 2px solid ${clSystemRest};
|
|
110
|
-
transition: 0.28s ease;
|
|
111
|
-
}
|
|
112
|
-
`;
|
|
49
|
+
const [checkedState, setCheckedState] = useState(Boolean(checked !== undefined ? checked : defaultChecked));
|
|
50
|
+
|
|
51
|
+
const _formCheckInputCSS = formCheckInputCSS(width);
|
|
52
|
+
|
|
53
|
+
const _formCheckLabelCSS = formCheckLabelCSS(width);
|
|
113
54
|
|
|
114
55
|
const handleChange = e => {
|
|
115
|
-
|
|
56
|
+
if (disabled || readOnly) return;
|
|
57
|
+
if (checked === undefined) setCheckedState(true);
|
|
58
|
+
e = {
|
|
59
|
+
value: value,
|
|
60
|
+
target: { ...inputRef.current,
|
|
61
|
+
checked: true
|
|
62
|
+
}
|
|
116
63
|
};
|
|
117
|
-
|
|
118
|
-
onChange && onChange(el);
|
|
64
|
+
if (onChange) onChange(e);
|
|
119
65
|
};
|
|
120
66
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (checked !== undefined) setCheckedState(Boolean(checked));
|
|
69
|
+
}, [checked]);
|
|
70
|
+
return useMemo(() => {
|
|
71
|
+
return jsx("div", {
|
|
72
|
+
id: 'DGN-Core-Radio-' + (id || unique),
|
|
73
|
+
css: formCheckCSS,
|
|
74
|
+
className: ['DGN-UI-Radio', className].join(' ').trim().replace(/\s+/g, ' '),
|
|
75
|
+
ref: ref,
|
|
76
|
+
...props
|
|
77
|
+
}, jsx("input", { ...inputProps,
|
|
78
|
+
disabled: disabled,
|
|
79
|
+
ref: inputRef,
|
|
80
|
+
name: name,
|
|
81
|
+
hidden: true,
|
|
82
|
+
checked: checkedState,
|
|
83
|
+
type: "radio",
|
|
84
|
+
css: _formCheckInputCSS,
|
|
85
|
+
id: id || unique,
|
|
86
|
+
onChange: handleChange
|
|
87
|
+
}), jsx("label", {
|
|
88
|
+
css: _formCheckLabelCSS,
|
|
89
|
+
className: `${disabled ? 'disabled' : ''} ${readOnly ? 'read-only' : ''}`,
|
|
90
|
+
htmlFor: id || unique,
|
|
91
|
+
onClick: handleChange
|
|
92
|
+
}, jsx(Typography, {
|
|
93
|
+
color: disabled ? clDisabled : '',
|
|
94
|
+
type: 'p1',
|
|
95
|
+
...labelProps
|
|
96
|
+
}, label !== null && label !== void 0 ? label : value)));
|
|
97
|
+
}, [disabled, onChange, readOnly, checkedState]);
|
|
147
98
|
}));
|
|
99
|
+
const formCheckCSS = css`
|
|
100
|
+
${displayBlock};
|
|
101
|
+
padding: ${spacing(0.5)}px;
|
|
102
|
+
`;
|
|
103
|
+
|
|
104
|
+
const formCheckInputCSS = width => css`
|
|
105
|
+
${positionAbsolute};
|
|
106
|
+
${borderBox};
|
|
107
|
+
${displayNone};
|
|
108
|
+
&:checked ~ label:after {
|
|
109
|
+
${borderBox};
|
|
110
|
+
${positionAbsolute};
|
|
111
|
+
width: ${width / 2}px;
|
|
112
|
+
height: ${width / 2}px;
|
|
113
|
+
left: ${width / 4}px;
|
|
114
|
+
background: ${clSystemActive};
|
|
115
|
+
border-radius: 50%;
|
|
116
|
+
top: 50%;
|
|
117
|
+
transform: translateY(-50%);
|
|
118
|
+
content: '';
|
|
119
|
+
transition: 0.28s ease;
|
|
120
|
+
}
|
|
121
|
+
&:checked ~ label:before {
|
|
122
|
+
border-color: ${clSystemActive};
|
|
123
|
+
}
|
|
124
|
+
`;
|
|
125
|
+
|
|
126
|
+
const formCheckLabelCSS = width => css`
|
|
127
|
+
${displayBlock};
|
|
128
|
+
${positionRelative};
|
|
129
|
+
${cursorPointer};
|
|
130
|
+
margin-bottom: 0 !important;
|
|
131
|
+
padding-left: ${width + spacing(1.5)}px;
|
|
132
|
+
min-height: ${width}px;
|
|
133
|
+
&:hover:not(.disabled):not(.read-only)::before {
|
|
134
|
+
box-shadow: 0 0 0 2px ${clFillHover};
|
|
135
|
+
background: ${clFillHover};
|
|
136
|
+
}
|
|
137
|
+
&.disabled,
|
|
138
|
+
&.read-only {
|
|
139
|
+
${cursorNoDrop};
|
|
140
|
+
}
|
|
141
|
+
&.disabled {
|
|
142
|
+
color: ${clDisabled};
|
|
143
|
+
&:after {
|
|
144
|
+
background: ${clDisabled} !important;
|
|
145
|
+
}
|
|
146
|
+
&:before {
|
|
147
|
+
border-color: ${clDisabled} !important;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
&:before {
|
|
151
|
+
${positionAbsolute};
|
|
152
|
+
${borderBox};
|
|
153
|
+
width: ${width}px;
|
|
154
|
+
height: ${width}px;
|
|
155
|
+
border-radius: 50%;
|
|
156
|
+
top: 50%;
|
|
157
|
+
transform: translateY(-50%);
|
|
158
|
+
left: 0;
|
|
159
|
+
content: '';
|
|
160
|
+
border: 2px solid ${clSystemRest};
|
|
161
|
+
transition: 0.28s ease;
|
|
162
|
+
}
|
|
163
|
+
`;
|
|
164
|
+
|
|
148
165
|
Radio.defaultProps = {
|
|
149
166
|
disabled: false,
|
|
167
|
+
readOnly: false,
|
|
150
168
|
defaultChecked: false,
|
|
151
169
|
label: '',
|
|
152
170
|
value: '',
|
|
153
171
|
className: '',
|
|
154
|
-
width: 20
|
|
172
|
+
width: 20,
|
|
173
|
+
labelProps: {}
|
|
155
174
|
};
|
|
156
175
|
Radio.propTypes = {
|
|
157
|
-
/**
|
|
158
|
-
* If `true`, the component is disabled.
|
|
159
|
-
*/
|
|
176
|
+
/** If `true`, the component is disabled. */
|
|
160
177
|
disabled: PropTypes.bool,
|
|
161
178
|
|
|
162
|
-
/**
|
|
163
|
-
* If `true`, the component is checked.
|
|
164
|
-
*/
|
|
179
|
+
/** If `true`, the component is checked. */
|
|
165
180
|
checked: PropTypes.bool,
|
|
166
181
|
|
|
167
|
-
/**
|
|
168
|
-
* If `true`, the component is defaultChecked.
|
|
169
|
-
*/
|
|
182
|
+
/** If `true`, the component is defaultChecked. */
|
|
170
183
|
defaultChecked: PropTypes.bool,
|
|
171
184
|
|
|
172
185
|
/** Id is randomized randomly to avoid duplication. */
|
|
@@ -176,7 +189,7 @@ Radio.propTypes = {
|
|
|
176
189
|
name: PropTypes.string,
|
|
177
190
|
|
|
178
191
|
/** The value of the component. The DOM API casts this to a string. */
|
|
179
|
-
value: PropTypes.string,
|
|
192
|
+
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
180
193
|
|
|
181
194
|
/** The name of the Radio is displayed on the interface */
|
|
182
195
|
label: PropTypes.string,
|
|
@@ -184,7 +197,7 @@ Radio.propTypes = {
|
|
|
184
197
|
/** The class for Radio component */
|
|
185
198
|
className: PropTypes.string,
|
|
186
199
|
|
|
187
|
-
/**
|
|
200
|
+
/** Props for input. */
|
|
188
201
|
inputProps: PropTypes.object,
|
|
189
202
|
|
|
190
203
|
/** Callback fired when the state is changed.
|
|
@@ -195,10 +208,10 @@ Radio.propTypes = {
|
|
|
195
208
|
* */
|
|
196
209
|
onChange: PropTypes.func,
|
|
197
210
|
|
|
198
|
-
/**
|
|
199
|
-
|
|
211
|
+
/** Prevent all event if true. */
|
|
212
|
+
readOnly: PropTypes.bool,
|
|
200
213
|
|
|
201
|
-
/**
|
|
202
|
-
|
|
214
|
+
/** Props for Typography of label. */
|
|
215
|
+
labelProps: PropTypes.object
|
|
203
216
|
};
|
|
204
217
|
export default Radio;
|