Inline controls for docs
Summary: Adding inline controls in markdown using: ``` <controls prop="flexWrap"></controls> ``` Reviewed By: emilsjolander Differential Revision: D6987150 fbshipit-source-id: 28def12df702ba5d5d5b6a83dd1cb907716d1b1c
This commit is contained in:
committed by
Facebook Github Bot
parent
5f2cf6623f
commit
8c5cbf698b
@@ -2,7 +2,10 @@
|
|||||||
path: "docs/absolute-layout"
|
path: "docs/absolute-layout"
|
||||||
title: "Absolute Layout"
|
title: "Absolute Layout"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['positionType', 'position']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Absolute Layout
|
## Absolute Layout
|
||||||
|
|
||||||
|
<controls prop="positionType"></controls>
|
||||||
|
|
||||||
|
<controls prop="position"></controls>
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
path: "docs/align-content"
|
path: "docs/align-content"
|
||||||
title: "Align Content"
|
title: "Align Content"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['alignContent']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Align Content
|
## Align Content
|
||||||
|
|
||||||
|
<controls prop="alignContent"></controls>
|
||||||
|
@@ -2,7 +2,10 @@
|
|||||||
path: "docs/align-items"
|
path: "docs/align-items"
|
||||||
title: "Align Items / Self"
|
title: "Align Items / Self"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['alignItems', 'alignSelf']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Align Items / Self
|
## Align Items / Self
|
||||||
|
|
||||||
|
<controls prop="alignItems"></controls>
|
||||||
|
|
||||||
|
<controls prop="alignSelf"></controls>
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
path: "docs/aspect-ratio"
|
path: "docs/aspect-ratio"
|
||||||
title: "Aspect Ratio"
|
title: "Aspect Ratio"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['aspectRatio']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Aspect Ratio
|
## Aspect Ratio
|
||||||
@@ -18,3 +17,5 @@ The aspect ratio property in Yoga has the following properties:
|
|||||||
- Respects the Min and Max dimensions of an item.
|
- Respects the Min and Max dimensions of an item.
|
||||||
- Has higher priority than FlexGrow
|
- Has higher priority than FlexGrow
|
||||||
- If AspectRatio, Width, and Height are set then the cross dimension is overridden.
|
- If AspectRatio, Width, and Height are set then the cross dimension is overridden.
|
||||||
|
|
||||||
|
<controls prop="aspectRatio"></controls>
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
path: "docs/flex-direction"
|
path: "docs/flex-direction"
|
||||||
title: "Flex Direction"
|
title: "Flex Direction"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['flexDirection']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Flex Direction
|
## Flex Direction
|
||||||
|
|
||||||
|
<controls prop="flexDirection"></controls>
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
path: "docs/flex-wrap"
|
path: "docs/flex-wrap"
|
||||||
title: "Flex Wrap"
|
title: "Flex Wrap"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['flexWrap']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Flex Wrap
|
## Flex Wrap
|
||||||
|
|
||||||
|
<controls prop="flexWrap"></controls>
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
path: "docs/flex"
|
path: "docs/flex"
|
||||||
title: "Flex Basis, Grow, and Shrink"
|
title: "Flex Basis, Grow, and Shrink"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['flexGrow', 'flexShrink', 'flexBasis']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Flex Basis, Grow, and Shrink
|
## Flex Basis, Grow, and Shrink
|
||||||
@@ -16,6 +15,8 @@ distribute any remaining space according to the flex grow values specified by it
|
|||||||
flex grow accepts any floating point value >= 0, with 0 being the default value.
|
flex grow accepts any floating point value >= 0, with 0 being the default value.
|
||||||
A container will distribute any remaining space among its children weighted by the child’s flex grow value.
|
A container will distribute any remaining space among its children weighted by the child’s flex grow value.
|
||||||
|
|
||||||
|
<controls prop="flexGrow"></controls>
|
||||||
|
|
||||||
### Flex Shrink
|
### Flex Shrink
|
||||||
|
|
||||||
Flex shrink describes how to shrink children along the main axis in the
|
Flex shrink describes how to shrink children along the main axis in the
|
||||||
@@ -27,6 +28,8 @@ These two properties also work well together by allowing children to grow and sh
|
|||||||
flex shrink accepts any floating point value >= 0, with 1 being the default value.
|
flex shrink accepts any floating point value >= 0, with 1 being the default value.
|
||||||
A container will shrink its children weighted by the child’s flex shrink value.
|
A container will shrink its children weighted by the child’s flex shrink value.
|
||||||
|
|
||||||
|
<controls prop="flexShrink"></controls>
|
||||||
|
|
||||||
### Flex Basis
|
### Flex Basis
|
||||||
|
|
||||||
Flex basis is an axis-independent way of providing the default size of an item
|
Flex basis is an axis-independent way of providing the default size of an item
|
||||||
@@ -35,3 +38,5 @@ child if its parent is a container with FlexDirection = row or setting the Heigh
|
|||||||
if its parent is a container with FlexDirection = column. The flex basis of an item is the
|
if its parent is a container with FlexDirection = column. The flex basis of an item is the
|
||||||
efault size of that item, the size of the item before any flex grow and flex shrink
|
efault size of that item, the size of the item before any flex grow and flex shrink
|
||||||
calculations are performed.
|
calculations are performed.
|
||||||
|
|
||||||
|
<controls prop="flexBasis"></controls>
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
path: "docs/justify-content"
|
path: "docs/justify-content"
|
||||||
title: "Justify Content"
|
title: "Justify Content"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['justifyContent']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Justify Content
|
## Justify Content
|
||||||
|
|
||||||
|
<controls prop="justifyContent"></controls>
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
path: "docs/layout-direction"
|
path: "docs/layout-direction"
|
||||||
title: "Layout Direction"
|
title: "Layout Direction"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['layoutDirection']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Layout Direction
|
## Layout Direction
|
||||||
|
|
||||||
|
<controls prop="layoutDirection"></controls>
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
path: "docs/margins-paddings-borders"
|
path: "docs/margins-paddings-borders"
|
||||||
title: "Margins, Paddings, and Borders"
|
title: "Margins, Paddings, and Borders"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['margin', 'padding', 'border']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Margins, Paddings, and Borders
|
## Margins, Paddings, and Borders
|
||||||
@@ -14,6 +13,8 @@ will offset itself from the bounds of its parent but also offset the
|
|||||||
location of any siblings. The margin of a node contributes to the total size
|
location of any siblings. The margin of a node contributes to the total size
|
||||||
of its parent if the parent is auto sized.
|
of its parent if the parent is auto sized.
|
||||||
|
|
||||||
|
<controls prop="margin"></controls>
|
||||||
|
|
||||||
### Padding
|
### Padding
|
||||||
|
|
||||||
Padding affect the size of the node it is applied to. Padding in Yoga acts as if
|
Padding affect the size of the node it is applied to. Padding in Yoga acts as if
|
||||||
@@ -21,6 +22,8 @@ Padding affect the size of the node it is applied to. Padding in Yoga acts as if
|
|||||||
of an element if it has an explicit size set. For auto sized nodes padding will increase
|
of an element if it has an explicit size set. For auto sized nodes padding will increase
|
||||||
the size of the node as well as offset the location of any children.
|
the size of the node as well as offset the location of any children.
|
||||||
|
|
||||||
|
<controls prop="padding"></controls>
|
||||||
|
|
||||||
### Border
|
### Border
|
||||||
|
|
||||||
Border in Yoga acts exactly like padding and only exists as a seperate property so
|
Border in Yoga acts exactly like padding and only exists as a seperate property so
|
||||||
@@ -28,3 +31,4 @@ that higher level frameworks get a hint as to how thick to draw a border. Yoga h
|
|||||||
does not do any drawing so just uses this information during layout where border
|
does not do any drawing so just uses this information during layout where border
|
||||||
acts exactly like padding.
|
acts exactly like padding.
|
||||||
|
|
||||||
|
<controls prop="border"></controls>
|
||||||
|
@@ -2,7 +2,14 @@
|
|||||||
path: "docs/min-max"
|
path: "docs/min-max"
|
||||||
title: "Max / Min Width and Height"
|
title: "Max / Min Width and Height"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['minWidth', 'minHeight', 'maxWidth', 'maxHeight']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Max / Min Width and Height
|
## Max / Min Width and Height
|
||||||
|
|
||||||
|
<controls prop="minWidth"></controls>
|
||||||
|
|
||||||
|
<controls prop="minHeight"></controls>
|
||||||
|
|
||||||
|
<controls prop="maxWidth"></controls>
|
||||||
|
|
||||||
|
<controls prop="maxHeight"></controls>
|
||||||
|
@@ -2,7 +2,11 @@
|
|||||||
path: "docs/width-height"
|
path: "docs/width-height"
|
||||||
title: "Width and Height"
|
title: "Width and Height"
|
||||||
hasPlayground: true
|
hasPlayground: true
|
||||||
editableProperties: ['width', 'height']
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Width and Height
|
## Width and Height
|
||||||
|
|
||||||
|
|
||||||
|
<controls prop="width"></controls>
|
||||||
|
|
||||||
|
<controls prop="height"></controls>
|
||||||
|
@@ -25,7 +25,6 @@ exports.createPages = ({boundActionCreators, graphql}) => {
|
|||||||
frontmatter {
|
frontmatter {
|
||||||
path
|
path
|
||||||
hasPlayground
|
hasPlayground
|
||||||
editableProperties
|
|
||||||
}
|
}
|
||||||
html
|
html
|
||||||
}
|
}
|
||||||
|
@@ -10,13 +10,67 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React, {Component} from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import EditValue from '../components/Playground/EditValue';
|
||||||
|
import Link from 'gatsby-link';
|
||||||
import './DocsSidebar.css';
|
import './DocsSidebar.css';
|
||||||
|
import type {LayoutRecordT} from './Playground/LayoutRecord';
|
||||||
|
|
||||||
|
const TAG_PATTERN = /<controls prop="([A-Za-z]+)"><\/controls>/gi;
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
children: any,
|
markdown: string,
|
||||||
|
onChange: (property: string, value: any) => void,
|
||||||
|
layout: LayoutRecordT,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (props: Props) => (
|
export default class DocsSidebar extends Component<Props> {
|
||||||
<div className="DocsSidebar">{props.children}</div>
|
componentDidMount() {
|
||||||
);
|
this.renderControls(this.props);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps: Props) {
|
||||||
|
this.renderControls(nextProps);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderControls = (props: Props) => {
|
||||||
|
let match;
|
||||||
|
while ((match = TAG_PATTERN.exec(props.markdown))) {
|
||||||
|
const prop = match[1];
|
||||||
|
const element = window.document.querySelector(
|
||||||
|
`controls[prop="${match[1]}"]`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (element) {
|
||||||
|
if (element.childNodes.length !== 0) {
|
||||||
|
console.warn(
|
||||||
|
`The element <controls type="${prop}"> is not empty. It's content will be replaced by the react-component mounted in this element.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ReactDOM.render(
|
||||||
|
<EditValue
|
||||||
|
property={prop}
|
||||||
|
value={props.layout[prop]}
|
||||||
|
onChange={props.onChange}
|
||||||
|
/>,
|
||||||
|
element,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div className="DocsSidebar">
|
||||||
|
<div
|
||||||
|
className="markdown"
|
||||||
|
dangerouslySetInnerHTML={{__html: this.props.markdown}}
|
||||||
|
/>
|
||||||
|
<Link to="/docs" className="overview">
|
||||||
|
BACK TO OVERVIEW
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React, {Component} from 'react';
|
||||||
import Page from '../components/Page';
|
import Page from '../components/Page';
|
||||||
import Playground from '../components/Playground';
|
import Playground from '../components/Playground';
|
||||||
import DocsSidebar from '../components/DocsSidebar';
|
import DocsSidebar from '../components/DocsSidebar';
|
||||||
@@ -19,31 +19,30 @@ import Link from 'gatsby-link';
|
|||||||
import {Button, Icon, Row, Col} from 'antd';
|
import {Button, Icon, Row, Col} from 'antd';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
export default ({pathContext}) => (
|
type Props = {
|
||||||
<Page className="doc-block playground">
|
pathContext: {
|
||||||
<Playground
|
html: string,
|
||||||
selectedNodePath={[]}
|
frontmatter: {},
|
||||||
showGuides={false}
|
},
|
||||||
renderSidebar={(layout, onChange) => (
|
};
|
||||||
<DocsSidebar>
|
const REGEX = /<controls prop="([A-Za-z]+)"\s?\/>/gi;
|
||||||
<div className="markdown" dangerouslySetInnerHTML={{__html: pathContext.html}} />
|
|
||||||
|
|
||||||
{(pathContext.frontmatter.editableProperties || []).map(prop => (
|
export default class withPlayground extends Component<Props> {
|
||||||
<div key={prop} className="prop">
|
render() {
|
||||||
<h4>{prop}</h4>
|
return (
|
||||||
<EditValue
|
<Page className="doc-block playground">
|
||||||
property={prop}
|
<Playground
|
||||||
value={layout[prop]}
|
selectedNodePath={[]}
|
||||||
onChange={onChange}
|
showGuides={false}
|
||||||
/>
|
renderSidebar={(layout, onChange) => (
|
||||||
</div>
|
<DocsSidebar
|
||||||
))}
|
layout={layout}
|
||||||
|
onChange={onChange}
|
||||||
<Link to="/docs" className="overview">
|
markdown={this.props.pathContext.html}
|
||||||
BACK TO OVERVIEW
|
/>
|
||||||
</Link>
|
)}
|
||||||
</DocsSidebar>
|
/>
|
||||||
)}
|
</Page>
|
||||||
/>
|
);
|
||||||
</Page>
|
}
|
||||||
);
|
}
|
||||||
|
Reference in New Issue
Block a user