🆕 新增复选框组件,添加对应ts类型

This commit is contained in:
xujiang 2020-09-27 15:20:53 +08:00
parent 8e8926e3b1
commit af614885b9
5 changed files with 35 additions and 10 deletions

View File

@ -135,6 +135,7 @@ yarn run start
## 赞助 ## 赞助
开源不易, 有了您的赞助, 我们会做的更好~ 开源不易, 有了您的赞助, 我们会做的更好~
<img src="http://io.nainor.com/uploads/WechatIMG2_1742b586c3d.jpeg" width="180px" />
## 技术反馈和交流 ## 技术反馈和交流
微信beautifulFront 微信beautifulFront

View File

@ -1,9 +1,10 @@
import { Input, Cell, DateSelect, Radio, Select } from 'zarm'; import { Input, Cell, DateSelect, Radio, Select, Checkbox } from 'zarm';
import styles from './baseForm.less'; import styles from './baseForm.less';
import React from 'react'; import React, { ReactText } from 'react';
import { import {
baseFormDateTpl, baseFormDateTpl,
baseFormMyRadioTpl, baseFormMyRadioTpl,
baseFormMyCheckboxTpl,
baseFormMySelectTpl, baseFormMySelectTpl,
baseFormNumberTpl, baseFormNumberTpl,
baseFormTextAreaTpl, baseFormTextAreaTpl,
@ -67,6 +68,27 @@ const BaseForm: TBaseForm = {
</div> </div>
); );
}, },
MyCheckbox: (
props: baseFormMyCheckboxTpl & { onChange: (v: Array<ReactText> | undefined) => void },
) => {
const { label, options, onChange } = props;
return (
<div className={styles.radioWrap}>
<div className={styles.radioTitle}>{label}</div>
<Cell>
<Checkbox.Group onChange={onChange}>
{options.map((item, i) => {
return (
<Checkbox value={item.value} key={i} className={styles.radioItem}>
{item.label}
</Checkbox>
);
})}
</Checkbox.Group>
</Cell>
</div>
);
},
Date: (props: baseFormDateTpl & { onChange: (v: Date) => void }) => { Date: (props: baseFormDateTpl & { onChange: (v: Date) => void }) => {
const { label, placeholder, onChange } = props; const { label, placeholder, onChange } = props;
return ( return (

View File

@ -9,10 +9,6 @@ const FormComponent = (props: IFormConfig) => {
const formData: Record<string, any> = {}; const formData: Record<string, any> = {};
const handleChange = useCallback( const handleChange = useCallback(
(item, v) => { (item, v) => {
if (item.options) {
formData[item.label] = v[0].label;
return;
}
formData[item.label] = v; formData[item.label] = v;
}, },
[formData], [formData],

View File

@ -8,12 +8,11 @@ import {
TNumberDefaultType, TNumberDefaultType,
TTextDefaultType, TTextDefaultType,
} from '@/components/PanelComponents/FormEditor/types'; } from '@/components/PanelComponents/FormEditor/types';
import { baseConfig, baseDefault, ICommonBaseType } from '../../common';
export type TFormEditData = Array< export type TFormEditData = Array<
ITextConfigType | INumberConfigType | IColorConfigType | ITextConfigType | IFormItemsConfigType ITextConfigType | INumberConfigType | IColorConfigType | ITextConfigType | IFormItemsConfigType
>; >;
export interface IFormConfig extends ICommonBaseType { export interface IFormConfig {
title: TTextDefaultType; title: TTextDefaultType;
fontSize: TNumberDefaultType; fontSize: TNumberDefaultType;
titColor: TColorDefaultType; titColor: TColorDefaultType;
@ -31,7 +30,6 @@ export interface IFormSchema {
const Form: IFormSchema = { const Form: IFormSchema = {
editData: [ editData: [
...baseConfig,
{ {
key: 'title', key: 'title',
name: '标题', name: '标题',
@ -105,7 +103,6 @@ const Form: IFormSchema = {
], ],
}, },
], ],
...baseDefault,
}, },
}; };
export default Form; export default Form;

View File

@ -167,6 +167,13 @@ export type baseFormMyRadioTpl = {
options: baseFormOptionsType[]; options: baseFormOptionsType[];
}; };
export type baseFormMyCheckboxTpl = {
id: string;
type: 'MyCheckbox';
label: string;
options: baseFormOptionsType[];
};
export type baseFormMySelectTpl = { export type baseFormMySelectTpl = {
id: string; id: string;
type: 'MySelect'; type: 'MySelect';
@ -186,6 +193,7 @@ export type baseFormUnion =
| baseFormNumberTpl | baseFormNumberTpl
| baseFormTextAreaTpl | baseFormTextAreaTpl
| baseFormMyRadioTpl | baseFormMyRadioTpl
| baseFormMyCheckboxTpl
| baseFormMySelectTpl | baseFormMySelectTpl
| baseFormDateTpl; | baseFormDateTpl;
export type baseFormUnionType = export type baseFormUnionType =
@ -193,6 +201,7 @@ export type baseFormUnionType =
| baseFormNumberTpl['type'] | baseFormNumberTpl['type']
| baseFormTextAreaTpl['type'] | baseFormTextAreaTpl['type']
| baseFormMyRadioTpl['type'] | baseFormMyRadioTpl['type']
| baseFormMyCheckboxTpl['type']
| baseFormMySelectTpl['type'] | baseFormMySelectTpl['type']
| baseFormDateTpl['type']; | baseFormDateTpl['type'];