-
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.
modals, removed conditional as distinct entity
- Loading branch information
William Nadeau
committed
May 15, 2018
1 parent
c2eb91a
commit 3211e45
Showing
16 changed files
with
346 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as React from 'react'; | ||
|
||
const EditForm: React.StatelessComponent<{ | ||
header: string, | ||
onSave?: () => void, | ||
onCancel?: () => void | ||
}> = ({ header, children, onSave, onCancel }) => { | ||
|
||
return ( | ||
<div className="sheet-panel card p-4"> | ||
<h1>{header}</h1> | ||
<form className="form-inline"> | ||
{children} | ||
</form> | ||
<div> | ||
{onSave ? ( | ||
<button | ||
onClick={event => { event.preventDefault(); onSave(); }} | ||
className="btn btn-small btn-secondary d-inline float-right" | ||
>Cancel</button> | ||
) : null} | ||
{onCancel ? ( | ||
<button | ||
onClick={event => { event.preventDefault(); onCancel(); }} | ||
className="btn btn-small btn-primary d-inline float-right" | ||
>Save</button> | ||
) : null} | ||
</div> | ||
</div> | ||
); | ||
|
||
}; | ||
|
||
export default EditForm; |
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,44 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
|
||
const modalRoot = document.getElementById('modal-root')!; | ||
|
||
class Modal extends React.Component<{}> { | ||
modalElement: HTMLElement; | ||
modalRoot: HTMLElement; | ||
|
||
constructor(props: {}) { | ||
super(props); | ||
// Create a div that we'll render the modal into. Because each | ||
// Modal component has its own element, we can render multiple | ||
// modal components into the modal container. | ||
this.modalElement = document.createElement('div'); | ||
} | ||
|
||
componentDidMount() { | ||
// Append the element into the DOM on mount. We'll render | ||
// into the modal container element (see the HTML tab). | ||
modalRoot.appendChild(this.modalElement); | ||
} | ||
|
||
componentWillUnmount() { | ||
// Remove the element from the DOM when we unmount | ||
modalRoot.removeChild(this.modalElement); | ||
} | ||
|
||
render() { | ||
// Use a portal to render the children into the element | ||
return ReactDOM.createPortal( | ||
// Any valid React child: JSX, strings, arrays, etc. | ||
( | ||
<div className="modal"> | ||
{this.props.children} | ||
</div> | ||
), | ||
// A DOM element | ||
this.modalElement, | ||
); | ||
} | ||
} | ||
|
||
export default Modal; |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.