-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): editor mode switch (#8896)
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/frontend/core/src/mobile/pages/workspace/detail/menu/mode-switch.css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const radioWrapper = style({ | ||
padding: '6px 10px', | ||
width: '100%', | ||
}); |
61 changes: 61 additions & 0 deletions
61
packages/frontend/core/src/mobile/pages/workspace/detail/menu/mode-switch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
RadioGroup, | ||
type RadioItem, | ||
useMobileMenuController, | ||
} from '@affine/component'; | ||
import { EditorService } from '@affine/core/modules/editor'; | ||
import track from '@affine/track'; | ||
import type { DocMode } from '@blocksuite/affine/blocks'; | ||
import { useLiveData, useService } from '@toeverything/infra'; | ||
import { useCallback } from 'react'; | ||
|
||
import * as styles from './mode-switch.css'; | ||
|
||
const EdgelessRadioItem: RadioItem = { | ||
value: 'edgeless', | ||
label: 'Edgeless', | ||
testId: 'switch-edgeless-mode-button', | ||
}; | ||
const PageRadioItem: RadioItem = { | ||
value: 'page', | ||
label: 'Page', | ||
testId: 'switch-page-mode-button', | ||
}; | ||
const items = [PageRadioItem, EdgelessRadioItem]; | ||
|
||
export const EditorModeSwitch = () => { | ||
const { close } = useMobileMenuController(); | ||
const editor = useService(EditorService).editor; | ||
const trash = useLiveData(editor.doc.trash$); | ||
const isSharedMode = editor.isSharedMode; | ||
const currentMode = useLiveData(editor.mode$); | ||
|
||
const onToggle = useCallback( | ||
(mode: DocMode) => { | ||
editor.setMode(mode); | ||
editor.setSelector(undefined); | ||
track.$.header.actions.switchPageMode({ mode }); | ||
close(); | ||
}, | ||
[close, editor] | ||
); | ||
|
||
if (trash || isSharedMode) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={styles.radioWrapper}> | ||
<RadioGroup | ||
itemHeight={28} | ||
width="100%" | ||
borderRadius={8} | ||
padding={2} | ||
gap={4} | ||
value={currentMode} | ||
items={items} | ||
onChange={onToggle} | ||
/> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters