-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from pivotal-cf/select-fancy
feat(select-fancy): add a select fancy react component
- Loading branch information
Showing
5 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require('../spec_helper'); | ||
|
||
describe('SelectFancy', function() { | ||
var SelectFancy, subject; | ||
beforeEach(function() { | ||
SelectFancy = require('../../../src/pivotal-ui-react/select-fancy/select-fancy').SelectFancy; | ||
subject = React.render((<SelectFancy className="foo myClass" id="myId"/>), root); | ||
}); | ||
|
||
afterEach(function() { | ||
React.unmountComponentAtNode(root); | ||
}); | ||
|
||
it('renders a select fancy component with class', function() { | ||
expect('.select-fancy').toHaveClass('foo'); | ||
expect('.select-fancy').toHaveClass('myClass'); | ||
|
||
expect('select').toHaveClass('form-control'); | ||
expect('select').toHaveAttr('id', 'myId'); | ||
}); | ||
|
||
describe('when a name is provided', function() { | ||
beforeEach(function() { | ||
subject.setProps({name: 'my-select'}); | ||
}); | ||
|
||
it('renders the select with a name', function() { | ||
expect('select').toHaveAttr('name', 'my-select'); | ||
}); | ||
}); | ||
|
||
describe('when event handlers are provided', function() { | ||
var changeSpy; | ||
beforeEach(function() { | ||
changeSpy = jasmine.createSpy('change'); | ||
subject.setProps({onChange: changeSpy}); | ||
}); | ||
|
||
it('adds the handlers to the search input', function() { | ||
$('select').simulate('change'); | ||
expect(changeSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('when the disabled prop is truthy', function() { | ||
beforeEach(function() { | ||
subject.setProps({disabled: true}); | ||
}); | ||
|
||
it('adds the disabled class to the select-fancy wrapper', function() { | ||
expect('.select-fancy').toHaveClass('disabled'); | ||
}); | ||
|
||
it('disables the select', function() { | ||
expect('select:disabled').toExist(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"version": "1.10.0", | ||
"description": "A React component that provides a styled select fancy", | ||
"homepage": "http://styleguide.pivotal.io/react.html#select-fancy", | ||
"dependencies": { | ||
"classnames": "^1.2.0", | ||
"pui-css-forms": "1.10.0", | ||
"pui-react-helpers": "0.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import classnames from 'classnames'; | ||
import {mergeProps} from 'pui-react-helpers'; | ||
import React from 'react'; | ||
|
||
/** | ||
* @component SelectFancy | ||
* @description A select with a fancy style | ||
* | ||
* @property disabled {Boolean} Whether to disable the select. | ||
* | ||
* @example ```js | ||
* var SelectFancy = require('pui-react-select-fancy').SelectFancy; | ||
* var MyComponent = React.createClass({ | ||
* render() { | ||
* return ( | ||
* <SelectFancy name="my-select"> | ||
* <option>Fancy Option 1</option> | ||
* <option>Fancy Option 2</option> | ||
* </SelectFancy> | ||
* } | ||
* }); | ||
* ``` | ||
* | ||
* @see [Pivotal UI React](http://styleguide.pivotal.io/react.html#form_select_fancy) | ||
* @see [Pivotal UI CSS](http://styleguide.pivotal.io/forms.html#02_form_fancy_select) | ||
*/ | ||
|
||
const types = React.PropTypes; | ||
|
||
var SelectFancy = React.createClass({ | ||
propTypes: { | ||
disabled: types.bool | ||
}, | ||
|
||
render() { | ||
const {disabled} = this.props; | ||
const {className, style, ...props} = mergeProps(this.props, {className: classnames('select-fancy', {disabled})}); | ||
return (<div {...{className, style}}><select {...props} className="form-control"/></div>); | ||
} | ||
}); | ||
|
||
module.exports = {SelectFancy}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters