-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert some components to functional components
- Loading branch information
Showing
11 changed files
with
87 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,28 @@ | ||
import { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useCallback } from 'react'; | ||
import { IIIFIFrameCommunication } from './IIIFIFrameCommunication'; | ||
/* eslint-disable react/prop-types */ | ||
|
||
/** | ||
* Opens a new window for click | ||
*/ | ||
export class AccessTokenSender extends Component { | ||
/** */ | ||
constructor(props) { | ||
super(props); | ||
export default function AccessTokenSender({ handleAccessTokenMessage, url }) { | ||
const onReceiveAccessTokenMessage = useCallback((e) => { | ||
if (e.data && e.data.messageId && e.data.messageId === url) { | ||
handleAccessTokenMessage(e.data); | ||
} | ||
}, [handleAccessTokenMessage, url]); | ||
|
||
this.onReceiveAccessTokenMessage = this.onReceiveAccessTokenMessage.bind(this); | ||
} | ||
if (!url) return null; | ||
|
||
/** @private */ | ||
onReceiveAccessTokenMessage(e) { | ||
const { handleAccessTokenMessage, url } = this.props; | ||
if (e.data && e.data.messageId && e.data.messageId === url) handleAccessTokenMessage(e.data); | ||
} | ||
|
||
/** */ | ||
render() { | ||
const { url } = this.props; | ||
if (!url) return null; | ||
|
||
/** | ||
login, clickthrough/kiosk open @id, wait for close | ||
external, no-op | ||
*/ | ||
return ( | ||
<IIIFIFrameCommunication | ||
src={`${url}?origin=${window.origin}&messageId=${url}`} | ||
title="AccessTokenSender" | ||
handleReceiveMessage={this.onReceiveAccessTokenMessage} | ||
/> | ||
); | ||
} | ||
/** | ||
login, clickthrough/kiosk open @id, wait for close | ||
external, no-op | ||
*/ | ||
return ( | ||
<IIIFIFrameCommunication | ||
src={`${url}?origin=${window.origin}&messageId=${url}`} | ||
title="AccessTokenSender" | ||
handleReceiveMessage={onReceiveAccessTokenMessage} | ||
/> | ||
); | ||
} | ||
|
||
AccessTokenSender.propTypes = { | ||
handleAccessTokenMessage: PropTypes.func.isRequired, | ||
url: PropTypes.string, | ||
}; | ||
|
||
AccessTokenSender.defaultProps = { | ||
url: undefined, | ||
}; |
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 |
---|---|---|
@@ -1,39 +1,26 @@ | ||
import { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import VisibilityIcon from '@mui/icons-material/VisibilitySharp'; | ||
import VisibilityOffIcon from '@mui/icons-material/VisibilityOffSharp'; | ||
import MiradorMenuButton from '../containers/MiradorMenuButton'; | ||
/* eslint-disable react/prop-types */ | ||
|
||
/** | ||
* AnnotationSettings is a component to handle various annotation | ||
* display settings in the Annotation companion window | ||
*/ | ||
export class AnnotationSettings extends Component { | ||
/** | ||
* Returns the rendered component | ||
*/ | ||
render() { | ||
const { | ||
displayAll, displayAllDisabled, t, toggleAnnotationDisplay, | ||
} = this.props; | ||
|
||
return ( | ||
<MiradorMenuButton | ||
aria-label={t(displayAll ? 'displayNoAnnotations' : 'highlightAllAnnotations')} | ||
onClick={toggleAnnotationDisplay} | ||
disabled={displayAllDisabled} | ||
size="small" | ||
> | ||
{ displayAll ? <VisibilityIcon /> : <VisibilityOffIcon /> } | ||
</MiradorMenuButton> | ||
); | ||
} | ||
*/ | ||
export default function AnnotationSettings({ | ||
displayAll, | ||
displayAllDisabled, | ||
t, | ||
toggleAnnotationDisplay, | ||
}) { | ||
return ( | ||
<MiradorMenuButton | ||
aria-label={t(displayAll ? 'displayNoAnnotations' : 'highlightAllAnnotations')} | ||
onClick={toggleAnnotationDisplay} | ||
disabled={displayAllDisabled} | ||
size="small" | ||
> | ||
{displayAll ? <VisibilityIcon /> : <VisibilityOffIcon />} | ||
</MiradorMenuButton> | ||
); | ||
} | ||
|
||
AnnotationSettings.propTypes = { | ||
displayAll: PropTypes.bool.isRequired, | ||
displayAllDisabled: PropTypes.bool.isRequired, | ||
t: PropTypes.func.isRequired, | ||
toggleAnnotationDisplay: PropTypes.func.isRequired, | ||
windowId: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types | ||
}; |
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 |
---|---|---|
@@ -1,56 +1,29 @@ | ||
import { | ||
createRef, Component, lazy, Suspense, | ||
createRef, lazy, Suspense, | ||
} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import PluginProvider from '../extend/PluginProvider'; | ||
import AppProviders from '../containers/AppProviders'; | ||
import WorkspaceContext from '../contexts/WorkspaceContext'; | ||
|
||
const WorkspaceArea = lazy(() => import('../containers/WorkspaceArea')); | ||
/* eslint-disable react/prop-types */ | ||
|
||
/** | ||
* This is the top level Mirador component. | ||
* @prop {Object} manifests | ||
*/ | ||
export class App extends Component { | ||
/** */ | ||
constructor(props) { | ||
super(props); | ||
|
||
this.areaRef = createRef(); | ||
} | ||
|
||
/** | ||
* render | ||
* @return {String} - HTML markup for the component | ||
*/ | ||
render() { | ||
const { dndManager, plugins } = this.props; | ||
|
||
return ( | ||
<PluginProvider plugins={plugins}> | ||
<AppProviders dndManager={dndManager}> | ||
<WorkspaceContext.Provider value={this.areaRef}> | ||
<Suspense | ||
fallback={<div />} | ||
> | ||
<WorkspaceArea areaRef={this.areaRef} /> | ||
</Suspense> | ||
</WorkspaceContext.Provider> | ||
</AppProviders> | ||
</PluginProvider> | ||
); | ||
} | ||
export default function App({ dndManager, plugins = [] }) { | ||
const areaRef = createRef(); | ||
|
||
return ( | ||
<PluginProvider plugins={plugins}> | ||
<AppProviders dndManager={dndManager}> | ||
<WorkspaceContext.Provider value={areaRef}> | ||
<Suspense fallback={<div />}> | ||
<WorkspaceArea areaRef={areaRef} /> | ||
</Suspense> | ||
</WorkspaceContext.Provider> | ||
</AppProviders> | ||
</PluginProvider> | ||
); | ||
} | ||
|
||
App.propTypes = { | ||
dndManager: PropTypes.object, // eslint-disable-line react/forbid-prop-types | ||
plugins: PropTypes.array, // eslint-disable-line react/forbid-prop-types | ||
}; | ||
|
||
App.defaultProps = { | ||
dndManager: undefined, | ||
plugins: [], | ||
}; | ||
|
||
export default App; |
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 |
---|---|---|
@@ -1,47 +1,37 @@ | ||
import { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import IconButton from '@mui/material/IconButton'; | ||
import Typography from '@mui/material/Typography'; | ||
import Stack from '@mui/material/Stack'; | ||
import MiradorIcon from './icons/MiradorIcon'; | ||
|
||
/* eslint-disable react/prop-types */ | ||
/** | ||
* Display a branding icon | ||
*/ | ||
export class Branding extends Component { | ||
/** */ | ||
render() { | ||
const { t, variant, ...ContainerProps } = this.props; | ||
|
||
return ( | ||
<Stack alignItems="center" {...ContainerProps}> | ||
{ variant === 'wide' && ( | ||
export default function Branding({ t = (k) => k, variant = 'default', ...ContainerProps }) { | ||
return ( | ||
<Stack alignItems="center" {...ContainerProps}> | ||
{variant === 'wide' && ( | ||
<div> | ||
<Typography align="center" component="p" variant="h3">{t('mirador')}</Typography> | ||
<Typography align="center" component="p" variant="h3"> | ||
{t('mirador')} | ||
</Typography> | ||
</div> | ||
)} | ||
<Typography align="center"> | ||
<IconButton | ||
component="a" | ||
href="https://projectmirador.org" | ||
target="_blank" | ||
rel="noopener" | ||
size="large" | ||
> | ||
<MiradorIcon aria-label={t('aboutMirador')} titleAccess={t('aboutMirador')} fontSize="large" /> | ||
</IconButton> | ||
</Typography> | ||
</Stack> | ||
); | ||
} | ||
)} | ||
<Typography align="center"> | ||
<IconButton | ||
component="a" | ||
href="https://projectmirador.org" | ||
target="_blank" | ||
rel="noopener" | ||
size="large" | ||
> | ||
<MiradorIcon | ||
aria-label={t('aboutMirador')} | ||
titleAccess={t('aboutMirador')} | ||
fontSize="large" | ||
/> | ||
</IconButton> | ||
</Typography> | ||
</Stack> | ||
); | ||
} | ||
|
||
Branding.propTypes = { | ||
t: PropTypes.func, | ||
variant: PropTypes.oneOf(['default', 'wide']), | ||
}; | ||
|
||
Branding.defaultProps = { | ||
t: k => k, | ||
variant: 'default', | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { withPlugins } from '../extend/withPlugins'; | ||
import { Branding } from '../components/Branding'; | ||
import Branding from '../components/Branding'; | ||
|
||
export default withPlugins('Branding')(Branding); |