about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/composer/textarea/suggestions/index.js
blob: dc72585f21ecd72c81686707b34155f81e14960f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//  Package imports.
import PropTypes from 'prop-types';
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';

//  Components.
import ComposerTextareaSuggestionsItem from './item';

//  The component.
export default function ComposerTextareaSuggestions ({
  hidden,
  onSuggestionClick,
  suggestions,
  value,
}) {

  //  The result.
  return (
    <div
      className='composer--textarea--suggestions'
      hidden={hidden || !suggestions || suggestions.isEmpty()}
    >
      {!hidden && suggestions ? suggestions.map(
        (suggestion, index) => (
          <ComposerTextareaSuggestionsItem
            index={index}
            key={typeof suggestion === 'object' ? suggestion.id : suggestion}
            onClick={onSuggestionClick}
            selected={index === value}
            suggestion={suggestion}
          />
        )
      ) : null}
    </div>
  );
}

ComposerTextareaSuggestions.propTypes = {
  hidden: PropTypes.bool,
  onSuggestionClick: PropTypes.func,
  suggestions: ImmutablePropTypes.list,
  value: PropTypes.number,
};