Skip to content

Commit fbbffc2

Browse files
author
Kenneth
committed
feature: add prop disableMargin for FormItem
1 parent 3ad1c0a commit fbbffc2

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/molecules/Form/FormItemReactHookForm.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Form as AntdForm } from 'antd';
2-
import { Children, cloneElement, isValidElement, useEffect, useLayoutEffect, useMemo } from 'react';
2+
import { Children, cloneElement, isValidElement, useEffect } from 'react';
33
import { FieldValues, useController } from 'react-hook-form';
4-
import { FormItemStyles } from './styles';
5-
import { FormItemReactHookFormProps } from './types';
64
import { FormItem } from './FormItem';
5+
import { FormItemReactHookFormProps } from './types';
76

87
export const FormItemReactHookForm = <TFieldValues extends FieldValues = FieldValues>({
98
children,

src/molecules/Form/styles.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ export const FormListStyles = styled(Form.List)``;
99
export const FormProviderStyles = styled(Form.Provider)``;
1010
export const FormErrorListStyles = styled(Form.ErrorList)``;
1111
export const FormItemStyles = styled(Form.Item, {
12-
shouldForwardProp: prop => getExcludeForwardProps<RdFormItemProps>(['block'], prop),
12+
shouldForwardProp: prop => getExcludeForwardProps<RdFormItemProps>(['block', 'disableMargin'], prop),
1313
})<RdFormItemProps>`
14+
${({ disableMargin }) =>
15+
disableMargin &&
16+
css`
17+
margin-bottom: 0px;
18+
`}
19+
1420
${({ block }) =>
1521
block &&
1622
css`

src/molecules/Form/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Form } from 'antd';
33
import { ComponentToken } from 'antd/es/form/style';
44
import { FormRef } from 'rc-field-form/lib/interface';
55
import React, { ReactElement } from 'react';
6-
import { Control, FieldPath, FieldValues } from 'react-hook-form';
6+
import { Control, FieldPath, FieldValues, Path, PathValue } from 'react-hook-form';
77

88
//#region Define Ant Design types
99
type FormPropsAntd<Values = any> = GetProps<typeof Form<Values>>;
@@ -42,6 +42,12 @@ type FormItemPropsExtend = {
4242
* @description Option to fit Space width to its parent width, default is false
4343
*/
4444
block?: boolean;
45+
46+
/**
47+
* If set to `true`, disables the default margin applied to the Typography.Title component.
48+
* @default false
49+
*/
50+
disableMargin?: boolean;
4551
};
4652

4753
type FormListPropsExtend = {};

0 commit comments

Comments
 (0)