Skip to content

Commit caa9c13

Browse files
committed
optimize code
1 parent a4468e6 commit caa9c13

File tree

7 files changed

+34
-57
lines changed

7 files changed

+34
-57
lines changed

src/DTableColorPicker/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ const RGB_COLORS_MAP = {
3434

3535
const LOCAL_STORAGE_KEY = 'dtable-color-picker';
3636

37-
const DTableColorPicker = forwardRef((props, ref) => {
38-
const { onToggle, popoverStyle, color, defaultColors, useProtal, target, scrollContainerId, throttleDelay = 20 } = props;
37+
const DTableColorPicker = forwardRef(({ onToggle, popoverStyle, color = '#ffffff', defaultColors, useProtal, target, scrollContainerId, throttleDelay = 20, onSubmit }, ref) => {
3938
const initialRgbaColor = hexToRgba(color);
4039
const [value, setValue] = useState(initialRgbaColor);
4140
const [hexVal, setHexVal] = useState(getInitialHexVal(color));
@@ -170,7 +169,7 @@ const DTableColorPicker = forwardRef((props, ref) => {
170169
const updateValue = (newValue) => {
171170
setValue(newValue);
172171
const submitHex = rgbaToHex(newValue);
173-
props.onSubmit(submitHex);
172+
onSubmit(submitHex);
174173
};
175174

176175
const onAlphaInputBlur = () => {
@@ -390,8 +389,4 @@ DTableColorPicker.propTypes = {
390389
throttleDelay: PropTypes.number,
391390
};
392391

393-
DTableColorPicker.defaultProps = {
394-
color: '#ffffff',
395-
};
396-
397392
export default DTableColorPicker;

src/DTablePopover/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import { getEventClassName } from '../utils/utils';
55

66
class DTablePopover extends React.Component {
77

8+
static defaultProps = {
9+
placement: 'bottom-start',
10+
hideArrow: true,
11+
canHideDTablePopover: true
12+
};
13+
814
dtablePopoverRef = null;
915

1016
componentDidMount() {
@@ -69,12 +75,6 @@ class DTablePopover extends React.Component {
6975
}
7076
}
7177

72-
DTablePopover.defaultProps = {
73-
placement: 'bottom-start',
74-
hideArrow: true,
75-
canHideDTablePopover: true
76-
};
77-
7878
DTablePopover.propTypes = {
7979
target: PropTypes.string.isRequired,
8080
innerClassName: PropTypes.string,

src/DTableRadio/index.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,39 @@ import classnames from 'classnames';
44

55
import './index.css';
66

7-
function DTableRadio(props) {
8-
const { className } = props;
7+
function DTableRadio({
8+
disabled = false,
9+
name = 'dtable-radio-input',
10+
onCheckedChange = () => {},
11+
className,
12+
isChecked,
13+
value,
14+
label
15+
}) {
916

1017
return (
1118
<label
1219
className={classnames('dtable-radio w-100 align-items-center', {
13-
'dtable-radio-disable': props.disabled,
20+
'dtable-radio-disable': disabled,
1421
[className]: className
1522
})}
1623
>
1724
<input
1825
type="radio"
1926
className="dtable-radio-input position-absolute"
20-
checked={props.isChecked}
21-
onChange={props.disabled ? () => {} : props.onCheckedChange}
22-
name={props.name}
23-
value={props.value}
27+
checked={isChecked}
28+
onChange={disabled ? () => {} : onCheckedChange}
29+
name={name}
30+
value={value}
2431
/>
2532
<span
2633
className={classnames('dtable-radio-indicator position-relative', {
27-
'dtable-radio-selected-indicator': props.isChecked,
28-
'dtable-radio-indicator-disable': props.disabled
34+
'dtable-radio-selected-indicator': isChecked,
35+
'dtable-radio-indicator-disable': disabled
2936
})}
3037
>
3138
</span>
32-
<span className="dtable-radio-description text-truncate ml-2">{props.label}</span>
39+
<span className="dtable-radio-description text-truncate ml-2">{label}</span>
3340
</label>
3441
);
3542
}
@@ -44,10 +51,4 @@ DTableRadio.propTypes = {
4451
onCheckedChange: PropTypes.func,
4552
};
4653

47-
DTableRadio.defaultProps = {
48-
disabled: false,
49-
name: 'dtable-radio-input',
50-
onCheckedChange: () => {}
51-
};
52-
5354
export default DTableRadio;

src/DTableSearchInput/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class DtableSearchInput extends Component {
1515
this.inputRef = null;
1616
}
1717

18+
static defaultProps = {
19+
wait: 100,
20+
disabled: false,
21+
value: '',
22+
};
23+
1824
UNSAFE_componentWillReceiveProps(nextProps) {
1925
if (nextProps.value !== this.props.value) {
2026
this.setState({ searchValue: nextProps.value });
@@ -121,10 +127,4 @@ DtableSearchInput.propTypes = {
121127
value: PropTypes.string,
122128
};
123129

124-
DtableSearchInput.defaultProps = {
125-
wait: 100,
126-
disabled: false,
127-
value: '',
128-
};
129-
130130
export default DtableSearchInput;

src/DTableSelect/dtable-select-label.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33

44
import './dtable-select-label.css';
55

6-
function DTableSelectLabel({ classname, name, isSelect }) {
6+
function DTableSelectLabel({ classname = '', name = '', isSelect = false }) {
77
return (
88
<div className={`${classname} w-100 d-flex justify-content-between`}>
99
<span>{name}</span>
@@ -22,10 +22,4 @@ DTableSelectLabel.propTypes = {
2222
isSelect: PropTypes.bool,
2323
};
2424

25-
DTableSelectLabel.defaultProps = {
26-
classname: '',
27-
name: '',
28-
isSelect: false,
29-
};
30-
3125
export default DTableSelectLabel;

src/DTableSwitch/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { generatorBase64Code } from 'dtable-utils';
55

66
import './index.css';
77

8-
function DTableSwitch(props) {
9-
const { onChange, checked, placeholder, disabled, size, switchPosition, switchClassName } = props;
8+
function DTableSwitch({ onChange, checked = false, placeholder, disabled, size = 'sm', switchPosition = 'right', switchClassName }) {
109
const switchNode = <span className="custom-switch-indicator"></span>;
1110
const textNode = <span className="custom-switch-description text-truncate">{placeholder}</span>;
1211
return (
@@ -35,12 +34,6 @@ function DTableSwitch(props) {
3534
);
3635
}
3736

38-
DTableSwitch.defaultProps = {
39-
checked: false,
40-
size: 'sm',
41-
switchPosition: 'right',
42-
};
43-
4437
DTableSwitch.propTypes = {
4538
checked: PropTypes.bool,
4639
size: PropTypes.string, // 'sm || lg'

src/Department-editor/selected-departments/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { getLocale } from '../../lang';
66

77
import './index.css';
88

9-
function SelectedDepartments(props) {
10-
const { value, removeDepartment, isShowRemoveIcon, departments } = props;
9+
function SelectedDepartments({ value, removeDepartment, isShowRemoveIcon = false, departments = [] }) {
1110

1211
const idDepartmentMap = useMemo(() => {
1312
let idDepartmentMap = {};
@@ -65,11 +64,6 @@ function SelectedDepartments(props) {
6564
return dom;
6665
}
6766

68-
SelectedDepartments.defaultProps = {
69-
isShowRemoveIcon: false,
70-
departments: [],
71-
};
72-
7367
SelectedDepartments.propTypes = {
7468
isShowRemoveIcon: PropTypes.bool,
7569
value: PropTypes.array,

0 commit comments

Comments
 (0)