Skip to content

Commit

Permalink
docs: Improve github stars homepage button
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Sep 22, 2023
1 parent 5546f66 commit d8a0c15
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 56 deletions.
26 changes: 26 additions & 0 deletions website/src/components/GithubStarsButton.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.GithubStars {
transition-duration: 0.3s;
display:inline-grid;
grid-auto-flow:column;
align-items:center;
gap: .375rem;
transition-timing-function: cubic-bezier(.4,0,.2,1);
}

.GithubStars svg {
margin-top:-5px;
}

.count {
white-space: nowrap;
overflow: hidden;
width:100%;
}
.count.done {
max-width:100px;
opacity:1;
}
.count.loading {
max-width: 0;
opacity: 0;
}
60 changes: 60 additions & 0 deletions website/src/components/GithubStarsButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import clsx from 'clsx';
import React, { useEffect, useState } from 'react';

import styles from './GithubStarsButton.module.css';

export function GithubStarsButton({ className }: Props) {
const [stars, setStars] = useState<string>();

const fetchStars = async () => {
const res = await fetch(
'https://api.github.com/repos/reactive/data-client',
);
const data = (await res.json()) as { stargazers_count: number };
if (typeof data?.stargazers_count === 'number') {
setStars(new Intl.NumberFormat().format(data.stargazers_count));
}
};

useEffect(() => {
fetchStars().catch(console.error);
}, []);

return (
<a
href="https://github.com/reactive/data-client/stargazers"
target="_blank"
className={clsx(
'button button--secondary',
className,
styles.GithubStars,
)}
rel="noreferrer"
>
<svg
stroke="currentColor"
fill="none"
strokeWidth="3"
viewBox="0 0 24 24"
strokeLinecap="round"
strokeLinejoin="round"
height="18"
width="18"
xmlns="http://www.w3.org/2000/svg"
>
<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon>
</svg>
<span>Star</span>
<span
style={{ transition: 'max-width 1s, opacity 1s' }}
className={clsx(stars ? styles.done : styles.loading, styles.count)}
>
{stars}
</span>
</a>
);
}

