Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Formatting the slate editor

Matt Roberts3b17fd70cf52
diff --git a/public/components/common/form/SlateEditor.scss b/public/components/common/form/SlateEditor.scss
index 866eedef4..dd843e2cd 100644
--- a/public/components/common/form/SlateEditor.scss
+++ b/public/components/common/form/SlateEditor.scss
@@ -1,15 +1,15 @@
@import "~@fider/assets/styles/variables.scss";
.slate-editor {
- background-color: get("colors.blue.100");
- // width: 100%;
- // line-height: get("font.size.xl");
- // padding: spacing(2);
- // resize: none;
- // border: 1px solid get("colors.gray.300");
- // border-radius: get("border.radius.medium");
- // -webkit-appearance: none;
- // appearance: none;
+ background-color: get("colors.white");
+ width: 100%;
+ line-height: get("font.size.xl");
+ padding: spacing(2);
+ resize: none;
+ border: 1px solid get("colors.gray.300");
+ border-radius: get("border.radius.medium");
+ -webkit-appearance: none;
+ appearance: none;
margin: spacing(3) 0;
&:disabled {
@@ -18,6 +18,10 @@
&--error {
border-color: get("colors.red.600");
}
+ p {
+ // line-height: 9px;
+ margin-bottom: 0;
+ }
}
.slate-editor--mention {
// padding: 3px 3px 2px;
@@ -38,5 +42,7 @@
background: get("colors.white");
border-radius: 4px;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
+
+
}
diff --git a/public/components/common/form/SlateEditor2.tsx b/public/components/common/form/SlateEditor2.tsx
index 88858f5e4..ba99a6c0b 100644
--- a/public/components/common/form/SlateEditor2.tsx
+++ b/public/components/common/form/SlateEditor2.tsx
@@ -1,7 +1,7 @@
import React, { useMemo, useCallback, useRef, useEffect, useState, Fragment, ReactNode } from "react"
import { Element, Editor, Transforms, Range, createEditor, Descendant, BaseEditor, BaseRange, Node } from "slate"
import { HistoryEditor, withHistory } from "slate-history"
-import { Slate, Editable, ReactEditor, withReact, useSelected, useFocused } from "slate-react"
+import { Slate, Editable, ReactEditor, withReact, useSelected, useFocused, RenderPlaceholderProps } from "slate-react"
export const IS_MAC = typeof navigator !== "undefined" && /Mac OS X/.test(navigator.userAgent)
@@ -69,6 +69,23 @@ interface CommentEditorProps {
className?: string
}
+const Placeholder = ({ attributes, children }: RenderPlaceholderProps) => {
+ return (
+ <span
+ {...attributes}
+ className="slate-editor--placeholder"
+ style={{
+ position: "absolute",
+ opacity: 0.3,
+ userSelect: "none",
+ pointerEvents: "none",
+ }}
+ >
+ {children}
+ </span>
+ )
+}
+
export const CommentEditor: React.FunctionComponent<CommentEditorProps> = (props) => {
const [users, setUsers] = useState<UserNames[]>([])
const ref = useRef<HTMLDivElement | null>(null)
@@ -174,7 +191,14 @@ export const CommentEditor: React.FunctionComponent<CommentEditorProps> = (props
setTarget(undefined)
}}
>
- <Editable readOnly={props.disabled} className="slate-editor" renderElement={renderElement} onKeyDown={onKeyDown} placeholder={props.placeholder} />
+ <Editable
+ readOnly={props.disabled}
+ className="slate-editor"
+ renderElement={renderElement}
+ onKeyDown={onKeyDown}
+ placeholder={props.placeholder}
+ renderPlaceholder={Placeholder}
+ />
{target && filteredUsers.length > 0 && (
<Portal>
<div ref={ref} className="slate-editor--mentions" data-cy="mentions-portal">