about summary refs log tree commit diff
path: root/src/view/com/composer/autocomplete/Autocomplete.web.tsx
blob: b6be1c21e41acbee20962285117cd6d3dac35330 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React from 'react'
import {TouchableOpacity, StyleSheet, View} from 'react-native'
import {usePalette} from 'lib/hooks/usePalette'
import {Text} from '../../util/text/Text'

interface AutocompleteItem {
  handle: string
  displayName?: string
}

export function Autocomplete({
  active,
  items,
  onSelect,
}: {
  active: boolean
  items: AutocompleteItem[]
  onSelect: (item: string) => void
}) {
  const pal = usePalette('default')

  if (!active) {
    return <View />
  }
  return (
    <View style={[styles.outer, pal.view, pal.border]}>
      {items.map((item, i) => (
        <TouchableOpacity
          testID="autocompleteButton"
          key={i}
          style={[pal.border, styles.item]}
          onPress={() => onSelect(item.handle)}>
          <Text type="md-medium" style={pal.text}>
            {item.displayName || item.handle}
            <Text type="sm" style={pal.textLight}>
              &nbsp;@{item.handle}
            </Text>
          </Text>
        </TouchableOpacity>
      ))}
    </View>
  )
}

const styles = StyleSheet.create({
  outer: {
    position: 'absolute',
    left: 0,
    right: 0,
    top: '100%',
    borderWidth: 1,
    borderRadius: 8,
  },
  item: {
    borderBottomWidth: 1,
    paddingVertical: 16,
    paddingHorizontal: 16,
  },
})