Skip to content

Commit

Permalink
🏷️ [#445] Convert FormDisplay and AppDisplay components to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Mar 3, 2025
1 parent ce3dc98 commit 7ab6f23
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const FormContext = React.createContext({
submissionAllowed: 'yes',
sendConfirmationEmail: true,
submissionStatementsConfiguration: [],
translationEnabled: false,
literals: {
beginText: {value: '', resolved: 'Begin'},
changeText: {value: '', resolved: 'Change'},
Expand Down
43 changes: 27 additions & 16 deletions src/components/AppDisplay.jsx → src/components/AppDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import classNames from 'classnames';
import PropTypes from 'prop-types';

export interface AppDisplayProps {
/**
* Main content
*/
children: React.ReactNode;
/**
* UI to change languages.
*/
languageSwitcher?: React.ReactNode;
/**
* UI to display progression through the form steps.
*/
progressIndicator?: React.ReactNode;
/**
* Element to display debug information.
*/
appDebug?: React.ReactNode;
/**
* Main content.
*
* @deprecated Use children instead.
*
*/
router?: React.ReactNode;
}

/**
* Main application display component - this is the layout wrapper around content.
Expand All @@ -8,7 +33,7 @@ import PropTypes from 'prop-types';
* is reserved for the main content.
*
*/
export const AppDisplay = ({
export const AppDisplay: React.FC<AppDisplayProps> = ({
children = null,
languageSwitcher = null,
progressIndicator = null,
Expand All @@ -30,18 +55,4 @@ export const AppDisplay = ({
</div>
);

AppDisplay.propTypes = {
children: PropTypes.node.isRequired,
languageSwitcher: PropTypes.node,
progressIndicator: PropTypes.node,
appDebug: PropTypes.node,
/**
* Main content.
*
* @deprecated Use children instead.
*
*/
router: PropTypes.node,
};

export default AppDisplay;
36 changes: 17 additions & 19 deletions src/components/FormDisplay.jsx → src/components/FormDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types';
import {useContext} from 'react';

import {ConfigContext} from 'Context';
Expand All @@ -7,15 +6,29 @@ import {AppDisplay} from 'components/AppDisplay';
import LanguageSwitcher from 'components/LanguageSwitcher';
import useFormContext from 'hooks/useFormContext';

export interface FormDisplayProps {
/**
* Main content.
*/
children?: React.ReactNode;
progressIndicator?: React.ReactNode;
/**
* @deprecated
*/
router?: React.ReactNode;
}

/**
* Layout component to render the form container.
*
* Takes in the main body and (optional) progress indicator and forwards them to the
* AppDisplay component, while adding in any global/skeleton nodes.
*
* @return {JSX}
*/
const FormDisplay = ({children = null, progressIndicator = null, router = null}) => {
const FormDisplay: React.FC<FormDisplayProps> = ({
children = null,
progressIndicator = null,
router = null,
}) => {
const {translationEnabled} = useFormContext();
const config = useContext(ConfigContext);

Expand All @@ -33,19 +46,4 @@ const FormDisplay = ({children = null, progressIndicator = null, router = null})
);
};

FormDisplay.propTypes = {
/**
* Main content.
*/
children: PropTypes.node,
progressIndicator: PropTypes.node,
/**
* Main content.
*
* @deprecated Use children instead.
*
*/
router: PropTypes.node,
};

export default FormDisplay;

0 comments on commit 7ab6f23

Please sign in to comment.