Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nanxiaobei/ant-plus
๐ช Ant Design Form Simplified
https://github.com/nanxiaobei/ant-plus
ant-design antd form input react select
Last synced: 5 days ago
JSON representation
๐ช Ant Design Form Simplified
- Host: GitHub
- URL: https://github.com/nanxiaobei/ant-plus
- Owner: nanxiaobei
- License: mit
- Created: 2018-06-10T08:20:08.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-11-21T07:43:47.000Z (21 days ago)
- Last Synced: 2024-11-29T13:13:48.362Z (13 days ago)
- Topics: ant-design, antd, form, input, react, select
- Language: TypeScript
- Homepage:
- Size: 35.4 MB
- Stars: 280
- Watchers: 6
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-star-libs - nanxiaobei / ant-plus
README
Link in bio to **widgets**,
your online **home screen**. โซ [๐ kee.so](https://kee.so/)---
Ant Design Form Simplified, build forms in the simplest way.
[![npm version](https://img.shields.io/npm/v/antx.svg?style=flat-square)](https://www.npmjs.com/package/antx)
[![npm downloads](https://img.shields.io/npm/dt/antx.svg?style=flat-square)](http://www.npmtrends.com/antx)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/antx?style=flat-square)](https://bundlephobia.com/result?p=antx)
[![GitHub](https://img.shields.io/github/license/nanxiaobei/ant-plus.svg?style=flat-square)](https://github.com/nanxiaobei/ant-plus/blob/main/LICENSE)
![npm peer dependency version](https://img.shields.io/npm/dependency-version/antx/peer/react?style=flat-square)
![npm peer dependency version](https://img.shields.io/npm/dependency-version/antx/peer/antd?style=flat-square)English ยท [็ฎไฝไธญๆ](./README.zh-CN.md)
---
## Introduction
`antx` provides a set of `antd` mixed field components:
**1. Say goodbye to cumbersome `` and `rules`**
Directly write on field components (e.g. `Input`) with `Form.Item` props and field props (**fully TypeScript support**), which greatly simplifies the code.**2. String `rules` (only enhanced, original `rules` are also supported)**
`rules` in string, for example `rules={['required', 'max=10']}` represents for `rules={[{ required: true }, { max: 10 }]}`.**3. Not adding any new props**
All props are `antd` original props, without add any other new props, reducing mental burden.In the same time, `antx` provides 2 helper components (`WrapperCol`, `Watch`), and a tool function `create()` for easily enhancing existing field components.
## Installation
```sh
pnpm add antx
# or
yarn add antx
# or
npm i antx
```## Usage
```tsx
import { Button, Form } from 'antd';
import { Input, Select, WrapperCol } from 'antx';const App = () => {
return (
Submit
);
};export default App;
```[![Edit antx](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/antx-v4hqw?fontsize=14&hidenavigation=1&theme=dark)
## API
### 1. Mixed components
1. **AutoComplete**
1. **Cascader**
1. **Checkbox**
1. **DatePicker**
1. **Input**
1. **InputNumber**
1. **Mentions**
1. **Radio**
1. **Rate**
1. **Select**
1. **Slider**
1. **Switch**
1. **TimePicker**
1. **Transfer**
1. **TreeSelect**
1. **Upload**
1. **CheckboxGroup** `Checkbox.Group`
1. **DateRange** `DatePicker.RangePicker`
1. **TextArea** `Input.TextArea`
1. **Search** `Input.Search`
1. **Password** `Input.Password`
1. **RadioGroup** `Radio.Group`
1. **TimeRange** `TimePicker.RangePicker`
1. **Dragger** `Upload.Dragger`For all the mixed components above, props like`className`, `style`, `name`, `tooltip` will be passed to `Form.Item`.
To pass to the inner field component, please use `selfClass`, `selfStyle`, `selfName`, `selfTooltip`.
### 2. Helper components
1. **Watch**: used to monitor the changes of form values, which can be only partial re-render, more refined and better performance
| Props | Description | Type | Default |
| ----------- | ------------------------------------------------------------------------------------------- | --------------------------------------------------------- | ------- |
| `name` | Field to monitor | [`NamePath`](https:ant.designcomponentsform-cnNamePath) | - |
| `list` | List of fields to monitor (mutually exclusive with `name`) | `NamePath[]` | - |
| `children` | Render props. Get the monitored value (or list), return UI | `(next: any, prev: any, form: FormInstance) => ReactNode` | - |
| `onlyValid` | Only trigger `children` rendering when the monitored value is not `undefined` | `boolean` | `false` |
| `onChange` | Get the monitored value (or list), handle side effects (mutually exclusive with `children`) | ` (next: any, prev: any, form: FormInstance) => void` | - |```tsx
// Watch example
import { Watch } from 'antx';
{(song) => {
returnSong: {song};
}}
{([song, artist]) => {
return (
Song: {song}, Artist: {artist}
);
}}
;
```2. **WrapperCol**: simplify the layout code, the same props as `Form.Item`, used when the UI needs to be aligned with the input box.
```tsx
// WrapperCol example
import { WrapperCol } from 'antx';
This is a hint that aligns with the input box
;
```### 3. `create()` function
- **create()**: convert existing custom field components into components that support `Form.Item` props mix-in.
```tsx
import { create } from 'antx';// Before
;// enhancing with create()
const MyCustomInputPlus = create(MyCustomInput);// After
;
```### 4. String `rules`
| String | Equals to | Description |
| --------------- | -------------------------------------- | ------------ |
| `'required'` | `{ required: true }` | |
| `'required=xx'` | `{ required: true, message: 'xx' }` | |
| `'string'` | `{ type: 'string', whitespace: true }` | |
| `'pureString'` | `{ type: 'string' }` | |
| `'number'` | `{ type: 'number' }` | |
| `'array'` | `{ type: 'array' }` | |
| `'boolean'` | `{ type: 'boolean' }` | |
| `'url'` | `{ type: 'url' }` | |
| `'email'` | `{ type: 'email' }` | |
| `'len=20'` | `{ len: 20 }` | `len === 20` |
| `'max=100'` | `{ max: 100 }` | `max <= 100` |
| `'min=10'` | `{ min: 10 }` | `min >= 10` |```tsx
// String rules example```
## Comparison
Ant Plus and Ant Design form code comparison:
![Comparison](public/antx_vs_antd.png)
## License
[MIT License](https://github.com/nanxiaobei/ant-plus/blob/main/LICENSE) (c) [nanxiaobei](https://lee.so/)