-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start working on implimenting auto-select
- Loading branch information
Josh Pollock
committed
Jul 5, 2018
1 parent
05e46b6
commit 5577685
Showing
6 changed files
with
124 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,60 @@ | ||
import React from 'react'; | ||
import {fieldInnerPropTypes, inputTypeProp, onValueChangePropType, optionsShapeProp, valuePropType} from '../propTypes'; | ||
import classNames from 'classnames'; | ||
import Autocomplete from 'react-autocomplete' | ||
import PropTypes from "prop-types"; | ||
/** | ||
* Encapsulates a complete Magic Select field | ||
*/ | ||
export const MagicSelect = (props) => { | ||
|
||
const onChange = (event) => { | ||
this.props.onValueChange(event.target.value); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={classNames('', props.className)} | ||
> | ||
<Autocomplete | ||
id={props.id} | ||
getItemValue={(item) => item.label} | ||
items={[ | ||
{ label: 'apple' }, | ||
{ label: 'banana' }, | ||
{ label: 'pear' } | ||
]} | ||
renderItem={(item, isHighlighted) => | ||
<div style={{ background: isHighlighted ? 'lightgray' : 'white' }}> | ||
{item.label} | ||
</div> | ||
} | ||
value={props.value} | ||
onChange={onChange} | ||
onSelect={(val) => value = val} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
/** | ||
* Prop definitions for MagicSelect component | ||
*/ | ||
MagicSelect.propTypes = { | ||
id: PropTypes.string.isRequired, | ||
fieldsList: optionsShapeProp, | ||
systemTagsList: optionsShapeProp, | ||
isRequired: PropTypes.bool, | ||
help: PropTypes.string, | ||
value: valuePropType, | ||
onValueChange: onValueChangePropType, | ||
options: PropTypes.array, | ||
disabled: PropTypes.bool, | ||
}; | ||
|
||
/** | ||
* Default property values for MagicSelect component | ||
* | ||
* @type {{}} | ||
*/ | ||
MagicSelect.defaultProps = {}; |
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,36 @@ | ||
|
||
import renderer from 'react-test-renderer'; | ||
import React from 'react'; | ||
import {mount} from 'enzyme'; | ||
import Enzyme from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import {MagicSelect } from "./MagicSelect"; | ||
|
||
Enzyme.configure({adapter: new Adapter()}); | ||
|
||
const genericChangeHandler = () => {}; | ||
describe( 'MagicSelect component', () => { | ||
let selectFieldValue = 'html'; | ||
|
||
|
||
it( 'Matches snapshot', () => { | ||
const component = renderer.create( | ||
<MagicSelect | ||
id={'magic-1'} | ||
fieldClassName={'magic'} | ||
onValueChange={genericChangeHandler} | ||
options={[ | ||
{ | ||
label: 'HTML', | ||
value: 'html' | ||
}, | ||
{ | ||
label: 'Plain Text', | ||
value: 'plain' | ||
} | ||
]} | ||
/> | ||
); | ||
expect( component.toJSON() ).toMatchSnapshot(); | ||
}) | ||
}); |
28 changes: 28 additions & 0 deletions
28
src/components/fields/magic-select/__snapshots__/MagicSelect.test.js.snap
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,28 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`MagicSelect component Matches snapshot 1`] = ` | ||
<div | ||
className="" | ||
> | ||
<div | ||
style={ | ||
Object { | ||
"display": "inline-block", | ||
} | ||
} | ||
> | ||
<input | ||
aria-autocomplete="list" | ||
aria-expanded={false} | ||
autoComplete="off" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
onClick={[Function]} | ||
onFocus={[Function]} | ||
onKeyDown={[Function]} | ||
role="combobox" | ||
value="" | ||
/> | ||
</div> | ||
</div> | ||
`; |
This file was deleted.
Oops, something went wrong.