mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat: rich editor component
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/* Basic editor styles */
|
||||
.tiptap {
|
||||
color: #222;
|
||||
|
||||
&:focus-visible {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
>*+* {
|
||||
margin-top: 0.75em;
|
||||
}
|
||||
|
||||
ul,
|
||||
ol {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
code {
|
||||
background: rgba(#ffffff, 0.1);
|
||||
color: rgba(#ffffff, 0.6);
|
||||
border: 1px solid rgba(#ffffff, 0.1);
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.2rem;
|
||||
}
|
||||
|
||||
pre {
|
||||
background: rgba(#ffffff, 0.1);
|
||||
font-family: "JetBrainsMono", monospace;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 0.5rem;
|
||||
|
||||
code {
|
||||
color: inherit;
|
||||
padding: 0;
|
||||
background: none;
|
||||
font-size: 0.8rem;
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin-left: 0;
|
||||
padding-left: 1rem;
|
||||
border-left: 2px solid rgba(#ffffff, 0.4);
|
||||
|
||||
hr {
|
||||
border: none;
|
||||
border-top: 2px solid rgba(#ffffff, 0.1);
|
||||
margin: 2rem 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
58
packages/webapp/src/components/RichEditor/RichEditor.tsx
Normal file
58
packages/webapp/src/components/RichEditor/RichEditor.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
// @ts-nocheck
|
||||
import { Color } from '@tiptap/extension-color';
|
||||
import ListItem from '@tiptap/extension-list-item';
|
||||
import TextStyle from '@tiptap/extension-text-style';
|
||||
import { EditorProvider } from '@tiptap/react';
|
||||
import StarterKit from '@tiptap/starter-kit';
|
||||
import { useUncontrolled } from '@/hooks/useUncontrolled';
|
||||
import { Box } from '../Layout/Box';
|
||||
import './RichEditor.style.scss';
|
||||
|
||||
const extensions = [
|
||||
Color.configure({ types: [TextStyle.name, ListItem.name] }),
|
||||
TextStyle.configure({ types: [ListItem.name] }),
|
||||
StarterKit.configure({
|
||||
bulletList: {
|
||||
keepMarks: true,
|
||||
keepAttributes: false,
|
||||
},
|
||||
orderedList: {
|
||||
keepMarks: true,
|
||||
keepAttributes: false,
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
export interface RichEditorProps {
|
||||
value?: string;
|
||||
initialValue?: string;
|
||||
onChange?: (value: string) => void;
|
||||
className?: string;
|
||||
}
|
||||
export const RichEditor = ({
|
||||
value,
|
||||
initialValue,
|
||||
onChange,
|
||||
className,
|
||||
}: RichEditorProps) => {
|
||||
const [content, handleChange] = useUncontrolled({
|
||||
value,
|
||||
initialValue,
|
||||
onChange,
|
||||
finalValue: '',
|
||||
});
|
||||
|
||||
const handleBlur = ({ editor }) => {
|
||||
handleChange(editor.getHTML());
|
||||
};
|
||||
|
||||
return (
|
||||
<Box className={className}>
|
||||
<EditorProvider
|
||||
extensions={extensions}
|
||||
content={content}
|
||||
onBlur={handleBlur}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
1
packages/webapp/src/components/RichEditor/index.ts
Normal file
1
packages/webapp/src/components/RichEditor/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './RichEditor';
|
||||
Reference in New Issue
Block a user