Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

feat: add tab switch to hide pages and sidebar #560

Merged
merged 6 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/bug-report/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface BugReportProps {

const StyledBugReport = styled.div`
justify-self: right;
margin-right: -${getSpace(SpaceSize.XXL) * 3 - getSpace(SpaceSize.L)}px; // align to top right corner
margin-right: -${getSpace(SpaceSize.XXL) * 2 + getSpace(SpaceSize.S - SpaceSize.L)}px; // align to top right corner
`;

export const BugReport: React.StatelessComponent<BugReportProps> = props => (
Expand Down
2 changes: 1 addition & 1 deletion src/components/chrome/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const StyledChrome = styled.div`
align-items: center;
width: 100%;
height: 40px;
padding: ${getSpace(SpaceSize.XS)}px ${getSpace(SpaceSize.XXL) * 3}px;
padding: 0 ${getSpace(SpaceSize.XXL) * 2 + getSpace(SpaceSize.S)}px;
border-bottom: 1px solid ${Color.Grey90};
@media screen and (-webkit-min-device-pixel-ratio: 2) {
border-bottom-width: 0.5px;
Expand Down
24 changes: 21 additions & 3 deletions src/components/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ export enum IconName {
ArrowFillRight,
ArrowFillLeft,
Check,
Uncheck,
Robo,
Element,
Page,
Plus,
Pattern,
Search
Robo,
Search,
Uncheck
}

export interface IconProps {
Expand Down Expand Up @@ -101,6 +103,22 @@ const icons: { readonly [key: string]: JSX.Element[][] | JSX.Element[] } = {
d="M14.89 13.477l6.024 6.023-1.414 1.414-6.023-6.023a6 6 0 1 1 1.414-1.414zm-1.649-1.132a4 4 0 1 0-.896.896l.896-.896z"
/>
]
],
[IconName.Page]: [
[
<path
key="page"
d="M6 6h10c.552 0 1 .418 1 .933v12.134c0 .515-.448.933-1 .933H6c-.552 0-1-.418-1-.933V6.933C5 6.418 5.448 6 6 6zm1.5 4a.5.5 0 1 0 0 1h3a.5.5 0 1 0 0-1h-3zm0-2a.5.5 0 0 0 0 1h5a.5.5 0 1 0 0-1h-5zm0 4a.5.5 0 1 0 0 1h6a.5.5 0 1 0 0-1h-6zM19 4.5v13a.5.5 0 1 1-1 0V5H8.5a.5.5 0 0 1 0-1h10a.5.5 0 0 1 .5.5z"
/>
]
],
[IconName.Element]: [
[
<path
key="element"
d="M12.757 5.077l7.04 5.28a1 1 0 0 1 0 1.6l-7.04 5.28a1 1 0 0 1-1.2 0l-7.04-5.28a1 1 0 0 1 0-1.6l7.04-5.28a1 1 0 0 1 1.2 0zm7.127 8.63c.151.241.093.557-.133.729l-7.06 5.35a1 1 0 0 1-1.205.002l-7.29-5.494A.494.494 0 0 1 4.1 13.6l.003-.004a.506.506 0 0 1 .705-.095l6.677 5.035a1 1 0 0 0 1.207-.001l6.527-4.951a.459.459 0 0 1 .665.122z"
/>
]
]
};

Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export * from './search';
export * from './select';
export * from './space';
export * from './splash-screen';
export * from './tab-switch';
export * from './teaser';
export * from './tag';
export * from './view-switch';
1 change: 1 addition & 0 deletions src/components/tab-switch/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './tab-switch';
8 changes: 8 additions & 0 deletions src/components/tab-switch/pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "tab-switch",
"displayName": "Tab Switch",
"description": "Tab to switch between Views",
"version": "1.0.0",
"tags": ["tab", "switch"],
"flag": "alpha"
}
40 changes: 40 additions & 0 deletions src/components/tab-switch/tab-switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Color } from '../colors';
import { Copy } from '../copy';
import { Icon, IconName, IconSize } from '../icons';
import * as React from 'react';
import { getSpace, SpaceSize } from '../space';
import styled from 'styled-components';

export interface TabSwitchProps {
active?: boolean;
Copy link
Contributor

@marionebl marionebl Jun 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use an required enum instead:

enum TabSwitchState {
  Active,
  Default
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did that!

icon?: IconName;
label?: string;
onClick?: React.MouseEventHandler<HTMLElement>;
title: string;
}

const StyledTabSwitch = styled.div`
display: flex;
box-sizing: border-box;
padding: 0 ${getSpace(SpaceSize.XS)}px;
color: ${(props: TabSwitchProps) => (props.active ? Color.Blue : Color.Grey50)};
height: 100%;
align-items: center;

&:active {
color: ${Color.Grey20};
}
`;

export const TabSwitch: React.SFC<TabSwitchProps> = props => (
<StyledTabSwitch
active={props.active}
icon={props.icon}
label={props.label}
onClick={props.onClick}
title={props.title}
>
{props.icon && <Icon name={props.icon} size={IconSize.S} />}
{props.label && <Copy>{props.label}</Copy>}
</StyledTabSwitch>
);
50 changes: 0 additions & 50 deletions src/components/view-switch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ export interface ViewSwitchProps {
title: string;
}

export interface StyledViewButtonProps {
onClick?: React.MouseEventHandler<SVGElement>;
}

export interface ViewButtonProps {
onClick?: React.MouseEventHandler<SVGElement>;
rotateIcon?: boolean;
title: string;
}

export interface ViewTitleProps {
fontSize?: CopySize;
justify?: JustifyType;
title: string;
}

interface StyledIconProps extends IconProps {
rotate?: boolean;
visible: boolean;
Expand All @@ -56,21 +40,6 @@ const StyledViewSwitch = styled.div`
props.fontSize ? `${props.fontSize}px` : `${CopySize.S}px`};
`;

// tslint:disable-next-line:no-any
const StyledViewButton: any = styled.div`
display: flex;
align-self: center;
justify-self: start;
font-size: ${`${CopySize.S}px`};
border-radius: ${getSpace(SpaceSize.XXS)}px;
&:hover {
background: ${Color.Grey90};
}
&:active {
background: ${Color.Grey80};
}
`;

const StyledTitle = styled.strong`
position: relative;
align-self: center;
Expand Down Expand Up @@ -103,25 +72,6 @@ const StyledIcons = styled(Icon)`
}
`;

export const ViewTitle: React.SFC<ViewTitleProps> = (props): JSX.Element => (
<StyledViewSwitch justify={props.justify} fontSize={props.fontSize}>
<StyledTitle>{props.title}</StyledTitle>
</StyledViewSwitch>
);

export const ViewButton: React.SFC<ViewButtonProps> = (props): JSX.Element => (
<StyledViewButton onClick={props.onClick}>
<StyledIcons
color={Color.Grey60}
size={IconSize.XS}
name={IconName.ArrowLeft}
rotate={props.rotateIcon}
visible={true}
/>
<StyledTitle grow>{props.title}</StyledTitle>
</StyledViewButton>
);

export const ViewSwitch: React.SFC<ViewSwitchProps> = (props): JSX.Element => (
<StyledViewSwitch justify={props.justify} fontSize={props.fontSize}>
<StyledIcons
Expand Down
29 changes: 11 additions & 18 deletions src/container/chrome/chrome-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import * as AlvaUtil from '../../alva-util';
import { BugReport, Chrome, CopySize, ViewSwitch } from '../../components';
import { ServerMessageType } from '../../message';
import * as MobxReact from 'mobx-react';
import { OverviewSwitchContainer } from './overview-switch-container';
import { ChromeSwitch } from './chrome-switch';
import * as React from 'react';
import * as Sender from '../../message/client';
import { ViewStore } from '../../store';
import * as Types from '../../types';
import * as uuid from 'uuid';

interface InjectedChromeContainerProps {
Expand Down Expand Up @@ -58,22 +57,16 @@ export const ChromeContainer = MobxReact.inject('store')(
});
}}
>
{store.getActiveAppView() === Types.AlvaView.PageDetail ? (
<OverviewSwitchContainer />
) : (
<div />
)}
{store.getActiveAppView() === Types.AlvaView.PageDetail && (
<ViewSwitch
fontSize={CopySize.M}
justify="center"
leftVisible={index > 0}
rightVisible={index < pages.length - 1}
onLeftClick={previous}
onRightClick={next}
title={page ? page.getName() : ''}
/>
)}
<ChromeSwitch />
<ViewSwitch
fontSize={CopySize.M}
justify="center"
leftVisible={index > 0}
rightVisible={index < pages.length - 1}
onLeftClick={previous}
onRightClick={next}
title={page ? page.getName() : ''}
/>
<BugReport
title="Found a bug?"
onClick={() => {
Expand Down
30 changes: 30 additions & 0 deletions src/container/chrome/chrome-switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { IconName } from '../../components';
import * as MobxReact from 'mobx-react';
import * as React from 'react';
import { TabSwitch } from '../../components';
import { ViewStore } from '../../store';

@MobxReact.inject('store')
@MobxReact.observer
export class ChromeSwitch extends React.Component {
public render(): JSX.Element | null {
const { store } = this.props as { store: ViewStore };

return (
<div style={{ display: 'flex', height: '100%' }}>
<TabSwitch
icon={IconName.Page}
title={'Pages'}
active={store.getShowPages()}
onClick={() => store.setShowPages(!store.getShowPages())}
/>
<TabSwitch
icon={IconName.Element}
title={'Elements & Library'}
active={store.getShowLeftSidebar()}
onClick={() => store.setShowLeftSidebar(!store.getShowLeftSidebar())}
/>
</div>
);
}
}
28 changes: 0 additions & 28 deletions src/container/chrome/overview-switch-container.tsx

This file was deleted.

21 changes: 16 additions & 5 deletions src/electron/create-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,22 +384,33 @@ export function createMenu(ctx: MenuContext): void {
{
type: 'separator'
},

{
label: '&Show Elements & Components',
label: 'Show Pages',
type: 'checkbox',
checked: true,
checked: ctx.store.getShowPages(),
enabled: ctx.store.getActiveAppView() === Types.AlvaView.PageDetail,
accelerator: 'CmdOrCtrl+Alt+1',
click: (item, checked) => {
ctx.store.setShowLeftSidebar(item.checked);
ctx.store.setShowPages(item.checked);
}
},
{
label: '&Show Properties',
label: 'Show Elements and Library',
type: 'checkbox',
checked: true,
checked: ctx.store.getShowLeftSidebar(),
enabled: ctx.store.getActiveAppView() === Types.AlvaView.PageDetail,
accelerator: 'CmdOrCtrl+Alt+2',
click: (item, checked) => {
ctx.store.setShowLeftSidebar(item.checked);
}
},
{
label: 'Show Properties',
type: 'checkbox',
checked: ctx.store.getShowRightSidebar(),
enabled: ctx.store.getActiveAppView() === Types.AlvaView.PageDetail,
accelerator: 'CmdOrCtrl+Alt+3',
click: (item, checked) => {
ctx.store.setShowRightSidebar(item.checked);
}
Expand Down
3 changes: 1 addition & 2 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Analyzer from '../analyzer';
import { checkForUpdates } from './auto-updater';
import { Color } from '../components';
import { createCompiler } from '../compiler/create-compiler';
import { app, BrowserWindow, dialog, screen, shell } from 'electron';
import * as electronIsDev from 'electron-is-dev';
Expand Down Expand Up @@ -508,7 +507,7 @@ async function createWindow(): Promise<void> {
minWidth: 780,
minHeight: 380,
titleBarStyle: 'hiddenInset',
backgroundColor: Color.Grey97,
backgroundColor: '#f7f7f7',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some special reason for this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Color.Grey97 didn’t work (I guess because electron only allows hex values)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so lets use the color module here to convert from rgb to hex then.

title: 'Alva'
});

Expand Down