Skip to content

Commit 22c88a7

Browse files
committed
fix(Overlay): faster transitions
1 parent d3cf4a1 commit 22c88a7

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

.changeset/neat-clouds-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': patch
3+
---
4+
5+
Faster overlay transition with 120ms duration instead of 180ms.

src/components/overlays/OverlayWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function OverlayWrapper({
4545
<CSSTransition
4646
unmountOnExit
4747
in={isOpen}
48-
timeout={180}
48+
timeout={120}
4949
classNames="cube-overlay-transition"
5050
>
5151
<>{children}</>

src/utils/react/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export { useLayoutEffect } from './useLayoutEffect';
77
export { useCombinedRefs } from './useCombinedRefs';
88
export { wrapNodeIfPlain } from './wrapNodeIfPlain';
99
export { useViewportSize } from './useViewportSize';
10+
export { useQaProps } from './useQaProps';

src/utils/react/useQaProps.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
type Props = {
2+
qa?: string;
3+
qaVal?: string;
4+
'data-qa'?: string;
5+
'data-qa-val'?: string;
6+
};
7+
8+
/**
9+
* Processes QA props.
10+
* If `qa` or `qaVal` props are present, they are not modified and have higher priority.
11+
* Otherwise, maps `data-qa` to `qa` and `data-qa-val` to `qaVal`.
12+
* Data attributes are always removed.
13+
* Modifies the original props object without copying it.
14+
* Accepts only non-falsy values, otherwise deletes both props.
15+
*
16+
* @param props - The object to process
17+
* @returns The modified object
18+
*/
19+
export function useQaProps<T extends Props>(props: T): T {
20+
// Helper function to process qa attributes
21+
const processQaAttribute = (propName: string, dataAttrName: string) => {
22+
if (props[propName] !== undefined || props[dataAttrName] !== undefined) {
23+
const propValue = props[propName];
24+
const dataAttrValue = props[dataAttrName];
25+
26+
if (!propValue) {
27+
if (dataAttrValue) {
28+
// If prop is empty but data-attr is truthy, map data-attr to prop
29+
props[propName] = dataAttrValue;
30+
} else {
31+
// Both values are falsy, delete both
32+
delete props[propName];
33+
}
34+
}
35+
36+
delete props[dataAttrName];
37+
}
38+
};
39+
40+
// Process qa attributes
41+
processQaAttribute('qa', 'data-qa');
42+
processQaAttribute('qaVal', 'data-qa-val');
43+
44+
return props;
45+
}

src/utils/transitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const getOverlayTransitionCSS = ({
4141
};
4242
--overlay-translate-visible: translate(0px, 0px);
4343
--overlay-translate-hidden: ${TRANSLATE_MAP[placement]};
44-
--overlay-transition: 180ms;
44+
--overlay-transition: 120ms;
4545
--overlay-hidden-scale: scale(var(--overlay-hidden-x-scale), var(--overlay-hidden-y-scale));
4646
--overlay-normal-scale: scale(1, 1);
4747
}

0 commit comments

Comments
 (0)