Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@freenow/uniform
Advanced tools
This library allows you to generate forms based on provided JSON configuration.
import formGenerator from '@freenow/uniform';
.const Form = formGenerator(formConfig, components);
...
<Form
onSubmit={/*your submit function*/}
/>
The formConfig
is an object that contains all field definitions. Let's look at simple example:
const formConfig = {
fields: [
{
component: 'TextInput',
defaultValue: 'default',
label: 'Text input with default value',
name: 'default',
},
],
name: 'test',
};
So the config consist of fields
array and name
(Unique form name). Each field
element can have following properties: component
, defaultValue
, label
, name
, displayConfigs
, validationConfig
.
The validationConfig
is implemented using Yup library. In our case validation checks that the field is string and required. You can chain validation by adding elements in methods
array.
const formConfig = {
fields: [
{
component: 'TextInput',
label: 'Text input with validation logic',
name: 'validation',
validationConfig: {
methods: [
{
message: 'Required',
type: 'required',
},
],
type: 'string',
},
},
],
name: 'test',
};
The displayConfigs
is implemented using Yup library. In the example below we only show the "display" field when field with the name "default" has value "show". Feel free to depend on multiple fields values by adding additional element to displayConfig
.
const formConfig = {
fields: [
{
component: 'TextInput',
defaultValue: 'default',
label: 'Text input with default value',
name: 'default',
},
{
component: 'TextInput',
displayConfigs: [
{
methods: [
{
compareValue: ['show'],
type: 'oneOf',
},
],
type: 'string',
valueKey: 'default',
},
],
label: 'Text input with display logic',
name: 'display',
},
],
name: 'test',
};
The component
property refers to render function of each field and specified in the second paramer in generator. Let's have a look at this:
const FormContainer = ({ children, ...rest }) => (
<form {...rest}>{children}</form>
);
FormContainer.propTypes = {
children: PropTypes.node.isRequired,
};
const TextInput = ({ field, setFieldValue }) => (
<input
{...field}
onChange={e => setFieldValue(field.name, e.target.value)}
id={field && field.name}
/>
);
TextInput.propTypes = {
field: PropTypes.object.isRequired,
setFieldValue: PropTypes.func.isRequired,
};
const SubmitButton = props => <button {...props} type='submit' />;
const components = {
FormContainer,
SubmitButton,
TextInput,
};
The components
object is a mapping between names and the actual components. SubmitButton
and FormContainer
are required to create. And TextInput
will be linked to component: 'TextInput'
in the form config. To create custom components for your field please follow Formik docs on the Field element.
By default, mandatory minimum test coverage of the library is set to 80%.
FAQs
Component for creating dynamic forms
We found that @freenow/uniform demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.