This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
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.
Run prettier on all files, added support for select and date
- Loading branch information
1 parent
9f957a9
commit ad75634
Showing
19 changed files
with
694 additions
and
413 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
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
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,61 @@ | ||
import React, { useContext } from "react"; | ||
import FormIdContext from "../context/FormIdContext"; | ||
import { connect } from "frontity"; | ||
|
||
/** | ||
* Select Dropdown. | ||
* | ||
* @param {Object} state Frontity state. | ||
* @param {Object} actions Actions. | ||
* @param {Object} inputProps Input props. | ||
* | ||
* @return {*} | ||
*/ | ||
const Select = ({ state, actions, inputProps }) => { | ||
// Context is used so that we can pass the form id to different components. | ||
const id = useContext(FormIdContext); | ||
const inputName = inputProps.name; | ||
|
||
if ("undefined" === typeof state.gf.forms[id].inputVals[inputName]) { | ||
actions.gf.changeInputValue({ | ||
id, | ||
inputName, | ||
value: inputProps.value, | ||
}); | ||
} | ||
|
||
/** | ||
* OnChange handler for input. | ||
* | ||
* @param {Object} event Event. | ||
* | ||
* @return {void} | ||
*/ | ||
const onChange = (event) => { | ||
actions.gf.changeInputValue({ | ||
id, | ||
inputName, | ||
value: event.target.value, | ||
}); | ||
}; | ||
|
||
return ( | ||
<select | ||
name={inputProps.name} | ||
className={inputProps.className} | ||
id={inputProps.id} | ||
aria-invalid={inputProps.ariaInvalid} | ||
aria-required={inputProps.ariaRequired} | ||
onChange={onChange} | ||
value={state.gf.forms[id].inputVals[inputName]} | ||
> | ||
{inputProps.options.map((item, index) => ( | ||
<option key={index} value={item.value}> | ||
{item.label} | ||
</option> | ||
))} | ||
</select> | ||
); | ||
}; | ||
|
||
export default connect(Select); |
Oops, something went wrong.