@@ -28,6 +28,7 @@ const GitHubStarCounter: React.FC<GitHubStarCounterProps> = ({
28
28
} ) => {
29
29
const [ starCount , setStarCount ] = useState < number | null > ( null ) ;
30
30
const [ loading , setLoading ] = useState ( true ) ;
31
+ const [ isHovered , setIsHovered ] = useState ( false ) ;
31
32
32
33
useEffect ( ( ) => {
33
34
const fetchStarCount = async ( ) => {
@@ -99,83 +100,120 @@ const GitHubStarCounter: React.FC<GitHubStarCounterProps> = ({
99
100
return count . toString ( ) ;
100
101
} ;
101
102
102
- // 美化后的容器样式
103
- const containerStyle = {
104
- display : 'inline- flex' ,
103
+ // 精美的按钮容器
104
+ const buttonStyles = {
105
+ display : 'flex' ,
105
106
alignItems : 'center' ,
106
- justifyContent : 'center' ,
107
- fontSize : '13px' ,
108
- color : '#24292e' ,
109
- cursor : 'pointer' ,
110
- transition : 'all 0.3s cubic-bezier(0.4, 0, 0.2, 1)' ,
111
107
height : '28px' ,
112
- borderRadius : '15px' ,
113
- textDecoration : 'none' ,
114
108
padding : '0 12px' ,
115
- fontWeight : 500 ,
116
- border : '1px solid rgba(36, 41, 46, 0.1)' ,
117
- background : 'linear-gradient(to bottom, #fafbfc, #f6f8fa)' ,
118
- boxShadow : '0 1px 2px rgba(0, 0, 0, 0.05)' ,
119
- } ;
120
-
121
- // 悬停样式
122
- const hoverStyle = {
123
- background : 'linear-gradient(to bottom, #f6f8fa, #e1e4e8)' ,
124
- boxShadow : '0 1px 3px rgba(0, 0, 0, 0.1)' ,
125
- transform : 'translateY(-1px)' ,
126
- borderColor : 'rgba(36, 41, 46, 0.2)' ,
109
+ background : isHovered
110
+ ? 'linear-gradient(135deg, #2b3137 0%, #373e47 100%)'
111
+ : 'linear-gradient(135deg, #24292e 0%, #2c3036 100%)' ,
112
+ color : 'white' ,
113
+ border : 'none' ,
114
+ borderRadius : '14px' ,
115
+ fontFamily : '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica' ,
116
+ fontSize : '12px' ,
117
+ fontWeight : 600 ,
118
+ letterSpacing : '0.2px' ,
119
+ transition : 'all 0.2s ease' ,
120
+ boxShadow : isHovered
121
+ ? '0 4px 8px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.06)'
122
+ : '0 2px 5px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(255, 255, 255, 0.04)' ,
123
+ cursor : 'pointer' ,
124
+ position : 'relative' ,
125
+ overflow : 'hidden' ,
126
+ transform : isHovered ? 'translateY(-1px)' : 'none' ,
127
+ textDecoration : 'none'
127
128
} ;
128
129
129
- // GitHub图标样式
130
- const githubIconStyle = {
131
- fontSize : '16px' ,
132
- color : '#24292e' ,
130
+ // GitHub 图标样式
131
+ const githubIconStyles = {
132
+ fontSize : '14px' ,
133
133
marginRight : '4px' ,
134
+ color : 'white' ,
135
+ transition : 'transform 0.2s ease' ,
136
+ transform : isHovered ? 'scale(1.1)' : 'scale(1)' ,
134
137
} ;
135
138
136
- // Star图标样式
137
- const starIconStyle = {
138
- fontSize : '14px' ,
139
- color : '#f1c40f' ,
140
- marginRight : '4px' ,
141
- filter : 'drop-shadow(0px 1px 1px rgba(0, 0, 0, 0.1))' ,
139
+ // 星星图标样式
140
+ const starIconStyles = {
141
+ color : isHovered ? '#ffdd57' : '#f9d361' ,
142
+ fontSize : '12px' ,
143
+ marginRight : '5px' ,
144
+ marginLeft : '3px' ,
145
+ transition : 'transform 0.3s ease, color 0.3s ease' ,
146
+ transform : isHovered ? 'scale(1.2) rotate(5deg)' : 'scale(1)' ,
147
+ filter : isHovered
148
+ ? 'drop-shadow(0 0 3px rgba(255, 221, 87, 0.6))'
149
+ : 'drop-shadow(0 0 1px rgba(255, 221, 87, 0.3))' ,
142
150
} ;
143
151
144
152
// 数字样式
145
- const countStyle = {
153
+ const countStyles = {
146
154
fontWeight : 600 ,
147
- color : '#24292e' ,
155
+ color : 'white' ,
156
+ fontSize : '12px' ,
157
+ textShadow : '0px 1px 2px rgba(0, 0, 0, 0.2)' ,
148
158
} ;
149
159
150
- // 加载动画样式
151
- const spinnerStyle = {
152
- margin : '0 5px' ,
160
+ // 加载动画容器样式
161
+ const loadingContainerStyles = {
162
+ display : 'inline-flex' ,
163
+ alignItems : 'center' ,
164
+ justifyContent : 'center' ,
165
+ marginLeft : '4px' ,
166
+ width : '20px' ,
167
+ height : '16px' ,
153
168
} ;
154
169
170
+ // 发光动画样式
171
+ const glowStyles = {
172
+ position : 'absolute' ,
173
+ top : 0 ,
174
+ left : 0 ,
175
+ right : 0 ,
176
+ height : '100%' ,
177
+ background : 'linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent)' ,
178
+ transform : isHovered ? 'translateX(100%)' : 'translateX(-100%)' ,
179
+ transition : 'transform 0.6s ease' ,
180
+ } as React . CSSProperties ;
181
+
182
+ // 按钮文本内容
183
+ const buttonText = loading ? (
184
+ < div style = { loadingContainerStyles } >
185
+ < Spin size = "small" style = { { transform : 'scale(0.7)' } } />
186
+ </ div >
187
+ ) : (
188
+ < span style = { countStyles } >
189
+ { starCount !== null ? formatStarCount ( starCount ) : '0' }
190
+ </ span >
191
+ ) ;
192
+
155
193
return (
156
- < Tooltip title = "Star us on GitHub" placement = "bottom" >
157
- < a
194
+ < Tooltip
195
+ title = "Star us on GitHub!"
196
+ placement = "bottom"
197
+ color = "#1a1e22"
198
+ overlayInnerStyle = { {
199
+ padding : '8px 10px' ,
200
+ fontSize : '12px' ,
201
+ fontWeight : 500 ,
202
+ borderRadius : '6px'
203
+ } }
204
+ >
205
+ < a
158
206
href = { `https://github.com/${ owner } /${ repo } ` }
159
207
target = "_blank"
160
208
rel = "noopener noreferrer"
161
- style = { containerStyle }
162
- onMouseOver = { ( e ) => {
163
- Object . assign ( e . currentTarget . style , hoverStyle ) ;
164
- } }
165
- onMouseOut = { ( e ) => {
166
- // 重置为原始样式
167
- Object . assign ( e . currentTarget . style , containerStyle ) ;
168
- } }
209
+ style = { buttonStyles as React . CSSProperties }
210
+ onMouseEnter = { ( ) => setIsHovered ( true ) }
211
+ onMouseLeave = { ( ) => setIsHovered ( false ) }
169
212
>
170
- < GithubOutlined style = { githubIconStyle } />
171
- < StarFilled style = { starIconStyle } />
172
- { loading ? (
173
- < Spin size = "small" style = { spinnerStyle } />
174
- ) : (
175
- < span style = { countStyle } >
176
- { starCount !== null ? formatStarCount ( starCount ) : '0' }
177
- </ span >
178
- ) }
213
+ < div style = { glowStyles } />
214
+ < GithubOutlined style = { githubIconStyles } />
215
+ < StarFilled style = { starIconStyles } />
216
+ { buttonText }
179
217
</ a >
180
218
</ Tooltip >
181
219
) ;
0 commit comments