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

109 lines
2.9 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'
import { IconButton } from 'components/shared'
import state from 'state'
import styled from 'styles'
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
}
2021-05-26 21:47:46 +00:00
export default function AlignDistribute({
hasTwoOrMore,
hasThreeOrMore,
}: {
hasTwoOrMore: boolean
hasThreeOrMore: boolean
}) {
2021-05-26 19:20:52 +00:00
return (
<Container>
2021-05-26 21:47:46 +00:00
<IconButton disabled={!hasTwoOrMore} onClick={alignLeft}>
2021-05-26 19:20:52 +00:00
<AlignLeftIcon />
</IconButton>
2021-05-26 21:47:46 +00:00
<IconButton disabled={!hasTwoOrMore} onClick={alignCenterHorizontal}>
2021-05-26 19:20:52 +00:00
<AlignCenterHorizontallyIcon />
</IconButton>
2021-05-26 21:47:46 +00:00
<IconButton disabled={!hasTwoOrMore} onClick={alignRight}>
2021-05-26 19:20:52 +00:00
<AlignRightIcon />
</IconButton>
2021-05-26 21:47:46 +00:00
<IconButton disabled={!hasTwoOrMore} onClick={stretchHorizontally}>
2021-05-26 19:20:52 +00:00
<StretchHorizontallyIcon />
</IconButton>
2021-05-26 21:47:46 +00:00
<IconButton disabled={!hasThreeOrMore} onClick={distributeHorizontally}>
2021-05-26 19:20:52 +00:00
<SpaceEvenlyHorizontallyIcon />
</IconButton>
2021-05-26 21:47:46 +00:00
<IconButton disabled={!hasTwoOrMore} onClick={alignTop}>
<AlignTopIcon />
</IconButton>
<IconButton disabled={!hasTwoOrMore} onClick={alignCenterVertical}>
<AlignCenterVerticallyIcon />
</IconButton>
<IconButton disabled={!hasTwoOrMore} onClick={alignBottom}>
<AlignBottomIcon />
</IconButton>
<IconButton disabled={!hasTwoOrMore} onClick={stretchVertically}>
<StretchVerticallyIcon />
</IconButton>
<IconButton disabled={!hasThreeOrMore} onClick={distributeVertically}>
<SpaceEvenlyVerticallyIcon />
</IconButton>
2021-05-26 19:20:52 +00:00
</Container>
)
}
2021-05-28 20:30:27 +00:00
const Container = styled('div', {
display: 'grid',
2021-05-26 19:20:52 +00:00
padding: 4,
2021-05-28 20:30:27 +00:00
gridTemplateColumns: 'repeat(5, auto)',
2021-05-26 19:20:52 +00:00
[`& ${IconButton} > svg`]: {
2021-05-28 20:30:27 +00:00
stroke: 'transparent',
2021-05-26 19:20:52 +00:00
},
})