Skip to content

Commit

Permalink
React.createClass to React.Component and fixing react 15.5 deprecatio…
Browse files Browse the repository at this point in the history
…ns (#181)

* replacing React.createClass to React.Component and fixing react 15.5 deprecations
* .gitignore reverted
  • Loading branch information
lunochkin authored and ericgio committed May 14, 2017
1 parent cb80abe commit 733700e
Show file tree
Hide file tree
Showing 45 changed files with 535 additions and 443 deletions.
26 changes: 13 additions & 13 deletions example/components/CodeSample.react.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import React from 'react';
import PropTypes from 'prop-types';

import Markdown from './Markdown';

const START_STR = '/* example-start */';
const END_STR = '/* example-end */';

const CodeSample = React.createClass({
propTypes: {
lang: React.PropTypes.string,
},

getDefaultProps() {
return {
lang: 'jsx',
};
},

class CodeSample extends React.Component {
render() {
// Strip out extraneous parts of the code.
const code = this.props.children;
Expand All @@ -29,7 +20,16 @@ ${code.slice(startIndex, endIndex)}
\`\`\``}
</Markdown>
);
},
});
}
}

CodeSample.propTypes = {
lang: PropTypes.string,
};

CodeSample.defaultProps = {
lang: 'jsx',
};


export default CodeSample;
14 changes: 8 additions & 6 deletions example/components/ExampleSection.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import React from 'react';

import CodeSample from '../components/CodeSample';

