|
| 1 | +import { useEffect, useState } from "react"; |
| 2 | +import clsx from "clsx"; |
| 3 | +import { InputFooter } from "./InputFooter"; |
| 4 | + |
| 5 | +const GITHUB_REPO = "https://github.com/webiny/webiny-js"; |
| 6 | + |
| 7 | +const GithubIcon = ( |
| 8 | + <svg |
| 9 | + width="16" |
| 10 | + height="16" |
| 11 | + viewBox="0 0 16 16" |
| 12 | + className="fill-dark-blue dark:fill-white" |
| 13 | + aria-hidden="true" |
| 14 | + > |
| 15 | + <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" /> |
| 16 | + </svg> |
| 17 | +); |
| 18 | + |
| 19 | +const StarIcon = ( |
| 20 | + <svg |
| 21 | + width="14" |
| 22 | + height="14" |
| 23 | + viewBox="0 0 24 24" |
| 24 | + fill="none" |
| 25 | + stroke="currentColor" |
| 26 | + strokeWidth="2" |
| 27 | + strokeLinecap="round" |
| 28 | + strokeLinejoin="round" |
| 29 | + aria-hidden="true" |
| 30 | + > |
| 31 | + <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" /> |
| 32 | + </svg> |
| 33 | +); |
| 34 | + |
| 35 | +function formatStars(count) { |
| 36 | + if (count >= 1000) { |
| 37 | + return `${(count / 1000).toFixed(1).replace(/\.0$/, "")}k`; |
| 38 | + } |
| 39 | + return `${count}`; |
| 40 | +} |
| 41 | + |
| 42 | +function StarOnGithub() { |
| 43 | + const [stars, setStars] = useState(null); |
| 44 | + |
| 45 | + useEffect(() => { |
| 46 | + let active = true; |
| 47 | + fetch("https://api.github.com/repos/webiny/webiny-js") |
| 48 | + .then(res => (res.ok ? res.json() : null)) |
| 49 | + .then(data => { |
| 50 | + if (active && data && typeof data.stargazers_count === "number") { |
| 51 | + setStars(data.stargazers_count); |
| 52 | + } |
| 53 | + }) |
| 54 | + .catch(() => {}); |
| 55 | + return () => { |
| 56 | + active = false; |
| 57 | + }; |
| 58 | + }, []); |
| 59 | + |
| 60 | + return ( |
| 61 | + <div> |
| 62 | + <p className="text-sidebar-right-title font-semibold text-dark-blue dark:text-white mb-2.5"> |
| 63 | + Star on GitHub |
| 64 | + </p> |
| 65 | + <a |
| 66 | + href={GITHUB_REPO} |
| 67 | + target="_blank" |
| 68 | + rel="noreferrer" |
| 69 | + className="group inline-flex items-stretch overflow-hidden rounded-md border border-neutral-200 dark:border-dark-grey text-nav-link font-roboto text-dark-blue dark:text-white transition-colors duration-300 hover:border-[#fa592885]" |
| 70 | + > |
| 71 | + <span className="flex items-center gap-x-1.5 px-2.5 py-1.5 group-hover:text-orange"> |
| 72 | + {StarIcon} |
| 73 | + <span className="font-semibold">Star</span> |
| 74 | + </span> |
| 75 | + <span className="flex items-center px-2.5 py-1.5 border-l border-neutral-200 dark:border-dark-grey font-semibold"> |
| 76 | + {stars === null ? GithubIcon : formatStars(stars)} |
| 77 | + </span> |
| 78 | + </a> |
| 79 | + </div> |
| 80 | + ); |
| 81 | +} |
| 82 | + |
| 83 | +const links = [ |
| 84 | + { |
| 85 | + label: "Questions?", |
| 86 | + linkText: "Find us on Slack.", |
| 87 | + href: "https://www.webiny.com/slack" |
| 88 | + }, |
| 89 | + { |
| 90 | + label: "Found a bug on the page?", |
| 91 | + linkText: "Submit an issue or a PR.", |
| 92 | + href: "https://github.com/webiny/docs.webiny.com" |
| 93 | + }, |
| 94 | + { |
| 95 | + label: "Check out our", |
| 96 | + linkText: "roadmap.", |
| 97 | + href: "https://www.webiny.com/roadmap" |
| 98 | + } |
| 99 | +]; |
| 100 | + |
| 101 | +export function SidebarTools({ divider = true }) { |
| 102 | + return ( |
| 103 | + <div |
| 104 | + className={clsx( |
| 105 | + "flex flex-col gap-y-8", |
| 106 | + divider |
| 107 | + ? "mt-8 pt-6 border-t border-neutral-200 dark:border-dark-grey" |
| 108 | + : "mt-[1.725rem]" |
| 109 | + )} |
| 110 | + > |
| 111 | + <StarOnGithub /> |
| 112 | + |
| 113 | + <ul className="flex flex-col gap-y-2.5 text-nav-link leading-5 font-roboto text-dark-blue dark:text-white"> |
| 114 | + {links.map(item => ( |
| 115 | + <li key={item.href}> |
| 116 | + {item.label}{" "} |
| 117 | + <a |
| 118 | + href={item.href} |
| 119 | + target="_blank" |
| 120 | + rel="noreferrer" |
| 121 | + className="font-source-sans-pro text-orange underline hover:decoration-2" |
| 122 | + > |
| 123 | + {item.linkText} |
| 124 | + </a> |
| 125 | + </li> |
| 126 | + ))} |
| 127 | + </ul> |
| 128 | + |
| 129 | + <div> |
| 130 | + <p className="text-sidebar-right-title font-semibold text-dark-blue dark:text-white mb-2.5"> |
| 131 | + Join our developer newsletter |
| 132 | + </p> |
| 133 | + <InputFooter className="mb-[0.3125rem]" /> |
| 134 | + <p className="text-[0.75rem] leading-[0.875rem] text-light-grey-4 dark:text-light-grey-5"> |
| 135 | + You can unsubscribe at any time. |
| 136 | + </p> |
| 137 | + </div> |
| 138 | + </div> |
| 139 | + ); |
| 140 | +} |
0 commit comments