fix: cmdk scrollbar gutter (#4488)

This commit is contained in:
Peng Xiao
2023-09-25 20:03:02 +08:00
committed by GitHub
parent 35dc6d6687
commit 3f09ba92bc
5 changed files with 26 additions and 15 deletions

View File

@@ -49,14 +49,7 @@ export const UserInfo = ({
className={accountButton} className={accountButton}
onClick={onAccountSettingClick} onClick={onAccountSettingClick}
> >
<Avatar <Avatar size={28} name={user.name} url={user.image} className="avatar" />
size={28}
name={user.name}
url={user.image}
style={{
marginRight: '10px',
}}
/>
<div className="content"> <div className="content">
<div className="name" title={user.name}> <div className="name" title={user.name}>

View File

@@ -100,6 +100,7 @@ export const accountButton = style({
cursor: 'pointer', cursor: 'pointer',
userSelect: 'none', userSelect: 'none',
display: 'flex', display: 'flex',
columnGap: '10px',
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'center', alignItems: 'center',
':hover': { ':hover': {
@@ -107,7 +108,7 @@ export const accountButton = style({
}, },
}); });
globalStyle(`${accountButton} .avatar.not-sign`, { globalStyle(`${accountButton} .avatar`, {
width: '28px', width: '28px',
height: '28px', height: '28px',
borderRadius: '50%', borderRadius: '50%',
@@ -115,6 +116,10 @@ globalStyle(`${accountButton} .avatar.not-sign`, {
display: 'flex', display: 'flex',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
flexShrink: 0,
});
globalStyle(`${accountButton} .avatar.not-sign`, {
borderColor: 'var(--affine-icon-secondary)', borderColor: 'var(--affine-icon-secondary)',
color: 'var(--affine-icon-secondary)', color: 'var(--affine-icon-secondary)',
background: 'var(--affine-white)', background: 'var(--affine-white)',

View File

@@ -41,6 +41,7 @@ import { usePageHelper } from '../../blocksuite/block-suite-page-list/utils';
import type { CMDKCommand, CommandContext } from './types'; import type { CMDKCommand, CommandContext } from './types';
export const cmdkQueryAtom = atom(''); export const cmdkQueryAtom = atom('');
export const cmdkValueAtom = atom('');
// like currentWorkspaceAtom, but not throw error // like currentWorkspaceAtom, but not throw error
const safeCurrentPageAtom = atom<Promise<Page | undefined>>(async get => { const safeCurrentPageAtom = atom<Promise<Page | undefined>>(async get => {

View File

@@ -83,24 +83,32 @@ globalStyle(`${root} [cmdk-group][hidden]`, {
display: 'none', display: 'none',
}); });
globalStyle(
`${root} [cmdk-group]:not([hidden]):first-of-type [cmdk-group-heading]`,
{
paddingTop: 16,
}
);
globalStyle(`${root} [cmdk-list]`, { globalStyle(`${root} [cmdk-list]`, {
maxHeight: 400, maxHeight: 400,
minHeight: 120,
overflow: 'auto', overflow: 'auto',
overscrollBehavior: 'contain', overscrollBehavior: 'contain',
transition: '.1s ease', transition: '.1s ease',
transitionProperty: 'height', transitionProperty: 'height',
height: 'min(330px, calc(var(--cmdk-list-height) + 8px))', height: 'min(330px, calc(var(--cmdk-list-height) + 8px))',
padding: '0 6px 8px 6px', padding: '0 0 8px 6px',
scrollbarGutter: 'stable',
}); });
globalStyle(`${root} [cmdk-list]::-webkit-scrollbar`, { globalStyle(`${root} [cmdk-list]::-webkit-scrollbar`, {
width: 8, width: 6,
height: 8, height: 6,
}); });
globalStyle(`${root} [cmdk-list]::-webkit-scrollbar-thumb`, { globalStyle(`${root} [cmdk-list]::-webkit-scrollbar-thumb`, {
borderRadius: 4, borderRadius: 4,
border: '1px solid transparent',
backgroundClip: 'padding-box', backgroundClip: 'padding-box',
}); });

View File

@@ -4,10 +4,11 @@ import { useAFFiNEI18N } from '@affine/i18n/hooks';
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, useEffect, useMemo } from 'react'; import { Suspense, useLayoutEffect, useMemo } from 'react';
import { import {
cmdkQueryAtom, cmdkQueryAtom,
cmdkValueAtom,
customCommandFilter, customCommandFilter,
useCMDKCommandGroups, useCMDKCommandGroups,
} from './data'; } from './data';
@@ -126,12 +127,15 @@ export const CMDKContainer = ({
onQueryChange: (query: string) => void; onQueryChange: (query: string) => void;
}>) => { }>) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
const [value, setValue] = useAtom(cmdkValueAtom);
return ( return (
<Command <Command
{...rest} {...rest}
data-testid="cmdk-quick-search" data-testid="cmdk-quick-search"
filter={customCommandFilter} filter={customCommandFilter}
className={clsx(className, styles.panelContainer)} className={clsx(className, styles.panelContainer)}
value={value}
onValueChange={setValue}
// Handle KeyboardEvent conflicts with blocksuite // Handle KeyboardEvent conflicts with blocksuite
onKeyDown={(e: React.KeyboardEvent) => { onKeyDown={(e: React.KeyboardEvent) => {
if ( if (
@@ -160,7 +164,7 @@ export const CMDKContainer = ({
export const CMDKQuickSearchModal = (props: CMDKModalProps) => { export const CMDKQuickSearchModal = (props: CMDKModalProps) => {
const [query, setQuery] = useAtom(cmdkQueryAtom); const [query, setQuery] = useAtom(cmdkQueryAtom);
useEffect(() => { useLayoutEffect(() => {
if (props.open) { if (props.open) {
setQuery(''); setQuery('');
} }