diff --git a/docs/src/demos/Examples/Tables/React/index.jsx b/docs/src/demos/Examples/Tables/React/index.jsx new file mode 100644 index 00000000..15702130 --- /dev/null +++ b/docs/src/demos/Examples/Tables/React/index.jsx @@ -0,0 +1,160 @@ +import React from 'react' +import { useEditor, EditorContent } from '@tiptap/react' +import StarterKit from '@tiptap/starter-kit' +import Table from '@tiptap/extension-table' +import TableRow from '@tiptap/extension-table-row' +import TableCell from '@tiptap/extension-table-cell' +import TableHeader from '@tiptap/extension-table-header' +import './styles.scss' + +const CustomTableCell = TableCell.extend({ + addAttributes() { + return { + // extend the existing attributes … + ...this.parent?.(), + + // and add a new one … + backgroundColor: { + default: null, + parseHTML: element => { + return { + backgroundColor: element.getAttribute('data-background-color'), + } + }, + renderHTML: attributes => { + return { + 'data-background-color': attributes.backgroundColor, + style: `background-color: ${attributes.backgroundColor}`, + } + }, + }, + } + }, +}) + +const MenuBar = ({ editor }) => { + if (!editor) { + return null + } + + return ( + <> + + + + + + + + + + + + + + + + + + + + ) +} + +export default () => { + const editor = useEditor({ + extensions: [ + StarterKit, + Table.configure({ + resizable: true, + }), + TableRow, + TableHeader, + // Default TableCell + // TableCell, + // Custom TableCell with backgroundColor attribute + CustomTableCell, + ], + content: ` +

+ Have you seen our tables? They are amazing! +

+ +

+ Here is an example: +

+ + + + + + + + + + + + + + + + + + + + + + + + +
NameDescription
Cyndi Laupersingersongwriteractress
Philipp Kühndesignerdevelopermaker
Hans Pagelwrote thisthat’s it
+ `, + }) + + return ( +
+ + +
+ ) +} diff --git a/docs/src/demos/Examples/Tables/React/styles.scss b/docs/src/demos/Examples/Tables/React/styles.scss new file mode 100644 index 00000000..1c5191d3 --- /dev/null +++ b/docs/src/demos/Examples/Tables/React/styles.scss @@ -0,0 +1,117 @@ +/* Basic editor styles */ +.ProseMirror { + margin: 1rem 0; + + > * + * { + margin-top: 0.75em; + } + + ul, + ol { + padding: 0 1rem; + } + + h1, + h2, + h3, + h4, + h5, + h6 { + line-height: 1.1; + } + + code { + background-color: rgba(#616161, 0.1); + color: #616161; + } + + pre { + background: #0D0D0D; + color: #FFF; + font-family: 'JetBrainsMono', monospace; + padding: 0.75rem 1rem; + border-radius: 0.5rem; + + code { + color: inherit; + padding: 0; + background: none; + font-size: 0.8rem; + } + } + + img { + max-width: 100%; + height: auto; + } + + blockquote { + padding-left: 1rem; + border-left: 2px solid rgba(#0D0D0D, 0.1); + } + + hr { + border: none; + border-top: 2px solid rgba(#0D0D0D, 0.1); + margin: 2rem 0; + } +} + +/* Table-specific styling */ +.ProseMirror { + table { + border-collapse: collapse; + table-layout: fixed; + width: 100%; + margin: 0; + overflow: hidden; + + td, + th { + min-width: 1em; + border: 2px solid #ced4da; + padding: 3px 5px; + vertical-align: top; + box-sizing: border-box; + position: relative; + + > * { + margin-bottom: 0; + } + } + + th { + font-weight: bold; + text-align: left; + background-color: #f1f3f5; + } + + .selectedCell:after { + z-index: 2; + position: absolute; + content: ""; + left: 0; right: 0; top: 0; bottom: 0; + background: rgba(200, 200, 255, 0.4); + pointer-events: none; + } + + .column-resize-handle { + position: absolute; + right: -2px; + top: 0; + bottom: -2px; + width: 4px; + background-color: #adf; + pointer-events: none; + } + } +} + +.tableWrapper { + overflow-x: auto; +} + +.resize-cursor { + cursor: ew-resize; + cursor: col-resize; +} diff --git a/docs/src/demos/Examples/Tables/Vue/index.spec.js b/docs/src/demos/Examples/Tables/Vue/index.spec.js new file mode 100644 index 00000000..a1bc784e --- /dev/null +++ b/docs/src/demos/Examples/Tables/Vue/index.spec.js @@ -0,0 +1,7 @@ +context('/demos/Examples/Tables/Vue', () => { + before(() => { + cy.visit('/demos/Examples/Tables/Vue') + }) + + // TODO: Write tests +}) diff --git a/docs/src/demos/Examples/Tables/index.vue b/docs/src/demos/Examples/Tables/Vue/index.vue similarity index 63% rename from docs/src/demos/Examples/Tables/index.vue rename to docs/src/demos/Examples/Tables/Vue/index.vue index b4617c81..d9b1a45e 100644 --- a/docs/src/demos/Examples/Tables/index.vue +++ b/docs/src/demos/Examples/Tables/Vue/index.vue @@ -3,60 +3,57 @@ - - + + + + + + + + + + + + + + + + + diff --git a/docs/src/demos/Examples/Tables/index.spec.js b/docs/src/demos/Examples/Tables/index.spec.js deleted file mode 100644 index b2a23a10..00000000 --- a/docs/src/demos/Examples/Tables/index.spec.js +++ /dev/null @@ -1,7 +0,0 @@ -context('/demos/Examples/Tables', () => { - before(() => { - cy.visit('/demos/Examples/Tables') - }) - - // TODO: Write tests -}) diff --git a/docs/src/docPages/examples/tables.md b/docs/src/docPages/examples/tables.md index 897339d1..b597d564 100644 --- a/docs/src/docPages/examples/tables.md +++ b/docs/src/docPages/examples/tables.md @@ -4,4 +4,7 @@ Using this extension in a commercial project? [Become a sponsor](/sponsor) to fund its development! ::: - +