Updated AutosuggestTextbox suggestions

• Updated:
- AutosuggestTextbox suggestions

• Removed:
- Hashtag auto suggestions
- BG Primary color on AutosuggestAccount, AutosuggestEmoji
This commit is contained in:
mgabdev 2020-06-15 23:16:43 -04:00
parent 3570ada5b7
commit d452fb5222
3 changed files with 15 additions and 31 deletions

View File

@ -27,7 +27,7 @@ class AutosuggestAccount extends ImmutablePureComponent {
return ( return (
<div <div
className={[_s.default, _s.cursorPointer, _s.bgSubtle_onHover, _s.bgPrimary, _s.flexRow, _s.py10, _s.alignItemsCenter, _s.px10, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')} className={[_s.default, _s.cursorPointer, _s.bgSubtle_onHover, _s.flexRow, _s.py10, _s.alignItemsCenter, _s.px10, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}
title={account.get('acct')} title={account.get('acct')}
> >
<Avatar account={account} size={26} /> <Avatar account={account} size={26} />

View File

@ -24,7 +24,7 @@ export default class AutosuggestEmoji extends PureComponent {
} }
return ( return (
<div className={[_s.default, _s.cursorPointer, _s.bgSubtle_onHover, _s.bgPrimary, _s.flexRow, _s.py10, _s.alignItemsCenter, _s.px10, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}> <div className={[_s.default, _s.cursorPointer, _s.bgSubtle_onHover, _s.flexRow, _s.py10, _s.alignItemsCenter, _s.px10, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
<img className='emojione' src={url} alt={emoji.native || emoji.colons} /> <img className='emojione' src={url} alt={emoji.native || emoji.colons} />
<Text className={_s.ml10}> <Text className={_s.ml10}>
{emoji.colons} {emoji.colons}

View File

@ -1,9 +1,9 @@
import { Fragment } from 'react' import { Fragment } from 'react'
import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePropTypes from 'react-immutable-proptypes'
import isObject from 'lodash.isobject' import isObject from 'lodash.isobject'
import classNames from 'classnames/bind'
import ImmutablePureComponent from 'react-immutable-pure-component' import ImmutablePureComponent from 'react-immutable-pure-component'
import Textarea from 'react-textarea-autosize' import Textarea from 'react-textarea-autosize'
import { CX } from '../constants'
import { isRtl } from '../utils/rtl' import { isRtl } from '../utils/rtl'
import { textAtCursorMatchesToken } from '../utils/cursor_token_match' import { textAtCursorMatchesToken } from '../utils/cursor_token_match'
import AutosuggestAccount from './autosuggest_account' import AutosuggestAccount from './autosuggest_account'
@ -11,8 +11,6 @@ import AutosuggestEmoji from './autosuggest_emoji'
import Input from './input' import Input from './input'
import Composer from './composer' import Composer from './composer'
const cx = classNames.bind(_s)
export default class AutosuggestTextbox extends ImmutablePureComponent { export default class AutosuggestTextbox extends ImmutablePureComponent {
static propTypes = { static propTypes = {
@ -26,23 +24,17 @@ export default class AutosuggestTextbox extends ImmutablePureComponent {
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
onKeyUp: PropTypes.func, onKeyUp: PropTypes.func,
onKeyDown: PropTypes.func, onKeyDown: PropTypes.func,
autoFocus: PropTypes.bool,
className: PropTypes.string,
id: PropTypes.string, id: PropTypes.string,
searchTokens: PropTypes.arrayOf(PropTypes.string), searchTokens: PropTypes.arrayOf(PropTypes.string),
maxLength: PropTypes.number,
onPaste: PropTypes.func, onPaste: PropTypes.func,
onFocus: PropTypes.func, onFocus: PropTypes.func,
onBlur: PropTypes.func, onBlur: PropTypes.func,
textarea: PropTypes.bool, textarea: PropTypes.bool,
small: PropTypes.bool, small: PropTypes.bool,
prependIcon: PropTypes.string,
} }
static defaultProps = { static defaultProps = {
autoFocus: true, searchTokens: ['@', ':'],
searchTokens: ['@', ':', '#'],
textarea: false,
} }
state = { state = {
@ -65,8 +57,6 @@ export default class AutosuggestTextbox extends ImmutablePureComponent {
const [ tokenStart, token ] = textAtCursorMatchesToken(e.target.value, e.target.selectionStart, this.props.searchTokens); const [ tokenStart, token ] = textAtCursorMatchesToken(e.target.value, e.target.selectionStart, this.props.searchTokens);
// console.log('onChange', e.target.value, e.target, this.textbox, tokenStart, token)
if (token !== null && this.state.lastToken !== token) { if (token !== null && this.state.lastToken !== token) {
this.setState({ lastToken: token, selectedSuggestion: 0, tokenStart }); this.setState({ lastToken: token, selectedSuggestion: 0, tokenStart });
this.props.onSuggestionsFetchRequested(token); this.props.onSuggestionsFetchRequested(token);
@ -175,17 +165,16 @@ export default class AutosuggestTextbox extends ImmutablePureComponent {
if (typeof suggestion === 'object') { if (typeof suggestion === 'object') {
inner = <AutosuggestEmoji emoji={suggestion} />; inner = <AutosuggestEmoji emoji={suggestion} />;
key = suggestion.id; key = suggestion.id;
} else if (suggestion[0] === '#') {
inner = suggestion;
key = suggestion;
} else { } else {
inner = <AutosuggestAccount id={suggestion} />; inner = <AutosuggestAccount id={suggestion} />;
key = suggestion; key = suggestion;
} }
const classes = classNames('autosuggest-textarea__suggestions__item', { const isSelected = i === selectedSuggestion
selected: i === selectedSuggestion, const classes = CX({
}); bgPrimary: !isSelected,
bgSubtle: isSelected,
})
return ( return (
<div <div
@ -213,13 +202,8 @@ export default class AutosuggestTextbox extends ImmutablePureComponent {
disabled, disabled,
placeholder, placeholder,
onKeyUp, onKeyUp,
autoFocus,
children, children,
className,
id, id,
maxLength,
textarea,
prependIcon,
} = this.props } = this.props
const { suggestionsHidden } = this.state const { suggestionsHidden } = this.state
@ -227,7 +211,7 @@ export default class AutosuggestTextbox extends ImmutablePureComponent {
direction: isRtl(value) ? 'rtl' : 'ltr', direction: isRtl(value) ? 'rtl' : 'ltr',
} }
const textareaClasses = cx({ const textareaClasses = CX({
default: 1, default: 1,
font: 1, font: 1,
wrap: 1, wrap: 1,
@ -248,7 +232,7 @@ export default class AutosuggestTextbox extends ImmutablePureComponent {
heightMin80PX: !small, heightMin80PX: !small,
}) })
const textareaContainerClasses = cx({ const textareaContainerClasses = CX({
default: 1, default: 1,
maxWidth100PC: 1, maxWidth100PC: 1,
flexGrow1: small, flexGrow1: small,
@ -297,12 +281,12 @@ export default class AutosuggestTextbox extends ImmutablePureComponent {
{children} {children}
</div> </div>
{ /* : todo : put in popover */ } {
<div className='autosuggest-textarea__suggestions-wrapper'> !small && !suggestionsHidden && !suggestions.isEmpty() &&
<div className={`autosuggest-textarea__suggestions ${suggestionsHidden || suggestions.isEmpty() ? '' : 'autosuggest-textarea__suggestions--visible'}`}> <div className={[_s.default].join(' ')}>
{suggestions.map(this.renderSuggestion)} {suggestions.map(this.renderSuggestion)}
</div> </div>
</div> }
</Fragment> </Fragment>
) )
} }