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

[D&D] Dropbox style and animations #1863

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@

&__container {
display: grid;
grid-gap: $euiSizeXS;
padding: $euiSizeS;
background-color: #e9edf3;
grid-gap: $euiSizeXS / 2;
Copy link
Member

Choose a reason for hiding this comment

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

seems like a pain point worth noting as a painpoint in the design system for UX.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, the actual spacing here fits within the UX guidelines. The DOM structure of the dropbox is kinda tricky such that i need to add and subtract margins and paddings to make the UX look clean. The end result it still valid EUI space sizing

padding: $euiSizeS - ($euiSizeXS / 2) $euiSizeS $euiSizeS $euiSizeS;
background-color: $euiColorLightShade;
border-radius: $euiBorderRadius;
}

&__field {
display: grid;
grid-template-columns: 1fr auto;

// grid-template-columns: auto 1fr auto;
grid-gap: $euiSizeS;
padding: $euiSizeS $euiSizeM;
align-items: center;
}

&__draggable {
padding: 2px 0;
padding: $euiSizeXS / 2 0;
animation: pop-in $euiAnimSpeedSlow $euiAnimSlightResistance forwards;
transform-origin: bottom;

&.closing {
animation: pop-out $euiAnimSpeedSlow $euiAnimSlightResistance forwards; // Also update speed in dropbox.tsx
}
}

&__field_text {
Expand All @@ -41,6 +45,8 @@
&__dropTarget {
color: $euiColorDarkShade;
grid-template-columns: 1fr auto;
transform-origin: top;
animation: pop-in $euiAnimSpeedFast $euiAnimSlightResistance forwards;

&.validField {
background-color: #a8d9e7;
Expand All @@ -54,3 +60,43 @@
}
}
}

@keyframes pop-in {
from {
max-height: 0;
opacity: 0;
}

to {
max-height: 1000px;
opacity: 1;
}
}

@keyframes pop-out {
from {
max-height: 1000px;
opacity: 1;
}

to {
max-height: 0;
opacity: 0;
}
}

@media (prefers-reduced-motion) {
.dropBox {
&__draggable {
animation: none;

&.closing {
animation: none;
}
}

&__dropTarget {
animation: none;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import {
EuiText,
DropResult,
} from '@elastic/eui';
import React, { useCallback } from 'react';
import React, { useCallback, useState } from 'react';
import { IDropAttributes, IDropState } from '../../utils/drag_drop';
import './dropbox.scss';
import { useDropbox } from './use';
import { UseDropboxProps } from './use/use_dropbox';
import { usePrefersReducedMotion } from './use/use_prefers_reduced_motion';

export interface DropboxDisplay {
label: string;
Expand Down Expand Up @@ -55,6 +56,8 @@ const DropboxComponent = ({
canDrop,
dropProps,
}: DropboxProps) => {
const prefersReducedMotion = usePrefersReducedMotion();
const [closing, setClosing] = useState<boolean | string>(false);
const handleDragEnd = useCallback(
({ source, destination }: DropResult) => {
if (!destination) return;
Expand All @@ -67,13 +70,32 @@ const DropboxComponent = ({
[fields, onReorderField]
);

const animateDelete = useCallback(
(id: string) => {
setClosing(id);
setTimeout(
() => {
onDeleteField(id);
setClosing(false);
},
prefersReducedMotion ? 0 : 350 // Also update speed in dropbox.scss
);
},
[onDeleteField, prefersReducedMotion]
);

return (
<EuiDragDropContext onDragEnd={handleDragEnd}>
<EuiFormRow label={boxLabel} className="dropBox" fullWidth>
<div className="dropBox__container">
<EuiDroppable droppableId={dropboxId}>
{fields.map(({ id, label }, index) => (
<EuiDraggable className="dropBox__draggable" key={id} draggableId={id} index={index}>
<EuiDraggable
className={`dropBox__draggable ${id === closing && 'closing'}`}
key={id}
draggableId={id}
index={index}
>
<EuiPanel key={index} paddingSize="s" className="dropBox__field">
<EuiText size="s" className="dropBox__field_text" onClick={() => onEditField(id)}>
<a role="button" tabIndex={0}>
Expand All @@ -85,7 +107,7 @@ const DropboxComponent = ({
iconType="cross"
aria-label="clear-field"
iconSize="s"
onClick={() => onDeleteField(id)}
onClick={() => animateDelete(id)}
/>
</EuiPanel>
</EuiDraggable>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { useEffect, useState } from 'react';

const QUERY = '(prefers-reduced-motion: no-preference)';

export function usePrefersReducedMotion() {
const [prefersReducedMotion, setPrefersReducedMotion] = useState(
!window.matchMedia(QUERY).matches
);

useEffect(() => {
const mediaQueryList = window.matchMedia(QUERY);
const listener = (event) => {
setPrefersReducedMotion(!event.matches);
};

if (mediaQueryList.addEventListener) {
mediaQueryList.addEventListener('change', listener);
}

return () => {
mediaQueryList.removeEventListener('change', listener);
};
}, []);

return prefersReducedMotion;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const Workspace: FC = ({ children }) => {
if (errorMsg) {
toasts.addWarning(errorMsg);
}
setExpression(undefined);
return;
}
const exp = await toExpression(rootState);
Expand Down