Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default props #2926

Merged
merged 13 commits into from
Nov 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ import {TypescriptComponentProps} from '../props';
/**
* Component docstring
*/
const TypeScriptComponent = (props: TypescriptComponentProps) => {
const {required_string, id} = props;
return <div id={id}>{required_string}</div>;
};

TypeScriptComponent.defaultProps = {
string_default: 'default',
number_default: 42,
bool_default: true,
null_default: null,
obj_default: {
a: 'a',
b: 3
}
const TypeScriptComponent = ({
required_string,
id,
string_default = 'default',
number_default = 42,
bool_default = true,
null_default = null,
obj_default = { a: 'a', b: 3 },
...props
}: TypescriptComponentProps) => {
return <div id={id}>{required_string}</div>;
};

export default TypeScriptComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type TypescriptComponentProps = {
array_elements?: JSX.Element[];

string_default?: string;
number_default?: string;
number_default?: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems kind of important :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to get tests to pass, but @T4rk1n can you confirm if this is OK?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is the good type.

obj_default?: {a: string; b: number};
bool_default?: boolean;
null_default?: any;
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- [#3025](https://github.com/plotly/dash/pull/3025) Fix no output callback with error handler setting the response to NoUpdate and triggering an error.
- [#3034](https://github.com/plotly/dash/pull/3034) Remove whitespace from `metadata.json` files to reduce package size.
- [#3009](https://github.com/plotly/dash/pull/3009) Performance improvement on (pattern-matching) callbacks.
- [3028](https://github.com/plotly/dash/pull/3028) Fix jupyterlab v4 support.
- [#3028](https://github.com/plotly/dash/pull/3028) Fix jupyterlab v4 support.
- [#2926](https://github.com/plotly/dash/pull/2926) Fix components defaultProps with react 18.3.1
- [#3051](https://github.com/plotly/dash/pull/3051) Add missing request data to callback context. Fix [#2235](https://github.com/plotly/dash/issues/2235).

## [2.18.1] - 2024-09-12
Expand Down
3 changes: 2 additions & 1 deletion components/dash-core-components/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"react",
"import"
],
"parser": "@babel/eslint-parser",
"rules": {
"accessor-pairs": ["error"],
"block-scoped-var": ["error"],
Expand All @@ -43,7 +44,7 @@
"import/named": ["off"],
"import/namespace": ["off"],
"import/no-duplicates": ["error"],
"import/no-named-as-default": ["error"],
"import/no-named-as-default": ["off"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies, but can you please explain what the impact of this one will be?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a linting that conflicted with the default notation on param functions.

"import/no-unresolved": ["off"],
"new-cap": ["error", {
"capIsNewExceptionPattern": "Immutable\\.*"
Expand Down
105 changes: 105 additions & 0 deletions components/dash-core-components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/dash-core-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"devDependencies": {
"@babel/cli": "^7.25.7",
"@babel/core": "^7.25.8",
"@babel/eslint-parser": "^7.25.8",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.25.8",
"@babel/preset-react": "^7.25.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CustomEvent.prototype = window.Event.prototype;
* For links with destinations outside the current app, `html.A` is a better
* component to use.
*/
const Link = props => {
const Link = ({refresh = false, ...props}) => {
const {
className,
style,
Expand All @@ -42,7 +42,6 @@ const Link = props => {
children,
title,
target,
refresh,
setProps,
} = props;
const cleanUrl = window.dash_clientside.clean_url;
Expand Down Expand Up @@ -155,7 +154,4 @@ Link.propTypes = {
setProps: PropTypes.func,
};

Link.defaultProps = {
refresh: false,
};
export default Link;
19 changes: 5 additions & 14 deletions components/dash-core-components/src/components/Loading.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const getSpinner = spinnerType =>
const Loading = ({
children,
loading_state,
display,
color,
display = 'auto',
color = '#119DFF',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have colors and other constants scattered elsewhere through the code as well or is there a way to consolidate them all in one place? (very low priority, not worth holding up this PR for)

id,
className,
style,
Expand All @@ -32,10 +32,10 @@ const Loading = ({
overlay_style,
fullscreen,
debug,
show_initially,
show_initially = true,
type: spinnerType,
delay_hide,
delay_show,
delay_hide = 0,
delay_show = 0,
target_components,
custom_spinner,
}) => {
Expand Down Expand Up @@ -164,15 +164,6 @@ const Loading = ({

Loading._dashprivate_isLoadingComponent = true;

Loading.defaultProps = {
type: 'default',
color: '#119DFF',
delay_show: 0,
delay_hide: 0,
show_initially: true,
display: 'auto',
};

Loading.propTypes = {
/**
* The ID of this component, used to identify dash components
Expand Down
19 changes: 11 additions & 8 deletions components/dash-core-components/src/components/Tab.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ import PropTypes from 'prop-types';
* Part of dcc.Tabs - this is the child Tab component used to render a tabbed page.
* Its children will be set as the content of that tab, which if clicked will become visible.
*/
const Tab = ({children}) => <Fragment>{children}</Fragment>;

/* eslint-disable no-unused-vars */
const Tab = ({
children,
disabled = false,
disabled_style = {color: '#d6d6d6'},
}) => <Fragment>{children}</Fragment>;
/* eslint-enable no-unused-vars */

// Default props are defined above for proper docstring generation in React 18.
// The actual default values are set in Tabs.react.js.

Tab.propTypes = {
/**
Expand Down Expand Up @@ -84,11 +94,4 @@ Tab.propTypes = {
}),
};

Tab.defaultProps = {
disabled: false,
disabled_style: {
color: '#d6d6d6',
},
};

export default Tab;
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const EnhancedTab = ({
selected_style,
selectHandler,
value,
disabled,
disabled_style,
disabled = false,
disabled_style = {color: '#d6d6d6'},
disabled_className,
mobile_breakpoint,
amountOfTabs,
Expand Down
Loading