type Props = {
className?: string;
};
18 changes: 13 additions & 5 deletions website/src/css/root.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ html[data-theme='dark'] {
--monoco-code-lineHighlightBorder: hsl(228, 20%, 20%);
--ifm-link-color: var(--ifm-color-primary-light);
--docusaurus-highlighted-code-line-bg: rgb(72 77 91);
--ifm-color-secondary: #cbd0d8;
--ifm-color-secondary-dark: #b3bac6;
--ifm-color-secondary-darker: #a7b0bd;
--ifm-color-secondary-darkest: #838fa2;
--ifm-color-secondary-light: #e3e6ea;
--ifm-color-secondary-lighter: #eff0f3;
--ifm-color-secondary-lightest: #fff;
}
html[data-theme='light'] {
--monoco-code-background: #292d3e;
--monoco-code-lineHighlightBorder: hsl(228, 20%, 25%);
--ifm-hero-fade-to-background-color: #fff;
--ifm-link-color: var(--ifm-color-primary-dark);

--ifm-color-secondary: #ebedf0;
}
:root {
--ifm-color-primary-lightest: hsl(206, 69%, 81%);
Expand All @@ -20,7 +27,7 @@ html[data-theme='light'] {
--ifm-color-primary-darker: hsl(206, 69%, 44%);
--ifm-color-primary-darkest: hsl(206, 69%, 35%);
--ifm-color-info: hsl(206, 77%, 69%);
--ifm-color-info-dark: hsl(206, 77%, 45%);
--ifm-color-info-dark: hsl(206, 77%, 45%);
--ifm-color-info-darker: hsl(206, 77%, 43%);
--ifm-color-info-darkest: hsl(206, 77%, 37%);
--ifm-color-info-light: hsl(206, 77%, 53%);
Expand All @@ -32,7 +39,7 @@ html[data-theme='light'] {
Consolas, 'Liberation Mono', 'Courier New', monospace;
--ifm-hero-background-color: var(--ifm-background-color);
--ifm-hero-fade-to-background-color: var(--ifm-background-color);
--ifm-pre-padding: .8rem;
--ifm-pre-padding: 0.8rem;
}

.theme-code-block {
Expand All @@ -48,10 +55,11 @@ html[data-theme='light'] {
font-family: var(--ifm-font-family-base);
}

code, pre {
code,
pre {
font-family: var(-ifm-font-family-monospace);
}

html {
font-family: var(--ifm-font-family-base);
}
}
32 changes: 2 additions & 30 deletions website/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React from 'react';

import styles from './index.module.css';
import Demo from '../components/Demo/index';
import { GithubStarsButton } from '../components/GithubStarsButton';
import HomepageFeatures from '../components/HomepageFeatures';
import { isGoogleBot } from '../components/Playground/isGoogleBot';
import StackBlitz from '../components/StackBlitz';
Expand Down Expand Up @@ -48,42 +49,13 @@ function HomepageHeader() {
<div className="container">
<ProjectTitle />
<div className={styles.buttons}>
<GithubStarsButton />
<Link
className="button button--primary"
to="/docs/getting-started/installation"
>
Get Started
</Link>

<span className={styles.GitHubButtonWrapper}>
<BrowserOnly
fallback={
<iframe
width={160}
height={30}
className={styles.GitHubButton}
></iframe>
}
>
{() =>
isGoogleBot ? (
<iframe
width={160}
height={30}
className={styles.GitHubButton}
></iframe>
) : (
<iframe
className={styles.GitHubButton}
src="https://ghbtns.com/github-btn.html?user=reactive&amp;repo=data-client&amp;type=star&amp;count=true&amp;size=large"
width={160}
height={30}
title="GitHub Stars"
/>
)
}
</BrowserOnly>
</span>
</div>
</div>
</header>
Expand Down
43 changes: 22 additions & 21 deletions website/src/pages/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,35 @@
.buttons :global(.button) {
font-size: 18px;
border-radius: 10px;
letter-spacing: 1px;
letter-spacing: 0;

padding: calc( var(--ifm-button-padding-vertical) * var(--ifm-button-size-multiplier) * 0.9 )
calc( var(--ifm-button-padding-horizontal) * var(--ifm-button-size-multiplier) * 0.9 );

--shadow: 0 10px 25px -5px var(--shadow-color),0 8px 10px -6px var(--shadow-color);
--ring-shadow: 0 0 #000;
--ring-offset-shadow: 0 0 #000;
box-shadow: var(--ring-offset-shadow,0 0 #0000),var(--ring-shadow,0 0 #0000),var(--shadow);
}
.buttons :global(.button.button--primary) {
--shadow-color: rgba(14,165,233,.2);
}
html[data-theme='dark'] .buttons :global(.button.button--secondary) {
--shadow-color: rgba(203, 208, 216,.2);
}
html[data-theme='light'] .buttons :global(.button.button--secondary) {
--shadow-color: rgba(167, 176, 189,.2);
}

.buttons :global(.button) svg {
margin-bottom: -3px;
display: inline-block;
}
.buttons :global(.button:last-of-type) {
margin: 0 36px;
}

.GitHubButtonWrapper {
display: flex;
}

.GitHubButton {
overflow: hidden;
margin: 0 16px;
}

@media only screen and (max-width: 768px) {
.buttons {
flex-direction: column;
}
.buttons :global(.button), .buttons :global(.button:last-of-type) {
margin: 0 0 15px 0;
}
.logoWrapper {
margin-bottom: 15px;
}
Expand All @@ -85,12 +89,9 @@
}

@media only screen and (max-width: 500px) {
.buttons :global(.button.button--primary),.buttons :global(.button.button--info) {
.buttons :global(.button.button--primary),.buttons :global(.button.button--secondary) {
font-size: 15px;
padding: 0.3em 1.1em;
}
.GitHubButtonWrapper {
transform: scale(80%);
padding: 0.3em 1.1em;
}
}

Expand Down

0 comments on commit d8a0c15

Please sign in to comment.