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

Adrienne / TS migration for Password Input #34

Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/components/src/components/input/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Input from './input';
import Input, { TInputProps } from './input';
import './input.scss';

export type { TInputProps };
export default Input;
2 changes: 1 addition & 1 deletion packages/components/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import Field from '../field';
import Text from '../text/text';

type TInputProps = {
export type TInputProps = {
autoComplete?: string;
bottom_label?: string;
className?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PasswordInput from './password-input.jsx';
import PasswordInput from './password-input';
import './password-input.scss';

export default PasswordInput;
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import Icon from '../icon';
import Input from '../input';
import Input, { TInputProps } from '../input';

type TPasswordInput = Partial<TInputProps> & {
Copy link
Author

Choose a reason for hiding this comment

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

Used Partial to make types for Input optional since there are some components that uses PasswordInput without passing the required props for Input

Choose a reason for hiding this comment

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

I can see that the type is required in the InputField. If you put Partial it might accept even the type is undefined. If you remove Partial can i know what error will be return to you?

Copy link
Author

Choose a reason for hiding this comment

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

If TInputProps is not wrapped with Partial, there will be some places that uses PasswordInput who does not pass in the required type prop, thus causing the build to fail. Since I wasn't so sure if the type definitions for Input component type needs to be made optional in input.tsx, I just made it optional for PasswordInput as for now
Screenshot 2023-01-10 at 11 56 48 AM

autoComplete: string;
className?: string;
input_id?: string;
};

const PasswordInput = ({
className, // Must not be passed to Input as the only trailing icon should be the visibility icon
autoComplete, // Must be passed to Input, if not will get console warning
input_id,
...otherProps
}) => {
}: TPasswordInput) => {
const [should_show_password, setShouldShowPassword] = React.useState(false);
Copy link
Author

Choose a reason for hiding this comment

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

Typescript automatically infers the useState since a default boolean value was provided


const togglePasswordVisibility = () => {
Expand Down Expand Up @@ -39,10 +44,4 @@ const PasswordInput = ({
);
};

PasswordInput.propTypes = {
className: PropTypes.string,
autoComplete: PropTypes.string.isRequired,
input_id: PropTypes.string,
};

export default PasswordInput;