-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Mario-Duarte/feat/ui-development
Input size component
- Loading branch information
Showing
6 changed files
with
118 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import styled from "styled-components"; | ||
|
||
|
||
export const InputContainer = styled.div` | ||
position: relative; | ||
width: 100%; | ||
background-color: var(--box-bg-color); | ||
border-radius: 5px; | ||
padding: 20px 10px; | ||
margin-top: 10px; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
align-items: center; | ||
`; | ||
|
||
export const StyledInput = styled.input` | ||
background: none; | ||
appearance: none; | ||
color: var(--color-main-copy); | ||
border: none; | ||
width: 100%; | ||
text-align: center; | ||
font-size: 4rem; | ||
font-weight: 600; | ||
padding: 0; | ||
letter-spacing: 0; | ||
&:focus { | ||
outline: none; | ||
} | ||
`; | ||
|
||
export const Label = styled.label` | ||
color: var(--color-main-copy); | ||
margin-top: 5px; | ||
text-transform: uppercase; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { render, screen, fireEvent, cleanup } from '@testing-library/react'; | ||
import { InputSize } from './InputSize'; | ||
|
||
afterEach(cleanup); | ||
|
||
const setup = (onChange:(size:number) => void) => { | ||
const util = render(<InputSize value={16} onChange={onChange} />); | ||
const input = util.getByLabelText('convertSize') as HTMLInputElement; | ||
return { input, ...util } | ||
}; | ||
|
||
test('Renders DropDown selector', () => { | ||
const onChangeHandle = (size:number) => {} | ||
setup(onChangeHandle); | ||
|
||
expect(screen.getByLabelText('convertSize')).toBeInTheDocument(); | ||
}); | ||
|
||
test('Sets default value to number', () => { | ||
const onChangeHandle = (size:number) => {} | ||
const { input } = setup(onChangeHandle); | ||
|
||
fireEvent.change(input, {target: {value: '16'}}); | ||
|
||
expect(input.value).toBe("16"); | ||
}); | ||
|
||
test('On change function called', () => { | ||
const onChangeMock = jest | ||
.fn() | ||
.mockImplementation((size:number) => { return size }); | ||
|
||
const { input } = setup(onChangeMock); | ||
fireEvent.change(input, {target: {value: '32'}}); | ||
|
||
expect(onChangeMock).toHaveBeenCalledWith(32); | ||
expect(onChangeMock).toHaveBeenCalledTimes(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
InputContainer, | ||
StyledInput, | ||
Label | ||
} from './InputSize.styles'; | ||
|
||
export interface InputSizeProps { | ||
value: number; | ||
onChange: (size:number) => void; | ||
} | ||
|
||
export function InputSize({ | ||
value, | ||
onChange | ||
}:InputSizeProps) { | ||
|
||
const handleChange = (e:React.ChangeEvent<HTMLInputElement>) => { | ||
const size:number = +e.target.value; // the + will convert the input value from a string to a number | ||
onChange(size); | ||
} | ||
|
||
return( | ||
<InputContainer> | ||
<StyledInput aria-label='convertSize' type="number" step={1} value={value} min={1} onChange={handleChange} /> | ||
<Label>Convert</Label> | ||
</InputContainer> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { InputSize } from './InputSize'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters