forked from npm/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-footer.js
89 lines (80 loc) · 2.27 KB
/
page-footer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React from 'react'
import {Box, Avatar, Text} from '@primer/react'
import {Octicon} from '@primer/react/deprecated'
import {Tooltip} from '@primer/react/next'
import {PencilIcon} from '@primer/octicons-react'
import Link from './link'
import usePage from '../hooks/use-page'
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
]
const format = d => `${months[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`
const pluralize = (word, count) => `${word}${count === 1 ? '' : 's'}`
const Contributors = ({contributors = [], latestCommit}) => {
if (!contributors.length) {
return null
}
return (
<>
<Box sx={{display: 'flex', alignItems: 'center', flexWrap: 'wrap'}}>
<Text sx={{mr: 2}}>
{contributors.length} {pluralize('contributor', contributors.length)}
</Text>
{contributors.map(login => (
<Tooltip key={login} text={login}>
<Link href={`https://github.com/${login}`} sx={{lineHeight: 'condensedUltra', mr: 2}}>
<Avatar src={`https://github.com/${login}.png?size=40`} alt={login} />
</Link>
</Tooltip>
))}
</Box>
{latestCommit ? (
<Text sx={{fontSize: 1, mt: 1}}>
Last edited by <Link href={`https://github.com/${latestCommit.login}`}>{latestCommit.login}</Link> on{' '}
<Link href={latestCommit.url}>{format(new Date(latestCommit.date))}</Link>
</Text>
) : null}
</>
)
}
const PageFooter = () => {
const {editUrl, latestCommit, contributors = []} = usePage().pageContext
if (!editUrl && !contributors.length) {
return null
}
return (
<Box
sx={{
borderWidth: 0,
borderTopWidth: 1,
borderRadius: 0,
mt: 8,
py: 5,
borderStyle: 'solid',
borderColor: 'border.default',
}}
>
<Box sx={{display: 'grid', gap: 4}}>
{editUrl ? (
<Link href={editUrl}>
<Octicon icon={PencilIcon} sx={{mr: 2}} />
Edit this page on GitHub
</Link>
) : null}
<Contributors contributors={contributors} latestCommit={latestCommit} />
</Box>
</Box>
)
}
export default PageFooter