Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the app/progress indicator markup and styling #603

Merged
merged 21 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
528b673
:pencil: [#36] Add story for large form progress indicator on mobile
sergei-maertens Nov 24, 2023
a6a83a6
:recycle: [#36] Refactor container app/form components
sergei-maertens Nov 23, 2023
c27cd60
:wheelchair: [#36] Use (hidden) caption as description for nav element
sergei-maertens Nov 24, 2023
10970de
:recycle: [#36] Reset markup and styles for progress indicator entirely
sergei-maertens Nov 24, 2023
157576e
:recycle: [#36] Refactor/parametrize card styles
sergei-maertens Nov 24, 2023
0bd512c
:recycle: [#36] Apply (base) styles for desktop
sergei-maertens Nov 24, 2023
84cab8a
:bug: [#36] Fix excluding steps mechanism
sergei-maertens Nov 24, 2023
c50126e
:iphone: [#36] Set up styling from scratch for mobile header
sergei-maertens Nov 24, 2023
3b31fbb
:recycle: [#36] Ensure that progress indicator is sticky on desktop
sergei-maertens Nov 24, 2023
e0ab43e
:recycle: [#36] Set up styling for scrollable progress indicator on m…
sergei-maertens Nov 24, 2023
c79d856
:recycle: [#36] Tweak spacing of language buttons
sergei-maertens Nov 27, 2023
751c233
:art: Properly clean up the localStorage globally
sergei-maertens Nov 27, 2023
58e1229
:recycle: [#36] Update/clean up design tokens
sergei-maertens Nov 27, 2023
9f96dc2
:pencil: [#36] Clean up FormDisplay usage and document upgrade instru…
sergei-maertens Nov 27, 2023
8bf751e
:recycle: [#36] Restore ability to set vertical space above main content
sergei-maertens Nov 27, 2023
bb3194d
:green_heart: [#36] Fix incorrect test
sergei-maertens Nov 27, 2023
cf27bea
:lipstick: [#36] Remove z-index
sergei-maertens Nov 27, 2023
4eac0e6
:ok_hand: [#36] PR feedback
sergei-maertens Nov 29, 2023
246f90b
:coffin: [#36] We no longer have a progress indicator display component
sergei-maertens Nov 29, 2023
1dbd964
:recycle: [#36] Fix the progress indicator overview/confirmation step…
sergei-maertens Nov 29, 2023
adc91c2
:arrow_up: [#36] Upgrade to design tokens 0.51.0
sergei-maertens Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .storybook/decorators.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,29 @@ export const withClearSessionStorage = Story => {
return <Story />;
};

/**
* Submission ID is persisted in the localStorage once a submission is started, and we
* need to clear it for stories.
*
* The storage key is the form UUID, the default from api-mocks/form is
* 'e450890a-4166-410e-8d64-0a54ad30ba01'. You can specify another key via parameters
* or args.
*/
export const withClearSubmissionLocalStorage = (Story, {args, parameters}) => {
const formId =
args?.formId ?? parameters?.localStorage?.formId ?? 'e450890a-4166-410e-8d64-0a54ad30ba01';
window.localStorage.removeItem(formId);
return <Story />;
};

/**
* This decorator wraps stories so that they are inside a container with the class name "utrecht-document". This is
* needed so that components inherit the right font.
*/
export const utrechtDocumentDecorator = Story => {
return (<div className="utrecht-document utrecht-document--surface" ><Story/></div>);
return (
<div className="utrecht-document utrecht-document--surface">
<Story />
</div>
);
};
13 changes: 11 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import 'styles.scss';
import OpenFormsModule from 'formio/module';
import OFLibrary from 'formio/templates';

import {utrechtDocumentDecorator, withClearSessionStorage} from './decorators';
import {
utrechtDocumentDecorator,
withClearSessionStorage,
withClearSubmissionLocalStorage,
} from './decorators';
import {reactIntl} from './reactIntl.js';

initialize({
Expand All @@ -35,7 +39,12 @@ Formio.use(OpenFormsModule);
Templates.current = OFLibrary;

export default {
decorators: [mswDecorator, withClearSessionStorage, utrechtDocumentDecorator],
decorators: [
mswDecorator,
withClearSessionStorage,
withClearSubmissionLocalStorage,
utrechtDocumentDecorator,
],
globals: {
locale: reactIntl.defaultLocale,
locales: {
Expand Down
4 changes: 3 additions & 1 deletion src/Context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';

import {DEBUG} from 'utils';

const FormContext = React.createContext({
uuid: '',
name: '',
Expand Down Expand Up @@ -29,10 +31,10 @@ const ConfigContext = React.createContext({
requiredFieldsWithAsterisk: true,
displayComponents: {
app: null,
form: null,
progressIndicator: null,
loginOptions: null,
},
debug: DEBUG,
});
ConfigContext.displayName = 'ConfigContext';

Expand Down
38 changes: 4 additions & 34 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import PropTypes from 'prop-types';
import React, {useContext} from 'react';
import ReactDOM from 'react-dom';
import React from 'react';
import {Navigate, Outlet, useMatch} from 'react-router-dom';

import {ConfigContext} from 'Context';
import AppDebug from 'components/AppDebug';
import {Cosign} from 'components/CoSign';
import Form from 'components/Form';
import LanguageSelection from 'components/LanguageSelection';
import {
CreateAppointment,
appointmentRoutes,
Expand All @@ -16,10 +11,6 @@ import {
import useFormContext from 'hooks/useFormContext';
import useQuery from 'hooks/useQuery';
import useZodErrorMap from 'hooks/useZodErrorMap';
import {I18NContext} from 'i18n';
import {DEBUG} from 'utils';

import AppDisplay from './AppDisplay';

export const routes = [
{
Expand All @@ -42,30 +33,18 @@ export const routes = [
},
];

const LanguageSwitcher = () => {
const {languageSelectorTarget: target} = useContext(I18NContext);
return target ? ReactDOM.createPortal(<LanguageSelection />, target) : <LanguageSelection />;
};

/*
Top level router - routing between an actual form or supporting screens.
*/
const App = ({noDebug = false}) => {
const App = () => {
const form = useFormContext();
const query = useQuery();
const config = useContext(ConfigContext);
const appointmentMatch = useMatch('afspraak-maken/*');
const appointmentCancelMatch = useMatch('afspraak-annuleren/*');

// register localized error messages in the default zod error map
useZodErrorMap();

const AppDisplayComponent = config?.displayComponents?.app ?? AppDisplay;

const {translationEnabled} = form;
const languageSwitcher = translationEnabled ? <LanguageSwitcher /> : null;
const appDebug = DEBUG && !noDebug ? <AppDebug /> : null;

const isAppointment = form.appointmentOptions?.isAppointment ?? false;
if (isAppointment && !appointmentMatch && !appointmentCancelMatch) {
return (
Expand All @@ -78,18 +57,9 @@ const App = ({noDebug = false}) => {
/>
);
}

return (
<AppDisplayComponent
router={<Outlet />}
languageSwitcher={languageSwitcher}
appDebug={appDebug}
/>
);
return <Outlet />;
};

App.propTypes = {
noDebug: PropTypes.bool,
};
App.propTypes = {};

export default App;
Loading