Add Tables feature to the Editor (#340)

* Install table extension

* Add the table extension to editor

* Add table button to toolbar

* Fix packages

* Add table icon

* Add table style

* Change table style

* Add buttons to add rows and columns

* Add buttons to remove columns and rows

* Fix resize icon
This commit is contained in:
Eduard-Constantin Ibinceanu 2024-10-23 20:08:41 +03:00 committed by GitHub
parent e6979ed1b4
commit ba6d17827b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 154 additions and 0 deletions

View file

@ -7,6 +7,11 @@ import {
ArrowRightIcon,
DividerVerticalIcon,
ListBulletIcon,
TableIcon,
RowsIcon,
ColumnsIcon,
SectionIcon,
ContainerIcon,
} from '@radix-ui/react-icons'
import {
AlertCircle,
@ -92,6 +97,34 @@ export const ToolbarButtons = ({ editor, props }: any) => {
<option value="5">Heading 5</option>
<option value="6">Heading 6</option>
</ToolSelect>
<DividerVerticalIcon
style={{ marginTop: 'auto', marginBottom: 'auto', color: 'grey' }}
/>
<ToolBtn content={'Create table'}
onClick={() => editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run()}
>
<TableIcon/>
</ToolBtn>
<ToolBtn content={'Insert row'}
onClick={() => editor.chain().focus().addRowAfter().run()}
>
<RowsIcon/>
</ToolBtn>
<ToolBtn content={'Insert column'}
onClick={() => editor.chain().focus().addColumnAfter().run()}
>
<ColumnsIcon/>
</ToolBtn>
<ToolBtn content={'Remove column'}
onClick={() => editor.chain().focus().deleteColumn().run()}
>
<ContainerIcon/>
</ToolBtn>
<ToolBtn content={'Remove row'}
onClick={() => editor.chain().focus().deleteRow().run()}
>
<SectionIcon/>
</ToolBtn>
{/* TODO: fix this : toggling only works one-way */}
<DividerVerticalIcon
style={{ marginTop: 'auto', marginBottom: 'auto', color: 'grey' }}