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

feat(animation): add framer motion to layer-selector #273

Merged
merged 7 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
99 changes: 97 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@types/react-router-dom": "^5.1.3",
"@types/redux-logger": "^3.0.7",
"cesium": "^1.66.0",
"framer-motion": "^1.8.4",
"lodash.debounce": "^4.0.8",
"react": "^16.12.0",
"react-dom": "^16.12.0",
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/components/app/app.styl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@require '../../../variables.styl'

:global(html), :global(body), :global(#app)
overflow: hidden
margin: 0
height: 100%

.app
position: relative
overflow: hidden
width: 100%
height: 100%
background-color: $black
Expand Down
13 changes: 3 additions & 10 deletions src/scripts/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {HashRouter as Router} from 'react-router-dom';

import rootReducer from '../../reducers/index';
import {languageSelector} from '../../selectors/language';
import {showLayerSelector} from '../../selectors/show-layer-selector';
import UrlSync from '../url-sync/url-sync';
import LayerLoader from '../layer-loader/layer-loader';
import Init from '../init/init';
Expand All @@ -34,7 +33,6 @@ const App: FunctionComponent = () => (

const TranslatedApp: FunctionComponent = () => {
const language = useSelector(languageSelector);
const layerSelector = useSelector(showLayerSelector);

return (
<Router>
Expand All @@ -43,14 +41,9 @@ const TranslatedApp: FunctionComponent = () => {
<div className={styles.logo}>
<EsaLogo />
</div>
{layerSelector ? (
<LayerSelector />
) : (
<React.Fragment>
<Navigation />
<GlobeZoom />
</React.Fragment>
)}
<Navigation />
<GlobeZoom />
<LayerSelector />
</div>
</IntlProvider>
<UrlSync />
Expand Down
7 changes: 5 additions & 2 deletions src/scripts/components/layer-selector/layer-selector.styl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
position: absolute
top: 0
right: 0
display: flex
flex-direction: column
min-width: emCalc(300px)
max-width: emCalc(500px)
width: 33%
height: 100%
background-color: $darkGrey2

.content
display: flex
flex-direction: column
height: 100%

.header
display: flex
justify-content: space-between
Expand Down
78 changes: 47 additions & 31 deletions src/scripts/components/layer-selector/layer-selector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, {FunctionComponent, useState} from 'react';
import {useDispatch, useSelector} from 'react-redux';
import {FormattedMessage} from 'react-intl';
import {motion, AnimatePresence} from 'framer-motion';
import {showLayerSelector} from '../../selectors/show-layer-selector';

import Button from '../button/button';
import {CloseIcon} from '../icons/close-icon';
Expand All @@ -14,6 +16,7 @@ import styles from './layer-selector.styl';
const LayerSelector: FunctionComponent = () => {
const dispatch = useDispatch();
const layers = useSelector(layersSelector);
const layerSelector = useSelector(showLayerSelector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showLayerSelector would be a better name

const [selectedMainId, setSelectedMainId] = useState<string | null>('clouds');
const [selectedCompareId, setSelectedCompareId] = useState<string | null>();
const selectedIds = [selectedMainId, selectedCompareId].filter(
Expand All @@ -25,37 +28,50 @@ const LayerSelector: FunctionComponent = () => {
);

return (
<div className={styles.layerSelector}>
<div className={styles.header}>
<h1 className={styles.title}>
<FormattedMessage id={'layers'} />
</h1>
<Button
className={styles.button}
icon={CloseIcon}
onClick={() => dispatch(showLayerSelectorAction(false))}
/>
</div>
{selectedMainLayer && (
<SelectedLayerListItem
layer={selectedMainLayer}
onRemove={() => setSelectedMainId(null)}
/>
)}
{selectedCompareLayer && (
<SelectedLayerListItem
showRemoveButton
layer={selectedCompareLayer}
onRemove={() => setSelectedCompareId(null)}
/>
)}
<LayerList
layers={layers}
selectedIds={selectedIds}
onMainSelect={layerId => setSelectedMainId(layerId)}
onCompareSelect={layerId => setSelectedCompareId(layerId)}
/>
</div>
<AnimatePresence>
{layerSelector ? (
<motion.div
className={styles.layerSelector}
initial={{x: '100%'}}
animate={{x: 0}}
transition={{type: 'spring', damping: 300, ease: 'easeOut'}}
exit={{x: '100%'}}>
<div className={styles.content}>
<div className={styles.header}>
<h1 className={styles.title}>
<FormattedMessage id={'layers'} />
</h1>
<Button
className={styles.button}
icon={CloseIcon}
onClick={() => {
dispatch(showLayerSelectorAction(false));
}}
/>
</div>
{selectedMainLayer && (
<SelectedLayerListItem
layer={selectedMainLayer}
onRemove={() => setSelectedMainId(null)}
/>
)}
{selectedCompareLayer && (
<SelectedLayerListItem
showRemoveButton
layer={selectedCompareLayer}
onRemove={() => setSelectedCompareId(null)}
/>
)}
<LayerList
layers={layers}
selectedIds={selectedIds}
onMainSelect={layerId => setSelectedMainId(layerId)}
onCompareSelect={layerId => setSelectedCompareId(layerId)}
/>
</div>
</motion.div>
) : null}
</AnimatePresence>
);
};

Expand Down
11 changes: 10 additions & 1 deletion src/scripts/components/navigation/navigation.styl
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
@require '../../../variables.styl'

@font-face
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only needed once

font-style: normal
font-family: NotesEsa
src: url('../../../fonts/NotesEsaReg.otf')

.navigation
position: absolute
top: emCalc(22px)
right: emCalc(22px)
display: flex

.button
&:not(:first-child)
font-size: emCalc(18px)
font-family: NotesEsa
line-height: emCalc(22px)

.button, &:not(:first-child)
padding-left: emCalc(30px)