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

remove btn

parent 6c4231f8
No related branches found
No related tags found
1 merge request!348Multiple single
...@@ -6,7 +6,7 @@ import { v4 as uuidv4 } from 'uuid'; ...@@ -6,7 +6,7 @@ import { v4 as uuidv4 } from 'uuid';
import { Fragment } from 'prosemirror-model'; import { Fragment } from 'prosemirror-model';
import { TextSelection } from 'prosemirror-state'; import { TextSelection } from 'prosemirror-state';
import { wrapIn } from 'prosemirror-commands'; import { wrapIn } from 'prosemirror-commands';
import ToolBarBtn from './components/ToolBarBtn'; import ToolBarBtn from '../MultipleChoiceQuestionService/components/ToolBarBtn';
import helpers from '../MultipleChoiceQuestionService/helpers/helpers'; import helpers from '../MultipleChoiceQuestionService/helpers/helpers';
import Tools from '../lib/Tools'; import Tools from '../lib/Tools';
......
/* eslint react/prop-types: 0 */
import React, { useContext, useMemo } from 'react';
import { WaxContext } from 'wax-prosemirror-core';
import styled, { css } from 'styled-components';
import { MenuButton } from 'wax-prosemirror-components';
const activeStyles = css`
pointer-events: none;
`;
const StyledButton = styled(MenuButton)`
${props => props.active && activeStyles}
`;
const ToolBarBtn = ({ view = {}, item }) => {
const { active, icon, label, onlyOnMain, run, select, title } = item;
const context = useContext(WaxContext);
const {
view: { main },
activeViewId,
activeView,
} = useContext(WaxContext);
if (onlyOnMain) view = main;
const isEditable = main.props.editable(editable => {
return editable;
});
const { state } = view;
const isActive = !!(
active(state, activeViewId) && select(state, activeViewId)
);
let isDisabled = !select(state, activeView);
if (!isEditable) isDisabled = true;
const ToolBarBtnComponent = useMemo(
() => (
<StyledButton
active={isActive || false}
disabled={isDisabled}
iconName={icon}
label={label}
onMouseDown={e => {
e.preventDefault();
item.run(view, main, context);
}}
title={title}
/>
),
[isActive, isDisabled],
);
return ToolBarBtnComponent;
};
export default ToolBarBtn;
...@@ -6,7 +6,7 @@ import { v4 as uuidv4 } from 'uuid'; ...@@ -6,7 +6,7 @@ import { v4 as uuidv4 } from 'uuid';
import { Fragment } from 'prosemirror-model'; import { Fragment } from 'prosemirror-model';
import { TextSelection } from 'prosemirror-state'; import { TextSelection } from 'prosemirror-state';
import { wrapIn } from 'prosemirror-commands'; import { wrapIn } from 'prosemirror-commands';
import ToolBarBtn from './components/ToolBarBtn'; import ToolBarBtn from '../MultipleChoiceQuestionService/components/ToolBarBtn';
import helpers from '../MultipleChoiceQuestionService/helpers/helpers'; import helpers from '../MultipleChoiceQuestionService/helpers/helpers';
import Tools from '../lib/Tools'; import Tools from '../lib/Tools';
......
/* eslint react/prop-types: 0 */
import React, { useContext, useMemo } from 'react';
import { WaxContext } from 'wax-prosemirror-core';
import styled, { css } from 'styled-components';
import { MenuButton } from 'wax-prosemirror-components';
const activeStyles = css`
pointer-events: none;
`;
const StyledButton = styled(MenuButton)`
${props => props.active && activeStyles}
`;
const ToolBarBtn = ({ view = {}, item }) => {
const { active, icon, label, onlyOnMain, run, select, title } = item;
const context = useContext(WaxContext);
const {
view: { main },
activeViewId,
activeView,
} = useContext(WaxContext);
if (onlyOnMain) view = main;
const isEditable = main.props.editable(editable => {
return editable;
});
const { state } = view;
const isActive = !!(
active(state, activeViewId) && select(state, activeViewId)
);
let isDisabled = !select(state, activeView);
if (!isEditable) isDisabled = true;
const ToolBarBtnComponent = useMemo(
() => (
<StyledButton
active={isActive || false}
disabled={isDisabled}
iconName={icon}
label={label}
onMouseDown={e => {
e.preventDefault();
item.run(view, main, context);
}}
title={title}
/>
),
[isActive, isDisabled],
);
return ToolBarBtnComponent;
};
export default ToolBarBtn;
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