|
1 | 1 | import { Icon } from '@iconify/react';
|
2 |
| -import { PREVIEW_LAYOUTS } from 'common/constants'; |
| 2 | +import { PREVIEW_LAYOUTS, PreviewLayout } from 'common/constants'; |
3 | 3 | import { useDispatch, useSelector } from 'react-redux';
|
| 4 | +import { ButtonGroup } from 'renderer/components/ButtonGroup'; |
4 | 5 | import useKeyboardShortcut, {
|
5 | 6 | SHORTCUT_CHANNEL,
|
6 | 7 | } from 'renderer/components/KeyboardShortcutsManager/useKeyboardShortcut';
|
7 |
| -import Toggle from 'renderer/components/Toggle'; |
8 | 8 | import { selectLayout, setLayout } from 'renderer/store/features/renderer';
|
9 | 9 |
|
10 |
| -const PreviewLayout = () => { |
| 10 | +const PreviewLayoutSelector = () => { |
11 | 11 | const layout = useSelector(selectLayout);
|
12 | 12 | const dispatch = useDispatch();
|
13 | 13 |
|
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)); |
18 | 16 | };
|
19 | 17 |
|
20 | 18 | useKeyboardShortcut(SHORTCUT_CHANNEL.PREVIEW_LAYOUT, handleLayout);
|
21 | 19 |
|
22 | 20 | return (
|
23 | 21 | <div className="flex flex-row items-center justify-start px-4">
|
24 | 22 | <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 | + ]} |
36 | 60 | />
|
37 |
| - <Icon icon="lucide:layout-dashboard" /> |
38 | 61 | </div>
|
39 | 62 | </div>
|
40 | 63 | );
|
41 | 64 | };
|
42 | 65 |
|
43 |
| -export default PreviewLayout; |
| 66 | +export default PreviewLayoutSelector; |
0 commit comments