Skip to content

Commit

Permalink
Merge pull request #58 from izumin5210/izumin5210/styled-components
Browse files Browse the repository at this point in the history
styled-components
  • Loading branch information
Masayuki Izumi committed May 21, 2017
2 parents 100371a + 423037d commit f986df8
Show file tree
Hide file tree
Showing 24 changed files with 325 additions and 207 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.*/node_modules/immutable/type-definitions/tests/.*
.*/node_modules/conventional-changelog-core/test/.*
.*/node_modules/stylelint/.*
.*/node_modules/styled-components/.*
./decls

[include]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"remark-yaml-meta": "https://github.com/izumin5210/remark-yaml-meta.git#3387774",
"reselect": "^3.0.0",
"scrollparent": "^2.0.1",
"styled-components": "^1.4.6",
"sweet-scroll": "^2.2.1",
"unist-builder": "^1.0.2",
"unist-util-visit": "^1.1.1"
Expand Down Expand Up @@ -116,7 +117,6 @@
"postinstall": "flow-typed install",
"prebuild": "yarn run clean",
"prepackage": "yarn build",
"postinstall": "flow-typed install",
"pretest": "run-p lint typecheck",
"start": "electron .",
"start:dev": "run-p start:dev:*",
Expand Down
48 changes: 0 additions & 48 deletions src/components/common/Panes.css

This file was deleted.

69 changes: 61 additions & 8 deletions src/components/common/Panes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,61 @@
// @flow
import SplitPane from 'react-split-pane'
import styled from 'styled-components'

import type { Element } from 'react'

import styles from './Panes.css'
import * as colors from 'settings/colors'

const resizerClassName = 'resizer'

const PanesWrapper = styled.div`
.${resizerClassName} {
background: #000;
opacity: 0.2;
z-index: 1;
box-sizing: border-box;
background-clip: padding-box;
&:hover {
transition: all 2s ease;
}
&.horizontal {
height: 11px;
margin: -5px 0;
border-top: 5px solid ${colors.white};
border-bottom: 5px solid ${colors.white};
cursor: row-resize;
width: 100%;
&:hover {
border-top: 5px solid ${colors.blackForeground500};
border-bottom: 5px solid ${colors.blackForeground500};
}
}
&.vertical {
width: 11px;
margin: 0 -5px;
border-left: 5px solid ${colors.white};
border-right: 5px solid ${colors.white};
cursor: col-resize;
&:hover {
border-left: 5px solid ${colors.blackForeground500};
border-right: 5px solid ${colors.blackForeground500};
}
}
&.disabled {
cursor: not-allowed;
&:hover {
border-color: ${colors.transparent};
}
}
}
`

