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
Changes from 1 commit
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
30 changes: 29 additions & 1 deletion src/frontend/components/SchemaForm/_RenderFormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
onChange,
} = useExtendRenderFormInputProps(props);
const { _ } = useLingui();
const isPasswordReveal = useToggle();

Check failure on line 31 in src/frontend/components/SchemaForm/_RenderFormInput.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'useToggle'.
const formProps = {
label,
required,
Expand Down Expand Up @@ -70,10 +71,37 @@

switch (type) {
case "email":
case "password":
case "url":
case "color":
return <FormInput type={type} {...formProps} />;
case "password":
return (
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.

Can we move this to a new component, FormPasswordInput

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay sir

<FormInput
type={isPasswordReveal.isOn ? "text" : "password"}

Check failure on line 80 in src/frontend/components/SchemaForm/_RenderFormInput.tsx

View workflow job for this annotation

GitHub Actions / build

Type '"password" | "text"' is not assignable to type '"password" | "email" | "url" | "color"'.
{...formProps}
rightActions={
formProps.input.value
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned above the logic of the rightAction always be present and should be based on the isPasswordReveal.isOn so we should be having something like

rightActions: [showPassword.isOn ? {
systemIcon: 'EyeOff',
 action: showPassword.toggle,
  label: msg`Hide Password`,
}: {
systemIcon: 'Eye',
 action: showPassword.toggle,
  label: msg`Show Password`,
}]

? [
{
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: () => {
isPasswordReveal.toggle();
},
label: msg`show Password`,

Check failure on line 90 in src/frontend/components/SchemaForm/_RenderFormInput.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'msg'.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
label: msg`show Password`,
label: msg`Show Password`,

},
]
: []
}
input={{
...formProps.input,
onChange: (val) => {
formProps.input.onChange(val);
if (!formProps.input.value) isPasswordReveal.off();
Copy link
Contributor

Choose a reason for hiding this comment

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

The switch should be intentional not hooked to the onChange handler

},
}}
/>
);

case "number":
return <FormNumberInput {...formProps} />;

Expand Down
Loading