Skip to content

Commit

Permalink
0.6.1 (#85)
Browse files Browse the repository at this point in the history
* Update README.md

* Fix rowIndex not defined error

* Implmented strict equal

* Removed redundant messages file

* Fixed showWhen and enabledWhen not working on change issue

* Removed unused code

* 0.6.1
  • Loading branch information
easeq authored May 15, 2020
1 parent 53888e8 commit f91afa3
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 91 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ containers and keys or use the ones that come with the module.
| | comment | String | comment / description that goes below the field | |
| | commentAs | String | define the HTML tag to be used for wrapping the comment. (Default: <small />) | |
| | commentClass | String | html class for the comment element | |
| | template | React Component | String | define your custom template for the field (check `src/FieldTemplate.js`) or set the template in the template registry using `registerTemplate` and pass the string key here |
| | template | React Component | String | define your custom template for the field (check `src/Template/Default.js`) or set the template in the template registry using `registerTemplate` and pass the string key here |
| | errorAs | String | define the HTML tag to be used for wrapping the error. (Default: <div />) | |
| | errorClass | String | html class for the error element | |

Expand Down
2 changes: 1 addition & 1 deletion demo/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React from 'react';
import { render } from 'react-dom';
import forms from './schema';
import ExampleFormContainer from './ExampleFormContainer';
Expand Down
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": "@flipbyte/formik-json",
"version": "0.6.0",
"version": "0.6.1",
"description": "formik-json is a wrapper for Formik to easily create forms using JSON / Javascript Object for defining the elements",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Container/EditableGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const EditableGrid = ({
{ isObject === false && !!buttons && !!buttons.add &&
<td colSpan={ _.size(elements) + additionalColumnCount }>
{ _.isFunction(buttons.add)
? buttons.add(arrayActions, arrayFields, rowIndex)
? buttons.add(arrayActions, arrayFields)
: (
<button
type="button"
Expand Down
18 changes: 10 additions & 8 deletions src/Container/Tabs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import Element from '../Element';
import { joinNames } from '../utils';
import React, { Component, useEffect, useRef, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import shallowequal from 'shallowequal';

Expand Down Expand Up @@ -80,14 +80,16 @@ const Tabs = ({ config = {} }) => {
key={ key }
href={ null }
className={
tabListItemClass + ( activeTab == key ? tabActiveClass : '' ) +
( tabInvalid ? ' is-invalid ' : '' )
tabListItemClass
+ ( activeTab === key ? tabActiveClass : '' )
+ ( tabInvalid ? ' is-invalid ' : '' )
}
style={ (tabInvalid
? activeTab == key
style={(
tabInvalid ? (
activeTab === key
? tabPaneActiveInvalid
: tabPaneInvalid
: null
) : null
)}
onClick={() => setActiveTab(key)}
>
Expand All @@ -107,15 +109,15 @@ const Tabs = ({ config = {} }) => {
<div
key={ tabKey }
className={
tabPaneClass + ' ' + ( activeTab == tabKey ? tabActiveClass : '' )
`${tabPaneClass} ${activeTab === tabKey ? tabActiveClass : ''}`
}
>
{ comment && <small className={ commentClass }>{ comment }</small> }
{ _.map(content, ({ name, ...rest }, key) => (
<Element
key={ key }
config={{ ...rest, name: joinNames(containerName, tabName, name) }}
update={ activeTab == tabKey }
update={ activeTab === tabKey }
/>
))}
</div>
Expand Down
5 changes: 2 additions & 3 deletions src/Element.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import _ from 'lodash';
import { connect } from 'formik';
import React, { useEffect, useLayoutEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import ElementRenderer from './Renderer';
import { FIELD } from './registry';
import shallowequal from 'shallowequal';

const Element = ({ config, update, formik }) => {
const { configSource, dataSource, name } = config;
const { configSource, dataSource } = config;
const [ hasLoadedConfig, setHasLoadedConfig ] = useState(false);
const [ hasLoadedData, setHasLoadedData ] = useState(dataSource ? false : true);
const [ hasMounted, setHasMounted ] = useState(update !== false);
const [ submitCount, setSubmitCount ] = useState();
const [ loadedConfig, setLoadedConfig ] = useState(undefined);

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Field/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ class Autocomplete extends Component {

render() {
const { config, formik, error, value } = this.props;
const {
name,
type,
attributes,
defaultValue,
options = {}
} = config;
const { name } = config;
const { setFieldValue, handleBlur } = formik;

this.autosuggestOptions.inputProps.name = name;
Expand Down
3 changes: 1 addition & 2 deletions src/Field/FileUploader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import PropTypes from 'prop-types';
import React, { useMemo, useEffect, Fragment } from 'react';
import React, { useMemo } from 'react';
import { useDropzone } from 'react-dropzone';
import { changeHandler } from '../utils';

Expand Down
1 change: 0 additions & 1 deletion src/Form.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash';
import React, { useEffect, useCallback, useState } from 'react';
import { Formik } from 'formik';
import messages from './messages';
import Element from './Element';
import { SchemaProvider } from './withFormConfig';
import { prepareValidationSchema } from './utils';
Expand Down
26 changes: 14 additions & 12 deletions src/Renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import _ from 'lodash';
import React, { useState, useEffect } from 'react';
import { Field } from 'formik';
import { Field, useFormikContext } from 'formik';
import withFormConfig from './withFormConfig';
import { containers, fields, templates, FIELD } from './registry';
import when from '@flipbyte/when-condition';
Expand Down Expand Up @@ -44,10 +43,9 @@ const ElementRenderer = ({
enabledWhen,
template
} = config;
const { values } = formik;
const { values } = useFormikContext();
const [ canShow, setCanShow ] = useState(showWhen ? false : true);
const [ disabled, setDisabled ] = useState(enabledWhen ? true : false);
const currentValue = _.get(values, name);

/**
* If the template is function, assuming it is a react component, use it
Expand All @@ -73,15 +71,19 @@ const ElementRenderer = ({

return !!type && canShow && (
type === FIELD
? <Field name={ name } render={({ field: { value }}) => (
<ErrorManager name={ name }>
{(error) => (
<Template disabled={ disabled } error={ error } { ...config }>
{ renderElement({ config, formik, value, error }) }
</Template>
? (
<Field name={ name }>
{({ field: { value }}) => (
<ErrorManager name={ name }>
{(error) => (
<Template disabled={ disabled } error={ error } { ...config }>
{ renderElement({ config, formik, value, error }) }
</Template>
)}
</ErrorManager>
)}
</ErrorManager>
)} />
</Field>
)
: renderElement({ config, formik })
);
}
Expand Down
47 changes: 0 additions & 47 deletions src/messages.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/registry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import React, { Component } from 'react';
import { Field } from 'formik';

export const CONTAINER = 'container';
export const FIELD = 'field';
export const TEMPLATE = 'template';
Expand Down
4 changes: 1 addition & 3 deletions src/withFormConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import messages from './messages';
import React, { Component } from 'react';
import { prepareValidationSchema } from './utils';
import React from 'react';

const SchemaContext = React.createContext({});
export const SchemaProvider = ({ value, children }) => (
Expand Down

0 comments on commit f91afa3

Please sign in to comment.