-
Notifications
You must be signed in to change notification settings - Fork 77
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 #1222 from facebookresearch/form-composer-instruct…
…ions-as-modal Accommodate lengthy task instructions in Form Composer
- Loading branch information
Showing
7 changed files
with
230 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
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
26 changes: 26 additions & 0 deletions
26
packages/react-form-composer/src/FormComposer/FormInstructionsButton.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,26 @@ | ||
/* | ||
* Copyright (c) Meta Platforms and its affiliates. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from "react"; | ||
|
||
export function FormInstructionsButton({ onClick }) { | ||
return ( | ||
// bootstrap classes: | ||
// - btn | ||
// - btn-primary | ||
// - btn-sm | ||
|
||
<button | ||
className={`form-instruction-button btn btn-primary btn-sm`} | ||
data-target={"#id-form-instruction-modal"} | ||
data-toggle={"modal"} | ||
onClick={onClick} | ||
type={"button"} | ||
> | ||
<span>ⓘ</span> Task Instructions | ||
</button> | ||
); | ||
} |
79 changes: 79 additions & 0 deletions
79
packages/react-form-composer/src/FormComposer/FormInstructionsModal.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,79 @@ | ||
/* | ||
* Copyright (c) Meta Platforms and its affiliates. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from "react"; | ||
|
||
export function FormInstructionsModal({ instructions, open, setOpen, title }) { | ||
const modalContentRef = React.useRef(null); | ||
|
||
const [modalContentTopPosition, setModalContentTopPosition] = React.useState( | ||
0 | ||
); | ||
|
||
function onScrollModalContent(e) { | ||
// Save scrolling position to restore it when we open this modal again | ||
setModalContentTopPosition(e.currentTarget.scrollTop); | ||
} | ||
|
||
React.useEffect(() => { | ||
if (open) { | ||
// Set saved scrolling position to continue reading from that place we stopped. | ||
// This is needed in case if instruction is too long, | ||
// and it is hard to start searching previous place again | ||
modalContentRef.current.scrollTo(0, modalContentTopPosition); | ||
} | ||
}, [open]); | ||
|
||
return ( | ||
// bootstrap classes: | ||
// - modal | ||
// - modal-dialog | ||
// - modal-dialog-scrollable | ||
// - modal-content | ||
// - modal-header | ||
// - modal-title | ||
// - close | ||
// - modal-body | ||
|
||
<div | ||
className={"form-instruction-modal modal"} | ||
id={"id-form-instruction-modal"} | ||
data-backdrop={"static"} | ||
data-keyboard={"false"} | ||
tabIndex={"-1"} | ||
aria-labelledby={"id-modal-title"} | ||
aria-hidden={"true"} | ||
> | ||
<div className={"modal-dialog modal-dialog-scrollable"}> | ||
<div className={"modal-content"}> | ||
<div className={"modal-header"}> | ||
<div className={"modal-title"} id={"id-modal-title"}> | ||
{title} | ||
</div> | ||
|
||
<button | ||
type={"button"} | ||
className={"close"} | ||
data-dismiss={"modal"} | ||
aria-label={"Close"} | ||
onClick={() => setOpen(false)} | ||
> | ||
<span aria-hidden={"true"}>×</span> | ||
</button> | ||
</div> | ||
|
||
<div | ||
className={"modal-body"} | ||
onScroll={onScrollModalContent} | ||
ref={modalContentRef} | ||
> | ||
{instructions} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |