Skip to content

Commit b467342

Browse files
committed
Add bottom bar to editor
1 parent d70a279 commit b467342

File tree

6 files changed

+216
-0
lines changed

6 files changed

+216
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React, { MouseEventHandler, FC } from 'react'
2+
import styled from '../../lib/styled'
3+
import { flexCenter, borderLeft } from '../../lib/styled/styleFunctions'
4+
5+
interface BottomBarButtonProps {
6+
className?: string
7+
onClick?: MouseEventHandler<HTMLButtonElement>
8+
}
9+
10+
const BottomBarButton: FC<BottomBarButtonProps> = ({
11+
className,
12+
onClick,
13+
children,
14+
}) => {
15+
return (
16+
<Container className={className} onClick={onClick}>
17+
{children}
18+
</Container>
19+
)
20+
}
21+
22+
export default BottomBarButton
23+
24+
const Container = styled.button`
25+
background-color: transparent;
26+
border: none;
27+
color: ${({ theme }) => theme.uiTextColor};
28+
font-size: 14px;
29+
${flexCenter}
30+
padding: 0 5px;
31+
${borderLeft}
32+
cursor: pointer;
33+
&:hover {
34+
background-color: ${({ theme }) => theme.navItemHoverBackgroundColor};
35+
}
36+
`
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React, { useCallback } from 'react'
2+
import { usePreferences } from '../../lib/preferences'
3+
import { openContextMenu } from '../../lib/electronOnly'
4+
import { MenuItemConstructorOptions } from 'electron'
5+
import { capitalize } from '../../lib/string'
6+
import BottomBarButton from '../atoms/BottomBarButton'
7+
8+
const EditorIndentationStatus = () => {
9+
const { preferences, setPreferences } = usePreferences()
10+
const currentIndentType = preferences['editor.indentType']
11+
const currentIndentSize = preferences['editor.indentSize']
12+
13+
const openEditorIndentationContextMenu = useCallback(() => {
14+
openContextMenu({
15+
menuItems: [
16+
{
17+
type: 'submenu',
18+
label: `Indent Size: ${capitalize(currentIndentType)}`,
19+
submenu: [
20+
{
21+
type: 'radio',
22+
label: 'Spaces',
23+
checked: currentIndentType === 'spaces',
24+
click: () => {
25+
setPreferences({
26+
'editor.indentType': 'spaces',
27+
})
28+
},
29+
},
30+
{
31+
type: 'normal',
32+
label: 'Tab',
33+
checked: currentIndentType === 'tab',
34+
click: () => {
35+
setPreferences({
36+
'editor.indentType': 'tab',
37+
})
38+
},
39+
},
40+
] as MenuItemConstructorOptions[],
41+
},
42+
{
43+
type: 'submenu',
44+
label: `Indent Size: ${currentIndentSize}`,
45+
submenu: ([2, 4, 8] as [2, 4, 8]).map((indentSize) => {
46+
return {
47+
type: 'radio',
48+
label: `${indentSize}`,
49+
checked: currentIndentSize === indentSize,
50+
click: () => {
51+
setPreferences({
52+
'editor.indentSize': indentSize,
53+
})
54+
},
55+
}
56+
}) as MenuItemConstructorOptions[],
57+
},
58+
] as MenuItemConstructorOptions[],
59+
})
60+
}, [currentIndentType, currentIndentSize, setPreferences])
61+
62+
return (
63+
<BottomBarButton onClick={openEditorIndentationContextMenu}>
64+
{capitalize(currentIndentType)}: {currentIndentSize}
65+
</BottomBarButton>
66+
)
67+
}
68+
69+
export default EditorIndentationStatus
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { useCallback } from 'react'
2+
import { usePreferences } from '../../lib/preferences'
3+
import { openContextMenu } from '../../lib/electronOnly'
4+
import { MenuItemConstructorOptions } from 'electron'
5+
import BottomBarButton from '../atoms/BottomBarButton'
6+
import Icon from '../atoms/Icon'
7+
import { mdiKeyboard } from '@mdi/js'
8+
9+
const EditorKeyMapSelect = () => {
10+
const { preferences, setPreferences } = usePreferences()
11+
const editorKeyMap = preferences['editor.keyMap']
12+
13+
const openThemeContextMenu = useCallback(() => {
14+
openContextMenu({
15+
menuItems: (['default', 'emacs', 'vim'] as [
16+
'default',
17+
'emacs',
18+
'vim'
19+
]).map((keyMap) => {
20+
return {
21+
type: 'radio',
22+
label: keyMap,
23+
checked: keyMap === editorKeyMap,
24+
click: () => {
25+
setPreferences({
26+
'editor.keyMap': keyMap,
27+
})
28+
},
29+
} as MenuItemConstructorOptions
30+
}),
31+
})
32+
}, [setPreferences, editorKeyMap])
33+
34+
return (
35+
<BottomBarButton onClick={openThemeContextMenu}>
36+
<Icon path={mdiKeyboard} />
37+
</BottomBarButton>
38+
)
39+
}
40+
41+
export default EditorKeyMapSelect

