Skip to content

Commit

Permalink
Replace Material UI styling with CSS (#9503)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasEng authored Jan 4, 2023
1 parent 480323c commit f7a1bc5
Show file tree
Hide file tree
Showing 79 changed files with 1,270 additions and 1,846 deletions.
10 changes: 9 additions & 1 deletion frontend/app-development/App.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.container {
--header-height: 111px;
--toolbar-height: 55px;
--header-border-bottom-width: 1px;
--header-height: calc(var(--toolbar-height) * 2 + var(--header-border-bottom-width));
--left-menu-width: 68px;

background-color: lightgray;
Expand All @@ -9,6 +11,12 @@
flex-direction: column;
}

@media screen and (max-width: 600px) {
.container {
--header-height: calc(var(--toolbar-height) + var(--header-border-bottom-width));
}
}

.contentWrapper {
height: calc(100vh - var(--header-height));
display: flex;
Expand Down
54 changes: 24 additions & 30 deletions frontend/app-development/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React, { useCallback, useEffect, useRef } from 'react';
import { createTheme, ThemeProvider } from '@mui/material';
import altinnTheme from 'app-shared/theme/altinnStudioTheme';
import postMessages from 'app-shared/utils/postMessages';
import AltinnPopoverSimple from 'app-shared/components/molecules/AltinnPopoverSimple';
import { getLanguageFromKey } from 'app-shared/utils/language';
Expand Down Expand Up @@ -34,8 +32,6 @@ import {
serviceNamePath,
} from 'app-shared/api-paths';

const theme = createTheme(altinnTheme);

const GetRepoStatusSelector = makeGetRepoStatusSelector();
const TEN_MINUTES_IN_MILLISECONDS = 600000;

Expand Down Expand Up @@ -152,31 +148,29 @@ export function App() {
);

return (
<ThemeProvider theme={theme}>
<div className={classes.container} ref={sessionExpiredPopoverRef}>
<AltinnPopoverSimple
testId='logout-warning'
anchorEl={sessionExpiredPopoverRef.current}
open={remainingSessionMinutes < 11}
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
transformOrigin={{ vertical: 'top', horizontal: 'center' }}
handleClose={(event: string) => handleSessionExpiresClose(event)}
btnCancelText={t('general.sign_out')}
btnConfirmText={t('general.continue')}
btnClick={handleSessionExpiresClose}
paperProps={{ style: { margin: '2.4rem' } }}
>
<h2>{t('session.expires')}</h2>
<p style={{ marginTop: '1.6rem' }}>{t('session.inactive')}</p>
</AltinnPopoverSimple>
<PageHeader repoStatus={repoStatus} />
<LeftMenu
className={classes.contentWrapper}
language={language}
repoStatus={repoStatus}
subAppClassName={repoStatus.hasMergeConflict ? classes.mergeConflictApp : classes.subApp}
/>
</div>
</ThemeProvider>
<div className={classes.container} ref={sessionExpiredPopoverRef}>
<AltinnPopoverSimple
testId='logout-warning'
anchorEl={sessionExpiredPopoverRef.current}
open={remainingSessionMinutes < 11}
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
transformOrigin={{ vertical: 'top', horizontal: 'center' }}
handleClose={(event: string) => handleSessionExpiresClose(event)}
btnCancelText={t('general.sign_out')}
btnConfirmText={t('general.continue')}
btnClick={handleSessionExpiresClose}
paperProps={{ style: { margin: '2.4rem' } }}
>
<h2>{t('session.expires')}</h2>
<p style={{ marginTop: '1.6rem' }}>{t('session.inactive')}</p>
</AltinnPopoverSimple>
<PageHeader repoStatus={repoStatus} />
<LeftMenu
className={classes.contentWrapper}
language={language}
repoStatus={repoStatus}
subAppClassName={repoStatus.hasMergeConflict ? classes.mergeConflictApp : classes.subApp}
/>
</div>
);
}
1 change: 1 addition & 0 deletions frontend/app-development/common/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import type { AppDispatch, RootState } from '../../store';
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
export { getOrgApp } from './getOrgApp';
export { useMediaQuery } from './useMediaQuery';
57 changes: 57 additions & 0 deletions frontend/app-development/common/hooks/useMediaQuery.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { renderHook } from '@testing-library/react';

import { useMediaQuery } from './useMediaQuery';

// Test data:
const query = '(min-width: 600px)';

describe('useMediaQuery', () => {
afterEach(() => jest.resetAllMocks());

it.each([true, false])(
'Returns value from window.matchMedia.matches when it is %s',
(matches) => {
const matchMediaValue = matchMediaValueMock({ matches });
const { result } = renderHook(() => useMediaQuery(query));
expect(matchMediaValue).toHaveBeenCalledWith(query);
expect(result.current).toBe(matches);
},
);

it('Adds event listener', () => {
const addEventListener = jest.fn();
matchMediaValueMock({ addEventListener });
renderHook(() => useMediaQuery(query));
expect(addEventListener).toHaveBeenCalledTimes(1);
});

it('Removes the event listener on unmount', () => {
const removeEventListener = jest.fn();
matchMediaValueMock({ removeEventListener });
const { unmount } = renderHook(() => useMediaQuery(query));
expect(removeEventListener).not.toHaveBeenCalled();
unmount();
expect(removeEventListener).toHaveBeenCalledTimes(1);
});
});

const matchMediaValueMock = ({
matches,
addEventListener,
removeEventListener,
}: Partial<{
matches: boolean;
addEventListener: jest.Mock;
removeEventListener: jest.Mock;
}>) => {
const value = jest.fn().mockImplementation((query) => ({
matches: matches ?? false,
media: query,
onchange: null,
addEventListener: addEventListener ?? jest.fn(),
removeEventListener: removeEventListener ?? jest.fn(),
dispatchEvent: jest.fn(),
}));
Object.defineProperty(window, 'matchMedia', { writable: true, value });
return value;
};
21 changes: 21 additions & 0 deletions frontend/app-development/common/hooks/useMediaQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useEffect, useState } from 'react';

