Skip to content

Commit 77099e4

Browse files
committed
fix(form): PasssWordStrength remove progressDom
1 parent fd5ef43 commit 77099e4

File tree

2 files changed

+15
-50
lines changed

2 files changed

+15
-50
lines changed

packages/form/src/components/LoginForm/demos/login-form.tsx

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,18 @@ export default () => {
7979
prefix: <LockOutlined className={'prefixIcon'} />,
8080
strengthText:
8181
'Password should contain numbers, letters and special characters, at least 8 characters long.',
82-
getStatus: (value) => {
83-
if (value && value.length > 12) {
84-
return 'ok';
85-
}
86-
if (value && value.length > 6) {
87-
return 'pass';
88-
}
89-
return 'poor';
90-
},
91-
getPercent: (status, value) => {
92-
if (value && value.length > 12) {
93-
return 100;
94-
}
95-
if (value && value.length > 6) {
96-
return 50;
97-
}
98-
return ((value?.length || 1) / 12) * 100;
99-
},
100-
statusRender: (status) => {
82+
83+
statusRender: (value) => {
84+
const getStatus = () => {
85+
if (value && value.length > 12) {
86+
return 'ok';
87+
}
88+
if (value && value.length > 6) {
89+
return 'pass';
90+
}
91+
return 'poor';
92+
};
93+
const status = getStatus();
10194
if (status === 'pass') {
10295
return (
10396
<div style={{ color: token.colorWarning }}>

packages/form/src/components/Text/index.tsx

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMountMergeState } from '@ant-design/pro-utils';
2-
import { Form, Popover, PopoverProps, Progress, type InputProps } from 'antd';
2+
import { Form, Popover, PopoverProps, type InputProps } from 'antd';
33
import type { InputRef, PasswordProps } from 'antd/lib/input';
44
import omit from 'omit.js';
55
import React, { useState } from 'react';
@@ -34,16 +34,8 @@ const ProFormText: React.FC<ProFormFieldItemProps<InputProps, InputRef>> = ({
3434

3535
export type PasswordStatus = 'ok' | 'pass' | 'poor' | undefined;
3636

37-
const passwordProgressMap = {
38-
ok: 'success',
39-
pass: 'normal',
40-
poor: 'exception',
41-
} as const;
42-
4337
export type PasssWordStrengthProps = {
44-
getStatus?: (value?: string) => PasswordStatus;
45-
statusRender?: (status: PasswordStatus, value?: string) => React.ReactNode;
46-
getPercent?: (status: PasswordStatus, value?: string) => number;
38+
statusRender?: (value?: string) => React.ReactNode;
4739
popoverProps?: PopoverProps;
4840
strengthText?: React.ReactNode;
4941
};
@@ -64,20 +56,6 @@ const PasssWordStrength: React.FC<
6456
<Form.Item shouldUpdate noStyle>
6557
{(form) => {
6658
const value = form.getFieldValue(props.name || []) as string;
67-
const status = props.getStatus?.(value);
68-
const getPasswordProgressDom = () => {
69-
return value && value.length && status ? (
70-
<Progress
71-
status={passwordProgressMap[status]}
72-
steps={3}
73-
style={{
74-
width: '100%',
75-
}}
76-
percent={props.getPercent?.(status, value) || 0}
77-
showInfo={false}
78-
/>
79-
) : null;
80-
};
8159
return (
8260
<Popover
8361
getPopupContainer={(node) => {
@@ -93,8 +71,6 @@ const PasssWordStrength: React.FC<
9371
padding: '4px 0',
9472
}}
9573
>
96-
{props?.statusRender?.(status, value)}
97-
{getPasswordProgressDom()}
9874
{props.strengthText ? (
9975
<div
10076
style={{
@@ -130,13 +106,11 @@ const Password: React.FC<
130106
}: ProFormFieldItemProps<PasswordProps & PasssWordStrengthProps, InputRef>) => {
131107
const [open, setOpen] = useState<boolean>(false);
132108

133-
if (fieldProps?.getStatus && fieldProps?.statusRender && rest.name) {
109+
if (fieldProps?.statusRender && rest.name) {
134110
return (
135111
<PasssWordStrength
136112
name={rest.name}
137-
getStatus={fieldProps?.getStatus}
138113
statusRender={fieldProps?.statusRender}
139-
getPercent={fieldProps?.getPercent}
140114
popoverProps={fieldProps?.popoverProps}
141115
strengthText={fieldProps?.strengthText}
142116
open={open}
@@ -146,9 +120,7 @@ const Password: React.FC<
146120
valueType="password"
147121
fieldProps={{
148122
...omit(fieldProps, [
149-
'getStatus',
150123
'statusRender',
151-
'getPercent',
152124
'popoverProps',
153125
'strengthText',
154126
]),

0 commit comments

Comments
 (0)