Skip to content
Snippets Groups Projects
Commit 4daf6b4d authored by Yannis Barlas's avatar Yannis Barlas
Browse files

fix select when on notes surface

parent 298043e2
No related branches found
No related tags found
1 merge request!171Buttons
...@@ -22,7 +22,8 @@ eslint.parserOptions = { ...@@ -22,7 +22,8 @@ eslint.parserOptions = {
}; };
eslint.rules = { eslint.rules = {
'sort-keys': 'off', 'class-methods-use-this': [1, { exceptMethods: ['run', 'enable', 'active'] }],
// 'import/no-named-as-default': 0,
'import/no-extraneous-dependencies': [ 'import/no-extraneous-dependencies': [
'error', 'error',
{ {
...@@ -30,8 +31,6 @@ eslint.rules = { ...@@ -30,8 +31,6 @@ eslint.rules = {
}, },
], ],
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }], 'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
'class-methods-use-this': [1, { exceptMethods: ['run', 'enable', 'active'] }],
'react/prop-types': [ 'react/prop-types': [
2, 2,
{ {
...@@ -45,7 +44,7 @@ eslint.rules = { ...@@ -45,7 +44,7 @@ eslint.rules = {
], ],
}, },
], ],
// 'import/no-named-as-default': 0, 'sort-keys': 'off',
}; };
module.exports = eslint; module.exports = eslint;
import React, { useContext } from 'react'; import React, { useContext } from 'react';
// import styled from 'styled-components';
// import { ButtonStyles } from 'wax-prosemirror-themes';
import { WaxContext } from 'wax-prosemirror-core'; import { WaxContext } from 'wax-prosemirror-core';
import MenuButton from '../ui/buttons/MenuButton'; import MenuButton from '../ui/buttons/MenuButton';
// const ButtonStyled = styled.button`
// ${ButtonStyles};
// opacity: ${props => (props.select ? 1 : 0.4)};
// pointer-events: ${props => (props.select ? 'default' : 'none')};
// color: ${props => (props.isActive ? 'white' : props.theme.colorButton)};
// background-color: ${props =>
// props.isActive ? props.theme.colorPrimary : 'transparent'};
// &:hover {
// background-color: ${props =>
// props.isActive ? props.theme.colorPrimary : 'transparent'};
// }
// `;
const Button = ({ view = {}, item }) => { const Button = ({ view = {}, item }) => {
const { active, enable, icon, label, onlyOnMain, run, select, title } = item; const { active, enable, icon, label, onlyOnMain, run, select, title } = item;
...@@ -37,7 +22,7 @@ const Button = ({ view = {}, item }) => { ...@@ -37,7 +22,7 @@ const Button = ({ view = {}, item }) => {
const isActive = active && active(state); const isActive = active && active(state);
const isDisabled = const isDisabled =
enable && !enable(state) && select && select(view.state, activeViewId); enable && !enable(state) && !(select && select(view.state, activeViewId));
return ( return (
<MenuButton <MenuButton
......
...@@ -5,19 +5,12 @@ import styled from 'styled-components'; ...@@ -5,19 +5,12 @@ import styled from 'styled-components';
import MenuButton from '../ui/buttons/MenuButton'; import MenuButton from '../ui/buttons/MenuButton';
const UploadImage = styled.div` const Wrapper = styled.div`
/* opacity: ${props => (props.select ? 1 : 0.4)};
pointer-events: ${props => (props.select ? 'default' : 'none')};
display: inline-flex;
padding: 0px 10px; */
input { input {
display: none; display: none;
} }
`; `;
// TO DO -- select should be done with MenuButton's disabled prop
const ImageUpload = ({ item, fileUpload, view }) => { const ImageUpload = ({ item, fileUpload, view }) => {
const { activeViewId } = useContext(WaxContext); const { activeViewId } = useContext(WaxContext);
...@@ -25,7 +18,7 @@ const ImageUpload = ({ item, fileUpload, view }) => { ...@@ -25,7 +18,7 @@ const ImageUpload = ({ item, fileUpload, view }) => {
const handleMouseDown = () => inputRef.current.click(); const handleMouseDown = () => inputRef.current.click();
return ( return (
<UploadImage> <Wrapper>
<label htmlFor="file-upload"> <label htmlFor="file-upload">
<MenuButton <MenuButton
active={false} active={false}
...@@ -42,7 +35,7 @@ const ImageUpload = ({ item, fileUpload, view }) => { ...@@ -42,7 +35,7 @@ const ImageUpload = ({ item, fileUpload, view }) => {
type="file" type="file"
/> />
</label> </label>
</UploadImage> </Wrapper>
); );
}; };
export default ImageUpload; export default ImageUpload;
/* eslint react/prop-types: 0 */
import React, { useState, useContext } from 'react'; import React, { useState, useContext } from 'react';
// import styled from 'styled-components';
// import { ButtonStyles } from 'wax-prosemirror-themes';
import { WaxContext } from 'wax-prosemirror-core'; import { WaxContext } from 'wax-prosemirror-core';
import Dropdown from '../../ui/buttons/Dropdown'; import Dropdown from '../../ui/buttons/Dropdown';
import InsertTableTool from '../../ui/tables/InsertTableTool'; import InsertTableTool from '../../ui/tables/InsertTableTool';
// const ButtonStyled = styled.button`
// ${ButtonStyles};
// opacity: ${props => (props.select ? 1 : 0.4)};
// pointer-events: ${props => (props.select ? 'default' : 'none')};
// color: ${props => (props.isActive ? 'white' : props.theme.colorButton)};
// background-color: ${props =>
// props.isActive ? props.theme.colorPrimary : 'transparent'};
// &:hover {
// background-color: ${props =>
// props.isActive ? props.theme.colorPrimary : 'transparent'};
// }
// `;
// const InsertTableToolContainer = styled.div`
// display: block !important;
// height: auto;
// top: 53px;
// left: 556px;
// position: absolute;
// `;
const CreateTable = ({ view = {}, item }) => { const CreateTable = ({ view = {}, item }) => {
const { const {
view: { main }, view: { main },
// activeViewId, activeViewId,
} = useContext(WaxContext); } = useContext(WaxContext);
if (item.onlyOnMain) { if (item.onlyOnMain) {
view = main; view = main;
} }
const [showTool, setShowTool] = useState(false);
const toggleShowTool = () => setShowTool(!showTool);
const { state, dispatch } = view; const { state, dispatch } = view;
const [isTableToolDisplayed, setTableToolDisplay] = useState(false); const { enable, icon, run, select, title } = item;
const dropComponent = (
<InsertTableTool
onGridSelect={colRows => {
run(colRows, state, dispatch);
}}
/>
);
// const CreateButton = ( const isDisabled =
// <ButtonStyled enable && !enable(state) && !(select && select(state, activeViewId));
// type="button"
// isActive={isTableToolDisplayed}
// title={item.title}
// disabled={item.enable && !item.enable(view.state)}
// onMouseDown={e => {
// e.preventDefault();
// setTableToolDisplay(!isTableToolDisplayed);
// }}
// select={item.select && item.select(view.state, activeViewId)}
// >
// {item.content}
// </ButtonStyled>
// );
// return isTableToolDisplayed ? (
// <>
// {CreateButton}
// <InsertTableToolContainer>
// <InsertTableTool
// onGridSelect={colRows => {
// item.run(colRows, state, dispatch);
// }}
// />
// </InsertTableToolContainer>
// </>
// ) : (
// <>{CreateButton}</>
// );
// select pending
return ( return (
<Dropdown <Dropdown
active={isTableToolDisplayed} active={showTool}
dropComponent={ dropComponent={dropComponent}
<InsertTableTool iconName={icon}
onGridSelect={colRows => { disabled={isDisabled}
item.run(colRows, state, dispatch); onClick={toggleShowTool}
}} title={title}
/>
}
iconName={item.icon}
disabled={item.enable && !item.enable(view.state)}
onClick={() => setTableToolDisplay(!isTableToolDisplayed)}
title={item.title}
/> />
); );
}; };
......
...@@ -17,7 +17,7 @@ const DropWrapper = styled.div` ...@@ -17,7 +17,7 @@ const DropWrapper = styled.div`
`; `;
const Dropdown = props => { const Dropdown = props => {
const { className, dropComponent, iconName, label, title } = props; const { className, disabled, dropComponent, iconName, label, title } = props;
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
...@@ -27,6 +27,7 @@ const Dropdown = props => { ...@@ -27,6 +27,7 @@ const Dropdown = props => {
<Wrapper className={className}> <Wrapper className={className}>
<MenuButton <MenuButton
active={isOpen} active={isOpen}
disabled={disabled}
iconName={iconName} iconName={iconName}
label={label} label={label}
onMouseDown={() => setIsOpen(!isOpen)} onMouseDown={() => setIsOpen(!isOpen)}
...@@ -39,6 +40,7 @@ const Dropdown = props => { ...@@ -39,6 +40,7 @@ const Dropdown = props => {
}; };
Dropdown.propTypes = { Dropdown.propTypes = {
disabled: PropTypes.bool,
dropComponent: PropTypes.node.isRequired, dropComponent: PropTypes.node.isRequired,
iconName: PropTypes.string, iconName: PropTypes.string,
label: PropTypes.string, label: PropTypes.string,
...@@ -46,6 +48,7 @@ Dropdown.propTypes = { ...@@ -46,6 +48,7 @@ Dropdown.propTypes = {
}; };
Dropdown.defaultProps = { Dropdown.defaultProps = {
disabled: false,
iconName: null, iconName: null,
label: null, label: null,
title: null, title: null,
......
...@@ -36,7 +36,7 @@ class Note extends Tools { ...@@ -36,7 +36,7 @@ class Note extends Tools {
get enable() { get enable() {
return state => { return state => {
return true; return false;
}; };
} }
} }
...@@ -33,13 +33,10 @@ class DisplayText extends ToolGroup { ...@@ -33,13 +33,10 @@ class DisplayText extends ToolGroup {
icon: 'title', icon: 'title',
component: ( component: (
<BlockLevelTools <BlockLevelTools
groups={this._toolGroups[0].groups.map(group => { groups={this._toolGroups[0].groups.map(group => ({
console.log(group); groupName: group.title.props.title,
return { items: group._tools,
groupName: group.title.props.title, }))}
items: group._tools,
};
})}
view={view} view={view}
/> />
), ),
......
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