Skip to content

Commit

Permalink
Merge branch 'master' into chore/upgrade-async-validator
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 authored Aug 14, 2024
2 parents 6cc06cd + 0ed0e7b commit ef742f9
Show file tree
Hide file tree
Showing 27 changed files with 737 additions and 153 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: npm
directory: "/"
schedule:
Expand Down
35 changes: 20 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ jobs:
- name: checkout
uses: actions/checkout@master

- uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '20'

- name: cache package-lock.json
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: create package-lock.json
run: npm i --package-lock-only
run: npm i --package-lock-only --legacy-peer-deps

- name: hack for singe file
run: |
Expand All @@ -34,7 +34,7 @@ jobs:
cp package-lock.json package-temp-dir
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
Expand All @@ -47,16 +47,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master
uses: actions/checkout@v4

- name: restore cache from package-lock.json
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
Expand All @@ -70,16 +70,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master
uses: actions/checkout@v4

- name: restore cache from package-lock.json
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
Expand All @@ -93,21 +93,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master
uses: actions/checkout@v4

- name: restore cache from package-lock.json
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: coverage
run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash)
run: npm test -- --coverage

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true # optional (default = false)
token: ${{ secrets.CODECOV_TOKEN }} # required

needs: setup
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
.umi-test
.env.local
.dumi/
package-lock.json
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ open http://localhost:8000
```js | pure
import Form, { Field } from 'rc-field-form';

const Input = ({ value = "", ...props }) => <input value={value} {...props} />;
const Input = ({ value = '', ...props }) => <input value={value} {...props} />;

const Demo = () => {
return (
<Form
onFinish={(values) => {
console.log("Finish:", values);
onFinish={values => {
console.log('Finish:', values);
}}
>
<Field name="username">
Expand Down Expand Up @@ -81,20 +81,20 @@ We use typescript to create the Type definition. You can view directly in IDE. B

### Field

| Prop | Description | Type | Default |
| ----------------- | ----------------------------------------------------------------------------- | ------------------------------------------- | -------- |
| dependencies | Will re-render if dependencies changed | [NamePath](#namepath)[] | - |
| getValueFromEvent | Specify how to get value from event | (..args: any[]) => any | - |
| getValueProps | Customize additional props with value. This prop will disable `valuePropName` | (value) => any | - |
| initialValue | Field initial value | any | - |
| name | Field name path | [NamePath](#namepath) | - |
| normalize | Normalize value before update | (value, prevValue, prevValues) => any | - |
| preserve | Preserve value when field removed | boolean | false |
| rules | Validate rules | [Rule](#rule)[] | - |
| Prop | Description | Type | Default |
| ----------------- | ----------------------------------------------------------------------------- | ---------------------------------------------- | -------- |
| dependencies | Will re-render if dependencies changed | [NamePath](#namepath)[] | - |
| getValueFromEvent | Specify how to get value from event | (..args: any[]) => any | - |
| getValueProps | Customize additional props with value. This prop will disable `valuePropName` | (value) => any | - |
| initialValue | Field initial value | any | - |
| name | Field name path | [NamePath](#namepath) | - |
| normalize | Normalize value before update | (value, prevValue, prevValues) => any | - |
| preserve | Preserve value when field removed | boolean | false |
| rules | Validate rules | [Rule](#rule)[] | - |
| shouldUpdate | Check if Field should update | boolean \| (prevValues, nextValues) => boolean | - |
| trigger | Collect value update by event trigger | string | onChange |
| validateTrigger | Config trigger point with rule validate | string \| string[] | onChange |
| valuePropName | Config value mapping prop with element | string | value |
| trigger | Collect value update by event trigger | string | onChange |
| validateTrigger | Config trigger point with rule validate | string \| string[] | onChange |
| valuePropName | Config value mapping prop with element | string | value |

### List

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

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

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

<code src="../examples/useWatch-selector.tsx"></code>
39 changes: 39 additions & 0 deletions docs/examples/clearOnDestroy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Form, { Field } from 'rc-field-form';
import React, { useState } from 'react';
import Input from './components/Input';

export default () => {
const [load, setLoad] = useState(false);
const [count, setCount] = useState(0);

const [form] = Form.useForm(undefined);

return (
<>
<button
onClick={() => {
setCount(c => c + 1);
setLoad(c => !c);
}}
>
load
</button>

<button
onClick={() => {
console.log(form.getFieldsValue(true));
}}
>
values
</button>
{load && (
<Form form={form} initialValues={{ count }} clearOnDestroy>
<Field name="count">
<Input placeholder="count" />
</Field>
<button type="submit">Submit</button>
</Form>
)}
</>
);
};
66 changes: 66 additions & 0 deletions docs/examples/fieldTouched.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import Form from 'rc-field-form';

export default () => {

const [form] = Form.useForm();
const [, forceUpdate] = React.useState({});

return (
<div>
<Form
form={form}
style={{ padding: 20 }}
initialValues={{
usename: '123',
list: [
{},
],
}}
>
<Form.Field name="username">
<input />
</Form.Field>
<div style={{ paddingLeft: 20 }}>
<Form.List name="list">
{(fields, { add }) => (
<>
{
fields.map((field) => {
return (
<div key={field.key}>
<div>
<Form.Field name={[field.name, 'field1']}>
<input placeholder="field1" />
</Form.Field>
</div>
<div>
<Form.Field name={[field.name, 'field2']}>
<input placeholder="field2" />
</Form.Field>
</div>
</div>
);
})
}
<button onClick={() => add()}>add</button>
</>
)}
</Form.List>
</div>
<div>
<button
onClick={() => {
forceUpdate({});
}}
>forceUpdate</button>
<button
onClick={() => form.resetFields()}
>reset</button>
</div>
<div>form.isFieldsTouched(true): {`${form.isFieldsTouched(true)}`}</div>
<div>{`form.isFieldsTouched(['list'], true)`}: {`${form.isFieldsTouched(['list'], true)}`}</div>
</Form>
</div>
);
}
37 changes: 37 additions & 0 deletions docs/examples/useWatch-selector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import Form, { Field } from 'rc-field-form';
import Input from './components/Input';

type FieldType = {
init?: string;
name?: string;
age?: number;
};

export default () => {
const [form] = Form.useForm<FieldType>();
const values = Form.useWatch(
values => ({ init: values.init, newName: values.name, newAge: values.age }),
{ form, preserve: true },
);
console.log('values', values);
return (
<>
<Form form={form} initialValues={{ init: 'init', name: 'aaa' }}>
name
<Field name="name">
<Input />
</Field>
age
<Field name="age">
<Input />
</Field>
no-watch
<Field name="no-watch">
<Input />
</Field>
values:{JSON.stringify(values)}
</Form>
</>
);
};
27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-field-form",
"version": "1.40.0-0",
"version": "2.4.0",
"description": "React Form Component",
"typings": "es/index.d.ts",
"engines": {
Expand Down Expand Up @@ -49,33 +49,36 @@
"react-dom": ">=16.9.0"
},
"dependencies": {
"@babel/runtime": "^7.23.2",
"@rc-component/async-validator": "^5.0.0",
"rc-util": "^5.38.0"
"@babel/runtime": "^7.18.0",
"@rc-component/async-validator": "^5.0.3",
"rc-util": "^5.32.2"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.0.0",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^15.0.2",
"@types/jest": "^29.2.5",
"@types/lodash": "^4.14.135",
"@types/node": "^20.11.30",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@umijs/fabric": "^2.5.2",
"@umijs/fabric": "^4.0.1",
"dumi": "^2.0.0",
"eslint": "^7.18.0",
"eslint": "^8.54.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-unicorn": "^52.0.0",
"father": "^4.0.0",
"gh-pages": "^3.1.0",
"gh-pages": "^6.1.0",
"jest": "^29.0.0",
"np": "^5.0.0",
"prettier": "^2.1.2",
"rc-test": "^7.0.15",
"react": "^18.0.0",
"react-dnd": "^8.0.3",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^8.0.3",
"react-dom": "^18.0.0",
"react-redux": "^8.1.2",
"redux": "^4.2.1",
"react-redux": "^9.0.4",
"redux": "^5.0.0",
"typescript": "^5.1.6"
}
}
Loading

0 comments on commit ef742f9

Please sign in to comment.