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

Animated service submenu #96

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 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
22 changes: 22 additions & 0 deletions assets/_globalCss.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,25 @@ input[type='password'][disabled] {
cursor: not-allowed;
border-color: var(--color-disabled);
}

.my-node-enter {
opacity: 0;
transform: translateY(-5%);
}

.my-node-enter-active {
opacity: 1;
transition: all 300ms ease-in-out;
transform: translateY(0);
}

.my-node-exit {
opacity: 1;
transform: translateY(0);
}

.my-node-exit-active {
opacity: 0;
transition: all 300ms ease-in-out;
transform: translateY(-5%);
}
81 changes: 46 additions & 35 deletions components/UI/ServiceSubmenu.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { cloneElement, useState } from 'react';
import React, { cloneElement, useRef, useState } from 'react';
import styled from 'styled-components';
import { useTranslation } from 'react-i18next';
import _ from 'lodash';
import { CSSTransition } from 'react-transition-group';
import { MenuAddIcon } from '@remixicons/react/line';

import Icon from './Icon';
Expand All @@ -21,29 +22,37 @@
`;

const Submenu = styled.aside`
padding-bottom: calc(var(--margin) * 3);
position: absolute;
right: 0;
left: 0;
padding: 0 0 calc(var(--margin) * 2) 0;
border-top: 1px solid transparent;

h3 {
line-height: calc(var(--margin) * 3);
border-bottom: 1px solid transparent;
}
`;

button {
padding: calc(var(--margin) / 1.5);
text-align: center;

& + button {
margin-top: calc(var(--margin) / 1.5);
}
}
const BlurOverlay = styled.div`
position: absolute;
top: 0;
left: 0;
z-index: 0;
width: 100%;
height: 100%;
background: rgb(247 247 247 / 90%);
backdrop-filter: blur(3px);
`;

export function ServiceSubmenu({ title, icon, subheadline, items, disabled }) {
const { t } = useTranslation();
const [isOpen, setIsOpen] = useState(false);
const [value, setValue] = useState('');

const nodeRef = useRef(null);
const nodeRef2 = useRef(null);

const handleMenuToggle = () => { setIsOpen(!isOpen); setValue(''); };

// We clone the passed in React element to add the callback function prop to it:
Expand All @@ -53,33 +62,35 @@

return (
<>
<Header>
{ title && title }
{ !disabled && <ToggleButton onClick={handleMenuToggle}>
{ icon ?
icon
:
<div style={{ position: 'relative', zIndex: 1 }}>
<Header>
{ title && title }
{ !disabled &&<ToggleButton onClick={handleMenuToggle}>
{ icon ? icon :
<Icon>
<MenuAddIcon />
</Icon>
}
</ToggleButton> }
</Header>
{ isOpen && (
<Submenu>
{ subheadline && <h3>{ subheadline }</h3> }
<select
value={value}
onChange={(e) => setValue(e.target.value)}
>
<option disabled value="">-- { t('Select action') } --</option>
{ items.map(({ value, label }) => (
<option key={value} value={value}>{ label }</option>
)) }
</select>
{ value && ActionComponent }
</Submenu>
) }
</Icon> }

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 28 spaces but found 24.
</ToggleButton>}

Check failure

Code scanning / ESLint

Enforce or disallow spaces inside of curly braces in JSX attributes and expressions Error

A space is required before '}'
</Header>
<CSSTransition nodeRef={nodeRef} in={isOpen} timeout={300} classNames="my-node" mountOnEnter unmountOnExit>
<Submenu ref={nodeRef}>
{ subheadline && <h3>{ subheadline }</h3> }
<select
value={value}
onChange={(e) => setValue(e.target.value)}
>
<option disabled value="">-- { t('Select action') } --</option>
{ items.map(({ value, label }) => (
<option key={value} value={value}>{ label }</option>
)) }
</select>
{ value && ActionComponent }
</Submenu>
</CSSTransition>
</div>
<CSSTransition nodeRef={nodeRef2} in={isOpen} timeout={300} classNames="my-node" mountOnEnter unmountOnExit>
<BlurOverlay ref={nodeRef2} />
</CSSTransition>
</>
);
}
147 changes: 27 additions & 120 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 @@ -28,6 +28,7 @@
"eslint-config-next": "^13.5.6",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-matrix-org": "^0.8.0",
"react-transition-group": "^4.4.5",
"stylelint": "^14.8.2",
"stylelint-config-recess-order": "^3.0.0",
"stylelint-config-standard": "^25.0.0",
Expand Down
Loading