aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/src/Keyboard/Keys/KeyValue.js
blob: 7aea9670707060e3bd37c4ca57baaa8d9297d141 (plain)
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
import { useMemo } from 'react'

import Icon from '../../Common/Icon'
import styles from './styles.module.css'

function NullKey() {
  return <span>⦸</span>
}

export default function KeyValue(props) {
  const { param, index, value, source, onSelect } = props
  const title = source && `(${source.code}) ${source.description}`
  const text = source && <span>{source?.symbol || source?.code}</span>
  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>
  )
}