|
1 |
| -import React, {Component} from 'react'; |
| 1 | +/* eslint-disable no-unused-vars */ |
| 2 | +import React from 'react'; |
2 | 3 | import PropTypes from 'prop-types';
|
3 | 4 | import {pick} from 'ramda';
|
4 | 5 |
|
@@ -34,44 +35,42 @@ const textAreaProps = [
|
34 | 35 | * A basic HTML textarea for entering multiline text.
|
35 | 36 | *
|
36 | 37 | */
|
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 | + ); |
75 | 74 | };
|
76 | 75 |
|
77 | 76 | Textarea.propTypes = {
|
@@ -250,24 +249,6 @@ Textarea.propTypes = {
|
250 | 249 | */
|
251 | 250 | setProps: PropTypes.func,
|
252 | 251 |
|
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 |
| - |
271 | 252 | /**
|
272 | 253 | * Used to allow user interactions in this component to be persisted when
|
273 | 254 | * the component - or the page - is refreshed. If `persisted` is truthy and
|
|
0 commit comments