From 27d745fef69269983d864ec48a2ffd160c1704c4 Mon Sep 17 00:00:00 2001 From: Alexander Fedyashov Date: Sat, 15 Jul 2017 13:53:30 +0300 Subject: [PATCH] docs(Example): add ShorthandExample and ability to version docs --- .../ComponentDoc/ComponentExample.js | 84 +++++++++++-------- .../ComponentDoc/ComponentVersion.js | 31 +++++++ .../ComponentDoc/ShorthandExample.js | 16 ++++ docs/app/index.ejs | 3 - 4 files changed, 96 insertions(+), 38 deletions(-) create mode 100644 docs/app/Components/ComponentDoc/ComponentVersion.js create mode 100644 docs/app/Components/ComponentDoc/ShorthandExample.js diff --git a/docs/app/Components/ComponentDoc/ComponentExample.js b/docs/app/Components/ComponentDoc/ComponentExample.js index 261e84fa59..f3766aba18 100644 --- a/docs/app/Components/ComponentDoc/ComponentExample.js +++ b/docs/app/Components/ComponentDoc/ComponentExample.js @@ -11,6 +11,7 @@ import { exampleContext, repoURL } from 'docs/app/utils' import { Divider, Grid, Icon, Header, Menu, Popup } from 'src' import Editor from 'docs/app/Components/Editor/Editor' import { scrollToAnchor } from 'docs/app/utils' +import ComponentVersion from './ComponentVersion' const babelConfig = { presets: ['es2015', 'react', 'stage-1'], @@ -67,6 +68,10 @@ class ComponentExample extends Component { location: PropTypes.object.isRequired, match: PropTypes.object.isRequired, title: PropTypes.node, + version: PropTypes.oneOfType([ + PropTypes.arrayOf(PropTypes.string), + PropTypes.string, + ]), } componentWillMount() { @@ -388,7 +393,7 @@ class ComponentExample extends Component { } render() { - const { children, description, title } = this.props + const { children, description, title, version } = this.props const { copiedDirectLink, exampleElement, showCode, showHTML } = this.state const exampleStyle = {} @@ -397,41 +402,50 @@ class ComponentExample extends Component { } return ( - - - {title &&
} - {description &&

{description}

} - - - - - - - - - - - - - - - - - - - - - - - - {children && ( - - {children} + + + + {title &&
} + {description &&

{description}

} - )} - - {exampleElement} - + + + + + + + + + + + + + + + + + + + + + + + + + {version && } + + + + + {children && {children}} + + + + + {exampleElement} + + + {this.renderJSX()} {this.renderHTML()} diff --git a/docs/app/Components/ComponentDoc/ComponentVersion.js b/docs/app/Components/ComponentDoc/ComponentVersion.js new file mode 100644 index 0000000000..356229d01d --- /dev/null +++ b/docs/app/Components/ComponentDoc/ComponentVersion.js @@ -0,0 +1,31 @@ +import PropTypes from 'prop-types' +import React, { PureComponent } from 'react' + +import { Label } from 'src' + +export default class ComponentVersion extends PureComponent { + static propTypes = { + version: PropTypes.oneOfType([ + PropTypes.arrayOf(PropTypes.string), + PropTypes.string, + ]), + } + + computeVersions = () => { + const { version } = this.props + + if (typeof version === 'string') return [version, null] + return version + } + + render() { + const [SUIR, SUI] = this.computeVersions() + + return ( +
+ {
+ ) + } +} diff --git a/docs/app/Components/ComponentDoc/ShorthandExample.js b/docs/app/Components/ComponentDoc/ShorthandExample.js new file mode 100644 index 0000000000..1b67f9921a --- /dev/null +++ b/docs/app/Components/ComponentDoc/ShorthandExample.js @@ -0,0 +1,16 @@ +import PropTypes from 'prop-types' +import React from 'react' + +import ComponentExample from './ComponentExample' + +const ShorthandExample = ({ description, ...rest }) => + +ShorthandExample.propTypes = { + description: PropTypes.node, +} + +ShorthandExample.defaultProps = { + description: 'You can do the same using shorthands.', +} + +export default ShorthandExample diff --git a/docs/app/index.ejs b/docs/app/index.ejs index 6a4fe7b527..a6b51ddb44 100644 --- a/docs/app/index.ejs +++ b/docs/app/index.ejs @@ -163,9 +163,6 @@ .docs-example-menu { transition: opacity 200ms; - position: absolute; - top: 1rem; - right: 1rem; opacity: 0; }