Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a MagicSelect #4

Merged
merged 25 commits into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3002d4a
version 1.3.1
Jul 5, 2018
05e46b6
require react-autocomplete #1
Jul 5, 2018
5577685
start working on implimenting auto-select
Jul 5, 2018
d6b879e
get MagicSelect roughly working #1
Jul 5, 2018
5b53a72
#1 handle open/close and update of magic select #1
Jul 5, 2018
75bec8b
impliment MagicItem list component in magic select
Jul 5, 2018
7eb3133
#1 split value and label in MagicItem
Jul 5, 2018
09903bd
#1 allow for render MagicItem wrapped in span
Jul 5, 2018
8d23e9e
#1 re-impliment magic item so that it doesn't make errors for passing…
Jul 6, 2018
4877dd6
additional test coverage #1
Jul 6, 2018
69d9d7d
Allow switching inner input type
Jul 6, 2018
06e0c31
accidently add a button group component #1
Jul 6, 2018
13e685a
allow icon buttons #1
Jul 7, 2018
e01c83a
Get magic select list type switching working #1
Jul 7, 2018
1e9c184
only show the magic select buttons when the magic selec tis open #1
Jul 7, 2018
3c8c353
rewire MagicSelect as a group and inner component
Jul 7, 2018
cb9a5ca
handle magic select value so it works with updates #1
Jul 7, 2018
39117a8
Use consistent classes and propTypes for magic group #1
Jul 7, 2018
0cb13b4
use a consitent label in magic group #1
Jul 7, 2018
0e63574
test for MagicSelect.onChange() #1
Jul 7, 2018
53c3522
Using magic tags in render groups #1
Jul 7, 2018
410d17b
clean up the message component in magic field gorup #1
Jul 7, 2018
fc5b44c
#1 refresh snapshots and docs
Jul 7, 2018
35e6ab1
#1 increase coverage for magic tag selectors
Jul 7, 2018
31ad27d
#1 additonal tests for magic groups
Jul 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
523 changes: 260 additions & 263 deletions .idea/workspace.xml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions asset-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"http://localhost:3000/main.js": "http://localhost:3000/static/js/bundle.js",
"http://localhost:3000/main.js.map": "http://localhost:3000/static/js/bundle.js.map",
"http://localhost:3000/static/media/logo.svg": "http://localhost:3000/static/media/logo.83748054.svg"
}
24 changes: 17 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "@caldera-labs/components",
"version": "1.3.0",
"version": "1.3.1",
"dependencies": {
"@helpdotcom/is": "^3.0.4",
"classnames": "^2.2.6",
"downshift": "^1.31.16"
"downshift": "^1.31.16",
"react-autocomplete": "^1.8.1"
},
"license": "GPL-2.0",
"scripts": {
Expand Down
23 changes: 22 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import './App.css';
import {FieldGroup} from "./components/fields/FieldGroup";
import {fieldSetFactory} from "./components/fields/factories/fieldSetFactory";
import {RenderGroup} from "./components/RenderGroup";
import {MagicSelect} from "./components/fields/magic-select/MagicSelect";

let textFieldValue = 'Roy,Mike';
const textFieldConfig = {
Expand Down Expand Up @@ -98,7 +99,8 @@ const configFields = [
textFieldConfig,
hiddenFieldConfig,
selectFieldConfig,
fieldSetField
fieldSetField,
numberFieldConfig
];
const configFieldEls = fieldSetFactory(configFields);

Expand Down Expand Up @@ -141,6 +143,25 @@ class App extends Component {
})}
</div>

<div>
<h2>Magic Select</h2>
<MagicSelect
id={'magic-3'}
fieldClassName={'magic'}
onValueChange={() => {}}
options={[
{
label: 'HTML',
value: 'html'
},
{
label: 'Plain Text',
value: 'plain'
}
]}
/>
</div>

