forked from aehrc/smart-forms
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add FormBodyPage Renderer Component * Rename tab to page on utils/page * Add storybook story for FormBodyPage Renderer Component * Add pages and currentPageIndex to questionnarieStore * Add next and previous button for Page * Modify Page utils * Make Page rendering logic on Top Level Renderer to help render * Upgrade smart-forms-renderer packages version * Change Page Next and Previous Button Design * Add Custom Styled Fab for Page Button
- Loading branch information
Showing
22 changed files
with
680 additions
and
8 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
10 changes: 10 additions & 0 deletions
10
packages/smart-forms-renderer/src/components/FormComponents/Button.styles.ts
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,10 @@ | ||
import { styled } from '@mui/material/styles'; | ||
import Fab from '@mui/material/Fab'; | ||
|
||
export const StandardFab = styled(Fab)(({ theme }) => ({ | ||
color: theme.palette.customButton.foreground, | ||
background: theme.palette.customButton.background, | ||
'&:hover': { | ||
background: theme.palette.customButton.backgroundHover | ||
} | ||
})); |
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
37 changes: 37 additions & 0 deletions
37
packages/smart-forms-renderer/src/components/FormComponents/GroupItem/NextPageButton.tsx
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,37 @@ | ||
/* | ||
* Copyright 2024 Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import Iconify from '../../Iconify/Iconify'; | ||
import { StandardFab } from '../Button.styles'; | ||
|
||
interface NextPageButtonProps { | ||
isDisabled: boolean; | ||
onNextPageClick: () => void; | ||
} | ||
|
||
function NextPageButton(props: NextPageButtonProps) { | ||
const { isDisabled, onNextPageClick } = props; | ||
|
||
return ( | ||
<StandardFab size="small" aria-label="next" disabled={isDisabled} onClick={onNextPageClick}> | ||
<Iconify icon="material-symbols:chevron-right-rounded" /> | ||
</StandardFab> | ||
); | ||
} | ||
|
||
export default NextPageButton; |
78 changes: 78 additions & 0 deletions
78
packages/smart-forms-renderer/src/components/FormComponents/GroupItem/PageButtonWrapper.tsx
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,78 @@ | ||
import React, { memo } from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import type { Pages } from '../../../interfaces/page.interface'; | ||
import { useQuestionnaireStore } from '../../../stores'; | ||
import NextPageButton from './NextPageButton'; | ||
import PreviousPageButton from './PreviousPageButton'; | ||
import useNextAndPreviousVisiblePages from '../../../hooks/useNextAndPreviousVisiblePages'; | ||
|
||
interface PageButtonsWrapperProps { | ||
currentPageIndex?: number; | ||
pages?: Pages; | ||
} | ||
|
||
const PageButtonsWrapper = memo(function PageButtonsWrapper(props: PageButtonsWrapperProps) { | ||
const { currentPageIndex, pages } = props; | ||
|
||
const switchPage = useQuestionnaireStore.use.switchPage(); | ||
|
||
const { previousPageIndex, nextPageIndex, numOfVisiblePages } = useNextAndPreviousVisiblePages( | ||
currentPageIndex, | ||
pages | ||
); | ||
|
||
const pagesNotDefined = currentPageIndex === undefined || pages === undefined; | ||
|
||
// Event handlers | ||
function handlePreviousPageButtonClick() { | ||
if (previousPageIndex === null) { | ||
return; | ||
} | ||
|
||
switchPage(previousPageIndex); | ||
|
||
// Scroll to top of page | ||
window.scrollTo(0, 0); | ||
} | ||
|
||
function handleNextPageButtonClick() { | ||
if (nextPageIndex === null) { | ||
return; | ||
} | ||
|
||
switchPage(nextPageIndex); | ||
|
||
// Scroll to top of page | ||
window.scrollTo(0, 0); | ||
} | ||
|
||
if (pagesNotDefined) { | ||
return null; | ||
} | ||
|
||
const previousPageButtonHidden = previousPageIndex === null; | ||
const nextPageButtonHidden = nextPageIndex === null; | ||
|
||
// This is more of a fallback check to prevent the user from navigating to an invisble page if buttons are visble for some reason | ||
const pageButtonsDisabled = numOfVisiblePages <= 1; | ||
|
||
return ( | ||
<Box display="flex" mt={3}> | ||
{previousPageButtonHidden ? null : ( | ||
<PreviousPageButton | ||
isDisabled={pageButtonsDisabled} | ||
onPreviousPageClick={handlePreviousPageButtonClick} | ||
/> | ||
)} | ||
<Box flexGrow={1} /> | ||
{nextPageButtonHidden ? null : ( | ||
<NextPageButton | ||
isDisabled={pageButtonsDisabled} | ||
onNextPageClick={handleNextPageButtonClick} | ||
/> | ||
)} | ||
</Box> | ||
); | ||
}); | ||
|
||
export default PageButtonsWrapper; |
37 changes: 37 additions & 0 deletions
37
packages/smart-forms-renderer/src/components/FormComponents/GroupItem/PreviousPageButton.tsx
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,37 @@ | ||
/* | ||
* Copyright 2024 Commonwealth Scientific and Industrial Research | ||
* Organisation (CSIRO) ABN 41 687 119 230. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import Iconify from '../../Iconify/Iconify'; | ||
import { StandardFab } from '../Button.styles'; | ||
|
||
interface PreviousPageButtonProps { | ||
isDisabled: boolean; | ||
onPreviousPageClick: () => void; | ||
} | ||
|
||
function PreviousPageButton(props: PreviousPageButtonProps) { | ||
const { isDisabled, onPreviousPageClick } = props; | ||
|
||
return ( | ||
<StandardFab size="small" aria-label="back" disabled={isDisabled} onClick={onPreviousPageClick}> | ||
<Iconify icon="material-symbols:chevron-left-rounded" /> | ||
</StandardFab> | ||
); | ||
} | ||
|
||
export default PreviousPageButton; |
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.