feat layers and align

This commit is contained in:
DiamondThree
2022-08-17 21:28:17 +08:00
parent 46727d367c
commit e8f82ddc55
3 changed files with 56 additions and 75 deletions

View File

@@ -45,18 +45,16 @@ export const AlignPanel = ({
}; };
const Container = styled('div')({ const Container = styled('div')({
width: '120px', width: '170px',
display: 'flex', display: 'flex',
flexWrap: 'wrap', flexWrap: 'wrap',
}); });
const SelectableContainer = styled('div')<{ selected?: boolean }>( const SelectableContainer = styled('div')<{ selected?: boolean }>(
({ selected, theme }) => ({ ({ selected, theme }) => ({
width: '20px', width: '22px',
height: '20px', height: '22px',
// border: `1px solid ${ color: theme.affine.palette.icons,
// selected ? theme.affine.palette.primary : 'rgba(0,0,0,0)'
// }`,
borderRadius: '5px', borderRadius: '5px',
overflow: 'hidden', overflow: 'hidden',
margin: '10px', margin: '10px',
@@ -65,10 +63,3 @@ const SelectableContainer = styled('div')<{ selected?: boolean }>(
boxSizing: 'border-box', boxSizing: 'border-box',
}) })
); );
const Color = styled('div')({
width: '16px',
height: '16px',
borderRadius: '5px',
boxShadow: '0px 0px 2px rgba(0, 0, 0, 0.25)',
});

View File

@@ -1,5 +1,5 @@
import type { TldrawApp } from '@toeverything/components/board-state'; import type { TldrawApp } from '@toeverything/components/board-state';
import type { TDShape } from '@toeverything/components/board-types'; import { StretchType, TDShape } from '@toeverything/components/board-types';
import { import {
AlignHorizontalCenterIcon, AlignHorizontalCenterIcon,
AlignIcon, AlignIcon,
@@ -8,6 +8,8 @@ import {
AlignToRightIcon, AlignToRightIcon,
AlignToTopIcon, AlignToTopIcon,
AlignVerticalCenterIcon, AlignVerticalCenterIcon,
DistributeHorizontalIcon,
DistributeVerticalIcon,
} from '@toeverything/components/icons'; } from '@toeverything/components/icons';
import { import {
IconButton, IconButton,
@@ -61,11 +63,31 @@ let AlignPanelArr = [
title: 'Align centerHorizontal', title: 'Align centerHorizontal',
icon: <AlignHorizontalCenterIcon></AlignHorizontalCenterIcon>, icon: <AlignHorizontalCenterIcon></AlignHorizontalCenterIcon>,
}, },
{
name: 'stretchCenterHorizontal',
title: 'Align stretch centerHorizontal',
icon: <DistributeHorizontalIcon></DistributeHorizontalIcon>,
},
{
name: 'stretchCenterVertical',
title: 'Align stretch centerHorizontal',
icon: <DistributeVerticalIcon></DistributeVerticalIcon>,
},
]; ];
export const AlignOperation = ({ app, shapes }: BorderColorConfigProps) => { export const AlignOperation = ({ app, shapes }: BorderColorConfigProps) => {
const theme = useTheme(); const theme = useTheme();
const setAlign = (alginType: AlignType) => { const setAlign = (alginType: string) => {
app.align(alginType); switch (alginType) {
case 'stretchCenterHorizontal':
app.stretch(StretchType.Horizontal);
break;
case 'stretchCenterVertical':
app.stretch(StretchType.Vertical);
break;
default:
app.align(alginType as AlignType);
break;
}
}; };
return ( return (
@@ -79,7 +101,7 @@ export const AlignOperation = ({ app, shapes }: BorderColorConfigProps) => {
></AlignPanel> ></AlignPanel>
} }
> >
<Tooltip content="Fill Color" placement="top-start"> <Tooltip content="Align" placement="top-start">
<IconButton> <IconButton>
<AlignIcon /> <AlignIcon />
</IconButton> </IconButton>

View File

@@ -1,44 +1,40 @@
import type { TldrawApp } from '@toeverything/components/board-state'; import type { TldrawApp } from '@toeverything/components/board-state';
import type { TDShape } from '@toeverything/components/board-types'; import type { TDShape } from '@toeverything/components/board-types';
import { import {
HeadingOneIcon, BringForwardIcon,
HeadingThreeIcon, BringToFrontIcon,
HeadingTwoIcon, LayersIcon,
LockIcon, SendBackwardIcon,
TextFontIcon, SendToBackIcon,
} from '@toeverything/components/icons'; } from '@toeverything/components/icons';
import { import { IconButton, Popover, Tooltip } from '@toeverything/components/ui';
IconButton, import { AlignPanel } from '../align-panel';
Popover,
styled,
Tooltip,
} from '@toeverything/components/ui';
interface FontSizeConfigProps { interface FontSizeConfigProps {
app: TldrawApp; app: TldrawApp;
shapes: TDShape[]; shapes: TDShape[];
} }
const _fontSizes = [ const AlignPanelArr = [
{ {
name: 'To Front', title: 'To Front',
value: 'tofront', name: 'tofront',
icon: <HeadingOneIcon />, icon: <BringToFrontIcon />,
}, },
{ {
name: 'Forward', title: 'Forward',
value: 'forward', name: 'forward',
icon: <HeadingTwoIcon />, icon: <BringForwardIcon />,
}, },
{ {
name: 'Backward', title: 'Backward',
value: 'backward', name: 'backward',
icon: <HeadingThreeIcon />, icon: <SendBackwardIcon />,
}, },
{ {
name: 'To Back', title: 'To Back',
value: 'toback', name: 'toback',
icon: <TextFontIcon />, icon: <SendToBackIcon />,
}, },
]; ];
@@ -65,45 +61,17 @@ export const MoveCoverageConfig = ({ app, shapes }: FontSizeConfigProps) => {
trigger="hover" trigger="hover"
placement="bottom-start" placement="bottom-start"
content={ content={
<div> <AlignPanel
{_fontSizes.map(fontSize => { alignOptions={AlignPanelArr}
return ( onSelect={moveCoverage}
<ListItemContainer ></AlignPanel>
key={fontSize.value}
onClick={() => moveCoverage(fontSize.value)}
>
{/* {fontSize.icon} */}
<ListItemTitle>{fontSize.name}</ListItemTitle>
</ListItemContainer>
);
})}
</div>
} }
> >
<Tooltip content="Font Size" placement="top-start"> <Tooltip content="Layers" placement="top-start">
<IconButton> <IconButton>
<LockIcon /> <LayersIcon />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
</Popover> </Popover>
); );
}; };
const ListItemContainer = styled('div')(({ theme }) => ({
display: 'flex',
alignItems: 'center',
cursor: 'pointer',
height: '32px',
padding: '4px 12px',
color: theme.affine.palette.icons,
// eslint-disable-next-line @typescript-eslint/naming-convention
'&:hover': {
backgroundColor: theme.affine.palette.hover,
},
}));
const ListItemTitle = styled('span')(({ theme }) => ({
marginLeft: '12px',
color: theme.affine.palette.primaryText,
}));