This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 831
Update autocomplete design and scroll it correctly #419
Merged
ara4n
merged 2 commits into
matrix-org:develop
from
aviraldg:feature-autocomplete-improvements
Aug 24, 2016
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,19 +1,62 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import classNames from 'classnames'; | ||
|
||
export function TextualCompletion({ | ||
title, | ||
subtitle, | ||
description, | ||
}: { | ||
title: ?string, | ||
subtitle: ?string, | ||
description: ?string | ||
}) { | ||
return ( | ||
<div style={{width: '100%'}}> | ||
<span>{title}</span> | ||
<em>{subtitle}</em> | ||
<span style={{color: 'gray', float: 'right'}}>{description}</span> | ||
</div> | ||
); | ||
/* These were earlier stateless functional components but had to be converted | ||
since we need to use refs/findDOMNode to access the underlying DOM node to focus the correct completion, | ||
something that is not entirely possible with stateless functional components. One could | ||
presumably wrap them in a <div> before rendering but I think this is the better way to do it. | ||
*/ | ||
|
||
export class TextualCompletion extends React.Component { | ||
render() { | ||
const { | ||
title, | ||
subtitle, | ||
description, | ||
className, | ||
...restProps, | ||
} = this.props; | ||
return ( | ||
<div className={classNames('mx_Autocomplete_Completion_block', className)} {...restProps}> | ||
<span>{title}</span> | ||
<em style={{flex: 1}}>{subtitle}</em> | ||
<span style={{color: 'gray', float: 'right'}}>{description}</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably belongs in the CSS |
||
</div> | ||
); | ||
} | ||
} | ||
TextualCompletion.propTypes = { | ||
title: React.PropTypes.string, | ||
subtitle: React.PropTypes.string, | ||
description: React.PropTypes.string, | ||
className: React.PropTypes.string, | ||
}; | ||
|
||
export class PillCompletion extends React.Component { | ||
render() { | ||
const { | ||
title, | ||
subtitle, | ||
description, | ||
initialComponent, | ||
className, | ||
...restProps, | ||
} = this.props; | ||
return ( | ||
<div className={classNames('mx_Autocomplete_Completion_pill', className)} {...restProps}> | ||
{initialComponent} | ||
<span>{title}</span> | ||
<em>{subtitle}</em> | ||
<span style={{color: 'gray'}}>{description}</span> | ||
</div> | ||
); | ||
} | ||
} | ||
PillCompletion.propTypes = { | ||
title: React.PropTypes.string, | ||
subtitle: React.PropTypes.string, | ||
description: React.PropTypes.string, | ||
initialComponent: React.PropTypes.element, | ||
className: React.PropTypes.string, | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import React from 'react'; | ||
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'; | ||
import ReactDOM from 'react-dom'; | ||
import classNames from 'classnames'; | ||
import flatMap from 'lodash/flatMap'; | ||
import sdk from '../../../index'; | ||
|
||
import {getCompletions} from '../../../autocomplete/Autocompleter'; | ||
|
||
|
@@ -100,11 +101,26 @@ export default class Autocomplete extends React.Component { | |
this.setState({selectionOffset}); | ||
} | ||
|
||
componentDidUpdate() { | ||
// this is the selected completion, so scroll it into view if needed | ||
const selectedCompletion = this.refs[`completion${this.state.selectionOffset}`]; | ||
if (selectedCompletion && this.container) { | ||
const {offsetTop} = ReactDOM.findDOMNode(selectedCompletion); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me, this syntax feels a bit unnecessary and less clear than |
||
if (offsetTop > this.container.scrollTop + this.container.offsetHeight || | ||
offsetTop < this.container.scrollTop) { | ||
this.container.scrollTop = offsetTop - this.container.offsetTop; | ||
} | ||
} | ||
} | ||
|
||
render() { | ||
const EmojiText = sdk.getComponent('views.elements.EmojiText'); | ||
|
||
let position = 0; | ||
let renderedCompletions = this.state.completions.map((completionResult, i) => { | ||
let completions = completionResult.completions.map((completion, i) => { | ||
let className = classNames('mx_Autocomplete_Completion', { | ||
|
||
const className = classNames('mx_Autocomplete_Completion', { | ||
'selected': position === this.state.selectionOffset, | ||
}); | ||
let componentPosition = position; | ||
|
@@ -116,40 +132,27 @@ export default class Autocomplete extends React.Component { | |
this.onConfirm(); | ||
}; | ||
|
||
return ( | ||
<div key={i} | ||
className={className} | ||
onMouseOver={onMouseOver} | ||
onClick={onClick}> | ||
{completion.component} | ||
</div> | ||
); | ||
return React.cloneElement(completion.component, { | ||
key: i, | ||
ref: `completion${i}`, | ||
className, | ||
onMouseOver, | ||
onClick, | ||
}); | ||
}); | ||
|
||
|
||
return completions.length > 0 ? ( | ||
<div key={i} className="mx_Autocomplete_ProviderSection"> | ||
<span className="mx_Autocomplete_provider_name">{completionResult.provider.getName()}</span> | ||
<ReactCSSTransitionGroup | ||
component="div" | ||
transitionName="autocomplete" | ||
transitionEnterTimeout={300} | ||
transitionLeaveTimeout={300}> | ||
{completions} | ||
</ReactCSSTransitionGroup> | ||
<EmojiText element="div" className="mx_Autocomplete_provider_name">{completionResult.provider.getName()}</EmojiText> | ||
{completionResult.provider.renderCompletions(completions)} | ||
</div> | ||
) : null; | ||
}); | ||
|
||
return ( | ||
<div className="mx_Autocomplete"> | ||
<ReactCSSTransitionGroup | ||
component="div" | ||
transitionName="autocomplete" | ||
transitionEnterTimeout={300} | ||
transitionLeaveTimeout={300}> | ||
{renderedCompletions} | ||
</ReactCSSTransitionGroup> | ||
<div className="mx_Autocomplete" ref={(e) => this.container = e}> | ||
{renderedCompletions} | ||
</div> | ||
); | ||
} | ||
|
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.
Given the superclass function here is taking the array and putting it in a div wrapper, the inheritance here seems a bit redundant, since it's doing this wrapping for the overridden function to clone it, add a class, return that and throw the original away.
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 would agree, in the context that it's a bit of unnecessary OOPism. I do
admit I wrote it this way expecting it would be required later. (If there's
a base structure and each layout needs to customise it a bit.)
On Wed 17 Aug, 2016, 7:26 PM David Baker, notifications@github.com wrote: