Skip to content

Commit 1736204

Browse files
committed
add button "star project" for all projects
1 parent cb748fe commit 1736204

File tree

9 files changed

+165
-9
lines changed

9 files changed

+165
-9
lines changed

public/locales/en/library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"readme": "Readme",
55
"changelog": "Changelog",
66
"about": "About library",
7-
"stars": "Stars",
7+
"stars": "Support library with a star",
88
"version": "Version",
99
"lastUpdate": "Last update",
1010
"repository": "Repository",
1111
"license": "License",
1212
"issues": "Issues",
1313
"maintainers": "Maintainers",
1414
"contributors": "Contributors"
15-
}
15+
}

public/locales/es/library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"readme": "Léeme",
55
"changelog": "Registro de cambios",
66
"about": "Acerca de la biblioteca",
7-
"stars": "Estrellas",
7+
"stars": "Apoya la biblioteca con una estrella",
88
"version": "Versión",
99
"lastUpdate": "Última actualización",
1010
"repository": "Repositorio",
1111
"license": "Licencia",
1212
"issues": "Cuestiones",
1313
"maintainers": "Mantenedores",
1414
"contributors": "Colaboradores"
15-
}
15+
}

public/locales/ru/library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"readme": "Readme",
55
"changelog": "Changelog",
66
"about": "О библиотеке",
7-
"stars": "Звёзды",
7+
"stars": "Поддержите библиотеку звёздочкой",
88
"version": "Версия",
99
"lastUpdate": "Последнее обновление",
1010
"repository": "Репозиторий",
1111
"license": "Лицензия",
1212
"issues": "Задачи",
1313
"maintainers": "Maintainers",
1414
"contributors": "Участники"
15-
}
15+
}