const ExampleSection = React.createClass({
getInitialState() {
return {
class ExampleSection extends React.Component {
constructor(props) {
super(props);

this.state = {
open: false,
};
},
}

render() {
const {children, code} = this.props;
Expand All @@ -33,7 +35,7 @@ const ExampleSection = React.createClass({
{open ? <CodeSample>{code}</CodeSample> : null}
</div>
);
},
});
}
}

export default ExampleSection;
8 changes: 4 additions & 4 deletions example/components/GithubStarsButton.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {findDOMNode} from 'react-dom';

const AUTHOR_REPO = 'ericgio/react-bootstrap-typeahead';

const GitHubStarsButton = React.createClass({
class GitHubStarsButton extends React.Component {
componentDidMount() {
const node = findDOMNode(this);
node.dataset.style = window.innerWidth > 480 ? 'mega': null;
},
}

render() {
return (
Expand All @@ -21,7 +21,7 @@ const GitHubStarsButton = React.createClass({
Star
</a>
);
},
});
}
}

export default GitHubStarsButton;
8 changes: 4 additions & 4 deletions example/components/Markdown.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cx from 'classnames';
import marked from 'marked';
import React from 'react';

const Markdown = React.createClass({
class Markdown extends React.Component {
componentWillMount() {
marked.setOptions({
gfm: true,
Expand All @@ -16,7 +16,7 @@ const Markdown = React.createClass({
return require('highlight.js').highlightAuto(code).value;
},
});
},
}

render() {
const html = marked.parse(this.props.children);
Expand All @@ -27,7 +27,7 @@ const Markdown = React.createClass({
dangerouslySetInnerHTML={{__html: html}}
/>
);
},
});
}
}

export default Markdown;
6 changes: 4 additions & 2 deletions example/components/Page.react.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, {Children, PropTypes} from 'react';
import React, {Children} from 'react';
import PropTypes from 'prop-types';
import createReactClass from 'create-react-class';
import {Col, Jumbotron, NavItem, Row} from 'react-bootstrap';

import Container from './Container';
Expand All @@ -8,7 +10,7 @@ import PageMenu from './PageMenu';

import getIdFromTitle from '../util/getIdFromTitle';

const Page = React.createClass({
const Page = createReactClass({
getInitialState() {
return {
activeHref: window.location.hash,
Expand Down
6 changes: 4 additions & 2 deletions example/components/Section.react.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, {PropTypes} from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import createReactClass from 'create-react-class';

import Anchor from './Anchor';
import ScrollSpy from './ScrollSpy';

import getIdFromTitle from '../util/getIdFromTitle';

const sectionContainer = Component => (
React.createClass({
createReactClass({
contextTypes: {
onAfter: PropTypes.func.isRequired,
onBefore: PropTypes.func.isRequired,
Expand Down
3 changes: 2 additions & 1 deletion example/components/Title.react.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {PropTypes} from 'react';
import React from 'react';
import PropTypes from 'prop-types';

import Anchor from './Anchor';

Expand Down
23 changes: 13 additions & 10 deletions example/examples/AsyncExample.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import {AsyncTypeahead} from '../../src/';
require('es6-promise').polyfill();

/* example-start */
const AsyncExample = React.createClass({
getInitialState() {
return {
class AsyncExample extends React.Component {

constructor(props) {
super(props);

this.state = {
allowNew: false,
multiple: false,
options: [],
};
},
}

render() {
return (
Expand All @@ -30,7 +33,7 @@ const AsyncExample = React.createClass({
{this._renderCheckboxes()}
</div>
);
},
}

_renderCheckboxes() {
const checkboxes = [
Expand All @@ -47,7 +50,7 @@ const AsyncExample = React.createClass({
{label}
</Checkbox>
));
},
}

_renderMenuItemChildren(option, props, index) {
return (
Expand All @@ -63,12 +66,12 @@ const AsyncExample = React.createClass({
<span>{option.login}</span>
</div>
);
},
}

_handleChange(e) {
const {checked, name} = e.target;
this.setState({[name]: checked});
},
}

_handleSearch(query) {
if (!query) {
Expand All @@ -78,8 +81,8 @@ const AsyncExample = React.createClass({
fetch(`https://api.github.com/search/users?q=${query}`)
.then(resp => resp.json())
.then(json => this.setState({options: json.items}));
},
});
}
}
/* example-end */

export default AsyncExample;
16 changes: 9 additions & 7 deletions example/examples/BasicBehaviorsExample.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import {Typeahead} from '../../src/';
import options from '../../example/exampleData';

/* example-start */
const BasicBehaviorsExample = React.createClass({
getInitialState() {
return {
class BasicBehaviorsExample extends React.Component {
constructor(props) {
super(props);

this.state = {
disabled: false,
dropup: false,
minLength: 0,
};
},
}

render() {
const {disabled, dropup, emptyLabel, minLength} = this.state;
Expand Down Expand Up @@ -56,7 +58,7 @@ const BasicBehaviorsExample = React.createClass({
</FormGroup>
</div>
);
},
}

_handleChange(e) {
const {checked, name} = e.target;
Expand All @@ -67,8 +69,8 @@ const BasicBehaviorsExample = React.createClass({
}

this.setState(newState);
},
});
}
}
/* example-end */

export default BasicBehaviorsExample;
14 changes: 8 additions & 6 deletions example/examples/BasicExample.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {Typeahead} from '../../src/';
import options from '../../example/exampleData';

/* example-start */
const BasicExample = React.createClass({
getInitialState() {
return {
class BasicExample extends React.Component {
constructor(props) {
super(props);

this.state = {
multiple: false,
};
},
}

render() {
const {multiple} = this.state;
Expand All @@ -30,8 +32,8 @@ const BasicExample = React.createClass({
</Checkbox>
</div>
);
},
});
}
}
/* example-end */

export default BasicExample;
13 changes: 7 additions & 6 deletions example/examples/BodyContainerExample.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {Typeahead} from '../../src/';
import options from '../../example/exampleData';

/* example-start */
const BodyContainerExample = React.createClass({
getInitialState() {
return {
class BodyContainerExample extends React.Component {
constructor(props) {
super(props);
this.state = {
bodyContainer: false,
};
},
}

render() {
const {bodyContainer} = this.state;
Expand Down Expand Up @@ -40,8 +41,8 @@ const BodyContainerExample = React.createClass({
</Checkbox>
</div>
);
},
});
}
}
/* example-end */

export default BodyContainerExample;
14 changes: 8 additions & 6 deletions example/examples/CustomFilteringExample.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {Typeahead} from '../../src/';
import options from '../../example/exampleData';

/* example-start */
const CustomFilteringExample = React.createClass({
getInitialState() {
return {
class CustomFilteringExample extends React.Component {
constructor(props) {
super(props);

this.state ={
filterBy: 'callback',
};
},
}

render() {
const {filterBy} = this.state;
Expand Down Expand Up @@ -55,8 +57,8 @@ const CustomFilteringExample = React.createClass({
))}
</div>
);
},
});
}
}
/* example-end */

export default CustomFilteringExample;
6 changes: 3 additions & 3 deletions example/examples/CustomSelectionsExample.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import {Typeahead} from '../../src/';

/* example-start */
const CustomSelectionsExample = React.createClass({
class CustomSelectionsExample extends React.Component {
render() {
return (
<Typeahead
Expand All @@ -13,8 +13,8 @@ const CustomSelectionsExample = React.createClass({
placeholder="Type anything..."
/>
);
},
});
}
}
/* example-end */

export default CustomSelectionsExample;
Loading

0 comments on commit 733700e

Please sign in to comment.