Skip to content

Commit

Permalink
feat: add githubRepo preset
Browse files Browse the repository at this point in the history
+ Via #246
  • Loading branch information
breadadams committed Jan 23, 2022
1 parent 1524cd9 commit a2740ef
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 0 deletions.
Binary file added packages/app/public/preview/githubRepo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
220 changes: 220 additions & 0 deletions packages/app/src/components/presets/githubRepo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/* eslint-disable no-use-before-define,react/jsx-pascal-case */

import Inline from '../inline.macro'
import { Box, Flex, Link, MQL, Spinner, Text } from './scope'

const code = (
<Inline>
<>
<Link
href='https://fonts.googleapis.com/icon?family=Material+Icons'
rel='stylesheet'
/>
<Flex
sx={{
background: '#fff',
color: '#30353B',
fontFamily:
'-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"'
}}
>
<MQL
url={query.url}
data={{
languages: {
selectorAll: '.Layout-sidebar .Progress > span',
type: 'text',
attr: 'style'
},
name: {
selector:
'#repository-container-header h1 strong[itemprop=name] a'
},
contributors: {
selector: '.Layout-sidebar a[href$=/contributors] .Counter'
},
contributorsRaw: {
selector: '.Layout-sidebar a[href$=/contributors] .Counter',
attr: 'title',
type: 'number'
},
dependants: {
selector:
'.Layout-sidebar a[href*=/dependents?package_id] .Counter'
},
description: {
selector: '.Layout-sidebar p:first-of-type'
},
tags: {
selectorAll: '.Layout-sidebar .topic-tag'
},
forks: {
selector: '#repo-network-counter'
},
forksRaw: {
selector: '#repo-network-counter',
attr: 'title',
type: 'number'
},
issues: {
selector: '#issues-repo-tab-count'
},
issuesRaw: {
selector: '#issues-repo-tab-count',
attr: 'title',
type: 'number'
},
stars: {
selector: '#repo-stars-counter-star'
},
starsRaw: {
selector: '#repo-stars-counter-star',
attr: 'title',
type: 'number'
}
}}
>
{(payload) => {
if (payload === null) return <Spinner />

const { data } = payload

const stats = [
{
icon: 'star',
label: data.starsRaw !== 1 ? 'Stars' : 'Star',
value: data.stars
},
{
icon: 'people',
label:
data.contributorsRaw !== 1 ? 'Contributors' : 'Contributor',
value: data.contributors
},
{
icon: 'download',
label: 'Used By',
value: data.dependants
},
{
icon: 'alt_route',
label: data.forksRaw !== 1 ? 'Forks' : 'Fork',
value: data.forks
},
{
icon: 'help',
label: data.issuesRaw !== 1 ? 'Issues' : 'Issue',
value: data.issues
}
]

return (
<Flex
sx={{ flexDirection: 'column', width: '100%', height: '100%' }}
>
<Flex
sx={{
flex: '1 1 auto',
flexDirection: 'column',
p: 60,
minHeight: 0
}}
>
<Box sx={{ mb: 10 }}>
<Text
sx={{ fontSize: 42, letterSpacing: 0.5, fontWeight: 200 }}
>
{data.author}/
<Text sx={{ fontWeight: 600 }}>{data.name}</Text>
</Text>
</Box>

<Box sx={{ mb: 20 }}>
<Text
dangerouslySetInnerHTML={{ __html: data.description }}
sx={{ fontSize: 16 }}
/>
</Box>

<Flex sx={{ flexWrap: 'wrap' }}>
{!!data.tags &&
data.tags.map((tag) => (
<Box
key={tag}
sx={{
background: '#ddf4ff',
color: '#0969da',
borderRadius: 9999,
px: 14,
pt: '4px',
pb: '6px',
mr: '8px',
mb: '8px',
fontSize: 14,
fontWeight: 500
}}
>
{tag}
</Box>
))}
</Flex>

<Flex sx={{ mt: 'auto' }}>
{stats.map((stat) =>
typeof stat.value === 'number' ||
typeof stat.value === 'string'
? (
<Flex sx={{ mr: 34 }} key={stat.label}>
<Box
sx={{
paddingRight: 10,
paddingTop: '2px'
}}
className='material-icons'
>
<Text sx={{ fontSize: 26, color: '#76767F' }}>
{stat.icon}
</Text>
</Box>
<Box>
<Box>
<Text sx={{ fontSize: 20, fontWeight: 400 }}>
{stat.value}
</Text>
</Box>
<Text
sx={{
fontSize: 18,
color: '#76767F',
letterSpacing: 0.5
}}
>
{stat.label}
</Text>
</Box>
</Flex>
)
: null
)}
</Flex>
</Flex>

<Flex sx={{ flex: '0 0 18px' }}>
{data.languages.map((styles, i) => (
<Box key={`language_${i}`} css={styles} />
))}
</Flex>
</Flex>
)
}}
</MQL>
</Flex>
</>
</Inline>
)

const query = {
url: 'https://github.com/vercel/next.js'
}

export const githubRepo = { name: 'githubRepo', code, query }
1 change: 1 addition & 0 deletions packages/app/src/components/presets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export { device } from './device'
export { dracula } from './dracula'
export { draculashop } from './draculashop'
export { frame } from './frame'
export { githubRepo } from './githubRepo'
export { jxnblk } from './jxnblk'
export { kfund } from './kfund'
export { kikobeats } from './kikobeats'
Expand Down

0 comments on commit a2740ef

Please sign in to comment.