-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
forgettable-frontend/src/components/InputSelector/InputSelector.js
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,53 @@ | ||
import React, {useEffect} from 'react'; | ||
import {useState} from 'react'; | ||
import styles from './InputSelector.module.css'; | ||
|
||
/** | ||
* React input selector component used for entry of data. | ||
* | ||
* The styling of the component is based on that of the "primary" InputField component. | ||
* | ||
* @author Bill Song | ||
*/ | ||
|
||
export default function InputField({inputLabel, placeholder, inputID, | ||
dataType, inputStateValue, autoFocusState, requiredState, options}) { | ||
/** | ||
* Retrieve state of input component to be rendered in a responsive manner. | ||
*/ | ||
const [inputState, setInput] = useState(inputStateValue); | ||
|
||
useEffect(() => { | ||
setInput(inputStateValue); | ||
}, [inputStateValue]); | ||
|
||
/** | ||
* process options into DOM elements | ||
*/ | ||
|
||
const optionElements = options.map((option) => { | ||
return <option key={option} value={option}>{option}</option>; | ||
}); | ||
|
||
/** | ||
* Types allowed for innput component styling. | ||
*/ | ||
|
||
return ( | ||
<div> | ||
<label className={styles.inputLabelPrimary}>{inputLabel} | ||
<select className={styles.inputFieldPrimary} | ||
type={dataType} | ||
name={inputID} | ||
placeholder = {placeholder} | ||
value={inputState} | ||
onChange={(event) => setInput(event.target.value)} | ||
autoFocus={autoFocusState} | ||
required={requiredState} | ||
> | ||
{optionElements} | ||
</select> | ||
</label> | ||
</div> | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
forgettable-frontend/src/components/InputSelector/InputSelector.module.css
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,24 @@ | ||
@import '../../colours.css'; | ||
|
||
.inputLabelPrimary { | ||
font-size: var(--text-medium); | ||
font-weight: var(--font-medium); | ||
text-align: left; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.inputFieldPrimary{ | ||
font-size: var(--text-normal); | ||
background-color: var(--bkgd); | ||
color: var(--txt2); | ||
width: 370px; | ||
height: 57px; | ||
border-radius: var(--radius-btn); | ||
border: 1.5px solid var(--bord); | ||
box-shadow: none; | ||
margin-top: 8px; | ||
padding: 10px; | ||
padding-left: 18px; | ||
font-family: 'Poppins', sans-serif; | ||
} |
18 changes: 18 additions & 0 deletions
18
forgettable-frontend/src/components/InputSelector/__tests__/InputSelector.test.js
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,18 @@ | ||
import React from 'react'; | ||
import InputSelector from '../InputSelector'; | ||
import {render, cleanup} from '@testing-library/react'; | ||
import testRenderer from 'react-test-renderer'; | ||
|
||
afterEach(cleanup); | ||
|
||
it('renders primary input field correctly', () => { | ||
const primaryInput = testRenderer.create( | ||
<InputSelector inputLabel={'SELECTOR'} | ||
placeholder={'SELECTOR TEXT'} | ||
dataType={'text'} | ||
inputID={'InputSelector'} | ||
options={['option1', 'option2', 'option3']} />).toJSON(); | ||
expect(primaryInput).toMatchSnapshot(); | ||
}); | ||
|
||
|
34 changes: 34 additions & 0 deletions
34
...-frontend/src/components/InputSelector/__tests__/__snapshots__/InputSelector.test.js.snap
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,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders primary input field correctly 1`] = ` | ||
<div> | ||
<label | ||
className="inputLabelPrimary" | ||
> | ||
SELECTOR | ||
<select | ||
className="inputFieldPrimary" | ||
name="InputSelector" | ||
onChange={[Function]} | ||
placeholder="SELECTOR TEXT" | ||
type="text" | ||
> | ||
<option | ||
value="option1" | ||
> | ||
option1 | ||
</option> | ||
<option | ||
value="option2" | ||
> | ||
option2 | ||
</option> | ||
<option | ||
value="option3" | ||
> | ||
option3 | ||
</option> | ||
</select> | ||
</label> | ||
</div> | ||
`; |
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