-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update _RenderFormInput.tsx featue Ehancement #67
Changes from 5 commits
ed63b26
34d244e
777b172
2179048
8d71754
1adf8d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,9 @@ import { FormSelectButton } from "frontend/design-system/components/Form/FormSel | |
import { FormRichTextArea } from "frontend/design-system/components/Form/FormRichTextArea"; | ||
import { useExtendRenderFormInputProps } from "frontend/views/data/portal"; | ||
import { useLingui } from "@lingui/react"; | ||
import { msg } from "@lingui/macro"; | ||
import { useToggle } from "frontend/hooks/state/useToggleState"; | ||
import { FormPasswordInput } from "frontend/design-system/components/Form/FormPasswordInput"; | ||
import { IRenderFormInputProps } from "./types"; | ||
|
||
export function RenderFormInput(props: IRenderFormInputProps) { | ||
|
@@ -28,6 +31,7 @@ export function RenderFormInput(props: IRenderFormInputProps) { | |
onChange, | ||
} = useExtendRenderFormInputProps(props); | ||
const { _ } = useLingui(); | ||
const showPassword = useToggle(); | ||
const formProps = { | ||
label, | ||
required, | ||
|
@@ -70,13 +74,37 @@ export function RenderFormInput(props: IRenderFormInputProps) { | |
|
||
switch (type) { | ||
case "email": | ||
case "password": | ||
case "url": | ||
case "color": | ||
return <FormInput type={type} {...formProps} />; | ||
case "number": | ||
return <FormNumberInput {...formProps} />; | ||
|
||
case "password": | ||
return ( | ||
<FormPasswordInput | ||
type={showPassword.isOn ? "text" : "password"} | ||
{...formProps} | ||
rightActions={ | ||
showPassword.isOn | ||
? [ | ||
{ | ||
systemIcon: "Eye", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add this
to |
||
action() { | ||
showPassword.toggle(); | ||
}, | ||
label: msg`Hide Password`, | ||
}, | ||
] | ||
: [ | ||
{ | ||
systemIcon: "EyeOff", | ||
action: showPassword.toggle, | ||
label: msg`Show Password`, | ||
}, | ||
] | ||
} | ||
/> | ||
); | ||
case "datetime-local": | ||
return <FormDateInput {...formProps} />; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useLingui } from "@lingui/react"; | ||
import { ISharedFormInput } from "./_types"; | ||
import { generateFormArias, wrapLabelAndError } from "./_wrapForm"; | ||
import { Input } from "./Styles"; | ||
|
||
interface IFormInput extends ISharedFormInput { | ||
type?: "password" | "text"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed, you can just pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it!! |
||
} | ||
|
||
export const FormPasswordInput = (formInput: IFormInput) => { | ||
const { input, type, disabled, meta, placeholder, ...rest } = formInput; | ||
const { _ } = useLingui(); | ||
return wrapLabelAndError( | ||
<Input | ||
{...input} | ||
{...rest} | ||
{...generateFormArias(meta)} | ||
type={type} | ||
id={formInput.input.name} | ||
placeholder={placeholder ? _(placeholder) : null} | ||
disabled={disabled} | ||
/>, | ||
formInput | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move all the logic here to the new password component
Like here it should just be
everything else should be in the component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got It