mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-23 16:22:21 +03:00
fix(component): disable CMDK list animation (#4685)
This commit is contained in:
parent
9d6b335829
commit
a8b10c64b8
@ -124,13 +124,15 @@ globalStyle(`${root} [cmdk-list]`, {
|
|||||||
minHeight: 120,
|
minHeight: 120,
|
||||||
overflow: 'auto',
|
overflow: 'auto',
|
||||||
overscrollBehavior: 'contain',
|
overscrollBehavior: 'contain',
|
||||||
transition: '.1s ease',
|
|
||||||
transitionProperty: 'height',
|
|
||||||
height: 'min(330px, calc(var(--cmdk-list-height) + 8px))',
|
height: 'min(330px, calc(var(--cmdk-list-height) + 8px))',
|
||||||
padding: '0 0 8px 6px',
|
padding: '0 0 8px 6px',
|
||||||
scrollbarGutter: 'stable',
|
scrollbarGutter: 'stable',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
globalStyle(`${root} [cmdk-list]:not([data-opening])`, {
|
||||||
|
transition: 'height .1s ease',
|
||||||
|
});
|
||||||
|
|
||||||
globalStyle(`${root} [cmdk-list]::-webkit-scrollbar`, {
|
globalStyle(`${root} [cmdk-list]::-webkit-scrollbar`, {
|
||||||
width: 6,
|
width: 6,
|
||||||
height: 6,
|
height: 6,
|
||||||
|
@ -5,7 +5,7 @@ import type { PageMeta } from '@blocksuite/store';
|
|||||||
import type { CommandCategory } from '@toeverything/infra/command';
|
import type { CommandCategory } from '@toeverything/infra/command';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { useAtom, useSetAtom } from 'jotai';
|
import { useAtom, useSetAtom } from 'jotai';
|
||||||
import { Suspense, useLayoutEffect, useMemo } from 'react';
|
import { Suspense, useLayoutEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
cmdkQueryAtom,
|
cmdkQueryAtom,
|
||||||
@ -126,8 +126,10 @@ export const CMDKContainer = ({
|
|||||||
query,
|
query,
|
||||||
children,
|
children,
|
||||||
pageMeta,
|
pageMeta,
|
||||||
|
open,
|
||||||
...rest
|
...rest
|
||||||
}: React.PropsWithChildren<{
|
}: React.PropsWithChildren<{
|
||||||
|
open: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
query: string;
|
query: string;
|
||||||
pageMeta?: PageMeta;
|
pageMeta?: PageMeta;
|
||||||
@ -136,6 +138,24 @@ export const CMDKContainer = ({
|
|||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
const [value, setValue] = useAtom(cmdkValueAtom);
|
const [value, setValue] = useAtom(cmdkValueAtom);
|
||||||
const isInEditor = pageMeta !== undefined;
|
const isInEditor = pageMeta !== undefined;
|
||||||
|
const [opening, setOpening] = useState(open);
|
||||||
|
|
||||||
|
// fix list height animation on openning
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
setOpening(true);
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
setOpening(false);
|
||||||
|
}, 150);
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
setOpening(false);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Command
|
<Command
|
||||||
{...rest}
|
{...rest}
|
||||||
@ -174,28 +194,32 @@ export const CMDKContainer = ({
|
|||||||
inEditor: isInEditor,
|
inEditor: isInEditor,
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<Command.List>{children}</Command.List>
|
<Command.List data-opening={opening ? true : undefined}>
|
||||||
|
{children}
|
||||||
|
</Command.List>
|
||||||
</Command>
|
</Command>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CMDKQuickSearchModal = ({
|
export const CMDKQuickSearchModal = ({
|
||||||
pageMeta,
|
pageMeta,
|
||||||
|
open,
|
||||||
...props
|
...props
|
||||||
}: CMDKModalProps & { pageMeta?: PageMeta }) => {
|
}: CMDKModalProps & { pageMeta?: PageMeta }) => {
|
||||||
const [query, setQuery] = useAtom(cmdkQueryAtom);
|
const [query, setQuery] = useAtom(cmdkQueryAtom);
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (props.open) {
|
if (open) {
|
||||||
setQuery('');
|
setQuery('');
|
||||||
}
|
}
|
||||||
}, [props.open, setQuery]);
|
}, [open, setQuery]);
|
||||||
return (
|
return (
|
||||||
<CMDKModal {...props}>
|
<CMDKModal open={open} {...props}>
|
||||||
<CMDKContainer
|
<CMDKContainer
|
||||||
className={styles.root}
|
className={styles.root}
|
||||||
query={query}
|
query={query}
|
||||||
onQueryChange={setQuery}
|
onQueryChange={setQuery}
|
||||||
pageMeta={pageMeta}
|
pageMeta={pageMeta}
|
||||||
|
open={open}
|
||||||
>
|
>
|
||||||
<Suspense fallback={<Command.Loading />}>
|
<Suspense fallback={<Command.Loading />}>
|
||||||
<QuickSearchCommands onOpenChange={props.onOpenChange} />
|
<QuickSearchCommands onOpenChange={props.onOpenChange} />
|
||||||
|
@ -30,7 +30,7 @@ export const CMDKPanelStory: StoryFn = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CMDKModal open>
|
<CMDKModal open>
|
||||||
<CMDKContainer query={query} onQueryChange={setQuery} />
|
<CMDKContainer open query={query} onQueryChange={setQuery} />
|
||||||
</CMDKModal>
|
</CMDKModal>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user