Skip to content

Commit 174233c

Browse files
committed
style: enhance GitHub star counter design and reposition in navbar
1 parent c5e68ff commit 174233c

File tree

2 files changed

+54
-29
lines changed

2 files changed

+54
-29
lines changed

src/components/GitHubStarCounter.tsx

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useEffect } from 'react';
2-
import { GithubOutlined } from '@ant-design/icons';
3-
import { Tooltip } from 'antd';
2+
import { GithubOutlined, StarFilled } from '@ant-design/icons';
3+
import { Tooltip, Badge } from 'antd';
44

55
interface GitHubStarCounterProps {
66
owner: string;
@@ -87,45 +87,70 @@ const GitHubStarCounter: React.FC<GitHubStarCounterProps> = ({
8787
fetchStarCount();
8888
}, [owner, repo, cacheTime]);
8989

90-
// 样式
90+
// 容器样式
9191
const containerStyle = {
9292
display: 'inline-flex',
9393
alignItems: 'center',
9494
justifyContent: 'center',
95-
fontWeight: 500,
96-
fontSize: '14px',
97-
padding: '4px 8px',
98-
border: '1px solid #e1e4e8',
99-
borderRadius: '6px',
100-
color: '#24292e',
101-
backgroundColor: '#f6f8fa',
95+
fontSize: '13px',
96+
color: '#333',
10297
cursor: 'pointer',
103-
transition: 'all 0.2s ease',
104-
height: '28px',
105-
lineHeight: '20px'
98+
transition: 'transform 0.2s ease, color 0.2s ease',
99+
height: '100%',
100+
borderRadius: '4px',
101+
textDecoration: 'none',
102+
padding: '0 8px',
103+
fontWeight: 600,
104+
};
105+
106+
// GitHub图标样式
107+
const githubIconStyle = {
108+
fontSize: '22px',
109+
color: '#24292e',
110+
marginRight: '2px',
111+
verticalAlign: 'middle'
112+
};
113+
114+
// Star图标样式
115+
const starIconStyle = {
116+
fontSize: '14px',
117+
color: '#ff9800',
118+
marginRight: '3px',
106119
};
107120

108-
// 当鼠标悬停时的样式
109-
const hoverStyle = {
110-
backgroundColor: '#e1e4e8'
121+
// 徽章样式
122+
const badgeStyle = {
123+
backgroundColor: '#24292e',
124+
color: 'white',
125+
fontSize: '12px',
126+
padding: '1px 6px',
127+
borderRadius: '10px',
128+
fontWeight: 'bold',
129+
marginLeft: '4px',
130+
display: 'inline-block',
111131
};
112132

113133
return (
114-
<Tooltip title="Star us on GitHub">
134+
<Tooltip title="Star us on GitHub" placement="bottom">
115135
<a
116136
href={`https://github.com/${owner}/${repo}`}
117137
target="_blank"
118138
rel="noopener noreferrer"
119139
style={containerStyle}
120140
onMouseOver={(e) => {
121-
Object.assign(e.currentTarget.style, hoverStyle);
141+
e.currentTarget.style.color = '#1890ff';
142+
e.currentTarget.style.transform = 'scale(1.05)';
122143
}}
123144
onMouseOut={(e) => {
124-
Object.assign(e.currentTarget.style, containerStyle);
145+
e.currentTarget.style.color = '#333';
146+
e.currentTarget.style.transform = 'scale(1)';
125147
}}
126148
>
127-
<GithubOutlined style={{ marginRight: '6px' }} />
128-
{loading ? '...' : `${starCount || 0}`}
149+
<GithubOutlined style={githubIconStyle} />
150+
<div style={{ display: 'flex', alignItems: 'center', marginLeft: '5px' }}>
151+
<StarFilled style={starIconStyle} />
152+
<span>{loading ? '...' : starCount}</span>
153+
</div>
129154
</a>
130155
</Tooltip>
131156
);

src/components/NavBar.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ const NavBar = () => {
170170
alignItems: 'center',
171171
gap: '8px'
172172
}}>
173-
{/* GitHub Star计数 */}
174-
<GitHubStarCounter owner="JSREP" repo="crawler-leetcode" />
175-
176173
{/* 贡献题目按钮 */}
177174
<Button
178175
type="primary"
@@ -198,6 +195,9 @@ const NavBar = () => {
198195
<Option value="zh">简体中文</Option>
199196
<Option value="en">English</Option>
200197
</Select>
198+
199+
{/* GitHub Star计数 */}
200+
<GitHubStarCounter owner="JSREP" repo="crawler-leetcode" />
201201
</div>
202202
</Col>
203203
)}
@@ -220,11 +220,6 @@ const NavBar = () => {
220220
style={{ border: 'none' }}
221221
/>
222222
<div style={{ marginTop: 24, padding: '0 16px' }}>
223-
{/* 移动端GitHub Star计数 */}
224-
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'center' }}>
225-
<GitHubStarCounter owner="JSREP" repo="crawler-leetcode" />
226-
</div>
227-
228223
<Button
229224
type="primary"
230225
icon={<PlusOutlined />}
@@ -245,6 +240,11 @@ const NavBar = () => {
245240
<Option value="en">English</Option>
246241
</Select>
247242
</div>
243+
244+
{/* 移动端GitHub Star计数 */}
245+
<div style={{ display: 'flex', justifyContent: 'center', marginBottom: 16 }}>
246+
<GitHubStarCounter owner="JSREP" repo="crawler-leetcode" />
247+
</div>
248248
</div>
249249
</Drawer>
250250
</Header>

0 commit comments

Comments
 (0)