tldraw/components/style-panel/align-distribute.tsx

156 lines
3.7 KiB
TypeScript
Raw Normal View History

2021-05-26 19:20:52 +00:00
import {
AlignBottomIcon,
AlignCenterHorizontallyIcon,
AlignCenterVerticallyIcon,
AlignLeftIcon,
AlignRightIcon,
AlignTopIcon,
SpaceEvenlyHorizontallyIcon,
SpaceEvenlyVerticallyIcon,
StretchHorizontallyIcon,
StretchVerticallyIcon,
2021-05-28 20:30:27 +00:00
} from '@radix-ui/react-icons'
2021-07-01 22:11:09 +00:00
import { breakpoints, ButtonsRow, IconButton } from 'components/shared'
import { memo } from 'react'
2021-05-28 20:30:27 +00:00
import state from 'state'
import { AlignType, DistributeType, StretchType } from 'types'
2021-05-26 19:20:52 +00:00
function alignTop() {
2021-05-28 20:30:27 +00:00
state.send('ALIGNED', { type: AlignType.Top })
2021-05-26 19:20:52 +00:00
}
function alignCenterVertical() {
2021-05-28 20:30:27 +00:00
state.send('ALIGNED', { type: AlignType.CenterVertical })
2021-05-26 19:20:52 +00:00
}
function alignBottom() {
2021-05-28 20:30:27 +00:00
state.send('ALIGNED', { type: AlignType.Bottom })
2021-05-26 19:20:52 +00:00
}
function stretchVertically() {
2021-05-28 20:30:27 +00:00
state.send('STRETCHED', { type: StretchType.Vertical })
2021-05-26 19:20:52 +00:00
}
function distributeVertically() {
2021-05-28 20:30:27 +00:00
state.send('DISTRIBUTED', { type: DistributeType.Vertical })
2021-05-26 19:20:52 +00:00
}
function alignLeft() {
2021-05-28 20:30:27 +00:00
state.send('ALIGNED', { type: AlignType.Left })
2021-05-26 19:20:52 +00:00
}
function alignCenterHorizontal() {
2021-05-28 20:30:27 +00:00
state.send('ALIGNED', { type: AlignType.CenterHorizontal })
2021-05-26 19:20:52 +00:00
}
function alignRight() {
2021-05-28 20:30:27 +00:00
state.send('ALIGNED', { type: AlignType.Right })
2021-05-26 19:20:52 +00:00
}
function stretchHorizontally() {
2021-05-28 20:30:27 +00:00
state.send('STRETCHED', { type: StretchType.Horizontal })
2021-05-26 19:20:52 +00:00
}
function distributeHorizontally() {
2021-05-28 20:30:27 +00:00
state.send('DISTRIBUTED', { type: DistributeType.Horizontal })
2021-05-26 19:20:52 +00:00
}
function AlignDistribute({
2021-05-26 21:47:46 +00:00
hasTwoOrMore,
hasThreeOrMore,
}: {
hasTwoOrMore: boolean
hasThreeOrMore: boolean
2021-06-21 21:35:28 +00:00
}): JSX.Element {
2021-05-26 19:20:52 +00:00
return (
2021-07-01 22:11:09 +00:00
<>
<ButtonsRow>
<IconButton
bp={breakpoints}
size="small"
disabled={!hasTwoOrMore}
onClick={alignLeft}
>
<AlignLeftIcon />
</IconButton>
<IconButton
bp={breakpoints}
size="small"
disabled={!hasTwoOrMore}
onClick={alignCenterHorizontal}
>
<AlignCenterHorizontallyIcon />
</IconButton>
<IconButton
bp={breakpoints}
size="small"
disabled={!hasTwoOrMore}
onClick={alignRight}
>
<AlignRightIcon />
</IconButton>
<IconButton
bp={breakpoints}
size="small"
disabled={!hasTwoOrMore}
onClick={stretchHorizontally}
>
<StretchHorizontallyIcon />
</IconButton>
<IconButton
bp={breakpoints}
size="small"
disabled={!hasThreeOrMore}
onClick={distributeHorizontally}
>
<SpaceEvenlyHorizontallyIcon />
</IconButton>
</ButtonsRow>
<ButtonsRow>
<IconButton
bp={breakpoints}
size="small"
disabled={!hasTwoOrMore}
onClick={alignTop}
>
<AlignTopIcon />
</IconButton>
<IconButton
bp={breakpoints}
size="small"
disabled={!hasTwoOrMore}
onClick={alignCenterVertical}
>
<AlignCenterVerticallyIcon />
</IconButton>
<IconButton
bp={breakpoints}
size="small"
disabled={!hasTwoOrMore}
onClick={alignBottom}
>
<AlignBottomIcon />
</IconButton>
<IconButton
bp={breakpoints}
size="small"
disabled={!hasTwoOrMore}
onClick={stretchVertically}
>
<StretchVerticallyIcon />
</IconButton>
<IconButton
bp={breakpoints}
size="small"
disabled={!hasThreeOrMore}
onClick={distributeVertically}
>
<SpaceEvenlyVerticallyIcon />
</IconButton>
</ButtonsRow>
</>
2021-05-26 19:20:52 +00:00
)
}
export default memo(AlignDistribute)