src/components/molecules/EditorSelectionStatus.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export default EditorSelectionStatus
4444

4545
const Container = styled.div`
4646
padding: 0 5px;
47+
height: 24px;
48+
font-size: 14px;
4749
color: ${({ theme }) => theme.uiTextColor};
4850
user-select: none;
4951
`
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React, { useCallback } from 'react'
2+
import { usePreferences } from '../../lib/preferences'
3+
import { openContextMenu } from '../../lib/electronOnly'
4+
import { MenuItemConstructorOptions } from 'electron'
5+
import BottomBarButton from '../atoms/BottomBarButton'
6+
import Icon from '../atoms/Icon'
7+
import { mdiPaletteOutline } from '@mdi/js'
8+
import { themes } from '../../lib/CodeMirror'
9+
10+
const EditorThemeSelect = () => {
11+
const { preferences, setPreferences } = usePreferences()
12+
const editorTheme = preferences['editor.theme']
13+
const codeBlockTheme = preferences['markdown.codeBlockTheme']
14+
15+
const openThemeContextMenu = useCallback(() => {
16+
openContextMenu({
17+
menuItems: [
18+
{
19+
type: 'submenu',
20+
label: `Editor Theme: ${editorTheme}`,
21+
submenu: themes.map((theme) => {
22+
return {
23+
type: 'radio',
24+
label: theme,
25+
checked: editorTheme === theme,
26+
click: () => {
27+
setPreferences({ 'editor.theme': theme })
28+
},
29+
} as MenuItemConstructorOptions
30+
}),
31+
},
32+
{
33+
type: 'submenu',
34+
label: `Markdown Code Block Theme: ${codeBlockTheme}`,
35+
submenu: themes.map((theme) => {
36+
return {
37+
type: 'radio',
38+
label: theme,
39+
checked: codeBlockTheme === theme,
40+
click: () => {
41+
setPreferences({ 'markdown.codeBlockTheme': theme })
42+
},
43+
} as MenuItemConstructorOptions
44+
}),
45+
},
46+
] as MenuItemConstructorOptions[],
47+
})
48+
}, [editorTheme, codeBlockTheme, setPreferences])
49+
50+
return (
51+
<BottomBarButton onClick={openThemeContextMenu}>
52+
<Icon path={mdiPaletteOutline} />
53+
</BottomBarButton>
54+
)
55+
}
56+
57+
export default EditorThemeSelect

src/components/organisms/NoteDetail.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import {
2121
} from '../../lib/dom'
2222
import { EditorPosition } from '../../lib/CodeMirror'
2323
import EditorSelectionStatus from '../molecules/EditorSelectionStatus'
24+
import EditorIndentationStatus from '../molecules/EditorIndentationStatus'
25+
import EditorThemeSelect from '../molecules/EditorThemeSelect'
26+
import EditorKeyMapSelect from '../molecules/EditorKeymapSelect'
2427

2528
type NoteDetailProps = {
2629
note: NoteDoc
@@ -333,6 +336,9 @@ class NoteDetail extends React.Component<NoteDetailProps, NoteDetailState> {
333336
cursor={currentCursor}
334337
selections={currentSelections}
335338
/>
339+
<EditorKeyMapSelect />
340+
<EditorThemeSelect />
341+
<EditorIndentationStatus />
336342
</div>
337343
</Container>
338344
)
@@ -347,7 +353,12 @@ const Container = styled.div`
347353
flex-direction: column;
348354
height: 100%;
349355
& > .bottomBar {
356+
display: flex;
350357
${borderTop}
358+
height: 24px;
359+
& > :first-child {
360+
flex: 1;
361+
}
351362
}
352363
`
353364

0 commit comments

Comments
 (0)