Skip to content

Commit b252d74

Browse files
committed
Fresh LayoutSelector with a ButtonGroup
1 parent 2fa7207 commit b252d74

File tree

4 files changed

+79
-65
lines changed

4 files changed

+79
-65
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ReactElement } from 'react';
2+
import cx from 'classnames';
3+
4+
interface Props {
5+
buttons: {
6+
content: ReactElement;
7+
srContent: string;
8+
onClick: () => void;
9+
isActive: boolean;
10+
}[];
11+
}
12+
13+
export const ButtonGroup = ({ buttons }: Props) => {
14+
return (
15+
<span className="isolate inline-flex rounded-md shadow-sm">
16+
{buttons.map(({ content, srContent, onClick, isActive }, index) => (
17+
<button
18+
type="button"
19+
className={cx(
20+
'relative inline-flex items-center px-2 py-2 text-slate-500 ring-1 ring-inset ring-slate-300 hover:bg-slate-300 focus:z-10 dark:text-slate-200 hover:dark:bg-slate-600',
21+
{
22+
'rounded-l-md': index === 0,
23+
'rounded-r-md': index === buttons.length - 1,
24+
'bg-slate-200 dark:bg-slate-600': isActive,
25+
}
26+
)}
27+
onClick={onClick}
28+
>
29+
<span className="sr-only">{srContent}</span>
30+
{content}
31+
</button>
32+
))}
33+
</span>
34+
);
35+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const Divider = () => (
2-
<div className="my-4 w-full border-t border-gray-200 opacity-20" />
2+
<div className="my-1 w-full border-t border-gray-400 opacity-30" />
33
);

desktop-app/src/renderer/components/Masonry/MasonryLayout.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,66 @@
11
import { Icon } from '@iconify/react';
2-
import { PREVIEW_LAYOUTS } from 'common/constants';
2+
import { PREVIEW_LAYOUTS, PreviewLayout } from 'common/constants';
33
import { useDispatch, useSelector } from 'react-redux';
4+
import { ButtonGroup } from 'renderer/components/ButtonGroup';
45
import useKeyboardShortcut, {
56
SHORTCUT_CHANNEL,
67
} from 'renderer/components/KeyboardShortcutsManager/useKeyboardShortcut';
7-
import Toggle from 'renderer/components/Toggle';
88
import { selectLayout, setLayout } from 'renderer/store/features/renderer';
99

10-
const PreviewLayout = () => {
10+
const PreviewLayoutSelector = () => {
1111
const layout = useSelector(selectLayout);
1212
const dispatch = useDispatch();
1313

14-
const handleLayout = () => {
15-
if (layout === PREVIEW_LAYOUTS.FLEX)
16-
dispatch(setLayout(PREVIEW_LAYOUTS.COLUMN));
17-
else dispatch(setLayout(PREVIEW_LAYOUTS.FLEX));
14+
const handleLayout = (newLayout: PreviewLayout) => {
15+
dispatch(setLayout(newLayout));
1816
};
1917

2018
useKeyboardShortcut(SHORTCUT_CHANNEL.PREVIEW_LAYOUT, handleLayout);
2119

2220
return (
2321
<div className="flex flex-row items-center justify-start px-4">
2422
<span className="w-1/2">Preview Layout</span>
25-
<div className="flex w-fit items-center gap-3 border-l px-5 dark:border-slate-400">
26-
<Icon icon="radix-icons:layout" />
27-
<Toggle
28-
isOn={layout === PREVIEW_LAYOUTS.FLEX}
29-
onChange={(e) => {
30-
if (e.target.checked) {
31-
dispatch(setLayout(PREVIEW_LAYOUTS.FLEX));
32-
} else {
33-
dispatch(setLayout(PREVIEW_LAYOUTS.COLUMN));
34-
}
35-
}}
23+
<div className="flex w-fit items-center gap-3 px-5 ">
24+
<ButtonGroup
25+
buttons={[
26+
{
27+
content: (
28+
<div className="flex flex-col items-center text-xs">
29+
{' '}
30+
<Icon icon="radix-icons:layout" /> Column
31+
</div>
32+
),
33+
srContent: 'Horizontal Layout',
34+
onClick: () => handleLayout(PREVIEW_LAYOUTS.COLUMN),
35+
isActive: layout === PREVIEW_LAYOUTS.COLUMN,
36+
},
37+
{
38+
content: (
39+
<div className="flex min-w-12 flex-col items-center text-xs">
40+
{' '}
41+
<Icon icon="lucide:layout-dashboard" /> Flex
42+
</div>
43+
),
44+
srContent: 'Flex Layout',
45+
onClick: () => handleLayout(PREVIEW_LAYOUTS.FLEX),
46+
isActive: layout === PREVIEW_LAYOUTS.FLEX,
47+
},
48+
{
49+
content: (
50+
<div className="flex flex-col items-center text-xs">
51+
{' '}
52+
<Icon icon="bx:bx-grid-alt" /> Masonry
53+
</div>
54+
),
55+
srContent: 'Masonry Layout',
56+
onClick: () => handleLayout(PREVIEW_LAYOUTS.MASONRY),
57+
isActive: layout === PREVIEW_LAYOUTS.MASONRY,
58+
},
59+
]}
3660
/>
37-
<Icon icon="lucide:layout-dashboard" />
3861
</div>
3962
</div>
4063
);
4164
};
4265

43-
export default PreviewLayout;
66+
export default PreviewLayoutSelector;

0 commit comments

Comments
 (0)