chore: adjust find in page modal style (#7087)
 
This commit is contained in:
@@ -1,12 +1,7 @@
|
|||||||
import { cssVar } from '@toeverything/theme';
|
import { cssVar } from '@toeverything/theme';
|
||||||
import { createVar, style } from '@vanilla-extract/css';
|
import { style } from '@vanilla-extract/css';
|
||||||
|
|
||||||
export const panelWidthVar = createVar('panel-width');
|
|
||||||
|
|
||||||
export const container = style({
|
export const container = style({
|
||||||
vars: {
|
|
||||||
[panelWidthVar]: '0px',
|
|
||||||
},
|
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
@@ -14,7 +9,9 @@ export const container = style({
|
|||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
right: '28px',
|
right: '28px',
|
||||||
top: '80px',
|
top: '80px',
|
||||||
transform: `translateX(calc(${panelWidthVar} * -1))`,
|
borderRadius: '8px',
|
||||||
|
boxShadow: cssVar('shadow3'),
|
||||||
|
border: `0.5px solid ${cssVar('borderColor')}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const leftContent = style({
|
export const leftContent = style({
|
||||||
@@ -23,15 +20,35 @@ export const leftContent = style({
|
|||||||
flex: 1,
|
flex: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const searchIcon = style({
|
||||||
|
fontSize: '20px',
|
||||||
|
color: cssVar('iconColor'),
|
||||||
|
verticalAlign: 'middle',
|
||||||
|
});
|
||||||
|
|
||||||
export const inputContainer = style({
|
export const inputContainer = style({
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignSelf: 'stretch',
|
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
gap: '8px',
|
gap: '8px',
|
||||||
flex: 1,
|
flex: 1,
|
||||||
height: '32px',
|
height: '32px',
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
margin: '0 8px',
|
padding: '0 8px',
|
||||||
|
borderRadius: '4px',
|
||||||
|
background: cssVar('white10'),
|
||||||
|
border: `1px solid ${cssVar('borderColor')}`,
|
||||||
|
selectors: {
|
||||||
|
'&.active': {
|
||||||
|
borderColor: cssVar('primaryColor'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
export const inputMain = style({
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
flex: 1,
|
||||||
|
height: '32px',
|
||||||
|
position: 'relative',
|
||||||
});
|
});
|
||||||
|
|
||||||
export const input = style({
|
export const input = style({
|
||||||
@@ -41,14 +58,13 @@ export const input = style({
|
|||||||
height: '100%',
|
height: '100%',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
color: 'transparent',
|
color: 'transparent',
|
||||||
background: cssVar('white10'),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const inputHack = style([
|
export const inputHack = style([
|
||||||
input,
|
input,
|
||||||
{
|
{
|
||||||
'::placeholder': {
|
'::placeholder': {
|
||||||
color: cssVar('iconColor'),
|
color: cssVar('textPrimaryColor'),
|
||||||
},
|
},
|
||||||
pointerEvents: 'none',
|
pointerEvents: 'none',
|
||||||
},
|
},
|
||||||
@@ -68,9 +84,13 @@ export const arrowButton = style({
|
|||||||
flexShrink: 0,
|
flexShrink: 0,
|
||||||
border: '1px solid',
|
border: '1px solid',
|
||||||
borderColor: cssVar('borderColor'),
|
borderColor: cssVar('borderColor'),
|
||||||
|
color: cssVar('iconSecondary'),
|
||||||
alignItems: 'baseline',
|
alignItems: 'baseline',
|
||||||
background: 'transparent',
|
background: 'transparent',
|
||||||
selectors: {
|
selectors: {
|
||||||
|
'&:hover': {
|
||||||
|
color: cssVar('iconColor'),
|
||||||
|
},
|
||||||
'&.backward': {
|
'&.backward': {
|
||||||
marginLeft: '8px',
|
marginLeft: '8px',
|
||||||
borderRadius: '4px 0 0 4px',
|
borderRadius: '4px 0 0 4px',
|
||||||
@@ -81,3 +101,12 @@ export const arrowButton = style({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
export const closeButton = style({
|
||||||
|
padding: '4px',
|
||||||
|
fontSize: '20px',
|
||||||
|
width: '24px',
|
||||||
|
height: '24px',
|
||||||
|
flexShrink: 0,
|
||||||
|
color: cssVar('iconColor'),
|
||||||
|
marginLeft: '8px',
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { Button, Modal } from '@affine/component';
|
import { Button, IconButton, Modal } from '@affine/component';
|
||||||
import { rightSidebarWidthAtom } from '@affine/core/atoms';
|
import {
|
||||||
import { ArrowDownSmallIcon, ArrowUpSmallIcon } from '@blocksuite/icons';
|
ArrowDownSmallIcon,
|
||||||
|
ArrowUpSmallIcon,
|
||||||
|
CloseIcon,
|
||||||
|
SearchIcon,
|
||||||
|
} from '@blocksuite/icons';
|
||||||
import { useLiveData, useService } from '@toeverything/infra';
|
import { useLiveData, useService } from '@toeverything/infra';
|
||||||
import { assignInlineVars } from '@vanilla-extract/dynamic';
|
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { useAtomValue } from 'jotai';
|
|
||||||
import {
|
import {
|
||||||
type KeyboardEventHandler,
|
type KeyboardEventHandler,
|
||||||
useCallback,
|
useCallback,
|
||||||
@@ -13,7 +15,6 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
|
|
||||||
import { RightSidebarService } from '../../right-sidebar';
|
|
||||||
import { FindInPageService } from '../services/find-in-page';
|
import { FindInPageService } from '../services/find-in-page';
|
||||||
import * as styles from './find-in-page-modal.css';
|
import * as styles from './find-in-page-modal.css';
|
||||||
|
|
||||||
@@ -26,12 +27,20 @@ const drawText = (canvas: HTMLCanvasElement, text: string) => {
|
|||||||
const dpr = window.devicePixelRatio || 1;
|
const dpr = window.devicePixelRatio || 1;
|
||||||
canvas.width = canvas.getBoundingClientRect().width * dpr;
|
canvas.width = canvas.getBoundingClientRect().width * dpr;
|
||||||
canvas.height = canvas.getBoundingClientRect().height * dpr;
|
canvas.height = canvas.getBoundingClientRect().height * dpr;
|
||||||
|
|
||||||
|
const rootStyles = getComputedStyle(document.documentElement);
|
||||||
|
const textColor = rootStyles
|
||||||
|
.getPropertyValue('--affine-text-primary-color')
|
||||||
|
.trim();
|
||||||
|
|
||||||
ctx.scale(dpr, dpr);
|
ctx.scale(dpr, dpr);
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
ctx.fillStyle = textColor;
|
||||||
ctx.font = '15px Inter';
|
ctx.font = '15px Inter';
|
||||||
|
|
||||||
ctx.fillText(text, 0, 22);
|
ctx.fillText(text, 0, 22);
|
||||||
ctx.textAlign = 'left';
|
ctx.textAlign = 'left';
|
||||||
ctx.textBaseline = 'ideographic';
|
ctx.textBaseline = 'middle';
|
||||||
};
|
};
|
||||||
|
|
||||||
const CanvasText = ({
|
const CanvasText = ({
|
||||||
@@ -69,11 +78,8 @@ export const FindInPageModal = () => {
|
|||||||
const result = useLiveData(findInPage.result$);
|
const result = useLiveData(findInPage.result$);
|
||||||
const isSearching = useLiveData(findInPage.isSearching$);
|
const isSearching = useLiveData(findInPage.isSearching$);
|
||||||
|
|
||||||
const rightSidebarWidth = useAtomValue(rightSidebarWidthAtom);
|
|
||||||
const rightSidebar = useService(RightSidebarService).rightSidebar;
|
|
||||||
const frontView = useLiveData(rightSidebar.front$);
|
|
||||||
const open = useLiveData(rightSidebar.isOpen$) && frontView !== undefined;
|
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const [active, setActive] = useState(false);
|
||||||
|
|
||||||
const handleValueChange = useCallback(
|
const handleValueChange = useCallback(
|
||||||
(v: string) => {
|
(v: string) => {
|
||||||
@@ -87,6 +93,14 @@ export const FindInPageModal = () => {
|
|||||||
[findInPage]
|
[findInPage]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleFocus = useCallback(() => {
|
||||||
|
setActive(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleBlur = useCallback(() => {
|
||||||
|
setActive(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
setValue(findInPage.searchText$.value || '');
|
setValue(findInPage.searchText$.value || '');
|
||||||
@@ -148,9 +162,6 @@ export const FindInPageModal = () => {
|
|||||||
},
|
},
|
||||||
[handleBackWard, handleForward]
|
[handleBackWard, handleForward]
|
||||||
);
|
);
|
||||||
const panelWidth = assignInlineVars({
|
|
||||||
[styles.panelWidthVar]: open ? `${rightSidebarWidth}px` : '0',
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
@@ -162,11 +173,16 @@ export const FindInPageModal = () => {
|
|||||||
minHeight={48}
|
minHeight={48}
|
||||||
contentOptions={{
|
contentOptions={{
|
||||||
className: styles.container,
|
className: styles.container,
|
||||||
style: panelWidth,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className={styles.leftContent}>
|
<div className={styles.leftContent}>
|
||||||
<div className={styles.inputContainer}>
|
<div
|
||||||
|
className={clsx(styles.inputContainer, {
|
||||||
|
active: active,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<SearchIcon className={styles.searchIcon} />
|
||||||
|
<div className={styles.inputMain}>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
autoFocus
|
autoFocus
|
||||||
@@ -175,6 +191,8 @@ export const FindInPageModal = () => {
|
|||||||
style={{
|
style={{
|
||||||
visibility: isSearching ? 'hidden' : 'visible',
|
visibility: isSearching ? 'hidden' : 'visible',
|
||||||
}}
|
}}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
onFocus={handleFocus}
|
||||||
className={styles.input}
|
className={styles.input}
|
||||||
onKeyDown={handleKeydown}
|
onKeyDown={handleKeydown}
|
||||||
onChange={e => handleValueChange(e.target.value)}
|
onChange={e => handleValueChange(e.target.value)}
|
||||||
@@ -192,6 +210,7 @@ export const FindInPageModal = () => {
|
|||||||
<span>No matches</span>
|
<span>No matches</span>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
className={clsx(styles.arrowButton, 'backward')}
|
className={clsx(styles.arrowButton, 'backward')}
|
||||||
@@ -206,9 +225,13 @@ export const FindInPageModal = () => {
|
|||||||
<ArrowDownSmallIcon />
|
<ArrowDownSmallIcon />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<Button type="primary" onClick={handleDone}>
|
<IconButton
|
||||||
Done
|
className={styles.closeButton}
|
||||||
</Button>
|
type="plain"
|
||||||
|
onClick={handleDone}
|
||||||
|
>
|
||||||
|
<CloseIcon />
|
||||||
|
</IconButton>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user