export function useMediaQuery(query: string): boolean {
const getMatches = (query: string): boolean =>
window?.matchMedia(query).matches ?? false;

const [matches, setMatches] = useState<boolean>(getMatches(query));

const eventListener = () => {
setMatches(getMatches(query));
};

useEffect(() => {
const matchMedia = window.matchMedia(query);
eventListener();
matchMedia.addEventListener('change', eventListener);
return () => matchMedia.removeEventListener('change', eventListener);
}, [query]); // eslint-disable-line react-hooks/exhaustive-deps

return matches;
}
2 changes: 1 addition & 1 deletion frontend/app-development/config/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Administration } from '../features/administration/components/Administra
import { TextEditor } from '../features/textEditor';
import DeployPage from '../features/appPublish/pages/deployPage';
import HandleMergeConflictContainerComponent from '../features/handleMergeConflict/HandleMergeConflictContainer';
import { IFrame } from '../features/iFrame/iFrameComponent';
import { IFrame } from '../features/iFrame/IFrameComponent';
import DataModellingContainer from '../features/dataModelling/containers/DataModellingContainer';
import { TopBarMenu } from '../layout/AppBar/appBarConfig';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.mainContainer {
height: fit-content;
}

.headingContainer {
border-bottom: 2px solid #C9C9C9;
border-top: 2px solid #000000;
margin-bottom: 3.6rem;
margin-top: 2rem;
padding: 2rem 5rem;
width: 100%;
}

.dropdownGrid {
padding-bottom: 5rem;
padding-left: 5rem;
padding-right: 6rem;
}

.select {
max-width: 34rem;
z-index: 900;
}

.gridItem {
padding-right: 2rem;
}

.gridBorder {
border: 1px solid black;
}

.gridEnvTitle {
max-width: 22.5rem;
padding-right: 0.5rem;
}

.envTitle {
font-size: 18px;
font-weight: 500;
}

.table {
background-color: #ffffff;
min-width: 30rem;
}

.colorBlack {
color: #000;
}

.tableRow {
height: 2.6rem;
}

.tableWrapper {
max-height: 350px;
overflow: auto;
}

.deployButton {
margin-top: 2.6rem;
}

.deployStatusGridContainer {
margin-top: 2.6rem;
}

.deploySpinnerGridItem {
min-width: 4.4rem;
}

.deploymentListGrid {
padding-left: 4.8rem;
}

.deployUnavailableContainer {
background-color: #F9CAD3;
padding: 1.2rem;
}

.paperProps {
background-color: #F9CAD3;
}

.typographyTekniskFeilkode {
padding-top: 1.2rem;
}
Loading

0 comments on commit f7a1bc5

Please sign in to comment.