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

159 lines
3.8 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-06-21 21:35:28 +00:00
}): JSX.Element {
2021-05-26 19:20:52 +00:00
return (
<Container>
<IconButton
bp={{ '@initial': 'mobile', '@sm': 'small' }}
size="small"
disabled={!hasTwoOrMore}
onClick={alignLeft}
>
2021-05-26 19:20:52 +00:00
<AlignLeftIcon />
</IconButton>
<IconButton
bp={{ '@initial': 'mobile', '@sm': 'small' }}
size="small"
disabled={!hasTwoOrMore}
onClick={alignCenterHorizontal}
>
2021-05-26 19:20:52 +00:00
<AlignCenterHorizontallyIcon />
</IconButton>
<IconButton
bp={{ '@initial': 'mobile', '@sm': 'small' }}
size="small"
disabled={!hasTwoOrMore}
onClick={alignRight}
>
2021-05-26 19:20:52 +00:00
<AlignRightIcon />
</IconButton>
<IconButton
bp={{ '@initial': 'mobile', '@sm': 'small' }}
size="small"
disabled={!hasTwoOrMore}
onClick={stretchHorizontally}
>
2021-05-26 19:20:52 +00:00
<StretchHorizontallyIcon />
</IconButton>
<IconButton
bp={{ '@initial': 'mobile', '@sm': 'small' }}
size="small"
disabled={!hasThreeOrMore}
onClick={distributeHorizontally}
>
2021-05-26 19:20:52 +00:00
<SpaceEvenlyHorizontallyIcon />
</IconButton>
<IconButton
bp={{ '@initial': 'mobile', '@sm': 'small' }}
size="small"
disabled={!hasTwoOrMore}
onClick={alignTop}
>
2021-05-26 21:47:46 +00:00
<AlignTopIcon />
</IconButton>
<IconButton
bp={{ '@initial': 'mobile', '@sm': 'small' }}
size="small"
disabled={!hasTwoOrMore}
onClick={alignCenterVertical}
>
2021-05-26 21:47:46 +00:00
<AlignCenterVerticallyIcon />
</IconButton>
<IconButton
bp={{ '@initial': 'mobile', '@sm': 'small' }}
size="small"
disabled={!hasTwoOrMore}
onClick={alignBottom}
>
2021-05-26 21:47:46 +00:00
<AlignBottomIcon />
</IconButton>
<IconButton
bp={{ '@initial': 'mobile', '@sm': 'small' }}
size="small"
disabled={!hasTwoOrMore}
onClick={stretchVertically}
>
2021-05-26 21:47:46 +00:00
<StretchVerticallyIcon />
</IconButton>
<IconButton
bp={{ '@initial': 'mobile', '@sm': 'small' }}
size="small"
disabled={!hasThreeOrMore}
onClick={distributeVertically}
>
2021-05-26 21:47:46 +00:00
<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
},
})