forked from mysociety/local-intelligence-hub
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from commonknowledge/add-rich-text-editor-puc…
…k-cms Add rich text editor puck cms
- Loading branch information
Showing
6 changed files
with
191 additions
and
10 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
nextjs/src/data/puck/config/blocks/RichText/customRichTextStyles.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
ul { | ||
list-style-type: disc; | ||
padding-left: 24px; | ||
} | ||
|
||
ol { | ||
list-style-type: decimal; | ||
padding-left: 24px; | ||
} | ||
|
||
a { | ||
text-decoration: underline; | ||
} | ||
|
||
.size-small { | ||
font-size: 16px; | ||
} | ||
|
||
.size-medium { | ||
font-size: 20px; | ||
} | ||
|
||
.size-large { | ||
font-size: 24px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import { ComponentConfig } from "@measured/puck"; | ||
import ReactQuill, { Quill } from 'react-quill'; | ||
import 'react-quill/dist/quill.snow.css'; | ||
import './customRichTextStyles.css'; | ||
|
||
const Parchment = Quill.import('parchment'); | ||
const SizeClass = new Parchment.Attributor.Class('size', 'size', { | ||
scope: Parchment.Scope.INLINE, | ||
whitelist: ['small', 'medium', 'large'] | ||
}); | ||
Quill.register(SizeClass, true); | ||
|
||
export type RichTextProps = { | ||
content: string | ||
}; | ||
|
||
const modules = { | ||
toolbar: [ | ||
[{ 'size': ['small', 'medium', 'large' ] }], | ||
[ 'italic', 'underline', 'strike'], | ||
[{ 'list': 'ordered'}, { 'list': 'bullet' }], | ||
['link'], | ||
['clean'] | ||
], | ||
}; | ||
|
||
const formats = [ | ||
'size', 'italic', 'underline', 'strike', | ||
'list', 'bullet', 'link' | ||
]; | ||
|
||
export const RichText: ComponentConfig<RichTextProps> = { | ||
label: "RichText", | ||
fields: { | ||
content: { | ||
type: "custom", | ||
render: ({ onChange, value }) => ( | ||
<ReactQuill | ||
value={value} | ||
onChange={(e: string) => onChange(e)} | ||
modules={modules} | ||
formats={formats} | ||
/> | ||
), | ||
} | ||
}, | ||
render: ({ content }) => { | ||
return ( | ||
<div className='max-w-prose' | ||
dangerouslySetInnerHTML={{ __html: content }} | ||
/> | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters