Skip to content
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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/frontend/components/SchemaForm/_RenderFormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -28,6 +31,7 @@ export function RenderFormInput(props: IRenderFormInputProps) {
onChange,
} = useExtendRenderFormInputProps(props);
const { _ } = useLingui();
const showPassword = useToggle();
const formProps = {
label,
required,
Expand Down Expand Up @@ -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 (
Copy link
Contributor

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

   return <FormPasswordInput {...formProps} />;

everything else should be in the component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got It

<FormPasswordInput
type={showPassword.isOn ? "text" : "password"}
{...formProps}
rightActions={
showPassword.isOn
? [
{
systemIcon: "Eye",
Copy link
Contributor

@thrownullexception thrownullexception May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this

  EyeOff: `<path d="M17.94 17.94A9.995 9.995 0 0112.009 20H12c-7 0-11-8-11-8a18.605 18.605 0 015.017-5.908l.043-.032M9.9 4.24A8.865 8.865 0 0111.979 4h.023-.001c7 0 11 8 11 8a18.62 18.62 0 01-2.182 3.217l.022-.027m-6.721-1.07a3 3 0 11-4.242-4.238l.002-.002M1 1l22 22" />`,

to src/shared/constants/Icons.tsx so that we have a EyeOff icon

action() {
showPassword.toggle();
},
label: msg`Hide Password`,
},
]
: [
{
systemIcon: "EyeOff",
action: showPassword.toggle,
label: msg`Show Password`,
},
]
}
/>
);
case "datetime-local":
return <FormDateInput {...formProps} />;

Expand Down
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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed, you can just pass ISharedFormInput as the component props

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
);
};
1 change: 1 addition & 0 deletions src/shared/constants/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const SystemIcons = {
Book: `<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20" /><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z" />`,
Terminal: `<polyline points="4 17 10 11 4 5" /><line x1="12" x2="20" y1="19" y2="19" />`,
Eye: `<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" /><circle cx="12" cy="12" r="3" />`,
EyeOff: `<path d="M17.94 17.94A9.995 9.995 0 0112.009 20H12c-7 0-11-8-11-8a18.605 18.605 0 015.017-5.908l.043-.032M9.9 4.24A8.865 8.865 0 0111.979 4h.023-.001c7 0 11 8 11 8a18.62 18.62 0 01-2.182 3.217l.022-.027m-6.721-1.07a3 3 0 11-4.242-4.238l.002-.002M1 1l22 22" />`,
Columns: `<path d="M12 3h7a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-7m0-18H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h7m0-18v18" />`,
Thrash: `<polyline points="3 6 5 6 21 6" /><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" /><line x1="10" x2="10" y1="11" y2="17" /><line x1="14" x2="14" y1="11" y2="17" />`,
Copy: `<rect height="13" rx="2" ry="2" width="13" x="9" y="9" />
Expand Down
Loading