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
|
import { useMemo } from 'react'
import PropTypes from 'prop-types'
import * as keyPropTypes from './keyPropTypes'
import styles from './styles.module.css'
import Icon from '../../Common/Icon'
function NullKey() {
return <span>⦸</span>
}
function KeyValue(props) {
const { param, index, value, source, onSelect } = props
const title = source && `(${source.code}) ${source.description}`
const text = source && (source?.symbol || source?.code)
const icon = source?.faIcon && <Icon name={source.faIcon} />
const handleClick = useMemo(() => function (event) {
event.stopPropagation()
onSelect({
target: event.target,
codeIndex: index,
code: value,
param
})
}, [param, value, index, onSelect])
return (
<span
className={styles.code}
title={title}
onClick={handleClick}
>
{icon || text || <NullKey />}
</span>
)
}
KeyValue.propTypes = {
index: PropTypes.number.isRequired,
param: keyPropTypes.param.isRequired,
value: keyPropTypes.value.isRequired,
source: keyPropTypes.source,
onSelect: PropTypes.func.isRequired
}
export default KeyValue
|