Skip to content

Commit

Permalink
feat: disable unfinished tools, add drag to tools
Browse files Browse the repository at this point in the history
  • Loading branch information
singuerinc committed May 2, 2018
1 parent 1ff293b commit 3cc31c3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 28 deletions.
6 changes: 3 additions & 3 deletions app/components/help/Help.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import styled from 'styled-components';
import { ToolboxIcon } from '../toolbox/ToolboxIcon';
import { ToolItem } from '../toolbox/ToolboxItem';
import { ToolboxItem } from '../toolbox/ToolboxItem';

const Element = ({
className,
Expand All @@ -12,9 +12,9 @@ const Element = ({
}) => (
<div className={className}>
<ul>
<ToolItem onClick={close}>
<ToolboxItem onClick={close}>
<ToolboxIcon icon="x" />
</ToolItem>
</ToolboxItem>
</ul>
<h1>Keyboard shortcuts</h1>
<div>
Expand Down
86 changes: 65 additions & 21 deletions app/components/toolbox/Toolbox.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as React from 'react';
import styled from 'styled-components';
import * as interactjs from 'interactjs';
import { Tool, ToolType } from './Tool';
import { ToolboxIcon } from './ToolboxIcon';
import { ToolItem } from './ToolboxItem';
import { ToolboxItem } from './ToolboxItem';
import { ToolboxItemDumb } from './ToolboxItemDumb';

const Wrapper = styled.ul.attrs<{
x: number;
Expand Down Expand Up @@ -49,13 +51,29 @@ interface State {
visible: boolean;
onTop: boolean;
isMenuOpen: boolean;
x: number;
y: number;
}

const setPosition = (el, x, y) => {
el.style.webkitTransform = el.style.transform = `translate(${x}px,${y}px)`;
el.setAttribute('data-x', x);
el.setAttribute('data-y', y);
};

export class Toolbox extends React.Component<Props, State> {
private el: HTMLDivElement;

static getDerivedStateFromProps(nextProps, prevState) {
return { ...nextProps, ...prevState };
}

state = {
visible: true,
onTop: true,
isMenuOpen: false
isMenuOpen: true,
x: 0,
y: 0
};

setOnTop = (value: boolean) => {
Expand All @@ -70,6 +88,25 @@ export class Toolbox extends React.Component<Props, State> {
});
};

componentDidMount() {
setPosition(this.el, this.state.x, this.state.y);

interactjs(this.el).draggable({
onmove: (event) => {
const { dx, dy, target } = event;

event.preventDefault();

const x = (parseFloat(target.getAttribute('data-x')) || 0) + dx;
const y = (parseFloat(target.getAttribute('data-y')) || 0) + dy;

setPosition(target, x, y);

this.setState({ x, y });
}
});
}

render() {
const {
isStuffVisible,
Expand All @@ -80,38 +117,45 @@ export class Toolbox extends React.Component<Props, State> {
setVisibility,
toggleHelp
} = this.props;
const { onTop, isMenuOpen } = this.state;
const { isMenuOpen } = this.state;
return (
<Wrapper x={x} y={y}>
<ToolItem onClick={() => this.setMenuOpen(!isMenuOpen)}>
<ToolboxIcon icon={isMenuOpen ? 'x' : 'menu'} />
</ToolItem>
<Wrapper
x={x}
y={y}
innerRef={(el: HTMLDivElement) => {
this.el = el;
}}
>
{/* <ToolItem onClick={() => this.setMenuOpen(!isMenuOpen)}> */}
<ToolboxItemDumb>
<ToolboxIcon icon={isMenuOpen ? 'more-vertical' : 'menu'} />
</ToolboxItemDumb>
{isMenuOpen && (
<MenuWrapper>
<ToolSpace />
<ToolItem onClick={() => this.setOnTop(!onTop)}>
{/* <ToolItem onClick={() => this.setOnTop(!onTop)}>
<ToolboxIcon icon={onTop ? 'zap' : 'zap-off'} />
</ToolItem>
<ToolItem onClick={() => setVisibility(!isStuffVisible)}>
</ToolItem> */}
<ToolboxItem onClick={() => setVisibility(!isStuffVisible)}>
<ToolboxIcon icon={isStuffVisible ? 'eye' : 'eye-off'} />
</ToolItem>
</ToolboxItem>
<ToolSpace />
<ToolItem onClick={() => create(Tool.GUIDE)}>
<ToolboxItem onClick={() => create(Tool.GUIDE)}>
<ToolboxIcon icon="layout" />
</ToolItem>
<ToolItem onClick={() => create(Tool.RULER)}>
</ToolboxItem>
{/* <ToolboxItem onClick={() => create(Tool.RULER)}>
<ToolboxIcon icon="square" />
</ToolItem>
<ToolItem onClick={() => create(Tool.ONION)}>
</ToolboxItem> */}
<ToolboxItem onClick={() => create(Tool.ONION)}>
<ToolboxIcon icon="image" />
</ToolItem>
<ToolItem onClick={() => toggle(Tool.GRID)}>
</ToolboxItem>
<ToolboxItem onClick={() => toggle(Tool.GRID)}>
<ToolboxIcon icon="grid" />
</ToolItem>
</ToolboxItem>
<ToolSpace />
<ToolItem onClick={() => toggleHelp()}>
<ToolboxItem onClick={() => toggleHelp()}>
<ToolboxIcon icon="help-circle" />
</ToolItem>
</ToolboxItem>
</MenuWrapper>
)}
</Wrapper>
Expand Down
4 changes: 2 additions & 2 deletions app/components/toolbox/ToolboxItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import styled from 'styled-components';
import { Color } from '../../utils/Color';

export const ToolItem = styled.li`
background-color: ${Color.GRAY};
export const ToolboxItem = styled.li`
background-color: ${Color.CYAN};
display: flex;
flex: 1 1 auto;
text-align: center;
Expand Down
12 changes: 12 additions & 0 deletions app/components/toolbox/ToolboxItemDumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import styled from 'styled-components';

export const ToolboxItemDumb = styled.li`
background-color: #333;
display: flex;
flex: 1 1 auto;
text-align: center;
justify-content: center;
flex-direction: column;
padding: 6px 8px;
margin: 0;
`;
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "overlay",
"productName": "Overlay",
"version": "0.0.3",
"description": "",
"description": "A set of tools for devs and designers to measure, align and overlay on-screen graphics and layouts.",
"main": "./main.js",
"author": {
"name": "Nahuel Scotti",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "overlay",
"productName": "Overlay",
"version": "0.0.3",
"description": "",
"description":
"A set of tools for devs and designers to measure, align and overlay on-screen graphics and layouts.",
"main": "main.js",
"scripts": {
"test": "cross-env NODE_ENV=test node --trace-warnings ./test/runTests.js",
Expand Down

0 comments on commit 3cc31c3

Please sign in to comment.