-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTechnologyPicker.js
108 lines (102 loc) · 3.05 KB
/
TechnologyPicker.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React, { useState } from 'react'
import {
Autocomplete,
AutocompleteItem,
Button,
ButtonGroup,
Icon,
Layout,
StyleService,
Text,
} from '@ui-kitten/components'
import technologyIcons from '../data/technologies.json'
import { View } from 'react-native'
const StarIcon = <Icon name="star" />
const BulbIcon = <Icon name="bulb" />
const RemoveIcon = <Icon name="close" />
const AwardIcon = <Icon name="award" />
export const TechnologyPicker = ({ technologies, onChange, style }) => {
const [newCompetence, setNewCompetence] = useState()
const onSelect = (index) => {
const selected = Object.keys(technologyIcons)[index]
onChange({ ...technologies, [selected]: true })
setNewCompetence('')
}
const onBlur = () => {
if (!newCompetence) return
onChange({ ...technologies, [newCompetence]: true })
setNewCompetence('')
}
return (
<>
<Autocomplete
placeholder="Ange nödvändig teknikkompetens"
style={style}
value={newCompetence}
onSelect={onSelect}
onChangeText={setNewCompetence}
onBlur={onBlur}
>
{Object.entries(technologyIcons).map(([title, icon], i) => (
<AutocompleteItem
accessoryLeft={<Icon name={icon} />}
key={i}
title={title}
/>
))}
</Autocomplete>
<Layout style={styles.grid}>
{Object.entries(technologies)
.filter(([, val]) => val)
.map(([key]) => (
<View>
<Text>{key}</Text>
<ButtonGroup style={styles.gridItem} size="small">
<Button
accessoryLeft={RemoveIcon}
onPress={() =>
onChange({ ...technologies, [key]: 0 })
}
>{RemoveIcon}</Button>
<Button
accessoryLeft={BulbIcon}
appearance={technologies[key] === 5 ? 'filled' : 'outline'}
disabled={technologies[key] === 1}
onPress={() => onChange({ ...technologies, [key]: 1 })}
>
1 år
</Button>
<Button
appearance={technologies[key] === 5 ? 'filled' : 'outline'}
disabled={technologies[key] === 3}
onPress={() => onChange({ ...technologies, [key]: 3 })}
>
3 år
</Button>
<Button
accessoryLeft={AwardIcon}
status="danger"
appearance={technologies[key] === 5 ? 'filled' : 'outline'}
disabled={technologies[key] === 5}
onPress={() => onChange({ ...technologies, [key]: 5 })}
>
>5 år
</Button>
</ButtonGroup>
</View>
))}
</Layout>
</>
)
}
const styles = StyleService.create({
grid: {
flexDirection: 'column',
marginHorizontal: 16,
flex: 1,
},
gridItem: {
marginVertical: 8,
height: 40,
},
})