Skip to content
Merged
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
10 changes: 4 additions & 6 deletions .umirc.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// more config: https://d.umijs.org/config
import { defineConfig } from 'dumi';

export default defineConfig({
title: 'rc-field-form',
favicon:
'https://user-images.githubusercontent.com/9554297/83762004-a0761b00-a6a9-11ea-83b4-9c8ff721d4b8.png',
'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
logo:
'https://user-images.githubusercontent.com/9554297/83762004-a0761b00-a6a9-11ea-83b4-9c8ff721d4b8.png',
outputPath: '.doc',
exportStatic: {},
// mode: 'site',
// more config: https://d.umijs.org/config
'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
outputPath: '.doc'
});
3 changes: 0 additions & 3 deletions docs/StateForm-list-draggable.md

This file was deleted.

4 changes: 0 additions & 4 deletions docs/basic.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/component.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/context.md

This file was deleted.

4 changes: 4 additions & 0 deletions docs/demo/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## basic


<code src="../examples/basic.tsx" />
3 changes: 3 additions & 0 deletions docs/demo/component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## component

<code src="../examples/component.tsx" />
3 changes: 3 additions & 0 deletions docs/demo/context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## context

<code src="../examples/context.tsx" />
3 changes: 3 additions & 0 deletions docs/demo/layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## layout

<code src="../examples/layout.tsx" />
3 changes: 3 additions & 0 deletions docs/demo/list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## list

<code src="../examples/list.tsx" />
3 changes: 3 additions & 0 deletions docs/demo/redux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## redux

<code src="../examples/redux.tsx" />
3 changes: 3 additions & 0 deletions docs/demo/renderProps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## renderProps

<code src="../examples/renderProps.tsx" />
3 changes: 3 additions & 0 deletions docs/demo/reset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## reset

<code src="../examples/reset.tsx" />
3 changes: 3 additions & 0 deletions docs/demo/stateForm-list-draggable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## stateForm-list-draggable

<code src="../examples/StateForm-list-draggable.tsx" />
Copy link
Member Author

Choose a reason for hiding this comment

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

奇了怪了,把 example 里的改成了小写,竟然 diff 检测不到

3 changes: 3 additions & 0 deletions docs/demo/useForm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## useForm

<code src="../examples/useForm.tsx" />
3 changes: 3 additions & 0 deletions docs/demo/validate-perf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## validate-perf

<code src="../examples/validate-perf.tsx" />
3 changes: 3 additions & 0 deletions docs/demo/validate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## validate

<code src="../examples/validate.tsx" />
1 change: 0 additions & 1 deletion docs/examples/test.mdx

This file was deleted.

41 changes: 19 additions & 22 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
## rc-field-form
# rc-field-form

React Performance First Form Component.

