mirror of
https://github.com/strapi/strapi.git
synced 2025-12-24 05:34:33 +00:00
Merge branch 'master' into fix/mariadb
This commit is contained in:
commit
ab8f271eda
@ -403,6 +403,32 @@ export default Foo;
|
||||
|
||||
***
|
||||
|
||||
## InputAddon
|
||||
|
||||
| Property | Type | Required | Description |
|
||||
| -------- | ---- | -------- | ----------- |
|
||||
| addon | string | no | Sets the input's addon. Works with i18n |
|
||||
| autoFocus | bool | no | Sets the input's autoFocus |
|
||||
| className | string | no | custom className for the input |
|
||||
| deactivateErrorHighlight | bool | no | Allow to deactivate the red border on the input when there is an error |
|
||||
| disabled | bool | no | Disables the input |
|
||||
| errors | array | no | Sets the red border on the input |
|
||||
| onBlur | func | no | Function executed when the user leaves the input |
|
||||
| onFocus | func | no | Function executed when the user enters the input |
|
||||
| name | string | yes | The name of the input |
|
||||
| placeholder | string | no | Input's placeholder, works with i18n |
|
||||
| style | object | no | Input's style property |
|
||||
| tabIndex | string | no | Input's tabIndex |
|
||||
| value | string or number | yes | Input's value |
|
||||
|
||||
***
|
||||
|
||||
## InputDate
|
||||
|
||||
Please refer to the [InputText documentation](#InputText);
|
||||
|
||||
***
|
||||
|
||||
## InputEmail
|
||||
|
||||
Please refer to the [InputText documentation](#InputText);
|
||||
@ -430,6 +456,26 @@ InputNumber component.
|
||||
|
||||
***
|
||||
|
||||
## InputSearch
|
||||
|
||||
InputSearch component.
|
||||
|
||||
| Property | Type | Required | Description |
|
||||
| -------- | ---- | -------- | ----------- |
|
||||
| autoFocus | bool | no | Sets the input's autoFocus |
|
||||
| className | string | no | custom className for the input |
|
||||
| deactivateErrorHighlight | bool | no | Allow to deactivate the red border on the input when there is an error |
|
||||
| disabled | bool | no | Disables the input |
|
||||
| error | bool | no | Sets the red border on the input |
|
||||
| onBlur | func | no | Function executed when the user leaves the input |
|
||||
| onChange | func | yes | Handler to modify the input's value |
|
||||
| onFocus | func | no | Function executed when the user enters the input |
|
||||
| name | string | yes | The name of the input |
|
||||
| placeholder | string | no | Input's placeholder, works with i18n |
|
||||
| style | object | no | Input's style property |
|
||||
| tabIndex | string | no | Input's tabIndex |
|
||||
| value | string | yes | Input's value |
|
||||
|
||||
***
|
||||
|
||||
## InputSelect
|
||||
@ -517,6 +563,49 @@ Input type: 'toggle' component
|
||||
|
||||
***
|
||||
|
||||
## InputAddonWithErrors
|
||||
|
||||
| Property | Type | Required | Description |
|
||||
| -------- | ---- | -------- | ----------- |
|
||||
| addon | string | no | Sets the input's addon. Works with i18n |
|
||||
| autoFocus | bool | no | Sets the input's autoFocus |
|
||||
| className | string | no | Overrides the container className |
|
||||
| customBootstrapClass | string | no | Allows to override the input bootstrap col system |
|
||||
| deactivateErrorHighlight | bool | no | Allow to deactivate the red border on the input when there is an error |
|
||||
| didCheckErrors | bool | no | Use this props to display errors after submitting a form. |
|
||||
| disabled | bool | no | Disables the input |
|
||||
| errors | array | no | Array of errors |
|
||||
| errorsClassName | string | no | Overrides the InputErrors' className |
|
||||
| errorsStyle | object | no | Overrides the InputErrors' style |
|
||||
| inputClassName | string | no | Overrides the InputText's className |
|
||||
| inputDescriptionClassName | string | no | Overrides the InputDescription's className |
|
||||
| inputDescriptionStyle | object | no | Overrides the InputDescription's style|
|
||||
| inputStyle | object | no | Overrides the InputText's style |
|
||||
| labelClassName | string | no | Overrides the Label's className |
|
||||
| labelStyle | object | no | Overrides the Label's style |
|
||||
| onBlur | func | no | Function executed when the user leaves the input |
|
||||
| onChange | func | yes | Handler to modify the input's value |
|
||||
| onFocus | func | no | Function executed when the user enters the input |
|
||||
| name | string | yes | The name of the input |
|
||||
| noErrorsDescription | bool | no | Remove the input's errors description |
|
||||
| placeholder | string | no | Input's placeholder, works with i18n |
|
||||
| style | object | no | Overrides the container style |
|
||||
| tabIndex | string | no | Input's tabIndex |
|
||||
| validations | object | no | Input's validations |
|
||||
| value | string | yes | Input's value |
|
||||
|
||||
### Usage
|
||||
|
||||
Please refer to the [InputTextWithErrors](#InputTextWithErrors) documentation.
|
||||
|
||||
***
|
||||
|
||||
## InputDateWithErrors
|
||||
|
||||
Please refer to the [InputTextWithErrors](#InputTextWithErrors) documentation.
|
||||
|
||||
***
|
||||
|
||||
## InputEmailWithErrors
|
||||
|
||||
Please refer to the [InputTextWithErrors](#InputTextWithErrors) documentation.
|
||||
@ -529,6 +618,12 @@ Please refer to the [InputTextWithErrors](#InputTextWithErrors) documentation.
|
||||
|
||||
***
|
||||
|
||||
## InputSearchWithErrors
|
||||
|
||||
Please refer to the [InputTextWithErrors](#InputTextWithErrors) documentation.
|
||||
|
||||
***
|
||||
|
||||
## InputSelectWithErrors
|
||||
|
||||
Component integrates Label, InputSelect, InputDescription and InputErrors.
|
||||
|
||||
1
packages/strapi-admin/admin/.gitignore
vendored
1
packages/strapi-admin/admin/.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
# Don't check auto-generated stuff into git
|
||||
coverage
|
||||
node_modules
|
||||
manifest.json
|
||||
plugins.json
|
||||
stats.json
|
||||
package-lock.json
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"host": "localhost",
|
||||
"host": "127.0.0.1",
|
||||
"port": 1337,
|
||||
"autoReload": {
|
||||
"enabled": true
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
"connector": "strapi-mongoose",
|
||||
"settings": {
|
||||
"client": "mongo",
|
||||
"host": "${process.env.DATABASE_HOST || 'localhost'}",
|
||||
"host": "${process.env.DATABASE_HOST || '127.0.0.1'}",
|
||||
"port": "${process.env.DATABASE_PORT || 27017}",
|
||||
"database": "${process.env.DATABASE_NAME || 'production'}",
|
||||
"username": "${process.env.DATABASE_USERNAME || ''}",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"host": "localhost",
|
||||
"host": "127.0.0.1",
|
||||
"port": 1337,
|
||||
"autoReload": {
|
||||
"enabled": false
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
"connector": "strapi-mongoose",
|
||||
"settings": {
|
||||
"client": "mongo",
|
||||
"host": "localhost",
|
||||
"host": "127.0.0.1",
|
||||
"port": 27017,
|
||||
"database": "test",
|
||||
"username": "",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"host": "localhost",
|
||||
"host": "127.0.0.1",
|
||||
"port": 1337,
|
||||
"autoReload": {
|
||||
"enabled": true
|
||||
|
||||
@ -136,7 +136,7 @@ module.exports = (scope, cb) => {
|
||||
prefix: '',
|
||||
name: 'host',
|
||||
message: 'Host:',
|
||||
default: _.get(scope.database, 'host', 'localhost')
|
||||
default: _.get(scope.database, 'host', '127.0.0.1')
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
|
||||
@ -270,6 +270,7 @@ class Input extends React.Component { // eslint-disable-line react/prefer-statel
|
||||
<FormattedMessage id={this.props.placeholder || this.props.label} values={this.props.labelValues}>
|
||||
{(placeholder) => (
|
||||
<input
|
||||
autoComplete="new-password"
|
||||
className={`form-control ${!this.props.deactivateErrorHighlight && !isEmpty(this.state.errors) ? 'is-invalid': ''}`}
|
||||
onChange={this.props.onChange}
|
||||
value={this.props.value}
|
||||
|
||||
@ -0,0 +1,122 @@
|
||||
/**
|
||||
*
|
||||
* InputAddon
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { isEmpty, isFunction, upperFirst } from 'lodash';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import cn from 'classnames';
|
||||
|
||||
import styles from './styles.scss';
|
||||
|
||||
class InputAddon extends React.Component {
|
||||
state = { isFocused: false };
|
||||
|
||||
handleBlur = (e) => {
|
||||
this.setState({ isFocused: !this.state.isFocused });
|
||||
|
||||
if (isFunction(this.props.onBlur)) {
|
||||
this.props.onBlur(e);
|
||||
}
|
||||
}
|
||||
|
||||
handleFocus = (e) => {
|
||||
this.setState({ isFocused: !this.state.isFocused });
|
||||
this.props.onFocus(e);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
addon,
|
||||
autoFocus,
|
||||
className,
|
||||
deactivateErrorHighlight,
|
||||
disabled,
|
||||
error,
|
||||
name,
|
||||
onChange,
|
||||
placeholder,
|
||||
style,
|
||||
tabIndex,
|
||||
value,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<div className={cn(styles.inputAddon, 'input-group', !isEmpty(className) && className)} style={style}>
|
||||
<FormattedMessage id={addon} defaultMessage={upperFirst(addon)}>
|
||||
{(message) => (
|
||||
<span className={cn(
|
||||
'input-group-addon',
|
||||
styles.addon,
|
||||
this.state.isFocused && styles.addonFocus,
|
||||
!deactivateErrorHighlight && error && styles.errorAddon,
|
||||
)}
|
||||
>
|
||||
{message}
|
||||
</span>
|
||||
)}
|
||||
</FormattedMessage>
|
||||
<FormattedMessage id={placeholder} defaultMessage={placeholder}>
|
||||
{(message) => (
|
||||
<input
|
||||
autoFocus={autoFocus}
|
||||
className={cn(
|
||||
'form-control',
|
||||
!deactivateErrorHighlight && error && 'is-invalid',
|
||||
!deactivateErrorHighlight && error && this.state.isFocused && styles.invalidAddon,
|
||||
)}
|
||||
disabled={disabled}
|
||||
id={name}
|
||||
name={name}
|
||||
onBlur={this.handleBlur}
|
||||
onChange={onChange}
|
||||
onFocus={this.handleFocus}
|
||||
placeholder={message}
|
||||
tabIndex={tabIndex}
|
||||
type="text"
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
</FormattedMessage>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
InputAddon.defaultProps = {
|
||||
addon: 'app.utils.placeholder.defaultMessage', // Prevent error from FormattedMessage
|
||||
autoFocus: false,
|
||||
className: '',
|
||||
deactivateErrorHighlight: false,
|
||||
disabled: false,
|
||||
error: false,
|
||||
onBlur: () => {},
|
||||
onFocus: () => {},
|
||||
placeholder: 'app.utils.placeholder.defaultMessage',
|
||||
style: {},
|
||||
tabIndex: '0',
|
||||
};
|
||||
|
||||
InputAddon.propTypes = {
|
||||
addon: PropTypes.string,
|
||||
autoFocus: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
deactivateErrorHighlight: PropTypes.bool,
|
||||
disabled: PropTypes.bool,
|
||||
error: PropTypes.bool,
|
||||
onBlur: PropTypes.oneOfType([
|
||||
PropTypes.func,
|
||||
PropTypes.bool,
|
||||
]),
|
||||
onChange: PropTypes.func.isRequired,
|
||||
onFocus: PropTypes.func,
|
||||
name: PropTypes.string.isRequired,
|
||||
placeholder: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
tabIndex: PropTypes.string,
|
||||
value: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default InputAddon;
|
||||
@ -0,0 +1,58 @@
|
||||
.addon {
|
||||
width: 5.9rem;
|
||||
height: 3.4rem;
|
||||
margin-top: .9rem;
|
||||
background-color: rgba(16, 22, 34, 0.02);
|
||||
border: 1px solid #E3E9F3;
|
||||
border-right: 0;
|
||||
border-radius: 0.25rem;
|
||||
color: rgba(16, 22, 34, 0.5);
|
||||
line-height: 3.2rem;
|
||||
font-size: 1.3rem;
|
||||
font-family: 'Lato';
|
||||
font-weight: 600!important;
|
||||
-moz-appearance: none;
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
.errorAddon {
|
||||
border: 1px solid #ff203c!important;
|
||||
border-right: none!important;
|
||||
}
|
||||
|
||||
.addonFocus {
|
||||
border-color: #78caff;
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.invalidAddon {
|
||||
border-color: #ff203c !important;
|
||||
border-left: 0;
|
||||
}
|
||||
|
||||
.inputAddon {
|
||||
min-width: 200px;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 1.3rem;
|
||||
|
||||
> input {
|
||||
height: 3.4rem;
|
||||
margin-top: .9rem;
|
||||
padding-left: 1rem;
|
||||
background-size: 0 !important;
|
||||
border: 1px solid #E3E9F3;
|
||||
border-left: 0;
|
||||
border-radius: 0.25rem;
|
||||
line-height: 3.4rem;
|
||||
font-size: 1.3rem;
|
||||
font-family: 'Lato' !important;
|
||||
box-shadow: 0px 1px 1px rgba(104, 118, 142, 0.05);
|
||||
&:focus {
|
||||
border-color: #78caff;
|
||||
}
|
||||
}
|
||||
|
||||
& + span {
|
||||
border-color: #E3E9F3;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,258 @@
|
||||
/**
|
||||
*
|
||||
* InputAddonWithErrors
|
||||
*
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { includes, isEmpty, isFunction, mapKeys, reject } from 'lodash';
|
||||
import cn from 'classnames';
|
||||
|
||||
// Design
|
||||
import Label from 'components/Label';
|
||||
import InputDescription from 'components/InputDescription';
|
||||
import InputErrors from 'components/InputErrors';
|
||||
import InputAddon from 'components/InputAddon';
|
||||
|
||||
import styles from './styles.scss';
|
||||
|
||||
class InputAddonWithErrors extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
||||
state = { errors: [], hasInitialValue: false };
|
||||
|
||||
componentDidMount() {
|
||||
const { value, errors } = this.props;
|
||||
|
||||
// Prevent the input from displaying an error when the user enters and leaves without filling it
|
||||
if (value && !isEmpty(value)) {
|
||||
this.setState({ hasInitialValue: true });
|
||||
}
|
||||
|
||||
// Display input error if it already has some
|
||||
if (!isEmpty(errors)) {
|
||||
this.setState({ errors });
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
// Check if errors have been updated during validations
|
||||
if (nextProps.didCheckErrors !== this.props.didCheckErrors) {
|
||||
// Remove from the state the errors that have already been set
|
||||
const errors = isEmpty(nextProps.errors) ? [] : nextProps.errors;
|
||||
this.setState({ errors });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the errors depending on the validations given to the input
|
||||
* @param {Object} target
|
||||
*/
|
||||
handleBlur = ({ target }) => {
|
||||
// Prevent from displaying error if the input is initially isEmpty
|
||||
if (!isEmpty(target.value) || this.state.hasInitialValue) {
|
||||
const errors = this.validate(target.value);
|
||||
this.setState({ errors, hasInitialValue: true });
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
addon,
|
||||
autoFocus,
|
||||
className,
|
||||
customBootstrapClass,
|
||||
deactivateErrorHighlight,
|
||||
disabled,
|
||||
errorsClassName,
|
||||
errorsStyle,
|
||||
inputClassName,
|
||||
inputDescription,
|
||||
inputDescriptionClassName,
|
||||
inputDescriptionStyle,
|
||||
inputStyle,
|
||||
label,
|
||||
labelClassName,
|
||||
labelStyle,
|
||||
name,
|
||||
noErrorsDescription,
|
||||
onBlur,
|
||||
onChange,
|
||||
onFocus,
|
||||
placeholder,
|
||||
style,
|
||||
tabIndex,
|
||||
value,
|
||||
} = this.props;
|
||||
const handleBlur = isFunction(onBlur) ? onBlur : this.handleBlur;
|
||||
|
||||
let spacer = !isEmpty(inputDescription) ? <div className={styles.spacer} /> : <div />;
|
||||
|
||||
if (!noErrorsDescription && !isEmpty(this.state.errors)) {
|
||||
spacer = <div />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn(
|
||||
styles.containerAddon,
|
||||
customBootstrapClass,
|
||||
!isEmpty(className) && className,
|
||||
)}
|
||||
style={style}
|
||||
>
|
||||
<Label
|
||||
className={labelClassName}
|
||||
htmlFor={name}
|
||||
message={label}
|
||||
style={labelStyle}
|
||||
/>
|
||||
<InputAddon
|
||||
addon={addon}
|
||||
autoFocus={autoFocus}
|
||||
className={inputClassName}
|
||||
disabled={disabled}
|
||||
deactivateErrorHighlight={deactivateErrorHighlight}
|
||||
error={!isEmpty(this.state.errors)}
|
||||
name={name}
|
||||
onBlur={handleBlur}
|
||||
onChange={onChange}
|
||||
onFocus={onFocus}
|
||||
placeholder={placeholder}
|
||||
style={inputStyle}
|
||||
tabIndex={tabIndex}
|
||||
value={value}
|
||||
/>
|
||||
<InputDescription
|
||||
className={inputDescriptionClassName}
|
||||
message={inputDescription}
|
||||
style={inputDescriptionStyle}
|
||||
/>
|
||||
<InputErrors
|
||||
className={errorsClassName}
|
||||
errors={!noErrorsDescription && this.state.errors || []}
|
||||
style={errorsStyle}
|
||||
/>
|
||||
{spacer}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
validate = (value) => {
|
||||
const requiredError = { id: 'components.Input.error.validation.required' };
|
||||
let errors = [];
|
||||
|
||||
mapKeys(this.props.validations, (validationValue, validationKey) => {
|
||||
switch (validationKey) {
|
||||
case 'maxLength': {
|
||||
if (value.length > validationValue) {
|
||||
errors.push({ id: 'components.Input.error.validation.maxLength' });
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'minLength': {
|
||||
if (value.length < validationValue) {
|
||||
errors.push({ id: 'components.Input.error.validation.minLength' });
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'required': {
|
||||
if (value.length === 0) {
|
||||
errors.push({ id: 'components.Input.error.validation.required' });
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'regex': {
|
||||
if (!new RegExp(validationValue).test(value)) {
|
||||
errors.push({ id: 'components.Input.error.validation.regex' });
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
errors = [];
|
||||
}
|
||||
});
|
||||
|
||||
if (includes(errors, requiredError)) {
|
||||
errors = reject(errors, (error) => error !== requiredError);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
InputAddonWithErrors.defaultProps = {
|
||||
addon: 'app.utils.placeholder.defaultMessage',
|
||||
autoFocus: false,
|
||||
className: '',
|
||||
customBootstrapClass: 'col-md-6',
|
||||
deactivateErrorHighlight: false,
|
||||
didCheckErrors: false,
|
||||
disabled: false,
|
||||
onBlur: false,
|
||||
onFocus: () => {},
|
||||
errors: [],
|
||||
errorsClassName: '',
|
||||
errorsStyle: {},
|
||||
inputClassName: '',
|
||||
inputDescription: '',
|
||||
inputDescriptionClassName: '',
|
||||
inputDescriptionStyle: {},
|
||||
inputStyle: {},
|
||||
label: '',
|
||||
labelClassName: '',
|
||||
labelStyle: {},
|
||||
noErrorsDescription: false,
|
||||
placeholder: 'app.utils.placeholder.defaultMessage',
|
||||
style: {},
|
||||
tabIndex: '0',
|
||||
validations: {},
|
||||
};
|
||||
|
||||
InputAddonWithErrors.propTypes = {
|
||||
addon: PropTypes.string,
|
||||
autoFocus: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
customBootstrapClass: PropTypes.string,
|
||||
deactivateErrorHighlight: PropTypes.bool,
|
||||
didCheckErrors: PropTypes.bool,
|
||||
disabled: PropTypes.bool,
|
||||
errors: PropTypes.array,
|
||||
errorsClassName: PropTypes.string,
|
||||
errorsStyle: PropTypes.object,
|
||||
inputClassName: PropTypes.string,
|
||||
inputDescription: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
params: PropTypes.object,
|
||||
}),
|
||||
]),
|
||||
inputDescriptionClassName: PropTypes.string,
|
||||
inputDescriptionStyle: PropTypes.object,
|
||||
inputStyle: PropTypes.object,
|
||||
label: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
params: PropTypes.object,
|
||||
}),
|
||||
]),
|
||||
labelClassName: PropTypes.string,
|
||||
labelStyle: PropTypes.object,
|
||||
name: PropTypes.string.isRequired,
|
||||
noErrorsDescription: PropTypes.bool,
|
||||
onBlur: PropTypes.oneOfType([
|
||||
PropTypes.bool,
|
||||
PropTypes.func,
|
||||
]),
|
||||
onChange: PropTypes.func.isRequired,
|
||||
onFocus: PropTypes.func,
|
||||
placeholder: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
tabIndex: PropTypes.string,
|
||||
validations: PropTypes.object,
|
||||
value: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default InputAddonWithErrors;
|
||||
@ -0,0 +1,9 @@
|
||||
.containerAddon {
|
||||
min-width: 200px;
|
||||
margin-bottom: 1.5rem;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
|
||||
.spacer {
|
||||
height: .5rem;
|
||||
}
|
||||
@ -0,0 +1,133 @@
|
||||
/**
|
||||
*
|
||||
* InputCheckbox
|
||||
*
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { isEmpty, isFunction, isObject } from 'lodash';
|
||||
import cn from 'classnames';
|
||||
|
||||
import styles from './styles.scss';
|
||||
|
||||
class InputCheckbox extends React.Component {
|
||||
handleChange = () => {
|
||||
const target = {
|
||||
name: this.props.name,
|
||||
type: 'checkbox',
|
||||
value: !this.props.value,
|
||||
};
|
||||
|
||||
this.props.onChange({ target });
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
autoFocus,
|
||||
className,
|
||||
disabled,
|
||||
label,
|
||||
name,
|
||||
onBlur,
|
||||
onFocus,
|
||||
style,
|
||||
tabIndex,
|
||||
value,
|
||||
} = this.props;
|
||||
const checkbox = (
|
||||
<input
|
||||
autoFocus={autoFocus}
|
||||
className="form-check-input"
|
||||
checked={value}
|
||||
disabled={disabled}
|
||||
id={name}
|
||||
onBlur={onBlur}
|
||||
onChange={this.handleChange}
|
||||
onFocus={onFocus}
|
||||
tabIndex={tabIndex}
|
||||
type="checkbox"
|
||||
/>
|
||||
);
|
||||
|
||||
let content = <div />;
|
||||
|
||||
if (typeof(label) === 'string') {
|
||||
content = (
|
||||
<label className={cn('form-check-label', disabled && styles.disabled)} htmlFor={name}>
|
||||
{checkbox}
|
||||
{label}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
if (isFunction(label)) {
|
||||
content = (
|
||||
<label className={cn('form-check-label', disabled && styles.disabled)} htmlFor={name}>
|
||||
{checkbox}
|
||||
{label()}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
if (isObject(label) && label.id) {
|
||||
content = (
|
||||
<FormattedMessage id={label.id} defaultMessage={label.id} values={label.params}>
|
||||
{(message) => (
|
||||
<label className={cn('form-check-label', disabled && styles.disabled)} htmlFor={name}>
|
||||
{checkbox}
|
||||
{message}
|
||||
</label>
|
||||
)}
|
||||
</FormattedMessage>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className={cn(
|
||||
'form-check',
|
||||
styles.inputCheckbox,
|
||||
!isEmpty(className) && className,
|
||||
)}
|
||||
style={style}
|
||||
>
|
||||
{content}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
InputCheckbox.defaultProps = {
|
||||
autoFocus: false,
|
||||
className: '',
|
||||
disabled: false,
|
||||
label: '',
|
||||
onBlur: () => {},
|
||||
onFocus: () => {},
|
||||
style: {},
|
||||
tabIndex: '0',
|
||||
value: false,
|
||||
};
|
||||
|
||||
InputCheckbox.propTypes = {
|
||||
autoFocus: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
disabled: PropTypes.bool,
|
||||
label: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
params: PropTypes.object,
|
||||
}),
|
||||
]),
|
||||
name: PropTypes.string.isRequired,
|
||||
onBlur: PropTypes.func,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
onFocus: PropTypes.func,
|
||||
style: PropTypes.object,
|
||||
tabIndex: PropTypes.string,
|
||||
value: PropTypes.bool,
|
||||
};
|
||||
|
||||
export default InputCheckbox;
|
||||
@ -0,0 +1,15 @@
|
||||
.inputCheckbox {
|
||||
margin-bottom: 0;
|
||||
font-weight: 400;
|
||||
label {
|
||||
cursor: pointer;
|
||||
}
|
||||
input {
|
||||
margin-right: 1.2rem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
@ -0,0 +1,213 @@
|
||||
/**
|
||||
*
|
||||
* InputCheckboxWithErrors
|
||||
*
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { includes, isEmpty, isObject, isFunction, mapKeys, reject } from 'lodash';
|
||||
import cn from 'classnames';
|
||||
|
||||
// Design
|
||||
import Label from 'components/Label';
|
||||
import InputDescription from 'components/InputDescription';
|
||||
import InputErrors from 'components/InputErrors';
|
||||
import InputCheckbox from 'components/InputCheckbox';
|
||||
|
||||
import styles from './styles.scss';
|
||||
|
||||
class InputCheckboxWithErrors extends React.Component {
|
||||
state = { errors: [] };
|
||||
|
||||
componentDidMount() {
|
||||
// Display input error if it already has some
|
||||
const { errors } = this.props;
|
||||
if (!isEmpty(errors)) {
|
||||
this.setState({ errors });
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
// Check if errors have been updated during validations
|
||||
if (nextProps.didCheckErrors !== this.props.didCheckErrors) {
|
||||
// Remove from the state the errors that have already been set
|
||||
const errors = isEmpty(nextProps.errors) ? [] : nextProps.errors;
|
||||
this.setState({ errors });
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const {
|
||||
autoFocus,
|
||||
className,
|
||||
customBootstrapClass,
|
||||
deactivateErrorHighlight,
|
||||
disabled,
|
||||
errorsClassName,
|
||||
errorsStyle,
|
||||
inputClassName,
|
||||
inputDescription,
|
||||
inputDescriptionClassName,
|
||||
inputDescriptionStyle,
|
||||
inputStyle,
|
||||
label,
|
||||
labelClassName,
|
||||
labelStyle,
|
||||
name,
|
||||
noErrorsDescription,
|
||||
onBlur,
|
||||
onChange,
|
||||
onFocus,
|
||||
placeholder,
|
||||
style,
|
||||
tabIndex,
|
||||
title,
|
||||
value,
|
||||
} = this.props;
|
||||
|
||||
const handleBlur = onBlur ? onBlur : () => {};
|
||||
let inputTitle = '';
|
||||
|
||||
let spacer = !isEmpty(inputDescription) ? <div className={styles.spacer} /> : <div />;
|
||||
|
||||
if (!noErrorsDescription && !isEmpty(this.state.errors)) {
|
||||
spacer = <div />;
|
||||
}
|
||||
|
||||
if (isObject(title) && title.id) {
|
||||
inputTitle = (
|
||||
<div className={styles.inputTitle}>
|
||||
<FormattedMessage id={title.id} defaultMessage={title.id} values={title.params} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isFunction(title)) {
|
||||
inputTitle = title();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn(
|
||||
styles.container,
|
||||
customBootstrapClass,
|
||||
!isEmpty(className) && className,
|
||||
)}
|
||||
style={style}
|
||||
>
|
||||
{inputTitle}
|
||||
<InputCheckbox
|
||||
autoFocus={autoFocus}
|
||||
className={inputClassName}
|
||||
disabled={disabled}
|
||||
label={label}
|
||||
name={name}
|
||||
onBlur={handleBlur}
|
||||
onChange={onChange}
|
||||
onFocus={onFocus}
|
||||
placeholder={placeholder}
|
||||
style={inputStyle}
|
||||
tabIndex={tabIndex}
|
||||
value={value}
|
||||
/>
|
||||
<InputDescription
|
||||
className={cn(styles.inputCheckboxDescriptionContainer, inputDescriptionClassName)}
|
||||
message={this.props.inputDescription}
|
||||
style={inputDescriptionStyle}
|
||||
/>
|
||||
<InputErrors
|
||||
className={errorsClassName}
|
||||
errors={this.state.errors}
|
||||
style={errorsStyle}
|
||||
/>
|
||||
{spacer}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
InputCheckboxWithErrors.defaultProps = {
|
||||
autoFocus: false,
|
||||
className: '',
|
||||
customBootstrapClass: 'col-md-3',
|
||||
deactivateErrorHighlight: false,
|
||||
didCheckErrors: false,
|
||||
disabled: false,
|
||||
onBlur: () => {},
|
||||
onFocus: () => {},
|
||||
errors: [],
|
||||
errorsClassName: '',
|
||||
errorsStyle: {},
|
||||
inputClassName: '',
|
||||
inputDescription: '',
|
||||
inputDescriptionClassName: '',
|
||||
inputDescriptionStyle: {},
|
||||
inputStyle: {},
|
||||
label: '',
|
||||
labelClassName: '',
|
||||
labelStyle: {},
|
||||
noErrorsDescription: false,
|
||||
placeholder: 'app.utils.placeholder.defaultMessage',
|
||||
style: {},
|
||||
tabIndex: '0',
|
||||
title: '',
|
||||
validations: {},
|
||||
value: false,
|
||||
};
|
||||
InputCheckboxWithErrors.propTypes = {
|
||||
autoFocus: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
customBootstrapClass: PropTypes.string,
|
||||
deactivateErrorHighlight: PropTypes.bool,
|
||||
didCheckErrors: PropTypes.bool,
|
||||
disabled: PropTypes.bool,
|
||||
errors: PropTypes.array,
|
||||
errorsClassName: PropTypes.string,
|
||||
errorsStyle: PropTypes.object,
|
||||
inputClassName: PropTypes.string,
|
||||
inputDescription: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
params: PropTypes.object,
|
||||
}),
|
||||
]),
|
||||
inputDescriptionClassName: PropTypes.string,
|
||||
inputDescriptionStyle: PropTypes.object,
|
||||
inputStyle: PropTypes.object,
|
||||
label: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
params: PropTypes.object,
|
||||
}),
|
||||
]),
|
||||
labelClassName: PropTypes.string,
|
||||
labelStyle: PropTypes.object,
|
||||
name: PropTypes.string.isRequired,
|
||||
noErrorsDescription: PropTypes.bool,
|
||||
onBlur: PropTypes.oneOfType([
|
||||
PropTypes.bool,
|
||||
PropTypes.func,
|
||||
]),
|
||||
onChange: PropTypes.func.isRequired,
|
||||
onFocus: PropTypes.func,
|
||||
placeholder: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
tabIndex: PropTypes.string,
|
||||
title: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
params: PropTypes.object,
|
||||
}),
|
||||
]),
|
||||
validations: PropTypes.object,
|
||||
value: PropTypes.bool,
|
||||
};
|
||||
|
||||
export default InputCheckboxWithErrors;
|
||||
@ -0,0 +1,27 @@
|
||||
.container {
|
||||
margin-bottom: 1.5rem;
|
||||
font-size: 1.3rem;
|
||||
font-family: 'Lato';
|
||||
}
|
||||
|
||||
.spacer {
|
||||
height: .5rem;
|
||||
}
|
||||
|
||||
.inputCheckboxDescriptionContainer {
|
||||
width: 150%;
|
||||
margin-top: .2rem;
|
||||
padding-left: 2.5rem;
|
||||
line-height: 1.2rem;
|
||||
|
||||
> small {
|
||||
color: #9EA7B8;
|
||||
font-family: 'Lato';
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.inputTitle {
|
||||
margin-bottom: 1.7rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
/**
|
||||
*
|
||||
* InputDate
|
||||
*
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import PropTypes from 'prop-types';
|
||||
import DateTimeStyle from 'react-datetime/css/react-datetime.css';
|
||||
import DateTime from 'react-datetime';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { isEmpty, isObject } from 'lodash';
|
||||
import cn from 'classnames';
|
||||
|
||||
import styles from './styles.scss';
|
||||
|
||||
function InputDate(props) {
|
||||
const value = isObject(props.value) && props.value._isAMomentObject === true ? props.value : moment(props.value);
|
||||
|
||||
return (
|
||||
<FormattedMessage id={props.placeholder} defaultMessage={props.placeholder}>
|
||||
{(placeholder) => (
|
||||
<DateTime
|
||||
dateFormat='YYYY-MM-DD'
|
||||
inputProps={{
|
||||
autoFocus: props.autoFocus,
|
||||
className: cn(
|
||||
'form-control',
|
||||
styles.inputDate,
|
||||
!props.deactivateErrorHighlight && props.error && 'is-invalid',
|
||||
!isEmpty(props.className) && props.className,
|
||||
),
|
||||
disabled: props.disabled,
|
||||
id: props.name,
|
||||
name: props.name,
|
||||
placeholder,
|
||||
style: props.style,
|
||||
}}
|
||||
onBlur={props.onBlur}
|
||||
onChange={(moment) => props.onChange({ target: {
|
||||
name: props.name,
|
||||
value: moment
|
||||
}})}
|
||||
onFocus={props.onFocus}
|
||||
tabIndex={props.tabIndex}
|
||||
timeFormat='HH:mm:ss'
|
||||
utc={true}
|
||||
value={value}
|
||||
style={props.style}
|
||||
/>
|
||||
)}
|
||||
</FormattedMessage>
|
||||
);
|
||||
}
|
||||
|
||||
InputDate.defaultProps = {
|
||||
autoFocus: true,
|
||||
className: '',
|
||||
deactivateErrorHighlight: false,
|
||||
disabled: false,
|
||||
error: false,
|
||||
onBlur: () => {},
|
||||
onFocus: () => {},
|
||||
placeholder: 'app.utils.placeholder.defaultMessage',
|
||||
style: {},
|
||||
tabIndex: '0',
|
||||
};
|
||||
|
||||
InputDate.propTypes = {
|
||||
autoFocus: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
deactivateErrorHighlight: PropTypes.bool,
|
||||
disabled: PropTypes.bool,
|
||||
error: PropTypes.bool,
|
||||
onBlur: PropTypes.func,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
onFocus: PropTypes.func,
|
||||
name: PropTypes.string.isRequired,
|
||||
placeholder: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
tabIndex: PropTypes.string,
|
||||
value: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.object,
|
||||
]).isRequired,
|
||||
};
|
||||
|
||||
export default InputDate;
|
||||
@ -0,0 +1,12 @@
|
||||
.inputDate {
|
||||
height: 3.4rem;
|
||||
margin-top: .9rem;
|
||||
padding-left: 1rem;
|
||||
background-size: 0 !important;
|
||||
border: 1px solid #E3E9F3;
|
||||
border-radius: 0.25rem;
|
||||
line-height: 3.4rem;
|
||||
font-size: 1.3rem;
|
||||
font-family: 'Lato' !important;
|
||||
box-shadow: 0px 1px 1px rgba(104, 118, 142, 0.05);
|
||||
}
|
||||
@ -0,0 +1,236 @@
|
||||
/**
|
||||
*
|
||||
* InputDateWithErrors
|
||||
*
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { get, includes, isEmpty, isFunction, mapKeys, reject } from 'lodash';
|
||||
import cn from 'classnames';
|
||||
|
||||
// Design
|
||||
import Label from 'components/Label';
|
||||
import InputDescription from 'components/InputDescription';
|
||||
import InputErrors from 'components/InputErrors';
|
||||
import InputDate from 'components/InputDate';
|
||||
|
||||
import styles from './styles.scss';
|
||||
|
||||
class InputDateWithErrors extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
||||
state = { errors: [], hasInitialValue: false };
|
||||
|
||||
componentDidMount() {
|
||||
const { value, errors } = this.props;
|
||||
|
||||
// Prevent the input from displaying an error when the user enters and leaves without filling it
|
||||
if (value && !isEmpty(value)) {
|
||||
this.setState({ hasInitialValue: true });
|
||||
}
|
||||
|
||||
// Display input error if it already has some
|
||||
if (!isEmpty(errors)) {
|
||||
this.setState({ errors });
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
// Check if errors have been updated during validations
|
||||
if (nextProps.didCheckErrors !== this.props.didCheckErrors) {
|
||||
// Remove from the state the errors that have already been set
|
||||
const errors = isEmpty(nextProps.errors) ? [] : nextProps.errors;
|
||||
this.setState({ errors });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the errors depending on the validations given to the input
|
||||
* @param {Object} target
|
||||
*/
|
||||
handleBlur = ({ target }) => {
|
||||
// Prevent from displaying error if the input is initially isEmpty
|
||||
if (!isEmpty(get(target, 'value')) || this.state.hasInitialValue) {
|
||||
const errors = this.validate(target.value);
|
||||
this.setState({ errors, hasInitialValue: true });
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
autoFocus,
|
||||
className,
|
||||
customBootstrapClass,
|
||||
deactivateErrorHighlight,
|
||||
disabled,
|
||||
errorsClassName,
|
||||
errorsStyle,
|
||||
inputClassName,
|
||||
inputDescription,
|
||||
inputDescriptionClassName,
|
||||
inputDescriptionStyle,
|
||||
inputStyle,
|
||||
label,
|
||||
labelClassName,
|
||||
labelStyle,
|
||||
name,
|
||||
noErrorsDescription,
|
||||
onBlur,
|
||||
onChange,
|
||||
onFocus,
|
||||
placeholder,
|
||||
style,
|
||||
tabIndex,
|
||||
value,
|
||||
} = this.props;
|
||||
const handleBlur = isFunction(onBlur) ? onBlur : this.handleBlur;
|
||||
|
||||
let spacer = !isEmpty(inputDescription) ? <div className={styles.spacer} /> : <div />;
|
||||
|
||||
if (!noErrorsDescription && !isEmpty(this.state.errors)) {
|
||||
spacer = <div />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn(
|
||||
!isEmpty(customBootstrapClass) && customBootstrapClass || 'col-md-4',
|
||||
styles.containerDate,
|
||||
!isEmpty(className) && className,
|
||||
)}
|
||||
style={style}
|
||||
>
|
||||
<Label
|
||||
className={labelClassName}
|
||||
htmlFor={name}
|
||||
message={label}
|
||||
style={labelStyle}
|
||||
/>
|
||||
<InputDate
|
||||
autoFocus={autoFocus}
|
||||
className={inputClassName}
|
||||
disabled={disabled}
|
||||
deactivateErrorHighlight={deactivateErrorHighlight}
|
||||
error={!isEmpty(this.state.errors)}
|
||||
name={name}
|
||||
onBlur={handleBlur}
|
||||
onChange={onChange}
|
||||
onFocus={onFocus}
|
||||
placeholder={placeholder}
|
||||
style={inputStyle}
|
||||
tabIndex={tabIndex}
|
||||
value={value}
|
||||
/>
|
||||
<InputDescription
|
||||
className={inputDescriptionClassName}
|
||||
message={inputDescription}
|
||||
style={inputDescriptionStyle}
|
||||
/>
|
||||
<InputErrors
|
||||
className={errorsClassName}
|
||||
errors={!noErrorsDescription && this.state.errors || []}
|
||||
style={errorsStyle}
|
||||
/>
|
||||
{spacer}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
validate = (value) => {
|
||||
const requiredError = { id: 'components.Input.error.validation.required' };
|
||||
let errors = [];
|
||||
|
||||
mapKeys(this.props.validations, (validationValue, validationKey) => {
|
||||
switch (validationKey) {
|
||||
case 'required': {
|
||||
if (value.length === 0) {
|
||||
errors.push({ id: 'components.Input.error.validation.required' });
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
errors = [];
|
||||
}
|
||||
});
|
||||
|
||||
if (includes(errors, requiredError)) {
|
||||
errors = reject(errors, (error) => error !== requiredError);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
InputDateWithErrors.defaultProps = {
|
||||
autoFocus: false,
|
||||
className: '',
|
||||
customBootstrapClass: 'col-md-4',
|
||||
deactivateErrorHighlight: false,
|
||||
didCheckErrors: false,
|
||||
disabled: false,
|
||||
onBlur: false,
|
||||
onFocus: () => {},
|
||||
errors: [],
|
||||
errorsClassName: '',
|
||||
errorsStyle: {},
|
||||
inputClassName: '',
|
||||
inputDescription: '',
|
||||
inputDescriptionClassName: '',
|
||||
inputDescriptionStyle: {},
|
||||
inputStyle: {},
|
||||
label: '',
|
||||
labelClassName: '',
|
||||
labelStyle: {},
|
||||
noErrorsDescription: false,
|
||||
placeholder: 'app.utils.placeholder.defaultMessage',
|
||||
style: {},
|
||||
tabIndex: '0',
|
||||
validations: {},
|
||||
};
|
||||
|
||||
InputDateWithErrors.propTypes = {
|
||||
autoFocus: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
customBootstrapClass: PropTypes.string,
|
||||
deactivateErrorHighlight: PropTypes.bool,
|
||||
didCheckErrors: PropTypes.bool,
|
||||
disabled: PropTypes.bool,
|
||||
errors: PropTypes.array,
|
||||
errorsClassName: PropTypes.string,
|
||||
errorsStyle: PropTypes.object,
|
||||
inputClassName: PropTypes.string,
|
||||
inputDescription: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
params: PropTypes.object,
|
||||
}),
|
||||
]),
|
||||
inputDescriptionClassName: PropTypes.string,
|
||||
inputDescriptionStyle: PropTypes.object,
|
||||
inputStyle: PropTypes.object,
|
||||
label: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
params: PropTypes.object,
|
||||
}),
|
||||
]),
|
||||
labelClassName: PropTypes.string,
|
||||
labelStyle: PropTypes.object,
|
||||
name: PropTypes.string.isRequired,
|
||||
noErrorsDescription: PropTypes.bool,
|
||||
onBlur: PropTypes.oneOfType([
|
||||
PropTypes.bool,
|
||||
PropTypes.func,
|
||||
]),
|
||||
onChange: PropTypes.func.isRequired,
|
||||
onFocus: PropTypes.func,
|
||||
placeholder: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
tabIndex: PropTypes.string,
|
||||
validations: PropTypes.object,
|
||||
value: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default InputDateWithErrors;
|
||||
@ -0,0 +1,36 @@
|
||||
.containerDate {
|
||||
min-width: 200px;
|
||||
margin-bottom: 1.5rem;
|
||||
font-size: 1.3rem;
|
||||
|
||||
> div:first-of-type{
|
||||
&:before{
|
||||
content: '\f073';
|
||||
position: absolute;
|
||||
left: 1px; top: 1px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 3px 0px 0px 3px;
|
||||
background: #FAFAFB;
|
||||
color: #B3B5B9;
|
||||
text-align: center;
|
||||
font-family: 'FontAwesome';
|
||||
font-size: 1.4rem;
|
||||
line-height: 32px;
|
||||
-webkit-font-smoothing: none;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
padding-left: 42px;
|
||||
box-shadow: 0px 1px 1px rgba(104, 118, 142, 0.05);
|
||||
&:focus{
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.spacer {
|
||||
height: .5rem;
|
||||
}
|
||||
@ -41,6 +41,7 @@ class InputPassword extends React.Component {
|
||||
<FormattedMessage id={placeholder} defaultMessage={placeholder}>
|
||||
{(message) => (
|
||||
<input
|
||||
autoComplete="new-password"
|
||||
autoFocus={autoFocus}
|
||||
className={cn(
|
||||
styles.inputPassword,
|
||||
|
||||
@ -0,0 +1,108 @@
|
||||
/**
|
||||
*
|
||||
* InputSearch
|
||||
*
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import cn from 'classnames';
|
||||
|
||||
import styles from './styles.scss';
|
||||
|
||||
class InputSearch extends React.Component {
|
||||
state = { isFocused: false };
|
||||
|
||||
handleBlur = (e) => {
|
||||
this.setState({ isFocused: !this.state.isFocused });
|
||||
this.props.onBlur(e);
|
||||
}
|
||||
|
||||
handleFocus = (e) => {
|
||||
this.setState({ isFocused: !this.state.isFocused });
|
||||
this.props.onFocus(e);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
autoFocus,
|
||||
className,
|
||||
deactivateErrorHighlight,
|
||||
disabled,
|
||||
error,
|
||||
name,
|
||||
onChange,
|
||||
placeholder,
|
||||
style,
|
||||
tabIndex,
|
||||
value,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<div className={cn(styles.inputSearch, 'input-group', !isEmpty(className) && className)} style={style}>
|
||||
<span className={cn(
|
||||
'input-group-addon',
|
||||
styles.addonSearch,
|
||||
this.state.isFocused && styles.addonFocus,
|
||||
!deactivateErrorHighlight && error && styles.errorAddon,
|
||||
)}
|
||||
/>
|
||||
<FormattedMessage id={placeholder} defaultMessage={placeholder}>
|
||||
{(message) => (
|
||||
<input
|
||||
autoFocus={autoFocus}
|
||||
className={cn(
|
||||
'form-control',
|
||||
!deactivateErrorHighlight && error && 'is-invalid',
|
||||
!deactivateErrorHighlight && error && this.state.isFocused && styles.invalidSearch,
|
||||
)}
|
||||
disabled={disabled}
|
||||
id={name}
|
||||
name={name}
|
||||
onBlur={this.handleBlur}
|
||||
onChange={onChange}
|
||||
onFocus={this.handleFocus}
|
||||
placeholder={message}
|
||||
tabIndex={tabIndex}
|
||||
type="text"
|
||||
value={value}
|
||||
/>
|
||||
)}
|
||||
</FormattedMessage>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
InputSearch.defaultProps = {
|
||||
autoFocus: false,
|
||||
className: '',
|
||||
deactivateErrorHighlight: false,
|
||||
disabled: false,
|
||||
error: false,
|
||||
onBlur: () => {},
|
||||
onFocus: () => {},
|
||||
placeholder: 'app.utils.placeholder.defaultMessage',
|
||||
style: {},
|
||||
tabIndex: '0',
|
||||
};
|
||||
|
||||
InputSearch.propTypes = {
|
||||
autoFocus: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
deactivateErrorHighlight: PropTypes.bool,
|
||||
disabled: PropTypes.bool,
|
||||
error: PropTypes.bool,
|
||||
onBlur: PropTypes.func,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
onFocus: PropTypes.func,
|
||||
name: PropTypes.string.isRequired,
|
||||
placeholder: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
tabIndex: PropTypes.string,
|
||||
value: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default InputSearch;
|
||||
@ -0,0 +1,71 @@
|
||||
.addonSearch {
|
||||
width: 3.4rem;
|
||||
height: 3.4rem;
|
||||
margin-top: .9rem;
|
||||
padding-left: 0.9rem;
|
||||
background-color: rgba(16, 22, 34, 0.02);
|
||||
border: 1px solid #E3E9F3;
|
||||
border-right: 0;
|
||||
border-radius: 0.25rem;
|
||||
color: rgba(16, 22, 34, 0.5);
|
||||
line-height: 3.2rem;
|
||||
font-size: 1.3rem;
|
||||
font-weight: 600!important;
|
||||
-moz-appearance: none;
|
||||
-webkit-appearance: none;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
&:after {
|
||||
content: '\F002';
|
||||
display: inline-table;
|
||||
color: #B3B5B9;
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
font-family: 'FontAwesome';
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
& + input {
|
||||
border-left: 0px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.inputSearch {
|
||||
min-width: 200px;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 1.3rem;
|
||||
|
||||
> input {
|
||||
height: 3.4rem;
|
||||
margin-top: .9rem;
|
||||
padding-left: 1rem;
|
||||
background-size: 0 !important;
|
||||
border: 1px solid #E3E9F3;
|
||||
border-radius: 0.25rem;
|
||||
line-height: 3.4rem;
|
||||
font-size: 1.3rem;
|
||||
font-family: 'Lato' !important;
|
||||
box-shadow: 0px 1px 1px rgba(104, 118, 142, 0.05);
|
||||
&:focus {
|
||||
border-color: #78caff;
|
||||
}
|
||||
}
|
||||
|
||||
& + span {
|
||||
border-color: #E3E9F3;
|
||||
}
|
||||
}
|
||||
|
||||
.errorAddon {
|
||||
border: 1px solid #ff203c!important;
|
||||
border-right: none!important;
|
||||
}
|
||||
|
||||
.addonFocus {
|
||||
border-color: #78caff;
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.invalidSearch {
|
||||
border-color: #ff203c !important;
|
||||
border-left: 0;
|
||||
}
|
||||
@ -0,0 +1,252 @@
|
||||
/**
|
||||
*
|
||||
* InputSearchWithErrors
|
||||
*
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { includes, isEmpty, isFunction, mapKeys, reject } from 'lodash';
|
||||
import cn from 'classnames';
|
||||
|
||||
// Design
|
||||
import Label from 'components/Label';
|
||||
import InputDescription from 'components/InputDescription';
|
||||
import InputErrors from 'components/InputErrors';
|
||||
import InputSearch from 'components/InputSearch';
|
||||
|
||||
import styles from './styles.scss';
|
||||
|
||||
class InputSearchWithErrors extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
||||
state = { errors: [], hasInitialValue: false };
|
||||
|
||||
componentDidMount() {
|
||||
const { value, errors } = this.props;
|
||||
|
||||
// Prevent the input from displaying an error when the user enters and leaves without filling it
|
||||
if (value && !isEmpty(value)) {
|
||||
this.setState({ hasInitialValue: true });
|
||||
}
|
||||
|
||||
// Display input error if it already has some
|
||||
if (!isEmpty(errors)) {
|
||||
this.setState({ errors });
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
// Check if errors have been updated during validations
|
||||
if (nextProps.didCheckErrors !== this.props.didCheckErrors) {
|
||||
// Remove from the state the errors that have already been set
|
||||
const errors = isEmpty(nextProps.errors) ? [] : nextProps.errors;
|
||||
this.setState({ errors });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the errors depending on the validations given to the input
|
||||
* @param {Object} target
|
||||
*/
|
||||
handleBlur = ({ target }) => {
|
||||
// Prevent from displaying error if the input is initially isEmpty
|
||||
if (!isEmpty(target.value) || this.state.hasInitialValue) {
|
||||
const errors = this.validate(target.value);
|
||||
this.setState({ errors, hasInitialValue: true });
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
autoFocus,
|
||||
deactivateErrorHighlight,
|
||||
disabled,
|
||||
errorsClassName,
|
||||
errorsStyle,
|
||||
inputClassName,
|
||||
inputDescription,
|
||||
inputDescriptionClassName,
|
||||
inputDescriptionStyle,
|
||||
inputStyle,
|
||||
label,
|
||||
labelClassName,
|
||||
labelStyle,
|
||||
name,
|
||||
noErrorsDescription,
|
||||
onBlur,
|
||||
onChange,
|
||||
onFocus,
|
||||
placeholder,
|
||||
style,
|
||||
tabIndex,
|
||||
value,
|
||||
} = this.props;
|
||||
const handleBlur = isFunction(onBlur) ? onBlur : this.handleBlur;
|
||||
|
||||
let spacer = !isEmpty(inputDescription) ? <div className={styles.spacer} /> : <div />;
|
||||
|
||||
if (!noErrorsDescription && !isEmpty(this.state.errors)) {
|
||||
spacer = <div />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn(
|
||||
styles.containerSearch,
|
||||
this.props.customBootstrapClass,
|
||||
!isEmpty(this.props.className) && this.props.className,
|
||||
)}
|
||||
style={style}
|
||||
>
|
||||
<Label
|
||||
className={labelClassName}
|
||||
htmlFor={name}
|
||||
message={label}
|
||||
style={labelStyle}
|
||||
/>
|
||||
<InputSearch
|
||||
autoFocus={autoFocus}
|
||||
className={inputClassName}
|
||||
disabled={disabled}
|
||||
deactivateErrorHighlight={deactivateErrorHighlight}
|
||||
error={!isEmpty(this.state.errors)}
|
||||
name={name}
|
||||
onBlur={handleBlur}
|
||||
onChange={onChange}
|
||||
onFocus={onFocus}
|
||||
placeholder={placeholder}
|
||||
style={inputStyle}
|
||||
tabIndex={tabIndex}
|
||||
value={value}
|
||||
/>
|
||||
<InputDescription
|
||||
className={inputDescriptionClassName}
|
||||
message={inputDescription}
|
||||
style={inputDescriptionStyle}
|
||||
/>
|
||||
<InputErrors
|
||||
className={errorsClassName}
|
||||
errors={!noErrorsDescription && this.state.errors || []}
|
||||
style={errorsStyle}
|
||||
/>
|
||||
{spacer}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
validate = (value) => {
|
||||
const requiredError = { id: 'components.Input.error.validation.required' };
|
||||
let errors = [];
|
||||
|
||||
mapKeys(this.props.validations, (validationValue, validationKey) => {
|
||||
switch (validationKey) {
|
||||
case 'maxLength': {
|
||||
if (value.length > validationValue) {
|
||||
errors.push({ id: 'components.Input.error.validation.maxLength' });
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'minLength': {
|
||||
if (value.length < validationValue) {
|
||||
errors.push({ id: 'components.Input.error.validation.minLength' });
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'required': {
|
||||
if (value.length === 0) {
|
||||
errors.push({ id: 'components.Input.error.validation.required' });
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'regex': {
|
||||
if (!new RegExp(validationValue).test(value)) {
|
||||
errors.push({ id: 'components.Input.error.validation.regex' });
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
errors = [];
|
||||
}
|
||||
});
|
||||
|
||||
if (includes(errors, requiredError)) {
|
||||
errors = reject(errors, (error) => error !== requiredError);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
InputSearchWithErrors.defaultProps = {
|
||||
autoFocus: false,
|
||||
className: '',
|
||||
customBootstrapClass: 'col-md-6',
|
||||
deactivateErrorHighlight: false,
|
||||
didCheckErrors: false,
|
||||
disabled: false,
|
||||
onBlur: false,
|
||||
onFocus: () => {},
|
||||
errors: [],
|
||||
errorsClassName: '',
|
||||
errorsStyle: {},
|
||||
inputClassName: '',
|
||||
inputDescription: '',
|
||||
inputDescriptionClassName: '',
|
||||
inputDescriptionStyle: {},
|
||||
inputStyle: {},
|
||||
label: '',
|
||||
labelClassName: '',
|
||||
labelStyle: {},
|
||||
noErrorsDescription: false,
|
||||
placeholder: 'app.utils.placeholder.defaultMessage',
|
||||
style: {},
|
||||
tabIndex: '0',
|
||||
validations: {},
|
||||
};
|
||||
|
||||
InputSearchWithErrors.propTypes = {
|
||||
autoFocus: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
customBootstrapClass: PropTypes.string,
|
||||
deactivateErrorHighlight: PropTypes.bool,
|
||||
didCheckErrors: PropTypes.bool,
|
||||
disabled: PropTypes.bool,
|
||||
errors: PropTypes.array,
|
||||
errorsClassName: PropTypes.string,
|
||||
errorsStyle: PropTypes.object,
|
||||
inputClassName: PropTypes.string,
|
||||
inputDescription: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
params: PropTypes.object,
|
||||
}),
|
||||
]),
|
||||
inputDescriptionClassName: PropTypes.string,
|
||||
inputDescriptionStyle: PropTypes.object,
|
||||
inputStyle: PropTypes.object,
|
||||
label: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.func,
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
params: PropTypes.object,
|
||||
}),
|
||||
]),
|
||||
labelClassName: PropTypes.string,
|
||||
labelStyle: PropTypes.object,
|
||||
name: PropTypes.string.isRequired,
|
||||
noErrorsDescription: PropTypes.bool,
|
||||
onBlur: PropTypes.oneOfType([
|
||||
PropTypes.bool,
|
||||
PropTypes.func,
|
||||
]),
|
||||
onChange: PropTypes.func.isRequired,
|
||||
onFocus: PropTypes.func,
|
||||
placeholder: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
tabIndex: PropTypes.string,
|
||||
validations: PropTypes.object,
|
||||
value: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default InputSearchWithErrors;
|
||||
@ -0,0 +1,9 @@
|
||||
.containerSearch {
|
||||
min-width: 200px;
|
||||
margin-bottom: 1.5rem;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
|
||||
.spacer {
|
||||
height: .5rem;
|
||||
}
|
||||
@ -5,10 +5,15 @@
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
// Design
|
||||
import InputAddonWithErrors from 'components/InputAddonWithErrors';
|
||||
import InputCheckboxWithErrors from 'components/InputCheckboxWithErrors';
|
||||
import InputDateWithErrors from 'components/InputDateWithErrors';
|
||||
import InputEmailWithErrors from 'components/InputEmailWithErrors';
|
||||
import InputNumberWithErrors from 'components/InputNumberWithErrors';
|
||||
import InputSearchWithErrors from 'components/InputSearchWithErrors';
|
||||
import InputSelectWithErrors from 'components/InputSelectWithErrors';
|
||||
import InputPasswordWithErrors from 'components/InputPasswordWithErrors';
|
||||
import InputTextAreaWithErrors from 'components/InputTextAreaWithErrors';
|
||||
@ -18,9 +23,13 @@ import InputToggleWithErrors from 'components/InputToggleWithErrors';
|
||||
const DefaultInputError = ({ type }) => <div>Your input type: <b>{type}</b> does not exist</div>
|
||||
|
||||
const inputs = {
|
||||
addon: InputAddonWithErrors,
|
||||
checkbox: InputCheckboxWithErrors,
|
||||
date: InputDateWithErrors,
|
||||
email: InputEmailWithErrors,
|
||||
number: InputNumberWithErrors,
|
||||
password: InputPasswordWithErrors,
|
||||
search: InputSearchWithErrors,
|
||||
select: InputSelectWithErrors,
|
||||
string: InputTextWithErrors,
|
||||
text: InputTextWithErrors,
|
||||
@ -29,20 +38,34 @@ const inputs = {
|
||||
};
|
||||
|
||||
function InputsIndex(props) {
|
||||
const Input = inputs[props.type] ? inputs[props.type] : DefaultInputError;
|
||||
const type = props.type && !isEmpty(props.addon) ? 'addon' : props.type;
|
||||
const inputValue = props.type === 'checkbox' || props.type === 'toggle' ? props.value || false : props.value || '';
|
||||
const Input = inputs[type] ? inputs[type] : DefaultInputError;
|
||||
|
||||
return <Input {...props} />;
|
||||
return <Input {...props} value={inputValue} />;
|
||||
}
|
||||
|
||||
InputsIndex.defaultProps = {
|
||||
addon: false,
|
||||
}
|
||||
|
||||
InputsIndex.propTypes = {
|
||||
addon: PropTypes.oneOfType([
|
||||
PropTypes.bool,
|
||||
PropTypes.string,
|
||||
]),
|
||||
type: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default InputsIndex;
|
||||
export {
|
||||
InputAddonWithErrors,
|
||||
InputCheckboxWithErrors,
|
||||
InputDateWithErrors,
|
||||
InputEmailWithErrors,
|
||||
InputNumberWithErrors,
|
||||
InputPasswordWithErrors,
|
||||
InputSearchWithErrors,
|
||||
InputSelectWithErrors,
|
||||
InputTextWithErrors,
|
||||
InputTextAreaWithErrors,
|
||||
|
||||
@ -9,9 +9,12 @@ module.exports = mongoose => {
|
||||
|
||||
const SchemaTypes = mongoose.Schema.Types;
|
||||
|
||||
SchemaTypes.Decimal.prototype.cast = function (value) {
|
||||
return value.toString();
|
||||
};
|
||||
// Note: The decimal format isn't well supported by MongoDB.
|
||||
// It's recommended to use Float or Number type instead.
|
||||
//
|
||||
// SchemaTypes.Decimal.prototype.cast = function (value) {
|
||||
// return value.toString();
|
||||
// };
|
||||
|
||||
return {
|
||||
convertType: mongooseType => {
|
||||
@ -25,9 +28,8 @@ module.exports = mongoose => {
|
||||
case 'biginteger':
|
||||
return 'Number';
|
||||
case 'float':
|
||||
return 'Float';
|
||||
case 'decimal':
|
||||
return 'Decimal';
|
||||
return 'Float';
|
||||
case 'date':
|
||||
case 'time':
|
||||
case 'datetime':
|
||||
|
||||
@ -142,7 +142,7 @@ export class AuthPage extends React.Component { // eslint-disable-line react/pre
|
||||
const headerDescription = this.props.match.params.authType === 'register' ?
|
||||
<FormattedMessage id="users-permissions.Auth.header.register.description" />
|
||||
: <span />;
|
||||
|
||||
|
||||
return (
|
||||
<div className={styles.authPage}>
|
||||
<div className={styles.wrapper}>
|
||||
|
||||
@ -17,7 +17,11 @@ module.exports = {
|
||||
return new Error('This feature requires to install the Content Manager plugin');
|
||||
}
|
||||
|
||||
const role = await strapi.query('role', 'users-permissions').create(_.omit(params, ['users', 'permissions', 'type']));
|
||||
if (!params.type) {
|
||||
params.type = _.snakeCase(_.deburr(_.toLower(params.name)));
|
||||
}
|
||||
|
||||
const role = await strapi.query('role', 'users-permissions').create(_.omit(params, ['users', 'permissions']));
|
||||
|
||||
const arrayOfPromises = Object.keys(params.permissions).reduce((acc, type) => {
|
||||
Object.keys(params.permissions[type].controllers).forEach(controller => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user