Skip to content

Commit 1745636

Browse files
authored
feat: toggle fullscreen (#14)
1 parent 24e4e5b commit 1745636

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

examples/svelte/src/App.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@
102102
margin: 10px 0;
103103
text-align: center;
104104
}
105-
:global(.bytemd-body) {
106-
height: calc(100vh - 140px);
105+
:global(.bytemd) {
106+
height: calc(100vh - 100px);
107107
}
108108
:global(.medium-zoom-overlay) {
109109
z-index: 100;

packages/bytemd/src/editor.svelte

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
let textarea: HTMLTextAreaElement;
2727
let editor: Editor;
2828
let activeTab = 0;
29+
let fullscreen = false;
2930
3031
$: context = { editor, $el: el };
3132
@@ -232,14 +233,20 @@
232233

233234
<svelte:options immutable={true} />
234235

235-
<div class={`bytemd bytemd-mode-${mode}`} bind:this={el}>
236+
<div
237+
class={`bytemd bytemd-mode-${mode}${fullscreen ? ' bytemd-fullscreen' : ''}`}
238+
bind:this={el}>
236239
<Toolbar
237240
{context}
238241
{mode}
239242
{activeTab}
240243
{plugins}
241244
{toolbar}
242-
on:tab={setActiveTab} />
245+
{fullscreen}
246+
on:tab={setActiveTab}
247+
on:fullscreen={() => {
248+
fullscreen = !fullscreen;
249+
}} />
243250
<div class="bytemd-body">
244251
<div
245252
class="bytemd-editor"

packages/bytemd/src/icons.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ export const icons = {
2323
'<svg width="1em" height="1em" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" fill-opacity=".01" d="M0 0h48v48H0z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M20 24h24-24z" fill="#FFF"/><path d="M20 24h24" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path fill-rule="evenodd" clip-rule="evenodd" d="M20 38h24-24z" fill="#FFF"/><path d="M20 38h24" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path fill-rule="evenodd" clip-rule="evenodd" d="M20 10h24-24z" fill="#FFF"/><path d="M20 10h24" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path fill="#FFF" stroke="currentColor" stroke-width="4" stroke-linejoin="round" d="M4 34h8v8H4zM4 20h8v8H4zM4 6h8v8H4z"/></svg>',
2424
info:
2525
'<svg width="1em" height="1em" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" fill-opacity=".01" d="M0 0h48v48H0z"/><path d="M24 44a19.937 19.937 0 0014.142-5.858A19.937 19.937 0 0044 24a19.938 19.938 0 00-5.858-14.142A19.937 19.937 0 0024 4 19.938 19.938 0 009.858 9.858 19.938 19.938 0 004 24a19.937 19.937 0 005.858 14.142A19.938 19.938 0 0024 44z" fill="#FFF" stroke="currentColor" stroke-width="4" stroke-linejoin="round"/><path fill-rule="evenodd" clip-rule="evenodd" d="M24 11a2.5 2.5 0 110 5 2.5 2.5 0 010-5z" fill="currentColor"/><path d="M24.5 34V20h-2M21 34h7" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>',
26+
fullscreenOn:
27+
'<svg width="1em" height="1em" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" fill-opacity=".01" d="M0 0h48v48H0z"/><path d="M33 6h9v9M42 33v9h-9M15 42H6v-9M6 15V6h9" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>',
28+
fullscreenOff:
29+
'<svg width="1em" height="1em" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" fill-opacity=".01" d="M0 0h48v48H0z"/><path d="M33 6v9h9M15 6v9H6M15 42v-9H6M33 42v-9h8.9" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>',
2630
};

packages/bytemd/src/toolbar.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
export let activeTab: number;
1313
export let plugins: EditorProps['plugins'];
1414
export let toolbar: EditorProps['toolbar'];
15+
export let fullscreen: boolean;
1516
1617
function normalize(itemMap: NonNullable<BytemdPlugin['toolbar']>) {
1718
if (toolbar == null) {
@@ -64,4 +65,11 @@
6465
on:click={() => {
6566
window.open('https://github.com/bytedance/bytemd');
6667
}} />
68+
<ToolbarButton
69+
tooltip="Toggle Fullscreen"
70+
icon={fullscreen ? icons.fullscreenOff : icons.fullscreenOn}
71+
style="float:right"
72+
on:click={() => {
73+
dispatch('fullscreen');
74+
}} />
6775
</div>

packages/bytemd/styles/index.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
.bytemd {
66
border: 1px solid $gray-200;
7+
background-color: $white;
78
box-sizing: border-box;
89
height: 300px;
910
}
@@ -79,6 +80,18 @@
7980
}
8081
}
8182

83+
.bytemd-fullscreen {
84+
&.bytemd {
85+
position: fixed;
86+
left: 0;
87+
right: 0;
88+
top: 0;
89+
bottom: 0;
90+
border: none;
91+
height: 100vh;
92+
}
93+
}
94+
8295
.bytemd-mode-split {
8396
.bytemd-editor {
8497
float: left;

scripts/icon.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
CheckCorrect,
1919
InsertTable,
2020
Pic,
21+
FullScreen,
22+
OffScreen,
2123
} from '@icon-park/svg';
2224

2325
const svgo = new Svgo();
@@ -37,6 +39,8 @@ const meta = {
3739
ol: OrderedList,
3840
ul: ListCheckbox,
3941
info: Info,
42+
fullscreenOn: FullScreen,
43+
fullscreenOff: OffScreen,
4044
},
4145
'plugin-gfm': {
4246
task: CheckCorrect,

0 commit comments

Comments
 (0)