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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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
  19. data-bp-desktop
  20. ref={rContainer}
  21. isOpen={isOpen}
  22. variant="controls"
  23. >
  24. {isOpen ? (
  25. <Panel.Layout>
  26. <Panel.Header>
  27. <IconButton
  28. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  29. size="small"
  30. onClick={() => state.send('CLOSED_CODE_PANEL')}
  31. >
  32. <X />
  33. </IconButton>
  34. <h3>Controls</h3>
  35. </Panel.Header>
  36. <ControlsList>
  37. {codeControls.map((id) => (
  38. <Control key={id} id={id} />
  39. ))}
  40. </ControlsList>
  41. </Panel.Layout>
  42. ) : (
  43. <IconButton
  44. bp={{ '@initial': 'mobile', '@sm': 'small' }}
  45. size="small"
  46. onClick={() => state.send('OPENED_CODE_PANEL')}
  47. >
  48. <Code />
  49. </IconButton>
  50. )}
  51. </Panel.Root>
  52. )
  53. }
  54. const ControlsList = styled(Panel.Content, {
  55. padding: 12,
  56. display: 'grid',
  57. gridTemplateColumns: '1fr 4fr',
  58. gridAutoRows: '24px',
  59. alignItems: 'center',
  60. gridColumnGap: '8px',
  61. gridRowGap: '8px',
  62. '& input': {
  63. font: '$ui',
  64. fontSize: '$1',
  65. border: '1px solid $inputBorder',
  66. backgroundColor: '$input',
  67. color: '$text',
  68. height: '100%',
  69. padding: '0px 6px',
  70. },
  71. })