mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-11 13:59:11 +08:00
46341b115c
* custom feedback icons initial
(cherry picked from commit 22e43ad0357ea5294baf6eda659c900b1ab170f1)
* tests added and snaps updated
* Revert "tests added and snaps updated"
This reverts commit 13b57be30c
.
* unittest and documentation changes
* feedback items could be turn off
* documentation fix
* move feedback icons object into the hasFeedback prop
* feedbackIcons added to the form element
* test: commit trigger
* fix: failed form test
* snaps updated
* Update components/form/index.en-US.md
Co-authored-by: afc163 <afc163@gmail.com>
Signed-off-by: Gunay <gladio@gmail.com>
* Update components/form/index.en-US.md
Co-authored-by: afc163 <afc163@gmail.com>
Signed-off-by: Gunay <gladio@gmail.com>
* Update components/form/index.zh-CN.md
Co-authored-by: afc163 <afc163@gmail.com>
Signed-off-by: Gunay <gladio@gmail.com>
* Update components/form/demo/custom-feedback-icons.md
Signed-off-by: afc163 <afc163@gmail.com>
* Update components/form/demo/custom-feedback-icons.md
Signed-off-by: afc163 <afc163@gmail.com>
---------
Signed-off-by: Gunay <gladio@gmail.com>
Signed-off-by: afc163 <afc163@gmail.com>
Co-authored-by: afc163 <afc163@gmail.com>
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
import React from 'react';
|
|
import { uniqueId } from 'lodash';
|
|
|
|
import { createStyles, css } from 'antd-style';
|
|
import { AlertFilled, CloseSquareFilled } from '@ant-design/icons';
|
|
import { Button, Form, Input, Tooltip } from 'antd';
|
|
|
|
const useStyle = createStyles(() => ({
|
|
'custom-feedback-icons': css`
|
|
.ant-form-item-feedback-icon {
|
|
pointer-events: all;
|
|
}
|
|
`,
|
|
}));
|
|
|
|
const App: React.FC = () => {
|
|
const [form] = Form.useForm();
|
|
const { styles } = useStyle();
|
|
|
|
return (
|
|
<Form
|
|
name="custom-feedback-icons"
|
|
form={form}
|
|
style={{ maxWidth: 600 }}
|
|
feedbackIcons={({ errors }) => ({
|
|
error: (
|
|
<Tooltip
|
|
key="tooltipKey"
|
|
title={errors?.map((error) => <div key={uniqueId()}>{error}</div>)}
|
|
color="red"
|
|
>
|
|
<CloseSquareFilled />
|
|
</Tooltip>
|
|
),
|
|
})}
|
|
>
|
|
<Form.Item
|
|
name="custom-feedback-test-item"
|
|
label="Test"
|
|
className={styles['custom-feedback-icons']}
|
|
rules={[{ required: true, type: 'email' }, { min: 10 }]}
|
|
help=""
|
|
hasFeedback
|
|
>
|
|
<Input />
|
|
</Form.Item>
|
|
<Form.Item
|
|
name="custom-feedback-test-item2"
|
|
label="Test"
|
|
className={styles['custom-feedback-icons']}
|
|
rules={[{ required: true, type: 'email' }, { min: 10 }]}
|
|
help=""
|
|
hasFeedback={{
|
|
icons: ({ errors }) => ({
|
|
error: (
|
|
<Tooltip
|
|
key="tooltipKey"
|
|
title={errors?.map((error) => <div key={uniqueId()}>{error}</div>)}
|
|
color="pink"
|
|
>
|
|
<AlertFilled />
|
|
</Tooltip>
|
|
),
|
|
success: false,
|
|
}),
|
|
}}
|
|
>
|
|
<Input />
|
|
</Form.Item>
|
|
<Form.Item>
|
|
<Button htmlType="submit">Submit</Button>
|
|
</Form.Item>
|
|
</Form>
|
|
);
|
|
};
|
|
|
|
export default App;
|