Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save isaiah/c18b20f9c3629ebd6dec to your computer and use it in GitHub Desktop.

Select an option

Save isaiah/c18b20f9c3629ebd6dec to your computer and use it in GitHub Desktop.

Revisions

  1. isaiah created this gist Mar 4, 2016.
    138 changes: 138 additions & 0 deletions 0001-include-jquery-and-materializecss-for-test.patch
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,138 @@
    From b34d733deefac7fb7f96bf5408ae705c49e764fa Mon Sep 17 00:00:00 2001
    From: Isaiah Peng <[email protected]>
    Date: Fri, 4 Mar 2016 11:17:40 +0100
    Subject: [PATCH 1/1] include jquery and materializecss for test

    ---
    karma.conf.js | 2 ++
    package.json | 2 ++
    src/Select.js | 67 ++++++++++++++++++++++++++++++-----------------------------
    3 files changed, 38 insertions(+), 33 deletions(-)

    diff --git a/karma.conf.js b/karma.conf.js
    index 0a03abf..875256b 100644
    --- a/karma.conf.js
    +++ b/karma.conf.js
    @@ -16,6 +16,8 @@ module.exports = function(config) {

    // list of files / patterns to load in the browser
    files: [
    + 'node_modules/jquery/dist/jquery.js',
    + 'node_modules/materializecss/src/ng2-materializecss.js',
    'test/*Spec.js'
    ],

    diff --git a/package.json b/package.json
    index c7c72aa..8ed1e2b 100644
    --- a/package.json
    +++ b/package.json
    @@ -45,6 +45,7 @@
    "es5-shim": "^4.2.0",
    "eslint": "^1.9.0",
    "eslint-plugin-react": "^3.8.0",
    + "jquery": "^2.2.1",
    "karma": "^0.13.15",
    "karma-babel-preprocessor": "^6.0.1",
    "karma-mocha": "^0.2.0",
    @@ -52,6 +53,7 @@
    "karma-sinon-chai": "^1.1.0",
    "karma-sourcemap-loader": "^0.3.6",
    "karma-webpack": "^1.7.0",
    + "materializecss": "^1.0.11",
    "mocha": "^2.3.3",
    "phantomjs": "^1.9.18",
    "react": ">=0.14.0",
    diff --git a/src/Select.js b/src/Select.js
    index c21ded9..3c09a09 100644
    --- a/src/Select.js
    +++ b/src/Select.js
    @@ -4,21 +4,6 @@ import constants from './constants';

    class Select extends Component {

    - static propTypes = {
    - onChange: PropTypes.func.isRequired,
    - children: PropTypes.node.isRequired,
    - s: PropTypes.number,
    - m: PropTypes.number,
    - l: PropTypes.number,
    - label: PropTypes.node,
    - defaultValue: PropTypes.string,
    - browserDefault: PropTypes.bool
    - }
    -
    - static defaultProps = {
    - browserDefault: false
    - }
    -
    constructor(props) {
    super(props);
    this.state = { value: props.defaultValue };
    @@ -52,30 +37,46 @@ class Select extends Component {
    render() {
    const { children, label, browserDefault } = this.props;
    const classes = Object.assign(
    - {},
    - {
    - 'input-field': true,
    - 'col': true,
    - 'browser-default': browserDefault
    - },
    - constants.SIZES.reduce((result, size) => {
    - return this.props[size]
    - ? Object.assign({}, result, { [size + this.props[size]]: true })
    - : result;
    - }, {})
    - );
    + {},
    + {
    + 'input-field': true,
    + 'col': true,
    + 'browser-default': browserDefault
    + },
    + constants.SIZES.reduce((result, size) => {
    + return this.props[size]
    + ? Object.assign({}, result, { [size + this.props[size]]: true })
    + : result;
    + }, {})
    + );
    return (
    - <div className={cx(classes)}>
    - <select
    + <div className={cx(classes)}>
    + <select
    ref="__SELECT__"
    value={this.state.value}
    onChange={this._onChange.bind(this)} >
    - {children}
    - </select>
    - <label>{label}</label>
    - </div>
    + {children}
    + </select>
    + <label>{label}</label>
    + </div>
    );
    }
    }

    +Select.propTypes = {
    + onChange: PropTypes.func.isRequired,
    + children: PropTypes.node.isRequired,
    + s: PropTypes.number,
    + m: PropTypes.number,
    + l: PropTypes.number,
    + label: PropTypes.node,
    + defaultValue: PropTypes.string,
    + browserDefault: PropTypes.bool
    +};
    +
    +Select.defaultProps = {
    + browserDefault: false
    +};
    +
    +
    export default Select;
    --
    2.7.2