Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Autogenerate the property description for the AppBar #2382

Merged
merged 3 commits into from
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ icon-builder/jsx

# Exclude IDE project folders
.idea
*.sublime-project
*.sublime-workspace

# OS files
.DS_STORE
8 changes: 6 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@
"prd": "webpack-dev-server --config webpack-production.config.js --progress --colors --profile"
},
"dependencies": {
"codemirror": "^5.5.0",
"css-loader": "^0.23.0",
"highlight.js": "^8.9.1",
"history": "^1.11.1",
"intl": "^1.0.1",
"marked": "^0.3.5",
"react-addons-perf": "^0.14.0",
"react-dom": "^0.14.0",
"react-motion": "^0.3.1",
"react-router": "^1.0.0-rc1",
"react-swipeable-views": "^0.3.0"
"react-swipeable-views": "^0.3.0",
"style-loader": "0.13.0"
},
"devDependencies": {
"raw-loader": "^0.5.1",
"react": "^0.14.0",
"react-addons-linked-state-mixin": "^0.14.0",
"react-addons-pure-render-mixin": "^0.14.3",
"react-docgen": "^2.4.0",
"webpack": "^1.11.0",
"webpack-dev-server": "^1.10.1"
}
Expand Down
15 changes: 15 additions & 0 deletions docs/src/app/components/AppBar/ExampleIcon.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import AppBar from 'material-ui/lib/app-bar';

const AppBarExampleIcon = React.createClass({
render() {
return (
<AppBar
title="Title"
iconClassNameRight="muidocs-icon-navigation-expand-more"
/>
);
},
});

export default AppBarExampleIcon;
29 changes: 29 additions & 0 deletions docs/src/app/components/AppBar/ExampleIconButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import AppBar from 'material-ui/lib/app-bar';
import IconButton from 'material-ui/lib/icon-button';
import NavigationClose from 'material-ui/lib/svg-icons/navigation/close';
import FlatButton from 'material-ui/lib/flat-button';

function handleTouchTap() {
alert('onTouchTap triggered on the title component');
}

const styles = {
title: {
cursor: 'pointer',
},
};

const AppBarExampleIconButton = React.createClass({
render() {
return (
<AppBar
title={<span style={styles.title} onTouchTap={handleTouchTap}>Title</span>}
iconElementLeft={<IconButton><NavigationClose /></IconButton>}
iconElementRight={<FlatButton label="Save" />}
/>
);
},
});

export default AppBarExampleIconButton;
33 changes: 33 additions & 0 deletions docs/src/app/components/AppBar/ExampleIconMenu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import AppBar from 'material-ui/lib/app-bar';
import IconButton from 'material-ui/lib/icon-button';
import NavigationClose from 'material-ui/lib/svg-icons/navigation/close';
import IconMenu from 'material-ui/lib/menus/icon-menu';
import MoreVertIcon from 'material-ui/lib/svg-icons/navigation/more-vert';
import MenuItem from 'material-ui/lib/menus/menu-item';

const AppBarExampleIconMenu = React.createClass({
render() {
return (
<AppBar
title="Title"
iconElementLeft={<IconButton><NavigationClose /></IconButton>}
iconElementRight={
<IconMenu
iconButtonElement={
<IconButton><MoreVertIcon /></IconButton>
}
targetOrigin={{horizontal:'right', vertical:'top'}}
anchorOrigin={{horizontal:'right', vertical:'top'}}
>
<MenuItem primaryText="Refresh" />
<MenuItem primaryText="Help" />
<MenuItem primaryText="Sign out" />
</IconMenu>
}
/>
);
},
});

export default AppBarExampleIconMenu;
7 changes: 7 additions & 0 deletions docs/src/app/components/AppBar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## AppBar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too maybe?


App bars are a collection of components placed as a static header for an application.
It is used for navigation, search branding, and actions.
An app bar is also referred to as the primary toolbar or action bar for Android.

### Examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be here? I mean... shouln't it be where this file is read from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it. What do you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples is inside the readme file, that means every read me MUST end with ###Examples. shouldn't it be where you make the final markdown FROM this readme file and append this there? also maybe the title should be there too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best practice would be to add a HeaderSection component that takes a title and a description markdown text and renders the header section. just like the PropTypeDescription,

59 changes: 59 additions & 0 deletions docs/src/app/components/MarkdownElement.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import marked from 'marked';
import PureRenderMixin from 'react-addons-pure-render-mixin';

require('./mui-github-markdown.css');

const styles = {
root: {
marginBottom: 14,
padding: '0 10px',
},
};

const MarkdownElement = React.createClass({
propTypes: {
text: React.PropTypes.string,
},
mixins: [
PureRenderMixin,
],
getDefaultProps() {
return {
text: '',
};
},

componentWillMount() {
marked.setOptions({
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false,
highlight: function(code, lang) {
return require('highlight.js').highlight(lang, code).value;
},
});
},

render() {
const {
text,
} = this.props;

/* eslint-disable */
return (
<div
style={styles.root}
className="markdown-body"
dangerouslySetInnerHTML={{__html: marked(text)}}
/>
);
/* eslint-enable */
},
});

export default MarkdownElement;
59 changes: 59 additions & 0 deletions docs/src/app/components/PropTypeDescription.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import {parse} from 'react-docgen';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import MarkdownElement from './MarkdownElement';

function generatePropType(type) {
switch (type.name) {
case 'func':
return 'function';

case 'custom':
return type.raw;

default:
return type.name;
}
}

const PropTypeDescription = React.createClass({
propTypes: {
code: React.PropTypes.string,
},
mixins: [
PureRenderMixin,
],
render() {
const {
code,
} = this.props;

let text = `### Properties
| Name | Type | Default | Description|
|:-----|:-----|:-----|:-----|\n`;

const componentInfo = parse(code);

for (let key in componentInfo.props) {
const prop = componentInfo.props[key];

let defaultValue = '';

if (prop.defaultValue) {
defaultValue = prop.defaultValue.value;
}

const description = (prop.required ? '**required**' : '*optional*') +
'. ' + prop.description.replace(/\n/g, '<br>');

text += `| ${key} | ${generatePropType(prop.type)} |`;
text += `${defaultValue} |${description} |\n`;
}

return (
<MarkdownElement text={text} />
);
},
});

export default PropTypeDescription;
65 changes: 13 additions & 52 deletions docs/src/app/components/code-example/code-block.jsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,23 @@
import React from 'react';
import ReactDOM from 'react-dom';
import {Styles} from 'material-ui';
const {ThemeManager} = Styles;
const DefaultRawTheme = Styles.LightRawTheme;

import MarkdownElement from '../MarkdownElement';
import PureRenderMixin from 'react-addons-pure-render-mixin';

const CodeBlock = React.createClass({

propTypes: {
children: React.PropTypes.node,
},

contextTypes : {
muiTheme: React.PropTypes.object,
},

//for passing default theme context to children
childContextTypes: {
muiTheme: React.PropTypes.object,
},

getChildContext() {
return {
muiTheme: this.state.muiTheme,
};
},

getInitialState() {
return {
muiTheme: this.context.muiTheme ? this.context.muiTheme : ThemeManager.getMuiTheme(DefaultRawTheme),
};
},

componentWillReceiveProps(nextProps, nextContext) {
let newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({muiTheme: newMuiTheme});
},

componentDidMount() {
let code = ReactDOM.findDOMNode(this.refs.code);
require([
'codemirror/lib/codemirror.js',
'codemirror/mode/htmlmixed/htmlmixed.js',
], function(Codemirror) {
Codemirror.fromTextArea(code, {
mode: 'htmlmixed',
readOnly: true,
});
});
children: React.PropTypes.string,
},

shouldComponentUpdate({children}) {
return this.props.children !== children;
},

mixins: [
PureRenderMixin,
],
render() {
const text = `\`\`\`js
${this.props.children}
\`\`\``;

return (
<textarea ref="code" value={this.props.children} readOnly={true}/>
<div className="CodeMirror">
<MarkdownElement text={text} />
</div>
);
},
});
Expand Down
Loading