mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 13:59:28 +08:00
refactor(Scrollbar, Messages): clean up scrollbar component and styles
- Removed unused 'right' prop from Scrollbar component. - Increased scrolling timeout duration for better user experience. - Updated scrollbar styles to simplify color handling. - Adjusted Messages component to remove unnecessary props and added margin for better layout. - Added responsive styles to CitationBlock for improved mobile display.
This commit is contained in:
parent
65c7b720de
commit
e83d31a232
@ -299,6 +299,7 @@ emoji-picker {
|
|||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
overflow-y: hidden;
|
overflow-y: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
mjx-container {
|
mjx-container {
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
:root {
|
:root {
|
||||||
--color-scrollbar-thumb: rgba(255, 255, 255, 0.15);
|
--color-scrollbar-thumb: rgba(255, 255, 255, 0.15);
|
||||||
--color-scrollbar-thumb-hover: rgba(255, 255, 255, 0.2);
|
--color-scrollbar-thumb-hover: rgba(255, 255, 255, 0.2);
|
||||||
--color-scrollbar-thumb-right: rgba(255, 255, 255, 0.18);
|
|
||||||
--color-scrollbar-thumb-right-hover: rgba(255, 255, 255, 0.25);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body[theme-mode='light'] {
|
body[theme-mode='light'] {
|
||||||
--color-scrollbar-thumb: rgba(0, 0, 0, 0.15);
|
--color-scrollbar-thumb: rgba(0, 0, 0, 0.15);
|
||||||
--color-scrollbar-thumb-hover: rgba(0, 0, 0, 0.2);
|
--color-scrollbar-thumb-hover: rgba(0, 0, 0, 0.2);
|
||||||
--color-scrollbar-thumb-right: rgba(0, 0, 0, 0.18);
|
|
||||||
--color-scrollbar-thumb-right-hover: rgba(0, 0, 0, 0.25);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 全局初始化滚动条样式 */
|
/* 全局初始化滚动条样式 */
|
||||||
|
|||||||
@ -4,11 +4,10 @@ import styled from 'styled-components'
|
|||||||
|
|
||||||
interface Props extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onScroll'> {
|
interface Props extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onScroll'> {
|
||||||
ref?: React.RefObject<HTMLDivElement | null>
|
ref?: React.RefObject<HTMLDivElement | null>
|
||||||
right?: boolean
|
|
||||||
onScroll?: () => void // Custom onScroll prop for useScrollPosition's handleScroll
|
onScroll?: () => void // Custom onScroll prop for useScrollPosition's handleScroll
|
||||||
}
|
}
|
||||||
|
|
||||||
const Scrollbar: FC<Props> = ({ ref: passedRef, right, children, onScroll: externalOnScroll, ...htmlProps }) => {
|
const Scrollbar: FC<Props> = ({ ref: passedRef, children, onScroll: externalOnScroll, ...htmlProps }) => {
|
||||||
const [isScrolling, setIsScrolling] = useState(false)
|
const [isScrolling, setIsScrolling] = useState(false)
|
||||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null)
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null)
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ const Scrollbar: FC<Props> = ({ ref: passedRef, right, children, onScroll: exter
|
|||||||
timeoutRef.current = setTimeout(() => {
|
timeoutRef.current = setTimeout(() => {
|
||||||
setIsScrolling(false)
|
setIsScrolling(false)
|
||||||
timeoutRef.current = null
|
timeoutRef.current = null
|
||||||
}, 1000)
|
}, 1500)
|
||||||
}, [clearScrollingTimeout])
|
}, [clearScrollingTimeout])
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
@ -52,7 +51,6 @@ const Scrollbar: FC<Props> = ({ ref: passedRef, right, children, onScroll: exter
|
|||||||
<Container
|
<Container
|
||||||
{...htmlProps} // Pass other HTML attributes
|
{...htmlProps} // Pass other HTML attributes
|
||||||
$isScrolling={isScrolling}
|
$isScrolling={isScrolling}
|
||||||
$right={right}
|
|
||||||
onScroll={combinedOnScroll} // Use the combined handler
|
onScroll={combinedOnScroll} // Use the combined handler
|
||||||
ref={passedRef}>
|
ref={passedRef}>
|
||||||
{children}
|
{children}
|
||||||
@ -60,15 +58,13 @@ const Scrollbar: FC<Props> = ({ ref: passedRef, right, children, onScroll: exter
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Container = styled.div<{ $isScrolling: boolean; $right?: boolean }>`
|
const Container = styled.div<{ $isScrolling: boolean }>`
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
&::-webkit-scrollbar-thumb {
|
&::-webkit-scrollbar-thumb {
|
||||||
transition: background 2s ease;
|
transition: background 2s ease;
|
||||||
background: ${(props) =>
|
background: ${(props) => (props.$isScrolling ? 'var(--color-scrollbar-thumb)' : 'transparent')};
|
||||||
props.$isScrolling ? `var(--color-scrollbar-thumb${props.$right ? '-right' : ''})` : 'transparent'};
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: ${(props) =>
|
background: var(--color-scrollbar-thumb-hover);
|
||||||
props.$isScrolling ? `var(--color-scrollbar-thumb${props.$right ? '-right' : ''}-hover)` : 'transparent'};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|||||||
@ -53,6 +53,16 @@ function CitationBlock({ block }: { block: CitationMessageBlock }) {
|
|||||||
|
|
||||||
const SearchEntryPoint = styled.div`
|
const SearchEntryPoint = styled.div`
|
||||||
margin: 10px 2px;
|
margin: 10px 2px;
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.carousel {
|
||||||
|
white-space: normal;
|
||||||
|
.chip {
|
||||||
|
margin: 0;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
export default React.memo(CitationBlock)
|
export default React.memo(CitationBlock)
|
||||||
|
|||||||
@ -273,8 +273,7 @@ const Messages: React.FC<MessagesProps> = ({ assistant, topic, setActiveTopic, o
|
|||||||
ref={scrollContainerRef}
|
ref={scrollContainerRef}
|
||||||
style={{ position: 'relative', paddingTop: showPrompt ? 10 : 0 }}
|
style={{ position: 'relative', paddingTop: showPrompt ? 10 : 0 }}
|
||||||
key={assistant.id}
|
key={assistant.id}
|
||||||
onScroll={handleScrollPosition}
|
onScroll={handleScrollPosition}>
|
||||||
$right={topicPosition === 'left'}>
|
|
||||||
<NarrowLayout style={{ display: 'flex', flexDirection: 'column-reverse' }}>
|
<NarrowLayout style={{ display: 'flex', flexDirection: 'column-reverse' }}>
|
||||||
<InfiniteScroll
|
<InfiniteScroll
|
||||||
dataLength={displayMessages.length}
|
dataLength={displayMessages.length}
|
||||||
@ -376,6 +375,7 @@ const MessagesContainer = styled(Scrollbar)<ContainerProps>`
|
|||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
background-color: var(--color-background);
|
background-color: var(--color-background);
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
margin-right: 2px;
|
||||||
`
|
`
|
||||||
|
|
||||||
export default Messages
|
export default Messages
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user