12 changed files with 3443 additions and 2649 deletions
@ -1,13 +1,11 @@
|
||||
import AnimateModal from 'inferno-bootstrap/dist/Modal/AnimateModal'; |
||||
import Modal from 'inferno-bootstrap/dist/Modal/Modal'; |
||||
import ModalBody from 'inferno-bootstrap/dist/Modal/ModalBody'; |
||||
import ModalFooter from 'inferno-bootstrap/dist/Modal/ModalFooter'; |
||||
import ModalHeader from 'inferno-bootstrap/dist/Modal/ModalHeader'; |
||||
|
||||
export { |
||||
AnimateModal, |
||||
Modal, |
||||
ModalBody, |
||||
ModalFooter, |
||||
ModalHeader, |
||||
Modal, |
||||
ModalBody, |
||||
ModalFooter, |
||||
ModalHeader, |
||||
}; |
||||
|
@ -0,0 +1,60 @@
|
||||
import { linkEvent } from 'inferno'; |
||||
|
||||
function handleChange (props, event) { |
||||
const formElement = event.target.closest('form'); |
||||
const rawFormData = new FormData(formElement); |
||||
|
||||
if (props.onChange !== undefined) { |
||||
const modified = props.onChange(rawFormData); |
||||
|
||||
if (modified !== undefined) { |
||||
// Update form
|
||||
modified.forEach((value, key) => { |
||||
const element = formElement.elements[key]; |
||||
element.value = value; |
||||
}); |
||||
} |
||||
} |
||||
} |
||||
|
||||
function handleSubmit (props, event) { |
||||
// Don't want to actually reload the page!
|
||||
event.preventDefault(); |
||||
|
||||
// Parsers are formatters or maskers
|
||||
const parsers = {}; |
||||
|
||||
const form = event.target.closest('form'); |
||||
const data = new FormData(form); |
||||
|
||||
data.forEach((value, name) => { |
||||
const parserName = form.elements[name].dataset.parse; |
||||
|
||||
if (parserName !== undefined && parsers[parserName] !== undefined) { |
||||
const parser = parsers[parserName]; |
||||
const parsedValue = parser(data.get(name)); |
||||
data.set(name, parsedValue); |
||||
} |
||||
}); |
||||
|
||||
if (props.onSubmit) { |
||||
props.onSubmit(data); |
||||
} |
||||
} |
||||
|
||||
export function DOMForm (props) { |
||||
const passProps = {...props}; |
||||
const children = passProps.children; |
||||
delete passProps.onChange; |
||||
delete passProps.onSubmit; |
||||
|
||||
return ( |
||||
<form |
||||
onInput={linkEvent(props, handleChange)} |
||||
onSubmit={linkEvent(props, handleSubmit)} |
||||
{...passProps} |
||||
> |
||||
{children} |
||||
</form> |
||||
); |
||||
} |
@ -1,3 +1,4 @@
|
||||
export * from '//components/Bootstrap'; |
||||
export * from '//components/DOMForm'; |
||||
export * from '//components/Form'; |
||||
export * from '//components/Loader'; |
||||
|
Loading…
Reference in new issue