2021-05-17 10:01:11 +00:00
|
|
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
2021-06-02 11:50:34 +00:00
|
|
|
import styled from 'styles'
|
|
|
|
import React, { useEffect, useRef } from 'react'
|
|
|
|
import state, { useSelector } from 'state'
|
|
|
|
import { X, Code, PlayCircle } from 'react-feather'
|
|
|
|
import { IconButton } from 'components/shared'
|
|
|
|
import * as Panel from '../panel'
|
|
|
|
import Control from './control'
|
|
|
|
import { deepCompareArrays } from 'utils/utils'
|
2021-05-17 10:01:11 +00:00
|
|
|
|
|
|
|
export default function ControlPanel() {
|
|
|
|
const rContainer = useRef<HTMLDivElement>(null)
|
|
|
|
const codeControls = useSelector(
|
|
|
|
(state) => Object.keys(state.data.codeControls),
|
|
|
|
deepCompareArrays
|
|
|
|
)
|
2021-05-17 21:27:18 +00:00
|
|
|
const isOpen = useSelector((s) => Object.keys(s.data.codeControls).length > 0)
|
2021-05-17 10:01:11 +00:00
|
|
|
|
|
|
|
return (
|
2021-05-17 21:27:18 +00:00
|
|
|
<Panel.Root data-bp-desktop ref={rContainer} isOpen={isOpen}>
|
2021-05-17 10:01:11 +00:00
|
|
|
{isOpen ? (
|
|
|
|
<Panel.Layout>
|
|
|
|
<Panel.Header>
|
2021-06-02 11:50:34 +00:00
|
|
|
<IconButton
|
2021-06-03 16:13:23 +00:00
|
|
|
bp={{ '@initial': 'mobile', '@sm': 'small' }}
|
2021-06-02 11:50:34 +00:00
|
|
|
size="small"
|
|
|
|
onClick={() => state.send('CLOSED_CODE_PANEL')}
|
|
|
|
>
|
2021-05-17 10:01:11 +00:00
|
|
|
<X />
|
|
|
|
</IconButton>
|
|
|
|
<h3>Controls</h3>
|
|
|
|
</Panel.Header>
|
|
|
|
<ControlsList>
|
|
|
|
{codeControls.map((id) => (
|
|
|
|
<Control key={id} id={id} />
|
|
|
|
))}
|
|
|
|
</ControlsList>
|
|
|
|
</Panel.Layout>
|
|
|
|
) : (
|
2021-06-02 11:50:34 +00:00
|
|
|
<IconButton
|
2021-06-03 16:13:23 +00:00
|
|
|
bp={{ '@initial': 'mobile', '@sm': 'small' }}
|
2021-06-02 11:50:34 +00:00
|
|
|
size="small"
|
|
|
|
onClick={() => state.send('OPENED_CODE_PANEL')}
|
|
|
|
>
|
2021-05-17 10:01:11 +00:00
|
|
|
<Code />
|
|
|
|
</IconButton>
|
|
|
|
)}
|
|
|
|
</Panel.Root>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const ControlsList = styled(Panel.Content, {
|
|
|
|
padding: 12,
|
2021-06-02 11:50:34 +00:00
|
|
|
display: 'grid',
|
|
|
|
gridTemplateColumns: '1fr 4fr',
|
|
|
|
gridAutoRows: '24px',
|
|
|
|
alignItems: 'center',
|
|
|
|
gridColumnGap: '8px',
|
|
|
|
gridRowGap: '8px',
|
2021-05-17 10:01:11 +00:00
|
|
|
|
2021-06-02 11:50:34 +00:00
|
|
|
'& input': {
|
|
|
|
font: '$ui',
|
|
|
|
fontSize: '$1',
|
|
|
|
border: '1px solid $inputBorder',
|
|
|
|
backgroundColor: '$input',
|
|
|
|
color: '$text',
|
|
|
|
height: '100%',
|
|
|
|
padding: '0px 6px',
|
2021-05-17 10:01:11 +00:00
|
|
|
},
|
|
|
|
})
|