Skip to content

Commit

Permalink
feat(animation): add framer motion to layer-selector (#273)
Browse files Browse the repository at this point in the history
* feat(layer-selector): add new layer selector

* style(layer-selector): use emCalc

* refactor(layer-selector): change from span to button, rename

* refactor(styles): remove styles

* refactor(font): move @font-face to main stylus file

* refactor(layer-selector): rename variable
  • Loading branch information
KatvonRivia committed Mar 2, 2020
1 parent 9721ddc commit 1890f70
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 51 deletions.
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
7 changes: 7 additions & 0 deletions src/scripts/components/app/app.styl
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
@require '../../../variables.styl'

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

: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
12 changes: 5 additions & 7 deletions src/scripts/components/layer-selector/layer-selector.styl
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
@require '../../../variables.styl'

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

.layerSelector
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 as showLayerSelectorSelector} 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 showLayerSelector = useSelector(showLayerSelectorSelector);
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>
{showLayerSelector ? (
<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
6 changes: 5 additions & 1 deletion src/scripts/components/navigation/navigation.styl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
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)

0 comments on commit 1890f70

Please sign in to comment.