Skip to content

Commit aba0449

Browse files
committed
feat(mobile): refactoring
1 parent a3098b4 commit aba0449

File tree

7 files changed

+29
-48
lines changed

7 files changed

+29
-48
lines changed

demo/stories/mobile-editor/MobileEditor.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import {memo} from 'react';
22

3-
import {ArrowUp} from '@gravity-ui/icons';
4-
import {Button, Icon} from '@gravity-ui/uikit';
5-
63
import {MarkdownEditorView, useMarkdownEditor} from '../../../src';
74
import {PlaygroundLayout} from '../../components/PlaygroundLayout';
85

@@ -24,11 +21,6 @@ export const MobileEditor = memo(() => {
2421
className={className}
2522
toolbarsPreset={toolbarPreset}
2623
mobile
27-
toolbarEnd={
28-
<Button view="action" pin="round-round">
29-
<Icon data={ArrowUp} size={16} />
30-
</Button>
31-
}
3224
/>
3325
)}
3426
/>

src/bundle/MarkdownEditorView.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
type ReactNode,
32
forwardRef,
43
useCallback,
54
useEffect,
@@ -68,7 +67,6 @@ const EditorWrapper = forwardRef<HTMLDivElement, EditorWrapperProps>(
6867
wysiwygHiddenActionsConfig: initialWysiwygHiddenActionsConfig,
6968
wysiwygToolbarConfig: initialWysiwygToolbarConfig,
7069
mobile = false,
71-
toolbarEnd,
7270
},
7371
ref,
7472
) => {
@@ -209,7 +207,6 @@ const EditorWrapper = forwardRef<HTMLDivElement, EditorWrapperProps>(
209207
{...settingsProps}
210208
settingsVisible={editor.toolbarVisible && settingsVisibleProp}
211209
/>
212-
{toolbarEnd}
213210
</WysiwygEditorView>
214211
)}
215212
{editorMode === 'markup' && (
@@ -277,7 +274,6 @@ type ViewProps = {
277274
enableSubmitInPreview?: boolean;
278275
hidePreviewAfterSubmit?: boolean;
279276
mobile?: boolean;
280-
toolbarEnd?: ReactNode;
281277
};
282278

283279
export type MarkdownEditorViewProps = ClassNameProps & ToolbarConfigs & ViewProps & QAProps & {};
@@ -314,7 +310,6 @@ export const MarkdownEditorView = forwardRef<HTMLDivElement, MarkdownEditorViewP
314310
wysiwygHiddenActionsConfig,
315311
wysiwygToolbarConfig,
316312
mobile = false,
317-
toolbarEnd,
318313
} = props;
319314

320315
const rerender = useUpdate();
@@ -400,7 +395,6 @@ export const MarkdownEditorView = forwardRef<HTMLDivElement, MarkdownEditorViewP
400395
wysiwygHiddenActionsConfig={wysiwygHiddenActionsConfig}
401396
wysiwygToolbarConfig={wysiwygToolbarConfig}
402397
mobile={mobile}
403-
toolbarEnd={toolbarEnd}
404398
/>
405399

406400
{markupSplitMode && (

src/bundle/SelectPopup.scss renamed to src/bundle/PlatformPopup.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.g-md-select-popup {
1+
.g-md-platform-popup {
22
&__sheet {
33
--g-sheet-content-padding: 0px;
44

src/bundle/SelectPopup.tsx renamed to src/bundle/PlatformPopup.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import {Popup, type PopupProps, Sheet} from '@gravity-ui/uikit';
44

55
import {cn} from '../classname';
66

7-
export type SelectPopupProps = Pick<PopupProps, 'placement' | 'open' | 'anchorElement'> & {
7+
export type PlatformPopupProps = Pick<PopupProps, 'placement' | 'open' | 'anchorElement'> & {
88
children: ReactNode;
99
mobile?: boolean;
1010
onClose?: () => void;
1111
};
1212

13-
import './SelectPopup.scss';
13+
import './PlatformPopup.scss';
1414

15-
const b = cn('select-popup');
15+
const b = cn('platform-popup');
1616

17-
export const SelectPopup: FC<SelectPopupProps> = ({
17+
export const PlatformPopup: FC<PlatformPopupProps> = ({
1818
mobile,
1919
children,
2020
onClose,

src/bundle/WysiwygEditorView.tsx

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export type WysiwygEditorViewProps = ClassNameProps &
3030
mobile?: boolean;
3131
};
3232

33-
const toolbarPosition: 'top' | 'bottom' = 'bottom';
34-
3533
export const WysiwygEditorView = memo<WysiwygEditorViewProps>((props) => {
3634
const {
3735
editor,
@@ -45,7 +43,6 @@ export const WysiwygEditorView = memo<WysiwygEditorViewProps>((props) => {
4543
toolbarClassName,
4644
children,
4745
stickyToolbar = true,
48-
mobile,
4946
} = props;
5047

5148
useRenderTime((time) => {
@@ -61,31 +58,27 @@ export const WysiwygEditorView = memo<WysiwygEditorViewProps>((props) => {
6158
});
6259
});
6360

64-
const toolbar = toolbarVisible ? (
65-
<ToolbarView
66-
qa="g-md-toolbar"
67-
editor={editor}
68-
editorMode="wysiwyg"
69-
toolbarEditor={editor}
70-
stickyToolbar={stickyToolbar}
71-
toolbarConfig={toolbarConfig}
72-
toolbarFocus={() => editor.focus()}
73-
hiddenActionsConfig={hiddenActionsConfig}
74-
settingsVisible={settingsVisible}
75-
className={b('toolbar', [toolbarClassName])}
76-
mobile={mobile}
77-
>
78-
{children}
79-
</ToolbarView>
80-
) : null;
81-
8261
return (
8362
<div className={b({toolbar: toolbarVisible}, [className])} data-qa={qa}>
84-
{toolbarPosition === 'top' && toolbar}
63+
{toolbarVisible ? (
64+
<ToolbarView
65+
qa="g-md-toolbar"
66+
editor={editor}
67+
editorMode="wysiwyg"
68+
toolbarEditor={editor}
69+
stickyToolbar={stickyToolbar}
70+
toolbarConfig={toolbarConfig}
71+
toolbarFocus={() => editor.focus()}
72+
hiddenActionsConfig={hiddenActionsConfig}
73+
settingsVisible={settingsVisible}
74+
className={b('toolbar', [toolbarClassName])}
75+
>
76+
{children}
77+
</ToolbarView>
78+
) : null}
8579
<WysiwygEditorComponent autofocus={autofocus} editor={editor} className={b('editor')}>
8680
<ReactRendererComponent storage={editor.renderStorage} />
8781
</WysiwygEditorComponent>
88-
{toolbarPosition === 'bottom' && toolbar}
8982
</div>
9083
);
9184
});

src/bundle/settings/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ import {noop} from '../../lodash';
2121
import {useBooleanState} from '../../react-utils/hooks';
2222
import {ToolbarTooltipDelay} from '../../toolbar';
2323
import {VERSION} from '../../version';
24-
import {SelectPopup} from '../SelectPopup';
2524
import type {MarkdownEditorMode, MarkdownEditorSplitMode} from '../types';
2625

2726
import {MarkdownHints} from './MarkdownHints';
2827

2928
import './index.scss';
3029

30+
import {PlatformPopup} from '../PlatformPopup';
31+
3132
const placement: PopupPlacement = ['bottom-end', 'top-end'];
3233

3334
const bSettings = cn('editor-settings');
@@ -91,7 +92,7 @@ export const EditorSettings = memo<EditorSettingsProps>(function EditorSettings(
9192
>
9293
<Icon data={Gear} />
9394
</Button>
94-
<SelectPopup
95+
<PlatformPopup
9596
mobile={mobile}
9697
open={popupShown}
9798
onClose={hidePopup}
@@ -104,7 +105,7 @@ export const EditorSettings = memo<EditorSettingsProps>(function EditorSettings(
104105
onClose={hidePopup}
105106
className={bSettings('content')}
106107
/>
107-
</SelectPopup>
108+
</PlatformPopup>
108109
</>
109110
)}
110111
</div>

src/toolbar/ToolbarListButton.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {Fragment, useEffect, useState} from 'react';
33
import {ChevronDown} from '@gravity-ui/icons';
44
import {HelpMark, Hotkey, Icon, Menu, Popover} from '@gravity-ui/uikit';
55

6-
import {SelectPopup} from '../bundle/SelectPopup';
6+
import {PlatformPopup} from 'src/bundle/PlatformPopup';
7+
78
import {cn} from '../classname';
89
import {i18n} from '../i18n/common';
910
import {isFunction} from '../lodash';
@@ -85,7 +86,7 @@ export function ToolbarListButton<E>({
8586
>
8687
{buttonContent}
8788
</ToolbarButtonView>
88-
<SelectPopup
89+
<PlatformPopup
8990
mobile={mobile}
9091
open={popupOpen}
9192
onClose={hide}
@@ -186,7 +187,7 @@ export function ToolbarListButton<E>({
186187
})
187188
.filter(Boolean)}
188189
</Menu>
189-
</SelectPopup>
190+
</PlatformPopup>
190191
{popupItem
191192
? popupItem.renderPopup({
192193
...popupItem,

0 commit comments

Comments
 (0)