diff --git a/website/.flowconfig b/website/.flowconfig
new file mode 100644
index 00000000..1fed4453
--- /dev/null
+++ b/website/.flowconfig
@@ -0,0 +1,11 @@
+[ignore]
+
+[include]
+
+[libs]
+
+[lints]
+
+[options]
+
+[strict]
diff --git a/website/contents/getting-started/litho.md b/website/contents/getting-started/litho.md
new file mode 100644
index 00000000..0a972968
--- /dev/null
+++ b/website/contents/getting-started/litho.md
@@ -0,0 +1,24 @@
+---
+path: "getting-started/litho"
+title: "Litho"
+hasPlayground: false
+---
+
+## Litho
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nec
+sodales libero, sit amet tempus diam. Vivamus finibus vestibulum
+est. Vestibulum feugiat pellentesque diam vel hendrerit. Nunc
+pretium sollicitudin magna sed pharetra.
+
+Duis bibendum dapibus quam ac rutrum. Suspendisse potenti. Aliquam
+est sapien, gravida ac turpis iaculis, convallis rutrum justo. Sed
+est augue, pellentesque eleifend mauris non, ultrices aliquam purus.
+Duis sed lorem a lectus feugiat fringilla eu non elit.
+
+```c
+enum {
+ Test
+ Test2
+}
+```
diff --git a/website/docs/flexDirection.md b/website/contents/properties/flexDirection.md
similarity index 89%
rename from website/docs/flexDirection.md
rename to website/contents/properties/flexDirection.md
index 3520967d..51e11a67 100644
--- a/website/docs/flexDirection.md
+++ b/website/contents/properties/flexDirection.md
@@ -2,6 +2,7 @@
path: "docs/flexDirection"
title: "Flex Direction"
hasPlayground: true
+editableProperties: ['flexDirection']
---
## Flex Direction
@@ -15,3 +16,10 @@ Duis bibendum dapibus quam ac rutrum. Suspendisse potenti. Aliquam
est sapien, gravida ac turpis iaculis, convallis rutrum justo. Sed
est augue, pellentesque eleifend mauris non, ultrices aliquam purus.
Duis sed lorem a lectus feugiat fringilla eu non elit.
+
+```c
+enum {
+ Test
+ Test2
+}
+```
diff --git a/website/gatsby-config.js b/website/gatsby-config.js
index d403e36a..5f5d2992 100644
--- a/website/gatsby-config.js
+++ b/website/gatsby-config.js
@@ -12,10 +12,12 @@
module.exports = {
siteMetadata: {
- title: 'Gatsby Default Starter',
+ title: 'Yoga Layout',
},
plugins: [
+ // using latest react version
'gatsby-plugin-react-next',
+ // setting head data like title from within components
'gatsby-plugin-react-helmet',
{
resolve: `gatsby-plugin-less`,
@@ -25,19 +27,35 @@ module.exports = {
},
},
},
+ // plugin for importing antd components
{
resolve: 'gatsby-plugin-antd',
options: {
style: true,
},
},
+ // reading files from the file-system (used for markdown files)
{
resolve: `gatsby-source-filesystem`,
options: {
- path: `${__dirname}/docs`,
+ path: `${__dirname}/contents`,
name: 'markdown-pages',
},
},
- 'gatsby-transformer-remark',
+ // parse markdown files, used for content files
+ {
+ resolve: `gatsby-transformer-remark`,
+ options: {
+ // code-highlighting in markdown files
+ plugins: [
+ {
+ resolve: `gatsby-remark-prismjs`,
+ options: {
+ classPrefix: 'language-',
+ },
+ },
+ ],
+ },
+ },
],
};
diff --git a/website/gatsby-node.js b/website/gatsby-node.js
index 20c54a85..28d5fc66 100644
--- a/website/gatsby-node.js
+++ b/website/gatsby-node.js
@@ -25,6 +25,7 @@ exports.createPages = ({boundActionCreators, graphql}) => {
frontmatter {
path
hasPlayground
+ editableProperties
}
html
}
diff --git a/website/package.json b/website/package.json
index b0b63cb5..052cada2 100644
--- a/website/package.json
+++ b/website/package.json
@@ -11,6 +11,7 @@
"gatsby-plugin-less": "^1.1.4",
"gatsby-plugin-react-helmet": "^2.0.3",
"gatsby-plugin-react-next": "^1.0.8",
+ "gatsby-remark-prismjs": "^1.2.14",
"gatsby-source-filesystem": "^1.5.18",
"gatsby-transformer-remark": "^1.7.31",
"immutable": "^4.0.0-rc.9",
@@ -25,9 +26,7 @@
"main": "n/a",
"scripts": {
"build": "gatsby build",
- "develop": "gatsby develop",
- "format": "prettier --trailing-comma es5 --no-semi --single-quote --write \"src/**/*.js\"",
- "test": "echo \"Error: no test specified\" && exit 1"
+ "develop": "gatsby develop"
},
"devDependencies": {
"prettier": "^1.10.2"
diff --git a/website/src/components/DocsSidebar.css b/website/src/components/DocsSidebar.css
index 451752ee..d8d1ff37 100644
--- a/website/src/components/DocsSidebar.css
+++ b/website/src/components/DocsSidebar.css
@@ -1,4 +1,15 @@
.DocsSidebar {
+ height: 100%;
width: 350px;
padding: 20px;
+ border-right: 1px solid #dddfe2;
+}
+
+.DocsSidebar h3 {
+ margin-bottom: 0;
+}
+
+.DocsSidebar h4 {
+ margin-top: 10px;
+ margin-bottom: 5px;
}
diff --git a/website/src/components/Page.css b/website/src/components/Page.css
index ec1b3bfc..70c80ebe 100644
--- a/website/src/components/Page.css
+++ b/website/src/components/Page.css
@@ -14,6 +14,13 @@ h2 {
font-weight: 500;
}
+.gatsby-highlight pre[class*="language-"] {
+ background: none;
+ padding: 0;
+ font-size: 14px;
+ margin-bottom: 15px;
+}
+
.Page {
display: flex;
flex-direction: column;
@@ -25,3 +32,7 @@ h2 {
flex-direction: column;
flex-grow: 1;
}
+
+.PageContent.withSpacing {
+ padding-top: 35px;
+}
diff --git a/website/src/components/Page.js b/website/src/components/Page.js
index 5a1680ea..0b010288 100644
--- a/website/src/components/Page.js
+++ b/website/src/components/Page.js
@@ -14,11 +14,13 @@ import React from 'react';
import Toolbar from './Toolbar';
import Footer from './Footer';
import './Page.css';
+require('prismjs/themes/prism.css');
type Props = {|
children: any,
title?: string,
className?: string,
+ withSpacing?: boolean,
|};
export default (props: Props) => (
@@ -32,7 +34,9 @@ export default (props: Props) => (
Yoga Layout{props.title ? ` | ${props.title}` : ''}
*/}
- {props.children}
+
+ {props.children}
+
);
diff --git a/website/src/components/Playground/EditValue.js b/website/src/components/Playground/EditValue.js
new file mode 100644
index 00000000..89e3b15f
--- /dev/null
+++ b/website/src/components/Playground/EditValue.js
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2014-present, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ *
+ * @flow
+ * @format
+ */
+
+import React, {Component} from 'react';
+import YogaEnumSelect from './YogaEnumSelect';
+import YogaPositionEditor from './YogaPositionEditor';
+import {Input} from 'antd';
+
+type Props = {
+ property: string,
+ disabled?: boolean,
+ value: string | number,
+ onChange: (value: number) => void,
+};
+
+export default (props: Props) => {
+ if (YogaEnumSelect.availableProperties.indexOf(props.property) > -1) {
+ return ;
+ } else if (
+ YogaPositionEditor.availableProperties.indexOf(props.property) > -1
+ ) {
+ return ;
+ } else {
+ return ;
+ }
+};
diff --git a/website/src/components/Playground/Editor.js b/website/src/components/Playground/Editor.js
index 8e0f053a..a32429eb 100644
--- a/website/src/components/Playground/Editor.js
+++ b/website/src/components/Playground/Editor.js
@@ -11,12 +11,11 @@
*/
import React, {Component} from 'react';
-import {Row, Col, Button, Tabs, Input} from 'antd';
-import YogaEnumSelect from './YogaEnumSelect';
+import {Row, Col, Button, Tabs} from 'antd';
+import EditValue from './EditValue';
import type {LayoutRecordT} from './LayoutRecord';
import type {Yoga$Direction} from 'yoga-layout';
import InfoText from './InfoText';
-import YogaPositionEditor from './YogaPositionEditor';
import './Editor.css';
const TabPane = Tabs.TabPane;
@@ -64,8 +63,8 @@ export default class Editor extends Component {
direction
- this.props.onChangeSetting('direction', e)}
/>
@@ -73,9 +72,9 @@ export default class Editor extends Component {
Flex direction
Defining the direction of the main-axis
- this.props.onChangeLayout('flexDirection', e)}
/>
@@ -89,7 +88,7 @@ export default class Editor extends Component {
up, relative to it's siblings
- {
anymore.
- {
Wrapping behaviour when child nodes don't fit into a single line
- this.props.onChangeLayout('flexWrap', e)}
/>
@@ -135,9 +134,9 @@ export default class Editor extends Component {
Justify content
Aligns child nodes along the main-axis
- this.props.onChangeLayout('justifyContent', e)}
/>
@@ -146,9 +145,9 @@ export default class Editor extends Component {
Align items
Aligns child nodes along the cross-axis
- this.props.onChangeLayout('alignItems', e)}
/>
@@ -159,9 +158,9 @@ export default class Editor extends Component {
Specifies alignment on the cross-axis for the node itself
- this.props.onChangeLayout('alignSelf', e)}
/>
@@ -172,9 +171,9 @@ export default class Editor extends Component {
Alignment of lines along the cross-axis when wrapping
- this.props.onChangeLayout('alignContent', e)}
/>
@@ -186,7 +185,7 @@ export default class Editor extends Component {
- {
/>
- {
displaying videos
- {
Box model
{['padding', 'border', 'margin'].map(property => (
- {
- this.props.onChangeLayout('positionType', e)}
/>
- this.props.onChangeLayout('position', value)}
diff --git a/website/src/components/Playground/YogaEnumSelect.css b/website/src/components/Playground/YogaEnumSelect.css
index 7a434be1..57a4ec1b 100644
--- a/website/src/components/Playground/YogaEnumSelect.css
+++ b/website/src/components/Playground/YogaEnumSelect.css
@@ -1,4 +1,4 @@
-.YogaEnumSelect.ant-radio-group {
+.YogaEnumSelect {
display: flex;
}
@@ -7,3 +7,8 @@
flex-basis: 0;
text-align: center;
}
+
+.YogaEnumSelect .ant-btn {
+ flex-grow: 1;
+ flex-basis: 0;
+}
diff --git a/website/src/components/Playground/YogaEnumSelect.js b/website/src/components/Playground/YogaEnumSelect.js
index afe51fb0..3da9e3e7 100644
--- a/website/src/components/Playground/YogaEnumSelect.js
+++ b/website/src/components/Playground/YogaEnumSelect.js
@@ -17,18 +17,32 @@ import './YogaEnumSelect.css';
const RadioButton = Radio.Button;
const RadioGroup = Radio.Group;
+const PROPERTY_LOOKUP = {
+ flexDirection: 'FLEX_DIRECTION',
+ direction: 'DIRECTION',
+ justifyContent: 'JUSTIFY',
+ alignSelf: 'ALIGN',
+ alignContent: 'ALIGN',
+ alignItems: 'ALIGN',
+ positionType: 'POSITION_TYPE',
+ flexWrap: 'WRAP',
+};
+
type Props = {
- property: string,
+ property: $Keys,
disabled?: boolean,
value: string | number,
onChange: (value: number) => void,
};
export default class YogaEnumSelect extends Component {
+ static availableProperties = Object.keys(PROPERTY_LOOKUP);
+
values: Array<{key: string, value: number}>;
constructor({property}: Props) {
super();
+ property = PROPERTY_LOOKUP[property];
// $FlowFixMe
this.values = Object.keys(yoga)
.map(key => ({key, value: yoga[key]}))
@@ -42,29 +56,32 @@ export default class YogaEnumSelect extends Component {
};
render() {
- const {property, ...props} = this.props;
+ let {property, ...props} = this.props;
+ property = PROPERTY_LOOKUP[property];
const selected = this.values.find(
({key, value}) => value === this.props.value,
);
const replacer = new RegExp(`^${property}_`);
return this.values.length > 3 ? (
-
- {this.values.map(({key, value}) => (
-
- {key.replace(replacer, '')}
-
- ))}
-
- }>
-
-
+
+
+ {this.values.map(({key, value}) => (
+
+ {key.replace(replacer, '')}
+
+ ))}
+
+ }>
+
+
+
) : (
void,
};
export default class YogaPositionEditor extends Component {
+ static availableProperties = ['position', 'margin', 'padding', 'border'];
+
static defaultProps = {
value: PositionRecord(),
};
diff --git a/website/src/components/Playground/index.js b/website/src/components/Playground/index.js
index b30941fb..bae542c7 100644
--- a/website/src/components/Playground/index.js
+++ b/website/src/components/Playground/index.js
@@ -34,6 +34,7 @@ type Props = {
showGuides: boolean,
className?: string,
height?: string | number,
+ persist?: boolean,
renderSidebar?: (layoutDefinition: LayoutRecordT, onChange: Function) => any,
};
@@ -53,7 +54,7 @@ export default class Playground extends Component {
static defaultProps = {
layoutDefinition: LayoutRecord({
- width: 800,
+ width: 700,
height: 400,
justifyContent: yoga.JUSTIFY_SPACE_BETWEEN,
alignItems: yoga.ALIGN_FLEX_START,
@@ -65,14 +66,15 @@ export default class Playground extends Component {
bottom: '10',
}),
margin: PositionRecord({
- left: '20',
- top: '70',
+ left: '30',
+ top: '30',
}),
}),
direction: yoga.DIRECTION_LTR,
maxDepth: 3,
showCode: false,
showGuides: true,
+ persist: false,
};
state = {
@@ -144,8 +146,9 @@ export default class Playground extends Component {
const {selectedNodePath, layoutDefinition} = this.state;
if (selectedNodePath) {
const index = selectedNodePath.pop();
- const path = getPath(selectedNodePath).concat('children');
- const updatedChildren = layoutDefinition.getIn(path).delete(index);
+ const updatedChildren = layoutDefinition
+ .getIn(getPath(selectedNodePath))
+ .delete(index);
this.modifyAtPath(path, updatedChildren);
this.setState({selectedNodePath: null});
}
@@ -154,8 +157,9 @@ export default class Playground extends Component {
onAdd = () => {
const {selectedNodePath, layoutDefinition} = this.state;
if (selectedNodePath) {
- const path = getPath(selectedNodePath).concat('children');
- const updatedChildren = layoutDefinition.getIn(path).push(LayoutRecord());
+ const updatedChildren = layoutDefinition
+ .getIn(getPath(selectedNodePath))
+ .push(LayoutRecord());
this.modifyAtPath(
path,
updatedChildren,
@@ -177,9 +181,11 @@ export default class Playground extends Component {
selectedNodePath,
});
- window.location.hash = btoa(
- JSON.stringify(this.removeUnchangedProperties(layoutDefinition)),
- );
+ if (this.props.persist) {
+ window.location.hash = btoa(
+ JSON.stringify(this.removeUnchangedProperties(layoutDefinition)),
+ );
+ }
}
removeUnchangedProperties = (node: LayoutRecordT): Object => {
@@ -306,7 +312,7 @@ export default class Playground extends Component {
{this.props.renderSidebar(
- this.state.layoutDefinition,
+ layoutDefinition.getIn(getPath(selectedNodePath)),
this.onChangeLayout,
)}
diff --git a/website/src/pages/docs/index.js b/website/src/pages/docs/index.js
index 851077ed..d195abd7 100644
--- a/website/src/pages/docs/index.js
+++ b/website/src/pages/docs/index.js
@@ -16,8 +16,15 @@ import Page from '../../components/Page';
import Padded from '../../components/Padded';
import {Row, Col} from 'antd';
-export default () => (
-
+const CATEGORY_TITLE = {
+ 'getting-started': 'Getting Started',
+ properties: 'Properties',
+ examples: 'Examples',
+ contributing: 'Contributing',
+};
+
+export default ({data}) => (
+
Documentation
@@ -29,65 +36,41 @@ export default () => (
nec leo pharetra fermentum.
-
- Getting Started
- Litho
-
- ComponentKit
-
- React Native
-
- Addin Yoga to a project
-
-
- Properties
- Width and height
-
- Max/min width and height
-
- Flex direction
-
- Justify content
-
- Align items/self
-
- Flex basis, grow and shrink
-
- Margins, paddings, and borders
-
- Flex wrap
-
- Align content
-
- Absolute layout
-
- Aspect ratio
-
- Layout direction
-
-
- Examples
- Overlays
-
- Floating buttons
-
- Flexible text
-
-
- Contributing
- Check out the code
-
- Running the test suite
-
- Making a change
-
- Adding a test
-
- Adding documentation
-
- Opening a pull request
-
+ {['getting-started', 'properties', 'examples', 'contributing'].map(
+ category => (
+
+ {CATEGORY_TITLE[category]}
+ {data.allMarkdownRemark.edges
+ .filter(
+ ({node}) =>
+ node.fileAbsolutePath.indexOf(`/${category}/`) > -1,
+ )
+ .map(({node}) => (
+
+ {node.frontmatter.title}
+
+ ))}
+
+ ),
+ )}
);
+
+export const query = graphql`
+ query IndexQuery {
+ allMarkdownRemark {
+ edges {
+ node {
+ id
+ frontmatter {
+ title
+ path
+ }
+ fileAbsolutePath
+ }
+ }
+ }
+ }
+`;
diff --git a/website/src/pages/playground.js b/website/src/pages/playground.js
index 176ca788..cc86fc76 100644
--- a/website/src/pages/playground.js
+++ b/website/src/pages/playground.js
@@ -16,6 +16,6 @@ import Playground from '../components/Playground';
export default () => (
-
+
);
diff --git a/website/src/templates/withPlayground.js b/website/src/templates/withPlayground.js
index 78463fa5..090b59da 100644
--- a/website/src/templates/withPlayground.js
+++ b/website/src/templates/withPlayground.js
@@ -14,25 +14,45 @@ import React from 'react';
import Page from '../components/Page';
import Playground from '../components/Playground';
import DocsSidebar from '../components/DocsSidebar';
-import YogaEnumSelect from '../components/Playground/YogaEnumSelect';
+import EditValue from '../components/Playground/EditValue';
+import Link from 'gatsby-link';
+import {Button, Icon, Row, Col} from 'antd';
-export default ({pathContext}) => {
- return (
-
- (
-
-
- onChange('flexDirection', e)}
- />
-
- )}
- />
-
- );
-};
+export default ({pathContext}) => (
+
+ (
+
+
+ back to overview
+
+
+ {pathContext.frontmatter.editableProperties && (
+
+
+ Try it out
+
+
+
+ Open in playground
+
+
+
+ )}
+ {(pathContext.frontmatter.editableProperties || []).map(prop => (
+
+
{prop}
+ onChange(prop, e)}
+ />
+
+ ))}
+
+ )}
+ />
+
+);
diff --git a/website/src/templates/withoutPlayground.js b/website/src/templates/withoutPlayground.js
index 7c1bc06c..5816775b 100644
--- a/website/src/templates/withoutPlayground.js
+++ b/website/src/templates/withoutPlayground.js
@@ -13,11 +13,16 @@
import React from 'react';
import Page from '../components/Page';
import Padded from '../components/Padded';
+import {Icon} from 'antd';
+import Link from 'gatsby-link';
export default ({pathContext}) => {
return (
-
+
+
+ back to overview
+
diff --git a/website/yarn.lock b/website/yarn.lock
index 125669f3..0f722009 100644
--- a/website/yarn.lock
+++ b/website/yarn.lock
@@ -3423,6 +3423,15 @@ gatsby-react-router-scroll@^1.0.10:
scroll-behavior "^0.9.9"
warning "^3.0.0"
+gatsby-remark-prismjs@^1.2.14:
+ version "1.2.14"
+ resolved "https://registry.yarnpkg.com/gatsby-remark-prismjs/-/gatsby-remark-prismjs-1.2.14.tgz#3f5fd2ac1d5a174673a6b6fa63b4e4fa526d36c0"
+ dependencies:
+ babel-runtime "^6.26.0"
+ parse-numeric-range "0.0.2"
+ prismjs "^1.11.0"
+ unist-util-visit "^1.3.0"
+
gatsby-source-filesystem@^1.5.18:
version "1.5.18"
resolved "https://registry.yarnpkg.com/gatsby-source-filesystem/-/gatsby-source-filesystem-1.5.18.tgz#e2cb96a2c248c304e58ba3d0142316a695d3ef35"
@@ -6144,6 +6153,10 @@ parse-latin@^4.0.0:
unist-util-modify-children "^1.0.0"
unist-util-visit-children "^1.0.0"
+parse-numeric-range@0.0.2:
+ version "0.0.2"
+ resolved "https://registry.yarnpkg.com/parse-numeric-range/-/parse-numeric-range-0.0.2.tgz#b4f09d413c7adbcd987f6e9233c7b4b210c938e4"
+
parse-passwd@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
@@ -6858,7 +6871,7 @@ pretty-error@^2.1.1:
renderkid "^2.0.1"
utila "~0.4"
-prismjs@^1.8.4:
+prismjs@^1.11.0, prismjs@^1.8.4:
version "1.11.0"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.11.0.tgz#297aef33eb79421bfdb19273a5092ca515970d29"
optionalDependencies:
@@ -9216,7 +9229,7 @@ unist-util-visit-children@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/unist-util-visit-children/-/unist-util-visit-children-1.1.1.tgz#eba63b371116231181068837118b6e6e10ec8844"
-unist-util-visit@^1.0.0, unist-util-visit@^1.1.0, unist-util-visit@^1.1.1:
+unist-util-visit@^1.0.0, unist-util-visit@^1.1.0, unist-util-visit@^1.1.1, unist-util-visit@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-1.3.0.tgz#41ca7c82981fd1ce6c762aac397fc24e35711444"
dependencies: