Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. import React, { useContext, useState } from 'react'
  2. import PropTypes from 'prop-types'
  3. import style from './SwitcherEditDeck.scss'
  4. import { MobileContext } from '../container/App'
  5.  
  6. const SwitcherEditDeck = ({ btns, onClick, value }) => {
  7. const isMobile = useContext(MobileContext)
  8. const [tooltipVisible, setTooltipVisible] = useState(null)
  9. return <div className={style.wrap_all}>
  10. {btns.map((btn, i) => {
  11. const isValue = btn.id === 'off' ? value === 'none' : btn.id === value
  12. return <div
  13. key={btn.id}
  14. className={style.wrap}
  15. >
  16. <div
  17. aria-checked={isValue}
  18. className={isValue ? style[`select_${btn.id}`] : style[`main_${btn.id}`]}
  19. role={'checkbox'}
  20. tabIndex={0}
  21. onClick={() => onClick(btn.id)}
  22. onKeyDown={(e) => e.key === 'Enter' && onClick(btn.id)}
  23. onMouseEnter={() => {
  24. setTooltipVisible(i)
  25. }}
  26. onMouseLeave={() => {
  27. setTooltipVisible(null)
  28. }}
  29. />
  30. {(!isMobile && tooltipVisible === i) && (<span
  31. className={style.tooltip}
  32. style={{ 'width': `${btn.width}px` }}
  33. >{btn.label}</span>)}
  34. </div>
  35. })}
  36. </div>
  37. }
  38.  
  39. SwitcherEditDeck.propTypes = {
  40. btns: PropTypes.arrayOf(
  41. PropTypes.shape({
  42. id: PropTypes.string,
  43. label: PropTypes.string,
  44. width: PropTypes.string
  45. })
  46. ),
  47. value: PropTypes.string,
  48. onClick: PropTypes.func()
  49. }
  50.  
  51. export default React.memo(SwitcherEditDeck)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement