You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

controls-panel.tsx 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* eslint-disable @typescript-eslint/ban-ts-comment */
  2. import styled from 'styles'
  3. import React, { useRef } from 'react'
  4. import state, { useSelector } from 'state'
  5. import { X, Code } from 'react-feather'
  6. import { IconButton } from 'components/shared'
  7. import * as Panel from '../panel'
  8. import Control from './control'
  9. import { deepCompareArrays } from 'utils'
  10. export default function ControlPanel(): JSX.Element {
  11. const rContainer = useRef<HTMLDivElement>(null)
  12. const codeControls = useSelector(
  13. (state) => Object.keys(state.data.codeControls),
  14. deepCompareArrays
  15. )
  16. const isOpen = useSelector((s) => Object.keys(s.data.codeControls).length > 0)
  17. return (
  18. <Panel.Root data-bp-desktop ref={rContainer} isOpen={isOpen}>
  19. {isOpen ? (
  20. <Panel.Layout>
  21. <Panel.Header>
  22. <IconButton
  23. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  24. size="small"
  25. onClick={() => state.send('CLOSED_CODE_PANEL')}
  26. >
  27. <X />
  28. </IconButton>
  29. <h3>Controls</h3>
  30. </Panel.Header>
  31. <ControlsList>
  32. {codeControls.map((id) => (
  33. <Control key={id} id={id} />
  34. ))}
  35. </ControlsList>
  36. </Panel.Layout>
  37. ) : (
  38. <IconButton
  39. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  40. size="small"
  41. onClick={() => state.send('OPENED_CODE_PANEL')}
  42. >
  43. <Code />
  44. </IconButton>
  45. )}
  46. </Panel.Root>
  47. )
  48. }
  49. const ControlsList = styled(Panel.Content, {
  50. padding: 12,
  51. display: 'grid',
  52. gridTemplateColumns: '1fr 4fr',
  53. gridAutoRows: '24px',
  54. alignItems: 'center',
  55. gridColumnGap: '8px',
  56. gridRowGap: '8px',
  57. '& input': {
  58. font: '$ui',
  59. fontSize: '$1',
  60. border: '1px solid $inputBorder',
  61. backgroundColor: '$input',
  62. color: '$text',
  63. height: '100%',
  64. padding: '0px 6px',
  65. },
  66. })