<div>
<h2>Inputs</h2>
<FieldGroup
Expand Down
3 changes: 2 additions & 1 deletion src/components/fields/FieldInner.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const FieldInner = (props) => {
switch( props.type ){
case 'select':
case 'dropdown':
const options = Array.isArray(props.options) ? props.options : [];
return (
<SelectField
id={props.id}
Expand All @@ -48,7 +49,7 @@ export const FieldInner = (props) => {
value={props.value}
onValueChange={props.onValueChange}
inputType={props.inputType}
options={props.options}
options={options}
disabled={props.disabled}
onBlur={props.onBlur}
onFocus={props.onFocus}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ exports[`Factories Field set factory Renders with elements 1`] = `
>
<option
className="caldera-config-option"
value={undefined}
/>
value={null}
>
-- Select --
</option>
</select>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/components/fields/factories/fieldFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ const configFields = [
'id': 'pid-1',
'label': 'Sequence',
'type': 'dropdown',
'options': ['-- Select A ConvertKit Sequence --'],
'options': [{
value: null,
label:'-- Select --'
}],
'desc': 'ConvertKit sequence to add subscriber to. Sequences are also referred to as courses.',
'description': false,
'extra_classes': 'field-Something is wrong',
Expand Down Expand Up @@ -368,7 +371,6 @@ describe('Factories', () => {
);
expect(wrapper.children()).toHaveLength(configFields.length);
expect(wrapper.find('.f-1')).toHaveLength(1);
expect(wrapper.find('.f-1').text()).toBe('Sequence');
});


Expand Down
80 changes: 80 additions & 0 deletions src/components/fields/magic-select/MagicItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react';
import {
optionShape
} from '../propTypes';
import classNames from 'classnames';
import PropTypes from 'prop-types';

/**
* Create magic item for option of magic selects
*
* This can not be a functional component
* https://github.com/reactjs/react-autocomplete/pull/293#issuecomment-371617758
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*
*
* @param {Object} props
* @return {*}
* @constructor
*/
export class MagicItem extends React.PureComponent {

render() {
return React.createElement(
this.props.elementType,
{
style: {background: this.props.isHighlighted ? this.props.highlightColor : this.props.notHighlighterColor},
className: classNames(this.props.className, 'magic-input-option'),

},
(
<React.Fragment>
<span
className={classNames('magic-item-label', 'magic-item-left')}

>
{this.props.item.value}
</span>

<span
className={classNames('magic-item-value', 'magic-item-right')}
>
{this.props.item.label}
</span>
</React.Fragment>
)
);
}
};

/**
* Prop definition for allowed element types
* @type {shim}
*/
const elemenetTypesProp = PropTypes.oneOf(['div', 'span']);
/**
* Prop definitions for MagicItem component
*
* @type {{item: shim, isHighlighted: shim, className: shim, highlightColor: shim, notHighlighterColor: shim}}
*/
MagicItem.propTypes = {
elementType: elemenetTypesProp,
innerElementType: elemenetTypesProp,
item: PropTypes.shape(optionShape),
isHighlighted: PropTypes.bool,
className: PropTypes.string,
highlightColor: PropTypes.string,
notHighlighterColor: PropTypes.string
};

/**
* Default props for the MagicItem component
*
* @type {{isHighlighted: boolean, highlightColor: string, notHighlightedColor: string}}
*/
MagicItem.defaultProps = {
elementType: 'div',
innerElementType: 'div',
isHighlighted: false,
highlightColor: 'lightgray',
notHighlightedColor: 'white',
};
38 changes: 38 additions & 0 deletions src/components/fields/magic-select/MagicItem.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import renderer from 'react-test-renderer';
import React from 'react';
import {MagicItem} from './MagicItem';


describe('MagicSelect component', () => {

it('Matches snapshot', () => {
const component = renderer.create(
<MagicItem
item={{
label: 'HTML',
value: 'html'
}}
highlightColor={'#fff00'}
notHighlighterColor={'white'}
isHighlighted={true}
/>
);
expect(component.toJSON()).toMatchSnapshot();
});

it('Can render as span', () => {
const component = renderer.create(
<MagicItem
item={{
label: 'HTML',
value: 'html'
}}
highlightColor={'#fff00'}
notHighlighterColor={'white'}
isHighlighted={true}
elementType={'span'}
/>
);
expect(component.toJSON()).toMatchSnapshot();
});
});
Loading