2021-05-28 20:30:27 +00:00
|
|
|
import state, { useSelector } from 'state'
|
2021-07-03 14:09:49 +00:00
|
|
|
import {
|
|
|
|
IconButton,
|
|
|
|
ButtonsRow,
|
2021-07-04 18:45:07 +00:00
|
|
|
breakpoints,
|
2021-07-11 12:51:01 +00:00
|
|
|
RowButton,
|
|
|
|
FloatingContainer,
|
|
|
|
Divider,
|
|
|
|
Kbd,
|
2021-07-03 14:09:49 +00:00
|
|
|
} from 'components/shared'
|
2021-06-28 12:13:34 +00:00
|
|
|
import ShapesFunctions from './shapes-functions'
|
2021-05-28 20:30:27 +00:00
|
|
|
import AlignDistribute from './align-distribute'
|
2021-06-02 11:50:34 +00:00
|
|
|
import QuickColorSelect from './quick-color-select'
|
|
|
|
import QuickSizeSelect from './quick-size-select'
|
2021-07-01 22:11:09 +00:00
|
|
|
import QuickDashSelect from './quick-dash-select'
|
|
|
|
import QuickFillSelect from './quick-fill-select'
|
2021-06-02 21:17:38 +00:00
|
|
|
import Tooltip from 'components/tooltip'
|
2021-07-11 12:51:01 +00:00
|
|
|
import { DotsHorizontalIcon, Cross2Icon } from '@radix-ui/react-icons'
|
|
|
|
import { commandKey, isMobile } from 'utils'
|
2021-05-26 10:34:10 +00:00
|
|
|
|
2021-06-27 19:19:57 +00:00
|
|
|
const handleStylePanelOpen = () => state.send('TOGGLED_STYLE_PANEL_OPEN')
|
2021-07-04 18:45:07 +00:00
|
|
|
const handleCopy = () => state.send('COPIED')
|
|
|
|
const handlePaste = () => state.send('PASTED')
|
|
|
|
const handleCopyToSvg = () => state.send('COPIED_TO_SVG')
|
2021-06-27 19:19:57 +00:00
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
export default function StylePanel(): JSX.Element {
|
2021-05-26 10:34:10 +00:00
|
|
|
const isOpen = useSelector((s) => s.data.settings.isStyleOpen)
|
|
|
|
|
|
|
|
return (
|
2021-07-11 12:51:01 +00:00
|
|
|
<FloatingContainer direction="column">
|
2021-07-01 22:11:09 +00:00
|
|
|
<ButtonsRow>
|
|
|
|
<QuickColorSelect />
|
|
|
|
<QuickSizeSelect />
|
|
|
|
<QuickDashSelect />
|
|
|
|
<QuickFillSelect />
|
|
|
|
<IconButton
|
|
|
|
bp={breakpoints}
|
|
|
|
title="Style"
|
|
|
|
size="small"
|
|
|
|
onClick={handleStylePanelOpen}
|
|
|
|
>
|
2021-07-14 13:45:24 +00:00
|
|
|
<Tooltip label={isOpen ? 'Close' : 'More'}>
|
2021-07-03 14:13:07 +00:00
|
|
|
{isOpen ? <Cross2Icon /> : <DotsHorizontalIcon />}
|
|
|
|
</Tooltip>
|
2021-07-01 22:11:09 +00:00
|
|
|
</IconButton>
|
|
|
|
</ButtonsRow>
|
|
|
|
{isOpen && <SelectedShapeContent />}
|
2021-07-11 12:51:01 +00:00
|
|
|
</FloatingContainer>
|
2021-05-26 10:34:10 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-01 22:11:09 +00:00
|
|
|
function SelectedShapeContent(): JSX.Element {
|
2021-06-28 12:13:34 +00:00
|
|
|
const selectedShapesCount = useSelector((s) => s.values.selectedIds.length)
|
2021-05-26 21:47:46 +00:00
|
|
|
|
2021-07-11 12:51:01 +00:00
|
|
|
const showKbds = !isMobile()
|
|
|
|
|
2021-05-26 10:34:10 +00:00
|
|
|
return (
|
2021-07-01 22:11:09 +00:00
|
|
|
<>
|
2021-07-11 12:51:01 +00:00
|
|
|
<Divider />
|
2021-07-01 22:11:09 +00:00
|
|
|
<ShapesFunctions />
|
2021-07-11 12:51:01 +00:00
|
|
|
<Divider />
|
2021-07-01 22:11:09 +00:00
|
|
|
<AlignDistribute
|
|
|
|
hasTwoOrMore={selectedShapesCount > 1}
|
|
|
|
hasThreeOrMore={selectedShapesCount > 2}
|
|
|
|
/>
|
2021-07-11 12:51:01 +00:00
|
|
|
<Divider />
|
2021-07-03 14:09:49 +00:00
|
|
|
<RowButton
|
|
|
|
bp={breakpoints}
|
|
|
|
disabled={selectedShapesCount === 0}
|
2021-07-04 18:45:07 +00:00
|
|
|
onClick={handleCopy}
|
2021-07-03 14:09:49 +00:00
|
|
|
>
|
|
|
|
<span>Copy</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
{showKbds && (
|
|
|
|
<Kbd>
|
|
|
|
<span>{commandKey()}</span>
|
|
|
|
<span>C</span>
|
|
|
|
</Kbd>
|
|
|
|
)}
|
2021-07-03 14:09:49 +00:00
|
|
|
</RowButton>
|
2021-07-04 18:45:07 +00:00
|
|
|
<RowButton bp={breakpoints} onClick={handlePaste}>
|
2021-07-03 14:09:49 +00:00
|
|
|
<span>Paste</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
{showKbds && (
|
|
|
|
<Kbd>
|
|
|
|
<span>{commandKey()}</span>
|
|
|
|
<span>V</span>
|
|
|
|
</Kbd>
|
|
|
|
)}
|
2021-07-03 14:09:49 +00:00
|
|
|
</RowButton>
|
2021-07-11 12:51:01 +00:00
|
|
|
<RowButton bp={breakpoints} onClick={handleCopyToSvg}>
|
2021-07-03 14:09:49 +00:00
|
|
|
<span>Copy to SVG</span>
|
2021-07-11 12:51:01 +00:00
|
|
|
{showKbds && (
|
|
|
|
<Kbd>
|
|
|
|
<span>⇧</span>
|
|
|
|
<span>{commandKey()}</span>
|
|
|
|
<span>C</span>
|
|
|
|
</Kbd>
|
|
|
|
)}
|
2021-07-03 14:09:49 +00:00
|
|
|
</RowButton>
|
2021-07-01 22:11:09 +00:00
|
|
|
</>
|
2021-05-26 10:34:10 +00:00
|
|
|
)
|
|
|
|
}
|