diff --git a/spec/pivotal-ui-react/select-fancy/select-fancy_spec.js b/spec/pivotal-ui-react/select-fancy/select-fancy_spec.js new file mode 100644 index 000000000..79d6823e2 --- /dev/null +++ b/spec/pivotal-ui-react/select-fancy/select-fancy_spec.js @@ -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((), 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(); + }); + }); +}); diff --git a/src/pivotal-ui-react/select-fancy/package.json b/src/pivotal-ui-react/select-fancy/package.json new file mode 100644 index 000000000..67a82c4e8 --- /dev/null +++ b/src/pivotal-ui-react/select-fancy/package.json @@ -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" + } +} diff --git a/src/pivotal-ui-react/select-fancy/select-fancy.js b/src/pivotal-ui-react/select-fancy/select-fancy.js new file mode 100644 index 000000000..d644d33db --- /dev/null +++ b/src/pivotal-ui-react/select-fancy/select-fancy.js @@ -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 ( + * + * + * + * + * } + * }); + * ``` + * + * @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 (