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'
|
2021-06-21 21:35:28 +00:00
|
|
|
import React, { useRef } from 'react'
|
2021-06-02 11:50:34 +00:00
|
|
|
import state, { useSelector } from 'state'
|
2021-06-29 14:58:27 +00:00
|
|
|
import { X } from 'react-feather'
|
2021-06-28 12:13:34 +00:00
|
|
|
import { breakpoints, IconButton } from 'components/shared'
|
2021-06-02 11:50:34 +00:00
|
|
|
import * as Panel from '../panel'
|
|
|
|
import Control from './control'
|
2021-06-24 08:18:14 +00:00
|
|
|
import { deepCompareArrays } from 'utils'
|
2021-05-17 10:01:11 +00:00
|
|
|
|
2021-06-29 14:58:27 +00:00
|
|
|
function handleClose() {
|
|
|
|
state.send('CLOSED_CONTROLS')
|
2021-06-28 12:13:34 +00:00
|
|
|
}
|
|
|
|
|
2021-06-27 19:53:47 +00:00
|
|
|
const stopKeyboardPropagation = (e: KeyboardEvent | React.KeyboardEvent) =>
|
|
|
|
e.stopPropagation()
|
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
export default function ControlPanel(): JSX.Element {
|
2021-05-17 10:01:11 +00:00
|
|
|
const rContainer = useRef<HTMLDivElement>(null)
|
2021-06-28 12:13:34 +00:00
|
|
|
const isOpen = useSelector((s) => Object.keys(s.data.codeControls).length > 0)
|
2021-06-29 14:58:27 +00:00
|
|
|
|
2021-05-17 10:01:11 +00:00
|
|
|
const codeControls = useSelector(
|
|
|
|
(state) => Object.keys(state.data.codeControls),
|
|
|
|
deepCompareArrays
|
|
|
|
)
|
|
|
|
|
2021-06-29 14:58:27 +00:00
|
|
|
if (codeControls.length === 0) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2021-05-17 10:01:11 +00:00
|
|
|
return (
|
2021-06-25 10:28:52 +00:00
|
|
|
<Panel.Root
|
2021-06-28 12:13:34 +00:00
|
|
|
ref={rContainer}
|
2021-06-27 19:19:57 +00:00
|
|
|
dir="ltr"
|
2021-06-25 10:28:52 +00:00
|
|
|
data-bp-desktop
|
|
|
|
variant="controls"
|
2021-06-28 12:13:34 +00:00
|
|
|
isOpen={isOpen}
|
2021-06-27 19:53:47 +00:00
|
|
|
onKeyDown={stopKeyboardPropagation}
|
|
|
|
onKeyUp={stopKeyboardPropagation}
|
2021-06-25 10:28:52 +00:00
|
|
|
>
|
2021-06-29 14:58:27 +00:00
|
|
|
<Panel.Layout>
|
|
|
|
<Panel.Header>
|
|
|
|
<IconButton bp={breakpoints} size="small" onClick={handleClose}>
|
|
|
|
<X />
|
|
|
|
</IconButton>
|
|
|
|
<h3>Controls</h3>
|
|
|
|
</Panel.Header>
|
|
|
|
<ControlsList>
|
|
|
|
{codeControls.map((id) => (
|
|
|
|
<Control key={id} id={id} />
|
|
|
|
))}
|
|
|
|
</ControlsList>
|
|
|
|
</Panel.Layout>
|
2021-05-17 10:01:11 +00:00
|
|
|
</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
|
|
|
},
|
|
|
|
})
|