-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
204 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import styled from "styled-components" | ||
|
||
const Card = styled.section` | ||
border-radius: 4px; | ||
min-width: 19em; | ||
max-width: 60em; | ||
display: flex; | ||
margin-bottom: 0.7em; | ||
flex-direction: column; | ||
overflow: hidden; | ||
`; | ||
|
||
export default Card |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import styled from 'styled-components' | ||
|
||
const SideBar = styled.section` | ||
display: block; | ||
width: auto; | ||
height: 90%; | ||
position: fixed; | ||
right: 0; | ||
top: 0; | ||
z-index: 1; | ||
background: rgba(38, 25, 58, 0.97); | ||
${({ isOpen }) => `box-shadow: 0px 8px 14px 0px rgba(0, 0, 0, 0.42);`}; | ||
`; | ||
|
||
export default SideBar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { Fragment } from 'react' | ||
import Sidebar from '../components/Sidebar' | ||
import Card from '../components/Card' | ||
import styled from 'styled-components' | ||
import { compose } from 'recompose' | ||
import { connect } from 'react-redux' | ||
import { sort, ascend, prop } from 'ramda' | ||
|
||
const Code = styled(Card)` | ||
padding: 1em 1em 20em; | ||
cursor: text; | ||
` | ||
|
||
const FieldNode = styled.p` | ||
line-height: 1.8em; | ||
margin: 0; | ||
font-size: 1em; | ||
font-family: Fira Code, "Consolas", "Inconsolata", "Droid Sans Mono", "Monaco", monospace; | ||
color: #ddd; | ||
font-weight: 100; | ||
` | ||
|
||
const FieldName = styled.span` | ||
color: #ec63c5; | ||
font-weight: 500; | ||
` | ||
|
||
const CodeContainer = ({ nodes }) => ( | ||
<Code> | ||
{ nodes.map(node => ( | ||
<Fragment> | ||
<FieldNode>{ 'type ' }<FieldName>{ node.name }</FieldName>{ ' {' }</FieldNode> | ||
{ node.fields.map(({ name, type }) => ( | ||
<FieldNode> { name + ':' } <FieldName>{ type }</FieldName></FieldNode> | ||
)) } | ||
<FieldNode>{ '}' }</FieldNode> | ||
<br /> | ||
</Fragment> | ||
)) } | ||
</Code> | ||
) | ||
|
||
const mapStateToProps = ({ nodes, sidebar }) => { | ||
const modelNodes = nodes.filter(({ type }) => type === 'model') | ||
const sortedNodes = sort(ascend(prop('name')), modelNodes) | ||
return { nodes: sortedNodes, sidebar }; | ||
} | ||
|
||
export default compose( | ||
connect(mapStateToProps) | ||
)(CodeContainer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react' | ||
import Sidebar from '../components/Sidebar' | ||
import CodeContainer from './CodeContainer' | ||
import TogglerContainer from './TogglerContainer' | ||
import styled from 'styled-components' | ||
import { compose } from 'recompose' | ||
import { connect } from 'react-redux' | ||
|
||
const Wrapper = styled.section` | ||
overflow: auto; | ||
padding: 0.9em 1.3em; | ||
height: 100%; | ||
box-sizing: border-box; | ||
transition: opacity 0.3s, padding-right 0.3s, padding-left 0.3s cubic-bezier(0.86, 0, 0.07, 1); | ||
${({ isOpen }) => !isOpen && ` | ||
width: 0; | ||
padding-right: 0; | ||
padding-left: 0; | ||
opacity: 0; | ||
`}; | ||
`; | ||
|
||
const SidebarContainer = ({ isOpen }) => ( | ||
<Sidebar isOpen={ isOpen }> | ||
<TogglerContainer /> | ||
<Wrapper isOpen={ isOpen }> | ||
<CodeContainer /> | ||
</Wrapper> | ||
</Sidebar> | ||
) | ||
|
||
const mapStateToProps = ({ sidebar: { isOpen } }) => ({ | ||
isOpen | ||
}) | ||
|
||
export default compose( | ||
connect(mapStateToProps), | ||
)(SidebarContainer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import { compose, withHandlers } from 'recompose' | ||
import { connect } from 'react-redux' | ||
|
||
import { toggleSidebar } from '../store' | ||
|
||
const Toggler = styled.button` | ||
position: absolute; | ||
width: 50px; | ||
height: 50px; | ||
display: block; | ||
background: white; | ||
top: 10px; | ||
left: -50px; | ||
color: #333; | ||
border-radius: 0 0 0 18px; | ||
border: 4px solid rgba(38, 25, 58, 0.97); | ||
border-right: 0; | ||
font-weight: 700; | ||
font-size: 1em; | ||
cursor: pointer; | ||
opacity: 0.6; | ||
box-shadow: 0px 8px 14px 0px rgba(0, 0, 0, 0.42); | ||
&:focus { | ||
outline: 0; | ||
} | ||
&:hover { | ||
opacity: 1; | ||
color: #ec63c5; | ||
border-color: #ec63c5; | ||
} | ||
${({ isOpen }) => isOpen && ` | ||
opacity: 1; | ||
`} | ||
`; | ||
|
||
const TogglerContainer = props => ( | ||
<Toggler { ...props }>{ props.isOpen ? 'X' : '{ }' }</Toggler> | ||
) | ||
|
||
const mapStateToProps = ({ sidebar: { isOpen } }) => ({ | ||
isOpen | ||
}) | ||
|
||
export default compose( | ||
connect(mapStateToProps), | ||
withHandlers({ | ||
onClick: ({ dispatch }) => () => { | ||
dispatch(toggleSidebar()) | ||
} | ||
}) | ||
)(TogglerContainer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { BOOT } from 'redux-boot' | ||
import { createAction } from 'redux-actions' | ||
import { over, lensPath, complement } from 'ramda' | ||
|
||
export const toggleSidebar = createAction('sidebar/TOGGLE') | ||
|
||
const getInitialState = state => ({ | ||
...state, | ||
sidebar: { | ||
isOpen: false | ||
} | ||
}) | ||
|
||
const reducer = { | ||
[BOOT]: (state, action) => getInitialState(state), | ||
[toggleSidebar]: (state, action) => over( | ||
lensPath(['sidebar', 'isOpen']), | ||
value => !value | ||
)(state) | ||
} | ||
|
||
export default { reducer } |