Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/volto-slate/news/8409.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move table row and column insertion and deletion controls to a floating menu above the currently selected row. @r4-rahul123
33 changes: 30 additions & 3 deletions packages/volto-slate/src/blocks/Table/TableBlockEdit.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect, useCallback, useMemo } from 'react';
import { useState, useEffect, useCallback, useMemo, useRef } from 'react';
import PropTypes from 'prop-types';
import isEmpty from 'lodash/isEmpty';
import map from 'lodash/map';
Expand Down Expand Up @@ -182,13 +182,35 @@ const Edit = (props) => {
row: 0,
cell: 0,
});
const tableRef = useRef(null);
const [toolbarTop, setToolbarTop] = useState(0);

// If selected prop is unset, update the state
useEffect(() => {
if (!selected) {
setSelectedCell(null);
}
}, [selected]);

useEffect(() => {
if (!selected || !selectedCell || !tableRef.current) {
setToolbarTop(0);
return;
}
let rowEl;
if (!data.table?.hideHeaders && selectedCell.row === 0) {
rowEl = tableRef.current.querySelector('thead tr');
} else {
const bodyRows = tableRef.current.querySelectorAll('tbody tr');
const rowIndex = selectedCell.row > 0 ? selectedCell.row - 1 : 0;
rowEl = bodyRows[rowIndex];
}
if (rowEl) {
setToolbarTop(rowEl.offsetTop);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selected, selectedCell?.row, data.table?.hideHeaders]);

useEffect(() => {
if (!data.table || isEmpty(data.table)) {
onChangeBlock(block, {
Expand Down Expand Up @@ -348,9 +370,14 @@ const Edit = (props) => {
}, [data, block, onChangeBlock, selectedCell]);

return (
<div className={cx('block table', { selected })}>
<div ref={tableRef} className={cx('block table', { selected })}>
{selected && (
<div className="toolbar">
<div
className="toolbar"
style={{
top: `${toolbarTop}px`,
}}
>
<Button.Group>
<Button
icon
Expand Down
1 change: 1 addition & 0 deletions packages/volto/news/8409.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move table row and column insertion and deletion controls to a floating menu above the currently selected row. @r4-rahul123
10 changes: 9 additions & 1 deletion packages/volto/theme/themes/pastanaga/extras/blocks.less
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,16 @@ body.has-toolbar.has-sidebar-collapsed .ui.wrapper > .ui.inner.block.full {
line-height: @headerLineHeight;
}

.ui.block.table {
.ui.block.table,
.block.table {
--toolbar-gap: 2px;
border: 0;

.toolbar {
top: 0;
transform: translate(-50%, calc(-100% - var(--toolbar-gap)));
transition: top 0.15s ease-in-out;
}
}

.block {
Expand Down
Loading