Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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:3001/main.js": "http://localhost:3001/static/js/bundle.js",
"http://localhost:3001/main.js.map": "http://localhost:3001/static/js/bundle.js.map",
"http://localhost:3001/static/media/logo.svg": "http://localhost:3001/static/media/logo.83748054.svg"
}
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@caldera-labs/components",
"version": "1.5.1",
"version": "1.6.0",
"dependencies": {
"@helpdotcom/is": "^3.0.4",
"classnames": "^2.2.6",
Expand Down
3 changes: 3 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ class App extends Component {
label: 'Two'
}
]}
onValueChange={(newValue) => {
console.log(newValue);
}}
/>

</div>
Expand Down
4 changes: 4 additions & 0 deletions src/components/fields/FieldGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Message} from './messages/Message';
import {messageObjectFactory} from './messages/messageObjectFactory';
import {fieldsetCheckboxHandler} from './field-group-change-handlers/fieldsetCheckboxHandler';
import {MagicFieldGroup} from './magic-select/MagicFieldGroup';
import {PasswordFieldGroup} from "./PasswordFieldGroup";

/**
* Represents one configField -- wrapper, label and input.
Expand All @@ -24,6 +25,9 @@ export const FieldGroup = (props) => {
return <MagicFieldGroup {...props} />;
}

if( 'password' === props.type ){
return <PasswordFieldGroup {...props } />;
}
/**
* Creates the id attribute
* @return {String}
Expand Down
95 changes: 95 additions & 0 deletions src/components/fields/PasswordFieldGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React from 'react';
import classNames from 'classnames';
import {ariaDescribedbyAttr} from './util';
import {
fieldGroupPropTypes,
} from './propTypes';
import {FieldGroup} from "./FieldGroup";
import {FieldInner} from './FieldInner';
import {RenderGroup} from '../RenderGroup';
import {Message} from './messages/Message';
import {messageObjectFactory} from './messages/messageObjectFactory';
import {Password} from "./input/password";

/**
* Represents one configField -- wrapper, label and input.
*
* @param props
* @return {*}
* @constructor
*/
export const PasswordFieldGroup = (props) => {

/**
* Creates the id attribute
* @return {String}
*/
function idAttrForHelpElement() {
return ariaDescribedbyAttr(props.id, props.help);
}

const message = 'object' === typeof props.message
? messageObjectFactory(props.message)
: messageObjectFactory({message: null, error: false});

return (
<div
className={RenderGroup.classNames.fieldWrapper}
>
<FieldGroup.Label
id={props.id}
label={props.label}
/>

<Message
message={message}
/>
<Password
id={props.id}
type={'password'}
help={props.help}
onClick={props.onClick}
disabled={props.disabled}
onFocus={props.onFocus}
onBlur={props.onBlur}
fieldClassName={
classNames(
props.fieldClassName,
{
required: props.isRequired,
}
)
}
/>

{props.help &&
<p
id={`${idAttrForHelpElement()}`}
className={'description'}
>
{props.help}
</p>
}
</div>
);


};

/**
* The prop type definitions for FieldGroup components
*
* @type {{id: (boolean|shim|*), isBlockInput: shim, isRequired: shim, help: shim, label: (boolean|shim|*), type: shim, value: shim, onValueChange: (boolean|shim|*), inputType: shim}}
*/
PasswordFieldGroup.propTypes = fieldGroupPropTypes;

/**
* Default props for FieldGroups
*
* @type {{isBlockInput: boolean, isRequired: boolean, help: string}}
*/
PasswordFieldGroup.defaultProps = {
isBlockInput: true,
isRequired: false,
help: ''
};
16 changes: 13 additions & 3 deletions src/components/fields/factories/fieldFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from './fieldFactory';
import {prepareFieldConfig} from './prepareFieldConfig';
import {fieldSetFactory} from './fieldSetFactory';
import {getHtmlInputTypes} from '../util';
import {getHtmlInputTypes, isValidHtml5type} from '../util';
import {mount} from 'enzyme';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Expand All @@ -27,6 +27,8 @@ const hiddenFieldConfig = {
'description': false
};