public/locales/zh/library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"readme": "自述文件",
55
"changelog": "变更日志",
66
"about": "关于图书馆",
7-
"stars": "明星",
7+
"stars": "用星星支持图书馆",
88
"version": "版本",
99
"lastUpdate": "上次更新",
1010
"repository": "存储库",
1111
"license": "执照",
1212
"issues": "问题",
1313
"maintainers": "维护者",
1414
"contributors": "贡献者"
15-
}
15+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@use '../../variables.scss';
2+
3+
$block: '.#{variables.$ns}github-star-button';
4+
5+
#{$block} {
6+
display: flex;
7+
justify-content: center;
8+
align-items: center;
9+
text-decoration: none;
10+
border-radius: 8px;
11+
transition: opacity 0.2s ease;
12+
background: rgba(255, 255, 255, 1);
13+
color: var(--g-color-text-dark-primary);
14+
height: 36px;
15+
width: 136px;
16+
17+
&:hover {
18+
opacity: 0.8;
19+
}
20+
21+
&__button {
22+
display: flex;
23+
align-items: center;
24+
gap: 4px;
25+
padding: 5px 8px;
26+
border: none;
27+
color: var(--g-color-text-dark-primary);
28+
}
29+
30+
&__divider {
31+
width: 1px;
32+
background: rgba(217, 217, 217, 1);
33+
height: 20px;
34+
}
35+
36+
&__count {
37+
padding: 5px 8px;
38+
}
39+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {Icon, Text} from '@gravity-ui/uikit';
2+
import React from 'react';
3+
4+
import githubIcon from '../../assets/icons/github.svg';
5+
6+
import './GitHubStarButton.scss';
7+
8+
const block = (name: string) => `gravity-ui-landing-github-star-button${name ? `__${name}` : ''}`;
9+
const b = block;
10+
11+
interface GitHubStarButtonProps {
12+
githubId: string;
13+
starCount: number;
14+
}
15+
16+
export const GitHubStarButton: React.FC<GitHubStarButtonProps> = ({githubId, starCount}) => {
17+
const githubUrl = `https://github.com/${githubId}`;
18+
19+
const formatStarCount = (count: number): string => {
20+
if (count >= 1000) {
21+
return `${(count / 1000).toFixed(1)}k`;
22+
}
23+
return count.toString();
24+
};
25+
26+
return (
27+
<a href={githubUrl} target="_blank" rel="noopener noreferrer" className={b('')}>
28+
<div className={b('button')}>
29+
<Icon data={githubIcon} size={20} className={b('icon')} />
30+
<Text variant="body-1" className={b('text')}>
31+
Stars
32+
</Text>
33+
</div>
34+
<div className={b('divider')} />
35+
<Text variant="body-1" className={b('count')}>
36+
{formatStarCount(starCount)}
37+
</Text>
38+
</a>
39+
);
40+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {GitHubStarButton} from './GitHubStarButton';

src/components/Library/Library.scss

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ $block: '.#{variables.$ns}library';
1212
& &__header-grid {
1313
.container-fluid {
1414
padding: 0;
15+
1516
.col {
1617
padding: 0;
1718
}
@@ -245,6 +246,48 @@ $block: '.#{variables.$ns}library';
245246
}
246247
}
247248

249+
&__info-item_github-star {
250+
padding: 16px;
251+
252+
&:first-child {
253+
margin-top: 16px;
254+
}
255+
}
256+
257+
&__github-star-content {
258+
display: flex;
259+
flex-direction: column;
260+
gap: 12px;
261+
width: 100%;
262+
}
263+
264+
&__github-star-text {
265+
display: flex;
266+
width: 100%;
267+
}
268+
269+
&__github-star-mobile {
270+
display: none;
271+
272+
@media (max-width: map-get(pcVariables.$gridBreakpoints, 'lg') - 1) {
273+
display: flex;
274+
justify-content: center;
275+
padding-right: 16px;
276+
277+
&_mobile-invisible {
278+
display: none;
279+
}
280+
}
281+
}
282+
283+
&__github-star-title {
284+
font-size: 13px;
285+
line-height: 18px;
286+
font-weight: 400;
287+
color: rgba(255, 255, 255, 0.6);
288+
text-align: center;
289+
}
290+
248291
&__contributors-content {
249292
display: block;
250293

src/components/Library/Library.tsx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import starIcon from '../../assets/icons/star.svg';
1414
import storybookIcon from '../../assets/icons/storybook.svg';
1515
import versionIcon from '../../assets/icons/version.svg';
1616
import {ContributorList} from '../../components/ContributorList';
17+
import {GitHubStarButton} from '../../components/GitHubStarButton';
1718
import {Link} from '../../components/Link';
1819
import {useLocale} from '../../hooks/useLocale';
1920
import {availablePlaygrounds} from '../../pages/libraries/[libId]/playground';
@@ -60,7 +61,6 @@ export const Library: React.FC<Props> = ({lib}) => {
6061
{
6162
id: 'stars',
6263
title: t('library:stars'),
63-
value: lib.metadata.stars,
6464
icon: starIcon,
6565
},
6666
{
@@ -258,6 +258,18 @@ export const Library: React.FC<Props> = ({lib}) => {
258258
}}
259259
>
260260
<div className={b('info-title-text')}>{t('library:about')}</div>
261+
262+
<div
263+
className={b('github-star-mobile', {
264+
'mobile-invisible': isVisibleInfoListMobile,
265+
})}
266+
>
267+
<GitHubStarButton
268+
githubId={lib.config.githubId}
269+
starCount={lib.metadata.stars}
270+
/>
271+
</div>
272+
261273
<div
262274
className={b('info-title-icon', {
263275
'mobile-visible': isVisibleInfoListMobile,
@@ -310,6 +322,27 @@ export const Library: React.FC<Props> = ({lib}) => {
310322
);
311323
}
312324

325+
if (item.id === 'stars') {
326+
return (
327+
<div
328+
key={item.id}
329+
className={b('info-item', {
330+
'github-star': true,
331+
})}
332+
>
333+
<div className={b('github-star-content')}>
334+
<div className={b('github-star-text')}>
335+
{content}
336+
</div>
337+
<GitHubStarButton
338+
githubId={lib.config.githubId}
339+
starCount={lib.metadata.stars}
340+
/>
341+
</div>
342+
</div>
343+
);
344+
}
345+
313346
return (
314347
<div key={item.id} className={b('info-item')}>
315348
{content}

0 commit comments

Comments
 (0)