[![NPM version][npm-image]][npm-url]
[![build status][github-actions-image]][github-actions-url]
[![Codecov][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]
[![NPM version][npm-image]][npm-url] [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/rc-field-form.svg?style=flat-square
[npm-url]: http://npmjs.org/package/rc-field-form
Expand All @@ -21,7 +18,7 @@ React Performance First Form Component.
```bash
npm install
npm start
open http://localhost:8000/
open http://localhost:8000
```

## Feature
Expand Down Expand Up @@ -56,11 +53,11 @@ import Form, { Field } from 'rc-field-form';
export default Demo;
```

# API
## 🔥 API

We use typescript to create the Type definition. You can view directly in IDE. But you can still check the type definition [here](https://github.com/react-component/field-form/blob/master/src/interface.ts).

## Form
### Form

| Prop | Description | Type | Default |
| ---------------- | -------------------------------------------------- | -------------------------------------------- | ---------------- |
Expand All @@ -76,7 +73,7 @@ We use typescript to create the Type definition. You can view directly in IDE. B
| onFinishFailed | Trigger when form submit and failed | ({ values, errorFields, outOfDate }) => void | - |
| onValuesChange | Trigger when any value of Field changed | (changedValues, values) => void | - |

## Field
### Field

| Prop | Description | Type | Default |
| ----------------- | ----------------------------------------------------------------------------- | ------------------------------------------- | -------- |
Expand All @@ -93,14 +90,14 @@ We use typescript to create the Type definition. You can view directly in IDE. B
| validateTrigger | Config trigger point with rule validate | string \| string[] | onChange |
| valuePropName | Config value mapping prop with element | string | value |

## List
### List

| Prop | Description | Type | Default |
| -------- | ------------------------------- | ------------------------------------------------------------------------------------------------------- | ------- |
| name | List field name path | [NamePath](#namepath)[] | - |
| children | Render props for listing fields | (fields: { name: [NamePath](#namepath) }[], operations: [ListOperations](#listoperations)) => ReactNode | - |

## useForm
### useForm

Form component default create an form instance by `Form.useForm`. But you can create it and pass to Form also. This allow you to call some function on the form instance.

Expand Down Expand Up @@ -140,15 +137,15 @@ class Demo extends React.Component {
| submit | Trigger form submit | () => void |
| validateFields | Trigger fields to validate | (nameList?: [NamePath](#namepath)[], options?: ValidateOptions) => Promise |

## FormProvider
### FormProvider

| Prop | Description | Type | Default |
| ---------------- | ----------------------------------------- | ---------------------------------------- | ------- |
| validateMessages | Config global `validateMessages` template | [ValidateMessages](#validatemessages) | - |
| onFormChange | Trigger by named form fields change | (name, { changedFields, forms }) => void | - |
| onFormFinish | Trigger by named form fields finish | (name, { values, forms }) => void | - |

## Interface
## 📋 Interface

### NamePath

Expand Down Expand Up @@ -208,27 +205,27 @@ Validate Messages provides a list of error template. You can ref [here](https://
| pattern | Rule `pattern` prop |
| type | Rule `type` prop |

# Different with `rc-form`
## Different with `rc-form`

`rc-field-form` is try to keep sync with `rc-form` in api level, but there still have something to change:

## 🔥 Field will not keep snyc with `initialValues` when un-touched
### 1. Field will not keep snyc with `initialValues` when un-touched

In `rc-form`, field value will get from `initialValues` if user not operate on it.
It's a bug but user use as a feature which makes fixing will be a breaking change and we have to keep it.
In Field Form, this bug will not exist anymore. If you want to change a field value, use `setFieldsValue` instead.

## 🔥 Remove Field will not clean up related value
### 2. Remove Field will not clean up related value

We do lots of logic to clean up the value when Field removed before. But with user feedback, remove exist value increase the additional work to keep value back with conditional field.

## 🔥 Nest name use array instead of string
### 3. Nest name use array instead of string

In `rc-form`, we support like `user.name` to be a name and convert value to `{ user: { name: 'Bamboo' } }`. This makes '.' always be the route of variable, this makes developer have to do additional work if name is real contains a point like `app.config.start` to be `app_config_start` and parse back to point when submit.

Field Form will only trade `['user', 'name']` to be `{ user: { name: 'Bamboo' } }`, and `user.name` to be `{ ['user.name']: 'Bamboo' }`.

## 🔥 Remove `validateFieldsAndScroll`
### 4. Remove `validateFieldsAndScroll`

Since `findDomNode` is marked as warning in [StrictMode](https://reactjs.org/docs/strict-mode.html#warning-about-deprecated-finddomnode-usage). It seems over control of Form component.
We decide to remove `validateFieldsAndScroll` method and you should handle it with you own logic:
Expand All @@ -241,7 +238,7 @@ We decide to remove `validateFieldsAndScroll` method and you should handle it wi
</Form>
```

## 🔥 `getFieldsError` always return array
### 5. `getFieldsError` always return array

`rc-form` returns `null` when no error happen. This makes user have to do some additional code like:

Expand All @@ -253,7 +250,7 @@ We decide to remove `validateFieldsAndScroll` method and you should handle it wi

Now `getFieldsError` will return `[]` if no errors.

## 🔥 Remove `callback` with `validateFields`
### 6. Remove `callback` with `validateFields`

Since ES8 is support `async/await`, that's no reason not to use it. Now you can easily handle your validate logic:

Expand All @@ -272,11 +269,11 @@ async function() {

**Notice: Now if your validator return an `Error(message)`, not need to get error by `e => e.message`. FieldForm will handle this.**

## 🔥 `preserve` is default to false
### 7. `preserve` is default to false

In `rc-form` you should use `preserve` to keep a value cause Form will auto remove a value from Field removed. Field Form will always keep the value in the Form whatever Field removed. But you can still use `preserve=false` to disable value keeping since `1.5.0`.

## 🔥 `setFields` not trigger `onFieldsChange` and `setFieldsValue` not trigger `onValuesChange`
### 8. `setFields` not trigger `onFieldsChange` and `setFieldsValue` not trigger `onValuesChange`

In `rc-form`, we hope to help user auto trigger change event by setting to make redux dispatch easier, but it's not good design since it makes code logic couping.

Expand Down
3 changes: 0 additions & 3 deletions docs/layout.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/list.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/redux.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/renderProps.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/reset.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/useForm.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/validate-perf.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/validate.md

This file was deleted.