|
1 | 1 | 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'; |
4 | 4 |
|
5 | 5 | interface GitHubStarCounterProps {
|
6 | 6 | owner: string;
|
@@ -87,45 +87,70 @@ const GitHubStarCounter: React.FC<GitHubStarCounterProps> = ({
|
87 | 87 | fetchStarCount();
|
88 | 88 | }, [owner, repo, cacheTime]);
|
89 | 89 |
|
90 |
| - // 样式 |
| 90 | + // 容器样式 |
91 | 91 | const containerStyle = {
|
92 | 92 | display: 'inline-flex',
|
93 | 93 | alignItems: 'center',
|
94 | 94 | 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', |
102 | 97 | 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', |
106 | 119 | };
|
107 | 120 |
|
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', |
111 | 131 | };
|
112 | 132 |
|
113 | 133 | return (
|
114 |
| - <Tooltip title="Star us on GitHub"> |
| 134 | + <Tooltip title="Star us on GitHub" placement="bottom"> |
115 | 135 | <a
|
116 | 136 | href={`https://github.com/${owner}/${repo}`}
|
117 | 137 | target="_blank"
|
118 | 138 | rel="noopener noreferrer"
|
119 | 139 | style={containerStyle}
|
120 | 140 | onMouseOver={(e) => {
|
121 |
| - Object.assign(e.currentTarget.style, hoverStyle); |
| 141 | + e.currentTarget.style.color = '#1890ff'; |
| 142 | + e.currentTarget.style.transform = 'scale(1.05)'; |
122 | 143 | }}
|
123 | 144 | onMouseOut={(e) => {
|
124 |
| - Object.assign(e.currentTarget.style, containerStyle); |
| 145 | + e.currentTarget.style.color = '#333'; |
| 146 | + e.currentTarget.style.transform = 'scale(1)'; |
125 | 147 | }}
|
126 | 148 | >
|
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> |
129 | 154 | </a>
|
130 | 155 | </Tooltip>
|
131 | 156 | );
|
|
0 commit comments