Skip to content
Open
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
23 changes: 17 additions & 6 deletions packages/ui/src/components/devPrompts/KeylessPrompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, { useMemo, useState } from 'react';
import { Portal } from '../../../elements/Portal';
import { MosaicThemeProvider, useMosaicTheme } from '../../../mosaic/theme-provider';
import { handleDashboardUrlParsing } from '../shared';
import { useDragToCorner } from './use-drag-to-corner';
import { useRevalidateEnvironment } from './use-revalidate-environment';

type KeylessPromptProps = {
Expand Down Expand Up @@ -36,8 +37,8 @@ function KeylessPromptInternal(props: KeylessPromptProps) {
const [isOpen, setIsOpen] = useState(isSignedIn || isLocked);
const [hasMounted, setHasMounted] = useState(false);
const id = React.useId();
const containerRef = React.useRef<HTMLDivElement>(null);
const theme = useMosaicTheme();
const { isDragging, cornerStyle, containerRef, onPointerDown, preventClick, isInitialized } = useDragToCorner();

React.useEffect(() => {
setHasMounted(true);
Expand Down Expand Up @@ -116,6 +117,11 @@ function KeylessPromptInternal(props: KeylessPromptProps) {
<Portal>
<div
ref={containerRef}
onPointerDown={isOpen ? undefined : onPointerDown}
style={{
...cornerStyle,
opacity: isInitialized ? undefined : 0,
}}
css={css`
--duration-open: 220ms;
--duration-close: 180ms;
Expand All @@ -131,8 +137,6 @@ function KeylessPromptInternal(props: KeylessPromptProps) {
-webkit-font-smoothing: auto;
-moz-osx-font-smoothing: auto;
position: fixed;
bottom: var(--offset);
right: var(--offset);
z-index: 999999;
height: auto;
width: ${isOpen ? 'var(--width-opened)' : 'var(--width-closed)'};
Expand Down Expand Up @@ -160,9 +164,13 @@ function KeylessPromptInternal(props: KeylessPromptProps) {
will-change: width, border-radius;
transform: translateZ(0);
backface-visibility: hidden;
transition: ${hasMounted
? `width ${isOpen ? 'var(--duration-open)' : 'var(--duration-close)'} var(--ease-bezier), border-radius var(--duration-open) var(--ease-bezier)`
: 'none'};
cursor: ${isDragging ? 'grabbing' : isOpen ? 'default' : 'grab'};
touch-action: none;
transition: ${isDragging
? 'none'
: hasMounted
? `width ${isOpen ? 'var(--duration-open)' : 'var(--duration-close)'} var(--ease-bezier), border-radius var(--duration-open) var(--ease-bezier)`
: 'none'};
@media (prefers-reduced-motion: reduce) {
transition: none;
}
Expand Down Expand Up @@ -191,6 +199,9 @@ function KeylessPromptInternal(props: KeylessPromptProps) {
<button
type='button'
onClick={() => {
if (preventClick) {
return;
}
if (!isLocked) {
setIsOpen(prev => !prev);
}
Expand Down
Loading