Skip to content

Commit

Permalink
make custom timer input pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
nmpereira committed Oct 4, 2023
1 parent 82b3409 commit 7b90669
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
14 changes: 14 additions & 0 deletions src/components/Controls/TimerControls.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,17 @@ export const TimerFormContainer = styled.div<{
width: 100%;
height: 100%;
`;

export const StyledRowDiv = styled.div`
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 100%;
gap: 20px;
margin-top: 20px;
@media (max-width: 300px), (max-height: 600px) {
display: none;
}
`;
48 changes: 35 additions & 13 deletions src/components/Controls/TimerForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { useEffect, useState } from "react";
import React, { useState } from "react";
import socket from "../Socket/socket";
import { roomName } from "../../../common/common";
import { TimerFormContainer } from "./TimerControls.styled";
import { StyledRowDiv, TimerFormContainer } from "./TimerControls.styled";
import { StyledButton } from "../Button/Button";
import ValidationInput from "../Modal/ValidationInput";

interface TimerFormProps {
isLoaded: boolean;
Expand All @@ -28,21 +30,41 @@ const TimerForm = (props: TimerFormProps): JSX.Element => {
console.log("Magic mode enabled");

Check warning

Code scanning / ESLint

disallow the use of `console` Warning

Unexpected console statement.
};

useEffect(() => {
console.log("isLoaded", isLoaded);
}, [isLoaded]);
const inputValidation = (input: string): string | false => {
const parsedInput = parseInt(input);

if (parsedInput < 0) {
return "Please enter a positive number";
}

if (parsedInput > 999999999999) {
return "Please enter a number less than 999999999999";
}

return false;
};

return (
<TimerFormContainer isVisibile={debugMode} isLoaded={isLoaded}>
<form onSubmit={onSubmit}>
<input
onChange={(e): void => setValue(e.target.value)}
value={value}
type="number"
placeholder="Enter something"
/>

<button type="submit">Submit</button>
<StyledRowDiv>
<ValidationInput
type="number"
id="custom-timer"
placeholder="Enter a custom timer duration"
value={value}
validationText={inputValidation(value)}
onChange={(e): void => setValue(e.target.value)}
onKeyDown={(): void => {}}
/>

<StyledButton
type="submit"
disabled={inputValidation(value) !== false}
>
Submit
</StyledButton>
</StyledRowDiv>
</form>
</TimerFormContainer>
);
Expand Down

0 comments on commit 7b90669

Please sign in to comment.