type Props = {
split: 'vertical' | 'horizontal',
Expand All @@ -12,12 +64,13 @@ type Props = {

export default function Panes ({ children, ...rest }: Props) {
return (
<SplitPane
{...rest}
resizerClassName={styles.resizer}
paneStyle={{ overflowY: 'auto' }}
>
{ children }
</SplitPane>
<PanesWrapper>
<SplitPane
{...{ resizerClassName, ...rest }}
paneStyle={{ overflowY: 'auto' }}
>
{ children }
</SplitPane>
</PanesWrapper>
)
}
3 changes: 0 additions & 3 deletions src/components/editor/Editor.css

This file was deleted.

41 changes: 26 additions & 15 deletions src/components/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import { defaultBody } from 'settings/constants'
import type { KeyboardHandler, Position } from 'types'
import type Page from 'entities/Page'

import styles from './Editor.css'
import Wrapper from './Wrapper'

type Props = {
url: string,
body: string,
keyboardHandler: KeyboardHandler,
currentPage: ?Page,
currentPageRangeClassName: string,
setBody: (body: string) => void,
setCursor: (pos: Position) => void,
}
Expand All @@ -28,7 +29,13 @@ type State = {
currentPageMarkerId: ?number,
}

export default class Editor extends PureComponent<void, Props, State> {
const defaultProps = {
currentPageRangeClassName: 'currentPageRange',
}

export default class Editor extends PureComponent<typeof defaultProps, Props, State> {
static defaultProps = defaultProps

constructor (props: Props) {
super(props)
this.state = {
Expand All @@ -51,7 +58,7 @@ export default class Editor extends PureComponent<void, Props, State> {
}
}

componentWillReceiveProps ({ url, body, currentPage }: Props) {
componentWillReceiveProps ({ url, body, currentPage, currentPageRangeClassName }: Props) {
if (url !== this.props.url) {
this.handleChange(body)
}
Expand All @@ -63,7 +70,7 @@ export default class Editor extends PureComponent<void, Props, State> {
const { id: currentPageMarkerId } = session.highlightLines(
beginRow - 1,
endRow - 1,
`ace_active-line ${styles.currentPageRange}`,
`ace_active-line ${currentPageRangeClassName}`,
)
const { currentPageMarkerId: prevPageMarkerId } = this.state
this.setState({ currentPageMarkerId }, () => {
Expand Down Expand Up @@ -117,17 +124,21 @@ export default class Editor extends PureComponent<void, Props, State> {

render () {
return (
<AceEditor
mode='markdown'
theme='tomorrow'
keyboardHandler={this.props.keyboardHandler}
width='100%'
height='100%'
value={this.state.body}
onChange={this.handleChange}
commands={this.commands}
ref={(c) => { this.editorComponent = c }}
/>
<Wrapper
currentPageRangeClassName={this.props.currentPageRangeClassName}
>
<AceEditor
mode='markdown'
theme='tomorrow'
keyboardHandler={this.props.keyboardHandler}
width='100%'
height='100%'
value={this.state.body}
onChange={this.handleChange}
commands={this.commands}
ref={(c) => { this.editorComponent = c }}
/>
</Wrapper>
)
}
}
19 changes: 19 additions & 0 deletions src/components/editor/Wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow
import styled, { css } from 'styled-components'

type Props = {
currentPageRangeClassName: string
}

const Wrapper = styled.div`
width: 100%;
height: 100%;
${(props: Props) => css`
.${props.currentPageRangeClassName} {
opacity: 0.8;
}
`}
`

export default Wrapper
13 changes: 0 additions & 13 deletions src/components/preview/Page.css

This file was deleted.

66 changes: 19 additions & 47 deletions src/components/preview/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Children, Element } from 'react'

import { default as highlightDefault } from 'settings/highlightStyles'

import styles from './Page.css'
import PageWrapper from './PageWrapper'

type Props = {
className: string,
Expand All @@ -18,7 +18,7 @@ type Props = {
}

export default class Page extends PureComponent<void, Props, void> {
static nodeStyle = {
static wrapperStyle = {
width: '100%',
height: '100%',
overflow: 'hidden',
Expand All @@ -27,37 +27,6 @@ export default class Page extends PureComponent<void, Props, void> {
// for lint
props: Props

get width (): number {
// FIXME
const { width, exportingAsPdf } = this.props
return exportingAsPdf ? 1024 : width
}

get height (): number {
// TODO: tweak slide acpect ratio
return 0.75 * this.width
}

get fontSize (): number {
// TODO: tweak base font-size
return this.props.fontSize * (this.width / 1024)
}

get style (): Object {
const { exportingAsPdf } = this.props
const { width, height, fontSize } = this
return Object.assign(
{},
{
height,
minHeight: height,
maxHeight: height,
fontSize,
},
exportingAsPdf ? { width } : {},
)
}

get userStyles (): Array<Element<*>> {
return this.props.userStyles.map((style, i) => (
<style type='text/css' key={`userStyle[${i}]`}>{ style }</style>
Expand All @@ -66,21 +35,24 @@ export default class Page extends PureComponent<void, Props, void> {

render () {
return (
<ShadowDom nodeName='div'>
<section
className={styles.page}
style={this.style}
>
<div
className={this.props.className}
style={Page.nodeStyle}
>
{ this.props.children }
{ this.userStyles }
<link rel='stylesheet' href={highlightDefault} />
<PageWrapper
screenWidth={this.props.width}
baseFontSize={this.props.fontSize}
exporting={this.props.exportingAsPdf}
>
<ShadowDom nodeName='div'>
<div style={Page.wrapperStyle}>
<div
className={this.props.className}
style={Page.wrapperStyle}
>
{ this.props.children }
{ this.userStyles }
<link rel='stylesheet' href={highlightDefault} />
</div>
</div>
</section>
</ShadowDom>
</ShadowDom>
</PageWrapper>
)
}
}
Loading

0 comments on commit f986df8

Please sign in to comment.