const magicField = {
'id': 'cf-magic-example',
'type': 'magic',
Expand Down Expand Up @@ -106,7 +108,17 @@ configFields.map(config => {

describe('Factories', () => {
describe('Field factory', () => {
const passwordFieldConfig = {
'id': 'your-password',
'type': 'password',
'label': 'Password',
'description': false,
'help': ''
};

it( 'Can be a password field', () => {
expect(prepareFieldConfig(passwordFieldConfig).type).toEqual('password' );
});
it('validators array is empty array if none supplied', () => {
expect(prepareFieldConfig(textFieldConfig).validators).toEqual([]);
});
Expand Down Expand Up @@ -148,7 +160,6 @@ describe('Factories', () => {
value: '2',
label: 'Two'
}

],
value: [],
onValueChange: () => {
Expand Down Expand Up @@ -189,7 +200,6 @@ describe('Factories', () => {

it('passes the field options for select fields', () => {
expect(prepareFieldConfig(selectFieldConfig).options).toEqual(selectFieldOptions);

});

it('Changes "dropdown" to select', () => {
Expand Down
10 changes: 9 additions & 1 deletion src/components/fields/factories/prepareFieldConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ export const prepareFieldConfig = (fieldArgs) => {
case 'number':
default:
fieldArgs.inputType = isValidHtml5type(fieldArgs.type) ? fieldArgs.type : 'text';
fieldArgs.type = 'input';
if ('password' === fieldArgs.type || 'password' === fieldArgs.inputType ) {
fieldArgs.type = 'password';
fieldArgs.inputType = 'password';

} else {
fieldArgs.type = 'input';

}
break;
}

Expand All @@ -78,6 +85,7 @@ export const prepareFieldConfig = (fieldArgs) => {
? messageObjectFactory(fieldArgs.message)
: messageObjectFactory({message:null, error: false });


fieldArgs.validators = validators;
return fieldArgs;
};
70 changes: 70 additions & 0 deletions src/components/fields/input/Password.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import renderer from 'react-test-renderer';
import React from 'react';
import {shallow} from 'enzyme';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import {Password} from './Password';
import {FieldGroup} from "../FieldGroup";

Enzyme.configure({adapter: new Adapter()});

describe('Input component', () => {
it('Passes its props', () => {
const component = renderer.create(
<Password
id={'bags'}
fieldClassName={'foo'}
onValueChange={() => {
}}
/>
);
expect(component.toJSON()).toMatchSnapshot();
});

describe('Password component rendering', () => {

it( 'passes value to change handler', () => {
let receivedValue = '';
const handler = (newValue) => {
receivedValue = newValue;
};
const wrapper = shallow(
<Password
id={'password2'}
fieldClassName={'password'}
onValueChange={handler}
value={receivedValue}
/>
);
wrapper.find('#password2').simulate('change', { target: { value: '12345' } });
expect(receivedValue).toBe('12345');
//expect(wrapper.find('input').prop('type')).toBe('password');
});

it( 'Renders in FieldGroup', () => {

const wrapper = shallow(
<FieldGroup
id={'password3'}
label={'password'}
type={'password'}
innertype={'password'}
isRequired={true}
value={'12345'}
onValueChange={() => {

}}
help={'aaa'}

/>
)
expect(wrapper.find('#password3').prop('type')).toBe('password');
});

});


});



16 changes: 16 additions & 0 deletions src/components/fields/input/__snapshots__/Password.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Input component Passes its props 1`] = `
<input
aria-describedby=""
className="foo field-config"
disabled={undefined}
id="bags"
onBlur={undefined}
onChange={[Function]}
onFocus={undefined}
required={false}
type="password"
value={undefined}
/>
`;
58 changes: 58 additions & 0 deletions src/components/fields/input/password.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import {fieldPropTypes} from '../propTypes';
import classNames from 'classnames';
import {RenderGroup} from '../../RenderGroup';
/**
* Password input component
*
* @param {Object} props
* @returns {*}
* @constructor
*/
export const Password = (props) => {

/**
* Dispatches value of input when it changes
* @param event
* @return {*}
*/
function changeHandler(event){
return props.onValueChange(event.target.value);
}

return (
<input
type={'password'}
id={props.id}
className={classNames(
props.fieldClassName,
RenderGroup.classNames.input
)}
aria-describedby={props.ariaDescribedbyAttr}
required={props.isRequired}
onChange={changeHandler}
value={props.value}
disabled={props.disabled}
onBlur={props.onBlur}
onFocus={props.onFocus}
/>
);

}


/**
* Prop definitions for Password components
*/
Password.propTypes = fieldPropTypes;

/**
* Default props for Password Component
*
* @type {{ariaDescribedbyAttr: string, isRequired: boolean, inputType: string}}
*/
Password.defaultProps = {
ariaDescribedbyAttr: '',
isRequired: false,
inputType: 'text'
};
2 changes: 1 addition & 1 deletion src/components/fields/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const fieldGroupPropTypes = {
isRequired: PropTypes.bool,
help: PropTypes.string,
label: PropTypes.string.isRequired,
type: PropTypes.oneOf(['input', 'select', 'fieldset', 'magic']),
type: PropTypes.oneOf(['input', 'select', 'fieldset', 'magic', 'password']),
value: valuePropType,
onValueChange: onValueChangePropType,
options: PropTypes.array,
Expand Down