Skip to content

Commit 7d66ebd

Browse files
authored
Update props and defaults for Dash 3.0 (#1077)
* Remove defaultProps * Remove duplicated props * Fix issue in Modal propTypes
1 parent 9487ece commit 7d66ebd

40 files changed

+690
-913
lines changed

src/components/accordion/Accordion.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ const Accordion = props => {
1414
let {
1515
children,
1616
active_item,
17-
always_open,
18-
start_collapsed,
1917
loading_state,
2018
key,
2119
setProps,
2220
class_name,
2321
className,
22+
always_open = false,
23+
start_collapsed = false,
2424
...otherProps
2525
} = props;
2626
children = parseChildrenToArray(children);
@@ -87,11 +87,9 @@ const Accordion = props => {
8787
);
8888
};
8989

90-
Accordion.defaultProps = {
90+
Accordion.dashPersistence = {
9191
persisted_props: ['active_item'],
92-
persistence_type: 'local',
93-
start_collapsed: false,
94-
always_open: false
92+
persistence_type: 'local'
9593
};
9694

9795
Accordion.propTypes = {

src/components/accordion/AccordionItem.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ const AccordionItem = ({
3535
(loading_state && loading_state.is_loading) || undefined
3636
}
3737
>
38-
<RBAccordion.Header
39-
onClick={() => {
40-
toggle(itemID);
41-
}}
42-
>
38+
<RBAccordion.Header onClick={() => toggle(itemID)}>
4339
{title}
4440
</RBAccordion.Header>
4541
<RBAccordion.Body>{children}</RBAccordion.Body>

src/components/alert/Alert.js

+15-20
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@ import {bootstrapColors} from '../../private/BootstrapColors';
1010
* Control the visibility using callbacks with the `is_open` prop, or set it to
1111
* auto-dismiss with the `duration` prop.
1212
*/
13-
const Alert = props => {
14-
const {
15-
children,
16-
dismissable,
17-
duration,
18-
is_open,
19-
loading_state,
20-
setProps,
21-
color,
22-
style,
23-
class_name,
24-
className,
25-
fade,
26-
...otherProps
27-
} = props;
28-
13+
const Alert = ({
14+
children,
15+
dismissable,
16+
loading_state,
17+
setProps,
18+
style,
19+
class_name,
20+
className,
21+
fade,
22+
color = 'success',
23+
is_open = true,
24+
duration = null,
25+
...otherProps
26+
}) => {
2927
const timeout = useRef(null);
3028

3129
useEffect(() => {
@@ -69,10 +67,7 @@ const Alert = props => {
6967
);
7068
};
7169

72-
Alert.defaultProps = {
73-
color: 'success',
74-
is_open: true,
75-
duration: null,
70+
Alert.dashPersistence = {
7671
persisted_props: ['is_open'],
7772
persistence_type: 'local'
7873
};

src/components/badge/Badge.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ const Badge = props => {
1414
href,
1515
loading_state,
1616
setProps,
17-
color,
1817
style,
1918
className,
2019
class_name,
2120
text_color,
21+
color = 'secondary',
22+
n_clicks = 0,
23+
n_clicks_timestamp = -1,
2224
...otherProps
2325
} = props;
2426

2527
const incrementClicks = () => {
2628
if (setProps) {
2729
setProps({
28-
n_clicks: props.n_clicks + 1,
30+
n_clicks: n_clicks + 1,
2931
n_clicks_timestamp: Date.now()
3032
});
3133
}
@@ -42,7 +44,7 @@ const Badge = props => {
4244
text={text_color}
4345
className={class_name || className}
4446
style={!isBootstrapColor ? {backgroundColor: color, ...style} : style}
45-
{...omit(['setProps', 'n_clicks', 'n_clicks_timestamp'], otherProps)}
47+
{...omit(['setProps'], otherProps)}
4648
data-dash-is-loading={
4749
(loading_state && loading_state.is_loading) || undefined
4850
}
@@ -52,12 +54,6 @@ const Badge = props => {
5254
);
5355
};
5456

55-
Badge.defaultProps = {
56-
color: 'secondary',
57-
n_clicks: 0,
58-
n_clicks_timestamp: -1
59-
};
60-
6157
Badge.propTypes = {
6258
/**
6359
* The ID of this component, used to identify dash components

src/components/button/Button.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const Button = props => {
7373
);
7474
};
7575

76-
Button.defaultProps = {
76+
Button.dashPersistence = {
7777
n_clicks: 0,
7878
n_clicks_timestamp: -1
7979
};

src/components/card/CardLink.js

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import {omit} from 'ramda';
43
import RBCard from 'react-bootstrap/Card';
54
import Link from '../../private/Link';
65

76
/**
87
* Use card link to add consistently styled links to your cards. Links can be
98
* used like buttons, external links, or internal Dash style links.
109
*/
11-
const CardLink = props => {
12-
const {
13-
children,
14-
loading_state,
15-
disabled,
16-
className,
17-
class_name,
18-
...otherProps
19-
} = props;
20-
10+
const CardLink = ({
11+
children,
12+
loading_state,
13+
disabled,
14+
className,
15+
class_name,
16+
n_clicks = 0,
17+
setProps,
18+
...otherProps
19+
}) => {
2120
const incrementClicks = () => {
22-
if (!disabled && props.setProps) {
23-
props.setProps({
24-
n_clicks: props.n_clicks + 1,
21+
if (!disabled && setProps) {
22+
setProps({
23+
n_clicks: n_clicks + 1,
2524
n_clicks_timestamp: Date.now()
2625
});
2726
}
@@ -36,18 +35,13 @@ const CardLink = props => {
3635
preOnClick={incrementClicks}
3736
disabled={disabled}
3837
className={class_name || className}
39-
{...omit(['setProps', 'n_clicks', 'n_clicks_timestamp'], otherProps)}
38+
{...otherProps}
4039
>
4140
{children}
4241
</RBCard.Link>
4342
);
4443
};
4544

46-
CardLink.defaultProps = {
47-
n_clicks: 0,
48-
n_clicks_timestamp: -1
49-
};
50-
5145
CardLink.propTypes = {
5246
/**
5347
* The ID of this component, used to identify dash components

src/components/carousel/Carousel.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import Link from '../../private/Link';
1313
const Carousel = props => {
1414
const {
1515
items,
16-
active_index,
1716
style,
1817
class_name,
1918
className,
2019
loading_state,
2120
setProps,
2221
interval,
22+
active_index = 0,
23+
controls = true,
24+
indicators = true,
2325
...otherProps
2426
} = props;
2527

@@ -81,10 +83,7 @@ const Carousel = props => {
8183
);
8284
};
8385

84-
Carousel.defaultProps = {
85-
active_index: 0,
86-
controls: true,
87-
indicators: true,
86+
Carousel.dashPersistence = {
8887
persisted_props: ['active_index'],
8988
persistence_type: 'local'
9089
};

src/components/collapse/Collapse.js

+33-30
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,39 @@ import RBCollapse from 'react-bootstrap/Collapse';
88
* children is controlled by the `is_open` prop which can be targetted by
99
* callbacks.
1010
*/
11-
const Collapse = React.forwardRef((props, ref) => {
12-
const {
13-
children,
14-
is_open,
15-
navbar,
16-
loading_state,
17-
className,
18-
class_name,
19-
tag,
20-
...otherProps
21-
} = props;
22-
23-
return (
24-
<RBCollapse
25-
in={is_open}
26-
as={tag}
27-
className={class_name || className}
28-
{...omit(['setProps'], otherProps)}
29-
data-dash-is-loading={
30-
(loading_state && loading_state.is_loading) || undefined
31-
}
32-
>
33-
<div ref={ref} className={navbar && 'navbar-collapse'}>
34-
{children}
35-
</div>
36-
</RBCollapse>
37-
);
38-
});
39-
40-
Collapse.defaultProps = {dimension: 'height'};
11+
const Collapse = React.forwardRef(
12+
(
13+
{
14+
children,
15+
is_open,
16+
navbar,
17+
loading_state,
18+
className,
19+
class_name,
20+
tag,
21+
dimension = 'height',
22+
...otherProps
23+
},
24+
ref
25+
) => {
26+
return (
27+
<RBCollapse
28+
in={is_open}
29+
as={tag}
30+
className={class_name || className}
31+
dimension={dimension}
32+
{...omit(['setProps'], otherProps)}
33+
data-dash-is-loading={
34+
(loading_state && loading_state.is_loading) || undefined
35+
}
36+
>
37+
<div ref={ref} className={navbar && 'navbar-collapse'}>
38+
{children}
39+
</div>
40+
</RBCollapse>
41+
);
42+
}
43+
);
4144

4245
Collapse.propTypes = {
4346
/**

src/components/dropdownmenu/DropdownMenu.js

+23-31
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,29 @@ import DropdownToggle from '../../private/DropdownToggle';
1414
* DropdownMenu creates an overlay useful for grouping together links and other
1515
* content to organise navigation or other interactive elements.
1616
*/
17-
const DropdownMenu = props => {
18-
const {
19-
children,
20-
nav,
21-
label,
22-
disabled,
23-
caret,
24-
in_navbar,
25-
addon_type,
26-
size,
27-
right,
28-
align_end,
29-
menu_variant,
30-
direction,
31-
loading_state,
32-
color,
33-
group,
34-
toggle_style,
35-
toggleClassName,
36-
toggle_class_name,
37-
className,
38-
class_name,
39-
...otherProps
40-
} = props;
41-
17+
const DropdownMenu = ({
18+
children,
19+
nav,
20+
label,
21+
in_navbar,
22+
addon_type,
23+
size,
24+
right,
25+
align_end,
26+
direction,
27+
loading_state,
28+
color,
29+
group,
30+
toggle_style,
31+
toggleClassName,
32+
toggle_class_name,
33+
className,
34+
class_name,
35+
caret = true,
36+
disabled = false,
37+
menu_variant = 'light',
38+
...otherProps
39+
}) => {
4240
const [dropdownOpen, setDropdownOpen] = useState(false);
4341
const isBootstrapColor = bootstrapColors.has(color) || color === 'link';
4442
const toggle = () => {
@@ -105,12 +103,6 @@ const DropdownMenu = props => {
105103
);
106104
};
107105

108-
DropdownMenu.defaultProps = {
109-
caret: true,
110-
disabled: false,
111-
menu_variant: 'light'
112-
};
113-
114106
DropdownMenu.propTypes = {
115107
/**
116108
* The ID of this component, used to identify dash components

0 commit comments

Comments
 (0)