fixup: #1762 optimize style on mobile screen

This commit is contained in:
Yidadaa 2023-06-13 03:04:09 +08:00
parent 88df4a2223
commit a7e9356c16
2 changed files with 21 additions and 13 deletions

View File

@ -18,6 +18,7 @@
margin-bottom: 10px; margin-bottom: 10px;
align-items: center; align-items: center;
height: 16px; height: 16px;
width: var(--icon-width);
&:not(:last-child) { &:not(:last-child) {
margin-right: 5px; margin-right: 5px;
@ -34,6 +35,8 @@
} }
&:hover { &:hover {
width: var(--full-width);
.text { .text {
opacity: 1; opacity: 1;
transform: translate(0); transform: translate(0);

View File

@ -1,5 +1,5 @@
import { useDebouncedCallback } from "use-debounce"; import { useDebouncedCallback } from "use-debounce";
import { useState, useRef, useEffect, useLayoutEffect } from "react"; import React, { useState, useRef, useEffect, useLayoutEffect } from "react";
import SendWhiteIcon from "../icons/send-white.svg"; import SendWhiteIcon from "../icons/send-white.svg";
import BrainIcon from "../icons/brain.svg"; import BrainIcon from "../icons/brain.svg";
@ -286,34 +286,39 @@ function ChatAction(props: {
}) { }) {
const iconRef = useRef<HTMLDivElement>(null); const iconRef = useRef<HTMLDivElement>(null);
const textRef = useRef<HTMLDivElement>(null); const textRef = useRef<HTMLDivElement>(null);
const [hovering, setHovering] = useState(false); const [width, setWidth] = useState({
const [width, setWidth] = useState(20); full: 20,
icon: 20,
});
const updateWidth = () => { function updateWidth() {
if (!iconRef.current || !textRef.current) return; if (!iconRef.current || !textRef.current) return;
const getWidth = (dom: HTMLDivElement) => dom.getBoundingClientRect().width; const getWidth = (dom: HTMLDivElement) => dom.getBoundingClientRect().width;
const textWidth = getWidth(textRef.current); const textWidth = getWidth(textRef.current);
const iconWidth = getWidth(iconRef.current); const iconWidth = getWidth(iconRef.current);
setWidth(hovering ? textWidth + iconWidth : iconWidth); setWidth({
}; full: textWidth + iconWidth,
icon: iconWidth,
});
}
useEffect(() => { useEffect(() => {
updateWidth(); updateWidth();
// eslint-disable-next-line react-hooks/exhaustive-deps }, []);
}, [hovering]);
return ( return (
<div <div
className={`${chatStyle["chat-input-action"]} clickable`} className={`${chatStyle["chat-input-action"]} clickable`}
onMouseEnter={() => setHovering(true)}
onMouseLeave={() => setHovering(false)}
style={{
width,
}}
onClick={() => { onClick={() => {
props.onClick(); props.onClick();
setTimeout(updateWidth, 1); setTimeout(updateWidth, 1);
}} }}
style={
{
"--icon-width": `${width.icon}px`,
"--full-width": `${width.full}px`,
} as React.CSSProperties
}
> >
<div ref={iconRef} className={chatStyle["icon"]}> <div ref={iconRef} className={chatStyle["icon"]}>
{props.icon} {props.icon}