Skip to content

Commit

Permalink
Merge pull request #32 from nickovchinnikov/login
Browse files Browse the repository at this point in the history
Login with React Hook Form
  • Loading branch information
nickovchinnikov authored May 2, 2022
2 parents dea338c + 3ea0566 commit 8099418
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 139 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,9 @@
### Login page part 2

[pull request](https://github.com/nickovchinnikov/coursesbox/pull/31)

### React hook form and login

### React hook form, validation and tests

[pull request](https://github.com/nickovchinnikov/coursesbox/pull/32)
57 changes: 32 additions & 25 deletions frontend/components/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { FC, ChangeEventHandler, InputHTMLAttributes, ReactChild } from "react";
import {
FC,
ChangeEventHandler,
InputHTMLAttributes,
ReactChild,
forwardRef,
ForwardedRef,
} from "react";
import styled from "@emotion/styled";

import { Icon, AvailableIcons } from "@/components/Icon";
Expand Down Expand Up @@ -100,27 +107,27 @@ export type Props = {
feedback?: ReactChild;
} & WrapperProps;

export const Input: FC<Props & InputHTMLAttributes<HTMLInputElement>> = ({
label,
height = 7,
width = 20,
icon,
feedback,
className,
...rest
}) => (
<Wrapper
isLabelVisible={Boolean(label)}
isFeedbackVisible={Boolean(feedback)}
height={height}
width={width}
className={className}
>
<Label>{label}</Label>
<InputWrapper>
<StyledInput {...rest} />
{icon && <StyledIcon name={icon} />}
</InputWrapper>
<Feedback>{feedback}</Feedback>
</Wrapper>
);
export const Input: FC<Props & InputHTMLAttributes<HTMLInputElement>> =
forwardRef(
(
{ label, height = 7, width = 20, icon, feedback, className, ...rest },
ref
) => (
<Wrapper
isLabelVisible={Boolean(label)}
isFeedbackVisible={Boolean(feedback)}
height={height}
width={width}
className={className}
>
<Label>{label}</Label>
<InputWrapper>
<StyledInput ref={ref as ForwardedRef<HTMLInputElement>} {...rest} />
{icon && <StyledIcon name={icon} />}
</InputWrapper>
<Feedback role="alert">{feedback}</Feedback>
</Wrapper>
)
);

Input.displayName = "Input";
2 changes: 2 additions & 0 deletions frontend/components/Input/__snapshots__/Input.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports[`Input test cases Render check 1`] = `
</div>
<span
class="css-1reg724"
role="alert"
/>
</label>
</DocumentFragment>
Expand Down Expand Up @@ -65,6 +66,7 @@ exports[`Input test cases Render check with icon 1`] = `
</div>
<span
class="css-1reg724"
role="alert"
/>
</label>
</DocumentFragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ exports[`Layout test cases Render check 1`] = `
</div>
<span
class="css-1reg724"
role="alert"
/>
</label>
<main
Expand Down
Loading

1 comment on commit 8099418

@vercel
Copy link

@vercel vercel bot commented on 8099418 May 2, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.