Skip to content

Animations #115

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

Merged
merged 3 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions src/components/button/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
user-select: none;
}

.button {
transition: transform 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95);
}

.button:hover {
transform: scale(1.02);
}

.button:active {
transform: scale(0.95);
}

.icon {
height: 1.5rem;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/button/button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const ButtonComponent = ({
<span
className={classNames(
styles.outlinedButton,
styles.button,
className
)}
role="button"
Expand Down
10 changes: 10 additions & 0 deletions src/components/library-item/library-item.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@
border-radius: $space;
text-align: center;
cursor: pointer;
transition: transform 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95), border-color 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95);
}

.library-item:hover {
transform: scale(1.02);
}

.library-item:active {
transform: scale(0.98);
}

[theme="dark"] .library-item {
background: $ui-primary;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/library/library.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class LibraryComponent extends React.Component {
contentLabel={this.props.title}
id={this.props.id}
onRequestClose={this.handleClose}
kind={this.props.kind}
>
{/*
todo: translation support?
Expand Down
10 changes: 10 additions & 0 deletions src/components/menu/menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@
overflow: visible;
color: $ui-white;
box-shadow: 0 8px 8px 0 $ui-black-transparent-default;
transform-origin: top left;
opacity: 0;
transform: scale(0.6);
transition: opacity 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95), transform 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95);
}

.menu-visible {
opacity: 1;
transform: scale(1);
}

[theme="dark"] .menu {
background-color: $motion-primary-dark;
}
Expand Down
48 changes: 31 additions & 17 deletions src/components/menu/menu.jsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';

import React, {useState, useEffect, useRef} from 'react';
import styles from './menu.css';

const animIn = 0; // ms, you could add a delay but it doesn't feel right

const MenuComponent = ({
className = '',
children,
componentRef,
place = 'right'
}) => (
<ul
className={classNames(
styles.menu,
className,
{
[styles.left]: place === 'left',
[styles.right]: place === 'right'
}
)}
ref={componentRef}
>
{children}
</ul>
);
}) => {
const [visible, setVisible] = useState(false); // provides a clear way to check visibility
const waitOut = useRef(null);

useEffect(() => {
const waitIn = setTimeout(() => setVisible(true), animIn);
return () => {
clearTimeout(waitIn);
if (waitOut.current) clearTimeout(waitOut.current);
};
}, []);
return (
<ul
className={classNames(
styles.menu,
className,
{
[styles.left]: place === 'left',
[styles.right]: place === 'right',
[styles.menuVisible]: visible,
}
)}
ref={componentRef}
>
{children}
</ul>
)
};

MenuComponent.propTypes = {
children: PropTypes.node,
Expand Down
40 changes: 40 additions & 0 deletions src/components/modal/modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
bottom: 0;
z-index: $z-index-modal;
background-color: $ui-modal-overlay;
opacity: 0;
transition: opacity 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95);
}

.modal-overlay-visible {
opacity: 1;
}

.scrollable {
overflow: auto;
}
Expand All @@ -19,6 +26,39 @@
box-sizing: border-box;
}

.full-screen {
opacity: 0;
transform: scale(0);
transition: opacity 0.5s cubic-bezier(0.63, 0.32, 0.08, 0.95), transform 0.5s cubic-bezier(0.63, 0.32, 0.08, 0.95);
-webkit-perspective: 240px;
perspective: 240px;
}

.modal-container {
opacity: 0;
transform: scale(0.7) rotateX(-45deg);
transition: opacity 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95), transform 0.2s cubic-bezier(0.63, 0.32, 0.08, 0.95);
-webkit-perspective: 240px;
perspective: 240px;
max-width: max(60%, 750px);
width: max(60%, 750px);
}


.modal-fs-visible {
opacity: 1;
transform: scale(1) rotateX(0deg);
}

.modal-visible {
opacity: 1;
transform: scale(1) rotateX(0deg);
}

.ext-modal {
transform-origin: bottom left;
}

.modal-content {
margin: 100px auto;
outline: none;
Expand Down
181 changes: 108 additions & 73 deletions src/components/modal/modal.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import React, {useState, useEffect, useRef, useCallback} from 'react';
import ReactModal from 'react-modal';
import {FormattedMessage} from 'react-intl';

Expand All @@ -13,88 +13,123 @@ import helpIcon from '../../lib/assets/icon--help.svg';

import styles from './modal.css';

const ModalComponent = props => (
<ReactModal
isOpen
className={classNames(styles.modalContent, props.className, {
[styles.fullScreen]: props.fullScreen
})}
contentLabel={props.contentLabel}
overlayClassName={classNames(styles.modalOverlay, {
[styles.scrollable]: props.scrollable
})}
onRequestClose={props.onRequestClose}
>
<Box
dir={props.isRtl ? 'rtl' : 'ltr'}
direction="column"
grow={1}
const animOut = 200; // ms

const ModalComponent = props => {
const [visible, setVisible] = useState(false); // provides a clear way to check visibility
const waitOut = useRef(null);
const onReqCloseRef = useRef(props.onRequestClose);

useEffect(() => {
onReqCloseRef.current = props.onRequestClose;
}, [props.onRequestClose]);

useEffect(() => {
const waitIn = setTimeout(() => setVisible(true), 0); // you could add an "in" delay here but it just doesn't feel right
return () => {
clearTimeout(waitIn);
if (waitOut.current) clearTimeout(waitOut.current);
};
}, []);

const closeThisModal = useCallback(() => {
setVisible(false); // animate out
waitOut.current = setTimeout(() => {
if (onReqCloseRef.current) onReqCloseRef.current(); // close window after animating out
}, animOut);
}, []);

return (
<ReactModal
isOpen
className={classNames(
styles.modalContent,
props.className,
{
[styles.modalContainer]: !props.fullScreen,
[styles.fullScreen]: props.fullScreen,
[styles.modalFsVisible]: visible && props.fullScreen,
[styles.modalVisible]: visible && !props.fullScreen,
[styles.extModal]: props.kind == 'extension'
}
)}
contentLabel={props.contentLabel}
overlayClassName={classNames(styles.modalOverlay, {
[styles.scrollable]: props.scrollable,
[styles.modalOverlayVisible]: visible,
})}
>
<div className={classNames(styles.header, props.headerClassName)}>
{props.onHelp ? (
<Box
dir={props.isRtl ? 'rtl' : 'ltr'}
direction="column"
grow={1}
>
<div className={classNames(styles.header, props.headerClassName)}>
{props.onHelp ? (
<div
className={classNames(
styles.headerItem,
styles.headerItemHelp
)}
>
<Button
className={styles.helpButton}
iconSrc={helpIcon}
onClick={props.onHelp}
>
<FormattedMessage
defaultMessage="Help"
description="Help button in modal"
id="gui.modal.help"
/>
</Button>
</div>
) : null}
<div
className={classNames(
styles.headerItem,
styles.headerItemHelp
styles.headerItemTitle
)}
>
<Button
className={styles.helpButton}
iconSrc={helpIcon}
onClick={props.onHelp}
>
<FormattedMessage
defaultMessage="Help"
description="Help button in modal"
id="gui.modal.help"
{props.headerImage ? (
<img
className={styles.headerImage}
src={props.headerImage}
/>
</Button>
) : null}
{props.contentLabel}
</div>
) : null}
<div
className={classNames(
styles.headerItem,
styles.headerItemTitle
)}
>
{props.headerImage ? (
<img
className={styles.headerImage}
src={props.headerImage}
/>
) : null}
{props.contentLabel}
</div>
<div
className={classNames(
styles.headerItem,
styles.headerItemClose
)}
>
{props.fullScreen ? (
<Button
className={styles.backButton}
iconSrc={backIcon}
onClick={props.onRequestClose}
>
<FormattedMessage
defaultMessage="Back"
description="Back button in modal"
id="gui.modal.back"
<div
className={classNames(
styles.headerItem,
styles.headerItemClose
)}
>
{props.fullScreen ? (
<Button
className={styles.backButton}
iconSrc={backIcon}
onClick={closeThisModal}
>
<FormattedMessage
defaultMessage="Back"
description="Back button in modal"
id="gui.modal.back"
/>
</Button>
) : (
<CloseButton
size={CloseButton.SIZE_LARGE}
onClick={closeThisModal}
/>
</Button>
) : (
<CloseButton
size={CloseButton.SIZE_LARGE}
onClick={props.onRequestClose}
/>
)}
)}
</div>
</div>
</div>
{props.children}
</Box>
</ReactModal>
);
{props.children}
</Box>
</ReactModal>
)
};

ModalComponent.propTypes = {
children: PropTypes.node,
Expand Down
Loading