diff --git a/frontend/src/cse-ui-kit/assets/code-button.svg b/frontend/src/cse-ui-kit/assets/code-button.svg
new file mode 100644
index 00000000..8baa053a
--- /dev/null
+++ b/frontend/src/cse-ui-kit/assets/code-button.svg
@@ -0,0 +1,4 @@
+
\ No newline at end of file
diff --git a/frontend/src/cse-ui-kit/small_buttons/CodeButton.tsx b/frontend/src/cse-ui-kit/small_buttons/CodeButton.tsx
new file mode 100644
index 00000000..d8463670
--- /dev/null
+++ b/frontend/src/cse-ui-kit/small_buttons/CodeButton.tsx
@@ -0,0 +1,23 @@
+import React, { MouseEventHandler } from 'react';
+import { StyledButton, buttonProps, scaleRate } from './small_buttons-Styled';
+import { ReactComponent as Code } from 'src/cse-ui-kit/assets/code-button.svg';
+
+type Props = {
+ onClick?: MouseEventHandler;
+ onMouseDown?: MouseEventHandler;
+} & buttonProps;
+
+export default function CodeButton({
+ onClick,
+ onMouseDown,
+ ...styleProps
+}: Props) {
+ return (
+
+
+
+ );
+}
diff --git a/frontend/src/packages/editor/components/EditorBlock.tsx b/frontend/src/packages/editor/components/EditorBlock.tsx
index 232edb7d..8d1add13 100644
--- a/frontend/src/packages/editor/components/EditorBlock.tsx
+++ b/frontend/src/packages/editor/components/EditorBlock.tsx
@@ -13,8 +13,9 @@ import EditorCenterAlignButton from './buttons/EditorCenterAlignButton';
import EditorLeftAlignButton from './buttons/EditorLeftAlignButton';
import EditorRightAlignButton from './buttons/EditorRightAlignButton';
-import ContentBlock from '../../../cse-ui-kit/contentblock/contentblock-wrapper';
-import { handleKey } from './buttons/buttonHelpers';
+import ContentBlock from "../../../cse-ui-kit/contentblock/contentblock-wrapper";
+import { handleKey } from "./buttons/buttonHelpers";
+import EditorCodeButton from "./buttons/EditorCodeButton";
const defaultTextSize = 16;
@@ -30,6 +31,7 @@ const Text = styled.span<{
bold: boolean;
italic: boolean;
underline: boolean;
+ code: boolean | string;
quote: boolean;
textSize: number;
align: string;
@@ -38,8 +40,10 @@ const Text = styled.span<{
font-style: ${(props) => (props.italic || props.quote ? 'italic' : 'normal')};
color: ${(props) => (props.quote ? '#9e9e9e' : 'black')};
font-size: ${(props) => props.textSize}px;
- text-decoration-line: ${(props) => (props.underline ? 'underline' : 'none')};
+ font-family: ${(props) => props.code ? "monospace" : "inherit"};
+ text-decoration-line: ${(props) => (props.underline ? "underline" : "none")};
text-align: ${(props) => props.align};
+ background-color: ${(props) => props.code ? "#eee" : "#fff"};
`;
const Quote = styled.blockquote`
@@ -66,6 +70,7 @@ const EditorBlock: FC = ({
italic: leaf.italic ?? false,
underline: leaf.underline ?? false,
quote: leaf.quote ?? false,
+ code: leaf.code ?? false,
align: leaf.align ?? 'left',
textSize: leaf.textSize ?? defaultTextSize,
...attributes,
@@ -93,6 +98,7 @@ const EditorBlock: FC = ({
+
diff --git a/frontend/src/packages/editor/components/buttons/EditorCodeButton.tsx b/frontend/src/packages/editor/components/buttons/EditorCodeButton.tsx
new file mode 100644
index 00000000..f5c6a7ad
--- /dev/null
+++ b/frontend/src/packages/editor/components/buttons/EditorCodeButton.tsx
@@ -0,0 +1,19 @@
+import React, { FC } from "react";
+import { useSlate } from "slate-react";
+import CodeButton from "src/cse-ui-kit/small_buttons/CodeButton";
+import { toggleMark } from "./buttonHelpers";
+
+const EditorCodeButton: FC = () => {
+ const editor = useSlate();
+ return (
+ {
+ event.preventDefault();
+ toggleMark(editor, "code");
+ }}
+ />
+ );
+};
+
+export default EditorCodeButton;
diff --git a/frontend/src/packages/editor/components/buttons/buttonHelpers.ts b/frontend/src/packages/editor/components/buttons/buttonHelpers.ts
index f228a8bc..872f2af8 100644
--- a/frontend/src/packages/editor/components/buttons/buttonHelpers.ts
+++ b/frontend/src/packages/editor/components/buttons/buttonHelpers.ts
@@ -8,7 +8,7 @@ import { ReactEditor } from 'slate-react';
*/
const toggleMark = (
editor: BaseEditor & ReactEditor,
- format: 'bold' | 'italic' | 'underline' | 'quote'
+ format: 'bold' | 'italic' | 'underline' | 'quote' | 'code'
): void => {
const isActive = isMarkActive(editor, format);
@@ -27,7 +27,7 @@ const toggleMark = (
*/
const isMarkActive = (
editor: BaseEditor & ReactEditor,
- format: 'bold' | 'italic' | 'underline' | 'quote'
+ format: 'bold' | 'italic' | 'underline' | 'quote' | 'code'
): boolean => {
// https://docs.slatejs.org/concepts/07-editor
// Editor object exposes properties of the current editor
@@ -69,6 +69,12 @@ const handleKey = (
toggleMark(editor, 'quote');
}
}
-};
+ switch (event.key) {
+ case '`': {
+ event.preventDefault();
+ toggleMark(editor, "code");
+ }
+ }
+}
export { toggleMark, isMarkActive, handleKey };
diff --git a/frontend/src/packages/editor/types.ts b/frontend/src/packages/editor/types.ts
index 2c0ac403..c1649e4b 100644
--- a/frontend/src/packages/editor/types.ts
+++ b/frontend/src/packages/editor/types.ts
@@ -16,6 +16,7 @@ export type CustomText = {
quote?: boolean;
type?: string;
align?: string;
+ code?: string;
};
export interface CMSBlockProps {