-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
dcc redesign: refactor TextArea
and Tooltip
#3468
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
Open
KoolADE85
wants to merge
11
commits into
v4
Choose a base branch
from
feature/dcc-refactor-textarea-tooltip
base: v4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9a9df1f
Implement textarea as typescript
KoolADE85 b05416d
Implement tooltip as tsx
KoolADE85 efe899b
Merge branch 'v4' into feature/dcc-refactor-textarea-tooltip
KoolADE85 24d08bb
Merge branch 'bugfix/dcc-redesign-bugfixes' into feature/dcc-refactor…
KoolADE85 e0e3a60
refactor tooltip
KoolADE85 6bb0f4a
Merge branch 'v4' into feature/dcc-refactor-textarea-tooltip
KoolADE85 0deace3
empty commit for ci
KoolADE85 5d40e68
Merge branch 'v4' into feature/dcc-refactor-textarea-tooltip
KoolADE85 07542a7
Merge branch 'v4' into feature/dcc-refactor-textarea-tooltip
KoolADE85 e8ff7aa
Remove "string" as possible option for some props
KoolADE85 df1fd9d
Merge remote-tracking branch 'refs/remotes/origin/feature/dcc-refacto…
KoolADE85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
287 changes: 0 additions & 287 deletions
287
components/dash-core-components/src/components/Textarea.react.js
This file was deleted.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
components/dash-core-components/src/components/Textarea.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* eslint-disable no-unused-vars */ | ||
import React from 'react'; | ||
import {pick} from 'ramda'; | ||
import {PersistedProps, PersistenceTypes, TextAreaProps} from '../types'; | ||
import './css/textarea.css'; | ||
|
||
const textAreaProps = [ | ||
'id', | ||
'form', | ||
'name', | ||
'placeholder', | ||
'wrap', | ||
'accessKey', | ||
'contextMenu', | ||
'dir', | ||
'draggable', | ||
'lang', | ||
'spellCheck', | ||
'style', | ||
'title', | ||
] as const; | ||
|
||
const asNumber = (value?: string | number): number | undefined => { | ||
return typeof value === 'string' | ||
? isNaN(parseInt(value, 10)) | ||
? undefined | ||
: parseInt(value, 10) | ||
: value; | ||
}; | ||
const asBool = (value?: string | boolean): boolean | undefined => { | ||
if (typeof value === 'string') { | ||
if (['true', 'TRUE', 'True'].includes(value)) { | ||
return true; | ||
} | ||
if (['false', 'FALSE', 'False'].includes(value)) { | ||
return false; | ||
} | ||
return undefined; | ||
} | ||
return value; | ||
}; | ||
|
||
/** | ||
* A basic HTML textarea for entering multiline text. | ||
* | ||
*/ | ||
const Textarea = ({ | ||
setProps, | ||
n_blur = 0, | ||
n_blur_timestamp = -1, | ||
n_clicks = 0, | ||
n_clicks_timestamp = -1, | ||
...props | ||
}: TextAreaProps) => { | ||
const ctx = window.dash_component_api.useDashContext(); | ||
const isLoading = ctx.useLoading(); | ||
|
||
return ( | ||
<textarea | ||
data-dash-is-loading={isLoading || undefined} | ||
className={'dash-textarea ' + props.className} | ||
value={props.value} | ||
cols={asNumber(props.cols)} | ||
rows={asNumber(props.rows)} | ||
disabled={asBool(props.disabled)} | ||
minLength={asNumber(props.minLength)} | ||
maxLength={asNumber(props.maxLength)} | ||
readOnly={asBool(props.readOnly)} | ||
required={asBool(props.required)} | ||
autoFocus={asBool(props.autoFocus)} | ||
contentEditable={asBool(props.contentEditable)} | ||
hidden={asBool(props.hidden)} | ||
tabIndex={asNumber(props.tabIndex)} | ||
onChange={e => { | ||
setProps({value: e.target.value}); | ||
}} | ||
onBlur={() => { | ||
setProps({ | ||
n_blur: n_blur + 1, | ||
n_blur_timestamp: Date.now(), | ||
}); | ||
}} | ||
onClick={() => { | ||
setProps({ | ||
n_clicks: n_clicks + 1, | ||
n_clicks_timestamp: Date.now(), | ||
}); | ||
}} | ||
{...pick(textAreaProps, props)} | ||
/> | ||
); | ||
}; | ||
|
||
Textarea.dashPersistence = { | ||
persisted_props: [PersistedProps.value], | ||
persistence_type: PersistenceTypes.local, | ||
}; | ||
|
||
export default Textarea; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think those conversion are necessary, the props are transfered in json and bool and number. The prop type should be bool or number but the string interpolation makes it harder on the python type check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your idea here, and pushed up a change that removes
string
as an allowed type for these props.However... these existed for API compatibility (the docs say
string
is allowed) so just want you to be aware of the backwards incompatibility that this introduces (especially for numeric props likecols
andmaxLength
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The html textarea cols/maxLength can accept string, but we didn't do the explicit conversion before. I think those props should follow what is in the react props for that html attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we're agreeing here.. Numeric props no longer accept a string value. And that is the current state of this PR.