style: resize terminal height

This commit is contained in:
jialin
2025-12-10 15:50:53 +08:00
parent a08f1e2512
commit 04f995b80c
+18 -6
View File
@@ -1,6 +1,7 @@
import XTerminal from '@/components/x-terminal'; import XTerminal from '@/components/x-terminal';
import { CloseOutlined } from '@ant-design/icons'; import { CloseOutlined } from '@ant-design/icons';
import { Button, Tabs } from 'antd'; import { Button, Tabs } from 'antd';
import { throttle } from 'lodash';
import React, { useEffect, useMemo, useState } from 'react'; import React, { useEffect, useMemo, useState } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import ResizeContainer from './resize-container'; import ResizeContainer from './resize-container';
@@ -27,8 +28,11 @@ const TabsContainer = styled.div`
border: none; border: none;
background-color: transparent; background-color: transparent;
.ant-tabs-tab-remove { .ant-tabs-tab-remove .anticon-close {
display: none; // display: none;
height: 0;
overflow: hidden;
transition: all 0.3s;
} }
&::before { &::before {
@@ -47,8 +51,9 @@ const TabsContainer = styled.div`
&::before { &::before {
display: block; display: block;
} }
.ant-tabs-tab-remove { .ant-tabs-tab-remove .anticon-close {
display: inline-block; // display: inline-block;
height: auto;
} }
} }
} }
@@ -79,6 +84,7 @@ const TerminalTabs: React.FC<TerminalTabsProps> = ({
currentActive || terminals[0]?.url || '' currentActive || terminals[0]?.url || ''
); );
const [height, setHeight] = useState(300); const [height, setHeight] = useState(300);
const resizeRef = React.useRef<any>(null);
const items = useMemo(() => { const items = useMemo(() => {
return terminals.map((terminal) => { return terminals.map((terminal) => {
@@ -88,7 +94,13 @@ const TerminalTabs: React.FC<TerminalTabsProps> = ({
children: <XTerminal height={height} url={terminal.url} /> children: <XTerminal height={height} url={terminal.url} />
}; };
}); });
}, [terminals]); }, [terminals, height]);
const handleOnResize = throttle(() => {
const newHeight = resizeRef.current?.container?.state?.height;
console.log('newHeight', newHeight);
setHeight(newHeight - 43); // 43 is the height of the tabs header
}, 200);
useEffect(() => { useEffect(() => {
if (currentActive) { if (currentActive) {
@@ -97,7 +109,7 @@ const TerminalTabs: React.FC<TerminalTabsProps> = ({
}, [currentActive]); }, [currentActive]);
return ( return (
<ResizeContainer> <ResizeContainer onReSize={handleOnResize} ref={resizeRef}>
<TabsContainer> <TabsContainer>
<Tabs <Tabs
type="editable-card" type="editable-card"