From 581ee6c1c9eaf9d96671196962855b6f7c2f43aa Mon Sep 17 00:00:00 2001 From: Felix Henninger Date: Wed, 12 Aug 2020 19:03:38 +0200 Subject: [PATCH] Add column actions in UI --- .../components/Content/Loop/Grid/header.js | 70 +++++++++++++++---- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/packages/builder/src/components/ComponentOptions/components/Content/Loop/Grid/header.js b/packages/builder/src/components/ComponentOptions/components/Content/Loop/Grid/header.js index 615bd786d..1fcd8431c 100644 --- a/packages/builder/src/components/ComponentOptions/components/Content/Loop/Grid/header.js +++ b/packages/builder/src/components/ComponentOptions/components/Content/Loop/Grid/header.js @@ -4,10 +4,12 @@ import { InputGroupButtonDropdown, DropdownToggle, DropdownMenu, DropdownItem, InputGroup } from 'reactstrap' import classnames from 'classnames' +import { useArrayContext } from '../../../../../Form/array' +import { ButtonCell } from '../../../../../Form/table' import Icon from '../../../../../Icon' import { FastField, useField } from 'formik' -const CellTypeDropdown = ({ name, disabled=false }) => { +const CellTypeDropdown = ({ name, index, actions, disabled=false }) => { const [field, , helpers] = useField(name) const [dropdownOpen, setDropdownOpen] = useState(false) @@ -61,12 +63,29 @@ const CellTypeDropdown = ({ name, disabled=false }) => { > Boolean (binary) + { + actions + ?
+ + + Actions + + { + Object.entries(actions).map(([k, v], i) => + v(index) } key={ i }> + { k } + + ) + } +
+ :
+ } ) } -export const HeaderCell = ({ index }) => +export const HeaderCell = ({ index, actions }) => className="form-control text-monospace font-weight-bolder" style={{ height: '42px' }} /> - + -export default ({ name, columns }) => - - - - { Array(columns).fill(null).map((_, i) => - - - - ) } - - - +export default ({ name, columns }) => { + const { addColumn, fillColumn, clearColumn, deleteColumn } = useArrayContext() + + return ( + + + + { Array(columns).fill(null).map((_, i) => + + + + ) } + addColumn('', { name: '', type: 'string' }) } + disabled={ columns >= 12 } + /> + + + ) +}