Skip to content
Snippets Groups Projects
Commit a23c2d55 authored by chris's avatar chris
Browse files

add new component

parent ca3cc28a
No related branches found
No related tags found
This commit is part of merge request !348. Comments created here will be created in the context of that merge request.
/* eslint react/prop-types: 0 */
import React, { useContext, useMemo } from 'react';
import { WaxContext } from 'wax-prosemirror-core';
import MenuButton from '../ui/buttons/MenuButton';
const UndoRedoButton = ({ view = {}, item }) => {
const { active, icon, label, run, select, title } = item;
const {
view: { main },
activeViewId,
activeView,
} = useContext(WaxContext);
const isEditable = main.props.editable(editable => {
return editable;
});
const { state } = view;
const handleMouseDown = (e, editorState, editorDispatch) => {
e.preventDefault();
run(editorState, editorDispatch);
};
const isActive = !!(
active(activeView.state, activeViewId) &&
select(state, activeViewId, activeView)
);
let isDisabled = !select(state, activeViewId, activeView);
if (!isEditable) isDisabled = true;
const UndoRedoButtonComponent = useMemo(
() => (
<MenuButton
active={isActive || false}
disabled={isDisabled}
iconName={icon}
label={label}
onMouseDown={e => handleMouseDown(e, main.state, main.dispatch)}
title={title}
/>
),
[isActive, isDisabled],
);
return UndoRedoButtonComponent;
};
export default UndoRedoButton;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment