Skip to content
Snippets Groups Projects
TableDropDown.js 1.67 KiB
Newer Older
chris's avatar
chris committed
/* eslint react/prop-types: 0 */
import React from 'react';
import styled from 'styled-components';
import * as tablesFn from 'prosemirror-tables';
import Dropdown from 'react-dropdown';
import 'react-dropdown/style.css';
chris's avatar
chris committed

const DropdownStyled = styled(Dropdown)`
chris's avatar
chris committed
  display: inline-flex;
  cursor: not-allowed;
  opacity: ${props => (props.select ? 1 : 0.4)};
chris's avatar
chris committed
  pointer-events: ${props => (props.select ? 'default' : 'none')};
chris's avatar
chris committed
  .Dropdown-control {
    border: none;
  }
chris's avatar
chris committed
  .Dropdown-arrow {
chris's avatar
chris committed
    right: 25px;
chris's avatar
chris committed
    top: 14px;
chris's avatar
chris committed
  }
chris's avatar
chris committed
  .Dropdown-menu {
    width: 120%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    .Dropdown-option {
      width: 100%;
    }
chris's avatar
chris committed
  }
chris's avatar
chris committed
`;

const dropDownOptions = [
chris's avatar
chris committed
  { label: 'add column before', value: 'addColumnBefore' },
  { label: 'add column after', value: 'addColumnAfter' },
  { label: 'Delete column', value: 'deleteColumn' },
  { label: 'Insert row before', value: 'addRowBefore' },
  { label: 'Insert row after', value: 'addRowAfter' },
  { label: 'Delete row', value: 'deleteRow' },
  { label: 'Delete table', value: 'deleteTable' },
  { label: 'Merge cells', value: 'mergeCells' },
  { label: 'Split cell', value: 'splitCell' },
  { label: 'Toggle header column', value: 'toggleHeaderColumn' },
  { label: 'Toggle header row', value: 'toggleHeaderRow' },
  { label: 'Toggle header cells', value: 'toggleHeaderCell' },
chris's avatar
chris committed
];

const TableDropDown = ({ view: { dispatch, state }, item }) => (
chris's avatar
chris committed
  <DropdownStyled
    options={dropDownOptions}
    onChange={option => {
chris's avatar
chris committed
      item.run(state, dispatch, tablesFn[option.value]);
chris's avatar
chris committed
    }}
    placeholder="Table Options"
    select={item.select && item.select(state)}
  />
);
chris's avatar
chris committed

chris's avatar
chris committed
export default TableDropDown;