Skip to content

Commit

Permalink
start working on implimenting auto-select
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pollock committed Jul 5, 2018
1 parent 05e46b6 commit 5577685
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .storybook/addons.js

This file was deleted.

7 changes: 0 additions & 7 deletions .storybook/config.js

This file was deleted.

60 changes: 60 additions & 0 deletions src/components/fields/magic-select/MagicSelect.js
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 = {};
36 changes: 36 additions & 0 deletions src/components/fields/magic-select/MagicSelect.test.js
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();
})
});
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>
`;
13 changes: 0 additions & 13 deletions stories/index.js

This file was deleted.

0 comments on commit 5577685

Please sign in to comment.