Skip to content

Commit 2bcb14d

Browse files
committed
Refactor TextArea to functional + new loading
1 parent 5a68ecd commit 2bcb14d

File tree

1 file changed

+38
-57
lines changed

1 file changed

+38
-57
lines changed

components/dash-core-components/src/components/Textarea.react.js

Lines changed: 38 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, {Component} from 'react';
1+
/* eslint-disable no-unused-vars */
2+
import React from 'react';
23
import PropTypes from 'prop-types';
34
import {pick} from 'ramda';
45

@@ -34,44 +35,42 @@ const textAreaProps = [
3435
* A basic HTML textarea for entering multiline text.
3536
*
3637
*/
37-
export default class Textarea extends Component {
38-
render() {
39-
const {setProps, loading_state, value} = this.props;
40-
41-
return (
42-
<textarea
43-
data-dash-is-loading={
44-
(loading_state && loading_state.is_loading) || undefined
45-
}
46-
value={value}
47-
onChange={e => {
48-
setProps({value: e.target.value});
49-
}}
50-
onBlur={() => {
51-
setProps({
52-
n_blur: this.props.n_blur + 1,
53-
n_blur_timestamp: Date.now(),
54-
});
55-
}}
56-
onClick={() => {
57-
setProps({
58-
n_clicks: this.props.n_clicks + 1,
59-
n_clicks_timestamp: Date.now(),
60-
});
61-
}}
62-
{...pick(textAreaProps, this.props)}
63-
/>
64-
);
65-
}
66-
}
67-
68-
Textarea.defaultProps = {
69-
n_blur: 0,
70-
n_blur_timestamp: -1,
71-
n_clicks: 0,
72-
n_clicks_timestamp: -1,
73-
persisted_props: ['value'],
74-
persistence_type: 'local',
38+
const Textarea = ({
39+
setProps,
40+
value,
41+
n_blur = 0,
42+
n_blur_timestamp = -1,
43+
n_clicks,
44+
n_clicks_timestamp = -1,
45+
persisted_props = ['value'],
46+
persistence_type = 'local',
47+
...props
48+
}) => {
49+
const ctx = window.dash_component_api.useDashContext();
50+
const isLoading = ctx.useLoading();
51+
52+
return (
53+
<textarea
54+
data-dash-is-loading={isLoading || undefined}
55+
value={value}
56+
onChange={e => {
57+
setProps({value: e.target.value});
58+
}}
59+
onBlur={() => {
60+
setProps({
61+
n_blur: n_blur + 1,
62+
n_blur_timestamp: Date.now(),
63+
});
64+
}}
65+
onClick={() => {
66+
setProps({
67+
n_clicks: n_clicks + 1,
68+
n_clicks_timestamp: Date.now(),
69+
});
70+
}}
71+
{...pick(textAreaProps, props)}
72+
/>
73+
);
7574
};
7675

7776
Textarea.propTypes = {
@@ -250,24 +249,6 @@ Textarea.propTypes = {
250249
*/
251250
setProps: PropTypes.func,
252251

253-
/**
254-
* Object that holds the loading state object coming from dash-renderer
255-
*/
256-
loading_state: PropTypes.shape({
257-
/**
258-
* Determines if the component is loading or not
259-
*/
260-
is_loading: PropTypes.bool,
261-
/**
262-
* Holds which property is loading
263-
*/
264-
prop_name: PropTypes.string,
265-
/**
266-
* Holds the name of the component that is loading
267-
*/
268-
component_name: PropTypes.string,
269-
}),
270-
271252
/**
272253
* Used to allow user interactions in this component to be persisted when
273254
* the component - or the page - is refreshed. If `persisted` is truthy and

0 commit comments

Comments
 (0)